~sbaildon/yemma

yemma/test/test_helper.exs -rw-r--r-- 2.7 KiB
38e5b1faSean Baildon user_settings_url with conn 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Application.put_env(:yemma, Phoenix.YemmaTest.Endpoint,
  url: [host: "localhost", port: 4001],
  secret_key_base: "LQLOmWs21foxaxwrEH+7lmarzFHYaAULHBl5pzdoFeZtEo/+wN0SAH0XAdkxz9i0",
  live_view: [signing_salt: "FaCYJ5ez"],
  render_errors: [view: Phoenix.YemmaTest.ErrorView],
  check_origin: false,
  pubsub_server: Phoenix.YemmaTest.PubSub
)

YemmaTest.Repo.start_link()
Ecto.Adapters.SQL.Sandbox.mode(YemmaTest.Repo, :manual)

defmodule Phoenix.YemmaTest.User do
  use Yemma.Users.User,
    primary_key: {:id, :string, autogenerate: {Ecto.UUID, :autogenerate, []}}
end

defmodule Phoenix.YemmaTest.UserToken do
  use Yemma.Users.UserToken,
    primary_key: {:id, :string, autogenerate: {Ecto.UUID, :autogenerate, []}},
    foreign_key_type: :string
end

defmodule Phoenix.YemmaTest.ErrorView do
  use Phoenix.View, root: "test/templates"

  def template_not_found(template, _assigns) do
    Phoenix.Controller.status_message_from_template(template)
  end
end

defmodule Phoenix.YemmaTest.Endpoint do
  use Phoenix.Endpoint, otp_app: :yemma

  plug Plug.Session,
    store: :cookie,
    key: "_live_view_key",
    signing_salt: "+6VTmn3nCp3U"

  plug Phoenix.YemmaTest.Router
end

defmodule Phoenix.YemmaTest.PageController do
  use YemmaWeb, :controller

  def index(conn, _params) do
    text(conn, "blank page")
  end
end

defmodule Phoenix.YemmaTest.Router do
  use Phoenix.Router

  import Yemma,
    only: [
      redirect_if_user_is_authenticated: 2,
      require_authenticated_user: 2,
      fetch_current_user: 2,
      prepare_yemma: 2
    ]

  pipeline :browser do
    plug :fetch_session
    plug :fetch_flash
    plug :fetch_query_params
    plug :fetch_current_user
  end

  pipeline :yemma do
    plug :prepare_yemma
  end

  scope "/", Phoenix.YemmaTest do
    pipe_through [:browser]

    get "/", PageController, :index
  end

  scope "/", YemmaWeb do
    pipe_through [:yemma, :browser, :redirect_if_user_is_authenticated]

    get "/sign_in", UserSessionController, :new
    get "/register", UserSessionController, :new, private: %{yemma_template: "register.html"}
    post "/sign_in", UserSessionController, :create
  end

  scope "/", YemmaWeb do
    pipe_through [:yemma, :browser, :require_authenticated_user]

    get "/settings", UserSettingsController, :edit
    put "/settings", UserSettingsController, :update
    get "/settings/confirm_email/:token", UserSettingsController, :confirm_email
  end

  scope "/", YemmaWeb do
    pipe_through [:yemma, :browser]

    delete "/log_out", UserSessionController, :delete
    get "/confirm/:token", UserConfirmationController, :edit
  end
end

Supervisor.start_link(
  [
    {Phoenix.PubSub, name: Phoenix.YemmaTest.PubSub, adapter: Phoenix.PubSub.PG2},
    Phoenix.YemmaTest.Endpoint
  ],
  strategy: :one_for_one
)

ExUnit.start()