From 7282f2becb3b9dc5864795ea198be4cd0b5b6bd0 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 10 Aug 2018 09:21:32 +0900 Subject: [PATCH] Remove internal methods which are no longer used `{find,build}_join_association_respecting_polymorphism` are no longer used since existed them for Active Record 3.2 and 4.0. --- .../join_dependency.rb | 18 ---------------- .../join_dependency.rb | 18 ---------------- .../join_dependency.rb | 18 ---------------- spec/ransack/join_association_spec.rb | 21 +------------------ spec/ransack/join_dependency_spec.rb | 11 +--------- 5 files changed, 2 insertions(+), 84 deletions(-) diff --git a/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb index 966c304..b1b63af 100644 --- a/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +++ b/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb @@ -30,24 +30,6 @@ module Polyamorous end end - def find_join_association_respecting_polymorphism(reflection, parent, klass) - if association = parent.children.find { |j| j.reflection == reflection } - unless reflection.polymorphic? - association - else - association if association.base_klass == klass - end - end - end - - def build_join_association_respecting_polymorphism(reflection, parent, klass) - if reflection.polymorphic? && klass - JoinAssociation.new(reflection, self, klass) - else - JoinAssociation.new(reflection, self) - end - end - # Replaces ActiveRecord::Associations::JoinDependency#join_constraints # # This internal method was changed in Rails 5.0 by commit diff --git a/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb index 9bbf992..0603daf 100644 --- a/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +++ b/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb @@ -30,24 +30,6 @@ module Polyamorous end end - def find_join_association_respecting_polymorphism(reflection, parent, klass) - if association = parent.children.find { |j| j.reflection == reflection } - unless reflection.polymorphic? - association - else - association if association.base_klass == klass - end - end - end - - def build_join_association_respecting_polymorphism(reflection, parent, klass) - if reflection.polymorphic? && klass - JoinAssociation.new(reflection, self, alias_tracker, klass) - else - JoinAssociation.new(reflection, self, alias_tracker) - end - end - # Replaces ActiveRecord::Associations::JoinDependency#join_constraints # # This internal method was changed in Rails 5.0 by commit diff --git a/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb index c1a6ec2..edbd257 100644 --- a/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +++ b/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb @@ -30,24 +30,6 @@ module Polyamorous end end - def find_join_association_respecting_polymorphism(reflection, parent, klass) - if association = parent.children.find { |j| j.reflection == reflection } - unless reflection.polymorphic? - association - else - association if association.base_klass == klass - end - end - end - - def build_join_association_respecting_polymorphism(reflection, parent, klass) - if reflection.polymorphic? && klass - JoinAssociation.new(reflection, self, klass) - else - JoinAssociation.new(reflection, self) - end - end - module ClassMethods # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree # diff --git a/spec/ransack/join_association_spec.rb b/spec/ransack/join_association_spec.rb index 58f7879..80b9fe2 100644 --- a/spec/ransack/join_association_spec.rb +++ b/spec/ransack/join_association_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' module Polyamorous describe JoinAssociation do - join_base, join_association_args, polymorphic = [:join_root, 'parent.children', 'reflection.options[:polymorphic]'] + join_base, join_association_args, polymorphic = :join_root, 'parent.children', 'reflection.options[:polymorphic]' let(:join_dependency) { new_join_dependency Note, {} } let(:reflection) { Note.reflect_on_association(:notable) } @@ -12,25 +12,6 @@ module Polyamorous eval("new_join_association(reflection, #{join_association_args}, Article)") } - subject { - join_dependency.build_join_association_respecting_polymorphism( - reflection, parent, Person - ) - } - - it 'respects polymorphism on equality test' do - expect(subject).to eq( - join_dependency.build_join_association_respecting_polymorphism( - reflection, parent, Person - ) - ) - expect(subject).not_to eq( - join_dependency.build_join_association_respecting_polymorphism( - reflection, parent, Article - ) - ) - end - it 'leaves the orginal reflection intact for thread safety' do reflection.instance_variable_set(:@klass, Article) join_association diff --git a/spec/ransack/join_dependency_spec.rb b/spec/ransack/join_dependency_spec.rb index cbaebcf..12908fd 100644 --- a/spec/ransack/join_dependency_spec.rb +++ b/spec/ransack/join_dependency_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' module Polyamorous describe JoinDependency do - method, join_associations, join_base = :instance_eval, 'join_root.drop(1)', :join_root + method, join_associations = :instance_eval, 'join_root.drop(1)' context 'with symbol joins' do subject { new_join_dependency Person, articles: :comments } @@ -53,15 +53,6 @@ module Polyamorous .to eq Polyamorous::InnerJoin } specify { expect(subject.send(method, join_associations).first.table_name) .to eq 'people' } - - it 'finds a join association respecting polymorphism' do - parent = subject.send(join_base) - reflection = Note.reflect_on_association(:notable) - - expect(subject.find_join_association_respecting_polymorphism( - reflection, parent, Person)) - .to eq subject.send(method, join_associations).first - end end context 'with polymorphic belongs_to join and nested symbol join' do