ransack 1.8.3 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +26 -63
  4. data/CHANGELOG.md +187 -24
  5. data/CONTRIBUTING.md +9 -0
  6. data/Gemfile +5 -20
  7. data/README.md +163 -40
  8. data/Rakefile +1 -22
  9. data/lib/ransack/adapters/active_record/base.rb +11 -2
  10. data/lib/ransack/adapters/active_record/context.rb +178 -168
  11. data/lib/ransack/adapters/active_record/ransack/constants.rb +6 -3
  12. data/lib/ransack/adapters/active_record/ransack/context.rb +10 -16
  13. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +3 -3
  14. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  15. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  16. data/lib/ransack/adapters/active_record.rb +0 -9
  17. data/lib/ransack/adapters.rb +2 -0
  18. data/lib/ransack/configuration.rb +30 -4
  19. data/lib/ransack/constants.rb +4 -1
  20. data/lib/ransack/context.rb +29 -24
  21. data/lib/ransack/helpers/form_builder.rb +15 -3
  22. data/lib/ransack/helpers/form_helper.rb +8 -3
  23. data/lib/ransack/locale/ar.yml +70 -0
  24. data/lib/ransack/locale/az.yml +70 -0
  25. data/lib/ransack/locale/bg.yml +70 -0
  26. data/lib/ransack/locale/ca.yml +70 -0
  27. data/lib/ransack/locale/el.yml +70 -0
  28. data/lib/ransack/locale/es.yml +22 -22
  29. data/lib/ransack/locale/fa.yml +70 -0
  30. data/lib/ransack/locale/fi.yml +71 -0
  31. data/lib/ransack/locale/it.yml +70 -0
  32. data/lib/ransack/locale/nl.yml +4 -4
  33. data/lib/ransack/locale/ru.yml +70 -0
  34. data/lib/ransack/locale/tr.yml +70 -0
  35. data/lib/ransack/locale/zh-CN.yml +12 -12
  36. data/lib/ransack/nodes/attribute.rb +1 -1
  37. data/lib/ransack/nodes/grouping.rb +2 -7
  38. data/lib/ransack/nodes/value.rb +74 -68
  39. data/lib/ransack/predicate.rb +11 -19
  40. data/lib/ransack/search.rb +1 -1
  41. data/lib/ransack/translate.rb +115 -115
  42. data/lib/ransack/version.rb +1 -1
  43. data/lib/ransack/visitor.rb +1 -12
  44. data/lib/ransack.rb +5 -2
  45. data/logo/ransack-h.png +0 -0
  46. data/logo/ransack-h.svg +34 -0
  47. data/logo/ransack-v.png +0 -0
  48. data/logo/ransack-v.svg +34 -0
  49. data/logo/ransack.png +0 -0
  50. data/logo/ransack.svg +21 -0
  51. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +2 -0
  52. data/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +2 -0
  53. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +31 -0
  54. data/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +112 -0
  55. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +31 -0
  56. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +112 -0
  57. data/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb +12 -0
  58. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +22 -0
  59. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +81 -0
  60. data/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +2 -0
  61. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +2 -0
  62. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +81 -0
  63. data/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +2 -0
  64. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +2 -0
  65. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +2 -0
  66. data/polyamorous/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +2 -0
  67. data/polyamorous/lib/polyamorous/join.rb +70 -0
  68. data/polyamorous/lib/polyamorous/swapping_reflection_class.rb +11 -0
  69. data/polyamorous/lib/polyamorous/tree_node.rb +7 -0
  70. data/polyamorous/lib/polyamorous/version.rb +3 -0
  71. data/polyamorous/lib/polyamorous.rb +29 -0
  72. data/polyamorous/polyamorous.gemspec +35 -0
  73. data/ransack.gemspec +9 -10
  74. data/spec/helpers/polyamorous_helper.rb +28 -0
  75. data/spec/ransack/adapters/active_record/base_spec.rb +74 -0
  76. data/spec/ransack/adapters/active_record/context_spec.rb +44 -6
  77. data/spec/ransack/configuration_spec.rb +17 -2
  78. data/spec/ransack/helpers/form_builder_spec.rb +3 -15
  79. data/spec/ransack/helpers/form_helper_spec.rb +88 -151
  80. data/spec/ransack/join_association_spec.rb +28 -0
  81. data/spec/ransack/join_dependency_spec.rb +97 -0
  82. data/spec/ransack/join_spec.rb +19 -0
  83. data/spec/ransack/predicate_spec.rb +16 -2
  84. data/spec/ransack/search_spec.rb +32 -3
  85. data/spec/spec_helper.rb +5 -0
  86. data/spec/support/schema.rb +45 -21
  87. metadata +81 -67
  88. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  89. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
  90. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
  91. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  92. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  93. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  94. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  95. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  96. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  97. data/lib/ransack/adapters/mongoid/base.rb +0 -134
  98. data/lib/ransack/adapters/mongoid/context.rb +0 -212
  99. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  100. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  101. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  102. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  103. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  104. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  105. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  106. data/lib/ransack/adapters/mongoid.rb +0 -15
  107. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
  108. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  109. data/spec/mongoid/configuration_spec.rb +0 -162
  110. data/spec/mongoid/dependencies_spec.rb +0 -8
  111. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  112. data/spec/mongoid/nodes/condition_spec.rb +0 -49
  113. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  114. data/spec/mongoid/predicate_spec.rb +0 -155
  115. data/spec/mongoid/search_spec.rb +0 -445
  116. data/spec/mongoid/support/mongoid.yml +0 -11
  117. data/spec/mongoid/support/schema.rb +0 -135
  118. data/spec/mongoid/translate_spec.rb +0 -14
  119. data/spec/mongoid_spec_helper.rb +0 -63
  120. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,24 +0,0 @@
1
- module Ransack
2
- class Visitor
3
- def visit_and(object)
4
- nodes = object.values.map { |o| accept(o) }.compact
5
- return nil unless nodes.size > 0
6
-
7
- if nodes.size > 1
8
- nodes.inject(&:and)
9
- else
10
- nodes.first
11
- end
12
- end
13
-
14
- def quoted?(object)
15
- case object
16
- when Arel::Nodes::SqlLiteral, Bignum, Fixnum
17
- false
18
- else
19
- true
20
- end
21
- end
22
-
23
- end
24
- end
@@ -1,35 +0,0 @@
1
- module Ransack
2
- module Adapters
3
- module Mongoid
4
- class Table
5
- attr_accessor :name
6
-
7
- alias :table_name :name
8
-
9
- def initialize(object, engine = nil)
10
- @object = object
11
- @name = object.collection.name
12
- @engine = engine
13
- @columns = nil
14
- @aliases = []
15
- @table_alias = nil
16
- @primary_key = nil
17
-
18
- if Hash === engine
19
- # @engine = engine[:engine] || Table.engine
20
-
21
- # Sometime AR sends an :as parameter to table, to let the table know
22
- # that it is an Alias. We may want to override new, and return a
23
- # TableAlias node?
24
- # @table_alias = engine[:as] unless engine[:as].to_s == @name
25
- end
26
- end
27
-
28
- def [](name)
29
- Ransack::Adapters::Mongoid::Attribute.new self, name
30
- end
31
-
32
- end
33
- end
34
- end
35
- end
@@ -1,15 +0,0 @@
1
- require 'ransack/adapters/mongoid/base'
2
- ::Mongoid::Document.send :include, Ransack::Adapters::Mongoid::Base
3
-
4
- require 'ransack/adapters/mongoid/attributes/attribute'
5
- require 'ransack/adapters/mongoid/table'
6
- require 'ransack/adapters/mongoid/inquiry_hash'
7
-
8
- case ::Mongoid::VERSION
9
- when /^3\.2\./
10
- require 'ransack/adapters/mongoid/3.2/context'
11
- else
12
- require 'ransack/adapters/mongoid/context'
13
- end
14
-
15
- Ransack::SUPPORTS_ATTRIBUTE_ALIAS = false
@@ -1,314 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- module Adapters
5
- module Mongoid
6
- describe Base do
7
-
8
- subject { Person }
9
-
10
- it { should respond_to :ransack }
11
- it { should respond_to :search }
12
-
13
- describe '#search' do
14
- subject { Person.search }
15
-
16
- it { should be_a Search }
17
- it 'has a Mongoid::Criteria as its object' do
18
- expect(subject.object).to be_an ::Mongoid::Criteria
19
- end
20
-
21
- context 'with scopes' do
22
- before do
23
- allow(Person)
24
- .to receive(:ransackable_scopes)
25
- .and_return([:active, :over_age])
26
- end
27
-
28
- it "applies true scopes" do
29
- search = Person.search('active' => true)
30
- expect(search.result.selector).to eq({ 'active' => 1 })
31
- end
32
-
33
- it "ignores unlisted scopes" do
34
- search = Person.search('restricted' => true)
35
- expect(search.result.selector).to_not eq({ 'restricted' => 1})
36
- end
37
-
38
- it "ignores false scopes" do
39
- search = Person.search('active' => false)
40
- expect(search.result.selector).to_not eq({ 'active' => 1 })
41
- end
42
-
43
- it "passes values to scopes" do
44
- search = Person.search('over_age' => 18)
45
- expect(search.result.selector).to eq({ 'age' => { '$gt' => 18 } })
46
- end
47
-
48
- it "chains scopes" do
49
- search = Person.search('over_age' => 18, 'active' => true)
50
- expect(search.result.selector).to eq({ 'age' => { '$gt' => 18 }, 'active' => 1 })
51
- end
52
- end
53
- end
54
-
55
- describe '#ransack_alias' do
56
- it 'translates an alias to the correct attributes' do
57
- p = Person.create!(name: 'Meatloaf', email: 'babies@example.com')
58
-
59
- s = Person.ransack(term_cont: 'atlo')
60
- expect(s.result.to_a).to eq [p]
61
-
62
- s = Person.ransack(term_cont: 'babi')
63
- expect(s.result.to_a).to eq [p]
64
-
65
- s = Person.ransack(term_cont: 'nomatch')
66
- expect(s.result.to_a).to eq []
67
- end
68
-
69
- it 'makes aliases available to subclasses' do
70
- yngwie = Musician.create!(name: 'Yngwie Malmsteen')
71
-
72
- musicians = Musician.ransack(term_cont: 'ngw').result
73
- expect(musicians).to eq([yngwie])
74
- end
75
-
76
- it 'handles naming collisions gracefully' do
77
- frank = Person.create!(name: 'Frank Stallone')
78
-
79
- people = Person.ransack(term_cont: 'allon').result
80
- expect(people).to eq([frank])
81
-
82
- Class.new(Article) do
83
- ransack_alias :term, :title
84
- end
85
-
86
- people = Person.ransack(term_cont: 'allon').result
87
- expect(people).to eq([frank])
88
- end
89
- end
90
-
91
- describe '#ransacker' do
92
- # For infix tests
93
- def self.sane_adapter?
94
- case ::Mongoid::Document.connection.adapter_name
95
- when "SQLite3", "PostgreSQL"
96
- true
97
- else
98
- false
99
- end
100
- end
101
- # # in schema.rb, class Person:
102
- # ransacker :reversed_name, formatter: proc { |v| v.reverse } do |parent|
103
- # parent.table[:name]
104
- # end
105
-
106
- # ransacker :doubled_name do |parent|
107
- # Arel::Nodes::InfixOperation.new(
108
- # '||', parent.table[:name], parent.table[:name]
109
- # )
110
- # end
111
-
112
- it 'creates ransack attributes' do
113
- s = Person.search(:reversed_name_eq => 'htimS cirA')
114
- expect(s.result.size).to eq(Person.where(name: 'Aric Smith').count)
115
-
116
- expect(s.result.first).to eq Person.where(name: 'Aric Smith').first
117
- end
118
-
119
- context 'with joins' do
120
- before { pending 'not implemented for mongoid' }
121
-
122
- it 'can be accessed through associations' do
123
- s = Person.search(:children_reversed_name_eq => 'htimS cirA')
124
- expect(s.result.to_sql).to match(
125
- /#{quote_table_name("children_people")}.#{
126
- quote_column_name("name")} = 'Aric Smith'/
127
- )
128
- end
129
-
130
- it "should keep proper key value pairs in the params hash" do
131
- s = Person.search(:children_reversed_name_eq => 'Testing')
132
- expect(s.result.to_sql).to match /LEFT OUTER JOIN/
133
- end
134
-
135
- end
136
-
137
- it 'allows an "attribute" to be an InfixOperation' do
138
- s = Person.search(:doubled_name_eq => 'Aric SmithAric Smith')
139
- expect(s.result.first).to eq Person.where(name: 'Aric Smith').first
140
- end if defined?(Arel::Nodes::InfixOperation) && sane_adapter?
141
-
142
- it "doesn't break #count if using InfixOperations" do
143
- s = Person.search(:doubled_name_eq => 'Aric SmithAric Smith')
144
- expect(s.result.count).to eq 1
145
- end if defined?(Arel::Nodes::InfixOperation) && sane_adapter?
146
-
147
- it "should remove empty key value pairs from the params hash" do
148
- s = Person.search(:reversed_name_eq => '')
149
- expect(s.result.selector).to eq({})
150
- end
151
-
152
- it "should function correctly when nil is passed in" do
153
- s = Person.search(nil)
154
- end
155
-
156
- it "should function correctly when a blank string is passed in" do
157
- s = Person.search('')
158
- end
159
-
160
- it "should function correctly when using fields with dots in them" do
161
- s = Person.search(:email_cont => "example.com")
162
- expect(s.result.exists?).to be true
163
-
164
- s = Person.search(:email_cont => "example.co.")
165
- expect(s.result.exists?).not_to be true
166
- end
167
-
168
- it "should function correctly when using fields with % in them" do
169
- Person.create!(:name => "110%-er")
170
- s = Person.search(:name_cont => "10%")
171
- expect(s.result.exists?).to be true
172
- end
173
-
174
- it "should function correctly when using fields with backslashes in them" do
175
- Person.create!(:name => "\\WINNER\\")
176
- s = Person.search(:name_cont => "\\WINNER\\")
177
- expect(s.result.exists?).to be true
178
- end
179
-
180
- it 'allows sort by "only_sort" field' do
181
- pending "it doesn't work :("
182
- s = Person.search(
183
- "s" => { "0" => { "dir" => "desc", "name" => "only_sort" } }
184
- )
185
- expect(s.result.to_sql).to match(
186
- /ORDER BY #{quote_table_name("people")}.#{
187
- quote_column_name("only_sort")} ASC/
188
- )
189
- end
190
-
191
- it "doesn't sort by 'only_search' field" do
192
- pending "it doesn't work :("
193
- s = Person.search(
194
- "s" => { "0" => { "dir" => "asc", "name" => "only_search" } }
195
- )
196
- expect(s.result.to_sql).not_to match(
197
- /ORDER BY #{quote_table_name("people")}.#{
198
- quote_column_name("only_search")} ASC/
199
- )
200
- end
201
-
202
- it 'allows search by "only_search" field' do
203
- s = Person.search(:only_search_eq => 'htimS cirA')
204
- expect(s.result.selector).to eq({'only_search' => 'htimS cirA'})
205
- end
206
-
207
- it "can't be searched by 'only_sort'" do
208
- s = Person.search(:only_sort_eq => 'htimS cirA')
209
- expect(s.result.selector).not_to eq({'only_sort' => 'htimS cirA'})
210
- end
211
-
212
- it 'allows sort by "only_admin" field, if auth_object: :admin' do
213
- s = Person.search(
214
- { "s" => { "0" => { "dir" => "asc", "name" => "only_admin" } } },
215
- { auth_object: :admin }
216
- )
217
- expect(s.result.options).to eq({ sort: { '_id' => -1, 'only_admin' => 1 } })
218
- end
219
-
220
- it "doesn't sort by 'only_admin' field, if auth_object: nil" do
221
- s = Person.search(
222
- "s" => { "0" => { "dir" => "asc", "name" => "only_admin" } }
223
- )
224
- expect(s.result.options).to eq({ sort: {'_id' => -1}})
225
- end
226
-
227
- it 'allows search by "only_admin" field, if auth_object: :admin' do
228
- s = Person.search(
229
- { :only_admin_eq => 'htimS cirA' },
230
- { :auth_object => :admin }
231
- )
232
- expect(s.result.selector).to eq({ 'only_admin' => 'htimS cirA' })
233
- end
234
-
235
- it "can't be searched by 'only_admin', if auth_object: nil" do
236
- s = Person.search(:only_admin_eq => 'htimS cirA')
237
- expect(s.result.selector).to eq({})
238
- end
239
-
240
- it 'searches by id' do
241
- ids = ['some_bson_id', 'another_bson_id']
242
- s = Person.search(:id_in => ids)
243
- expect(s.result.selector).to eq({ '_id' => { '$in' => ids } })
244
- end
245
- end
246
-
247
- describe '#ransackable_attributes' do
248
- context 'when auth_object is nil' do
249
- subject { Person.ransackable_attributes }
250
-
251
- it { should include 'name' }
252
- it { should include 'reversed_name' }
253
- it { should include 'doubled_name' }
254
- it { should include 'term' }
255
- it { should include 'only_search' }
256
- it { should_not include 'only_sort' }
257
- it { should_not include 'only_admin' }
258
- end
259
-
260
- context 'with auth_object :admin' do
261
- subject { Person.ransackable_attributes(:admin) }
262
-
263
- it { should include 'name' }
264
- it { should include 'reversed_name' }
265
- it { should include 'doubled_name' }
266
- it { should include 'term' }
267
- it { should include 'only_search' }
268
- it { should_not include 'only_sort' }
269
- it { should include 'only_admin' }
270
- end
271
- end
272
-
273
- describe '#ransortable_attributes' do
274
- context 'when auth_object is nil' do
275
- subject { Person.ransortable_attributes }
276
-
277
- it { should include 'name' }
278
- it { should include 'reversed_name' }
279
- it { should include 'doubled_name' }
280
- it { should include 'only_sort' }
281
- it { should_not include 'only_search' }
282
- it { should_not include 'only_admin' }
283
- end
284
-
285
- context 'with auth_object :admin' do
286
- subject { Person.ransortable_attributes(:admin) }
287
-
288
- it { should include 'name' }
289
- it { should include 'reversed_name' }
290
- it { should include 'doubled_name' }
291
- it { should include 'only_sort' }
292
- it { should_not include 'only_search' }
293
- it { should include 'only_admin' }
294
- end
295
- end
296
-
297
- describe '#ransackable_associations' do
298
- subject { Person.ransackable_associations }
299
-
300
- it { should include 'parent' }
301
- it { should include 'children' }
302
- it { should include 'articles' }
303
- end
304
-
305
- describe '#ransackable_scopes' do
306
- subject { Person.ransackable_scopes }
307
-
308
- it { should eq [] }
309
- end
310
-
311
- end
312
- end
313
- end
314
- end
@@ -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