solidus_api 1.2.3 → 1.3.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Rakefile +1 -1
  4. data/app/controllers/spree/api/addresses_controller.rb +3 -2
  5. data/app/controllers/spree/api/base_controller.rb +10 -15
  6. data/app/controllers/spree/api/checkouts_controller.rb +56 -55
  7. data/app/controllers/spree/api/classifications_controller.rb +4 -4
  8. data/app/controllers/spree/api/config_controller.rb +6 -1
  9. data/app/controllers/spree/api/credit_cards_controller.rb +11 -11
  10. data/app/controllers/spree/api/images_controller.rb +13 -13
  11. data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
  12. data/app/controllers/spree/api/line_items_controller.rb +27 -23
  13. data/app/controllers/spree/api/option_types_controller.rb +6 -5
  14. data/app/controllers/spree/api/option_values_controller.rb +12 -12
  15. data/app/controllers/spree/api/orders_controller.rb +6 -17
  16. data/app/controllers/spree/api/payments_controller.rb +15 -17
  17. data/app/controllers/spree/api/product_properties_controller.rb +13 -14
  18. data/app/controllers/spree/api/products_controller.rb +31 -28
  19. data/app/controllers/spree/api/promotions_controller.rb +9 -8
  20. data/app/controllers/spree/api/properties_controller.rb +9 -10
  21. data/app/controllers/spree/api/resource_controller.rb +9 -1
  22. data/app/controllers/spree/api/shipments_controller.rb +18 -18
  23. data/app/controllers/spree/api/states_controller.rb +8 -7
  24. data/app/controllers/spree/api/stock_items_controller.rb +2 -1
  25. data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
  26. data/app/controllers/spree/api/stores_controller.rb +0 -1
  27. data/app/controllers/spree/api/taxonomies_controller.rb +7 -5
  28. data/app/controllers/spree/api/taxons_controller.rb +20 -19
  29. data/app/controllers/spree/api/users_controller.rb +1 -4
  30. data/app/controllers/spree/api/variants_controller.rb +19 -18
  31. data/app/controllers/spree/api/zones_controller.rb +3 -4
  32. data/app/helpers/spree/api/api_helpers.rb +7 -6
  33. data/app/models/spree/api_configuration.rb +1 -1
  34. data/app/views/spree/api/config/show.v1.rabl +2 -1
  35. data/app/views/spree/api/products/show.v1.rabl +1 -1
  36. data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
  37. data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
  38. data/lib/spree/api/engine.rb +8 -8
  39. data/lib/spree/api/responders/rabl_template.rb +1 -1
  40. data/lib/spree/api/testing_support/caching.rb +4 -4
  41. data/script/rails +0 -1
  42. data/solidus_api.gemspec +3 -3
  43. data/spec/controllers/spree/api/addresses_controller_spec.rb +12 -13
  44. data/spec/controllers/spree/api/base_controller_spec.rb +10 -11
  45. data/spec/controllers/spree/api/checkouts_controller_spec.rb +38 -59
  46. data/spec/controllers/spree/api/config_controller_spec.rb +4 -2
  47. data/spec/controllers/spree/api/countries_controller_spec.rb +5 -5
  48. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +5 -5
  49. data/spec/controllers/spree/api/images_controller_spec.rb +20 -18
  50. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +11 -11
  51. data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -19
  52. data/spec/controllers/spree/api/option_types_controller_spec.rb +23 -24
  53. data/spec/controllers/spree/api/option_values_controller_spec.rb +28 -29
  54. data/spec/controllers/spree/api/orders_controller_spec.rb +157 -179
  55. data/spec/controllers/spree/api/payments_controller_spec.rb +35 -45
  56. data/spec/controllers/spree/api/product_properties_controller_spec.rb +14 -15
  57. data/spec/controllers/spree/api/products_controller_spec.rb +64 -70
  58. data/spec/controllers/spree/api/promotion_application_spec.rb +4 -4
  59. data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
  60. data/spec/controllers/spree/api/properties_controller_spec.rb +15 -15
  61. data/spec/controllers/spree/api/resource_controller_spec.rb +31 -2
  62. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +31 -31
  63. data/spec/controllers/spree/api/shipments_controller_spec.rb +6 -8
  64. data/spec/controllers/spree/api/states_controller_spec.rb +11 -12
  65. data/spec/controllers/spree/api/stock_items_controller_spec.rb +10 -7
  66. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +3 -4
  67. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +2 -3
  68. data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -2
  69. data/spec/controllers/spree/api/stores_controller_spec.rb +1 -2
  70. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +17 -18
  71. data/spec/controllers/spree/api/taxons_controller_spec.rb +22 -24
  72. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -2
  73. data/spec/controllers/spree/api/users_controller_spec.rb +13 -15
  74. data/spec/controllers/spree/api/variants_controller_spec.rb +42 -37
  75. data/spec/controllers/spree/api/zones_controller_spec.rb +18 -18
  76. data/spec/features/checkout_spec.rb +2 -2
  77. data/spec/models/spree/legacy_user_spec.rb +5 -5
  78. data/spec/requests/api/address_books_spec.rb +10 -11
  79. data/spec/requests/rabl_cache_spec.rb +7 -7
  80. data/spec/requests/ransackable_attributes_spec.rb +5 -7
  81. data/spec/shared_examples/protect_product_actions.rb +3 -4
  82. data/spec/spec_helper.rb +8 -4
  83. data/spec/support/controller_hacks.rb +5 -5
  84. data/spec/support/have_attributes_matcher.rb +0 -4
  85. data/spec/test_views/spree/api/widgets/show.v1.rabl +1 -1
  86. metadata +9 -10
  87. data/app/models/spree/option_value_decorator.rb +0 -9
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CreditCardsController, :type => :controller do
4
+ describe Api::CreditCardsController, type: :controller do
5
5
  describe '#index' do
