Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved polyamorous from gem to a module #1105

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# active_record_6.0_ruby_2/join_association
require 'polyamorous/activerecord_5.2_ruby_2/join_association'
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# active_record_6.0_ruby_2/join_dependency.rb

module Polyamorous
module JoinDependencyExtensions
# Replaces ActiveRecord::Associations::JoinDependency#build
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# active_record_6.0_ruby_2/reflection.rb
require 'polyamorous/activerecord_5.2_ruby_2/reflection'
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# active_record_6.1_ruby_2/join_association
require 'polyamorous/activerecord_6.0_ruby_2/join_association'
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# active_record_6.1_ruby_2/join_dependency.rb
require 'polyamorous/activerecord_6.0_ruby_2/join_dependency'
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# active_record_6.1_ruby_2/reflection.rb
require 'polyamorous/activerecord_6.0_ruby_2/reflection'
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/ransack.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'active_support/core_ext'
require 'ransack/configuration'
require 'ransack/adapters'
require 'polyamorous'
require 'polyamorous/polyamorous.rb'

Ransack::Adapters.object_mapper.require_constants

Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'ransack/context'
require 'polyamorous'
require 'polyamorous/polyamorous'

module Ransack
module Adapters
Expand Down
3 changes: 0 additions & 3 deletions polyamorous/lib/polyamorous/version.rb

This file was deleted.

27 changes: 0 additions & 27 deletions polyamorous/polyamorous.gemspec

This file was deleted.

7 changes: 3 additions & 4 deletions ransack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ Gem::Specification.new do |s|
s.add_dependency 'activerecord', '>= 5.2.1'
s.add_dependency 'activesupport', '>= 5.2.1'
s.add_dependency 'i18n'
s.add_dependency 'polyamorous', '2.3.2'

s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(polyamorous/|logo/|coverage/|spec/)}) }
s.test_files = `git ls-files -- spec/*`.split("\n")

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
end
2 changes: 0 additions & 2 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,12 @@ module ActiveRecord
it 'removes redundant joins from top query' do
s = Article.ransack(tags_name_not_eq: "Fantasy")
sql = s.result.to_sql

expect(sql).to_not include('LEFT OUTER JOIN')
end

it 'handles != for single values' do
s = Article.ransack(tags_name_not_eq: "Fantasy")
articles = s.result.to_a

expect(articles).to include marco
expect(articles).to_not include arthur
end
Expand Down
17 changes: 0 additions & 17 deletions spec/ransack/adapters/active_record/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,6 @@ module ActiveRecord
context: shared_context)
end

describe '#join_associations', if: AR_version <= '4.0' do
it 'returns dependent join associations for all searches run
against the context' do
parents, children = shared_context.join_associations

expect(children.aliased_table_name).to eq "children_people"
expect(parents.aliased_table_name).to eq "parents_people"
end

it 'can be rejoined to execute a valid query' do
parents, children = shared_context.join_associations

expect { Person.joins(parents).joins(children).to_a }
.to_not raise_error
end
end

describe '#join_sources' do
it 'returns dependent arel join nodes for all searches run against
the context' do
Expand Down
24 changes: 15 additions & 9 deletions spec/ransack/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,21 @@ module Ransack
parent_name_eq: "parent_name_query",
parent_articles_title_eq: 'parents_article_title_query'
}).result

real_query = remove_quotes_and_backticks(s.to_sql)

expect(real_query)
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) > ::Gem::Version.new(Constants::RAILS_6_0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add an a test where the data for this condition is created, and we check that the output is the same across each version of AR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried but i couldn't find a way to change the dynamically change the version of AR. But i have tested with different versions without spec, it's fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shadabmalik1310 the way to do this would to:

  • set up some data
  • check for an expected output of a Ransack query as data (not the SQL generated)
  • run it in CI for each different version of Rails

expect(real_query)
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = parents_people.id})
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = people.id})
else
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles ON (\('default_scope' = 'default_scope'\) AND )?articles.person_id = people.id})
expect(real_query)
.to match(%r{LEFT OUTER JOIN articles articles_people ON (\('default_scope' = 'default_scope'\) AND )?articles_people.person_id = parents_people.id})
end

expect(real_query)
.to include "people.name = 'person_name_query'"
expect(real_query)
Expand Down Expand Up @@ -320,11 +329,8 @@ module Ransack
{ m: 'or', comments_body_cont: 'e', articles_comments_body_cont: 'e' }
]
)
if ActiveRecord::VERSION::MAJOR == 3
all_or_load, uniq_or_distinct = :all, :uniq
else
all_or_load, uniq_or_distinct = :load, :distinct
end

all_or_load, uniq_or_distinct = :load, :distinct
expect(s.result.send(all_or_load).size)
.to eq(9000)
expect(s.result(distinct: true).size)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'machinist/active_record'
require 'polyamorous/polyamorous.rb'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the specs from the Polyamorous gem added and passing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @seanfcarroll - All files are covered with the specs and coverage is 100%, let me know the file and line which is not covered with the spec.

Thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add in the code missing from here https://github.com/activerecord-hackery/polyamorous/blob/master/spec/polyamorous/join_association_spec.rb#L20-L37

Also, please move the Polyamorous tests under their own folder (at the same level as Ransack).

Thank you. :-)

require 'sham'
require 'faker'
require 'ransack'
Expand Down