Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

PDI 3.1

  • Loading branch information...
commit 5a1988d218027a938597c35c45b04e152d6e8e1f 1 parent 3ac8f4b
@lifo authored
View
10 lib/sidekick/active_record.rb
@@ -41,10 +41,6 @@ def to_a_with_kick
alias_method_chain :to_a, :kick
end
-if ActiveRecord::VERSION::STRING < '3.1' && !ActiveRecord::Associations::AssociationProxy.instance_methods.include?(:load)
- require 'sidekick/association_proxy_monkey'
-end
-
[
ActiveRecord::Associations::BelongsToAssociation,
ActiveRecord::Associations::HasManyAssociation,
@@ -54,6 +50,12 @@ def to_a_with_kick
ActiveRecord::Associations::HasManyThroughAssociation
].each do |association_klass|
association_klass.send :include, Sidekick::Target
+end
+
+[
+ ActiveRecord::Associations::HasManyAssociation,
+ ActiveRecord::Associations::HasManyThroughAssociation
+].each do |association_klass|
association_klass.send :include, Sidekick::Reload
end
View
41 lib/sidekick/association_proxy_monkey.rb
@@ -1,41 +0,0 @@
-# Please remove me as soon as you can - __FILE__
-
-class ActiveRecord::Associations::AssociationProxy
- def load
- load_target unless loaded?
- self unless @target.nil?
- end
-
- def reload
- reset
- load
- end
-end
-
-module Sidekick
- module MonkeyAssociationAccessor
- def association_accessor_methods(reflection, association_proxy_class)
- super(reflection, association_proxy_class)
-
- redefine_method(reflection.name) do |*params|
- force_reload = params.first unless params.empty?
- association = association_instance_get(reflection.name)
-
- if association.nil? || force_reload
- association = association_proxy_class.new(self, reflection)
- retval = force_reload ? reflection.klass.uncached { association.reload } : association.load
- if retval.nil? and association_proxy_class == ActiveRecord::Associations::BelongsToAssociation
- association_instance_set(reflection.name, nil)
- return nil
- end
- association_instance_set(reflection.name, association)
- end
-
- association.target.nil? ? nil : association
- end
-
- end
- end
-end
-
-ActiveRecord::Base.send :extend, Sidekick::MonkeyAssociationAccessor
View
4 test/basic_test.rb
@@ -62,7 +62,7 @@ def test_belongs_to
end
def test_belongs_reload
- assert_queries(4) do
+ assert_queries(3) do
# Query 1
posts = Post.all
hello_post = posts.detect {|p| p.title == 'Hello' }
@@ -70,7 +70,7 @@ def test_belongs_reload
# Query 2 - Load all the users
assert_equal 'Bob', hello_post.user.name
- # Query 3 & 4- Reload Bob. Also fires SHOW TABLES query.
+ # Query 3 Reload Bob
assert_equal 'Bob', hello_post.user.reload.name
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.