Skip to content

Instantly share code, notes, and snippets.

@durran
Created January 20, 2010 04:56
Show Gist options
  • Select an option

  • Save durran/281621 to your computer and use it in GitHub Desktop.

Select an option

Save durran/281621 to your computer and use it in GitHub Desktop.
class Campaign
include Mongoid::Document
field :name
index :name, :unique => true
validates_presence_of :name
validates_uniqueness_of :name
end
describe Campaign do
context "validation" do
it "should validate uniqueness of name" do
campaign_a = Campaign.new(:name => 'Testing')
campaign_b = Campaign.new(:name => 'Testing')
campaign_a.save
campaign_b.valid?.should be_false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment