usefull_scopes 0.2.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +13 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +11 -10
- data/README.md +71 -20
- data/Rakefile +0 -1
- data/lib/usefull_scopes.rb +6 -5
- data/lib/usefull_scopes/version.rb +1 -1
- data/test/lib/scopes_test.rb +658 -0
- data/test/test_helper.rb +10 -11
- data/usefull_scopes.gemspec +6 -0
- metadata +53 -20
- data/test/lib/usefull_scopes_test.rb +0 -652
data/test/test_helper.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'bundler/setup'
|
2
|
+
Bundler.require
|
2
3
|
require 'active_record'
|
3
|
-
|
4
|
+
|
4
5
|
require 'coveralls'
|
5
6
|
Coveralls.wear!
|
6
7
|
|
7
8
|
ENV["COVERAGE"] = "true"
|
8
9
|
SimpleCov.start if ENV["COVERAGE"]
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
# reporters doesn't work with AS < 4 (see https://travis-ci.org/kaize/validates/jobs/28579079)
|
12
|
+
if defined?(ActiveSupport::VERSION) && ActiveSupport::VERSION::MAJOR >= 4
|
13
|
+
require "minitest/reporters"
|
14
|
+
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)]
|
15
|
+
end
|
13
16
|
|
14
17
|
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
15
|
-
|
16
18
|
ActiveRecord::Migration.create_table :models do |t|
|
17
19
|
t.integer :field_1
|
18
20
|
t.string :field_2
|
@@ -25,13 +27,10 @@ class Model < ActiveRecord::Base
|
|
25
27
|
include UsefullScopes
|
26
28
|
end
|
27
29
|
|
28
|
-
class TestCase < MiniTest::
|
29
|
-
def load_fixture(filename)
|
30
|
-
File.read(File.dirname(__FILE__) + "/fixtures/#{filename}")
|
31
|
-
end
|
32
|
-
|
30
|
+
class TestCase < MiniTest::Test
|
33
31
|
require 'factory_girl'
|
34
32
|
FactoryGirl.reload
|
35
|
-
|
36
33
|
include FactoryGirl::Syntax::Methods
|
37
34
|
end
|
35
|
+
|
36
|
+
require 'minitest/autorun'
|
data/usefull_scopes.gemspec
CHANGED
@@ -18,4 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
|
20
20
|
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.rdoc_options = %w(--line-numbers --inline-source --title usefull_scopes --main README.md)
|
23
|
+
s.extra_rdoc_files = %w(README.md LICENSE CONTRIBUTING.md)
|
24
|
+
|
25
|
+
s.add_dependency "activerecord", [">= 3.0.0"]
|
26
|
+
s.add_dependency "activesupport", [">= 3.0.0"]
|
21
27
|
end
|
metadata
CHANGED
@@ -1,26 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usefull_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Kaize Team
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
14
41
|
description: This gem provides additional scopes for your Active:Record models within
|
15
42
|
Ruby on Rails framework.
|
16
43
|
email:
|
17
44
|
- info@kaize.ru
|
18
45
|
executables: []
|
19
46
|
extensions: []
|
20
|
-
extra_rdoc_files:
|
47
|
+
extra_rdoc_files:
|
48
|
+
- README.md
|
49
|
+
- LICENSE
|
50
|
+
- CONTRIBUTING.md
|
21
51
|
files:
|
22
|
-
- .coveralls.yml
|
23
|
-
- .gitignore
|
52
|
+
- ".coveralls.yml"
|
53
|
+
- ".gitignore"
|
54
|
+
- ".travis.yml"
|
55
|
+
- CONTRIBUTING.md
|
24
56
|
- Gemfile
|
25
57
|
- LICENSE
|
26
58
|
- README.md
|
@@ -29,35 +61,36 @@ files:
|
|
29
61
|
- lib/usefull_scopes/version.rb
|
30
62
|
- test/factories/models.rb
|
31
63
|
- test/factories/sequences.rb
|
32
|
-
- test/lib/
|
64
|
+
- test/lib/scopes_test.rb
|
33
65
|
- test/test_helper.rb
|
34
66
|
- usefull_scopes.gemspec
|
35
67
|
homepage: http://github.com/kaize/usefull_scopes
|
36
68
|
licenses: []
|
69
|
+
metadata: {}
|
37
70
|
post_install_message:
|
38
|
-
rdoc_options:
|
71
|
+
rdoc_options:
|
72
|
+
- "--line-numbers"
|
73
|
+
- "--inline-source"
|
74
|
+
- "--title"
|
75
|
+
- usefull_scopes
|
76
|
+
- "--main"
|
77
|
+
- README.md
|
39
78
|
require_paths:
|
40
79
|
- lib
|
41
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
81
|
requirements:
|
44
|
-
- -
|
82
|
+
- - ">="
|
45
83
|
- !ruby/object:Gem::Version
|
46
84
|
version: '0'
|
47
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
-
none: false
|
49
86
|
requirements:
|
50
|
-
- -
|
87
|
+
- - ">="
|
51
88
|
- !ruby/object:Gem::Version
|
52
89
|
version: '0'
|
53
90
|
requirements: []
|
54
91
|
rubyforge_project: usefull_scopes
|
55
|
-
rubygems_version:
|
92
|
+
rubygems_version: 2.2.2
|
56
93
|
signing_key:
|
57
|
-
specification_version:
|
94
|
+
specification_version: 4
|
58
95
|
summary: Additional scopes for Active:Record models.
|
59
|
-
test_files:
|
60
|
-
- test/factories/models.rb
|
61
|
-
- test/factories/sequences.rb
|
62
|
-
- test/lib/usefull_scopes_test.rb
|
63
|
-
- test/test_helper.rb
|
96
|
+
test_files: []
|
@@ -1,652 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module UsefullScopes
|
4
|
-
class ScopesTest < TestCase
|
5
|
-
def setup
|
6
|
-
3.times { create :model }
|
7
|
-
@model = Model.first
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_random_order_condition
|
11
|
-
random_request = Model.random
|
12
|
-
|
13
|
-
request_arel = random_request.arel
|
14
|
-
order = request_arel.order
|
15
|
-
order_conditions = order.orders
|
16
|
-
|
17
|
-
assert_includes order_conditions, "RANDOM()"
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_random_sql
|
21
|
-
random_request = Model.random
|
22
|
-
|
23
|
-
assert_equal "SELECT \"models\".* FROM \"models\" ORDER BY RANDOM()", random_request.to_sql
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_exclude_result
|
27
|
-
@models = Model.exclude(@model)
|
28
|
-
|
29
|
-
models_count = Model.count - 1
|
30
|
-
|
31
|
-
assert_equal models_count, @models.count
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_exclude_conditions
|
35
|
-
@models = Model.exclude(@model)
|
36
|
-
|
37
|
-
request_arel = @models.arel
|
38
|
-
condition = request_arel.where_clauses
|
39
|
-
assert_equal 1, condition.count
|
40
|
-
assert condition.first.match "NOT IN"
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_with_result
|
44
|
-
@models = Model.with({field_1: @model.field_1})
|
45
|
-
|
46
|
-
assert @models
|
47
|
-
|
48
|
-
assert_includes @models, @model
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_with_conditions
|
52
|
-
@models = Model.with({field_1: @model.field_1})
|
53
|
-
|
54
|
-
ctx = @models.arel.as_json["ctx"]
|
55
|
-
where_conditions = ctx.wheres
|
56
|
-
|
57
|
-
assert where_conditions.any?
|
58
|
-
|
59
|
-
where_conditions.each do |condition|
|
60
|
-
condition.children.each do |condition_part|
|
61
|
-
assert_kind_of Arel::Nodes::Equality, condition_part
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_with_incorrect_params
|
67
|
-
begin
|
68
|
-
@models = Model.with("field_1 = #{@model.field_1}")
|
69
|
-
rescue Exception => e
|
70
|
-
assert_equal "Hash is expected", e.message
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_without_result
|
75
|
-
@models = Model.without({field_1: @model.field_1})
|
76
|
-
|
77
|
-
assert @models
|
78
|
-
|
79
|
-
refute @models.include?(@model)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_without_conditions
|
83
|
-
@models = Model.without({field_1: @model.field_1})
|
84
|
-
|
85
|
-
ctx = @models.arel.as_json["ctx"]
|
86
|
-
where_conditions = ctx.wheres
|
87
|
-
|
88
|
-
assert where_conditions.any?
|
89
|
-
|
90
|
-
where_conditions.each do |condition|
|
91
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
92
|
-
condition.expr.children.each do |condition_part|
|
93
|
-
assert_kind_of Arel::Nodes::NotIn, condition_part
|
94
|
-
|
95
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
96
|
-
|
97
|
-
assert_equal :field_1, condition_part.left.name
|
98
|
-
assert_equal 1, condition_part.right
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_without_incorrect_params
|
104
|
-
begin
|
105
|
-
@models = Model.without("field_1 = #{@model.field_1}")
|
106
|
-
rescue Exception => e
|
107
|
-
assert_equal "Hash is expected", e.message
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_like_by_result
|
112
|
-
|
113
|
-
assert_respond_to Model, :like_by_field_2
|
114
|
-
|
115
|
-
@models = Model.like_by_field_2(@model.field_2[0..3])
|
116
|
-
|
117
|
-
assert @models.any?
|
118
|
-
assert_includes @models, @model
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_like_by_condition
|
122
|
-
|
123
|
-
@models = Model.like_by_field_2(@model.field_2[0..3])
|
124
|
-
|
125
|
-
ctx = @models.arel.as_json["ctx"]
|
126
|
-
where_conditions = ctx.wheres
|
127
|
-
|
128
|
-
assert where_conditions.any?
|
129
|
-
|
130
|
-
where_conditions.each do |condition|
|
131
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
132
|
-
assert condition.expr.match "like"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_ilike_by_result
|
137
|
-
assert_respond_to Model, :ilike_by_field_2
|
138
|
-
|
139
|
-
# SQLite error %(
|
140
|
-
#@models = Model.ilike_by_field_2(@model.field_2[0..3])
|
141
|
-
|
142
|
-
#assert @models.any?
|
143
|
-
#assert_includes @models, @model
|
144
|
-
end
|
145
|
-
|
146
|
-
def test_ilike_by_condition
|
147
|
-
@models = Model.ilike_by_field_2(@model.field_2[0..3])
|
148
|
-
|
149
|
-
ctx = @models.arel.as_json["ctx"]
|
150
|
-
where_conditions = ctx.wheres
|
151
|
-
|
152
|
-
assert where_conditions.any?
|
153
|
-
|
154
|
-
where_conditions.each do |condition|
|
155
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
156
|
-
assert_kind_of Arel::Nodes::Matches, condition.expr
|
157
|
-
|
158
|
-
assert_kind_of Arel::Attributes::Attribute, condition.expr.left
|
159
|
-
assert_equal :field_2, condition.expr.left.name
|
160
|
-
assert_equal "stri%", condition.expr.right
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_desc_by_result
|
165
|
-
assert_respond_to Model, :desc_by
|
166
|
-
|
167
|
-
@models = Model.desc_by(:field_1)
|
168
|
-
|
169
|
-
assert @models.any?
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_desc_by_condition_array_attrs
|
173
|
-
attrs = [:field_1, :field_2]
|
174
|
-
|
175
|
-
@models = Model.desc_by(attrs)
|
176
|
-
|
177
|
-
arel = @models.arel
|
178
|
-
orders_conditions = arel.orders
|
179
|
-
|
180
|
-
assert orders_conditions.any?
|
181
|
-
|
182
|
-
orders_conditions.each_with_index do |condition, index|
|
183
|
-
assert_kind_of Arel::Nodes::Descending, condition
|
184
|
-
assert_kind_of Arel::Attributes::Attribute, condition.expr
|
185
|
-
|
186
|
-
assert_equal attrs[index], condition.expr.name
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_desc_by_condition
|
191
|
-
@models = Model.desc_by(:field_1)
|
192
|
-
|
193
|
-
arel = @models.arel
|
194
|
-
orders_conditions = arel.orders
|
195
|
-
|
196
|
-
assert orders_conditions.any?
|
197
|
-
|
198
|
-
orders_conditions.each do |condition|
|
199
|
-
assert_kind_of Arel::Nodes::Descending, condition
|
200
|
-
assert_kind_of Arel::Attributes::Attribute, condition.expr
|
201
|
-
|
202
|
-
assert_equal :field_1, condition.expr.name
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_desc_by_incorrect_params
|
207
|
-
begin
|
208
|
-
@models = Model.desc_by("field_1")
|
209
|
-
rescue Exception => e
|
210
|
-
assert_equal "Symbol or Array of symbols is expected", e.message
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def test_asc_by_result
|
215
|
-
assert_respond_to Model, :asc_by
|
216
|
-
|
217
|
-
@models = Model.asc_by(:field_1)
|
218
|
-
|
219
|
-
assert @models.any?
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_asc_by_condition_array_attrs
|
223
|
-
attrs = [:field_1, :field_2]
|
224
|
-
|
225
|
-
@models = Model.asc_by(attrs)
|
226
|
-
|
227
|
-
arel = @models.arel
|
228
|
-
orders_conditions = arel.orders
|
229
|
-
|
230
|
-
assert orders_conditions.any?
|
231
|
-
|
232
|
-
orders_conditions.each_with_index do |condition, index|
|
233
|
-
assert_kind_of Arel::Nodes::Ascending, condition
|
234
|
-
assert_kind_of Arel::Attributes::Attribute, condition.expr
|
235
|
-
|
236
|
-
assert_equal attrs[index], condition.expr.name
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_asc_by_condition
|
241
|
-
@models = Model.asc_by(:field_1)
|
242
|
-
|
243
|
-
arel = @models.arel
|
244
|
-
orders_conditions = arel.orders
|
245
|
-
|
246
|
-
assert orders_conditions.any?
|
247
|
-
|
248
|
-
orders_conditions.each do |condition|
|
249
|
-
assert_kind_of Arel::Nodes::Ascending, condition
|
250
|
-
assert_kind_of Arel::Attributes::Attribute, condition.expr
|
251
|
-
|
252
|
-
assert_equal :field_1, condition.expr.name
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_asc_by_incorrect_params
|
257
|
-
begin
|
258
|
-
@models = Model.asc_by("field_1")
|
259
|
-
rescue Exception => e
|
260
|
-
assert_equal "Symbol or Array of symbols is expected", e.message
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_field_more_than_value_by_result
|
265
|
-
@model_less = create :model
|
266
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
267
|
-
|
268
|
-
@models = Model.field_1_more(@model_less.field_1)
|
269
|
-
|
270
|
-
assert @models.any?
|
271
|
-
assert @models.include?(@model_more)
|
272
|
-
refute @models.include?(@model_less)
|
273
|
-
end
|
274
|
-
|
275
|
-
def test_field_more_than_object_by_result
|
276
|
-
@model_less = create :model
|
277
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
278
|
-
|
279
|
-
@models = Model.field_1_more(@model_less)
|
280
|
-
|
281
|
-
assert @models.any?
|
282
|
-
assert @models.include?(@model_more)
|
283
|
-
refute @models.include?(@model_less)
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_field_more_by_condition
|
287
|
-
@models = Model.field_1_more(@model.field_1)
|
288
|
-
|
289
|
-
ctx = @models.arel.as_json["ctx"]
|
290
|
-
where_conditions = ctx.wheres
|
291
|
-
|
292
|
-
assert where_conditions.any?
|
293
|
-
|
294
|
-
where_conditions.each do |condition|
|
295
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
296
|
-
assert_kind_of Arel::Nodes::GreaterThan, condition.expr
|
297
|
-
assert_equal @model.field_1, condition.expr.right
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
def test_field_less_than_value_by_result
|
302
|
-
@model_less = create :model
|
303
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
304
|
-
|
305
|
-
@models = Model.field_1_less(@model_more.field_1)
|
306
|
-
|
307
|
-
assert @models.any?
|
308
|
-
assert @models.include?(@model_less)
|
309
|
-
refute @models.include?(@model_more)
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_field_less_than_object_by_result
|
313
|
-
@model_less = create :model
|
314
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
315
|
-
|
316
|
-
@models = Model.field_1_less(@model_more)
|
317
|
-
|
318
|
-
assert @models.any?
|
319
|
-
assert @models.include?(@model_less)
|
320
|
-
refute @models.include?(@model_more)
|
321
|
-
end
|
322
|
-
|
323
|
-
def test_field_less_by_condition
|
324
|
-
@models = Model.field_1_less(@model.field_1)
|
325
|
-
|
326
|
-
ctx = @models.arel.as_json["ctx"]
|
327
|
-
where_conditions = ctx.wheres
|
328
|
-
|
329
|
-
assert where_conditions.any?
|
330
|
-
|
331
|
-
where_conditions.each do |condition|
|
332
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
333
|
-
assert_kind_of Arel::Nodes::LessThan, condition.expr
|
334
|
-
assert_equal @model.field_1, condition.expr.right
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
def test_field_more_or_equal_than_value_by_result
|
339
|
-
@model_less = create :model
|
340
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
341
|
-
|
342
|
-
@models = Model.field_1_more_or_equal(@model_more.field_1)
|
343
|
-
|
344
|
-
assert @models.any?
|
345
|
-
assert @models.include?(@model_more)
|
346
|
-
refute @models.include?(@model_less)
|
347
|
-
end
|
348
|
-
|
349
|
-
def test_field_more_or_equal_than_object_by_result
|
350
|
-
@model_less = create :model
|
351
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
352
|
-
|
353
|
-
@models = Model.field_1_more_or_equal(@model_more)
|
354
|
-
|
355
|
-
assert @models.any?
|
356
|
-
assert @models.include?(@model_more)
|
357
|
-
refute @models.include?(@model_less)
|
358
|
-
end
|
359
|
-
|
360
|
-
def test_field_more_or_equal_by_condition
|
361
|
-
@models = Model.field_1_more_or_equal(@model.field_1)
|
362
|
-
|
363
|
-
ctx = @models.arel.as_json["ctx"]
|
364
|
-
where_conditions = ctx.wheres
|
365
|
-
|
366
|
-
assert where_conditions.any?
|
367
|
-
|
368
|
-
where_conditions.each do |condition|
|
369
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
370
|
-
assert_kind_of Arel::Nodes::GreaterThanOrEqual, condition.expr
|
371
|
-
assert_equal @model.field_1, condition.expr.right
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
def test_field_less_or_equal_than_value_by_result
|
376
|
-
@model_less = create :model
|
377
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
378
|
-
|
379
|
-
@models = Model.field_1_less_or_equal(@model_less.field_1)
|
380
|
-
|
381
|
-
assert @models.any?
|
382
|
-
assert @models.include?(@model_less)
|
383
|
-
refute @models.include?(@model_more)
|
384
|
-
end
|
385
|
-
|
386
|
-
def test_field_less_or_equal_than_object_by_result
|
387
|
-
@model_less = create :model
|
388
|
-
@model_more = create :model, field_1: @model_less.field_1 + 1
|
389
|
-
|
390
|
-
@models = Model.field_1_less_or_equal(@model_less)
|
391
|
-
|
392
|
-
assert @models.any?
|
393
|
-
assert @models.include?(@model_less)
|
394
|
-
refute @models.include?(@model_more)
|
395
|
-
end
|
396
|
-
def test_field_less_or_equal_by_condition
|
397
|
-
@models = Model.field_1_less_or_equal(@model.field_1)
|
398
|
-
|
399
|
-
ctx = @models.arel.as_json["ctx"]
|
400
|
-
where_conditions = ctx.wheres
|
401
|
-
|
402
|
-
assert where_conditions.any?
|
403
|
-
|
404
|
-
where_conditions.each do |condition|
|
405
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
406
|
-
assert_kind_of Arel::Nodes::LessThanOrEqual, condition.expr
|
407
|
-
assert_equal @model.field_1, condition.expr.right
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
def test_more_than_result
|
412
|
-
@model = Model.last
|
413
|
-
|
414
|
-
@models = Model.more_than({field_1: 1})
|
415
|
-
|
416
|
-
assert @models.any?
|
417
|
-
assert @models.include?(@model)
|
418
|
-
end
|
419
|
-
|
420
|
-
def test_more_than_condition_value
|
421
|
-
@models = Model.more_than({field_1: 1})
|
422
|
-
|
423
|
-
ctx = @models.arel.as_json["ctx"]
|
424
|
-
where_conditions = ctx.wheres
|
425
|
-
|
426
|
-
assert where_conditions.any?
|
427
|
-
|
428
|
-
where_conditions.each do |condition|
|
429
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
430
|
-
condition.expr.children.each do |condition_part|
|
431
|
-
assert_kind_of Arel::Nodes::GreaterThan, condition_part
|
432
|
-
|
433
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
434
|
-
|
435
|
-
assert_equal :field_1, condition_part.left.name
|
436
|
-
assert_equal 1, condition_part.right
|
437
|
-
end
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
def test_more_than_condition_ar_object
|
442
|
-
@models = Model.more_than(@model)
|
443
|
-
|
444
|
-
ctx = @models.arel.as_json["ctx"]
|
445
|
-
where_conditions = ctx.wheres
|
446
|
-
|
447
|
-
assert where_conditions.any?
|
448
|
-
|
449
|
-
where_conditions.each do |condition|
|
450
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
451
|
-
condition.expr.children.each do |condition_part|
|
452
|
-
assert_kind_of Arel::Nodes::GreaterThan, condition_part
|
453
|
-
|
454
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
455
|
-
|
456
|
-
assert_equal :id, condition_part.left.name
|
457
|
-
assert_equal 1, condition_part.right
|
458
|
-
end
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_more_than_incorrect_params
|
463
|
-
begin
|
464
|
-
@models = Model.more_than("field_1")
|
465
|
-
rescue Exception => e
|
466
|
-
assert_equal "Hash or AR object is expected", e.message
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
def test_less_than_result
|
471
|
-
@model_first = Model.first
|
472
|
-
@model_last = Model.last
|
473
|
-
|
474
|
-
@models = Model.less_than({field_1: @model_last.field_1})
|
475
|
-
|
476
|
-
assert @models.any?
|
477
|
-
assert @models.include?(@model_first)
|
478
|
-
end
|
479
|
-
|
480
|
-
def test_less_than_condition_value
|
481
|
-
@models = Model.less_than({field_1: 1})
|
482
|
-
|
483
|
-
ctx = @models.arel.as_json["ctx"]
|
484
|
-
where_conditions = ctx.wheres
|
485
|
-
|
486
|
-
assert where_conditions.any?
|
487
|
-
|
488
|
-
where_conditions.each do |condition|
|
489
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
490
|
-
condition.expr.children.each do |condition_part|
|
491
|
-
assert_kind_of Arel::Nodes::LessThan, condition_part
|
492
|
-
|
493
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
494
|
-
|
495
|
-
assert_equal :field_1, condition_part.left.name
|
496
|
-
assert_equal 1, condition_part.right
|
497
|
-
end
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
def test_less_than_condition_ar_object
|
502
|
-
@models = Model.less_than(@model)
|
503
|
-
|
504
|
-
ctx = @models.arel.as_json["ctx"]
|
505
|
-
where_conditions = ctx.wheres
|
506
|
-
|
507
|
-
assert where_conditions.any?
|
508
|
-
|
509
|
-
where_conditions.each do |condition|
|
510
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
511
|
-
condition.expr.children.each do |condition_part|
|
512
|
-
assert_kind_of Arel::Nodes::LessThan, condition_part
|
513
|
-
|
514
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
515
|
-
|
516
|
-
assert_equal :id, condition_part.left.name
|
517
|
-
assert_equal 1, condition_part.right
|
518
|
-
end
|
519
|
-
end
|
520
|
-
end
|
521
|
-
|
522
|
-
def test_less_than_incorrect_params
|
523
|
-
begin
|
524
|
-
@models = Model.less_than("field_1")
|
525
|
-
rescue Exception => e
|
526
|
-
assert_equal "Hash or AR object is expected", e.message
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
def test_more_or_equal_result
|
531
|
-
@model_first = Model.first
|
532
|
-
@model_last = Model.last
|
533
|
-
|
534
|
-
@models = Model.more_or_equal({field_1: @model_last.field_1})
|
535
|
-
|
536
|
-
assert @models.any?
|
537
|
-
assert @models.include?(@model_last)
|
538
|
-
assert_equal @models.count, 1
|
539
|
-
end
|
540
|
-
|
541
|
-
def test_more_or_equal_condition_value
|
542
|
-
@models = Model.more_or_equal({field_1: 1})
|
543
|
-
|
544
|
-
ctx = @models.arel.as_json["ctx"]
|
545
|
-
where_conditions = ctx.wheres
|
546
|
-
|
547
|
-
assert where_conditions.any?
|
548
|
-
|
549
|
-
where_conditions.each do |condition|
|
550
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
551
|
-
condition.expr.children.each do |condition_part|
|
552
|
-
assert_kind_of Arel::Nodes::GreaterThanOrEqual, condition_part
|
553
|
-
|
554
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
555
|
-
|
556
|
-
assert_equal :field_1, condition_part.left.name
|
557
|
-
assert_equal 1, condition_part.right
|
558
|
-
end
|
559
|
-
end
|
560
|
-
end
|
561
|
-
|
562
|
-
def test_more_or_equal_condition_ar_object
|
563
|
-
@models = Model.more_or_equal(@model)
|
564
|
-
|
565
|
-
ctx = @models.arel.as_json["ctx"]
|
566
|
-
where_conditions = ctx.wheres
|
567
|
-
|
568
|
-
assert where_conditions.any?
|
569
|
-
|
570
|
-
where_conditions.each do |condition|
|
571
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
572
|
-
condition.expr.children.each do |condition_part|
|
573
|
-
assert_kind_of Arel::Nodes::GreaterThanOrEqual, condition_part
|
574
|
-
|
575
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
576
|
-
|
577
|
-
assert_equal :id, condition_part.left.name
|
578
|
-
assert_equal 1, condition_part.right
|
579
|
-
end
|
580
|
-
end
|
581
|
-
end
|
582
|
-
|
583
|
-
def test_more_or_equal_incorrect_params
|
584
|
-
begin
|
585
|
-
@models = Model.more_or_equal("field_1")
|
586
|
-
rescue Exception => e
|
587
|
-
assert_equal "Hash or AR object is expected", e.message
|
588
|
-
end
|
589
|
-
end
|
590
|
-
|
591
|
-
def test_less_or_equal_result
|
592
|
-
@model_first = Model.first
|
593
|
-
@model_last = Model.last
|
594
|
-
|
595
|
-
@models = Model.less_or_equal({field_1: @model_first.field_1})
|
596
|
-
|
597
|
-
assert @models.any?
|
598
|
-
assert @models.include?(@model_first)
|
599
|
-
assert_equal @models.count, 1
|
600
|
-
end
|
601
|
-
|
602
|
-
def test_less_or_equal_condition_value
|
603
|
-
@models = Model.less_or_equal({field_1: 1})
|
604
|
-
|
605
|
-
ctx = @models.arel.as_json["ctx"]
|
606
|
-
where_conditions = ctx.wheres
|
607
|
-
|
608
|
-
assert where_conditions.any?
|
609
|
-
|
610
|
-
where_conditions.each do |condition|
|
611
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
612
|
-
condition.expr.children.each do |condition_part|
|
613
|
-
assert_kind_of Arel::Nodes::LessThanOrEqual, condition_part
|
614
|
-
|
615
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
616
|
-
|
617
|
-
assert_equal :field_1, condition_part.left.name
|
618
|
-
assert_equal 1, condition_part.right
|
619
|
-
end
|
620
|
-
end
|
621
|
-
end
|
622
|
-
|
623
|
-
def test_less_or_equal_condition_ar_object
|
624
|
-
@models = Model.less_or_equal(@model)
|
625
|
-
|
626
|
-
ctx = @models.arel.as_json["ctx"]
|
627
|
-
where_conditions = ctx.wheres
|
628
|
-
|
629
|
-
assert where_conditions.any?
|
630
|
-
|
631
|
-
where_conditions.each do |condition|
|
632
|
-
assert_kind_of Arel::Nodes::Grouping, condition
|
633
|
-
condition.expr.children.each do |condition_part|
|
634
|
-
assert_kind_of Arel::Nodes::LessThanOrEqual, condition_part
|
635
|
-
|
636
|
-
assert_kind_of Arel::Attributes::Attribute, condition_part.left
|
637
|
-
|
638
|
-
assert_equal :id, condition_part.left.name
|
639
|
-
assert_equal 1, condition_part.right
|
640
|
-
end
|
641
|
-
end
|
642
|
-
end
|
643
|
-
|
644
|
-
def test_less_or_equal_incorrect_params
|
645
|
-
begin
|
646
|
-
@models = Model.less_or_equal("field_1")
|
647
|
-
rescue Exception => e
|
648
|
-
assert_equal "Hash or AR object is expected", e.message
|
649
|
-
end
|
650
|
-
end
|
651
|
-
end
|
652
|
-
end
|