Skip to content

Commit

Permalink
Merge pull request stavro#88 from azhi/fix-filename-in-tests
Browse files Browse the repository at this point in the history
fix 'filename' spelling in all tests
  • Loading branch information
stavro authored May 10, 2018
2 parents 4dddcb9 + 3429c95 commit 8972a7d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule ArcTest.Ecto.Schema do
end

def build_upload(path) do
%{__struct__: Plug.Upload, path: path, file_name: Path.basename(path)}
%{__struct__: Plug.Upload, path: path, filename: Path.basename(path)}
end

test "supports :invalid changeset" do
Expand All @@ -58,40 +58,40 @@ defmodule ArcTest.Ecto.Schema do
assert cs.errors == [avatar: {"can't be blank", [validation: :required]}]
end

test_with_mock "cascades storage success into a valid change", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", file_name: "file.png"}, %TestUser{}}) -> {:ok, "file.png"} end] do
test_with_mock "cascades storage success into a valid change", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:ok, "file.png"} end] do
upload = build_upload("/path/to/my/file.png")
cs = TestUser.changeset(%TestUser{}, %{"avatar" => upload})
assert cs.valid?
%{file_name: "file.png", updated_at: _} = cs.changes.avatar
end

test_with_mock "cascades storage error into an error", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", file_name: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
test_with_mock "cascades storage error into an error", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
upload = build_upload("/path/to/my/file.png")
cs = TestUser.changeset(%TestUser{}, %{"avatar" => upload})
assert called DummyDefinition.store({upload, %TestUser{}})
assert cs.valid? == false
assert cs.errors == [avatar: {"is invalid", [type: ArcTest.Ecto.Schema.DummyDefinition.Type, validation: :cast]}]
end

test_with_mock "converts changeset into schema", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", file_name: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
test_with_mock "converts changeset into schema", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
upload = build_upload("/path/to/my/file.png")
TestUser.changeset(%TestUser{}, %{"avatar" => upload})
assert called DummyDefinition.store({upload, %TestUser{}})
end

test_with_mock "applies changes to schema", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", file_name: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
test_with_mock "applies changes to schema", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
upload = build_upload("/path/to/my/file.png")
TestUser.changeset(%TestUser{}, %{"avatar" => upload, "first_name" => "test"})
assert called DummyDefinition.store({upload, %TestUser{first_name: "test"}})
end

test_with_mock "converts atom keys", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", file_name: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
test_with_mock "converts atom keys", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:error, :invalid_file} end] do
upload = build_upload("/path/to/my/file.png")
TestUser.changeset(%TestUser{}, %{avatar: upload})
assert called DummyDefinition.store({upload, %TestUser{}})
end

test_with_mock "casting nil attachments", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", file_name: "file.png"}, %TestUser{}}) -> {:ok, "file.png"} end] do
test_with_mock "casting nil attachments", DummyDefinition, [store: fn({%{__struct__: Plug.Upload, path: "/path/to/my/file.png", filename: "file.png"}, %TestUser{}}) -> {:ok, "file.png"} end] do
changeset = TestUser.changeset(%TestUser{}, %{"avatar" => build_upload("/path/to/my/file.png")})
changeset = TestUser.changeset2(changeset, %{"avatar" => nil})
assert nil == Ecto.Changeset.get_field(changeset, :avatar)
Expand Down

0 comments on commit 8972a7d

Please sign in to comment.