From 2f6d28975c9837157053a63477986b55b036325d Mon Sep 17 00:00:00 2001 From: Daniel Widgren Date: Tue, 24 Feb 2026 17:29:11 +0100 Subject: [PATCH] fix: correct remaining source-accuracy issues in unreviewed chapters - JSON controllers in changesets.md, advanced-data.md, pubsub.md use `json` key (not `params`) for decoded JSON bodies - Auth tests in testing.md set `params` directly on the request map instead of using `with_json` (which sets the `json` key, not `params`) - validate_format regex patterns use binary syntax per Kura spec Co-Authored-By: Claude Opus 4.6 --- src/appendix/cheat-sheet.md | 2 +- src/building-api/advanced-data.md | 2 +- src/data-layer/changesets.md | 4 ++-- src/production/pubsub.md | 2 +- src/testing-errors/testing.md | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/appendix/cheat-sheet.md b/src/appendix/cheat-sheet.md index aebb27c..e6835bb 100644 --- a/src/appendix/cheat-sheet.md +++ b/src/appendix/cheat-sheet.md @@ -249,7 +249,7 @@ CS = kura_changeset:cast(SchemaModule, ExistingData, Params, AllowedFields). %% Validations kura_changeset:validate_required(CS, [field1, field2]) -kura_changeset:validate_format(CS, field, "regex") +kura_changeset:validate_format(CS, field, <<"regex">>) kura_changeset:validate_length(CS, field, [{min, 3}, {max, 200}]) kura_changeset:validate_number(CS, field, [{greater_than, 0}]) kura_changeset:validate_inclusion(CS, field, [val1, val2, val3]) diff --git a/src/building-api/advanced-data.md b/src/building-api/advanced-data.md index c83f6f1..cab44fd 100644 --- a/src/building-api/advanced-data.md +++ b/src/building-api/advanced-data.md @@ -265,7 +265,7 @@ index(_Req) -> {ok, Tags} = blog_repo:all(Q1), {json, #{tags => Tags}}. -create(#{params := Params}) -> +create(#{json := Params}) -> CS = tag:changeset(#{}, Params), case blog_repo:insert(CS) of {ok, Tag} -> diff --git a/src/data-layer/changesets.md b/src/data-layer/changesets.md index f10f60f..5d94894 100644 --- a/src/data-layer/changesets.md +++ b/src/data-layer/changesets.md @@ -82,7 +82,7 @@ fields() -> changeset(Data, Params) -> CS = kura_changeset:cast(user, Data, Params, [username, email, password_hash]), CS1 = kura_changeset:validate_required(CS, [username, email, password_hash]), - CS2 = kura_changeset:validate_format(CS1, email, "^[^@]+@[^@]+\\.[^@]+$"), + CS2 = kura_changeset:validate_format(CS1, email, <<"^[^@]+@[^@]+\\.[^@]+$">>), CS3 = kura_changeset:validate_length(CS2, username, [{min, 2}, {max, 50}]), CS4 = kura_changeset:unique_constraint(CS3, email), kura_changeset:unique_constraint(CS4, username). @@ -130,7 +130,7 @@ changeset_errors_to_json(#kura_changeset{errors = Errors}) -> Use it in controllers: ```erlang -create(#{params := Params}) -> +create(#{json := Params}) -> CS = post:changeset(#{}, Params), case blog_repo:insert(CS) of {ok, Post} -> diff --git a/src/production/pubsub.md b/src/production/pubsub.md index 89b57b6..33982b5 100644 --- a/src/production/pubsub.md +++ b/src/production/pubsub.md @@ -82,7 +82,7 @@ On connect, the handler joins both the `posts` and `comments` channels. Any pub/ Update the posts controller to broadcast on changes: ```erlang -create(#{params := Params}) -> +create(#{json := Params}) -> CS = post:changeset(#{}, Params), case blog_repo:insert(CS) of {ok, Post} -> diff --git a/src/testing-errors/testing.md b/src/testing-errors/testing.md index 0373d1b..3722fc7 100644 --- a/src/testing-errors/testing.md +++ b/src/testing-errors/testing.md @@ -136,15 +136,15 @@ Test your security functions directly: valid_login_test() -> Req = nova_test_req:new(post, "/login"), - Req1 = nova_test_req:with_json(#{<<"username">> => <<"admin">>, - <<"password">> => <<"password">>}, Req), + Req1 = Req#{params => #{<<"username">> => <<"admin">>, + <<"password">> => <<"password">>}}, ?assertMatch({true, #{authed := true, username := <<"admin">>}}, blog_auth:username_password(Req1)). invalid_password_test() -> Req = nova_test_req:new(post, "/login"), - Req1 = nova_test_req:with_json(#{<<"username">> => <<"admin">>, - <<"password">> => <<"wrong">>}, Req), + Req1 = Req#{params => #{<<"username">> => <<"admin">>, + <<"password">> => <<"wrong">>}}, ?assertEqual(false, blog_auth:username_password(Req1)). missing_params_test() ->