6
6
  render_views
7
7
 
@@ -13,7 +13,7 @@ module Spree
13
13
  create(:user, :with_api_key)
14
14
  end
15
15
 
16
- let!(:card) { create(:credit_card, :user_id => admin_user.id, gateway_customer_profile_id: "random") }
16
+ let!(:card) { create(:credit_card, user_id: admin_user.id, gateway_customer_profile_id: "random") }
17
17
 
18
18
  before do
19
19
  stub_authentication!
@@ -52,7 +52,7 @@ module Spree
52
52
  normal_user
53
53
  end
54
54
 
55
- let!(:card) { create(:credit_card, :user_id => normal_user.id, gateway_customer_profile_id: "random") }
55
+ let!(:card) { create(:credit_card, user_id: normal_user.id, gateway_customer_profile_id: "random") }
56
56
 
57
57
  it "can not view user" do
58
58
  api_get :index, user_id: admin_user.id
@@ -85,7 +85,7 @@ module Spree
85
85
 
86
86
  it 'updates the credit card' do
87
87
  expect {
88
- api_put :update, id: credit_card.to_param, credit_card: {name: 'Jordan Brough'}
88
+ api_put :update, id: credit_card.to_param, credit_card: { name: 'Jordan Brough' }
89
89
  }.to change {
90
90
  credit_card.reload.name
91
91
  }.from('Joe Shmoe').to('Jordan Brough')
@@ -96,7 +96,7 @@ module Spree
96
96
  let(:current_api_user) { create(:user) }
97
97
 
98
98
  it 'rejects the request' do
99
- api_put :update, id: credit_card.to_param, credit_card: {name: 'Jordan Brough'}
99
+ api_put :update, id: credit_card.to_param, credit_card: { name: 'Jordan Brough' }
100
100
  expect(response.status).to eq(401)
101
101
  end
102
102
  end
@@ -1,13 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Spree::Api::ImagesController, :type => :controller do
4
+ describe Spree::Api::ImagesController, type: :controller do
5
5
  render_views
6
6
 
7
7
  let!(:product) { create(:product) }
8
- let!(:attributes) { [:id, :position, :attachment_content_type,
9
- :attachment_file_name, :type, :attachment_updated_at, :attachment_width,
10
- :attachment_height, :alt] }
8
+ let!(:attributes) {
9
+ [:id, :position, :attachment_content_type,
10
+ :attachment_file_name, :type, :attachment_updated_at, :attachment_width,
11
+ :attachment_height, :alt]
12
+ }
11
13
 
12
14
  before do
13
15
  stub_authentication!
@@ -19,39 +21,39 @@ module Spree
19
21
  it "can upload a new image for a variant" do
20
22
  expect do
21
23
  api_post :create,
