solidus_api 2.9.6 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -2
  3. data/app/controllers/spree/api/addresses_controller.rb +2 -2
  4. data/app/controllers/spree/api/base_controller.rb +21 -13
  5. data/app/controllers/spree/api/checkouts_controller.rb +1 -11
  6. data/app/controllers/spree/api/countries_controller.rb +2 -2
  7. data/app/controllers/spree/api/credit_cards_controller.rb +3 -3
  8. data/app/controllers/spree/api/customer_returns_controller.rb +67 -0
  9. data/app/controllers/spree/api/images_controller.rb +5 -5
  10. data/app/controllers/spree/api/inventory_units_controller.rb +2 -2
  11. data/app/controllers/spree/api/option_types_controller.rb +4 -4
  12. data/app/controllers/spree/api/option_values_controller.rb +3 -3
  13. data/app/controllers/spree/api/orders_controller.rb +11 -6
  14. data/app/controllers/spree/api/payments_controller.rb +2 -2
  15. data/app/controllers/spree/api/product_properties_controller.rb +9 -14
  16. data/app/controllers/spree/api/promotions_controller.rb +3 -12
  17. data/app/controllers/spree/api/properties_controller.rb +4 -4
  18. data/app/controllers/spree/api/resource_controller.rb +3 -3
  19. data/app/controllers/spree/api/return_authorizations_controller.rb +4 -4
  20. data/app/controllers/spree/api/shipments_controller.rb +2 -2
  21. data/app/controllers/spree/api/states_controller.rb +3 -3
  22. data/app/controllers/spree/api/stock_items_controller.rb +3 -3
  23. data/app/controllers/spree/api/stock_locations_controller.rb +4 -4
  24. data/app/controllers/spree/api/stock_movements_controller.rb +3 -3
  25. data/app/controllers/spree/api/stores_controller.rb +4 -4
  26. data/app/controllers/spree/api/taxonomies_controller.rb +5 -3
  27. data/app/controllers/spree/api/taxons_controller.rb +5 -5
  28. data/app/controllers/spree/api/users_controller.rb +13 -0
  29. data/app/controllers/spree/api/variants_controller.rb +4 -4
  30. data/app/controllers/spree/api/zones_controller.rb +3 -3
  31. data/app/helpers/spree/api/api_helpers.rb +20 -7
  32. data/app/views/spree/api/customer_returns/index.json.jbuilder +6 -0
  33. data/app/views/spree/api/customer_returns/new.json.jbuilder +4 -0
  34. data/app/views/spree/api/customer_returns/show.json.jbuilder +3 -0
  35. data/app/views/spree/api/errors/could_not_transition.json.jbuilder +4 -0
  36. data/app/views/spree/api/images/_image.json.jbuilder +2 -2
  37. data/app/views/spree/api/orders/_order.json.jbuilder +1 -1
  38. data/app/views/spree/api/orders/could_not_transition.json.jbuilder +5 -0
  39. data/app/views/spree/api/shared/_pagination.json.jbuilder +1 -1
  40. data/config/locales/en.yml +2 -0
  41. data/config/routes.rb +6 -3
  42. data/lib/spree/api.rb +0 -7
  43. data/lib/spree/api/config.rb +9 -0
  44. data/lib/spree/api/engine.rb +4 -4
  45. data/lib/spree/api/responders.rb +3 -2
  46. data/lib/spree/api/responders/{rabl_template.rb → jbuilder_template.rb} +3 -1
  47. data/lib/spree/api/testing_support/helpers.rb +1 -1
  48. data/{app/models → lib}/spree/api_configuration.rb +0 -0
  49. data/openapi/.stoplight.yml +7 -0
  50. data/openapi/authentication.md +33 -0
  51. data/openapi/checkout-flow.md +63 -0
  52. data/openapi/errors.md +3 -0
  53. data/openapi/lint.yml +1 -0
  54. data/openapi/main.hub.yml +65 -0
  55. data/openapi/pagination.md +7 -0
  56. data/openapi/solidus-api.oas.yml +6753 -0
  57. data/openapi/theme.css +0 -0
  58. data/solidus_api.gemspec +19 -19
  59. metadata +27 -115
  60. data/script/rails +0 -10
  61. data/spec/controllers/spree/api/base_controller_spec.rb +0 -118
  62. data/spec/controllers/spree/api/resource_controller_spec.rb +0 -190
  63. data/spec/features/checkout_spec.rb +0 -192
  64. data/spec/fixtures/thinking-cat.jpg +0 -0
  65. data/spec/models/spree/legacy_user_spec.rb +0 -103
  66. data/spec/requests/api/address_books_spec.rb +0 -240
  67. data/spec/requests/rabl_cache_spec.rb +0 -34
  68. data/spec/requests/ransackable_attributes_spec.rb +0 -79
  69. data/spec/requests/spree/api/addresses_controller_spec.rb +0 -57
  70. data/spec/requests/spree/api/checkouts_controller_spec.rb +0 -484
  71. data/spec/requests/spree/api/classifications_controller_spec.rb +0 -50
  72. data/spec/requests/spree/api/config_controller_spec.rb +0 -26
  73. data/spec/requests/spree/api/countries_controller_spec.rb +0 -48
  74. data/spec/requests/spree/api/coupon_codes_controller_spec.rb +0 -105
  75. data/spec/requests/spree/api/credit_cards_controller_spec.rb +0 -105
  76. data/spec/requests/spree/api/images_controller_spec.rb +0 -99
  77. data/spec/requests/spree/api/inventory_units_controller_spec.rb +0 -55
  78. data/spec/requests/spree/api/line_items_controller_spec.rb +0 -213
  79. data/spec/requests/spree/api/option_types_controller_spec.rb +0 -116
  80. data/spec/requests/spree/api/option_values_controller_spec.rb +0 -138
  81. data/spec/requests/spree/api/orders_controller_spec.rb +0 -954
  82. data/spec/requests/spree/api/payments_controller_spec.rb +0 -259
  83. data/spec/requests/spree/api/product_properties_controller_spec.rb +0 -114
  84. data/spec/requests/spree/api/products_controller_spec.rb +0 -422
  85. data/spec/requests/spree/api/promotion_application_spec.rb +0 -50
  86. data/spec/requests/spree/api/promotions_controller_spec.rb +0 -67
  87. data/spec/requests/spree/api/properties_controller_spec.rb +0 -102
  88. data/spec/requests/spree/api/return_authorizations_controller_spec.rb +0 -180
  89. data/spec/requests/spree/api/shipments_controller_spec.rb +0 -532
  90. data/spec/requests/spree/api/states_controller_spec.rb +0 -69
  91. data/spec/requests/spree/api/stock_items_controller_spec.rb +0 -311
  92. data/spec/requests/spree/api/stock_locations_controller_spec.rb +0 -170
  93. data/spec/requests/spree/api/stock_movements_controller_spec.rb +0 -81
  94. data/spec/requests/spree/api/store_credit_events_controller_spec.rb +0 -59
  95. data/spec/requests/spree/api/stores_controller_spec.rb +0 -134
  96. data/spec/requests/spree/api/taxonomies_controller_spec.rb +0 -114
  97. data/spec/requests/spree/api/taxons_controller_spec.rb +0 -217
  98. data/spec/requests/spree/api/unauthenticated_products_controller_spec.rb +0 -27
  99. data/spec/requests/spree/api/users_controller_spec.rb +0 -151
  100. data/spec/requests/spree/api/variants_controller_spec.rb +0 -340
  101. data/spec/requests/spree/api/zones_controller_spec.rb +0 -89
  102. data/spec/shared_examples/protect_product_actions.rb +0 -18
  103. data/spec/spec_helper.rb +0 -73
  104. data/spec/support/be_paginated_matcher.rb +0 -9
  105. data/spec/support/controller_hacks.rb +0 -43
  106. data/spec/support/database_cleaner.rb +0 -16
  107. data/spec/support/have_attributes_matcher.rb +0 -11
  108. data/spec/test_views/spree/api/widgets/_widget.json.jbuilder +0 -3
  109. data/spec/test_views/spree/api/widgets/index.json.jbuilder +0 -9
  110. data/spec/test_views/spree/api/widgets/new.json.jbuilder +0 -3
  111. data/spec/test_views/spree/api/widgets/show.json.jbuilder +0 -3
