ransack 2.4.2 → 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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/cronjob.yml +6 -9
  3. data/.github/workflows/rubocop.yml +1 -1
  4. data/.github/workflows/test.yml +25 -34
  5. data/CHANGELOG.md +18 -1
  6. data/CONTRIBUTING.md +4 -3
  7. data/README.md +76 -10
  8. data/docs/release_process.md +2 -5
  9. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +20 -1
  10. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +0 -1
  11. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +11 -1
  12. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +0 -4
  13. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +0 -1
  14. data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_association.rb +0 -0
  15. data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/join_dependency.rb +0 -0
  16. data/lib/polyamorous/{activerecord_6.2_ruby_2 → activerecord_7.0_ruby_2}/reflection.rb +0 -0
  17. data/lib/polyamorous.rb +1 -0
  18. data/lib/ransack/adapters/active_record/base.rb +1 -1
  19. data/lib/ransack/adapters/active_record/context.rb +6 -2
  20. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +10 -9
  21. data/lib/ransack/configuration.rb +16 -2
  22. data/lib/ransack/helpers/form_helper.rb +1 -1
  23. data/lib/ransack/locale/sv.yml +70 -0
  24. data/lib/ransack/nodes/sort.rb +2 -2
  25. data/lib/ransack/search.rb +2 -1
  26. data/lib/ransack/translate.rb +1 -1
  27. data/lib/ransack/version.rb +1 -1
  28. data/ransack.gemspec +2 -2
  29. data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
  30. data/spec/polyamorous/join_association_spec.rb +1 -6
  31. data/spec/polyamorous/join_dependency_spec.rb +0 -16
  32. data/spec/ransack/adapters/active_record/base_spec.rb +18 -10
  33. data/spec/ransack/configuration_spec.rb +14 -0
  34. data/spec/ransack/helpers/form_helper_spec.rb +1 -2
  35. data/spec/ransack/nodes/condition_spec.rb +13 -0
  36. data/spec/ransack/search_spec.rb +117 -27
  37. data/spec/support/schema.rb +33 -0
  38. metadata +17 -16
  39. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +0 -24
  40. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +0 -79
  41. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +0 -11
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', '>= 5.2.4'
19
- s.add_dependency 'activesupport', '>= 5.2.4'
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,12 +12,7 @@ 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
- it 'leaves the orginal reflection intact for thread safety' do
15
+ it 'leaves the original reflection intact for thread safety' do
21
16
  reflection.instance_variable_set(:@klass, Article)
22
17
  join_association
23
18
  .swapping_reflection_klass(reflection, Person) do |new_reflection|
@@ -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
@@ -44,12 +44,12 @@ module Ransack
44
44
 
45
45
  it 'applies stringy boolean scopes with true value in an array' do
46
46
  s = Person.ransack('of_age' => ['true'])
47
- expect(s.result.to_sql).to (include 'age >= 18')
47
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{(age >= '18')} : 'age >= 18')
48
48
  end
49
49
 
50
50
  it 'applies stringy boolean scopes with false value in an array' do
51
51
  s = Person.ransack('of_age' => ['false'])
52
- expect(s.result.to_sql).to (include 'age < 18')
52
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age < '18'} : 'age < 18')
53
53
  end
54
54
 
55
55
  it 'ignores unlisted scopes' do
@@ -69,12 +69,12 @@ module Ransack
69
69
 
70
70
  it 'passes values to scopes' do
71
71
  s = Person.ransack('over_age' => 18)
72
- expect(s.result.to_sql).to (include 'age > 18')
72
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '18'} : 'age > 18')
73
73
  end
74
74
 
75
75
  it 'chains scopes' do
76
76
  s = Person.ransack('over_age' => 18, 'active' => true)
77
- expect(s.result.to_sql).to (include 'age > 18')
77
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '18'} : 'age > 18')
78
78
  expect(s.result.to_sql).to (include 'active = 1')
79
79
  end
80
80
 
@@ -89,12 +89,12 @@ module Ransack
89
89
 
90
90
  it 'passes true values to scopes' do
