Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to spec validates_uniqueness_of in Rspec?

How does one do this? Couldn't find any examples online... (using rspec 2.5.0 & rails 3.0.5)

like image 997
neezer Avatar asked Mar 11 '11 16:03

neezer


2 Answers

Found it in shoulda-matchers: http://rubydoc.info/github/thoughtbot/shoulda-matchers/master/frames

like image 69
neezer Avatar answered Jan 03 '23 19:01

neezer


before(:each) do
  @attr = { :bar => "foobar" }
end

it "should reject duplicate bar" do
  Foo.create!(@attr)
  duplicate_bar = Foo.new(@attr)
  duplicate_bar.should_not be_valid
end
like image 29
Toady00 Avatar answered Jan 03 '23 17:01

Toady00