Skip to content

Commit

Permalink
Add tests for to_form :action
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Mar 1, 2024
1 parent afc1798 commit 3b72a08
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/phoenix_ecto/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ defmodule PhoenixEcto.HTMLTest do
assert f.params == %{}
assert f.hidden == []
assert f.options == [method: "post"]
assert f.action == nil
assert f.source.action == nil
end

test "to_form :action option sets changeset action" do
changeset =
%User{}
|> cast(%{}, ~w()a)
|> validate_length(:name, min: 3)
|> Map.put(:action, :validate)

assert changeset.action == :validate
f = to_form(changeset, action: :insert)
assert f.action == :insert
assert f.source.action == :insert
end

test "to_form without :action option uses changeset action" do
changeset =
%User{}
|> cast(%{}, ~w()a)
|> validate_length(:name, min: 3)
|> Map.put(:action, :insert)

assert changeset.action == :insert
f = to_form(changeset)
assert f.action == :insert
assert f.source.action == :insert
end

test "with loaded changeset" do
Expand Down

0 comments on commit 3b72a08

Please sign in to comment.