Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

if singletons belong to the contract, test them

Object#respond_to? returns singletons and thus we inherit that contract.
The implementation of the predicate is good, but the test is only
checking boolean semantics, which in this case is not enough.
  • Loading branch information...
commit 0400a7ff574f83f2f5d5c3f7d7569bfb37963dda 1 parent d32ef7c
@fxn fxn authored
View
2  activerecord/lib/active_record/attribute_methods.rb
@@ -167,7 +167,7 @@ def respond_to?(name, include_private = false)
self.class.define_attribute_methods unless self.class.attribute_methods_generated?
result = super
- # If the result is false then it means this method is not supported by ActiveModel too
+ # If the result is false the answer is false.
return false unless result
# If the result is true then check for the select case.
View
5 activerecord/test/cases/relation_test.rb
@@ -186,8 +186,11 @@ def test_relation_merging_with_merged_joins
end
def test_respond_to_for_non_selected_element
+ post = Post.select(:title).first
+ assert_equal false, post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception"
+
post = Post.select("'title' as post_title").first
- assert !post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception"
+ assert_equal false, post.respond_to?(:title), "post should not respond_to?(:body) since invoking it raises exception"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.