Hi,

I'm a bit stuck with mocking a unit test of a join model with regards to a
validates_uniqueness_of clause.

I have

class Book < AR:B
 has_many :clippings
 various validates_presence_of etc
end

class Clip <  AR:B
 has_many :clippings
 various validates_presence_of etc
end

class Clipping < AR:B
 belongs_to :book
 belongs_to :clip

 validates_uniqueness_of :clip_id, :scope => :book_id
end

What I want to do is just confirm that the validates uniqueness_of clause is
set and functioning correctly in the spec for the clipping model.

So if I was using fixtures I would do something like

it "should not allow duplicate clips in the same book" do
 clip = clips( :some_clip )
 book = books( :some_book )

 lambda do
   clipping = Clipping.create( :clip => clip, :book => book )
 end.should change( Clipping, :count ).by( 1 )

 lambda do
   clipping = Clipping.create( :clip => clip, :book => )
   clipping.should_not be_valid
 end.should_not change( Clipping, :count )

end

Any hints as to how to do this without using fixtures?

Cheers
Daniel
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to