Bettermeans Introduction
Ruby, PHP, MySql, Software engineering and more.
I wanted to test 'validates_uniqueness_of' for this model:
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
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 |