ransack 2.5.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +0 -18
- data/CHANGELOG.md +8 -0
- data/CONTRIBUTING.md +1 -3
- data/README.md +2 -2
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +20 -1
- data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
- data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +11 -1
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +1 -1
- data/lib/ransack/helpers/form_helper.rb +1 -1
- data/lib/ransack/version.rb +1 -1
- data/ransack.gemspec +2 -2
- data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
- data/spec/polyamorous/join_association_spec.rb +0 -5
- data/spec/polyamorous/join_dependency_spec.rb +0 -16
- data/spec/ransack/helpers/form_helper_spec.rb +1 -2
- data/spec/support/schema.rb +10 -0
- metadata +9 -10
- data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
- data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
- data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 613abc9bb025f01243aa427878dec0cb7e990e3a9deb3e1436b7f0f3b124bf44
|
4
|
+
data.tar.gz: 1466899c236bc6c9d1e95fc5262b5b3d6cde18f51929273168ff3286ead4be34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d8f6c96d9b0d4af4d5d64c3aa24cbe79abefe78388ff35637577a46b99b99decf25e51433368634ae557a72707470a9291c62ca33cae15b7ce0edb51b682712
|
7
|
+
data.tar.gz: 66bcf53be5d9f201f0e51db95140a56b29e3d61c0b9d79fbd3238e3e67a2b0bb5463dc08ebf445155d502f1b8bfb87b0be38040521219733a852471f32385e0b
|
data/.github/workflows/test.yml
CHANGED
@@ -15,8 +15,6 @@ jobs:
|
|
15
15
|
- v6.1.4
|
16
16
|
- v6.0.4
|
17
17
|
- 6-0-stable
|
18
|
-
- 5-2-stable
|
19
|
-
- v5.2.4
|
20
18
|
ruby:
|
21
19
|
- 3.0.2
|
22
20
|
- 2.7.4
|
@@ -24,10 +22,6 @@ jobs:
|
|
24
22
|
exclude:
|
25
23
|
- rails: v7.0.0
|
26
24
|
ruby: 2.6.7
|
27
|
-
- rails: v5.2.4
|
28
|
-
ruby: 3.0.2
|
29
|
-
- rails: 5-2-stable
|
30
|
-
ruby: 3.0.2
|
31
25
|
env:
|
32
26
|
DB: sqlite3
|
33
27
|
RAILS: ${{ matrix.rails }}
|
@@ -52,8 +46,6 @@ jobs:
|
|
52
46
|
- v6.1.4
|
53
47
|
- v6.0.4
|
54
48
|
- 6-0-stable
|
55
|
-
- 5-2-stable
|
56
|
-
- v5.2.4
|
57
49
|
ruby:
|
58
50
|
- 3.0.2
|
59
51
|
- 2.7.4
|
@@ -61,10 +53,6 @@ jobs:
|
|
61
53
|
exclude:
|
62
54
|
- rails: v7.0.0
|
63
55
|
ruby: 2.6.7
|
64
|
-
- rails: v5.2.4
|
65
|
-
ruby: 3.0.2
|
66
|
-
- rails: 5-2-stable
|
67
|
-
ruby: 3.0.2
|
68
56
|
env:
|
69
57
|
DB: mysql
|
70
58
|
RAILS: ${{ matrix.rails }}
|
@@ -98,8 +86,6 @@ jobs:
|
|
98
86
|
- v6.1.4
|
99
87
|
- v6.0.4
|
100
88
|
- 6-0-stable
|
101
|
-
- 5-2-stable
|
102
|
-
- v5.2.4
|
103
89
|
ruby:
|
104
90
|
- 3.0.2
|
105
91
|
- 2.7.4
|
@@ -107,10 +93,6 @@ jobs:
|
|
107
93
|
exclude:
|
108
94
|
- rails: v7.0.0
|
109
95
|
ruby: 2.6.7
|
110
|
-
- rails: v5.2.4
|
111
|
-
ruby: 3.0.2
|
112
|
-
- rails: 5-2-stable
|
113
|
-
ruby: 3.0.2
|
114
96
|
env:
|
115
97
|
DB: postgres
|
116
98
|
RAILS: ${{ matrix.rails }}
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.6.0 - 2022-03-08
|
6
|
+
|
7
|
+
* Fix regression when joining a table with itself.
|
8
|
+
PR [1275](https://github.com/activerecord-hackery/ransack/pull/1276)
|
9
|
+
|
10
|
+
* Drop support for ActiveRecord older than 6.0.4.
|
11
|
+
PR [1276](https://github.com/activerecord-hackery/ransack/pull/1276)
|
12
|
+
|
5
13
|
## 2.5.0 - 2021-12-26
|
6
14
|
|
7
15
|
* ActiveRecord 7.0 support
|
data/CONTRIBUTING.md
CHANGED
@@ -64,9 +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='
|
68
|
-
|
69
|
-
$ RAILS='5-2-stable' bundle install
|
67
|
+
To install rails other than latest (set in Gemfile): `RAILS='6-0-stable' bundle install`
|
70
68
|
|
71
69
|
4. Begin by running the tests. We only take pull requests with passing tests,
|
72
70
|
and it's great to know that you have a clean slate:
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ or controller layer, you're probably not looking for Ransack.
|
|
15
15
|
|
16
16
|
## Getting started
|
17
17
|
|
18
|
-
Ransack is supported for Rails
|
18
|
+
Ransack is supported for Rails 7.0, 6.x on Ruby 2.6.6 and later.
|
19
19
|
|
20
20
|
In your Gemfile, for the last officially released gem:
|
21
21
|
|
@@ -310,7 +310,7 @@ end
|
|
310
310
|
|
311
311
|
If this approach is taken, it is advisable to [add a functional index](https://www.postgresql.org/docs/13/citext.html).
|
312
312
|
|
313
|
-
This was originally asked in [a Ransack issue](https://github.com/activerecord-hackery/ransack/issues/1201) and a solution was found on [Stack Overflow](https://stackoverflow.com/a/34677378).
|
313
|
+
This was originally asked in [a Ransack issue](https://github.com/activerecord-hackery/ransack/issues/1201) and a solution was found on [Stack Overflow](https://stackoverflow.com/a/34677378).
|
314
314
|
|
315
315
|
### Advanced Mode
|
316
316
|
|
@@ -1 +1,20 @@
|
|
1
|
-
|
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 +1,11 @@
|
|
1
|
-
|
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
|
data/lib/ransack/version.rb
CHANGED
data/ransack.gemspec
CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.required_ruby_version = '>= 2.6'
|
16
16
|
s.license = 'MIT'
|
17
17
|
|
18
|
-
s.add_dependency 'activerecord', '>=
|
19
|
-
s.add_dependency 'activesupport', '>=
|
18
|
+
s.add_dependency 'activerecord', '>= 6.0.4'
|
19
|
+
s.add_dependency 'activesupport', '>= 6.0.4'
|
20
20
|
s.add_dependency 'i18n'
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Polyamorous
|
4
|
+
describe "ActiveRecord Compatibility" do
|
5
|
+
it 'works with self joins and includes' do
|
6
|
+
trade_account = Account.create!
|
7
|
+
Account.create!(trade_account: trade_account)
|
8
|
+
|
9
|
+
accounts = Account.joins(:trade_account).includes(:trade_account, :agent_account)
|
10
|
+
account = accounts.first
|
11
|
+
|
12
|
+
expect(account.agent_account).to be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -12,11 +12,6 @@ module Polyamorous
|
|
12
12
|
|
13
13
|
subject { new_join_association(reflection, parent.children, Person) }
|
14
14
|
|
15
|
-
it 'respects polymorphism on equality test' do
|
16
|
-
expect(subject).to eq new_join_association(reflection, parent.children, Person)
|
17
|
-
expect(subject).not_to eq new_join_association(reflection, parent.children, Article)
|
18
|
-
end
|
19
|
-
|
20
15
|
it 'leaves the original reflection intact for thread safety' do
|
21
16
|
reflection.instance_variable_set(:@klass, Article)
|
22
17
|
join_association
|
@@ -77,21 +77,5 @@ module Polyamorous
|
|
77
77
|
specify { expect(subject.send(:join_root).drop(1)[1].table_name)
|
78
78
|
.to eq 'comments' }
|
79
79
|
end
|
80
|
-
|
81
|
-
context '#left_outer_join in Rails 5 overrides join type specified',
|
82
|
-
if: ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MAJOR < 6 && ActiveRecord::VERSION::MINOR < 2 do
|
83
|
-
|
84
|
-
let(:join_type_class) do
|
85
|
-
new_join_dependency(
|
86
|
-
Person,
|
87
|
-
new_join(:articles)
|
88
|
-
).join_constraints(
|
89
|
-
[],
|
90
|
-
Arel::Nodes::OuterJoin
|
91
|
-
).first.joins.map(&:class)
|
92
|
-
end
|
93
|
-
|
94
|
-
specify { expect(join_type_class).to eq [Arel::Nodes::OuterJoin] }
|
95
|
-
end
|
96
80
|
end
|
97
81
|
end
|
@@ -469,8 +469,7 @@ module Ransack
|
|
469
469
|
it { should match /exist\=existing/ }
|
470
470
|
end
|
471
471
|
|
472
|
-
context 'using a real ActionController::Parameter object'
|
473
|
-
if: ::ActiveRecord::VERSION::MAJOR > 3 do
|
472
|
+
context 'using a real ActionController::Parameter object' do
|
474
473
|
|
475
474
|
describe 'with symbol q:, #sort_link should include search params' do
|
476
475
|
subject { @controller.view_context.sort_link(Person.ransack, :name) }
|
data/spec/support/schema.rb
CHANGED
@@ -199,6 +199,11 @@ class Note < ActiveRecord::Base
|
|
199
199
|
belongs_to :notable, polymorphic: true
|
200
200
|
end
|
201
201
|
|
202
|
+
class Account < ActiveRecord::Base
|
203
|
+
belongs_to :agent_account, class_name: "Account"
|
204
|
+
belongs_to :trade_account, class_name: "Account"
|
205
|
+
end
|
206
|
+
|
202
207
|
module Schema
|
203
208
|
def self.create
|
204
209
|
ActiveRecord::Migration.verbose = false
|
@@ -257,6 +262,11 @@ module Schema
|
|
257
262
|
t.integer :target_person_id
|
258
263
|
t.integer :article_id
|
259
264
|
end
|
265
|
+
|
266
|
+
create_table :accounts, force: true do |t|
|
267
|
+
t.belongs_to :agent_account
|
268
|
+
t.belongs_to :trade_account
|
269
|
+
end
|
260
270
|
end
|
261
271
|
|
262
272
|
10.times do
|
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: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernie Miller
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2022-03-10 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -19,28 +19,28 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 6.0.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 6.0.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: activesupport
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
34
|
- - ">="
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
36
|
+
version: 6.0.4
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 6.0.4
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: i18n
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,9 +84,6 @@ files:
|
|
84
84
|
- docs/img/create_release.png
|
85
85
|
- docs/release_process.md
|
86
86
|
- lib/polyamorous.rb
|
87
|
-
- lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
|
88
|
-
- lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
|
89
|
-
- lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
|
90
87
|
- lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
|
91
88
|
- lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
|
92
89
|
- lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
|
@@ -172,6 +169,7 @@ files:
|
|
172
169
|
- spec/console.rb
|
173
170
|
- spec/helpers/polyamorous_helper.rb
|
174
171
|
- spec/helpers/ransack_helper.rb
|
172
|
+
- spec/polyamorous/activerecord_compatibility_spec.rb
|
175
173
|
- spec/polyamorous/join_association_spec.rb
|
176
174
|
- spec/polyamorous/join_dependency_spec.rb
|
177
175
|
- spec/polyamorous/join_spec.rb
|
@@ -207,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
205
|
- !ruby/object:Gem::Version
|
208
206
|
version: '0'
|
209
207
|
requirements: []
|
210
|
-
rubygems_version: 3.
|
208
|
+
rubygems_version: 3.3.9
|
211
209
|
signing_key:
|
212
210
|
specification_version: 4
|
213
211
|
summary: Object-based searching for Active Record and Mongoid (currently).
|
@@ -220,6 +218,7 @@ test_files:
|
|
220
218
|
- spec/console.rb
|
221
219
|
- spec/helpers/polyamorous_helper.rb
|
222
220
|
- spec/helpers/ransack_helper.rb
|
221
|
+
- spec/polyamorous/activerecord_compatibility_spec.rb
|
223
222
|
- spec/polyamorous/join_association_spec.rb
|
224
223
|
- spec/polyamorous/join_dependency_spec.rb
|
225
224
|
- spec/polyamorous/join_spec.rb
|
@@ -1,24 +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
|
-
|
20
|
-
def ==(other)
|
21
|
-
base_klass == other.base_klass
|
22
|
-
end
|
23
|
-
end
|
24
|
-
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, join_type, 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
|
40
|
-
else
|
41
|
-
make_join_constraints(oj.join_root, 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
|