File without changes
@@ -2,27 +2,27 @@
2
2
 
3
3
  require_relative '../core/lib/spree/core/version.rb'
4
4
 
5
- Gem::Specification.new do |gem|
6
- gem.author = 'Solidus Team'
7
- gem.email = 'contact@solidus.io'
8
- gem.homepage = 'http://solidus.io/'
9
- gem.license = 'BSD-3-Clause'
5
+ Gem::Specification.new do |s|
6
+ s.platform = Gem::Platform::RUBY
7
+ s.name = "solidus_api"
8
+ s.version = Spree.solidus_version
9
+ s.summary = 'REST API for the Solidus e-commerce framework.'
10
+ s.description = s.summary
10
11
 
11
- gem.summary = 'REST API for the Solidus e-commerce framework.'
12
- gem.description = gem.summary
12
+ s.author = 'Solidus Team'
13
+ s.email = 'contact@solidus.io'
14
+ s.homepage = 'http://solidus.io'
15
+ s.license = 'BSD-3-Clause'
13
16
 
14
- gem.files = `git ls-files`.split($\)
15
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
- gem.name = "solidus_api"
18
- gem.require_paths = ["lib"]
19
- gem.version = Spree.solidus_version
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(spec|script)/})
19
+ end
20
20
 
21
- gem.required_ruby_version = '>= 2.2.2'
22
- gem.required_rubygems_version = '>= 1.8.23'
21
+ s.required_ruby_version = '>= 2.5.0'
22
+ s.required_rubygems_version = '>= 1.8.23'
23
23
 
