ransack 1.8.4 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +3 -0
- data/.github/SECURITY.md +12 -0
- data/.github/workflows/cronjob.yml +102 -0
- data/.github/workflows/deploy.yml +35 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.github/workflows/test-deploy.yml +29 -0
- data/.github/workflows/test.yml +130 -0
- data/.gitignore +3 -0
- data/{lib/ransack/adapters/mongoid/3.2/.gitkeep → .nojekyll} +0 -0
- data/.rubocop.yml +44 -0
- data/CHANGELOG.md +352 -0
- data/CONTRIBUTING.md +25 -13
- data/Gemfile +26 -27
- data/README.md +65 -815
- data/Rakefile +1 -22
- data/bug_report_templates/test-ransack-scope-and-column-same-name.rb +78 -0
- data/bug_report_templates/test-ransacker-arel-present-predicate.rb +71 -0
- data/docs/.gitignore +19 -0
- data/docs/.nojekyll +0 -0
- data/docs/babel.config.js +3 -0
- data/docs/blog/2022-03-27-ransack-3.0.0.md +20 -0
- data/docs/docs/getting-started/_category_.json +4 -0
- data/docs/docs/getting-started/advanced-mode.md +46 -0
- data/docs/docs/getting-started/configuration.md +47 -0
- data/docs/docs/getting-started/search-matches.md +67 -0
- data/docs/docs/getting-started/simple-mode.md +284 -0
- data/docs/docs/getting-started/sorting.md +79 -0
- data/docs/docs/getting-started/using-predicates.md +282 -0
- data/docs/docs/going-further/_category_.json +4 -0
- data/docs/docs/going-further/acts-as-taggable-on.md +114 -0
- data/docs/docs/going-further/associations.md +70 -0
- data/docs/docs/going-further/custom-predicates.md +52 -0
- data/docs/docs/going-further/documentation.md +43 -0
- data/docs/docs/going-further/exporting-to-csv.md +49 -0
- data/docs/docs/going-further/external-guides.md +57 -0
- data/docs/docs/going-further/form-customisation.md +63 -0
- data/docs/docs/going-further/i18n.md +53 -0
- data/docs/docs/going-further/img/create_release.png +0 -0
- data/docs/docs/going-further/merging-searches.md +41 -0
- data/docs/docs/going-further/other-notes.md +428 -0
- data/docs/docs/going-further/polymorphic-search.md +40 -0
- data/docs/docs/going-further/ransackers.md +331 -0
- data/docs/docs/going-further/release_process.md +36 -0
- data/docs/docs/going-further/saving-queries.md +82 -0
- data/docs/docs/going-further/searching-postgres.md +57 -0
- data/docs/docs/going-further/wiki-contributors.md +82 -0
- data/docs/docs/intro.md +99 -0
- data/docs/docusaurus.config.js +120 -0
- data/docs/package.json +38 -0
- data/docs/sidebars.js +31 -0
- data/docs/src/components/HomepageFeatures/index.js +64 -0
- data/docs/src/components/HomepageFeatures/styles.module.css +11 -0
- data/docs/src/css/custom.css +39 -0
- data/docs/src/pages/index.module.css +23 -0
- data/docs/src/pages/markdown-page.md +7 -0
- data/docs/static/.nojekyll +0 -0
- data/docs/static/img/docusaurus.png +0 -0
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/logo.svg +1 -0
- data/docs/static/img/tutorial/docsVersionDropdown.png +0 -0
- data/docs/static/img/tutorial/localeDropdown.png +0 -0
- data/docs/static/img/undraw_docusaurus_mountain.svg +171 -0
- data/docs/static/img/undraw_docusaurus_react.svg +170 -0
- data/docs/static/img/undraw_docusaurus_tree.svg +40 -0
- data/docs/static/logo/ransack-h.png +0 -0
- data/docs/static/logo/ransack-h.svg +34 -0
- data/docs/static/logo/ransack-v.png +0 -0
- data/docs/static/logo/ransack-v.svg +34 -0
- data/docs/static/logo/ransack.png +0 -0
- data/docs/static/logo/ransack.svg +21 -0
- data/docs/yarn.lock +8436 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_association.rb +70 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +92 -0
- data/lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb +11 -0
- data/lib/polyamorous/activerecord_7.0_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_7.0_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_7.0_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_association.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/join_dependency.rb +1 -0
- data/lib/polyamorous/activerecord_7.1_ruby_2/reflection.rb +1 -0
- data/lib/polyamorous/join.rb +70 -0
- data/lib/polyamorous/polyamorous.rb +24 -0
- data/lib/polyamorous/swapping_reflection_class.rb +11 -0
- data/lib/polyamorous/tree_node.rb +7 -0
- data/lib/polyamorous.rb +1 -0
- data/lib/ransack/adapters/active_record/base.rb +14 -3
- data/lib/ransack/adapters/active_record/context.rb +140 -196
- data/lib/ransack/adapters/active_record/ransack/constants.rb +19 -4
- data/lib/ransack/adapters/active_record/ransack/context.rb +9 -19
- data/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +7 -7
- data/lib/ransack/adapters/active_record/ransack/translate.rb +1 -5
- data/lib/ransack/adapters/active_record/ransack/visitor.rb +23 -0
- data/lib/ransack/adapters/active_record.rb +0 -9
- data/lib/ransack/adapters.rb +2 -0
- data/lib/ransack/configuration.rb +52 -2
- data/lib/ransack/constants.rb +1 -5
- data/lib/ransack/context.rb +29 -24
- data/lib/ransack/helpers/form_builder.rb +12 -6
- data/lib/ransack/helpers/form_helper.rb +11 -3
- data/lib/ransack/helpers.rb +1 -1
- data/lib/ransack/locale/ar.yml +70 -0
- data/lib/ransack/locale/az.yml +70 -0
- data/lib/ransack/locale/bg.yml +70 -0
- data/lib/ransack/locale/ca.yml +70 -0
- data/lib/ransack/locale/el.yml +70 -0
- data/lib/ransack/locale/es.yml +22 -22
- data/lib/ransack/locale/fa.yml +70 -0
- data/lib/ransack/locale/fi.yml +71 -0
- data/lib/ransack/locale/nl.yml +4 -4
- data/lib/ransack/locale/ru.yml +70 -0
- data/lib/ransack/locale/sk.yml +70 -0
- data/lib/ransack/locale/sv.yml +70 -0
- data/lib/ransack/locale/tr.yml +70 -0
- data/lib/ransack/locale/zh-CN.yml +12 -12
- data/lib/ransack/nodes/attribute.rb +2 -2
- data/lib/ransack/nodes/condition.rb +7 -1
- data/lib/ransack/nodes/grouping.rb +3 -8
- data/lib/ransack/nodes/sort.rb +3 -3
- data/lib/ransack/nodes/value.rb +3 -3
- data/lib/ransack/predicate.rb +13 -20
- data/lib/ransack/search.rb +7 -4
- data/lib/ransack/translate.rb +115 -115
- data/lib/ransack/version.rb +1 -1
- data/lib/ransack/visitor.rb +1 -12
- data/lib/ransack.rb +7 -5
- data/ransack.gemspec +9 -25
- data/spec/blueprints/articles.rb +1 -1
- data/spec/blueprints/comments.rb +1 -1
- data/spec/blueprints/notes.rb +1 -1
- data/spec/blueprints/tags.rb +1 -1
- data/spec/console.rb +5 -5
- data/spec/helpers/polyamorous_helper.rb +13 -0
- data/spec/helpers/ransack_helper.rb +1 -1
- data/spec/polyamorous/activerecord_compatibility_spec.rb +15 -0
- data/spec/polyamorous/join_association_spec.rb +30 -0
- data/spec/polyamorous/join_dependency_spec.rb +81 -0
- data/spec/polyamorous/join_spec.rb +19 -0
- data/spec/ransack/adapters/active_record/base_spec.rb +105 -11
- data/spec/ransack/adapters/active_record/context_spec.rb +63 -24
- data/spec/ransack/configuration_spec.rb +24 -0
- data/spec/ransack/helpers/form_builder_spec.rb +3 -15
- data/spec/ransack/helpers/form_helper_spec.rb +135 -168
- data/spec/ransack/nodes/condition_spec.rb +13 -0
- data/spec/ransack/nodes/grouping_spec.rb +2 -2
- data/spec/ransack/nodes/value_spec.rb +115 -0
- data/spec/ransack/predicate_spec.rb +54 -2
- data/spec/ransack/search_spec.rb +266 -36
- data/spec/spec_helper.rb +14 -5
- data/spec/support/schema.rb +99 -21
- metadata +117 -187
- data/.travis.yml +0 -86
- data/lib/ransack/adapters/active_record/3.0/compat.rb +0 -179
- data/lib/ransack/adapters/active_record/3.0/context.rb +0 -203
- data/lib/ransack/adapters/active_record/3.1/context.rb +0 -212
- data/lib/ransack/adapters/active_record/3.2/context.rb +0 -44
- data/lib/ransack/adapters/active_record/compat.rb +0 -14
- data/lib/ransack/adapters/mongoid/attributes/attribute.rb +0 -37
- data/lib/ransack/adapters/mongoid/attributes/order_predications.rb +0 -17
- data/lib/ransack/adapters/mongoid/attributes/predications.rb +0 -141
- data/lib/ransack/adapters/mongoid/base.rb +0 -134
- data/lib/ransack/adapters/mongoid/context.rb +0 -212
- data/lib/ransack/adapters/mongoid/inquiry_hash.rb +0 -23
- data/lib/ransack/adapters/mongoid/ransack/constants.rb +0 -88
- data/lib/ransack/adapters/mongoid/ransack/context.rb +0 -60
- data/lib/ransack/adapters/mongoid/ransack/nodes/condition.rb +0 -27
- data/lib/ransack/adapters/mongoid/ransack/translate.rb +0 -13
- data/lib/ransack/adapters/mongoid/ransack/visitor.rb +0 -24
- data/lib/ransack/adapters/mongoid/table.rb +0 -35
- data/lib/ransack/adapters/mongoid.rb +0 -15
- data/spec/mongoid/adapters/mongoid/base_spec.rb +0 -314
- data/spec/mongoid/adapters/mongoid/context_spec.rb +0 -56
- data/spec/mongoid/configuration_spec.rb +0 -162
- data/spec/mongoid/dependencies_spec.rb +0 -8
- data/spec/mongoid/helpers/ransack_helper.rb +0 -11
- data/spec/mongoid/nodes/condition_spec.rb +0 -49
- data/spec/mongoid/nodes/grouping_spec.rb +0 -13
- data/spec/mongoid/predicate_spec.rb +0 -155
- data/spec/mongoid/search_spec.rb +0 -445
- data/spec/mongoid/support/mongoid.yml +0 -11
- data/spec/mongoid/support/schema.rb +0 -135
- data/spec/mongoid/translate_spec.rb +0 -14
- data/spec/mongoid_spec_helper.rb +0 -63
- data/spec/ransack/dependencies_spec.rb +0 -12
@@ -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,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,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
|