Add locale to the path

pull/2/head
Doc Ritezel 7 years ago committed by CJ Bryan and Matt Olenick
parent 1f35823aa9
commit 6cf05ae1aa
  1. 3
      config/config.exs
  2. 12
      lib/explorer_web/router.ex
  3. 5
      mix.exs
  4. 1
      mix.lock
  5. 15
      test/explorer_web/controllers/page_controller_test.exs
  6. 4
      test/explorer_web/features/contributor_browsing_test.exs

@ -9,6 +9,9 @@ use Mix.Config
config :explorer, config :explorer,
ecto_repos: [Explorer.Repo] ecto_repos: [Explorer.Repo]
# Configures gettext
config :explorer, ExplorerWeb.Gettext, locales: ~w(en), default_locale: "en"
# Configures the endpoint # Configures the endpoint
config :explorer, ExplorerWeb.Endpoint, config :explorer, ExplorerWeb.Endpoint,
url: [host: "localhost"], url: [host: "localhost"],

@ -7,6 +7,7 @@ defmodule ExplorerWeb.Router do
plug :fetch_flash plug :fetch_flash
plug :protect_from_forgery plug :protect_from_forgery
plug :put_secure_browser_headers plug :put_secure_browser_headers
plug SetLocale, gettext: ExplorerWeb.Gettext, default_locale: "en"
end end
pipeline :api do pipeline :api do
@ -14,13 +15,12 @@ defmodule ExplorerWeb.Router do
end end
scope "/", ExplorerWeb do scope "/", ExplorerWeb do
pipe_through :browser # Use the default browser stack pipe_through :browser
get "/", PageController, :dummy
end
scope "/:locale", ExplorerWeb do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index get "/", PageController, :index
end end
# Other scopes may use custom stacks.
# scope "/api", ExplorerWeb do
# pipe_through :api
# end
end end

@ -29,8 +29,8 @@ defmodule Explorer.Mixfile do
defp elixirc_paths(_), do: ["lib"] defp elixirc_paths(_), do: ["lib"]
# Specifies extra applications to start per environment # Specifies extra applications to start per environment
defp extra_applications(:prod), do: [:logger, :runtime_tools, :phoenix_pubsub_redis, :new_relixir] defp extra_applications(:prod), do: [:set_locale, :logger, :runtime_tools, :phoenix_pubsub_redis, :new_relixir]
defp extra_applications(_), do: [:logger, :runtime_tools] defp extra_applications(_), do: [:set_locale, :logger, :runtime_tools]
# Specifies your project dependencies. # Specifies your project dependencies.
# #
@ -50,6 +50,7 @@ defmodule Explorer.Mixfile do
{:phoenix_pubsub, "~> 1.0"}, {:phoenix_pubsub, "~> 1.0"},
{:phoenix_pubsub_redis, "~> 2.1.0", only: [:prod]}, {:phoenix_pubsub_redis, "~> 2.1.0", only: [:prod]},
{:postgrex, ">= 0.0.0"}, {:postgrex, ">= 0.0.0"},
{:set_locale, github: "minifast/set_locale", branch: "master"}, # Waiting on https://github.com/smeevil/set_locale/pull/9
{:wallaby, "~> 0.19.2", only: [:test], runtime: false}, {:wallaby, "~> 0.19.2", only: [:test], runtime: false},
] ]
end end

@ -31,6 +31,7 @@
"ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"}, "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"},
"redix": {:hex, :redix, "0.6.1", "20986b0e02f02b13e6f53c79a1ae70aa83147488c408f40275ec261f5bb0a6d0", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"}, "redix": {:hex, :redix, "0.6.1", "20986b0e02f02b13e6f53c79a1ae70aa83147488c408f40275ec261f5bb0a6d0", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"redix_pubsub": {:hex, :redix_pubsub, "0.4.1", "26e6a69129072ac2226be49139019bdf951bb1e9e210a773c1372acf88100936", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:redix, "~> 0.6.0", [hex: :redix, repo: "hexpm", optional: false]}], "hexpm"}, "redix_pubsub": {:hex, :redix_pubsub, "0.4.1", "26e6a69129072ac2226be49139019bdf951bb1e9e210a773c1372acf88100936", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:redix, "~> 0.6.0", [hex: :redix, repo: "hexpm", optional: false]}], "hexpm"},
"set_locale": {:git, "https://github.com/minifast/set_locale.git", "da9ae029642bc0fbd9212c2aaf86c0adca70c084", [branch: "master"]},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [:rebar3], [], "hexpm"},
"wallaby": {:hex, :wallaby, "0.19.2", "358bbff251e3555e02566280d1795132da792969dd58ff89963536d013058719", [:mix], [{:httpoison, "~> 0.12", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm"}} "wallaby": {:hex, :wallaby, "0.19.2", "358bbff251e3555e02566280d1795132da792969dd58ff89963536d013058719", [:mix], [{:httpoison, "~> 0.12", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm"}}

@ -1,22 +1,29 @@
defmodule ExplorerWeb.PageControllerTest do defmodule ExplorerWeb.PageControllerTest do
use ExplorerWeb.ConnCase use ExplorerWeb.ConnCase
describe "GET index/2" do describe "GET index/2 without a locale" do
test "returns a welcome message", %{conn: conn} do test "redirects to the en locale", %{conn: conn} do
conn = get conn, "/" conn = get conn, "/"
assert redirected_to(conn) == "/en"
end
end
describe "GET index/2 with a locale" do
test "returns a welcome message", %{conn: conn} do
conn = get conn, "/en"
assert html_response(conn, 200) =~ "Welcome" assert html_response(conn, 200) =~ "Welcome"
end end
test "returns a block", %{conn: conn} do test "returns a block", %{conn: conn} do
block = insert(:block, %{number: 23}) block = insert(:block, %{number: 23})
conn = get conn, "/" conn = get conn, "/en"
assert(List.first(conn.assigns.blocks) == block) assert(List.first(conn.assigns.blocks) == block)
end end
test "excludes all but the most recent five blocks", %{conn: conn} do test "excludes all but the most recent five blocks", %{conn: conn} do
old_block = insert(:block) old_block = insert(:block)
insert_list(5, :block) insert_list(5, :block)
conn = get conn, "/" conn = get conn, "/en"
refute(Enum.member?(conn.assigns.blocks, old_block)) refute(Enum.member?(conn.assigns.blocks, old_block))
end end
end end

@ -6,8 +6,10 @@ defmodule ExplorerWeb.UserListTest do
@logo css("img.header__logo") @logo css("img.header__logo")
test "browses the home page", %{session: session} do test "browses the home page", %{session: session} do
session |> visit("/")
assert current_path(session) == "/en"
session session
|> visit("/")
|> assert_has(css(".header__title", text: "POA Network Explorer")) |> assert_has(css(".header__title", text: "POA Network Explorer"))
|> click(@logo) |> click(@logo)
|> assert_has(css("main", text: "Welcome to our blockchain explorer.")) |> assert_has(css("main", text: "Welcome to our blockchain explorer."))

Loading…
Cancel
Save