samedi 15 août 2015

Undefined method for factory_girl transient attributes

I'm working on a rails 3 (rails (3.2.13)) application and I am using factory_girl_rails (4.5.0) with rspec (2.13.0).

I have a delivery factory that looks like this

FactoryGirl.define do

  factory :delivery do

    trait :assigned do
      delivery_type 1
    end

    trait :started do
      delivery_type 2
    end

    factory :delivery_with_jobs do

      ignore do
        jobs_count = 2
        duration = 10
      end

      after(:create) do |delivery, evaluator|
        create_list(:job, evaluator.jobs_count, delivery: delivery, client: delivery.client)
      end
    end
  end
end

which i try to instantiate in my specs like this

let!(:delivery_with_jobs) {
        FactoryGirl.create(
            :delivery_with_jobs,
            :started,
            jobs_count: 3,
            user: user,
            current_user: user,
            account: user.account,
            client: client
        )
      }

The thing is I keep getting NoMethodError: undefined method 'jobs_count' for #<FactoryGirl::SyntaxRunner:0x000000079e5f00> when running tests and also when trying to create the factory in the rails console. I was on a lower version of factory_girl first and found this post. So I have tried to change the keyword to ignore which didn't help, so I have tried to upgrade factory girl which also didn't help.

I also get the same error when I omit the jobs_count parameter from FactoryGirl.create(:delivery_with_jobs).

Am I doing something wrong? Do you have any suggestions on what could be the cause of this issue?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire