Created
November 20, 2010 20:21
-
-
Save rtacconi/708121 to your computer and use it in GitHub Desktop.
Test unique attributes with RSpec and accept_values_for, a custom matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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