Revision: 42360
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 3, 2011 21:46 by widescape
Initial Code
class Post < ActiveRecord::Base
validates_presence_of :title
validates_presence_of :publishing_date, :if => :published
end
class PostTest < ActiveSupport::TestCase
context "Post that is NOT going to be published" do
should validate_presence_of(:title)
should_not validate_presence_of(:publishing_date)
end
context "Post that is going to be published" do
subject do
Post.new(:title => 'Valid Title', :published => true)
end
should validate_presence_of(:publishing_date)
end
end
Initial URL
Initial Description
Initial Title
Shoulda with TestUnit: Conditional Validation using Shoulda/Subject
Initial Tags
validation
Initial Language
Rails