ransack 1.8.10 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +12 -3
  4. data/CHANGELOG.md +29 -5
  5. data/Gemfile +1 -9
  6. data/README.md +16 -25
  7. data/Rakefile +1 -22
  8. data/lib/polyamorous.rb +5 -18
  9. data/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +2 -2
  10. data/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +2 -2
  11. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +38 -0
  12. data/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +75 -0
  13. data/lib/ransack/adapters/active_record.rb +0 -9
  14. data/lib/ransack/adapters/active_record/base.rb +8 -0
  15. data/lib/ransack/adapters/active_record/context.rb +118 -182
  16. data/lib/ransack/adapters/active_record/ransack/context.rb +1 -8
  17. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  18. data/lib/ransack/constants.rb +1 -1
  19. data/lib/ransack/context.rb +4 -0
  20. data/lib/ransack/nodes/value.rb +1 -1
  21. data/lib/ransack/search.rb +1 -1
  22. data/lib/ransack/version.rb +1 -1
  23. data/ransack.gemspec +4 -3
  24. data/spec/helpers/polyamorous_helper.rb +7 -9
  25. data/spec/ransack/adapters/active_record/base_spec.rb +35 -0
  26. data/spec/ransack/adapters/active_record/context_spec.rb +3 -6
  27. data/spec/ransack/helpers/form_builder_spec.rb +3 -15
  28. data/spec/ransack/helpers/form_helper_spec.rb +11 -99
  29. data/spec/ransack/join_association_spec.rb +1 -6
  30. data/spec/ransack/join_dependency_spec.rb +1 -6
  31. data/spec/ransack/search_spec.rb +2 -2
  32. data/spec/support/schema.rb +3 -21
  33. metadata +10 -83
  34. data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_association.rb +0 -76
  35. data/lib/polyamorous/activerecord_3_and_4.0_ruby_1.9/join_dependency.rb +0 -96
  36. data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_association.rb +0 -2
  37. data/lib/polyamorous/activerecord_4.1_ruby_1.9/join_dependency.rb +0 -4
  38. data/lib/polyamorous/activerecord_4.1_ruby_2/join_association.rb +0 -2
  39. data/lib/polyamorous/activerecord_4.1_ruby_2/join_dependency.rb +0 -3
  40. data/lib/polyamorous/activerecord_4.1_ruby_2/make_polyamorous_inner_joins.rb +0 -14
  41. data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_association.rb +0 -46
  42. data/lib/polyamorous/activerecord_4.2_ruby_1.9/join_dependency.rb +0 -87
  43. data/lib/polyamorous/activerecord_4.2_ruby_2/join_association.rb +0 -2
  44. data/lib/polyamorous/activerecord_4.2_ruby_2/join_dependency.rb +0 -24
  45. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -173
  46. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
  47. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
  48. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  49. data/lib/ransack/adapters/mongoid.rb +0 -15
  50. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  51. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  52. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  53. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  54. data/lib/ransack/adapters/mongoid/base.rb +0 -134
  55. data/lib/ransack/adapters/mongoid/context.rb +0 -212
  56. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  57. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  58. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -59
  59. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -22
  60. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  61. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -18
  62. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  63. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
  64. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  65. data/spec/mongoid/configuration_spec.rb +0 -162
  66. data/spec/mongoid/dependencies_spec.rb +0 -8
  67. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  68. data/spec/mongoid/nodes/condition_spec.rb +0 -49
  69. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  70. data/spec/mongoid/predicate_spec.rb +0 -155
  71. data/spec/mongoid/search_spec.rb +0 -445
  72. data/spec/mongoid/support/mongoid.yml +0 -11
  73. data/spec/mongoid/support/schema.rb +0 -135
  74. data/spec/mongoid/translate_spec.rb +0 -14
  75. data/spec/mongoid_spec_helper.rb +0 -63
  76. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,56 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- module Adapters
