[rspec-users] Mock or Stub strategy for validates_uniqueness_of
Daniel N
has.sox at gmail.com
Tue Jul 24 09:07:30 EDT 2007
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070724/d3118a91/attachment-0001.html
More information about the rspec-users
mailing list