This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def update(conn, %{"id" => id, "user" => user_params}) do | |
user = Repo.get!(User, id) | |
changeset = User.changeset(user, user_params) | |
case Repo.update(changeset) do | |
{:ok, user} -> | |
conn | |
|> put_flash(:info, "User updated successfully.") | |
|> redirect(to: user_path(conn, :show, user)) | |
{:error, changeset} -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mix phoenix.new --no-html --no-brunch my_app | |
* creating my_app/config/config.exs | |
* creating my_app/config/dev.exs | |
* creating my_app/config/prod.exs | |
# ... more files here | |
* creating my_app/priv/static/js/phoenix.js | |
* creating my_app/priv/static/images/phoenix.png | |
* creating my_app/priv/static/favicon.ico | |
Fetch and install dependencies? [Yn] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.UserController.InviteTest do | |
use MyApp.ConnCase | |
test "inviting a user responds with the new user" do | |
conn = | |
build_conn | |
|> post("/users", email: "[email protected]") | |
body = conn |> response(201) |> Poison.decode! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.UserController.InviteTest do | |
use MyApp.ConnCase | |
test "inviting a user responds with the new user" do | |
conn = | |
build_conn | |
|> post("/users", email: "[email protected]") | |
body = conn |> response(201) |> Poison.decode! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mix test | |
... | |
1) test inviting a user responds with the new user (MyApp.UserController.InviteTest) | |
test/controllers/user_controller/invite_test.exs:4 | |
** (RuntimeError) expected response with status 201, got: 404, with body: | |
{"errors":{"detail":"Page not found"}} | |
stacktrace: | |
(phoenix) lib/phoenix/test/conn_test.ex:362: Phoenix.ConnTest.response/2 | |
test/controllers/user_controller/invite_test.exs:9: (test) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Router do | |
use MyApp.Web, :router | |
pipeline :api do | |
plug :accepts, ["json"] | |
end | |
scope "/", MyApp do | |
pipe_through :api |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mix test | |
Compiling 3 files (.ex) | |
... | |
1) test inviting a user responds with the new user (MyApp.UserController.InviteTest) | |
test/controllers/user_controller/invite_test.exs:4 | |
** (UndefinedFunctionError) function MyApp.UserController.init/1 is undefined (module MyApp.UserController is not available) | |
stacktrace: | |
MyApp.UserController.init(:create) | |
(my_app) web/router.ex:1: anonymous fn/1 in MyApp.Router.match_route/4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.UserController do | |
use MyApp.Web, :controller | |
def create(conn, _params) do | |
conn | |
|> resp(201, "{}") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body = conn |> response(201) |> Poison.decode! | |
assert body["id"] > 0 | |
assert body["email"] == "[email protected]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mix test | |
Compiling 1 file (.ex) | |
Generated my_app app | |
... | |
1) test inviting a user responds with the new user (MyApp.UserController.InviteTest) | |
test/controllers/user_controller/invite_test.exs:4 | |
Assertion with == failed | |
code: body["email"] == "[email protected]" | |
lhs: nil |
OlderNewer