aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-09-09 06:08:57 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-09-09 06:08:57 -0300
commitd9e55535164feb1a0f73a9f64c1055cc67b98121 (patch)
tree509cf0f0ae38af6d2d9571728af1c3636a00cb1a
parentd5ba9a42a6e93b163a49f99d739aa56820e044d0 (diff)
downloadrails-d9e55535164feb1a0f73a9f64c1055cc67b98121.tar.gz
rails-d9e55535164feb1a0f73a9f64c1055cc67b98121.tar.bz2
rails-d9e55535164feb1a0f73a9f64c1055cc67b98121.zip
Revert "Merge pull request #20080 from robertjlooby/fix_overwriting_by_dynamic_finders"
This reverts commit d5ba9a42a6e93b163a49f99d739aa56820e044d0, reversing changes made to 30c503395bf6bf7db1ec0295bd661ce644628db5. Reason: This generate the dynalic finders more than one time
-rw-r--r--activerecord/lib/active_record/dynamic_matchers.rb6
-rw-r--r--activerecord/test/cases/finder_test.rb13
-rw-r--r--activerecord/test/models/electron.rb8
3 files changed, 3 insertions, 24 deletions
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index 78fac1f3bb..b6dd6814db 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -16,7 +16,7 @@ module ActiveRecord
if match && match.valid?
match.define
- generated_association_methods.send(name, *arguments, &block)
+ send(name, *arguments, &block)
else
super
end
@@ -60,7 +60,7 @@ module ActiveRecord
end
def define
- model.generated_association_methods.class_eval <<-CODE, __FILE__, __LINE__ + 1
+ model.class_eval <<-CODE, __FILE__, __LINE__ + 1
def self.#{name}(#{signature})
#{body}
end
@@ -70,7 +70,7 @@ module ActiveRecord
private
def body
- "#{model}.#{finder}(#{attributes_hash})"
+ "#{finder}(#{attributes_hash})"
end
# The parameters in the signature may have reserved Ruby words, in order
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index daf8299242..4b819a82e8 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -17,7 +17,6 @@ require 'models/matey'
require 'models/dog'
require 'models/car'
require 'models/tyre'
-require 'models/electron'
class FinderTest < ActiveRecord::TestCase
fixtures :companies, :topics, :entrants, :developers, :developers_projects, :posts, :comments, :accounts, :authors, :customers, :categories, :categorizations, :cars
@@ -800,18 +799,6 @@ class FinderTest < ActiveRecord::TestCase
assert_nil Topic.find_by_title("The First Topic!")
end
- def test_find_by_does_not_overwrite_method_on_class
- Electron.create(name: 'First Electron')
-
- assert_equal 0, Electron.times_called_find_by_name
-
- Electron.find_by_name('First Electron')
- assert_equal 1, Electron.times_called_find_by_name
-
- Electron.find_by_name('Some Other Electron')
- assert_equal 2, Electron.times_called_find_by_name
- end
-
def test_find_by_one_attribute_bang
assert_equal topics(:first), Topic.find_by_title!("The First Topic")
assert_raises_with_message(ActiveRecord::RecordNotFound, "Couldn't find Topic") do
diff --git a/activerecord/test/models/electron.rb b/activerecord/test/models/electron.rb
index aacdaa71b7..6fc270673f 100644
--- a/activerecord/test/models/electron.rb
+++ b/activerecord/test/models/electron.rb
@@ -2,12 +2,4 @@ class Electron < ActiveRecord::Base
belongs_to :molecule
validates_presence_of :name
-
- cattr_reader :times_called_find_by_name
- @@times_called_find_by_name = 0
-
- def self.find_by_name(name)
- @@times_called_find_by_name += 1
- super(name)
- end
end