[rspec-users] Testing has_many :through

s.ross cwdinfo at gmail.com
Tue Dec 12 19:48:45 EST 2006


I'm working with a has_many :through association, where a Member  
has_many Projects through ProjectViewers. The problem I'm running  
into is that Rails doesn't load the association so line (3) fails  
until I explicitly access a member of the collection (in this case, I  
iterated it). Is there a better way?

Thanks,

Steve

1. assigns[:member].should_not_be_nil
2. assigns[:member].projects.each{|p| puts "project #{p.name}"}  #  
force association to be loaded
3. assigns[:member].projects.size.should_be 1




More information about the rspec-users mailing list