Giter Club home page Giter Club logo

Comments (15)

asiniy avatar asiniy commented on August 29, 2024 2

It's modern.

video:           %{ file_name: "test/fixtures/sample.mp4", updated_at: Ecto.DateTime.now },

solved the problem

from arc_ecto.

gullitmiranda avatar gullitmiranda commented on August 29, 2024

@asiniy try use %{file_name: "sample.mp4", updated_at: nil}

from arc_ecto.

asiniy avatar asiniy commented on August 29, 2024

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

from arc_ecto.

gullitmiranda avatar gullitmiranda commented on August 29, 2024

@asiniy which version of arc_ecto are you using?

from arc_ecto.

asiniy avatar asiniy commented on August 29, 2024

@gullitmiranda updated to 0.4.2. Now I have

  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

from arc_ecto.

gullitmiranda avatar gullitmiranda commented on August 29, 2024

it seems that the ex_machina is removing the field updated_at. By chance the :ex_machina is this outdated?

from arc_ecto.

ArturT avatar ArturT commented on August 29, 2024

Ecto.DateTime.now is not available anymore. You can use Ecto.DateTime.utc.

from arc_ecto.

cubeguerrero avatar cubeguerrero commented on August 29, 2024

Hi,

I tried using

video: %{ file_name: "test/fixtures/sample.mp4", updated_at: Ecto.DateTime.now },

and I'm getting the following error:
screen shot 2017-03-12 at 10 31 55 am

My mix.exs
screen shot 2017-03-12 at 10 33 31 am

Anyone also encountering the same error?

from arc_ecto.

stavro avatar stavro commented on August 29, 2024

@fatbotdesigns replace file_name with filename

from arc_ecto.

cubeguerrero avatar cubeguerrero commented on August 29, 2024

Hi @stavro,

I did that and got the following error:
screen shot 2017-03-12 at 3 13 03 pm

Looking at your code:
I also tried passing:

  • %{filename: "file.jpg", binary: "something"}
  • %{filename: "file.jpg", path: "some/path"}
  • some/path
  • http://example.com/someimage.jpg -> this causes the test to timeout.

All them doesn't work. :(

from arc_ecto.

ArturT avatar ArturT commented on August 29, 2024

Have you tried?

video: %{ file_name: "test/fixtures/sample.mp4", updated_at: Ecto.DateTime.utc },

What is in your article_test.exs ?

from arc_ecto.

cubeguerrero avatar cubeguerrero commented on August 29, 2024

@ArturT tried that already. that was the first I thing I tried

my article_test has the following:
screen shot 2017-03-12 at 3 50 22 pm

My factory.exs has the following
screen shot 2017-03-12 at 3 51 11 pm

from arc_ecto.

ArturT avatar ArturT commented on August 29, 2024

@fatbotdesigns The problem is because you have insert(:article) and the result of it is passed to Article.changeset.

The Arc expects the %Plug.Upload{}
https://github.com/stavro/arc/blob/master/lib/arc/file.ex#L39

Here is how I'm doing it:
Note there is filename instead of file_name and there is path instead of updated_at.

valid_attrs = {file: %Plug.Upload{path: "test/fixtures/attachment.pdf", filename: "attachment.pdf"}
changeset = Article.changeset(%Article{}, valid_attrs)
assert changeset.valid?

from arc_ecto.

nsweeting avatar nsweeting commented on August 29, 2024

I tried many versions of this. Basically just wanted to create an asset record without storing anything. As per the cast function:

def cast(_definition, %{"file_name" => file, "updated_at" => updated_at}) do
- only thing that ended up working for me within the actual factory file was:

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

from arc_ecto.

richeterre avatar richeterre commented on August 29, 2024

@nsweeting Nice! However, I noticed that under certain circumstances ex_machina still converts the string keys to atoms internally before casting, so cast/2 receives this:

%{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 arc_ecto also match on atom keys, like so:

def cast(_definition, %{file_name: file, updated_at: updated_at}) do

In fact, the inverse seems to happen for Arc.Ecto.Type.dump/2, which is called with string keys by ex_machina when trying to pass an existing struct as an association to a factory. It all works if both cast/2 and dump/2 match both string and atom keys, but would this be too hacky to add?

(cc @stavro)

from arc_ecto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.