diff options
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 11 |
2 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 1c753524de..177d156834 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -233,7 +233,7 @@ module ActiveRecord method_name = method_id.to_s if self.class.private_method_defined?(method_name) - raise NoMethodError("Attempt to call private method", method_name, args) + raise NoMethodError.new("Attempt to call private method", method_name, args) end # If we haven't generated any methods yet, generate them, then diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 160716f944..77ee8d8fc4 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -233,8 +233,9 @@ class AttributeMethodsTest < ActiveRecord::TestCase topic = @target.new(:title => "The pros and cons of programming naked.") assert !topic.respond_to?(:title) - assert_raise(NoMethodError) { topic.title } - topic.send(:title) + exception = assert_raise(NoMethodError) { topic.title } + assert_equal "Attempt to call private method", exception.message + assert_equal "I'm private", topic.send(:title) end def test_write_attributes_respect_access_control @@ -242,7 +243,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase topic = @target.new assert !topic.respond_to?(:title=) - assert_raise(NoMethodError) { topic.title = "Pants"} + exception = assert_raise(NoMethodError) { topic.title = "Pants"} + assert_equal "Attempt to call private method", exception.message topic.send(:title=, "Very large pants") end @@ -251,7 +253,8 @@ class AttributeMethodsTest < ActiveRecord::TestCase topic = @target.new(:title => "Isaac Newton's pants") assert !topic.respond_to?(:title?) - assert_raise(NoMethodError) { topic.title? } + exception = assert_raise(NoMethodError) { topic.title? } + assert_equal "Attempt to call private method", exception.message assert topic.send(:title?) end |