Skip to content
Open
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
30 changes: 1 addition & 29 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
import Config

# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# third-party users, it should be done in your "mix.exs" file.

# You can configure your application as:
#
# config :test_dispatch, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:test_dispatch, :key)
#
# You can also configure a third-party app:
#
# config :logger, level: :info
#
config :phoenix, :json_library, Jason

# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env()}.exs"
5 changes: 4 additions & 1 deletion lib/test_dispatch/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ defmodule TestDispatch.Form do

defp resolve_nested(key), do: String.split(key, ["[", "]"], trim: true)

@spec send_to_action(map() | Keyword.t(), binary(), Plug.Conn.t()) :: Plug.Conn.t()
def send_to_action(params, form, conn) do
endpoint = endpoint_module(conn)
method = get_method_of_form(form)
action = floki_attribute(form, "action")

action = floki_attribute(form, "action") || conn.request_path

dispatch(conn, endpoint, method, action, params)
end
Expand All @@ -131,6 +133,7 @@ defmodule TestDispatch.Form do
defp downcase(nil), do: nil
defp downcase(string), do: String.downcase(string)

@spec find_form(Plug.Conn.t(), binary() | Keyword.t() | tuple()) :: {binary(), atom()}
def find_form(%Plug.Conn{status: status} = conn, entity_or_test_selector)
when status in 200..299 or status == 401 do
conn
Expand Down
25 changes: 25 additions & 0 deletions test/test_dispatch/form_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule TestDispatch.FormTest do
use TestDispatch.ConnCase

@params %{
user: %{
roles: ["admin", "moderator"]
}
}
setup %{conn: conn} do
conn = Plug.Conn.put_private(conn, :phoenix_endpoint, @endpoint)
{:ok, conn: conn}
end

describe "#send_to_action/3" do
test "Send a request to the current path when no action is given", %{conn: conn} do
conn = get(conn, "/users/index")

form =
{"form", [{"method", "get"}],
[{"input", [{"name", "_method"}, {"type", "hidden"}, {"value", "get"}], []}]}

assert TestDispatch.Form.send_to_action(@params, form, conn).request_path == "/users/index"
end
end
end