[rspec-users] How To Express Change of Associated Data

s.ross cwdinfo at gmail.com
Sun Jul 6 17:43:07 EDT 2008


I'm not sure if I'm pushing too far out of specing a given model, but  
here's what I want to express:

class A < AR::Base
   has_many :bs

   def okay(segment)

class B < AR::Base
   belongs_to :a

it A, "should increase the vote count for a given segment if okayed" do
   @a = A.create(stuff)
   @a.okay(10) # okay segment 10
   # here's where I'm having trouble...
   # a.bs should have one row, and it should have a segment number of  
10 and various other stuff should happen
   # subsequent @a.okay with different values should transform numbers  
in a predictable way. This is handled in
   # the A model because the transforms occur only in Bs that belong  
to a given A.
   @a.bs.find_by_segment_number(10).thingie.should be(1)  # not too  
   @a.bs.find_by_segment_number(9).thingie.should be(1)  # still not  
too expressive
   @a.bs. find_by_segment_number(9).transformed_thingie.should  

This kind of spec smells to me, yet I am having trouble figuring out  
how to explain, using rspec, exactly what the behavior is to be in a  
multi-step sequence.

Anybody have thoughts regarding how this might be done better?


More information about the rspec-users mailing list