Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a fixture ActsAsTaggableOn with FactoryGirl?

How can i create a fixture for ActsAsTaggableOn::tag Using FactoryGirl ?

I tried :

/spec/factories/tags.rb

Factory.define ActsAsTaggableOn::Tag do |f|
  f.sequence(:name) { |n| "titre#{n}" }
end

/spec/controllers/books_controller.rb

it "should return 2 categories whith books" do

      fake_tag = Factory(:tag)
...

end

I get :

Failure/Error: fake_tag = Factory(:tag)
     ArgumentError:
       Factory not registered: tag

Thanks for your help, Vincent

like image 290
vdaubry Avatar asked Mar 03 '12 09:03

vdaubry


1 Answers

I guess you're using a quite old version of factory girl. I encourage you to switch to the latest version if you're able to.

Answering your question, I think you need something like:

Factory.define :tag, :class => ActsAsTaggableOn::Tag do |f|
  f.sequence(:name) { |n| "titre#{n}" }
end

Check the Factory 1.3 doc here. But as I told you before. Try to switch to a newer version.

like image 65
Fran Avatar answered Sep 19 '22 21:09

Fran