Cannot sum and pass it as argument in FactoryGirl

119 views Asked by At

This is the code that is causing the error (FactoryGirl::Declaration::Static can't be coerced into Fixnum).

factory :detail do
    k ["book","tvserie","movie"].sample
    rc rand(1400000)
    r 1+rand(10)+rand.round(1)
    g generate_genres(self)
end

How can I sum and pass it as argument to the factory attribute?

Thanks.

1

There are 1 answers

0
Joe Essey On

Try putting the code to be executed in a block.

factory :detail do
    k { ["book","tvserie","movie"].sample }
    rc { rand(1400000) }
    r { 1+rand(10)+rand.round(1) }
    g { generate_genres(self) }
end

I'd also expect you'd need to specify the class for generate_genres(self) unless that method is defined in the factory. That's a technique I'm not familiar with.