diff options
author | Jon Leighton <j@jonathanleighton.com> | 2014-02-25 22:21:56 +0000 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2014-02-25 22:21:56 +0000 |
commit | 90ba6a762c4576c6b7c83fc8a2c8c3038aeaa274 (patch) | |
tree | b82458f3ba4004a28f9bd34f337c094c9fa16e4b /activerecord/test/cases | |
parent | 6e94140300c7f8e84f2e5b8086fc9517906197e1 (diff) | |
parent | 41554319f8454f667b5e315339d3e286dbf6e1a4 (diff) | |
download | rails-90ba6a762c4576c6b7c83fc8a2c8c3038aeaa274.tar.gz rails-90ba6a762c4576c6b7c83fc8a2c8c3038aeaa274.tar.bz2 rails-90ba6a762c4576c6b7c83fc8a2c8c3038aeaa274.zip |
Merge remote-tracking branch 'chancancode/fix_instance_method_already_implemented'
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 38a43de05a..1a1e442df0 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -746,19 +746,27 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert "unknown attribute: hello", error.message end - def test_read_attribute_overwrites_private_method_not_considered_implemented - # simulate a model with a db column that shares its name an inherited - # private method (e.g. Object#system) - # - Object.class_eval do - private - def title; "private!"; end + def test_global_methods_are_overwritten + klass = Class.new(ActiveRecord::Base) do + self.table_name = 'computers' + end + + assert !klass.instance_method_already_implemented?(:system) + computer = klass.new + assert_nil computer.system + end + + def test_global_methods_are_overwritte_when_subclassing + klass = Class.new(ActiveRecord::Base) { self.abstract_class = true } + + subklass = Class.new(klass) do + self.table_name = 'computers' end - assert !@target.instance_method_already_implemented?(:title) - topic = @target.new - assert_nil topic.title - Object.send(:undef_method, :title) # remove test method from object + assert !klass.instance_method_already_implemented?(:system) + assert !subklass.instance_method_already_implemented?(:system) + computer = subklass.new + assert_nil computer.system end def test_instance_method_should_be_defined_on_the_base_class |