24
- gem.add_dependency 'jbuilder', '~> 2.8'
25
- gem.add_dependency 'kaminari-activerecord', '~> 1.1'
26
- gem.add_dependency 'responders'
27
- gem.add_dependency 'solidus_core', gem.version
24
+ s.add_dependency 'jbuilder', '~> 2.8'
25
+ s.add_dependency 'kaminari-activerecord', '~> 1.1'
26
+ s.add_dependency 'responders'
27
+ s.add_dependency 'solidus_core', s.version
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.6
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-16 00:00:00.000000000 Z
11
+ date: 2020-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.9.6
61
+ version: 2.11.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.9.6
68
+ version: 2.11.0
69
69
  description: REST API for the Solidus e-commerce framework.
70
70
  email: contact@solidus.io
71
71
  executables: []
@@ -85,6 +85,7 @@ files:
85
85
  - app/controllers/spree/api/countries_controller.rb
86
86
  - app/controllers/spree/api/coupon_codes_controller.rb
87
87
  - app/controllers/spree/api/credit_cards_controller.rb
88
+ - app/controllers/spree/api/customer_returns_controller.rb
88
89
  - app/controllers/spree/api/images_controller.rb
89
90
  - app/controllers/spree/api/inventory_units_controller.rb
90
91
  - app/controllers/spree/api/line_items_controller.rb
@@ -111,7 +112,6 @@ files:
111
112
  - app/controllers/spree/api/variants_controller.rb
112
113
  - app/controllers/spree/api/zones_controller.rb
113
114
  - app/helpers/spree/api/api_helpers.rb
114
- - app/models/spree/api_configuration.rb
115
115
  - app/views/.rubocop.yml
116
116
  - app/views/spree/api/address_books/show.json.jbuilder
117
117
  - app/views/spree/api/addresses/_address.json.jbuilder
@@ -124,6 +124,10 @@ files:
124
124
  - app/views/spree/api/credit_cards/_credit_card.json.jbuilder
125
125
  - app/views/spree/api/credit_cards/index.json.jbuilder
126
126
  - app/views/spree/api/credit_cards/show.json.jbuilder
127
+ - app/views/spree/api/customer_returns/index.json.jbuilder
128
+ - app/views/spree/api/customer_returns/new.json.jbuilder
129
+ - app/views/spree/api/customer_returns/show.json.jbuilder
130
+ - app/views/spree/api/errors/could_not_transition.json.jbuilder
127
131
  - app/views/spree/api/errors/delete_restriction.json.jbuilder
128
132
  - app/views/spree/api/errors/gateway_error.json.jbuilder
129
133
  - app/views/spree/api/errors/invalid_api_key.json.jbuilder
@@ -230,71 +234,30 @@ files:
230
234
  - db/migrate/20131017162334_add_index_to_user_spree_api_key.rb
231
235
  - lib/solidus_api.rb
232
236
  - lib/spree/api.rb
237
+ - lib/spree/api/config.rb
233
238
  - lib/spree/api/engine.rb
234
239
  - lib/spree/api/responders.rb
235
- - lib/spree/api/responders/rabl_template.rb
240
+ - lib/spree/api/responders/jbuilder_template.rb
236
241
  - lib/spree/api/testing_support/caching.rb
237
242
  - lib/spree/api/testing_support/helpers.rb
238
243
  - lib/spree/api/testing_support/setup.rb
244
+ - lib/spree/api_configuration.rb
239
245
  - lib/spree_api.rb
240
- - script/rails
246
+ - openapi/.stoplight.yml
247
+ - openapi/authentication.md
248
+ - openapi/checkout-flow.md
249
+ - openapi/errors.md
250
+ - openapi/lint.yml
251
+ - openapi/main.hub.yml
252
+ - openapi/pagination.md
253
+ - openapi/solidus-api.oas.yml
254
+ - openapi/theme.css
241
255
  - solidus_api.gemspec
242
- - spec/controllers/spree/api/base_controller_spec.rb
243
- - spec/controllers/spree/api/resource_controller_spec.rb
244
- - spec/features/checkout_spec.rb
245
- - spec/fixtures/thinking-cat.jpg
246
- - spec/models/spree/legacy_user_spec.rb
247
- - spec/requests/api/address_books_spec.rb
248
- - spec/requests/rabl_cache_spec.rb
249
- - spec/requests/ransackable_attributes_spec.rb
250
- - spec/requests/spree/api/addresses_controller_spec.rb
251
- - spec/requests/spree/api/checkouts_controller_spec.rb
252
- - spec/requests/spree/api/classifications_controller_spec.rb
253
- - spec/requests/spree/api/config_controller_spec.rb
254
- - spec/requests/spree/api/countries_controller_spec.rb
255
- - spec/requests/spree/api/coupon_codes_controller_spec.rb
256
- - spec/requests/spree/api/credit_cards_controller_spec.rb
257
- - spec/requests/spree/api/images_controller_spec.rb
258
- - spec/requests/spree/api/inventory_units_controller_spec.rb
259
- - spec/requests/spree/api/line_items_controller_spec.rb
260
- - spec/requests/spree/api/option_types_controller_spec.rb
261
- - spec/requests/spree/api/option_values_controller_spec.rb
262
- - spec/requests/spree/api/orders_controller_spec.rb
263
- - spec/requests/spree/api/payments_controller_spec.rb
264
- - spec/requests/spree/api/product_properties_controller_spec.rb
265
- - spec/requests/spree/api/products_controller_spec.rb
266
- - spec/requests/spree/api/promotion_application_spec.rb
267
- - spec/requests/spree/api/promotions_controller_spec.rb
268
- - spec/requests/spree/api/properties_controller_spec.rb
269
- - spec/requests/spree/api/return_authorizations_controller_spec.rb
270
- - spec/requests/spree/api/shipments_controller_spec.rb
271
- - spec/requests/spree/api/states_controller_spec.rb
272
- - spec/requests/spree/api/stock_items_controller_spec.rb
273
- - spec/requests/spree/api/stock_locations_controller_spec.rb
274
- - spec/requests/spree/api/stock_movements_controller_spec.rb
275
- - spec/requests/spree/api/store_credit_events_controller_spec.rb
276
- - spec/requests/spree/api/stores_controller_spec.rb
277
- - spec/requests/spree/api/taxonomies_controller_spec.rb
278
- - spec/requests/spree/api/taxons_controller_spec.rb
279
- - spec/requests/spree/api/unauthenticated_products_controller_spec.rb
280
- - spec/requests/spree/api/users_controller_spec.rb
281
- - spec/requests/spree/api/variants_controller_spec.rb
282
- - spec/requests/spree/api/zones_controller_spec.rb
283
- - spec/shared_examples/protect_product_actions.rb
284
- - spec/spec_helper.rb
285
- - spec/support/be_paginated_matcher.rb
286
- - spec/support/controller_hacks.rb
287
- - spec/support/database_cleaner.rb
288
- - spec/support/have_attributes_matcher.rb
289
- - spec/test_views/spree/api/widgets/_widget.json.jbuilder
290
- - spec/test_views/spree/api/widgets/index.json.jbuilder
291
- - spec/test_views/spree/api/widgets/new.json.jbuilder
292
- - spec/test_views/spree/api/widgets/show.json.jbuilder
293
- homepage: http://solidus.io/
256
+ homepage: http://solidus.io
294
257
  licenses:
295
258
  - BSD-3-Clause
296
259
  metadata: {}
297
- post_install_message:
260
+ post_install_message:
298
261
  rdoc_options: []
299
262
  require_paths:
300
263
  - lib
@@ -302,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
302
265
  requirements:
303
266
  - - ">="
304
267
  - !ruby/object:Gem::Version
305
- version: 2.2.2
268
+ version: 2.5.0
306
269
  required_rubygems_version: !ruby/object:Gem::Requirement
307
270
  requirements:
308
271
  - - ">="
@@ -310,58 +273,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
310
273
  version: 1.8.23
311
274
  requirements: []
312
275
  rubygems_version: 3.0.3
313
- signing_key:
276
+ signing_key:
314
277
  specification_version: 4
315
278
  summary: REST API for the Solidus e-commerce framework.
316
- test_files:
317
- - spec/controllers/spree/api/base_controller_spec.rb
318
- - spec/controllers/spree/api/resource_controller_spec.rb
319
- - spec/features/checkout_spec.rb
320
- - spec/fixtures/thinking-cat.jpg
321
- - spec/models/spree/legacy_user_spec.rb
322
- - spec/requests/api/address_books_spec.rb
323
- - spec/requests/rabl_cache_spec.rb
324
- - spec/requests/ransackable_attributes_spec.rb
325
- - spec/requests/spree/api/addresses_controller_spec.rb
326
- - spec/requests/spree/api/checkouts_controller_spec.rb
327
- - spec/requests/spree/api/classifications_controller_spec.rb
328
- - spec/requests/spree/api/config_controller_spec.rb
329
- - spec/requests/spree/api/countries_controller_spec.rb
330
- - spec/requests/spree/api/coupon_codes_controller_spec.rb
331
- - spec/requests/spree/api/credit_cards_controller_spec.rb
332
- - spec/requests/spree/api/images_controller_spec.rb
333
- - spec/requests/spree/api/inventory_units_controller_spec.rb
334
- - spec/requests/spree/api/line_items_controller_spec.rb
335
- - spec/requests/spree/api/option_types_controller_spec.rb
336
- - spec/requests/spree/api/option_values_controller_spec.rb
337
- - spec/requests/spree/api/orders_controller_spec.rb
338
- - spec/requests/spree/api/payments_controller_spec.rb
339
- - spec/requests/spree/api/product_properties_controller_spec.rb
340
- - spec/requests/spree/api/products_controller_spec.rb
341
- - spec/requests/spree/api/promotion_application_spec.rb
342
- - spec/requests/spree/api/promotions_controller_spec.rb
343
- - spec/requests/spree/api/properties_controller_spec.rb
344
- - spec/requests/spree/api/return_authorizations_controller_spec.rb
345
- - spec/requests/spree/api/shipments_controller_spec.rb
346
- - spec/requests/spree/api/states_controller_spec.rb
347
- - spec/requests/spree/api/stock_items_controller_spec.rb
348
- - spec/requests/spree/api/stock_locations_controller_spec.rb
349
- - spec/requests/spree/api/stock_movements_controller_spec.rb
350
- - spec/requests/spree/api/store_credit_events_controller_spec.rb
351
- - spec/requests/spree/api/stores_controller_spec.rb
352
- - spec/requests/spree/api/taxonomies_controller_spec.rb
353
- - spec/requests/spree/api/taxons_controller_spec.rb
354
- - spec/requests/spree/api/unauthenticated_products_controller_spec.rb
355
- - spec/requests/spree/api/users_controller_spec.rb
356
- - spec/requests/spree/api/variants_controller_spec.rb
357
- - spec/requests/spree/api/zones_controller_spec.rb
358
- - spec/shared_examples/protect_product_actions.rb
359
- - spec/spec_helper.rb
360
- - spec/support/be_paginated_matcher.rb
361
- - spec/support/controller_hacks.rb
362
- - spec/support/database_cleaner.rb
363
- - spec/support/have_attributes_matcher.rb
364
- - spec/test_views/spree/api/widgets/_widget.json.jbuilder
365
- - spec/test_views/spree/api/widgets/index.json.jbuilder
366
- - spec/test_views/spree/api/widgets/new.json.jbuilder
367
- - spec/test_views/spree/api/widgets/show.json.jbuilder
279
+ test_files: []
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
5
-
6
- ENGINE_ROOT = File.expand_path('..', __dir__)
7
- ENGINE_PATH = File.expand_path('../lib/spree/api/engine', __dir__)
8
-
9
- require 'rails/all'
10
- require 'rails/engine/commands'
@@ -1,118 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- class FakesController < Spree::Api::BaseController
6
- end
7
-
8
- describe Spree::Api::BaseController, type: :controller do
9
- render_views
10
- controller(Spree::Api::BaseController) do
11
- rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
12
-
13
- def index
14
- render json: { "products" => [] }
15
- end
16
- end
17
-
18
- before do
19
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
20
- r.draw { get 'index', to: 'spree/api/base#index' }
21
- end
22
- end
23
-
24
- context "when validating based on an order token" do
25
- let!(:order) { create :order }
26
-
27
- context "with a correct order token" do
28
- it "succeeds" do
29
- get :index, params: { order_token: order.guest_token, order_id: order.number }
30
- expect(response.status).to eq(200)
31
- end
32
-
33
- it "succeeds with an order_number parameter" do
34
- get :index, params: { order_token: order.guest_token, order_number: order.number }
35
- expect(response.status).to eq(200)
36
- end
37
- end
38
-
39
- context "with an incorrect order token" do
40
- it "returns unauthorized" do
41
- get :index, params: { order_token: "NOT_A_TOKEN", order_id: order.number }
42
- expect(response.status).to eq(401)
43
- end
44
- end
45
- end
46
-
47
- context "cannot make a request to the API" do
48
- it "without an API key" do
49
- get :index
50
- expect(json_response).to eq({ "error" => "You must specify an API key." })
51
- expect(response.status).to eq(401)
52
- end
53
-
54
- it "with an invalid API key" do
55
- request.headers["Authorization"] = "Bearer fake_key"
56
- get :index, params: {}
57
- expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
58
- expect(response.status).to eq(401)
59
- end
60
-
61
- it "using an invalid token param" do
62
- get :index, params: { token: "fake_key" }
63
- expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
64
- end
65
- end
66
-
67
- it "lets a subclass override the product associations that are eager-loaded" do
68
- expect(controller.respond_to?(:product_includes, true)).to be
69
- end
70
-
71
- context 'insufficient stock' do
72
- before do
73
- expect(subject).to receive(:authenticate_user).and_return(true)
74
- expect(subject).to receive(:index).and_raise(Spree::Order::InsufficientStock)
75
- get :index, params: { token: "fake_key" }
76
- end
77
-
78
- it "should return a 422" do
79
- expect(response.status).to eq(422)
80
- end
81
-
82
- it "returns an error message" do
83
- expect(json_response).to eq(
84
- { "errors" => ["Quantity is not available for items in your order"], "type" => "insufficient_stock" }
85
- )
86
- end
87
- end
88
-
89
- context 'lock_order' do
90
- let!(:order) { create :order }
91
-
92
- controller(Spree::Api::BaseController) do
93
- around_action :lock_order
94
-
95
- def index
96
- render json: { "products" => [] }
97
- end
98
- end
99
-
100
- context 'without an existing lock' do
101
- it 'succeeds' do
102
- get :index, params: { order_token: order.guest_token, order_id: order.number }
103
- expect(response.status).to eq(200)
104
- end
105
- end
106
-
107
- context 'with an existing lock' do
108
- around do |example|
109
- Spree::OrderMutex.with_lock!(order) { example.run }
110
- end
111
-
112
- it 'returns a 409 conflict' do
113
- get :index, params: { order_token: order.guest_token, order_id: order.number }
114
- expect(response.status).to eq(409)
115
- end
116
- end
117
- end
118
- end
@@ -1,190 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- module Spree
6
- module Api
7
- class WidgetsController < Spree::Api::ResourceController
8
- prepend_view_path('spec/test_views')
9
-
10
- def model_class
11
- Widget
12
- end
13
-
14
- def permitted_widget_attributes
15
- [:name]
16
- end
17
- end
18
- end
19
-
20
- describe Api::WidgetsController, type: :controller do
21
- render_views
22
-
23
- after(:all) do
24
- Rails.application.reload_routes!
25
- end
26
-
27
- with_model 'Widget', scope: :all do
28
- table do |t|
29
- t.string :name
30
- t.integer :position
31
- t.timestamps null: false
32
- end
33
-
34
- model do
35
- acts_as_list
36
- validates :name, presence: true
37
- end
38
- end
39
-
40
- before do
41
- Spree::Core::Engine.routes.draw do
42
- namespace :api do
43
- resources :widgets
44
- end
45
- end
46
- end
47
-
48
- let(:user) { create(:user, :with_api_key) }
49
- let(:admin_user) { create(:admin_user, :with_api_key) }
50
-
51
- describe "#index" do
52
- let!(:widget) { Widget.create!(name: "a widget") }
53
-
54
- it "returns no widgets" do
55
- get :index, params: { token: user.spree_api_key }, as: :json
56
- expect(response).to be_successful
57
- expect(json_response['widgets']).to be_blank
58
- end
59
-
60
- context "it has authorization to read widgets" do
61
- it "returns widgets" do
62
- get :index, params: { token: admin_user.spree_api_key }, as: :json
63
- expect(response).to be_successful
64
- expect(json_response['widgets']).to include(
65
- hash_including(
66
- 'name' => 'a widget',
67
- 'position' => 1
68
- )
69
- )
70
- end
71
-
72
- context "specifying ids" do
73
- let!(:widget2) { Widget.create!(name: "a widget") }
74
-
75
- it "returns both widgets from comma separated string" do
76
- get :index, params: { ids: [widget.id, widget2.id].join(','), token: admin_user.spree_api_key }, as: :json
77
- expect(response).to be_successful
78
- expect(json_response['widgets'].size).to eq 2
79
- end
80
-
81
- it "returns both widgets from multiple arguments" do
82
- get :index, params: { ids: [widget.id, widget2.id], token: admin_user.spree_api_key }, as: :json
83
- expect(response).to be_successful
84
- expect(json_response['widgets'].size).to eq 2
85
- end
86
-
87
- it "returns one requested widgets" do
88
- get :index, params: { ids: widget2.id.to_s, token: admin_user.spree_api_key }, as: :json
89
- expect(response).to be_successful
90
- expect(json_response['widgets'].size).to eq 1
91
- expect(json_response['widgets'][0]['id']).to eq widget2.id
92
- end
93
-
94
- it "returns no widgets if empty" do
95
- get :index, params: { ids: '', token: admin_user.spree_api_key }, as: :json
96
- expect(response).to be_successful
97
- expect(json_response['widgets']).to be_empty
98
- end
99
- end
100
- end
101
- end
102
-
103
- describe "#show" do
104
- let(:widget) { Widget.create!(name: "a widget") }
105
-
106
- it "returns not found" do
107
- get :show, params: { id: widget.to_param, token: user.spree_api_key }, as: :json
108
- assert_not_found!
109
- end
110
-
111
- context "it has authorization read widgets" do
112
- it "returns widget details" do
113
- get :show, params: { id: widget.to_param, token: admin_user.spree_api_key }, as: :json
114
- expect(response).to be_successful
115
- expect(json_response['name']).to eq 'a widget'
116
- end
117
- end
118
- end
119
-
120
- describe "#new" do
121
- it "returns unauthorized" do
122
- get :new, params: { token: user.spree_api_key }, as: :json
123
- expect(response).to be_unauthorized
124
- end
125
-
126
- context "it is allowed to view a new widget" do
127
- it "can learn how to create a new widget" do
128
- get :new, params: { token: admin_user.spree_api_key }, as: :json
129
- expect(response).to be_successful
130
- expect(json_response["attributes"]).to eq(['name'])
131
- end
132
- end
133
- end
134
-
135
- describe "#create" do
136
- it "returns unauthorized" do
137
- expect {
138
- post :create, params: { widget: { name: "a widget" }, token: user.spree_api_key }, as: :json
139
- }.not_to change(Widget, :count)
140
- expect(response).to be_unauthorized
141
- end
142
-
143
- context "it is authorized to create widgets" do
144
- it "can create a widget" do
145
- expect {
146
- post :create, params: { widget: { name: "a widget" }, token: admin_user.spree_api_key }, as: :json
147
- }.to change(Widget, :count).by(1)
148
- expect(response).to be_created
149
- expect(json_response['name']).to eq 'a widget'
150
- expect(Widget.last.name).to eq 'a widget'
151
- end
152
- end
153
- end
154
-
155
- describe "#update" do
156
- let!(:widget) { Widget.create!(name: "a widget") }
157
- it "returns unauthorized" do
158
- put :update, params: { id: widget.to_param, widget: { name: "another widget" }, token: user.spree_api_key }, as: :json
159
- assert_not_found!
160
- expect(widget.reload.name).to eq 'a widget'
161
- end
162
-
163
- context "it is authorized to update widgets" do
164
- it "can update a widget" do
165
- put :update, params: { id: widget.to_param, widget: { name: "another widget" }, token: admin_user.spree_api_key }, as: :json
166
- expect(response).to be_successful
167
- expect(json_response['name']).to eq 'another widget'
168
- expect(widget.reload.name).to eq 'another widget'
169
- end
170
- end
171
- end
172
-
173
- describe "#destroy" do
174
- let!(:widget) { Widget.create!(name: "a widget") }
175
- it "returns unauthorized" do
176
- delete :destroy, params: { id: widget.to_param, token: user.spree_api_key }, as: :json
177
- assert_not_found!
178
- expect { widget.reload }.not_to raise_error
179
- end
180
-
181
- context "it is authorized to destroy widgets" do
182
- it "can destroy a widget" do
183
- delete :destroy, params: { id: widget.to_param, token: admin_user.spree_api_key }, as: :json
184
- expect(response.status).to eq 204
185
- expect { widget.reload }.to raise_error(ActiveRecord::RecordNotFound)
186
- end
187
- end
188
- end
189
- end
190
- end