Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mock_model.respond_to?(xxx_before_type_cast) returns false

- Closes #266.
  • Loading branch information...
commit 9ad6bedfdd79476e7fd8909e5632457e7033ca00 1 parent e0f80df
@dchelimsky dchelimsky authored
View
4 lib/rspec/rails/mocks.rb
@@ -15,6 +15,10 @@ def as_new_record
def persisted?
true
end
+
+ def respond_to?(message)
+ message.to_s =~ /_before_type_cast$/ ? false : super
+ end
end
module ActiveRecordInstanceMethods
View
30 spec/rspec/rails/mocks/mock_model_spec.rb
@@ -144,11 +144,27 @@
MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
@model = mock_model(MockableModel)
end
- it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
- @model.respond_to?("column_a").should be(true)
+ context "without as_null_object" do
+ it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
+ @model.respond_to?("column_a").should be(true)
+ end
+ it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
+ @model.respond_to?("column_c").should be(false)
+ end
+ it "says it will not respond_to?(xxx_before_type_cast)" do
+ @model.respond_to?("title_before_type_cast").should be(false)
+ end
end
- it "does not say it will respond_to?(key) if RealModel does not have the attribute 'key'" do
- @model.respond_to?("column_c").should be(false)
+ context "with as_null_object" do
+ it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
+ @model.as_null_object.respond_to?("column_a").should be(true)
+ end
+ it "says it will respond_to?(key) even if RealModel does not have the attribute 'key'" do
+ @model.as_null_object.respond_to?("column_c").should be(true)
+ end
+ it "says it will not respond_to?(xxx_before_type_cast)" do
+ @model.as_null_object.respond_to?("title_before_type_cast").should be(false)
+ end
end
end
@@ -157,6 +173,12 @@
model = NonActiveRecordModel.new
model.should respond_to(:to_param)
end
+ context "with as_null_object" do
+ it "says it will not respond_to?(xxx_before_type_cast)" do
+ model = NonActiveRecordModel.new.as_null_object
+ model.respond_to?("title_before_type_cast").should be(false)
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.