Read more

Use Shoulda's validate_uniqueness_of matcher correctly

Henning Koch
September 08, 2010Software engineer at makandra GmbH

Works without requiring an initial record in modern versions.

This raises "Could not find first Keyword":

describe Keyword do
  it { should validate_uniqueness_of(:text) }
end
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Do this instead:

describe Keyword do

  it 'should have a unique #text' do
    Keyword.make
    should validate_uniqueness_of(:text)
  end

end

This is the intended behavior.

Posted by Henning Koch to makandra dev (2010-09-08 16:44)