Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/appendix/cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/building-api/advanced-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -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} ->
Expand Down
4 changes: 2 additions & 2 deletions src/data-layer/changesets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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} ->
Expand Down
2 changes: 1 addition & 1 deletion src/production/pubsub.md
Original file line number Diff line number Diff line change
Expand Up @@ -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} ->
Expand Down
8 changes: 4 additions & 4 deletions src/testing-errors/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() ->
Expand Down