22
- :image => { :attachment => upload_image('thinking-cat.jpg'),
23
- :viewable_type => 'Spree::Variant',
24
- :viewable_id => product.master.to_param },
25
- :product_id => product.id
24
+ image: { attachment: upload_image('thinking-cat.jpg'),
25
+ viewable_type: 'Spree::Variant',
26
+ viewable_id: product.master.to_param },
27
+ product_id: product.id
26
28
  expect(response.status).to eq(201)
27
29
  expect(json_response).to have_attributes(attributes)
28
30
  end.to change(Image, :count).by(1)
29
31
  end
30
32
 
31
33
  context "working with an existing image" do
32
- let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
34
+ let!(:product_image) { product.master.images.create!(attachment: image('thinking-cat.jpg')) }
33
35
 
34
36
  it "can get a single product image" do
35
- api_get :show, :id => product_image.id, :product_id => product.id
37
+ api_get :show, id: product_image.id, product_id: product.id
36
38
  expect(response.status).to eq(200)
37
39
  expect(json_response).to have_attributes(attributes)
38
40
  end
39
41
 
40
42
  it "can get a single variant image" do
41
- api_get :show, :id => product_image.id, :variant_id => product.master.id
43
+ api_get :show, id: product_image.id, variant_id: product.master.id
42
44
  expect(response.status).to eq(200)
43
45
  expect(json_response).to have_attributes(attributes)
44
46
  end
45
47
 
46
48
  it "can get a list of product images" do
47
- api_get :index, :product_id => product.id
49
+ api_get :index, product_id: product.id
48
50
  expect(response.status).to eq(200)
49
51
  expect(json_response).to have_key("images")
50
52
  expect(json_response["images"].first).to have_attributes(attributes)
51
53
  end
52
54
 
53
55
  it "can get a list of variant images" do
54
- api_get :index, :variant_id => product.master.id
56
+ api_get :index, variant_id: product.master.id
55
57
  expect(response.status).to eq(200)
56
58
  expect(json_response).to have_key("images")
57
59
  expect(json_response["images"].first).to have_attributes(attributes)
@@ -59,14 +61,14 @@ module Spree
59
61
 
60
62
  it "can update image data" do
61
63
  expect(product_image.position).to eq(1)
62
- api_post :update, :image => { :position => 2 }, :id => product_image.id, :product_id => product.id
64
+ api_post :update, image: { position: 2 }, id: product_image.id, product_id: product.id
63
65
  expect(response.status).to eq(200)
64
66
  expect(json_response).to have_attributes(attributes)
65
67
  expect(product_image.reload.position).to eq(2)
66
68
  end
67
69
 
68
70
  it "can delete an image" do
69
- api_delete :destroy, :id => product_image.id, :product_id => product.id
71
+ api_delete :destroy, id: product_image.id, product_id: product.id
70
72
  expect(response.status).to eq(204)
71
73
  expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
72
74
  end
@@ -75,17 +77,17 @@ module Spree
75
77
 
76
78
  context "as a non-admin" do
77
79
  it "cannot create an image" do
78
- api_post :create, :product_id => product.id
80
+ api_post :create, product_id: product.id
79
81
  assert_unauthorized!
80
82
  end
81
83
 
82
84
  it "cannot update an image" do
83
- api_put :update, :id => 1, :product_id => product.id
85
+ api_put :update, id: 1, product_id: product.id
84
86
  assert_not_found!
85
87
  end
86
88
 
87
89
  it "cannot delete an image" do
88
- api_delete :destroy, :id => 1, :product_id => product.id
90
+ api_delete :destroy, id: 1, product_id: product.id
89
91
  assert_not_found!
90
92
  end
91
93
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::InventoryUnitsController, :type => :controller do
4
+ describe Api::InventoryUnitsController, type: :controller do
5
5
  render_views
6
6
 
7
7
  before do
@@ -14,34 +14,34 @@ module Spree
14
14
  let(:variant) { create(:variant) }
15
15
 
16
16
  it "gets an inventory unit" do
17
- api_get :show, :id => @inventory_unit.id
17
+ api_get :show, id: @inventory_unit.id
18
18
  expect(json_response['state']).to eq @inventory_unit.state
19
19
  end
20
20
 
21
21
  it "updates an inventory unit" do
22
- api_put :update, :id => @inventory_unit.id,
23
- :inventory_unit => { variant_id: variant.id }
22
+ api_put :update, id: @inventory_unit.id,
23
+ inventory_unit: { variant_id: variant.id }
24
24
  expect(json_response['variant_id']).to eq variant.id
25
25
  end
26
26
 
27
27
  context 'fires state event' do
28
28
  it 'if supplied with :fire param' do
29
- api_put :update, :id => @inventory_unit.id,
30
- :fire => 'ship',
31
- :inventory_unit => { variant_id: variant.id }
29
+ api_put :update, id: @inventory_unit.id,
30
+ fire: 'ship',
31
+ inventory_unit: { variant_id: variant.id }
32
32
 
33
33
  expect(json_response['state']).to eq 'shipped'
34
34
  end
35
35
 
36
36
  it 'and returns exception if cannot fire' do
37
- api_put :update, :id => @inventory_unit.id,
38
- :fire => 'return'
37
+ api_put :update, id: @inventory_unit.id,
38
+ fire: 'return'
39
39
  expect(json_response['exception']).to match /cannot transition to return/
40
40
  end
41
41
 
42
42
  it 'and returns exception bad state' do
43
- api_put :update, :id => @inventory_unit.id,
44
- :fire => 'bad'
43
+ api_put :update, id: @inventory_unit.id,
44
+ fire: 'bad'
45
45
  expect(json_response['exception']).to match /cannot transition to bad/
46
46
  end
47
47
  end
@@ -12,14 +12,14 @@ module Spree
12
12
  # This should go in an initializer
13
13
  Spree::Api::LineItemsController.line_item_options += [:some_option]
14
14
 
15
- describe Api::LineItemsController, :type => :controller do
15
+ describe Api::LineItemsController, type: :controller do
16
16
  render_views
17
17
 
18
18
  let!(:order) { create(:order_with_line_items, line_items_count: 1) }
19
19
 
20
20
  let(:product) { create(:product) }
21
21
  let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
22
- let(:resource_scoping) { { :order_id => order.to_param } }
22
+ let(:resource_scoping) { { order_id: order.to_param } }
23
23
 
24
24
  before do
25
25
  stub_authentication!
@@ -34,7 +34,7 @@ module Spree
34
34
 
35
35
  context "authenticating with a token" do
36
36
  it "can add a new line item to an existing order" do
37
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }, :order_token => order.guest_token
37
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }, order_token: order.guest_token
38
38
  expect(response.status).to eq(201)
39
39
  expect(json_response).to have_attributes(attributes)
40
40
  expect(json_response["variant"]["name"]).not_to be_blank
@@ -42,7 +42,7 @@ module Spree
42
42
 
43
43
  it "can add a new line item to an existing order with token in header" do
44
44
  request.headers["X-Spree-Order-Token"] = order.guest_token
45
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
45
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
46
46
  expect(response.status).to eq(201)
47
47
  expect(json_response).to have_attributes(attributes)
48
48
  expect(json_response["variant"]["name"]).not_to be_blank
@@ -51,11 +51,11 @@ module Spree
51
51
 
52
52
  context "as the order owner" do
53
53
  before do
54
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
54
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
55
55
  end
56
56
 
57
57
  it "can add a new line item to an existing order" do
58
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
58
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
59
59
  expect(response.status).to eq(201)
60
60
  expect(json_response).to have_attributes(attributes)
61
61
  expect(json_response["variant"]["name"]).not_to be_blank
@@ -73,15 +73,15 @@ module Spree
73
73
  end
74
74
 
75
75
  it "default quantity to 1 if none is given" do
76
- api_post :create, :line_item => { :variant_id => product.master.to_param }
76
+ api_post :create, line_item: { variant_id: product.master.to_param }
77
77
  expect(response.status).to eq(201)
78
78
  expect(json_response).to have_attributes(attributes)
79
79
  expect(json_response[:quantity]).to eq 1
80
80
  end
81
81
 
82
82
  it "increases a line item's quantity if it exists already" do
83
- order.line_items.create(:variant_id => product.master.id, :quantity => 10)
84
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
83
+ order.line_items.create(variant_id: product.master.id, quantity: 10)
84
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
85
85
  expect(response.status).to eq(201)
86
86
  order.reload
87
87
  expect(order.line_items.count).to eq(2) # 1 original due to factory, + 1 in this test
@@ -91,7 +91,7 @@ module Spree
91
91
 
92
92
  it "can update a line item on the order" do
93
93
  line_item = order.line_items.first
94
- api_put :update, :id => line_item.id, :line_item => { :quantity => 101 }
94
+ api_put :update, id: line_item.id, line_item: { quantity: 101 }
95
95
  expect(response.status).to eq(200)
96
96
  order.reload
97
97
  expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test
@@ -110,7 +110,7 @@ module Spree
110
110
 
111
111
  it "can delete a line item on the order" do
112
112
  line_item = order.line_items.first
113
- api_delete :destroy, :id => line_item.id
113
+ api_delete :destroy, id: line_item.id
114
114
  expect(response.status).to eq(204)
115
115
  order.reload
116
116
  expect(order.line_items.count).to eq(0) # 1 original due to factory, - 1 in this test
@@ -118,26 +118,27 @@ module Spree
118
118
  end
119
119
 
120
120
  context "order contents changed after shipments were created" do
121
- let!(:order) { Order.create }
121
+ let!(:store) { create(:store) }
122
+ let!(:order) { Order.create(store: store) }
122
123
  let!(:line_item) { order.contents.add(product.master) }
123
124
 
124
125
  before { order.create_proposed_shipments }
125
126
 
126
127
  it "clear out shipments on create" do
127
128
  expect(order.reload.shipments).not_to be_empty
128
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
129
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
129
130
  expect(order.reload.shipments).to be_empty
130
131
  end
131
132
 
132
133
  it "clear out shipments on update" do
133
134
  expect(order.reload.shipments).not_to be_empty
134
- api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
135
+ api_put :update, id: line_item.id, line_item: { quantity: 1000 }
135
136
  expect(order.reload.shipments).to be_empty
136
137
  end
137
138
 
138
139
  it "clear out shipments on delete" do
139
140
  expect(order.reload.shipments).not_to be_empty
140
- api_delete :destroy, :id => line_item.id
141
+ api_delete :destroy, id: line_item.id
141
142
  expect(order.reload.shipments).to be_empty
142
143
  end
143
144
 
@@ -149,7 +150,7 @@ module Spree
149
150
 
150
151
  it "doesn't destroy shipments or restart checkout flow" do
151
152
  expect(order.reload.shipments).not_to be_empty
152
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
153
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
153
154
  expect(order.reload.shipments).not_to be_empty
154
155
  end
155
156
  end
@@ -164,20 +165,20 @@ module Spree
164
165
  end
165
166
 
166
167
  it "cannot add a new line item to the order" do
167
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
168
+ api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
168
169
  assert_unauthorized!
169
170
  end
170
171
 
171
172
  it "cannot update a line item on the order" do
172
173
  line_item = order.line_items.first
173
- api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
174
+ api_put :update, id: line_item.id, line_item: { quantity: 1000 }
174
175
  assert_unauthorized!
175
176
  expect(line_item.reload.quantity).not_to eq(1000)
176
177
  end
177
178
 
178
179
  it "cannot delete a line item on the order" do
179
180
  line_item = order.line_items.first
180
- api_delete :destroy, :id => line_item.id
181
+ api_delete :destroy, id: line_item.id
181
182
  assert_unauthorized!
182
183
  expect { line_item.reload }.not_to raise_error
183
184
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::OptionTypesController, :type => :controller do
4
+ describe Api::OptionTypesController, type: :controller do
5
5
  render_views
6
6
 
7
7
  let(:attributes) { [:id, :name, :position, :presentation] }
@@ -15,7 +15,7 @@ module Spree
15
15
  def check_option_values(option_values)
16
16
  expect(option_values.count).to eq(1)
17
17
  expect(option_values.first).to have_attributes([:id, :name, :presentation,
18
- :option_type_name, :option_type_id])
18
+ :option_type_name, :option_type_id])
19
19
  end
20
20
 
21
21
  it "can list all option types" do
@@ -27,47 +27,47 @@ module Spree
27
27
  end
28
28
 
29
29
  it "can search for an option type" do
30
- create(:option_type, :name => "buzz")
31
- api_get :index, :q => { :name_cont => option_type.name }
30
+ create(:option_type, name: "buzz")
31
+ api_get :index, q: { name_cont: option_type.name }
32
32
  expect(json_response.count).to eq(1)
33
33
  expect(json_response.first).to have_attributes(attributes)
34
34
  end
35
35
 
36
36
  it "can retrieve a list of specific option types" do
37
37
  option_type_1 = create(:option_type)
38
- option_type_2 = create(:option_type)
39
- api_get :index, :ids => "#{option_type.id},#{option_type_1.id}"
38
+ create(:option_type)
39
+ api_get :index, ids: "#{option_type.id},#{option_type_1.id}"
40
40
  expect(json_response.count).to eq(2)
