search_object 1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +24 -0
- data/.travis.yml +4 -2
- data/CHANGELOG.md +40 -0
- data/README.md +38 -0
- data/example/Gemfile +2 -2
- data/example/app/assets/images/favicon.png +0 -0
- data/example/app/views/layouts/application.html.slim +1 -0
- data/example/config/environments/test.rb +1 -1
- data/example/screenshot.png +0 -0
- data/example/spec/models/post_search_spec.rb +11 -9
- data/example/spec/spec_helper.rb +1 -2
- data/lib/search_object/base.rb +22 -14
- data/lib/search_object/helper.rb +12 -4
- data/lib/search_object/plugin/kaminari.rb +0 -1
- data/lib/search_object/plugin/paging.rb +10 -10
- data/lib/search_object/plugin/sorting.rb +4 -4
- data/lib/search_object/search.rb +12 -0
- data/lib/search_object/version.rb +1 -1
- data/search_object.gemspec +2 -0
- data/spec/search_object/base_spec.rb +93 -57
- data/spec/search_object/helper_spec.rb +7 -7
- data/spec/search_object/plugin/kaminari_spec.rb +3 -3
- data/spec/search_object/plugin/model_spec.rb +6 -2
- data/spec/search_object/plugin/paging_spec.rb +1 -1
- data/spec/search_object/plugin/sorting_spec.rb +38 -33
- data/spec/search_object/plugin/will_paginate_spec.rb +3 -3
- data/spec/search_object/search_spec.rb +25 -26
- data/spec/spec_helper.rb +0 -1
- data/spec/spec_helper_active_record.rb +1 -1
- data/spec/support/kaminari_setup.rb +0 -1
- data/spec/support/paging_shared_example.rb +35 -32
- metadata +56 -27
@@ -1,4 +1,4 @@
|
|
1
|
-
shared_examples_for
|
1
|
+
shared_examples_for 'a paging plugin' do
|
2
2
|
after do
|
3
3
|
Product.delete_all
|
4
4
|
end
|
@@ -8,9 +8,7 @@ shared_examples_for "a paging plugin" do
|
|
8
8
|
Class.new do
|
9
9
|
include SearchObject.module(plugin_name)
|
10
10
|
|
11
|
-
if block_given?
|
12
|
-
instance_eval &block
|
13
|
-
end
|
11
|
+
instance_eval(&block) if block_given?
|
14
12
|
end
|
15
13
|
end
|
16
14
|
|
@@ -29,8 +27,13 @@ shared_examples_for "a paging plugin" do
|
|
29
27
|
search_class.new page: page, per_page: per_page
|
30
28
|
end
|
31
29
|
|
32
|
-
|
33
|
-
|
30
|
+
it 'can be inherited' do
|
31
|
+
child_class = Class.new(search_class)
|
32
|
+
expect(child_class.new.per_page).to eq 2
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#results' do
|
36
|
+
it 'paginates results' do
|
34
37
|
6.times { |i| Product.create name: "product_#{i}" }
|
35
38
|
search = search_with_page 2, 2
|
36
39
|
|
@@ -38,75 +41,75 @@ shared_examples_for "a paging plugin" do
|
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
41
|
-
describe
|
42
|
-
it
|
44
|
+
describe '#page' do
|
45
|
+
it 'treats nil page as 0' do
|
43
46
|
search = search_with_page nil
|
44
47
|
expect(search.page).to eq 0
|
45
48
|
end
|
46
49
|
|
47
|
-
it
|
48
|
-
search = search_with_page
|
50
|
+
it 'treats negative page numbers as positive' do
|
51
|
+
search = search_with_page(-1)
|
49
52
|
expect(search.page).to eq 0
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
53
|
-
describe
|
54
|
-
it
|
56
|
+
describe '#per_page' do
|
57
|
+
it 'returns the class defined per page' do
|
55
58
|
search = search_class.new
|
56
59
|
expect(search.per_page).to eq 2
|
57
60
|
end
|
58
61
|
|
59
|
-
it
|
62
|
+
it 'can be overwritten as option' do
|
60
63
|
search = search_class.new per_page: 3
|
61
64
|
expect(search.per_page).to eq 3
|
62
65
|
end
|
63
66
|
|
64
|
-
it
|
67
|
+
it 'respects min per page' do
|
65
68
|
search = search_class.new per_page: 1
|
66
69
|
expect(search.per_page).to eq 2
|
67
70
|
end
|
68
71
|
|
69
|
-
it
|
72
|
+
it 'respects max per page' do
|
70
73
|
search = search_class.new per_page: 100
|
71
74
|
expect(search.per_page).to eq 10
|
72
75
|
end
|
73
76
|
end
|
74
77
|
|
75
|
-
describe
|
76
|
-
it
|
78
|
+
describe '#count' do
|
79
|
+
it 'gives the real count' do
|
77
80
|
10.times { |i| Product.create name: "product_#{i}" }
|
78
81
|
search = search_with_page 1
|
79
82
|
expect(search.count).to eq 10
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
|
-
describe
|
84
|
-
it
|
85
|
-
expect { define_search_class { per_page
|
86
|
+
describe '.per_page' do
|
87
|
+
it 'does not accept 0' do
|
88
|
+
expect { define_search_class { per_page(0) } }.to raise_error SearchObject::InvalidNumberError
|
86
89
|
end
|
87
90
|
|
88
|
-
it
|
89
|
-
expect { define_search_class { per_page
|
91
|
+
it 'does not accept negative number' do
|
92
|
+
expect { define_search_class { per_page(-1) } }.to raise_error SearchObject::InvalidNumberError
|
90
93
|
end
|
91
94
|
end
|
92
95
|
|
93
|
-
describe
|
94
|
-
it
|
95
|
-
expect { define_search_class { min_per_page
|
96
|
+
describe '.min_per_page' do
|
97
|
+
it 'does not accept 0' do
|
98
|
+
expect { define_search_class { min_per_page(0) } }.to raise_error SearchObject::InvalidNumberError
|
96
99
|
end
|
97
100
|
|
98
|
-
it
|
99
|
-
expect { define_search_class { min_per_page
|
101
|
+
it 'does not accept negative number' do
|
102
|
+
expect { define_search_class { min_per_page(-1) } }.to raise_error SearchObject::InvalidNumberError
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
103
|
-
describe
|
104
|
-
it
|
105
|
-
expect { define_search_class { max_per_page
|
106
|
+
describe '.max_per_page' do
|
107
|
+
it 'does not accept 0' do
|
108
|
+
expect { define_search_class { max_per_page(0) } }.to raise_error SearchObject::InvalidNumberError
|
106
109
|
end
|
107
110
|
|
108
|
-
it
|
109
|
-
expect { define_search_class { max_per_page
|
111
|
+
it 'does not accept negative number' do
|
112
|
+
expect { define_search_class { max_per_page(-1) } }.to raise_error SearchObject::InvalidNumberError
|
110
113
|
end
|
111
114
|
end
|
112
115
|
end
|
metadata
CHANGED
@@ -1,139 +1,167 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: search_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Radoslav Stankov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.14'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.14'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-mocks
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 2.12.3
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 2.12.3
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activerecord
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 3.0.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.0.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: coveralls
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: will_paginate
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: kaminari
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
137
165
|
- !ruby/object:Gem::Version
|
138
166
|
version: '0'
|
139
167
|
description: Search object DSL
|
@@ -143,9 +171,10 @@ executables: []
|
|
143
171
|
extensions: []
|
144
172
|
extra_rdoc_files: []
|
145
173
|
files:
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
174
|
+
- .gitignore
|
175
|
+
- .rspec
|
176
|
+
- .rubocop.yml
|
177
|
+
- .travis.yml
|
149
178
|
- CHANGELOG.md
|
150
179
|
- Gemfile
|
151
180
|
- LICENSE.txt
|
@@ -156,6 +185,7 @@ files:
|
|
156
185
|
- example/Gemfile
|
157
186
|
- example/README.md
|
158
187
|
- example/Rakefile
|
188
|
+
- example/app/assets/images/favicon.png
|
159
189
|
- example/app/assets/javascripts/application.js
|
160
190
|
- example/app/assets/stylesheets/application.css.scss
|
161
191
|
- example/app/assets/stylesheets/reset.css
|
@@ -224,17 +254,17 @@ require_paths:
|
|
224
254
|
- lib
|
225
255
|
required_ruby_version: !ruby/object:Gem::Requirement
|
226
256
|
requirements:
|
227
|
-
- -
|
257
|
+
- - '>='
|
228
258
|
- !ruby/object:Gem::Version
|
229
259
|
version: '0'
|
230
260
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
261
|
requirements:
|
232
|
-
- -
|
262
|
+
- - '>='
|
233
263
|
- !ruby/object:Gem::Version
|
234
264
|
version: '0'
|
235
265
|
requirements: []
|
236
266
|
rubyforge_project:
|
237
|
-
rubygems_version: 2.
|
267
|
+
rubygems_version: 2.4.2
|
238
268
|
signing_key:
|
239
269
|
specification_version: 4
|
240
270
|
summary: Provides DSL for creating search objects
|
@@ -251,4 +281,3 @@ test_files:
|
|
251
281
|
- spec/spec_helper_active_record.rb
|
252
282
|
- spec/support/kaminari_setup.rb
|
253
283
|
- spec/support/paging_shared_example.rb
|
254
|
-
has_rdoc:
|