91
91
  s = Person.ransack('over_age' => 1)
92
- expect(s.result.to_sql).to (include 'age > 1')
92
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '1'} : 'age > 1')
93
93
  end
94
94
 
95
95
  it 'passes false values to scopes' do
96
96
  s = Person.ransack('over_age' => 0)
97
- expect(s.result.to_sql).to (include 'age > 0')
97
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '0'} : 'age > 0')
98
98
  end
99
99
  end
100
100
 
@@ -107,12 +107,12 @@ module Ransack
107
107
 
108
108
  it 'passes true values to scopes' do
109
109
  s = Person.ransack('over_age' => 1)
110
- expect(s.result.to_sql).to (include 'age > 1')
110
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '1'} : 'age > 1')
111
111
  end
112
112
 
113
113
  it 'passes false values to scopes' do
114
114
  s = Person.ransack('over_age' => 0)
115
- expect(s.result.to_sql).to (include 'age > 0')
115
+ expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '0'} : 'age > 0')
116
116
  end
117
117
  end
118
118
 
@@ -123,7 +123,7 @@ module Ransack
123
123
  end
124
124
 
125
125
  it 'raises exception if ransack! called with unknown condition' do
126
- expect { Person.ransack!(unknown_attr_eq: 'Ernie') }.to raise_error
126
+ expect { Person.ransack!(unknown_attr_eq: 'Ernie') }.to raise_error(ArgumentError)
127
127
  end
128
128
 
129
129
  it 'does not modify the parameters' do
@@ -314,7 +314,11 @@ module Ransack
314
314
  end
315
315
 
316
316
  it 'should function correctly with a multi-parameter attribute' do
317
- ::ActiveRecord::Base.default_timezone = :utc
317
+ if ::ActiveRecord::VERSION::MAJOR >= 7
318
+ ::ActiveRecord.default_timezone = :utc
319
+ else
320
+ ::ActiveRecord::Base.default_timezone = :utc
321
+ end
318
322
  Time.zone = 'UTC'
319
323
 
320
324
  date = Date.current
@@ -690,6 +694,10 @@ module Ransack
690
694
  it { should eq [] }
691
695
  end
692
696
 
697
+ private
698
+ def rails7_and_mysql
699
+ ::ActiveRecord::VERSION::MAJOR >= 7 && ENV['DB'] == 'mysql'
700
+ end
693
701
  end
694
702
  end
695
703
  end
@@ -45,6 +45,20 @@ module Ransack
45
45
  Ransack.options = default
46
46
  end
47
47
 
48
+ it 'should have default value for strip_whitespace' do
49
+ expect(Ransack.options[:strip_whitespace]).to eq true
50
+ end
51
+
52
+ it 'changes default search key parameter' do
53
+ default = Ransack.options.clone
54
+
55
+ Ransack.configure { |c| c.strip_whitespace = false }
56
+
57
+ expect(Ransack.options[:strip_whitespace]).to eq false
58
+
59
+ Ransack.options = default
60
+ end
61
+
48
62
  it 'should have default values for arrows' do
49
63
  expect(Ransack.options[:up_arrow]).to eq '&#9660;'
50
64
  expect(Ransack.options[:down_arrow]).to eq '&#9650;'
@@ -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) }
@@ -3,6 +3,19 @@ require 'spec_helper'
3
3
  module Ransack
4
4
  module Nodes
5
5
  describe Condition do
6
+ context 'bug report #1245' do
7
+ it 'preserves tuple behavior' do
8
+ ransack_hash = {
9
+ m: 'and',
10
+ g: [
11
+ { title_type_in: ['["title 1", ""]'] }
12
+ ]
13
+ }
14
+
15
+ sql = Article.ransack(ransack_hash).result.to_sql
16
+ expect(sql).to include("IN (('title 1', ''))")
17
+ end
18
+ end
6
19
 
7
20
  context 'with an alias' do
8
21
  subject {
@@ -20,10 +20,42 @@ module Ransack
20
20
  Search.new(Person, name_eq: 'foobar')
21
21
  end
22
22
 
23
- it 'strip leading & trailing whitespace before building' do
24
- expect_any_instance_of(Search).to receive(:build)
25
- .with({ 'name_eq' => 'foobar' })
26
- Search.new(Person, name_eq: ' foobar ')
23
+ context 'whitespace stripping' do
24
+ context 'when whitespace_strip option is true' do
25
+ before do
26
+ Ransack.configure { |c| c.strip_whitespace = true }
27
+ end
28
+
29
+ it 'strips leading & trailing whitespace before building' do
30
+ expect_any_instance_of(Search).to receive(:build)
31
+ .with({ 'name_eq' => 'foobar' })
32
+ Search.new(Person, name_eq: ' foobar ')
33
+ end
34
+ end
35
+
36
+ context 'when whitespace_strip option is false' do
37
+ before do
38
+ Ransack.configure { |c| c.strip_whitespace = false }
39
+ end
40
+
41
+ it 'doesn\'t strip leading & trailing whitespace before building' do
42
+ expect_any_instance_of(Search).to receive(:build)
43
+ .with({ 'name_eq' => ' foobar ' })
44
+ Search.new(Person, name_eq: ' foobar ')
45
+ end
46
+ end
47
+
48
+ it 'strips leading & trailing whitespace when strip_whitespace search parameter is true' do
49
+ expect_any_instance_of(Search).to receive(:build)
50
+ .with({ 'name_eq' => 'foobar' })
51
+ Search.new(Person, { name_eq: ' foobar ' }, { strip_whitespace: true })
52
+ end
53
+
54
+ it 'doesn\'t strip leading & trailing whitespace when strip_whitespace search parameter is false' do
55
+ expect_any_instance_of(Search).to receive(:build)
56
+ .with({ 'name_eq' => ' foobar ' })
57
+ Search.new(Person, { name_eq: ' foobar ' }, { strip_whitespace: false })
58
+ end
27
59
  end
28
60
 
29
61
  it 'removes empty suffixed conditions before building' do
@@ -300,8 +332,6 @@ module Ransack
300
332
  end
301
333
 
302
334
  it 'use appropriate table alias' do
303
- skip "Rails 6 regressed here, but it's fixed in 6-0-stable since https://github.com/rails/rails/commit/f9ba52477ca288e7effa5f6794ae3df3f4e982bc" if ENV["RAILS"] == "v6.0.3"
304
-
305
335
  s = Search.new(Person, {
306
336
  name_eq: "person_name_query",
307
337
  articles_title_eq: "person_article_title_query",
@@ -451,82 +481,109 @@ module Ransack
451
481
  expect(sort.dir).to eq 'asc'
452
482
  end
453
483
 
454
- it 'creates sorts based on multiple attributes/directions in array format' do
455
- @s.sorts = ['id desc', { name: 'name', dir: 'asc' }]
484
+ it 'creates sorts based on a single alias/direction' do
485
+ @s.sorts = 'daddy desc'
486
+ expect(@s.sorts.size).to eq(1)
487
+ sort = @s.sorts.first
488
+ expect(sort).to be_a Nodes::Sort
489
+ expect(sort.name).to eq 'parent_name'
490
+ expect(sort.dir).to eq 'desc'
491
+ end
492
+
493
+ it 'creates sorts based on a single alias and uppercase direction' do
494
+ @s.sorts = 'daddy DESC'
495
+ expect(@s.sorts.size).to eq(1)
496
+ sort = @s.sorts.first
497
+ expect(sort).to be_a Nodes::Sort
498
+ expect(sort.name).to eq 'parent_name'
499
+ expect(sort.dir).to eq 'desc'
500
+ end
501
+
502
+ it 'creates sorts based on a single alias and without direction' do
503
+ @s.sorts = 'daddy'
504
+ expect(@s.sorts.size).to eq(1)
505
+ sort = @s.sorts.first
506
+ expect(sort).to be_a Nodes::Sort
507
+ expect(sort.name).to eq 'parent_name'
508
+ expect(sort.dir).to eq 'asc'
509
+ end
510
+
511
+ it 'creates sorts based on attributes, alias and directions in array format' do
512
+ @s.sorts = ['id desc', { name: 'daddy', dir: 'asc' }]
456
513
  expect(@s.sorts.size).to eq(2)
457
514
  sort1, sort2 = @s.sorts
458
515
  expect(sort1).to be_a Nodes::Sort
459
516
  expect(sort1.name).to eq 'id'
460
517
  expect(sort1.dir).to eq 'desc'
461
518
  expect(sort2).to be_a Nodes::Sort
462
- expect(sort2.name).to eq 'name'
519
+ expect(sort2.name).to eq 'parent_name'
463
520
  expect(sort2.dir).to eq 'asc'
464
521
  end
465
522
 
466
- it 'creates sorts based on multiple attributes and uppercase directions in array format' do
467
- @s.sorts = ['id DESC', { name: 'name', dir: 'ASC' }]
523
+ it 'creates sorts based on attributes, alias and uppercase directions in array format' do
524
+ @s.sorts = ['id DESC', { name: 'daddy', dir: 'ASC' }]
468
525
  expect(@s.sorts.size).to eq(2)
469
526
  sort1, sort2 = @s.sorts
470
527
  expect(sort1).to be_a Nodes::Sort
471
528
  expect(sort1.name).to eq 'id'
472
529
  expect(sort1.dir).to eq 'desc'
473
530
  expect(sort2).to be_a Nodes::Sort
474
- expect(sort2.name).to eq 'name'
531
+ expect(sort2.name).to eq 'parent_name'
475
532
  expect(sort2.dir).to eq 'asc'
476
533
  end
477
534
 
478
- it 'creates sorts based on multiple attributes and different directions
535
+ it 'creates sorts based on attributes, alias and different directions
479
536
  in array format' do
480
- @s.sorts = ['id DESC', { name: 'name', dir: nil }]
537
+ @s.sorts = ['id DESC', { name: 'daddy', dir: nil }]
481
538
  expect(@s.sorts.size).to eq(2)
482
539
  sort1, sort2 = @s.sorts
483
540
  expect(sort1).to be_a Nodes::Sort
484
541
  expect(sort1.name).to eq 'id'
485
542
  expect(sort1.dir).to eq 'desc'
486
543
  expect(sort2).to be_a Nodes::Sort
487
- expect(sort2.name).to eq 'name'
544
+ expect(sort2.name).to eq 'parent_name'
488
545
  expect(sort2.dir).to eq 'asc'
489
546
  end
490
547
 
491
- it 'creates sorts based on multiple attributes/directions in hash format' do
548
+ it 'creates sorts based on attributes, alias and directions in hash format' do
492
549
  @s.sorts = {
493
550
  '0' => { name: 'id', dir: 'desc' },
494
- '1' => { name: 'name', dir: 'asc' }
551
+ '1' => { name: 'daddy', dir: 'asc' }
495
552
  }
496
553
  expect(@s.sorts.size).to eq(2)
497
554
  expect(@s.sorts).to be_all { |s| Nodes::Sort === s }
498
555
  id_sort = @s.sorts.detect { |s| s.name == 'id' }
499
- name_sort = @s.sorts.detect { |s| s.name == 'name' }
556
+ daddy_sort = @s.sorts.detect { |s| s.name == 'parent_name' }
500
557
  expect(id_sort.dir).to eq 'desc'
501
- expect(name_sort.dir).to eq 'asc'
558
+ expect(daddy_sort.dir).to eq 'asc'
502
559
  end
503
560
 
504
- it 'creates sorts based on multiple attributes and uppercase directions
561
+ it 'creates sorts based on attributes, alias and uppercase directions
505
562
  in hash format' do
506
563
  @s.sorts = {
507
564
  '0' => { name: 'id', dir: 'DESC' },
508
- '1' => { name: 'name', dir: 'ASC' }
565
+ '1' => { name: 'daddy', dir: 'ASC' }
509
566
  }
510
567
  expect(@s.sorts.size).to eq(2)
511
568
  expect(@s.sorts).to be_all { |s| Nodes::Sort === s }
512
569
  id_sort = @s.sorts.detect { |s| s.name == 'id' }
513
- name_sort = @s.sorts.detect { |s| s.name == 'name' }
570
+ daddy_sort = @s.sorts.detect { |s| s.name == 'parent_name' }
514
571
  expect(id_sort.dir).to eq 'desc'
515
- expect(name_sort.dir).to eq 'asc'
572
+ expect(daddy_sort.dir).to eq 'asc'
516
573
  end
517
574
 
518
- it 'creates sorts based on multiple attributes and different directions
575
+ it 'creates sorts based on attributes, alias and different directions
519
576
  in hash format' do
520
577
  @s.sorts = {
521
578
  '0' => { name: 'id', dir: 'DESC' },
522
- '1' => { name: 'name', dir: nil }
579
+ '1' => { name: 'daddy', dir: nil }
523
580
  }
524
581
  expect(@s.sorts.size).to eq(2)
525
582
  expect(@s.sorts).to be_all { |s| Nodes::Sort === s }
526
583
  id_sort = @s.sorts.detect { |s| s.name == 'id' }
527
- name_sort = @s.sorts.detect { |s| s.name == 'name' }
584
+ daddy_sort = @s.sorts.detect { |s| s.name == 'parent_name' }
528
585
  expect(id_sort.dir).to eq 'desc'
529
- expect(name_sort.dir).to eq 'asc'
586
+ expect(daddy_sort.dir).to eq 'asc'
530
587
  end
531
588
 
532
589
  it 'overrides existing sort' do
@@ -554,6 +611,39 @@ module Ransack
554
611
 
555
612
  Ransack.options = default
556
613
  end
614
+
615
+ it "PG's sort option with double name", if: ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" do
616
+ default = Ransack.options.clone
617
+
618
+ s = Search.new(Person, s: 'doubled_name asc')
619
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" ASC"
620
+
621
+ Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_first }
622
+ s = Search.new(Person, s: 'doubled_name asc')
623
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" ASC NULLS FIRST"
624
+ s = Search.new(Person, s: 'doubled_name desc')
625
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" DESC NULLS LAST"
626
+
627
+ Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_last }
628
+ s = Search.new(Person, s: 'doubled_name asc')
629
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" ASC NULLS LAST"
630
+ s = Search.new(Person, s: 'doubled_name desc')
631
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" DESC NULLS FIRST"
632
+
633
+ Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_always_first }
634
+ s = Search.new(Person, s: 'doubled_name asc')
635
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" ASC NULLS FIRST"
636
+ s = Search.new(Person, s: 'doubled_name desc')
637
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" DESC NULLS FIRST"
638
+
639
+ Ransack.configure { |c| c.postgres_fields_sort_option = :nulls_always_last }
640
+ s = Search.new(Person, s: 'doubled_name asc')
641
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" ASC NULLS LAST"
642
+ s = Search.new(Person, s: 'doubled_name desc')
643
+ expect(s.result.to_sql).to eq "SELECT \"people\".* FROM \"people\" ORDER BY \"people\".\"name\" || \"people\".\"name\" DESC NULLS LAST"
644
+
645
+ Ransack.options = default
646
+ end
557
647
  end
558
648
 
559
649
  describe '#method_missing' do
@@ -138,6 +138,29 @@ class Article < ActiveRecord::Base
138
138
  alias_attribute :content, :body
139
139
 
140
140
  default_scope { where("'default_scope' = 'default_scope'") }
141
+
142
+ ransacker :title_type, formatter: lambda { |tuples|
143
+ title, type = JSON.parse(tuples)
144
+ Arel::Nodes::Grouping.new(
145
+ [
146
+ Arel::Nodes.build_quoted(title),
147
+ Arel::Nodes.build_quoted(type)
148
+ ]
149
+ )
150
+ } do |_parent|
151
+ articles = Article.arel_table
152
+ Arel::Nodes::Grouping.new(
153
+ %i[title type].map do |field|
154
+ Arel::Nodes::NamedFunction.new(
155
+ 'COALESCE',
156
+ [
157
+ Arel::Nodes::NamedFunction.new('TRIM', [articles[field]]),
158
+ Arel::Nodes.build_quoted('')
159
+ ]
160
+ )
161
+ end
162
+ )
163
+ end
141
164
  end
142
165
 
143
166
  class StoryArticle < Article
@@ -176,6 +199,11 @@ class Note < ActiveRecord::Base
176
199
  belongs_to :notable, polymorphic: true
177
200
  end
178
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
+
179
207
  module Schema
180
208
  def self.create
181
209
  ActiveRecord::Migration.verbose = false
@@ -234,6 +262,11 @@ module Schema
234
262
  t.integer :target_person_id
235
263
  t.integer :article_id
236
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
237
270
  end
238
271
 
239
272
  10.times do
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernie Miller
8
8
  - Ryan Bigg
9
9
  - Jon Atack
10
10
  - Sean Carroll
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-01-23 00:00:00.000000000 Z
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: 5.2.4
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: 5.2.4
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: 5.2.4
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: 5.2.4
43
+ version: 6.0.4
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: i18n
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -83,18 +83,16 @@ files:
83
83
  - bug_report_templates/test-ransacker-arel-present-predicate.rb
84
84
  - docs/img/create_release.png
85
85
  - docs/release_process.md
86
- - lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb
87
- - lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb
88
- - lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb
86
+ - lib/polyamorous.rb
89
87
  - lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb
90
88
  - lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb
91
89
  - lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb
92
90
  - lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb
93
91
  - lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb
94
92
  - lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
95
- - lib/polyamorous/activerecord_6.2_ruby_2/join_association.rb
96
- - lib/polyamorous/activerecord_6.2_ruby_2/join_dependency.rb
97
- - lib/polyamorous/activerecord_6.2_ruby_2/reflection.rb
93
+ - lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb
94
+ - lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb
95
+ - lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb
98
96
  - lib/polyamorous/join.rb
