Skip to content

Instantly share code, notes, and snippets.

@dnszero
Created May 10, 2014 00:19
Show Gist options
  • Save dnszero/ba70116663970a828ce9 to your computer and use it in GitHub Desktop.
Save dnszero/ba70116663970a828ce9 to your computer and use it in GitHub Desktop.
Rails, FactoryGirl, and has_and_belongs_to_many
When testing has_and_belongs_to_many models using rspec and factory girl you should setup your factory the following way:
FactoryGirl.define do
factory :foo do
name "Foo"
end
factory :bar do
name "Bar"
foos { |a| [a.association(:foo)] }
end
end
credit: https://coderwall.com/p/o5yssw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment