ransack 1.7.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/SECURITY.md +12 -0
  4. data/.github/workflows/test.yml +120 -0
  5. data/.gitignore +3 -0
  6. data/CHANGELOG.md +463 -27
  7. data/CONTRIBUTING.md +52 -22
  8. data/Gemfile +24 -24
  9. data/README.md +453 -126
  10. data/Rakefile +6 -25
  11. data/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +24 -0
  12. data/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +79 -0
  13. data/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +11 -0
  14. data/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +1 -0
  15. data/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +80 -0
  16. data/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +1 -0
  17. data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +74 -0
  18. data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +93 -0
  19. data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +1 -0
  20. data/lib/polyamorous/join.rb +70 -0
  21. data/lib/polyamorous/polyamorous.rb +24 -0
  22. data/lib/polyamorous/swapping_reflection_class.rb +11 -0
  23. data/lib/polyamorous/tree_node.rb +7 -0
  24. data/lib/ransack/adapters/active_record/base.rb +27 -2
  25. data/lib/ransack/adapters/active_record/context.rb +213 -139
  26. data/lib/ransack/adapters/active_record/ransack/constants.rb +70 -55
  27. data/lib/ransack/adapters/active_record/ransack/context.rb +10 -18
  28. data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +42 -32
  29. data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
  30. data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
  31. data/lib/ransack/adapters/active_record.rb +11 -10
  32. data/lib/ransack/adapters.rb +45 -23
  33. data/lib/ransack/configuration.rb +107 -4
  34. data/lib/ransack/constants.rb +13 -26
  35. data/lib/ransack/context.rb +45 -33
  36. data/lib/ransack/helpers/form_builder.rb +21 -12
  37. data/lib/ransack/helpers/form_helper.rb +75 -70
  38. data/lib/ransack/locale/ar.yml +70 -0
  39. data/lib/ransack/locale/az.yml +70 -0
  40. data/lib/ransack/locale/bg.yml +70 -0
  41. data/lib/ransack/locale/ca.yml +70 -0
  42. data/lib/ransack/locale/da.yml +70 -0
  43. data/lib/ransack/locale/el.yml +70 -0
  44. data/lib/ransack/locale/es.yml +22 -22
  45. data/lib/ransack/locale/fa.yml +70 -0
  46. data/lib/ransack/locale/fi.yml +71 -0
  47. data/lib/ransack/locale/id.yml +70 -0
  48. data/lib/ransack/locale/it.yml +70 -0
  49. data/lib/ransack/locale/ja.yml +70 -0
  50. data/lib/ransack/locale/nl.yml +4 -4
  51. data/lib/ransack/locale/pt-BR.yml +70 -0
  52. data/lib/ransack/locale/ru.yml +70 -0
  53. data/lib/ransack/locale/sk.yml +70 -0
  54. data/lib/ransack/locale/tr.yml +70 -0
  55. data/lib/ransack/locale/{zh.yml → zh-CN.yml} +13 -13
  56. data/lib/ransack/locale/zh-TW.yml +70 -0
  57. data/lib/ransack/nodes/attribute.rb +5 -2
  58. data/lib/ransack/nodes/bindable.rb +18 -6
  59. data/lib/ransack/nodes/condition.rb +85 -28
  60. data/lib/ransack/nodes/grouping.rb +17 -11
  61. data/lib/ransack/nodes/sort.rb +9 -5
  62. data/lib/ransack/nodes/value.rb +74 -68
  63. data/lib/ransack/nodes.rb +1 -1
  64. data/lib/ransack/predicate.rb +17 -20
  65. data/lib/ransack/search.rb +17 -8
  66. data/lib/ransack/translate.rb +115 -115
  67. data/lib/ransack/version.rb +1 -1
  68. data/lib/ransack/visitor.rb +1 -12
  69. data/lib/ransack.rb +9 -9
  70. data/logo/ransack-h.png +0 -0
  71. data/logo/ransack-h.svg +34 -0
  72. data/logo/ransack-v.png +0 -0
  73. data/logo/ransack-v.svg +34 -0
  74. data/logo/ransack.png +0 -0
  75. data/logo/ransack.svg +21 -0
  76. data/ransack.gemspec +7 -24
  77. data/spec/console.rb +4 -0
  78. data/spec/helpers/polyamorous_helper.rb +19 -0
  79. data/spec/polyamorous/join_association_spec.rb +35 -0
  80. data/spec/polyamorous/join_dependency_spec.rb +97 -0
  81. data/spec/polyamorous/join_spec.rb +19 -0
  82. data/spec/ransack/adapters/active_record/base_spec.rb +370 -75
  83. data/spec/ransack/adapters/active_record/context_spec.rb +72 -34
  84. data/spec/ransack/configuration_spec.rb +97 -14
  85. data/spec/ransack/helpers/form_builder_spec.rb +2 -11
  86. data/spec/ransack/helpers/form_helper_spec.rb +481 -113
  87. data/spec/ransack/nodes/condition_spec.rb +24 -0
  88. data/spec/ransack/nodes/grouping_spec.rb +56 -0
  89. data/spec/ransack/predicate_spec.rb +79 -5
  90. data/spec/ransack/search_spec.rb +207 -81
  91. data/spec/spec_helper.rb +8 -0
  92. data/spec/support/schema.rb +100 -42
  93. metadata +57 -184
  94. data/.travis.yml +0 -69
  95. data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
  96. data/lib/ransack/adapters/active_record/3.0/context.rb +0 -201
  97. data/lib/ransack/adapters/active_record/3.1/context.rb +0 -215
  98. data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
  99. data/lib/ransack/adapters/active_record/compat.rb +0 -14
  100. data/lib/ransack/adapters/mongoid/3.2/.gitkeep +0 -0
  101. data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
  102. data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
  103. data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
  104. data/lib/ransack/adapters/mongoid/base.rb +0 -130
  105. data/lib/ransack/adapters/mongoid/context.rb +0 -208
  106. data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
  107. data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
  108. data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
  109. data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
  110. data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
  111. data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
  112. data/lib/ransack/adapters/mongoid/table.rb +0 -35
  113. data/lib/ransack/adapters/mongoid.rb +0 -13
  114. data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -276
  115. data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
  116. data/spec/mongoid/configuration_spec.rb +0 -102
  117. data/spec/mongoid/dependencies_spec.rb +0 -8
  118. data/spec/mongoid/helpers/ransack_helper.rb +0 -11
  119. data/spec/mongoid/nodes/condition_spec.rb +0 -34
  120. data/spec/mongoid/nodes/grouping_spec.rb +0 -13
  121. data/spec/mongoid/predicate_spec.rb +0 -155
  122. data/spec/mongoid/search_spec.rb +0 -446
  123. data/spec/mongoid/support/mongoid.yml +0 -6
  124. data/spec/mongoid/support/schema.rb +0 -128
  125. data/spec/mongoid/translate_spec.rb +0 -14
  126. data/spec/mongoid_spec_helper.rb +0 -59
  127. data/spec/ransack/dependencies_spec.rb +0 -12
@@ -1,60 +0,0 @@
1
- require 'ransack/visitor'
2
-
3
- module Ransack
4
- class Context
5
- # attr_reader :arel_visitor
6
-
7
- class << self
8
-
9
- def for_class(klass, options = {})
10
- if klass.ancestors.include?(::Mongoid::Document)
11
- Adapters::Mongoid::Context.new(klass, options)
12
- end
13
- end
14
-
15
- def for_object(object, options = {})
16
- case object
17
- when ActiveRecord::Relation
18
- Adapters::ActiveRecord::Context.new(object.klass, options)
19
- end
20
- end
21
-
22
- end # << self
23
-
24
- def initialize(object, options = {})
25
- @object = relation_for(object)
26
- @klass = @object.klass
27
- # @join_dependency = join_dependency(@object)
28
- # @join_type = options[:join_type] || Arel::OuterJoin
29
- @search_key = options[:search_key] || Ransack.options[:search_key]
30
-
31
- @base = @object.klass
32
- # @engine = @base.arel_engine
33
-
34
- # @default_table = Arel::Table.new(
35
- # @base.table_name, :as => @base.aliased_table_name, :engine => @engine
36
- # )
37
- @bind_pairs = Hash.new do |hash, key|
38
- parent, attr_name = get_parent_and_attribute_name(key.to_s)
39
- if parent && attr_name
40
- hash[key] = [parent, attr_name]
41
- end
42
- end
43
- end
44
-
45
- def klassify(obj)
46
- if Class === obj && ::ActiveRecord::Base > obj
47
- obj
48
- elsif obj.respond_to? :klass
49
- obj.klass
50
- elsif obj.respond_to? :active_record # Rails 3
51
- obj.active_record
52
- elsif obj.respond_to? :base_klass # Rails 4
53
- obj.base_klass
54
- else
55
- raise ArgumentError, "Don't know how to klassify #{obj.inspect}"
56
- end
57
- end
58
-
59
- end
60
- end
@@ -1,27 +0,0 @@
1
- module Ransack
2
- module Nodes
3
- class Condition
4
-
5
- def arel_predicate
6
- predicates = attributes.map do |attr|
7
- attr.attr.send(
8
- arel_predicate_for_attribute(attr),
9
- formatted_values_for_attribute(attr)
10
- )
11
- end
12
-
13
- if predicates.size > 1
14
- case combinator
15
- when 'and'
16
- Arel::Nodes::Grouping.new(Arel::Nodes::And.new(predicates))
17
- when 'or'
18
- predicates.inject(&:or)
19
- end
20
- else
21
- predicates.first
22
- end
23
- end
24
-
25
- end # Condition
26
- end
27
- end
@@ -1,13 +0,0 @@
1
- module Ransack
2
- module Translate
3
-
4
- def self.i18n_key(klass)
5
- # if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR == 0
6
- # klass.model_name.i18n_key.to_s.tr('.', '/')
7
- # else
8
- # klass.model_name.i18n_key.to_s
9
- # end
10
- klass.model_name.i18n_key.to_s
11
- end
12
- end
13
- end
@@ -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,13 +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
@@ -1,276 +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
- Person.stub :ransackable_scopes => [:active, :over_age]
24
- end
25
-
26
- it "applies true scopes" do
27
- search = Person.search('active' => true)
28
- expect(search.result.selector).to eq({ 'active' => 1 })
29
- end
30
-
31
- it "ignores unlisted scopes" do
32
- search = Person.search('restricted' => true)
33
- expect(search.result.selector).to_not eq({ 'restricted' => 1})
34
- end
35
-
36
- it "ignores false scopes" do
37
- search = Person.search('active' => false)
38
- expect(search.result.selector).to_not eq({ 'active' => 1 })
39
- end
40
-
41
- it "passes values to scopes" do
42
- search = Person.search('over_age' => 18)
43
- expect(search.result.selector).to eq({ 'age' => { '$gt' => 18 } })
44
- end
45
-
46
- it "chains scopes" do
47
- search = Person.search('over_age' => 18, 'active' => true)
48
- expect(search.result.selector).to eq({ 'age' => { '$gt' => 18 }, 'active' => 1 })
49
- end
50
- end
51
- end
52
-
53
- describe '#ransacker' do
54
- # For infix tests
55
- def self.sane_adapter?
56
- case ::Mongoid::Document.connection.adapter_name
57
- when "SQLite3", "PostgreSQL"
58
- true
59
- else
60
- false
61
- end
62
- end
63
- # # in schema.rb, class Person:
64
- # ransacker :reversed_name, formatter: proc { |v| v.reverse } do |parent|
65
- # parent.table[:name]
66
- # end
67
-
68
- # ransacker :doubled_name do |parent|
69
- # Arel::Nodes::InfixOperation.new(
70
- # '||', parent.table[:name], parent.table[:name]
71
- # )
72
- # end
73
-
74
- it 'creates ransack attributes' do
75
- s = Person.search(:reversed_name_eq => 'htimS cirA')
76
- expect(s.result.size).to eq(Person.where(name: 'Aric Smith').count)
77
-
78
- expect(s.result.first).to eq Person.where(name: 'Aric Smith').first
79
- end
80
-
81
- context 'with joins' do
82
- before { pending 'not implemented for mongoid' }
83
-
84
- it 'can be accessed through associations' do
85
- s = Person.search(:children_reversed_name_eq => 'htimS cirA')
86
- expect(s.result.to_sql).to match(
87
- /#{quote_table_name("children_people")}.#{
88
- quote_column_name("name")} = 'Aric Smith'/
89
- )
90
- end
91
-
92
- it "should keep proper key value pairs in the params hash" do
93
- s = Person.search(:children_reversed_name_eq => 'Testing')
94
- expect(s.result.to_sql).to match /LEFT OUTER JOIN/
95
- end
96
-
97
- end
98
-
99
- it 'allows an "attribute" to be an InfixOperation' do
100
- s = Person.search(:doubled_name_eq => 'Aric SmithAric Smith')
101
- expect(s.result.first).to eq Person.where(name: 'Aric Smith').first
102
- end if defined?(Arel::Nodes::InfixOperation) && sane_adapter?
103
-
104
- it "doesn't break #count if using InfixOperations" do
105
- s = Person.search(:doubled_name_eq => 'Aric SmithAric Smith')
106
- expect(s.result.count).to eq 1
107
- end if defined?(Arel::Nodes::InfixOperation) && sane_adapter?
108
-
109
- it "should remove empty key value pairs from the params hash" do
110
- s = Person.search(:reversed_name_eq => '')
111
- expect(s.result.selector).to eq({})
112
- end
113
-
114
- it "should function correctly when nil is passed in" do
115
- s = Person.search(nil)
116
- end
117
-
118
- it "should function correctly when a blank string is passed in" do
119
- s = Person.search('')
120
- end
121
-
122
- it "should function correctly when using fields with dots in them" do
123
- s = Person.search(:email_cont => "example.com")
124
- expect(s.result.exists?).to be true
125
-
126
- s = Person.search(:email_cont => "example.co.")
127
- expect(s.result.exists?).not_to be true
128
- end
129
-
130
- it "should function correctly when using fields with % in them" do
131
- Person.create!(:name => "110%-er")
132
- s = Person.search(:name_cont => "10%")
133
- expect(s.result.exists?).to be true
134
- end
135
-
136
- it "should function correctly when using fields with backslashes in them" do
137
- Person.create!(:name => "\\WINNER\\")
138
- s = Person.search(:name_cont => "\\WINNER\\")
139
- expect(s.result.exists?).to be true
140
- end
141
-
142
- it 'allows sort by "only_sort" field' do
143
- pending "it doesn't work :("
144
- s = Person.search(
145
- "s" => { "0" => { "dir" => "desc", "name" => "only_sort" } }
146
- )
147
- expect(s.result.to_sql).to match(
148
- /ORDER BY #{quote_table_name("people")}.#{
149
- quote_column_name("only_sort")} ASC/
150
- )
151
- end
152
-
153
- it "doesn't sort by 'only_search' field" do
154
- pending "it doesn't work :("
155
- s = Person.search(
156
- "s" => { "0" => { "dir" => "asc", "name" => "only_search" } }
157
- )
158
- expect(s.result.to_sql).not_to match(
159
- /ORDER BY #{quote_table_name("people")}.#{
160
- quote_column_name("only_search")} ASC/
161
- )
162
- end
163
-
164
- it 'allows search by "only_search" field' do
165
- s = Person.search(:only_search_eq => 'htimS cirA')
166
- expect(s.result.selector).to eq({'only_search' => 'htimS cirA'})
167
- end
168
-
169
- it "can't be searched by 'only_sort'" do
170
- s = Person.search(:only_sort_eq => 'htimS cirA')
171
- expect(s.result.selector).not_to eq({'only_sort' => 'htimS cirA'})
172
- end
173
-
174
- it 'allows sort by "only_admin" field, if auth_object: :admin' do
175
- s = Person.search(
176
- { "s" => { "0" => { "dir" => "asc", "name" => "only_admin" } } },
177
- { auth_object: :admin }
178
- )
179
- expect(s.result.options).to eq({ sort: { '_id' => -1, 'only_admin' => 1 } })
180
- end
181
-
182
- it "doesn't sort by 'only_admin' field, if auth_object: nil" do
183
- s = Person.search(
184
- "s" => { "0" => { "dir" => "asc", "name" => "only_admin" } }
185
- )
186
- expect(s.result.options).to eq({ sort: {'_id' => -1}})
187
- end
188
-
189
- it 'allows search by "only_admin" field, if auth_object: :admin' do
190
- s = Person.search(
191
- { :only_admin_eq => 'htimS cirA' },
192
- { :auth_object => :admin }
193
- )
194
- expect(s.result.selector).to eq({ 'only_admin' => 'htimS cirA' })
195
- end
196
-
197
- it "can't be searched by 'only_admin', if auth_object: nil" do
198
- s = Person.search(:only_admin_eq => 'htimS cirA')
199
- expect(s.result.selector).to eq({})
200
- end
201
-
202
- it 'searches by id' do
203
- ids = ['some_bson_id', 'another_bson_id']
204
- s = Person.search(:id_in => ids)
205
- expect(s.result.selector).to eq({ '_id' => { '$in' => ids } })
206
- end
207
- end
208
-
209
- describe '#ransackable_attributes' do
210
- context 'when auth_object is nil' do
211
- subject { Person.ransackable_attributes }
212
-
213
- it { should include 'name' }
214
- it { should include 'reversed_name' }
215
- it { should include 'doubled_name' }
216
- it { should include 'only_search' }
217
- it { should_not include 'only_sort' }
218
- it { should_not include 'only_admin' }
219
- end
220
-
221
- context 'with auth_object :admin' do
222
- subject { Person.ransackable_attributes(:admin) }
223
-
224
- it { should include 'name' }
225
- it { should include 'reversed_name' }
226
- it { should include 'doubled_name' }
227
- it { should include 'only_search' }
228
- it { should_not include 'only_sort' }
229
- it { should include 'only_admin' }
230
- end
231
- end
232
-
233
- describe '#ransortable_attributes' do
234
- context 'when auth_object is nil' do
235
- subject { Person.ransortable_attributes }
236
-
237
- it { should include 'name' }
238
- it { should include 'reversed_name' }
239
- it { should include 'doubled_name' }
240
- it { should include 'only_sort' }
241
- it { should_not include 'only_search' }
242
- it { should_not include 'only_admin' }
243
- end
244
-
245
- context 'with auth_object :admin' do
246
- subject { Person.ransortable_attributes(:admin) }
247
-
248
- it { should include 'name' }
249
- it { should include 'reversed_name' }
250
- it { should include 'doubled_name' }
251
- it { should include 'only_sort' }
252
- it { should_not include 'only_search' }
253
- it { should include 'only_admin' }
254
- end
255
- end
256
-
257
- describe '#ransackable_associations' do
258
- before { pending "not implemented for mongoid" }
259
-
260
- subject { Person.ransackable_associations }
261
-
262
- it { should include 'parent' }
263
- it { should include 'children' }
264
- it { should include 'articles' }
265
- end
266
-
267
- describe '#ransackable_scopes' do
268
- subject { Person.ransackable_scopes }
269
-
270
- it { should eq [] }
271
- end
272
-
273
- end
274
- end
275
- end
276
- 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,102 +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
- # store original state so we can restore it later
40
- before = Ransack.options.clone
41
-
42
- Ransack.configure do |config|
43
- config.search_key = :query
44
- end
45
-
46
- expect(Ransack.options[:search_key]).to eq :query
47
-
48
- # restore original state so we don't break other tests
49
- Ransack.options = before
50
- end
51
-
52
- it 'adds predicates that take arrays, overriding compounds' do
53
- Ransack.configure do |config|
54
- config.add_predicate(
55
- :test_array_predicate,
56
- :wants_array => true,
57
- :compounds => true
58
- )
59
- end
60
-
61
- expect(Ransack.predicates['test_array_predicate'].wants_array).to eq true
62
- expect(Ransack.predicates).not_to have_key 'test_array_predicate_any'
63
- expect(Ransack.predicates).not_to have_key 'test_array_predicate_all'
64
- end
65
-
66
- describe '`wants_array` option takes precedence over Arel predicate' do
67
- it 'implicitly wants an array for in/not in predicates' do
68
- Ransack.configure do |config|
69
- config.add_predicate(
70
- :test_in_predicate,
71
- :arel_predicate => 'in'
72
- )
73
- config.add_predicate(
74
- :test_not_in_predicate,
75
- :arel_predicate => 'not_in'
76
- )
77
- end
78
-
79
- expect(Ransack.predicates['test_in_predicate'].wants_array).to eq true
80
- expect(Ransack.predicates['test_not_in_predicate'].wants_array).to eq true
81
- end
82
-
83
- it 'explicitly does not want array for in/not_in predicates' do
84
- Ransack.configure do |config|
85
- config.add_predicate(
86
- :test_in_predicate_no_array,
87
- :arel_predicate => 'in',
88
- :wants_array => false
89
- )
90
- config.add_predicate(
91
- :test_not_in_predicate_no_array,
92
- :arel_predicate => 'not_in',
93
- :wants_array => false
94
- )
95
- end
96
-
97
- expect(Ransack.predicates['test_in_predicate_no_array'].wants_array).to eq false
98
- expect(Ransack.predicates['test_not_in_predicate_no_array'].wants_array).to eq false
99
- end
100
- end
101
- end
102
- 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,34 +0,0 @@
1
- require 'mongoid_spec_helper'
2
-
3
- module Ransack
4
- module Nodes
5
- describe Condition do
6
-
7
- context 'with multiple values and an _any predicate' do
8
- subject { Condition.extract(Context.for(Person), 'name_eq_any', Person.first(2).map(&:name)) }
9
-
10
- specify { expect(subject.values.size).to eq(2) }
11
- end
12
-
13
- context 'with an invalid predicate' do
14
- subject { Condition.extract(Context.for(Person), 'name_invalid', Person.first.name) }
15
-
16
- context "when ignore_unknown_conditions is false" do
17
- before do
18
- Ransack.configure { |config| config.ignore_unknown_conditions = false }
19
- end
20
-
21
- specify { expect { subject }.to raise_error ArgumentError }
22
- end
23
-
24
- context "when ignore_unknown_conditions is true" do
25
- before do
26
- Ransack.configure { |config| config.ignore_unknown_conditions = true }
27
- end
28
-
29
- specify { expect(subject).to be_nil }
30
- end
31
- end
32
- end
33
- end
34
- 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