Created
September 10, 2011 04:44
-
-
Save stuliston/1207931 to your computer and use it in GitHub Desktop.
Testing HABTM with rspec and factory girl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe "Artists to releases relationship" do | |
before(:all) do | |
@kanye = FactoryGirl.create(:artist, :name => 'Kanye West') | |
@jz = FactoryGirl.create(:artist, :name => 'Jay Z') | |
@watch_the_throne = FactoryGirl.create(:release, :name => 'Watch the Throne') | |
@dropout = FactoryGirl.create(:release, :name => 'The College Dropout') | |
end | |
it "should recognise when an artist has no releases" do | |
@kanye.releases.count.should == 0 | |
end | |
it "should handle an artist with a release" do | |
@kanye.releases << @dropout | |
@kanye.releases.count.should == 1 | |
end | |
# (testing 2-way fixup) | |
it "should automatically know a release's artist" do | |
@kanye.releases << @dropout | |
@dropout.artists.count.should == 1 | |
end | |
it "should hanlde an artist collaboration" do | |
@kanye.releases << @watch_the_throne | |
@jz.releases << @watch_the_throne | |
@watch_the_throne.artists.count.should == 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did a similar implementation. Except in my case artist = user and release = team.
Following is my method that is similar to your test at line 27.
The problem is that the test is failing with the following error.
associations are working as expected through the rails console. Do you, by any chance, have ideas as to why this is happening?