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
| post "/db/factory" do | |
| # When piped through a generic Phoenix JSON API pipeline, using a route | |
| # like this allows you to call your factory via your test API easily. | |
| with {:ok, schema} <- Map.fetch(conn.body_params, "schema"), | |
| {:ok, attrs} <- Map.fetch(conn.body_params, "attributes") do | |
| db_schema = String.to_atom(schema) | |
| db_attrs = Enum.map(attrs, fn {k, v} -> {String.to_atom(k), v} end) | |
| db_entry = Factory.insert(db_schema, db_attrs) | |
| send_resp(conn, 200, Poison.encode!(%{id: db_entry.id})) |
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
| before(() => { | |
| // Before we run any tests, we reset our database. | |
| // We also check back in any open database connection. If you save a | |
| // test file, cypress will re-run the tests, not finishing the ones it | |
| // is currently running, so we might end up with a checked-out connection | |
| // lying around and blocking our database reset. | |
| cy.checkindb() | |
| cy.resetdb() | |
| }) |
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
| Cypress.Commands.add("resetdb", () => { | |
| cy.exec('docker-compose run myapp mix do ecto.drop, ecto.create, ecto.migrate') | |
| }) | |
| Cypress.Commands.add("checkoutdb", () => { | |
| cy.request('POST', '/api/end-to-end/db/checkout').as('checkoutDb') | |
| }) | |
| Cypress.Commands.add("checkindb", () => { | |
| cy.request('POST', '/api/end-to-end/db/checkin').as('checkinDb') |
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
| it ("shows email not confirmed notification in dashboard for unconfirmed user", () => { | |
| cy.factorydb('user', { | |
| username: "Sven Gehring", | |
| password: "password", | |
| email: "[email protected]" | |
| }) | |
| // This is another custom command we use for getting our auth token | |
| cy.login('[email protected]', 'password') |
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 PhxstaticWeb.Router do | |
| use PhxstaticWeb, :router | |
| pipeline :static do | |
| plug Plug.Static, | |
| at: "/static", | |
| from: {:phxstatic, "priv/test"} | |
| end | |
| scope "/", PhxstaticWeb do |
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 PhxstaticWeb.Router do | |
| use PhxstaticWeb, :router | |
| pipeline :static do | |
| plug Plug.Static, | |
| at: "/static", | |
| from: {:phxstatic, "priv/test"} | |
| end | |
| scope "/", PhxstaticWeb do |
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 Recursive do | |
| def function do | |
| function() | |
| 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
| defmodule Recursive do | |
| def function do | |
| receive do | |
| _ -> function() | |
| end | |
| 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
| defmodule Pragmatic do | |
| def supervisor(worker) do | |
| spawn_link(fn -> | |
| Process.flag(:trap_exit, true) | |
| worker_pid = spawn_link(worker) | |
| receive do | |
| {:EXIT, ^worker_pid, _} -> | |
| supervisor(worker) | |
| 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
| worker_function = fn -> | |
| :timer.sleep(1_000) | |
| IO.puts("completed at #{:erlang.system_time()}") | |
| end | |
| Pragmatic.supervisor(worker_function) | |
| #> completed at 1556621845035672000 | |
| #> completed at 1556621846038645599 | |
| #> completed at 1556621847039733259 |