99
97
  - lib/polyamorous/polyamorous.rb
100
98
  - lib/polyamorous/swapping_reflection_class.rb
@@ -137,6 +135,7 @@ files:
137
135
  - lib/ransack/locale/ro.yml
138
136
  - lib/ransack/locale/ru.yml
139
137
  - lib/ransack/locale/sk.yml
138
+ - lib/ransack/locale/sv.yml
140
139
  - lib/ransack/locale/tr.yml
141
140
  - lib/ransack/locale/zh-CN.yml
142
141
  - lib/ransack/locale/zh-TW.yml
@@ -170,6 +169,7 @@ files:
170
169
  - spec/console.rb
171
170
  - spec/helpers/polyamorous_helper.rb
172
171
  - spec/helpers/ransack_helper.rb
172
+ - spec/polyamorous/activerecord_compatibility_spec.rb
173
173
  - spec/polyamorous/join_association_spec.rb
174
174
  - spec/polyamorous/join_dependency_spec.rb
175
175
  - spec/polyamorous/join_spec.rb
@@ -190,7 +190,7 @@ homepage: https://github.com/activerecord-hackery/ransack
190
190
  licenses:
191
191
  - MIT
192
192
  metadata: {}
193
- post_install_message:
193
+ post_install_message:
194
194
  rdoc_options: []
195
195
  require_paths:
196
196
  - lib
@@ -205,8 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  - !ruby/object:Gem::Version
206
206
  version: '0'
207
207
  requirements: []
208
- rubygems_version: 3.0.3
209
- signing_key:
208
+ rubygems_version: 3.3.9
209
+ signing_key:
210
210
  specification_version: 4
211
211
  summary: Object-based searching for Active Record and Mongoid (currently).
212
212
  test_files:
@@ -218,6 +218,7 @@ test_files:
218
218
  - spec/console.rb
219
219
  - spec/helpers/polyamorous_helper.rb
220
220
  - spec/helpers/ransack_helper.rb
221
+ - spec/polyamorous/activerecord_compatibility_spec.rb
221
222
  - spec/polyamorous/join_association_spec.rb
222
223
  - spec/polyamorous/join_dependency_spec.rb
223
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