spree_api 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/v1/product_properties_controller.rb +7 -10
  3. data/app/views/spree/api/v1/countries/index.v1.rabl +1 -1
  4. data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
  5. data/app/views/spree/api/v1/orders/index.v1.rabl +1 -1
  6. data/app/views/spree/api/v1/orders/mine.v1.rabl +1 -1
  7. data/app/views/spree/api/v1/payments/index.v1.rabl +1 -1
  8. data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
  9. data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
  10. data/app/views/spree/api/v1/properties/index.v1.rabl +1 -1
  11. data/app/views/spree/api/v1/return_authorizations/index.v1.rabl +1 -1
  12. data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
  13. data/app/views/spree/api/v1/states/index.v1.rabl +1 -1
  14. data/app/views/spree/api/v1/stock_items/index.v1.rabl +1 -1
  15. data/app/views/spree/api/v1/stock_locations/index.v1.rabl +1 -1
  16. data/app/views/spree/api/v1/stock_movements/index.v1.rabl +1 -1
  17. data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
  18. data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -1
  19. data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
  20. data/app/views/spree/api/v1/zones/index.v1.rabl +1 -1
  21. data/spree_api.gemspec +1 -2
  22. metadata +6 -88
  23. data/spec/controllers/spree/api/base_controller_spec.rb +0 -96
  24. data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +0 -56
  25. data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +0 -363
  26. data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +0 -48
  27. data/spec/controllers/spree/api/v1/countries_controller_spec.rb +0 -48
  28. data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +0 -80
  29. data/spec/controllers/spree/api/v1/images_controller_spec.rb +0 -115
  30. data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +0 -49
  31. data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +0 -184
  32. data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +0 -122
  33. data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +0 -141
  34. data/spec/controllers/spree/api/v1/orders_controller_spec.rb +0 -735
  35. data/spec/controllers/spree/api/v1/payments_controller_spec.rb +0 -234
  36. data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +0 -116
  37. data/spec/controllers/spree/api/v1/products_controller_spec.rb +0 -409
  38. data/spec/controllers/spree/api/v1/promotion_application_spec.rb +0 -50
  39. data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +0 -64
  40. data/spec/controllers/spree/api/v1/properties_controller_spec.rb +0 -102
  41. data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +0 -161
  42. data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +0 -187
  43. data/spec/controllers/spree/api/v1/states_controller_spec.rb +0 -86
  44. data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +0 -143
  45. data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +0 -113
  46. data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +0 -84
  47. data/spec/controllers/spree/api/v1/stores_controller_spec.rb +0 -133
  48. data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +0 -114
  49. data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +0 -177
  50. data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +0 -26
  51. data/spec/controllers/spree/api/v1/users_controller_spec.rb +0 -153
  52. data/spec/controllers/spree/api/v1/variants_controller_spec.rb +0 -205
  53. data/spec/controllers/spree/api/v1/zones_controller_spec.rb +0 -91
  54. data/spec/fixtures/thinking-cat.jpg +0 -0
  55. data/spec/models/spree/legacy_user_spec.rb +0 -19
  56. data/spec/requests/rabl_cache_spec.rb +0 -32
  57. data/spec/requests/ransackable_attributes_spec.rb +0 -79
  58. data/spec/requests/version_spec.rb +0 -19
  59. data/spec/shared_examples/protect_product_actions.rb +0 -17
  60. data/spec/spec_helper.rb +0 -55
  61. data/spec/support/controller_hacks.rb +0 -33
  62. data/spec/support/database_cleaner.rb +0 -14
  63. data/spec/support/have_attributes_matcher.rb +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b8ad4edd7469cb2c67174d856ae8aa1284f183c
4
- data.tar.gz: 2ab89546cef6d0e1a1ab7b89ae248030db2f4704
3
+ metadata.gz: eb6992b77897c73750856161f7dbc3dffb5c364e
4
+ data.tar.gz: '0964719f61957349955e4829a300d00797244ac5'
5
5
  SHA512:
6
- metadata.gz: f2a3c1859e39e8040005fe536d1d26e53e8dc6179a318435d74c26cf7ec7ccff9207e1bb26a3f30776175eac0414788158030d391d814da48d84cf8910be4811
7
- data.tar.gz: dec9414e9c0f82be84fcd5a6c8a019ed10964c92e053610ee6a0df383bd44db14176adaf4bc7b094f05f83d6a22f76a17e2369f4440c20b2feb36b80a3deb985
6
+ metadata.gz: 75cbb0627aca0fa825b74c296d394384f2db34023000b0560887c6d7ec71e73af880e4251d592c70246f7fe05f72e76f739498377eba8140b7eb8e8d5f27a168
7
+ data.tar.gz: ae601fbe2cc4e48de3a1c41fcdaa80f4b586a4af14375c0f82d133f6684feec55b78490ff6692101675b0ce23c93242b3af2d459b9286fe40f330c5830b0bd61
@@ -30,9 +30,9 @@ module Spree
30
30
  end
31
31
 
32
32
  def update
33
- if @product_property
34
- authorize! :update, @product_property
35
- @product_property.update_attributes(product_property_params)
33
+ authorize! :update, @product_property
34
+
35
+ if @product_property.update_attributes(product_property_params)
36
36
  respond_with(@product_property, status: 200, default_template: :show)
37
37
  else
38
38
  invalid_resource!(@product_property)
@@ -40,13 +40,9 @@ module Spree
40
40
  end
41
41
 
42
42
  def destroy
43
- if @product_property
44
- authorize! :destroy, @product_property
45
- @product_property.destroy
46
- respond_with(@product_property, status: 204)
47
- else
48
- invalid_resource!(@product_property)
49
- end
43
+ authorize! :destroy, @product_property
44
+ @product_property.destroy
45
+ respond_with(@product_property, status: 204)
50
46
  end
51
47
 
52
48
  private
@@ -60,6 +56,7 @@ module Spree
60
56
  if @product
61
57
  @product_property ||= @product.product_properties.find_by(id: params[:id])
62
58
  @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first
59
+ fail ActiveRecord::RecordNotFound unless @product_property
63
60
  authorize! :read, @product_property
64
61
  end
65
62
  end
@@ -3,5 +3,5 @@ child(@countries => :countries) do
3
3
  attributes *country_attributes
4
4
  end
5
5
  node(:count) { @countries.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @countries.total_pages }
@@ -3,5 +3,5 @@ child(@credit_cards => :credit_cards) do
3
3
  extends "spree/api/v1/credit_cards/show"
4
4
  end
5
5
  node(:count) { @credit_cards.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @credit_cards.total_pages }
@@ -3,5 +3,5 @@ child(@orders => :orders) do
3
3
  extends "spree/api/v1/orders/order"
4
4
  end
5
5
  node(:count) { @orders.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @orders.total_pages }
@@ -5,5 +5,5 @@ child(@orders => :orders) do
5
5
  end
6
6
 
7
7
  node(:count) { @orders.count }
8
- node(:current_page) { params[:page] || 1 }
8
+ node(:current_page) { params[:page].try(:to_i) || 1 }
9
9
  node(:pages) { @orders.total_pages }
@@ -3,5 +3,5 @@ child(@payments => :payments) do
3
3
  attributes *payment_attributes
4
4
  end
5
5
  node(:count) { @payments.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @payments.total_pages }
@@ -3,5 +3,5 @@ child(@product_properties => :product_properties) do
3
3
  attributes *product_property_attributes
4
4
  end
5
5
  node(:count) { @product_properties.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @product_properties.total_pages }
@@ -2,7 +2,7 @@ object false
2
2
  node(:count) { @products.count }
3
3
  node(:total_count) { @products.total_count }
4
4
  node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
- node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
5
+ node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }
6
6
  node(:pages) { @products.total_pages }
7
7
  child(@products => :products) do
8
8
  extends "spree/api/v1/products/show"
@@ -3,5 +3,5 @@ child(@properties => :properties) do
3
3
  attributes *property_attributes
4
4
  end
5
5
  node(:count) { @properties.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @properties.total_pages }
@@ -3,5 +3,5 @@ child(@return_authorizations => :return_authorizations) do
3
3
  attributes *return_authorization_attributes
4
4
  end
5
5
  node(:count) { @return_authorizations.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @return_authorizations.total_pages }
@@ -1,7 +1,7 @@
1
1
  object false
2
2
 
3
3
  node(:count) { @shipments.count }
4
- node(:current_page) { params[:page] || 1 }
4
+ node(:current_page) { params[:page].try(:to_i) || 1 }
5
5
  node(:pages) { @shipments.total_pages }
6
6
 
7
7
  child(@shipments => :shipments) do
@@ -9,6 +9,6 @@ end
9
9
 
10
10
  if @states.respond_to?(:total_pages)
11
11
  node(:count) { @states.count }
12
- node(:current_page) { params[:page] || 1 }
12
+ node(:current_page) { params[:page].try(:to_i) || 1 }
13
13
  node(:pages) { @states.total_pages }
14
14
  end
@@ -3,5 +3,5 @@ child(@stock_items => :stock_items) do
3
3
  extends 'spree/api/v1/stock_items/show'
4
4
  end
5
5
  node(:count) { @stock_items.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @stock_items.total_pages }
@@ -3,5 +3,5 @@ child(@stock_locations => :stock_locations) do
3
3
  extends 'spree/api/v1/stock_locations/show'
4
4
  end
5
5
  node(:count) { @stock_locations.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @stock_locations.total_pages }
@@ -3,5 +3,5 @@ child(@stock_movements => :stock_movements) do
3
3
  extends 'spree/api/v1/stock_movements/show'
4
4
  end
5
5
  node(:count) { @stock_movements.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @stock_movements.total_pages }
@@ -3,5 +3,5 @@ child(@taxonomies => :taxonomies) do
3
3
  extends "spree/api/v1/taxonomies/show"
4
4
  end
5
5
  node(:count) { @taxonomies.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @taxonomies.total_pages }
@@ -2,7 +2,7 @@ object false
2
2
  node(:count) { @taxons.count }
3
3
  node(:total_count) { @taxons.total_count }
4
4
  node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
- node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }
5
+ node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }
6
6
  node(:pages) { @taxons.total_pages }
7
7
  child @taxons => :taxons do
8
8
  attributes *taxon_attributes
@@ -3,5 +3,5 @@ child(@users => :users) do
3
3
  extends "spree/api/v1/users/show"
4
4
  end
5
5
  node(:count) { @users.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @users.total_pages }
@@ -3,5 +3,5 @@ child(@zones => :zones) do
3
3
  extends 'spree/api/v1/zones/show'
4
4
  end
5
5
  node(:count) { @zones.count }
6
- node(:current_page) { params[:page] || 1 }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
7
  node(:pages) { @zones.total_pages }
data/spree_api.gemspec CHANGED
@@ -9,9 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.homepage = 'https://spreecommerce.com'
10
10
  s.license = 'BSD-3'
11
11
 
12
- s.files = `git ls-files`.split($\)
12
+ s.files = `git ls-files`.split($\).reject { |f| f.match(/^spec/) }
13
13
  s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
- s.test_files = s.files.grep(%r{^(test|spec|features)/})
15
14
  s.name = "spree_api"
16
15
  s.require_paths = ["lib"]
17
16
  s.version = Spree.version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-04 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.5
19
+ version: 3.1.6
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.5
26
+ version: 3.1.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -206,47 +206,6 @@ files:
206
206
  - lib/spree/api/testing_support/setup.rb
207
207
  - lib/spree_api.rb
208
208
  - script/rails
209
- - spec/controllers/spree/api/base_controller_spec.rb
210
- - spec/controllers/spree/api/v1/addresses_controller_spec.rb
211
- - spec/controllers/spree/api/v1/checkouts_controller_spec.rb
212
- - spec/controllers/spree/api/v1/classifications_controller_spec.rb
213
- - spec/controllers/spree/api/v1/countries_controller_spec.rb
214
- - spec/controllers/spree/api/v1/credit_cards_controller_spec.rb
215
- - spec/controllers/spree/api/v1/images_controller_spec.rb
216
- - spec/controllers/spree/api/v1/inventory_units_controller_spec.rb
217
- - spec/controllers/spree/api/v1/line_items_controller_spec.rb
218
- - spec/controllers/spree/api/v1/option_types_controller_spec.rb
219
- - spec/controllers/spree/api/v1/option_values_controller_spec.rb
220
- - spec/controllers/spree/api/v1/orders_controller_spec.rb
221
- - spec/controllers/spree/api/v1/payments_controller_spec.rb
222
- - spec/controllers/spree/api/v1/product_properties_controller_spec.rb
223
- - spec/controllers/spree/api/v1/products_controller_spec.rb
224
- - spec/controllers/spree/api/v1/promotion_application_spec.rb
225
- - spec/controllers/spree/api/v1/promotions_controller_spec.rb
226
- - spec/controllers/spree/api/v1/properties_controller_spec.rb
227
- - spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
228
- - spec/controllers/spree/api/v1/shipments_controller_spec.rb
229
- - spec/controllers/spree/api/v1/states_controller_spec.rb
230
- - spec/controllers/spree/api/v1/stock_items_controller_spec.rb
231
- - spec/controllers/spree/api/v1/stock_locations_controller_spec.rb
232
- - spec/controllers/spree/api/v1/stock_movements_controller_spec.rb
233
- - spec/controllers/spree/api/v1/stores_controller_spec.rb
234
- - spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
235
- - spec/controllers/spree/api/v1/taxons_controller_spec.rb
236
- - spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
237
- - spec/controllers/spree/api/v1/users_controller_spec.rb
238
- - spec/controllers/spree/api/v1/variants_controller_spec.rb
239
- - spec/controllers/spree/api/v1/zones_controller_spec.rb
240
- - spec/fixtures/thinking-cat.jpg
241
- - spec/models/spree/legacy_user_spec.rb
242
- - spec/requests/rabl_cache_spec.rb
243
- - spec/requests/ransackable_attributes_spec.rb
244
- - spec/requests/version_spec.rb
245
- - spec/shared_examples/protect_product_actions.rb
246
- - spec/spec_helper.rb
247
- - spec/support/controller_hacks.rb
248
- - spec/support/database_cleaner.rb
249
- - spec/support/have_attributes_matcher.rb
250
209
  - spree_api.gemspec
251
210
  homepage: https://spreecommerce.com
252
211
  licenses:
@@ -268,49 +227,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
268
227
  version: '0'
269
228
  requirements: []
270
229
  rubyforge_project:
271
- rubygems_version: 2.6.10
230
+ rubygems_version: 2.6.11
272
231
  signing_key:
273
232
  specification_version: 4
274
233
  summary: Spree's API
275
- test_files:
276
- - spec/controllers/spree/api/base_controller_spec.rb
277
- - spec/controllers/spree/api/v1/addresses_controller_spec.rb
278
- - spec/controllers/spree/api/v1/checkouts_controller_spec.rb
279
- - spec/controllers/spree/api/v1/classifications_controller_spec.rb
280
- - spec/controllers/spree/api/v1/countries_controller_spec.rb
281
- - spec/controllers/spree/api/v1/credit_cards_controller_spec.rb
282
- - spec/controllers/spree/api/v1/images_controller_spec.rb
283
- - spec/controllers/spree/api/v1/inventory_units_controller_spec.rb
284
- - spec/controllers/spree/api/v1/line_items_controller_spec.rb
285
- - spec/controllers/spree/api/v1/option_types_controller_spec.rb
286
- - spec/controllers/spree/api/v1/option_values_controller_spec.rb
287
- - spec/controllers/spree/api/v1/orders_controller_spec.rb
288
- - spec/controllers/spree/api/v1/payments_controller_spec.rb
289
- - spec/controllers/spree/api/v1/product_properties_controller_spec.rb
290
- - spec/controllers/spree/api/v1/products_controller_spec.rb
291
- - spec/controllers/spree/api/v1/promotion_application_spec.rb
292
- - spec/controllers/spree/api/v1/promotions_controller_spec.rb
293
- - spec/controllers/spree/api/v1/properties_controller_spec.rb
294
- - spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
295
- - spec/controllers/spree/api/v1/shipments_controller_spec.rb
296
- - spec/controllers/spree/api/v1/states_controller_spec.rb
297
- - spec/controllers/spree/api/v1/stock_items_controller_spec.rb
298
- - spec/controllers/spree/api/v1/stock_locations_controller_spec.rb
299
- - spec/controllers/spree/api/v1/stock_movements_controller_spec.rb
300
- - spec/controllers/spree/api/v1/stores_controller_spec.rb
301
- - spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
302
- - spec/controllers/spree/api/v1/taxons_controller_spec.rb
303
- - spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
304
- - spec/controllers/spree/api/v1/users_controller_spec.rb
305
- - spec/controllers/spree/api/v1/variants_controller_spec.rb
306
- - spec/controllers/spree/api/v1/zones_controller_spec.rb
307
- - spec/fixtures/thinking-cat.jpg
308
- - spec/models/spree/legacy_user_spec.rb
309
- - spec/requests/rabl_cache_spec.rb
310
- - spec/requests/ransackable_attributes_spec.rb
311
- - spec/requests/version_spec.rb
312
- - spec/shared_examples/protect_product_actions.rb
313
- - spec/spec_helper.rb
314
- - spec/support/controller_hacks.rb
315
- - spec/support/database_cleaner.rb
316
- - spec/support/have_attributes_matcher.rb
234
+ test_files: []
@@ -1,96 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class FakesController < Spree::Api::BaseController
4
- end
5
-
6
- describe Spree::Api::BaseController, :type => :controller do
7
- render_views
8
- controller(Spree::Api::BaseController) do
9
- def index
10
- render :text => { "products" => [] }.to_json
11
- end
12
- end
13
-
14
- before do
15
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
16
- r.draw { get 'index', to: 'spree/api/base#index' }
17
- end
18
- end
19
-
20
- context "when validating based on an order token" do
21
- let!(:order) { create :order }
22
-
23
- context "with a correct order token" do
24
- it "succeeds" do
25
- api_get :index, order_token: order.guest_token, order_id: order.number
26
- expect(response.status).to eq(200)
27
- end
28
-
29
- it "succeeds with an order_number parameter" do
30
- api_get :index, order_token: order.guest_token, order_number: order.number
31
- expect(response.status).to eq(200)
32
- end
33
- end
34
-
35
- context "with an incorrect order token" do
36
- it "returns unauthorized" do
37
- api_get :index, order_token: "NOT_A_TOKEN", order_id: order.number
38
- expect(response.status).to eq(401)
39
- end
40
- end
41
- end
42
-
43
- context "cannot make a request to the API" do
44
- it "without an API key" do
45
- api_get :index
46
- expect(json_response).to eq({ "error" => "You must specify an API key." })
47
- expect(response.status).to eq(401)
48
- end
49
-
50
- it "with an invalid API key" do
51
- request.headers["X-Spree-Token"] = "fake_key"
52
- get :index, {}
53
- expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
54
- expect(response.status).to eq(401)
55
- end
56
-
57
- it "using an invalid token param" do
58
- get :index, :token => "fake_key"
59
- expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
60
- end
61
- end
62
-
63
- it 'handles parameter missing exceptions' do
64
- expect(subject).to receive(:authenticate_user).and_return(true)
65
- expect(subject).to receive(:load_user_roles).and_return(true)
66
- expect(subject).to receive(:index).and_raise(ActionController::ParameterMissing.new('foo'))
67
- get :index, token: 'exception-message'
68
- expect(json_response).to eql('exception' => 'param is missing or the value is empty: foo')
69
- end
70
-
71
- it 'handles record invalid exceptions' do
72
- expect(subject).to receive(:authenticate_user).and_return(true)
73
- expect(subject).to receive(:load_user_roles).and_return(true)
74
- resource = Spree::Product.new
75
- resource.valid? # get some errors
76
- expect(subject).to receive(:index).and_raise(ActiveRecord::RecordInvalid.new(resource))
77
- get :index, token: 'exception-message'
78
- expect(json_response).to eql('exception' => "Validation failed: Name can't be blank, Shipping Category can't be blank, Price can't be blank")
79
- end
80
-
81
- it "maps semantic keys to nested_attributes keys" do
82
- klass = double(:nested_attributes_options => { :line_items => {},
83
- :bill_address => {} })
84
- attributes = { 'line_items' => { :id => 1 },
85
- 'bill_address' => { :id => 2 },
86
- 'name' => 'test order' }
87
-
88
- mapped = subject.map_nested_attributes_keys(klass, attributes)
89
- expect(mapped.has_key?('line_items_attributes')).to be true
90
- expect(mapped.has_key?('name')).to be true
91
- end
92
-
93
- it "lets a subclass override the product associations that are eager-loaded" do
94
- expect(controller.respond_to?(:product_includes, true)).to be
95
- end
96
- end