How to specify validates_uniqueness_of in rspec?

How to do it? Could not find examples on the Internet ... (using rspec 2.5.0and rails 3.0.5)

+5
source share
3 answers
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
+6
source

, , save update

@widget.save
#untested, but this should be close
@widget.errors.full_messages.include?("validation message you are looking for").should be true

, , , , , ( ). , Rails . .

0

All Articles