Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Created November 20, 2010 20:21
Show Gist options
  • Save rtacconi/708121 to your computer and use it in GitHub Desktop.
Save rtacconi/708121 to your computer and use it in GitHub Desktop.
Test unique attributes with RSpec and accept_values_for, a custom matcher
class CourseItem < ActiveRecord::Base
validates_presence_of :course_id, :day, :url
validates_uniqueness_of :course_id, :scope => :day, :message => "- this day has been already created."
end
describe CourseItem do
# check uniqueness using this matcher https://github.com/bogdan/accept_values_for
context "should create one item per day and per course only" do
before do
CourseItem.create! :day => 1, :course_id => 1, :url => '/courses/index.html'
end
it { should_not accept_values_for(:day => 1, :course_id => 1) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment