apicasso 0.6.0 → 0.6.1
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 +4 -4
- data/app/controllers/apicasso/apidocs_controller.rb +1 -1
- data/app/controllers/apicasso/application_controller.rb +0 -13
- data/app/controllers/apicasso/crud_controller.rb +13 -0
- data/lib/apicasso/version.rb +1 -1
- data/spec/dummy/log/test.log +2050 -0
- data/spec/requests/plurarized/bad_requests_with_plurarize_spec.rb +51 -0
- data/spec/requests/plurarized/requests_with_plurarize_spec.rb +337 -0
- data/spec/requests/{bad_requests_spec.rb → singularized/bad_requests_spec.rb} +0 -0
- data/spec/requests/{requests_spec.rb → singularized/requests_spec.rb} +13 -22
- data/spec/token/token_spec.rb +18 -0
- metadata +12 -6
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
RSpec.describe 'Used Model plurarized bad requests', type: :request do
|
5
|
+
token = Apicasso::Key.create(scope: { manage: { used_model: true } }).token
|
6
|
+
access_token = { 'AUTHORIZATION' => "Token token=#{token}" }
|
7
|
+
|
8
|
+
context 'raise a bad request when using SQL injection' do
|
9
|
+
it 'for grouping in fields' do
|
10
|
+
expect {
|
11
|
+
get '/api/v1/used_models', params: {
|
12
|
+
'group[by]': 'brand',
|
13
|
+
'group[calculate]': 'count',
|
14
|
+
'group[fields]': "'OR 1=1;"
|
15
|
+
}, headers: access_token
|
16
|
+
}.to raise_exception(ActionController::BadRequest)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'for sorting' do
|
20
|
+
expect {
|
21
|
+
get '/api/v1/used_models', params: { 'per_page': -1, 'sort': "'OR 1=1;" }, headers: access_token
|
22
|
+
}.to raise_exception(ActionController::BadRequest)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'for include' do
|
26
|
+
expect {
|
27
|
+
get '/api/v1/used_models', params: { 'include': "'OR 1=1;" }, headers: access_token
|
28
|
+
}.to raise_exception(ActionController::BadRequest)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'raise a bad request when using invalid resources' do
|
33
|
+
it 'for root resource' do
|
34
|
+
expect {
|
35
|
+
get '/api/v1/admins', headers: access_token
|
36
|
+
}.to raise_exception(ActionController::BadRequest)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'for nested resource' do
|
40
|
+
expect {
|
41
|
+
get '/api/v1/used_models/1/admins', headers: access_token
|
42
|
+
}.to raise_exception(ActionController::BadRequest)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'for include' do
|
46
|
+
expect {
|
47
|
+
get '/api/v1/used_models', params: { 'include': 'admins' }, headers: access_token
|
48
|
+
}.to raise_exception(ActionController::BadRequest)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,337 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
RSpec.describe 'Used Model requests', type: :request do
|
5
|
+
token = Apicasso::Key.create(scope: { manage: { used_model: true } }).token
|
6
|
+
access_token = { 'AUTHORIZATION' => "Token token=#{token}" }
|
7
|
+
|
8
|
+
describe 'GET /api/v1/used_models' do
|
9
|
+
context 'with default pagination' do
|
10
|
+
before(:all) do
|
11
|
+
get '/api/v1/used_models', headers: access_token
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns status ok' do
|
15
|
+
expect(response).to have_http_status(:ok)
|
16
|
+
end
|
17
|
+
it 'returns UsedModel records equal to WillPaginate.per_page or all UsedModels' do
|
18
|
+
if JSON.parse(response.body)['last_page'] == false
|
19
|
+
expect(JSON.parse(response.body)['entries'].size).to eq(WillPaginate.per_page)
|
20
|
+
else
|
21
|
+
expect(JSON.parse(response.body)['entries'].size).to eq(UsedModel.count)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with negative pagination' do
|
27
|
+
before(:all) do
|
28
|
+
get '/api/v1/used_models', params: { per_page: -1 }, headers: access_token
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns status ok' do
|
32
|
+
expect(response).to have_http_status(:ok)
|
33
|
+
end
|
34
|
+
it 'returns all UsedModel' do
|
35
|
+
expect(JSON.parse(response.body)['entries'].size).to eq(UsedModel.all.size)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with pagination' do
|
40
|
+
per_page = (1..UsedModel.count + 1).to_a.sample
|
41
|
+
page = (1..5).to_a.sample
|
42
|
+
|
43
|
+
before(:all) do
|
44
|
+
get '/api/v1/used_models', params: { per_page: per_page, page: page }, headers: access_token
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'returns status ok' do
|
48
|
+
expect(response).to have_http_status(:ok)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns size of records from UsedModel if not last page' do
|
52
|
+
expect(JSON.parse(response.body)['entries'].size).to be(per_page) if JSON.parse(response.body)['last_page'] == false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'by searching' do
|
57
|
+
brand_to_search = UsedModel.all.sample.brand
|
58
|
+
before(:all) do
|
59
|
+
get '/api/v1/used_models', params: { 'q[brand_matches]': brand_to_search }, headers: access_token
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns status ok' do
|
63
|
+
expect(response).to have_http_status(:ok)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns all records with brand queried' do
|
67
|
+
JSON.parse(response.body)['entries'].each do |record|
|
68
|
+
expect(record['brand']).to eq(brand_to_search)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'by grouping' do
|
74
|
+
column_by, column_fields = [:active, :account_id, :unit_id, :brand, :name, :slug,
|
75
|
+
:model, :version, :model_year, :production_year, :kind, :new_vehicle, :old_price,
|
76
|
+
:price_value, :price, :category, :transmission, :km_value, :km, :plate, :color, :doors,
|
77
|
+
:fuel, :fuel_text, :shielded].sample(2)
|
78
|
+
|
79
|
+
before(:all) do
|
80
|
+
get '/api/v1/used_models', params: {
|
81
|
+
'group[by]': column_by,
|
82
|
+
'group[calculate]': 'count',
|
83
|
+
'group[fields]': column_fields
|
84
|
+
}, headers: access_token
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns status ok' do
|
88
|
+
expect(response).to have_http_status(:ok)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns all records grouped by field queried' do
|
92
|
+
expect(response.body).to eq(UsedModel.where("#{column_fields} is NOT NULL").group(column_by).count.to_json)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'with sorting' do
|
97
|
+
before(:all) do
|
98
|
+
get '/api/v1/used_models', params: { 'per_page': -1, 'sort': '+brand,+model' }, headers: access_token
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'returns status ok' do
|
102
|
+
expect(response).to have_http_status(:ok)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns all records sorted queried' do
|
106
|
+
used_model_sorted = UsedModel.order(:brand, :model).map(&:id)
|
107
|
+
entries = JSON.parse(response.body)['entries'].map { |model| model['id'] }
|
108
|
+
expect(entries).to eq(used_model_sorted)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with field selecting' do
|
113
|
+
fields = UsedModel.column_names
|
114
|
+
fields.delete('id')
|
115
|
+
field_select = fields.sample
|
116
|
+
|
117
|
+
before(:all) do
|
118
|
+
get '/api/v1/used_models', params: { 'select': field_select }, headers: access_token
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'returns status ok' do
|
122
|
+
expect(response).to have_http_status(:ok)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns all records with id (default) and that have field queried' do
|
126
|
+
JSON.parse(response.body)['entries'].each do |record|
|
127
|
+
expect(record.keys).to eq(['id', field_select])
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with include associations valid' do
|
133
|
+
before(:all) do
|
134
|
+
get '/api/v1/used_models', params: { 'include': 'files_blobs,files_url' }, headers: access_token
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'returns status ok' do
|
138
|
+
expect(response).to have_http_status(:ok)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns all records with includes queried' do
|
142
|
+
JSON.parse(response.body)['entries'].each do |record|
|
143
|
+
expect(record.keys).to include('files_blobs', 'files_url')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when include invalid associations' do
|
149
|
+
it 'raise a bad request exception' do
|
150
|
+
expect {
|
151
|
+
get '/api/v1/used_models', params: { 'include': 'filess,filee' }, headers: access_token
|
152
|
+
}.to raise_exception(ActionController::BadRequest)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'GET /api/v1/used_models/:id' do
|
158
|
+
before(:all) do
|
159
|
+
get '/api/v1/used_models/' + UsedModel.all.sample.id.to_s, headers: access_token
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns status ok' do
|
163
|
+
expect(response).to have_http_status(:ok)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'returns a record with attributes' do
|
167
|
+
expect(JSON.parse(response.body).keys).to include('id', 'active', 'account_id', 'unit_id', 'brand', 'name', 'slug', 'model', 'version', 'model_year', 'production_year', 'kind', 'new_vehicle', 'old_price', 'price_value', 'price', 'category', 'transmission', 'km_value', 'km', 'plate', 'color', 'doors', 'fuel', 'fuel_text', 'note', 'chassis', 'shielded', 'featured', 'integrator', 'ordination', 'visits', 'bait_id', 'fipe_id', 'identifier', 'synced_at', 'deleted_at', 'created_at', 'updated_at')
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'return matches with object searched' do
|
171
|
+
expect(UsedModel.find(JSON.parse(response.body)['id']).attributes.to_json).to eq(response.body)
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'with field selecting' do
|
175
|
+
fields = UsedModel.column_names
|
176
|
+
fields.delete('id')
|
177
|
+
field_select = fields.sample
|
178
|
+
|
179
|
+
before(:all) do
|
180
|
+
get '/api/v1/used_models/' + UsedModel.all.sample.id.to_s, params: { 'select': field_select }, headers: access_token
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'returns status ok' do
|
184
|
+
expect(response).to have_http_status(:ok)
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'returns the record with id (default) and that have field queried' do
|
188
|
+
expect(JSON.parse(response.body).keys).to eq([field_select])
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'with include associations valid' do
|
193
|
+
before(:all) do
|
194
|
+
get '/api/v1/used_models/' + UsedModel.all.sample.id.to_s, params: { 'include': 'files_blobs,files_url' }, headers: access_token
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'returns status ok' do
|
198
|
+
expect(response).to have_http_status(:ok)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'returns the record with includes queried' do
|
202
|
+
expect(JSON.parse(response.body).keys).to include('files_blobs', 'files_url')
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when include invalid associations' do
|
207
|
+
it 'raise a bad request exception' do
|
208
|
+
expect {
|
209
|
+
get '/api/v1/used_models/' + UsedModel.all.sample.id.to_s, params: { 'include': 'filess,filee' }, headers: access_token
|
210
|
+
}.to raise_exception(ActionController::BadRequest)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe 'GET /api/v1/used_models/:slug' do
|
216
|
+
before(:all) do
|
217
|
+
get '/api/v1/used_models/' + UsedModel.all.sample.slug.to_s, headers: access_token
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'returns status ok' do
|
221
|
+
expect(response).to have_http_status(:ok)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'returns a record with attributes' do
|
225
|
+
expect(JSON.parse(response.body).keys).to include('id', 'active', 'account_id', 'unit_id', 'brand', 'name', 'slug', 'model', 'version', 'model_year', 'production_year', 'kind', 'new_vehicle', 'old_price', 'price_value', 'price', 'category', 'transmission', 'km_value', 'km', 'plate', 'color', 'doors', 'fuel', 'fuel_text', 'note', 'chassis', 'shielded', 'featured', 'integrator', 'ordination', 'visits', 'bait_id', 'fipe_id', 'identifier', 'synced_at', 'deleted_at', 'created_at', 'updated_at')
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'return matches with object searched' do
|
229
|
+
expect(UsedModel.friendly.find(JSON.parse(response.body)['slug']).attributes.to_json).to eq(response.body)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe 'POST /api/v1/used_models/' do
|
234
|
+
slug_to_post = Faker::Lorem.word
|
235
|
+
|
236
|
+
context 'with valid params' do
|
237
|
+
before(:all) do
|
238
|
+
@quantity = UsedModel.all.size
|
239
|
+
slug_to_post = Faker::Lorem.word
|
240
|
+
post '/api/v1/used_models/', params: {
|
241
|
+
'used_model': {
|
242
|
+
'active': Faker::Boolean.boolean,
|
243
|
+
'account_id': Faker::Number.number(1),
|
244
|
+
'unit_id': Faker::Number.number(1),
|
245
|
+
'brand': Faker::Vehicle.make,
|
246
|
+
'name': Faker::Vehicle.make_and_model,
|
247
|
+
'model': Faker::Vehicle.model,
|
248
|
+
'slug': slug_to_post,
|
249
|
+
'version': Faker::Number.decimal(1, 1),
|
250
|
+
'model_year': Faker::Vehicle.year,
|
251
|
+
'production_year': Faker::Vehicle.year,
|
252
|
+
'kind': 'car',
|
253
|
+
'new_vehicle': Faker::Boolean.boolean,
|
254
|
+
'old_price': Faker::Number.decimal(4, 2).to_s,
|
255
|
+
'price_value': Faker::Number.decimal(4, 2),
|
256
|
+
'price': Faker::Number.decimal(4, 2).to_s,
|
257
|
+
'category': Faker::Vehicle.car_type,
|
258
|
+
'transmission': Faker::Vehicle.transmission,
|
259
|
+
'km_value': Faker::Number.number(8),
|
260
|
+
'km': Faker::Number.number(8),
|
261
|
+
'plate': Faker::Number.number(4),
|
262
|
+
'color': Faker::Vehicle.color,
|
263
|
+
'doors': Faker::Number.number(1),
|
264
|
+
'fuel': Faker::Number.number(1),
|
265
|
+
'fuel_text': Faker::Vehicle.fuel_type,
|
266
|
+
'shielded': Faker::Boolean.boolean,
|
267
|
+
}}, headers: access_token
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'returns status created' do
|
271
|
+
expect(response).to have_http_status(:created)
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'check records size into db' do
|
275
|
+
expect(UsedModel.all.size).to eq(@quantity + 1)
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'find record into db' do
|
279
|
+
expect(UsedModel.find_by(slug: slug_to_post)).not_to eq nil
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
context 'with invalid params' do
|
284
|
+
it 'return a error' do
|
285
|
+
post '/api/v1/used_models/', params: { 'used_model': { 'slug': 'cr-v' }}, headers: access_token
|
286
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
describe 'PUT /api/v1/used_models/:id' do
|
292
|
+
name_to_put = Faker::Lorem.word
|
293
|
+
|
294
|
+
context 'with valid params' do
|
295
|
+
before(:all) do
|
296
|
+
patch '/api/v1/used_models/' + UsedModel.all.sample.id.to_s, params: { 'used_model': { 'name': name_to_put }}, headers: access_token
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'returns status ok' do
|
300
|
+
expect(response).to have_http_status(:ok)
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'updates requested record' do
|
304
|
+
expect(UsedModel.find(JSON.parse(response.body)['id']).name).to eq(name_to_put)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
context 'with invalid params' do
|
309
|
+
it 'return a error' do
|
310
|
+
patch '/api/v1/used_models/' + UsedModel.all.sample.id.to_s, params: { 'used_model': { 'unit_id': nil }}, headers: access_token
|
311
|
+
expect(response).to have_http_status(:unprocessable_entity)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe 'DELETE /api/v1/used_models/:id' do
|
317
|
+
context 'with valid params' do
|
318
|
+
before(:all) do
|
319
|
+
@quantity = UsedModel.all.size
|
320
|
+
@id_to_del = UsedModel.all.sample.id.to_s
|
321
|
+
delete '/api/v1/used_models/' + @id_to_del, headers: access_token
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'returns status no content' do
|
325
|
+
expect(response).to have_http_status(:no_content)
|
326
|
+
end
|
327
|
+
|
328
|
+
it 'detete a UsedModel record' do
|
329
|
+
expect(UsedModel.all.size).to eq(@quantity - 1)
|
330
|
+
end
|
331
|
+
|
332
|
+
it 'check if record was deleted' do
|
333
|
+
expect{ UsedModel.find(@id_to_del.to_i) }.to raise_exception(ActiveRecord::RecordNotFound)
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
File without changes
|
@@ -155,9 +155,8 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
describe 'GET /api/v1/used_model/:id' do
|
158
|
-
id_to_get_id = UsedModel.all.sample.id.to_s
|
159
158
|
before(:all) do
|
160
|
-
get '/api/v1/used_model/' +
|
159
|
+
get '/api/v1/used_model/' + UsedModel.all.sample.id.to_s, headers: access_token
|
161
160
|
end
|
162
161
|
|
163
162
|
it 'returns status ok' do
|
@@ -169,17 +168,16 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
169
168
|
end
|
170
169
|
|
171
170
|
it 'return matches with object searched' do
|
172
|
-
expect(UsedModel.find(
|
171
|
+
expect(UsedModel.find(JSON.parse(response.body)['id']).attributes.to_json).to eq(response.body)
|
173
172
|
end
|
174
173
|
|
175
174
|
context 'with field selecting' do
|
176
|
-
id_to_get_id = UsedModel.all.sample.id.to_s
|
177
175
|
fields = UsedModel.column_names
|
178
176
|
fields.delete('id')
|
179
177
|
field_select = fields.sample
|
180
178
|
|
181
179
|
before(:all) do
|
182
|
-
get '/api/v1/used_model/' +
|
180
|
+
get '/api/v1/used_model/' + UsedModel.all.sample.id.to_s, params: { 'select': field_select }, headers: access_token
|
183
181
|
end
|
184
182
|
|
185
183
|
it 'returns status ok' do
|
@@ -192,10 +190,8 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
192
190
|
end
|
193
191
|
|
194
192
|
context 'with include associations valid' do
|
195
|
-
id_to_test = UsedModel.all.sample.id.to_s
|
196
|
-
|
197
193
|
before(:all) do
|
198
|
-
get '/api/v1/used_model/' +
|
194
|
+
get '/api/v1/used_model/' + UsedModel.all.sample.id.to_s, params: { 'include': 'files_blobs,files_url' }, headers: access_token
|
199
195
|
end
|
200
196
|
|
201
197
|
it 'returns status ok' do
|
@@ -208,20 +204,17 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
208
204
|
end
|
209
205
|
|
210
206
|
context 'when include invalid associations' do
|
211
|
-
id_to_test = UsedModel.all.sample.id.to_s
|
212
|
-
|
213
207
|
it 'raise a bad request exception' do
|
214
208
|
expect {
|
215
|
-
get '/api/v1/used_model/' +
|
209
|
+
get '/api/v1/used_model/' + UsedModel.all.sample.id.to_s, params: { 'include': 'filess,filee' }, headers: access_token
|
216
210
|
}.to raise_exception(ActionController::BadRequest)
|
217
211
|
end
|
218
212
|
end
|
219
213
|
end
|
220
214
|
|
221
215
|
describe 'GET /api/v1/used_model/:slug' do
|
222
|
-
id_to_get_slug = UsedModel.all.sample.slug.to_s
|
223
216
|
before(:all) do
|
224
|
-
get '/api/v1/used_model/' +
|
217
|
+
get '/api/v1/used_model/' + UsedModel.all.sample.slug.to_s, headers: access_token
|
225
218
|
end
|
226
219
|
|
227
220
|
it 'returns status ok' do
|
@@ -233,7 +226,7 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
233
226
|
end
|
234
227
|
|
235
228
|
it 'return matches with object searched' do
|
236
|
-
expect(UsedModel.friendly.find(
|
229
|
+
expect(UsedModel.friendly.find(JSON.parse(response.body)['slug']).attributes.to_json).to eq(response.body)
|
237
230
|
end
|
238
231
|
end
|
239
232
|
|
@@ -296,12 +289,11 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
296
289
|
end
|
297
290
|
|
298
291
|
describe 'PUT /api/v1/used_model/:id' do
|
299
|
-
id_to_put = UsedModel.all.sample.id.to_s
|
300
292
|
name_to_put = Faker::Lorem.word
|
301
293
|
|
302
294
|
context 'with valid params' do
|
303
295
|
before(:all) do
|
304
|
-
patch '/api/v1/used_model/' +
|
296
|
+
patch '/api/v1/used_model/' + UsedModel.all.sample.id.to_s, params: { 'used_model': { 'name': name_to_put }}, headers: access_token
|
305
297
|
end
|
306
298
|
|
307
299
|
it 'returns status ok' do
|
@@ -309,25 +301,24 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
309
301
|
end
|
310
302
|
|
311
303
|
it 'updates requested record' do
|
312
|
-
expect(UsedModel.find(
|
304
|
+
expect(UsedModel.find(JSON.parse(response.body)['id']).name).to eq(name_to_put)
|
313
305
|
end
|
314
306
|
end
|
315
307
|
|
316
308
|
context 'with invalid params' do
|
317
309
|
it 'return a error' do
|
318
|
-
patch '/api/v1/used_model/' +
|
310
|
+
patch '/api/v1/used_model/' + UsedModel.all.sample.id.to_s, params: { 'used_model': { 'unit_id': nil }}, headers: access_token
|
319
311
|
expect(response).to have_http_status(:unprocessable_entity)
|
320
312
|
end
|
321
313
|
end
|
322
314
|
end
|
323
315
|
|
324
316
|
describe 'DELETE /api/v1/used_model/:id' do
|
325
|
-
id_to_del = UsedModel.all.sample.id.to_s
|
326
|
-
|
327
317
|
context 'with valid params' do
|
328
318
|
before(:all) do
|
329
319
|
@quantity = UsedModel.all.size
|
330
|
-
|
320
|
+
@id_to_del = UsedModel.all.sample.id.to_s
|
321
|
+
delete '/api/v1/used_model/' + @id_to_del, headers: access_token
|
331
322
|
end
|
332
323
|
|
333
324
|
it 'returns status no content' do
|
@@ -339,7 +330,7 @@ RSpec.describe 'Used Model requests', type: :request do
|
|
339
330
|
end
|
340
331
|
|
341
332
|
it 'check if record was deleted' do
|
342
|
-
expect{ UsedModel.find(id_to_del.to_i) }.to raise_exception(ActiveRecord::RecordNotFound)
|
333
|
+
expect{ UsedModel.find(@id_to_del.to_i) }.to raise_exception(ActiveRecord::RecordNotFound)
|
343
334
|
end
|
344
335
|
end
|
345
336
|
end
|
data/spec/token/token_spec.rb
CHANGED
@@ -318,5 +318,23 @@ RSpec.describe 'Apicasso Keys', type: :request do
|
|
318
318
|
expect(UsedModel.all.size).to eq(size_before - 1)
|
319
319
|
end
|
320
320
|
end
|
321
|
+
|
322
|
+
context 'with a false key' do
|
323
|
+
access_token = { 'AUTHORIZATION' => "Token token=notavalidtoken" }
|
324
|
+
|
325
|
+
it 'returns unauthorized to request' do
|
326
|
+
get '/api/v1/used_model', headers: access_token
|
327
|
+
expect(response).to have_http_status(:unauthorized)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
context 'with an empty key' do
|
332
|
+
access_token = { 'AUTHORIZATION' => "Token token=" }
|
333
|
+
|
334
|
+
it 'returns unauthorized to request' do
|
335
|
+
get '/api/v1/used_model', headers: access_token
|
336
|
+
expect(response).to have_http_status(:unauthorized)
|
337
|
+
end
|
338
|
+
end
|
321
339
|
end
|
322
340
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apicasso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Bellincanta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -292,12 +292,15 @@ files:
|
|
292
292
|
- spec/dummy/db/migrate/20180920133933_change_used_model_to_validates.rb
|
293
293
|
- spec/dummy/db/schema.rb
|
294
294
|
- spec/dummy/db/seeds.rb
|
295
|
+
- spec/dummy/log/test.log
|
295
296
|
- spec/dummy/package.json
|
296
297
|
- spec/factories/used_model.rb
|
297
298
|
- spec/models/used_model_spec.rb
|
298
299
|
- spec/rails_helper.rb
|
299
|
-
- spec/requests/
|
300
|
-
- spec/requests/
|
300
|
+
- spec/requests/plurarized/bad_requests_with_plurarize_spec.rb
|
301
|
+
- spec/requests/plurarized/requests_with_plurarize_spec.rb
|
302
|
+
- spec/requests/singularized/bad_requests_spec.rb
|
303
|
+
- spec/requests/singularized/requests_spec.rb
|
301
304
|
- spec/spec_helper.rb
|
302
305
|
- spec/support/database_cleaner.rb
|
303
306
|
- spec/support/factory_bot.rb
|
@@ -363,13 +366,16 @@ test_files:
|
|
363
366
|
- spec/dummy/db/seeds.rb
|
364
367
|
- spec/dummy/Gemfile
|
365
368
|
- spec/dummy/Gemfile.lock
|
369
|
+
- spec/dummy/log/test.log
|
366
370
|
- spec/dummy/package.json
|
367
371
|
- spec/dummy/Rakefile
|
368
372
|
- spec/factories/used_model.rb
|
369
373
|
- spec/models/used_model_spec.rb
|
370
374
|
- spec/rails_helper.rb
|
371
|
-
- spec/requests/
|
372
|
-
- spec/requests/
|
375
|
+
- spec/requests/plurarized/bad_requests_with_plurarize_spec.rb
|
376
|
+
- spec/requests/plurarized/requests_with_plurarize_spec.rb
|
377
|
+
- spec/requests/singularized/bad_requests_spec.rb
|
378
|
+
- spec/requests/singularized/requests_spec.rb
|
373
379
|
- spec/spec_helper.rb
|
374
380
|
- spec/support/database_cleaner.rb
|
375
381
|
- spec/support/factory_bot.rb
|