From 15bc25ea2470eede0e8e8c3c8399fad2de1f11cd Mon Sep 17 00:00:00 2001 From: John Mileham Date: Wed, 23 Feb 2011 13:19:02 -0500 Subject: [PATCH] Tests to verify failure behavior when an attribute is not included in the readonly set. --- .../have_readonly_attributes_matcher_spec.rb | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb b/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb index baa77989..0357a6c2 100644 --- a/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb +++ b/spec/shoulda/active_record/have_readonly_attributes_matcher_spec.rb @@ -15,15 +15,34 @@ describe Shoulda::Matchers::ActiveRecord::HaveReadonlyAttributeMatcher do end end - context "an attribute that can be set after being saved" do + context "an attribute not included in the readonly set" do + before do + define_model :example, :attr => :string, :other => :string do + attr_readonly :other + end + @model = Example.new + end + + it "should not accept being read-only" do + @model.should_not have_readonly_attribute(:attr) + end + end + + context "an attribute on a class with no readonly attributes" do before do define_model :example, :attr => :string @model = Example.new end - it "should accept being read-only" do + it "should not accept being read-only" do @model.should_not have_readonly_attribute(:attr) end + + it "should assign a failure message" do + matcher = have_readonly_attribute(:attr) + matcher.matches?(@model).should == false + matcher.failure_message.should_not be_nil + end end end