41
41
 
42
42
  check_option_values(json_response.first["option_values"])
43
43
  end
44
44
 
45
45
  it "can list a single option type" do
46
- api_get :show, :id => option_type.id
46
+ api_get :show, id: option_type.id
47
47
  expect(json_response).to have_attributes(attributes)
48
48
  check_option_values(json_response["option_values"])
49
49
  end
50
50
 
51
51
  it "cannot create a new option type" do
52
- api_post :create, :option_type => {
53
- :name => "Option Type",
54
- :presentation => "Option Type"
52
+ api_post :create, option_type: {
53
+ name: "Option Type",
54
+ presentation: "Option Type"
55
55
  }
56
56
  assert_unauthorized!
57
57
  end
58
58
 
59
59
  it "cannot alter an option type" do
60
60
  original_name = option_type.name
61
- api_put :update, :id => option_type.id,
62
- :option_type => {
63
- :name => "Option Type"
61
+ api_put :update, id: option_type.id,
62
+ option_type: {
63
+ name: "Option Type"
64
64
  }
65
65
  assert_not_found!
66
66
  expect(option_type.reload.name).to eq(original_name)
67
67
  end
68
68
 
69
69
  it "cannot delete an option type" do
70
- api_delete :destroy, :id => option_type.id
70
+ api_delete :destroy, id: option_type.id
71
71
  assert_not_found!
72
72
  expect { option_type.reload }.not_to raise_error
73
73
  end
@@ -76,23 +76,22 @@ module Spree
76
76
  sign_in_as_admin!
77
77
 
78
78
  it "can create an option type" do
79
- api_post :create, :option_type => {
80
- :name => "Option Type",
81
- :presentation => "Option Type"
79
+ api_post :create, option_type: {
80
+ name: "Option Type",
81
+ presentation: "Option Type"
82
82
  }
83
83
  expect(json_response).to have_attributes(attributes)
84
84
  expect(response.status).to eq(201)
85
85
  end
86
86
 
87
87
  it "cannot create an option type with invalid attributes" do
88
- api_post :create, :option_type => {}
88
+ api_post :create, option_type: {}
89
89
  expect(response.status).to eq(422)
90
90
  end
91
91
 
92
92
  it "can update an option type" do
93
- original_name = option_type.name
94
- api_put :update, :id => option_type.id, :option_type => {
95
- :name => "Option Type",
93
+ api_put :update, id: option_type.id, option_type: {
94
+ name: "Option Type"
96
95
  }
97
96
  expect(response.status).to eq(200)
98
97
 
@@ -101,14 +100,14 @@ module Spree
101
100
  end
102
101
 
103
102
  it "cannot update an option type with invalid attributes" do
104
- api_put :update, :id => option_type.id, :option_type => {
105
- :name => ""
103
+ api_put :update, id: option_type.id, option_type: {
104
+ name: ""
106
105
  }
107
106
  expect(response.status).to eq(422)
108
107
  end
109
108
 
110
109
  it "can delete an option type" do
111
- api_delete :destroy, :id => option_type.id
110
+ api_delete :destroy, id: option_type.id
112
111
  expect(response.status).to eq(204)
113
112
  end
114
113
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::OptionValuesController, :type => :controller do
4
+ describe Api::OptionValuesController, type: :controller do
5
5
  render_views
6
6
 
7
7
  let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_name] }
@@ -15,13 +15,13 @@ module Spree
15
15
  def check_option_values(option_values)
16
16
  expect(option_values.count).to eq(1)
17
17
  expect(option_values.first).to have_attributes([:id, :name, :presentation,
18
- :option_type_name, :option_type_id])
18
+ :option_type_name, :option_type_id])
19
19
  end
20
20
 
21
21
  context "without any option type scoping" do
22
22
  before do
23
23
  # Create another option value with a brand new option type
24
- create(:option_value, :option_type => create(:option_type))
24
+ create(:option_value, option_type: create(:option_type))
25
25
  end
26
26
 
27
27
  it "can retrieve a list of all option values" do
@@ -32,7 +32,7 @@ module Spree
32
32
  end
33
33
 
34
34
  context "for a particular option type" do
35
- let(:resource_scoping) { { :option_type_id => option_type.id } }
35
+ let(:resource_scoping) { { option_type_id: option_type.id } }
36
36
 
37
37
  it "can list all option values" do
38
38
  api_get :index
@@ -41,44 +41,44 @@ module Spree
41
41
  end
42
42
 
43
43
  it "can search for an option type" do
44
- create(:option_value, :name => "buzz")
45
- api_get :index, :q => { :name_cont => option_value.name }
44
+ create(:option_value, name: "buzz")
45
+ api_get :index, q: { name_cont: option_value.name }
46
46
  expect(json_response.count).to eq(1)
47
47
  expect(json_response.first).to have_attributes(attributes)
48
48
  end
49
49
 
50
50
  it "can retrieve a list of option types" do
51
- option_value_1 = create(:option_value, :option_type => option_type)
52
- option_value_2 = create(:option_value, :option_type => option_type)
53
- api_get :index, :ids => [option_value.id, option_value_1.id]
51
+ option_value_1 = create(:option_value, option_type: option_type)
52
+ create(:option_value, option_type: option_type)
53
+ api_get :index, ids: [option_value.id, option_value_1.id]
54
54
  expect(json_response.count).to eq(2)
55
55
  end
56
56
 
57
57
  it "can list a single option value" do
58
- api_get :show, :id => option_value.id
58
+ api_get :show, id: option_value.id
59
59
  expect(json_response).to have_attributes(attributes)
60
60
  end
61
61
 
62
62
  it "cannot create a new option value" do
63
- api_post :create, :option_value => {
64
- :name => "Option Value",
65
- :presentation => "Option Value"
63
+ api_post :create, option_value: {
64
+ name: "Option Value",
65
+ presentation: "Option Value"
66
66
  }
67
67
  assert_unauthorized!
68
68
  end
69
69
 
70
70
  it "cannot alter an option value" do
71
71
  original_name = option_type.name
72
- api_put :update, :id => option_type.id,
73
- :option_value => {
74
- :name => "Option Value"
72
+ api_put :update, id: option_type.id,
73
+ option_value: {
74
+ name: "Option Value"
75
75
  }
76
76
  assert_not_found!
77
77
  expect(option_type.reload.name).to eq(original_name)
78
78
  end
79
79
 
80
80
  it "cannot delete an option value" do
81
- api_delete :destroy, :id => option_type.id
81
+ api_delete :destroy, id: option_type.id
82
82
  assert_not_found!
83
83
  expect { option_type.reload }.not_to raise_error
84
84
  end
@@ -87,23 +87,22 @@ module Spree
87
87
  sign_in_as_admin!
88
88
 
89
89
  it "can create an option value" do
90
- api_post :create, :option_value => {
91
- :name => "Option Value",
92
- :presentation => "Option Value"
90
+ api_post :create, option_value: {
91
+ name: "Option Value",
92
+ presentation: "Option Value"
93
93
  }
94
94
  expect(json_response).to have_attributes(attributes)
95
95
  expect(response.status).to eq(201)
96
96
  end
97
97
 
98
98
  it "cannot create an option type with invalid attributes" do
99
- api_post :create, :option_value => {}
99
+ api_post :create, option_value: {}
100
100
  expect(response.status).to eq(422)
101
101
  end
102
102
 
103
103
  it "can update an option value" do
104
- original_name = option_value.name
105
- api_put :update, :id => option_value.id, :option_value => {
106
- :name => "Option Value",
104
+ api_put :update, id: option_value.id, option_value: {
105
+ name: "Option Value"
107
106
  }
108
107
  expect(response.status).to eq(200)
109
108
 
@@ -113,20 +112,20 @@ module Spree
113
112
 
114
113
  it "permits the correct attributes" do
115
114
  expect(controller).to receive(:permitted_option_value_attributes)
116
- api_put :update, :id => option_value.id, :option_value => {
117
- :name => ""
115
+ api_put :update, id: option_value.id, option_value: {
116
+ name: ""
118
117
  }
119
118
  end
120
119
 
121
120
  it "cannot update an option value with invalid attributes" do
122
- api_put :update, :id => option_value.id, :option_value => {
123
- :name => ""
121
+ api_put :update, id: option_value.id, option_value: {
122
+ name: ""
124
123
  }
125
124
  expect(response.status).to eq(422)
126
125
  end
127
126
 
128
127
  it "can delete an option value" do
129
- api_delete :destroy, :id => option_value.id
128
+ api_delete :destroy, id: option_value.id
130
129
  expect(response.status).to eq(204)
131
130
  end
132
131
  end