-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ex_machina integration #33
Comments
@asiniy try use |
I'm getting this kind of error: 1) test GET index lists reviews marked as unappropriate (MyReelty.Admin.UnappropriateControllerTest)
test/controllers/admin/unappropriate_controller_test.exs:26
** (FunctionClauseError) no function clause matching in Ecto.DateTime.to_erl/1
stacktrace:
(ecto) lib/ecto/date_time.ex:615: Ecto.DateTime.to_erl(nil)
(arc_ecto) lib/arc_ecto/type.ex:20: Arc.Ecto.Type.dump/2
(ecto) lib/ecto/query/planner.ex:29: anonymous fn/6 in Ecto.Query.Planner.fields/4
(stdlib) lists.erl:1262: :lists.foldl/3
(ecto) lib/ecto/query/planner.ex:21: Ecto.Query.Planner.fields/4
(ecto) lib/ecto/repo/schema.ex:449: Ecto.Repo.Schema.dump_changes/5
(ecto) lib/ecto/repo/schema.ex:77: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/repo/schema.ex:477: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/9
(ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
(ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
(ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
(ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3
(ecto) lib/ecto/repo/schema.ex:14: Ecto.Repo.Schema.insert!/4
(ex_machina) lib/ex_machina/ecto.ex:157: ExMachina.Ecto.save_record/3
test/controllers/admin/unappropriate_controller_test.exs:11: MyReelty.Admin.UnappropriateControllerTest.__ex_unit_setup_1/1
test/controllers/admin/unappropriate_controller_test.exs:1: MyReelty.Admin.UnappropriateControllerTest.__ex_unit__/2 |
@asiniy which version of |
@gullitmiranda updated to 1) test GET index lists reviews marked as unappropriate (MyReelty.Admin.UnappropriateControllerTest)
test/controllers/admin/unappropriate_controller_test.exs:26
** (FunctionClauseError) no function clause matching in Arc.Ecto.Type.dump/2
stacktrace:
(arc_ecto) lib/arc_ecto/type.ex:19: Arc.Ecto.Type.dump(MyReelty.Video, %{file_name: "test/fixtures/sample.mp4"})
(ecto) lib/ecto/query/planner.ex:29: anonymous fn/6 in Ecto.Query.Planner.fields/4
(stdlib) lists.erl:1262: :lists.foldl/3
(ecto) lib/ecto/query/planner.ex:21: Ecto.Query.Planner.fields/4
(ecto) lib/ecto/repo/schema.ex:449: Ecto.Repo.Schema.dump_changes/5
(ecto) lib/ecto/repo/schema.ex:77: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
(ecto) lib/ecto/repo/schema.ex:477: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/9
(ecto) lib/ecto/pool.ex:292: Ecto.Pool.with_rollback/3
(ecto) lib/ecto/adapters/sql.ex:582: Ecto.Adapters.SQL.transaction/8
(ecto) lib/ecto/pool.ex:244: Ecto.Pool.outer_transaction/6
(ecto) lib/ecto/adapters/sql.ex:551: Ecto.Adapters.SQL.transaction/3
(ecto) lib/ecto/repo/schema.ex:14: Ecto.Repo.Schema.insert!/4
(ex_machina) lib/ex_machina/ecto.ex:157: ExMachina.Ecto.save_record/3
test/controllers/admin/unappropriate_controller_test.exs:11: MyReelty.Admin.UnappropriateControllerTest.__ex_unit_setup_1/1
test/controllers/admin/unappropriate_controller_test.exs:1: MyReelty.Admin.UnappropriateControllerTest.__ex_unit__/2 My factory: def factory(:review) do
%MyReelty.Review{
city: "Las Vegas",
state: "Nevada",
country: "USA",
address: "11th avenue",
thumbnail_type: "screenshot",
zipcode: 1234,
video: %{ file_name: "test/fixtures/sample.mp4", updated_at: nil },
}
end |
it seems that the |
It's modern. video: %{ file_name: "test/fixtures/sample.mp4", updated_at: Ecto.DateTime.now }, solved the problem |
|
@fatbotdesigns replace |
Hi @stavro, I did that and got the following error: Looking at your code:
All them doesn't work. :( |
Have you tried?
What is in your article_test.exs ? |
@ArturT tried that already. that was the first I thing I tried |
@fatbotdesigns The problem is because you have The Arc expects the Here is how I'm doing it: valid_attrs = {file: %Plug.Upload{path: "test/fixtures/attachment.pdf", filename: "attachment.pdf"}
changeset = Article.changeset(%Article{}, valid_attrs)
assert changeset.valid?
|
I tried many versions of this. Basically just wanted to create an Line 7 in a30a3db
defmodule MyApp.AssetFactory do
defmacro __using__(_opts) do
quote do
def asset_factory do
%MyApp.Asset{
attachment: %{
"file_name" => "test.png",
"updated_at" => Ecto.DateTime.utc()
}
}
end
end
end
end |
@nsweeting Nice! However, I noticed that under certain circumstances ex_machina still converts the string keys to atoms internally before casting, so %{file_name: "test.png", updated_at: #Ecto.DateTime<2018-03-23 14:40:49>} which fails to match the pattern and makes the test crash. Could this be solved by making def cast(_definition, %{file_name: file, updated_at: updated_at}) do
In fact, the inverse seems to happen for (cc @stavro) |
This helps with ex_machina integration (see stavro#33).
ex_machina is a de-facto standard for pre-building models in ExUnit. Unfortunately, I can't force it to work with
arc_ecto
. I'm not sure why:And exception:
Is there any plans for further
ex_machina
integration? Thanks!The text was updated successfully, but these errors were encountered: