rice_cooker 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
1
+ require 'pry'
2
+ require 'rice_cooker'
3
+ require 'active_record'
4
+ require 'spec_helper'
5
+
6
+ # include Sort
7
+
8
+ RSpec.describe RiceCooker::Sort do
9
+ include RiceCooker::Helpers
10
+
11
+ before do
12
+ @collection_class = User
13
+ @collection = @collection_class.all
14
+ end
15
+
16
+ describe 'Sort params must be okay' do
17
+ it 'Default null sorting' do
18
+ # Default null sorting
19
+ sorting_params = parse_sorting_param('', @collection_class)
20
+ expect(sorting_params).to be_eql({})
21
+ end
22
+
23
+ it 'Default asc sorting' do
24
+ # Default asc sorting
25
+ sorting_params = parse_sorting_param('id', @collection_class)
26
+ expect(sorting_params).to be_eql(id: :asc)
27
+ end
28
+
29
+ it 'Desc sorting' do
30
+ # Desc sorting
31
+ sorting_params = parse_sorting_param('-id', @collection_class)
32
+ expect(sorting_params).to be_eql(id: :desc)
33
+ end
34
+
35
+ it 'Same param sorting' do
36
+ sorting_params = parse_sorting_param('-id,id', @collection_class)
37
+ expect(sorting_params).to be_eql(id: :asc)
38
+ end
39
+
40
+ it 'Multiple args' do
41
+ # Multiple args
42
+ sorting_params = parse_sorting_param('-login,id', @collection_class)
43
+ expect(sorting_params).to be_eql(login: :desc, id: :asc)
44
+ end
45
+
46
+ it 'invalid args' do
47
+ # invalid args
48
+ expect { parse_sorting_param('-turututu,id', @collection_class) }.to raise_error(RiceCooker::InvalidSortException)
49
+ end
50
+ end
51
+
52
+ describe 'Must apply sort to given collection' do
53
+ it 'Default null sorting' do
54
+ # Default null sorting
55
+ sorted_collection = apply_sort_to_collection(@collection, {})
56
+ expect(sorted_collection.to_sql).to match(/^((?!ORDER).)*$/)
57
+ end
58
+
59
+ it 'Default asc sorting' do
60
+ # Default asc sorting
61
+ sorted_collection = apply_sort_to_collection(@collection, id: :asc)
62
+ expect(sorted_collection.to_sql).to match(/ORDER/)
63
+ expect(sorted_collection.to_sql).to match(/"id" ASC/)
64
+ end
65
+
66
+ it 'Desc sorting' do
67
+ # Desc sorting
68
+ sorted_collection = apply_sort_to_collection(@collection, id: :desc)
69
+ expect(sorted_collection.to_sql).to match(/ORDER/)
70
+ expect(sorted_collection.to_sql).to match(/"id" DESC/)
71
+ end
72
+
73
+ it 'Same param sorting' do
74
+ # Desc sorting
75
+ sorted_collection = apply_sort_to_collection(@collection, id: :asc)
76
+ expect(sorted_collection.to_sql).to match(/ORDER/)
77
+ expect(sorted_collection.to_sql).to match(/^((?!DESC).)*$/)
78
+ expect(sorted_collection.to_sql).to match(/"id" ASC/)
79
+ end
80
+
81
+ it 'Multiple args' do
82
+ # Multiple args
83
+ sorted_collection = apply_sort_to_collection(@collection, login: :desc, id: :asc)
84
+ expect(sorted_collection.to_sql).to match(/ORDER/)
85
+ expect(sorted_collection.to_sql).to match(/"login" DESC/)
86
+ expect(sorted_collection.to_sql).to match(/"id" ASC/)
87
+ end
88
+ end
89
+ end
90
+
91
+ RSpec.describe UsersController, type: :controller do
92
+ include RiceCooker::Helpers
93
+
94
+ before { request.host = 'example.org' }
95
+
96
+ describe 'GET #index' do
97
+ it 'without sort parameter' do
98
+ process :index, method: :get, params: { sort: '', format: :json }
99
+ expect(response.body).to eq(User.all.to_json)
100
+ end
101
+
102
+ it 'with simple sort parameter' do
103
+ process :index, method: :get, params: { sort: 'login', format: :json }
104
+ expect(response.body).to eq(User.all.order(:login).to_json)
105
+ end
106
+
107
+ it 'with double sort parameter' do
108
+ process :index, method: :get, params: { sort: 'login,id', format: :json }
109
+ expect(response.body).to eq(User.all.order(:login, :id).to_json)
110
+ end
111
+
112
+ it 'with double and reverse sort parameter' do
113
+ process :index, method: :get, params: { sort: 'login,-id', format: :json }
114
+ expect(response.body).to eq(User.all.order(:login, id: :desc).to_json)
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ begin
5
+ require 'rails/engine'
6
+ rescue LoadError
7
+ p 'Unable to load rails/engine !'
8
+ end
9
+
10
+ require 'bundler/setup'
11
+ Bundler.require
12
+ require 'rspec/active_model/mocks'
13
+ require 'mocks/mocks'
14
+
15
+ RSpec.configure do |config|
16
+ config.include Rack::Test::Methods
17
+ config.include ControllerExampleGroup, type: :controller
18
+ config.color = true
19
+ # Use color not only in STDOUT but also in pagers and files
20
+ config.tty = true
21
+ # Use the specified formatter
22
+ config.formatter = :documentation # :progress, :html, :textmate
23
+ end
metadata ADDED
@@ -0,0 +1,381 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rice_cooker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andre Aubin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: actionpack
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 5.0.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.1'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 5.0.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.1'
53
+ - !ruby/object:Gem::Dependency
54
+ name: railties
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 5.0.0
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '5.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 5.0.0
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '5.1'
73
+ - !ruby/object:Gem::Dependency
74
+ name: has_scope
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.7.0
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.0
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.6.0
93
+ - !ruby/object:Gem::Dependency
94
+ name: sqlite3
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ type: :development
101
+ prerelease: false
102
+ version_requirements: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ - !ruby/object:Gem::Dependency
108
+ name: rspec
109
+ requirement: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ type: :development
115
+ prerelease: false
116
+ version_requirements: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ - !ruby/object:Gem::Dependency
122
+ name: rspec-rails
123
+ requirement: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ type: :development
129
+ prerelease: false
130
+ version_requirements: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ - !ruby/object:Gem::Dependency
136
+ name: rspec-activemodel-mocks
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ type: :development
143
+ prerelease: false
144
+ version_requirements: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ - !ruby/object:Gem::Dependency
150
+ name: mocha
151
+ requirement: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '='
154
+ - !ruby/object:Gem::Version
155
+ version: 1.1.0
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '='
161
+ - !ruby/object:Gem::Version
162
+ version: 1.1.0
163
+ - !ruby/object:Gem::Dependency
164
+ name: ruby-prof
165
+ requirement: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - '='
168
+ - !ruby/object:Gem::Version
169
+ version: 0.15.8
170
+ type: :development
171
+ prerelease: false
172
+ version_requirements: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '='
175
+ - !ruby/object:Gem::Version
176
+ version: 0.15.8
177
+ - !ruby/object:Gem::Dependency
178
+ name: test-unit
179
+ requirement: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - '='
182
+ - !ruby/object:Gem::Version
183
+ version: 3.1.3
184
+ type: :development
185
+ prerelease: false
186
+ version_requirements: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - '='
189
+ - !ruby/object:Gem::Version
190
+ version: 3.1.3
191
+ - !ruby/object:Gem::Dependency
192
+ name: rails-perftest
193
+ requirement: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - '='
196
+ - !ruby/object:Gem::Version
197
+ version: 0.0.6
198
+ type: :development
199
+ prerelease: false
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - '='
203
+ - !ruby/object:Gem::Version
204
+ version: 0.0.6
205
+ - !ruby/object:Gem::Dependency
206
+ name: simplecov
207
+ requirement: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - '='
210
+ - !ruby/object:Gem::Version
211
+ version: 0.11.1
212
+ type: :development
213
+ prerelease: false
214
+ version_requirements: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - '='
217
+ - !ruby/object:Gem::Version
218
+ version: 0.11.1
219
+ - !ruby/object:Gem::Dependency
220
+ name: factory_girl_rails
221
+ requirement: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - "~>"
224
+ - !ruby/object:Gem::Version
225
+ version: '4.0'
226
+ type: :development
227
+ prerelease: false
228
+ version_requirements: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - "~>"
231
+ - !ruby/object:Gem::Version
232
+ version: '4.0'
233
+ - !ruby/object:Gem::Dependency
234
+ name: database_cleaner
235
+ requirement: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ type: :development
241
+ prerelease: false
242
+ version_requirements: !ruby/object:Gem::Requirement
243
+ requirements:
244
+ - - ">="
245
+ - !ruby/object:Gem::Version
246
+ version: '0'
247
+ - !ruby/object:Gem::Dependency
248
+ name: faker
249
+ requirement: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - '='
252
+ - !ruby/object:Gem::Version
253
+ version: 1.6.1
254
+ type: :development
255
+ prerelease: false
256
+ version_requirements: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - '='
259
+ - !ruby/object:Gem::Version
260
+ version: 1.6.1
261
+ - !ruby/object:Gem::Dependency
262
+ name: pry
263
+ requirement: !ruby/object:Gem::Requirement
264
+ requirements:
265
+ - - ">="
266
+ - !ruby/object:Gem::Version
267
+ version: '0'
268
+ type: :development
269
+ prerelease: false
270
+ version_requirements: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - ">="
273
+ - !ruby/object:Gem::Version
274
+ version: '0'
275
+ - !ruby/object:Gem::Dependency
276
+ name: derailed
277
+ requirement: !ruby/object:Gem::Requirement
278
+ requirements:
279
+ - - ">="
280
+ - !ruby/object:Gem::Version
281
+ version: '0'
282
+ type: :development
283
+ prerelease: false
284
+ version_requirements: !ruby/object:Gem::Requirement
285
+ requirements:
286
+ - - ">="
287
+ - !ruby/object:Gem::Version
288
+ version: '0'
289
+ - !ruby/object:Gem::Dependency
290
+ name: stackprof
291
+ requirement: !ruby/object:Gem::Requirement
292
+ requirements:
293
+ - - ">="
294
+ - !ruby/object:Gem::Version
295
+ version: '0'
296
+ type: :development
297
+ prerelease: false
298
+ version_requirements: !ruby/object:Gem::Requirement
299
+ requirements:
300
+ - - ">="
301
+ - !ruby/object:Gem::Version
302
+ version: '0'
303
+ - !ruby/object:Gem::Dependency
304
+ name: rubocop
305
+ requirement: !ruby/object:Gem::Requirement
306
+ requirements:
307
+ - - "~>"
308
+ - !ruby/object:Gem::Version
309
+ version: 0.40.0
310
+ type: :development
311
+ prerelease: false
312
+ version_requirements: !ruby/object:Gem::Requirement
313
+ requirements:
314
+ - - "~>"
315
+ - !ruby/object:Gem::Version
316
+ version: 0.40.0
317
+ description: Handle sort, filters, searches, and ranges on Rails collections.
318
+ email:
319
+ - andre.aubin@lambdaweb.fr
320
+ executables: []
321
+ extensions: []
322
+ extra_rdoc_files: []
323
+ files:
324
+ - ".gitignore"
325
+ - ".rubocop.yml"
326
+ - ".travis.yml"
327
+ - Gemfile
328
+ - Gemfile.lock
329
+ - LICENSE
330
+ - README.md
331
+ - Rakefile
332
+ - lib/rice_cooker.rb
333
+ - lib/rice_cooker/filter.rb
334
+ - lib/rice_cooker/helpers.rb
335
+ - lib/rice_cooker/range.rb
336
+ - lib/rice_cooker/sort.rb
337
+ - lib/rice_cooker/version.rb
338
+ - lib/tasks/rice_cooker_tasks.rake
339
+ - rice_cooker-0.1.0.gem
340
+ - rice_cooker.gemspec
341
+ - spec/filter/filter_spec.rb
342
+ - spec/mocks/config.rb
343
+ - spec/mocks/controllers/users_controller.rb
344
+ - spec/mocks/mocks.rb
345
+ - spec/mocks/models/user.rb
346
+ - spec/range/range_spec.rb
347
+ - spec/sort/sort_spec.rb
348
+ - spec/spec_helper.rb
349
+ homepage: https://github.com/lambda2/rice_cooker
350
+ licenses:
351
+ - MIT
352
+ metadata: {}
353
+ post_install_message:
354
+ rdoc_options: []
355
+ require_paths:
356
+ - lib
357
+ required_ruby_version: !ruby/object:Gem::Requirement
358
+ requirements:
359
+ - - ">="
360
+ - !ruby/object:Gem::Version
361
+ version: '0'
362
+ required_rubygems_version: !ruby/object:Gem::Requirement
363
+ requirements:
364
+ - - ">="
365
+ - !ruby/object:Gem::Version
366
+ version: '0'
367
+ requirements: []
368
+ rubyforge_project:
369
+ rubygems_version: 2.5.1
370
+ signing_key:
371
+ specification_version: 4
372
+ summary: A collection manager for Rails API's
373
+ test_files:
374
+ - spec/filter/filter_spec.rb
375
+ - spec/mocks/config.rb
376
+ - spec/mocks/controllers/users_controller.rb
377
+ - spec/mocks/mocks.rb
378
+ - spec/mocks/models/user.rb
379
+ - spec/range/range_spec.rb
380
+ - spec/sort/sort_spec.rb
381
+ - spec/spec_helper.rb