ransack 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9db4893295fd342185cf668f2b3edbc59f1e649945024147778bdc52978e53fa
4
- data.tar.gz: 9f57ba51a61d63f1f4023735d8a2ef9384e7840461af65169f4c0214f4b619a8
3
+ metadata.gz: 3f37dfefd63333903d6b36084a8dda1193ca31788777b2645d25b96dd97d2d2c
4
+ data.tar.gz: dba86f7268c931801e1caf32f3552ebfeecc06fec2f773130118cc2c809c61e9
5
5
  SHA512:
6
- metadata.gz: 625d61491c96bd319e95d65d0d704f3906b8087e21f8fd2f8f2d1515ac4debdd3e39b678bbea8f0d39d6a5e58d5b46ba66919cb8b4770c8bb7fc4a77421c743e
7
- data.tar.gz: cec0aa2875df4b9b8d5e8ae222fba9970ec0aaaf66de05ae21110a981828704a294f8f16fb55037ea0db39429611d7ea0e5f5d4ff51dbcd01cd66fca171b4ecf
6
+ metadata.gz: 7c8364c70e6536c5aa5dca37c5539164d89dab6fb9e582501dbf5611ff4a647aa0b5ff69450a0b4d480de4d61e62708b3c376ffb6813c0f06ff6b0a591c670f6
7
+ data.tar.gz: 4681b4c7f4e03002b968e165abf930a6b42dfc1e4d740a0bb8a034a9c805b1f956d6f82ab5ca0e39117a8a08b8899b849e34ccf665ac5f7c36fd1aec83ebe3e5
@@ -13,7 +13,6 @@ jobs:
13
13
  rails:
14
14
  - v7.0.2
15
15
  - v6.1.5
16
- - v6.0.4
17
16
  ruby:
18
17
  - 3.1.1
19
18
  - 3.0.2
@@ -40,7 +39,6 @@ jobs:
40
39
  rails:
41
40
  - v7.0.2
42
41
  - v6.1.5
43
- - v6.0.4
44
42
  ruby:
45
43
  - 3.1.1
46
44
  - 3.0.2
@@ -76,7 +74,6 @@ jobs:
76
74
  rails:
77
75
  - v7.0.2
78
76
  - v6.1.5
79
- - v6.0.4
80
77
  ruby:
81
78
  - 3.1.1
82
79
  - 3.0.2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.2.0 - 2022-05-08
6
+
7
+ * Drop Rails 6.0 support.
8
+ PR [1318](https://github.com/activerecord-hackery/ransack/pull/1318)
9
+
10
+ * Exclude "host" from params sent to url generator.
11
+ PR [1319](https://github.com/activerecord-hackery/ransack/pull/1319)
12
+
5
13
  ## 3.1.0 - 2022-04-21
6
14
 
7
15
  * Fix predicate name in "Using Predicates" documentation page.
data/CONTRIBUTING.md CHANGED
@@ -64,7 +64,7 @@ Here's a quick guide:
64
64
  2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`).
65
65
 
66
66
  3. Install the development dependencies by running `bundle install`.
67
- To install rails other than latest (set in Gemfile): `RAILS='6-0-stable' bundle install`
67
+ To install rails other than latest (set in Gemfile): `RAILS='6-1-stable' bundle install`
68
68
 
69
69
  4. Begin by running the tests. We only take pull requests with passing tests,
70
70
  and it's great to know that you have a clean slate:
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ gemspec
3
3
 
4
4
  gem 'rake'
5
5
 
6
- rails = ENV['RAILS'] || '6-0-stable'
6
+ rails = ENV['RAILS'] || '6-1-stable'
7
7
 
8
8
  rails_version = case rails
9
9
  when /\// # A path
@@ -15,7 +15,7 @@ rails_version = case rails
15
15
  end
16
16
 
17
17
  gem 'faker', '~> 2.0'
18
- gem 'sqlite3', ::Gem::Version.new(rails_version == 'main' ? '6.2.0.alpha' : rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
18
+ gem 'sqlite3', '~> 1.4.1'
19
19
  gem 'pg', '~> 1.0'
20
20
  gem 'pry', '~> 0.12.2'
21
21
  gem 'byebug'
data/docs/yarn.lock CHANGED
@@ -2347,9 +2347,9 @@ asap@~2.0.3:
2347
2347
  integrity sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=
2348
2348
 
2349
2349
  async@^2.6.2:
2350
- version "2.6.3"
2351
- resolved "https://registry.yarnpkg.com/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
2352
- integrity sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==
2350
+ version "2.6.4"
2351
+ resolved "https://registry.yarnpkg.com/async/-/async-2.6.4.tgz#706b7ff6084664cd7eae713f6f965433b5504221"
2352
+ integrity sha512-mzo5dfJYwAn29PeiJ0zvwTo04zj8HDJj0Mn8TD7sno7q12prdbnasKJHhkm2c1LgrhlJ0teaea8860oxi51mGA==
2353
2353
  dependencies:
2354
2354
  lodash "^4.17.14"
2355
2355
 
@@ -1 +1,11 @@
1
- require 'polyamorous/activerecord_6.0_ruby_2/reflection'
1
+ module Polyamorous
2
+ module ReflectionExtensions
3
+ def join_scope(table, foreign_table, foreign_klass)
4
+ if respond_to?(:polymorphic?) && polymorphic?
5
+ super.where!(foreign_table[foreign_type].eq(klass.name))
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -110,13 +110,7 @@ module Ransack
110
110
  def join_sources
111
111
  base, joins = begin
112
112
  alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
113
- constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
114
- @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
115
- elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
116
- @join_dependency.join_constraints(@object.joins_values, alias_tracker)
117
- else
118
- @join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
119
- end
113
+ constraints = @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
120
114
 
121
115
  [
122
116
  Arel::SelectManager.new(@object.table),
@@ -284,11 +278,7 @@ module Ransack
284
278
  join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)
285
279
 
286
280
  alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
287
- join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
288
- Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
289
- else
290
- Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins)
291
- end
281
+ join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
292
282
  join_dependency.instance_variable_set(:@alias_tracker, alias_tracker)
293
283
  join_nodes.each do |join|
294
284
  join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1
@@ -315,22 +305,13 @@ module Ransack
315
305
  end
316
306
 
317
307
  def build_association(name, parent = @base, klass = nil)
318
- if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
319
- jd = Polyamorous::JoinDependency.new(
320
- parent.base_klass,
321
- parent.table,
322
- Polyamorous::Join.new(name, @join_type, klass),
323
- @join_type
324
- )
325
- found_association = jd.instance_variable_get(:@join_root).children.last
326
- else
327
- jd = Polyamorous::JoinDependency.new(
328
- parent.base_klass,
329
- parent.table,
330
- Polyamorous::Join.new(name, @join_type, klass)
331
- )
332
- found_association = jd.instance_variable_get(:@join_root).children.last
333
- end
308
+ jd = Polyamorous::JoinDependency.new(
309
+ parent.base_klass,
310
+ parent.table,
311
+ Polyamorous::Join.new(name, @join_type, klass),
312
+ @join_type
313
+ )
314
+ found_association = jd.instance_variable_get(:@join_root).children.last
334
315
 
335
316
  @associations_pot[found_association] = parent
336
317
 
@@ -339,11 +320,7 @@ module Ransack
339
320
  @join_dependency.instance_variable_get(:@join_root).children.push found_association
340
321
 
341
322
  # Builds the arel nodes properly for this association
342
- if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
343
- @tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
344
- else
345
- @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
346
- end
323
+ @tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
347
324
 
348
325
  # Leverage the stashed association functionality in AR
349
326
  @object = @object.joins(jd)
@@ -353,22 +330,13 @@ module Ransack
353
330
  def extract_joins(association)
354
331
  parent = @join_dependency.instance_variable_get(:@join_root)
355
332
  reflection = association.reflection
356
- join_constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
357
- association.join_constraints_with_tables(
358
- parent.table,
359
- parent.base_klass,
360
- Arel::Nodes::OuterJoin,
361
- @join_dependency.instance_variable_get(:@alias_tracker),
362
- @tables_pot[association]
363
- )
364
- else
365
- association.join_constraints(
366
- parent.table,
367
- parent.base_klass,
368
- Arel::Nodes::OuterJoin,
369
- @join_dependency.instance_variable_get(:@alias_tracker)
370
- )
371
- end
333
+ join_constraints = association.join_constraints_with_tables(
334
+ parent.table,
335
+ parent.base_klass,
336
+ Arel::Nodes::OuterJoin,
337
+ @join_dependency.instance_variable_get(:@alias_tracker),
338
+ @tables_pot[association]
339
+ )
372
340
  join_constraints.to_a.flatten
373
341
  end
374
342
  end
@@ -47,19 +47,11 @@ module Ransack
47
47
  end
48
48
 
49
49
  def casted_array?(predicate)
50
- value_from(predicate).is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
51
- end
52
-
53
- def value_from(predicate)
54
- if predicate.respond_to?(:value)
55
- predicate.value # Rails 6.1
56
- elsif predicate.respond_to?(:val)
57
- predicate.val # Rails 6.0
58
- end
50
+ predicate.value.is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
59
51
  end
60
52
 
61
53
  def format_values_for(predicate)
62
- value_from(predicate).map do |val|
54
+ predicate.value.map do |val|
63
55
  val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
64
56
  end
65
57
  end
@@ -45,9 +45,6 @@ module Ransack
45
45
  NOT_EQ_ALL = 'not_eq_all'.freeze
46
46
  CONT = 'cont'.freeze
47
47
 
48
- RAILS_6_0 = '6.0.0'.freeze
49
- RAILS_6_1 = '6.1.0'.freeze
50
-
51
48
  RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
52
49
  RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
53
50
  end
@@ -130,7 +130,7 @@ module Ransack
130
130
 
131
131
  def url_options
132
132
  @params.merge(
133
- @options.except(:class, :data).merge(
133
+ @options.except(:class, :data, :host).merge(
134
134
  @search.context.search_key => search_and_sort_params))
135
135
  end
136
136
 
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.0'
3
3
  end
data/ransack.gemspec CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.required_ruby_version = '>= 2.7'
16
16
  s.license = 'MIT'
17
17
 
18
- s.add_dependency 'activerecord', '>= 6.0.4'
19
- s.add_dependency 'activesupport', '>= 6.0.4'
18
+ s.add_dependency 'activerecord', '>= 6.1.5'
19
+ s.add_dependency 'activesupport', '>= 6.1.5'
20
20
  s.add_dependency 'i18n'
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
@@ -3,14 +3,8 @@ module PolyamorousHelper
3
3
  Polyamorous::JoinAssociation.new reflection, children, klass
4
4
  end
5
5
 
6
- if ActiveRecord.version >= ::Gem::Version.new("6.0.0.rc1")
7
- def new_join_dependency(klass, associations = {})
8
- Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
9
- end
10
- else
11
- def new_join_dependency(klass, associations = {})
12
- Polyamorous::JoinDependency.new klass, klass.arel_table, associations
13
- end
6
+ def new_join_dependency(klass, associations = {})
7
+ Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
14
8
  end
15
9
 
16
10
  def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
@@ -770,6 +770,18 @@ module Ransack
770
770
  it { should_not match /people\?data%5Bturbo_action%5D=advance/ }
771
771
  end
772
772
 
773
+ describe "#sort_link with host option" do
774
+ subject { @controller.view_context
775
+ .sort_link(
776
+ [:main_app, Person.ransack(sorts: ['name desc'])],
777
+ :name,
778
+ host: 'foo', controller: 'people'
779
+ )
780
+ }
781
+ it { should match /href="\/people\?q/ }
782
+ it { should_not match /href=".*foo/ }
783
+ end
784
+
773
785
  describe '#search_form_for with default format' do
774
786
  subject { @controller.view_context
775
787
  .search_form_for(Person.ransack) {} }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2022-04-21 00:00:00.000000000 Z
15
+ date: 2022-05-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -20,28 +20,28 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 6.0.4
23
+ version: 6.1.5
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- version: 6.0.4
30
+ version: 6.1.5
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: activesupport
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - ">="
36
36
  - !ruby/object:Gem::Version
37
- version: 6.0.4
37
+ version: 6.1.5
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 6.0.4
44
+ version: 6.1.5
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: i18n
47
47
  requirement: !ruby/object:Gem::Requirement
@@ -140,9 +140,6 @@ files:
140
140
  - docs/static/logo/ransack.svg
141
141
  - docs/yarn.lock
142
142
  - lib/polyamorous.rb
143
- - lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
144
- - lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
145
- - lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
146
143
  - lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
147
144
  - lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
148
145
  - lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
@@ -258,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
255
  - !ruby/object:Gem::Version
259
256
  version: '0'
260
257
  requirements: []
261
- rubygems_version: 3.3.10
258
+ rubygems_version: 3.4.0.dev
262
259
  signing_key:
263
260
  specification_version: 4
264
261
  summary: Object-based searching for Active Record.
@@ -1,20 +0,0 @@
1
- module Polyamorous
2
- module JoinAssociationExtensions
3
- include SwappingReflectionClass
4
- def self.prepended(base)
5
- base.class_eval { attr_reader :join_type }
6
- end
7
-
8
- def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin)
9
- @join_type = join_type
10
- if polymorphic_class && ::ActiveRecord::Base > polymorphic_class
11
- swapping_reflection_klass(reflection, polymorphic_class) do |reflection|
12
- super(reflection, children)
13
- self.reflection.options[:polymorphic] = true
14
- end
15
- else
16
- super(reflection, children)
17
- end
18
- end
19
- end
20
- end
@@ -1,79 +0,0 @@
1
- module Polyamorous
2
- module JoinDependencyExtensions
3
- # Replaces ActiveRecord::Associations::JoinDependency#build
4
- def build(associations, base_klass)
5
- associations.map do |name, right|
6
- if name.is_a? Join
7
- reflection = find_reflection base_klass, name.name
8
- reflection.check_validity!
9
- reflection.check_eager_loadable!
10
-
11
- klass = if reflection.polymorphic?
12
- name.klass || base_klass
13
- else
14
- reflection.klass
15
- end
16
- JoinAssociation.new(reflection, build(right, klass), name.klass, name.type)
17
- else
18
- reflection = find_reflection base_klass, name
19
- reflection.check_validity!
20
- reflection.check_eager_loadable!
21
-
22
- if reflection.polymorphic?
23
- raise ActiveRecord::EagerLoadPolymorphicError.new(reflection)
24
- end
25
- JoinAssociation.new(reflection, build(right, reflection.klass))
26
- end
27
- end
28
- end
29
-
30
- def join_constraints(joins_to_add, alias_tracker)
31
- @alias_tracker = alias_tracker
32
-
33
- construct_tables!(join_root)
34
- joins = make_join_constraints(join_root, join_type)
35
-
36
- joins.concat joins_to_add.flat_map { |oj|
37
- construct_tables!(oj.join_root)
38
- if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name
39
- walk join_root, oj.join_root, oj.join_type
40
- else
41
- make_join_constraints(oj.join_root, oj.join_type)
42
- end
43
- }
44
- end
45
-
46
- private
47
- def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin)
48
- foreign_table = parent.table
49
- foreign_klass = parent.base_klass
50
- join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin
51
- joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
52
- joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) }
53
- end
54
-
55
- module ClassMethods
56
- # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree
57
- #
58
- def walk_tree(associations, hash)
59
- case associations
60
- when TreeNode
61
- associations.add_to_tree(hash)
62
- when Hash
63
- associations.each do |k, v|
64
- cache =
65
- if TreeNode === k
66
- k.add_to_tree(hash)
67
- else
68
- hash[k] ||= {}
69
- end
70
- walk_tree(v, cache)
71
- end
72
- else
73
- super(associations, hash)
74
- end
75
- end
76
- end
77
-
78
- end
79
- end
@@ -1,11 +0,0 @@
1
- module Polyamorous
2
- module ReflectionExtensions
3
- def join_scope(table, foreign_table, foreign_klass)
4
- if respond_to?(:polymorphic?) && polymorphic?
5
- super.where!(foreign_table[foreign_type].eq(klass.name))
6
- else
7
- super
8
- end
9
- end
10
- end
11
- end