5
- module Mongoid
6
- describe Context do
7
- subject { Context.new(Person) }
8
-
9
- describe '#relation_for' do
10
- before { pending "not implemented for mongoid" }
11
- it 'returns relation for given object' do
12
- expect(subject.object).to be_an ::ActiveRecord::Relation
13
- end
14
- end
15
-
16
- describe '#evaluate' do
17
- it 'evaluates search objects' do
18
- search = Search.new(Person, :name_eq => 'Joe Blow')
19
- result = subject.evaluate(search)
20
-
21
- expect(result).to be_an ::Mongoid::Criteria
22
- expect(result.selector).to eq({ 'name' => 'Joe Blow' })
23
- end
24
-
25
- it 'SELECTs DISTINCT when distinct: true' do
26
- pending "distinct doesn't work"
27
-
28
- search = Search.new(Person, :name_eq => 'Joe Blow')
29
- result = subject.evaluate(search, :distinct => true)
30
-
31
- expect(result).to be_an ::ActiveRecord::Relation
32
- expect(result.to_sql).to match /SELECT DISTINCT/
33
- end
34
- end
35
-
36
- it 'contextualizes strings to attributes' do
37
- attribute = subject.contextualize 'name'
38
- expect(attribute).to be_a ::Ransack::Adapters::Mongoid::Attributes::Attribute
39
- expect(attribute.name.to_s).to eq 'name'
40
- # expect(attribute.relation.table_alias).to eq 'parents_people'
41
- end
42
-
43
- it 'builds new associations if not yet built' do
44
- pending "not implemented for mongoid"
45
-
46
- attribute = subject.contextualize 'children_articles_title'
47
- expect(attribute).to be_a Arel::Attributes::Attribute
48
- expect(attribute.name.to_s).to eq 'title'
49
- expect(attribute.relation.name).to eq 'articles'
50
- expect(attribute.relation.table_alias).to be_nil
51
- end
52
-
53
- end
54
- end
55
- end
56
- end
@@ -1,162 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- describe Configuration do
5
- it 'yields Ransack on configure' do
6
- Ransack.configure { |config| expect(config).to eq Ransack }
7
- end
8
-
9
- it 'adds predicates' do
10
- Ransack.configure do |config|
11
- config.add_predicate :test_predicate
12
- end
13
-
14
- expect(Ransack.predicates).to have_key 'test_predicate'
15
- expect(Ransack.predicates).to have_key 'test_predicate_any'
16
- expect(Ransack.predicates).to have_key 'test_predicate_all'
17
- end
18
-
19
- it 'avoids creating compound predicates if compounds: false' do
20
- Ransack.configure do |config|
21
- config.add_predicate(
22
- :test_predicate_without_compound,
23
- :compounds => false
24
- )
25
- end
26
- expect(Ransack.predicates)
27
- .to have_key 'test_predicate_without_compound'
28
- expect(Ransack.predicates)
29
- .not_to have_key 'test_predicate_without_compound_any'
30
- expect(Ransack.predicates)
31
- .not_to have_key 'test_predicate_without_compound_all'
32
- end
33
-
34
- it 'should have default value for search key' do
35
- expect(Ransack.options[:search_key]).to eq :q
36
- end
37
-
38
- it 'changes default search key parameter' do
39
- default = Ransack.options.clone
40
-
41
- Ransack.configure { |c| c.search_key = :query }
42
-
43
- expect(Ransack.options[:search_key]).to eq :query
44
-
45
- Ransack.options = default
46
- end
47
-
48
- it 'should have default values for arrows' do
49
- expect(Ransack.options[:up_arrow]).to eq '▼'
50
- expect(Ransack.options[:down_arrow]).to eq '▲'
51
- end
52
-
53
- it 'changes the default value for the up arrow only' do
54
- default, new_up_arrow = Ransack.options.clone, 'U+02191'
55
-
56
- Ransack.configure { |c| c.custom_arrows = { up_arrow: new_up_arrow } }
57
-
58
- expect(Ransack.options[:down_arrow]).to eq default[:down_arrow]
59
- expect(Ransack.options[:up_arrow]).to eq new_up_arrow
60
-
61
- Ransack.options = default
62
- end
63
-
64
- it 'changes the default value for the down arrow only' do
65
- default, new_down_arrow = Ransack.options.clone, '<i class="down"></i>'
66
-
67
- Ransack.configure { |c| c.custom_arrows = { down_arrow: new_down_arrow } }
68
-
69
- expect(Ransack.options[:up_arrow]).to eq default[:up_arrow]
70
- expect(Ransack.options[:down_arrow]).to eq new_down_arrow
71
-
72
- Ransack.options = default
73
- end
74
-
75
- it 'changes the default value for both arrows' do
76
- default = Ransack.options.clone
77
- new_up_arrow = '<i class="fa fa-long-arrow-up"></i>'
78
- new_down_arrow = 'U+02193'
79
-
80
- Ransack.configure do |c|
81
- c.custom_arrows = { up_arrow: new_up_arrow, down_arrow: new_down_arrow }
82
- end
83
-
84
- expect(Ransack.options[:up_arrow]).to eq new_up_arrow
85
- expect(Ransack.options[:down_arrow]).to eq new_down_arrow
86
-
87
- Ransack.options = default
88
- end
89
-
90
- it 'consecutive arrow customizations respect previous customizations' do
91
- default = Ransack.options.clone
92
-
93
- Ransack.configure { |c| c.custom_arrows = { up_arrow: 'up' } }
94
- expect(Ransack.options[:down_arrow]).to eq default[:down_arrow]
95
-
96
- Ransack.configure { |c| c.custom_arrows = { down_arrow: 'DOWN' } }
97
- expect(Ransack.options[:up_arrow]).to eq 'up'
98
-
99
- Ransack.configure { |c| c.custom_arrows = { up_arrow: '<i>U-Arrow</i>' } }
100
- expect(Ransack.options[:down_arrow]).to eq 'DOWN'
101
-
102
- Ransack.configure { |c| c.custom_arrows = { down_arrow: 'down arrow-2' } }
103
- expect(Ransack.options[:up_arrow]).to eq '<i>U-Arrow</i>'
104
-
105
- Ransack.options = default
106
- end
107
-
108
- it 'adds predicates that take arrays, overriding compounds' do
109
- Ransack.configure do |config|
110
- config.add_predicate(
111
- :test_array_predicate,
112
- :wants_array => true,
113
- :compounds => true
114
- )
115
- end
116
-
117
- expect(Ransack.predicates['test_array_predicate'].wants_array).to eq true
118
- expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
119
- expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
120
- end
121
-
122
- describe '`wants_array` option takes precedence over Arel predicate' do
123
- it 'implicitly wants an array for in/not in predicates' do
124
- Ransack.configure do |config|
125
- config.add_predicate(
126
- :test_in_predicate,
127
- :arel_predicate => 'in'
128
- )
129
- config.add_predicate(
130
- :test_not_in_predicate,
131
- :arel_predicate => 'not_in'
132
- )
133
- end
134
-
135
- expect(Ransack.predicates['test_in_predicate'].wants_array)
136
- .to eq true
137
- expect(Ransack.predicates['test_not_in_predicate'].wants_array)
138
- .to eq true
139
- end
140
-
141
- it 'explicitly does not want array for in/not_in predicates' do
142
- Ransack.configure do |config|
143
- config.add_predicate(
144
- :test_in_predicate_no_array,
145
- :arel_predicate => 'in',
146
- :wants_array => false
147
- )
148
- config.add_predicate(
149
- :test_not_in_predicate_no_array,
150
- :arel_predicate => 'not_in',
151
- :wants_array => false
152
- )
153
- end
154
-
155
- expect(Ransack.predicates['test_in_predicate_no_array'].wants_array)
156
- .to eq false
157
- expect(Ransack.predicates['test_not_in_predicate_no_array'].wants_array)
158
- .to eq false
159
- end
160
- end
161
- end
162
- end
@@ -1,8 +0,0 @@
1
- unless ::ActiveSupport::VERSION::STRING >= '4'
2
- describe 'Ransack' do
3
- it 'can be required without errors' do
4
- output = `bundle exec ruby -e "require 'ransack'" 2>&1`
5
- expect(output).to be_empty
6
- end
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- module RansackHelper
2
- def quote_table_name(table)
3
- # ActiveRecord::Base.connection.quote_table_name(table)
4
- table
5
- end
6
-
7
- def quote_column_name(column)
8
- # ActiveRecord::Base.connection.quote_column_name(column)
9
- column
10
- end
11
- end
@@ -1,49 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- module Nodes
5
- describe Condition do
6
-
7
- context 'with an alias' do
8
- subject {
9
- Condition.extract(
10
- Context.for(Person), 'term_start', Person.first(2).map(&:name)
11
- )
12
- }
13
-
14
- specify { expect(subject.combinator).to eq 'or' }
15
- specify { expect(subject.predicate.name).to eq 'start' }
16
-
17
- it 'converts the alias to the correct attributes' do
18
- expect(subject.attributes.map(&:name)).to eq(['name', 'email'])
19
- end
20
- end
21
-
22
- context 'with multiple values and an _any predicate' do
23
- subject { Condition.extract(Context.for(Person), 'name_eq_any', Person.first(2).map(&:name)) }
24
-
25
- specify { expect(subject.values.size).to eq(2) }
26
- end
27
-
28
- context 'with an invalid predicate' do
29
- subject { Condition.extract(Context.for(Person), 'name_invalid', Person.first.name) }
30
-
31
- context "when ignore_unknown_conditions is false" do
32
- before do
33
- Ransack.configure { |config| config.ignore_unknown_conditions = false }
34
- end
35
-
36
- specify { expect { subject }.to raise_error ArgumentError }
37
- end
38
-
39
- context "when ignore_unknown_conditions is true" do
40
- before do
41
- Ransack.configure { |config| config.ignore_unknown_conditions = true }
42
- end
43
-
44
- specify { expect(subject).to be_nil }
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,13 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- module Nodes
5
- describe Grouping do
6
- before do
7
- @g = 1
8
- end
9
-
10
-
11
- end
12
- end
13
- end
@@ -1,155 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- describe Predicate do
5
-
6
- before do
7
- @s = Search.new(Person)
8
- end
9
-
10
- shared_examples 'wildcard escaping' do |method, value|
11
- it 'automatically converts integers to strings' do
12
- subject.parent_id_cont = 1
13
- expect { subject.result }.to_not raise_error
14
- end
15
-
16
- it "escapes '%', '.' and '\\\\' in value" do
17
- subject.send(:"#{method}=", '%._\\')
18
- expect(subject.result.selector).to eq(value)
19
- end
20
- end
21
-
22
- describe 'eq' do
23
- it 'generates an equality condition for boolean true' do
24
- @s.awesome_eq = true
25
- expect(@s.result.selector).to eq({ "awesome" => true })
26
- end
27
-
28
- it 'generates an equality condition for boolean false' do
29
- @s.awesome_eq = false
30
- expect(@s.result.selector).to eq({ "awesome" => false })
31
- end
32
-
33
- it 'does not generate a condition for nil' do
34
- @s.awesome_eq = nil
35
- expect(@s.result.selector).to eq({ })
36
- end
37
- end
38
-
39
- describe 'cont' do
40
- it_has_behavior 'wildcard escaping', :name_cont, { 'name' => /%\._\\/i } do
41
- subject { @s }
42
- end
43
-
44
- it 'generates a regex query' do
45
- @s.name_cont = 'ric'
46
- expect(@s.result.selector).to eq({ 'name' => /ric/i })
47
- end
48
- end
49
-
50
- describe 'not_cont' do
51
- it_has_behavior 'wildcard escaping', :name_not_cont, { "$not" => { 'name' => /%\._\\/i } } do
52
- subject { @s }
53
- end
54
-
55
- it 'generates a regex query' do
56
- @s.name_not_cont = 'ric'
57
- expect(@s.result.selector).to eq({ "$not" => { 'name' => /ric/i } })
58
- end
59
- end
60
-
61
- describe 'null' do
62
- it 'generates a value IS NULL query' do
63
- @s.name_null = true
64
- expect(@s.result.selector).to eq({ 'name' => nil })
65
- end
66
-
67
- it 'generates a value IS NOT NULL query when assigned false' do
68
- @s.name_null = false
69
- expect(@s.result.selector).to eq( { 'name' => { '$ne' => nil } })
70
- end
71
- end
72
-
73
- describe 'not_null' do
74
- it 'generates a value IS NOT NULL query' do
75
- @s.name_not_null = true
76
- expect(@s.result.selector).to eq({ 'name' => { '$ne' => nil } })
77
- end
78
-
79
- it 'generates a value IS NULL query when assigned false' do
80
- @s.name_not_null = false
81
- expect(@s.result.selector).to eq({ 'name' => nil })
82
- end
83
- end
84
-
85
- describe 'present' do
86
- it %q[generates a value IS NOT NULL AND value != '' query] do
87
- @s.name_present = true
88
- expect(@s.result.selector).to eq({ '$and' => [ { 'name' => { '$ne' => nil } }, { 'name' => { '$ne' => '' } } ] })
89
- end
90
-
91
- it %q[generates a value IS NULL OR value = '' query when assigned false] do
92
- @s.name_present = false
93
- expect(@s.result.selector).to eq({ '$or' => [ { 'name' => nil }, { 'name' => '' } ] })
94
- end
95
- end
96
-
97
- describe 'blank' do
98
- it %q[generates a value IS NULL OR value = '' query] do
99
- @s.name_blank = true
100
- expect(@s.result.selector).to eq({ '$or' => [ { 'name' => nil}, { 'name' => '' } ] })
101
- end
102
-
103
- it %q[generates a value IS NOT NULL AND value != '' query when assigned false] do
104
- @s.name_blank = false
105
- expect(@s.result.selector).to eq({ '$and' => [ { 'name' => { '$ne' => nil}}, { 'name' => { '$ne' => '' }} ] })
106
- end
107
- end
108
-
109
- describe 'gt' do
110
- it 'generates an greater than for time' do
111
- time = Time.now
112
- @s.created_at_gt = time
113
- expect(@s.result.selector).to eq({ "created_at" => { '$gt' => time } })
114
- end
115
- end
116
-
117
- describe 'lt' do
118
- it 'generates an greater than for time' do
119
- time = Time.now
120
- @s.created_at_lt = time
121
- expect(@s.result.selector).to eq({ "created_at" => { '$lt' => time } })
122
- end
123
- end
124
-
125
- describe 'gteq' do
126
- it 'generates an greater than for time' do
127
- time = Time.now
128
- @s.created_at_gteq = time
129
- expect(@s.result.selector).to eq({ "created_at" => { '$gte' => time } })
130
- end
131
- end
132
-
133
- describe 'lteq' do
134
- it 'generates an greater than for time' do
135
- time = Time.now
136
- @s.created_at_lteq = time
137
- expect(@s.result.selector).to eq({ "created_at" => { '$lte' => time } })
138
- end
139
- end
140
-
141
- describe 'starts_with' do
142
- it 'generates an starts_with' do
143
- @s.name_start = 'ric'
144
- expect(@s.result.selector).to eq({ "name" => /\Aric/i })
145
- end
146
- end
147
-
148
- describe 'ends_with' do
149
- it 'generates an ends_with' do
150
- @s.name_end = 'ric'
151
- expect(@s.result.selector).to eq({ "name" => /ric\Z/i })
152
- end
153
- end
154
- end
155
- end