solidus_api 1.2.3 → 1.3.0.beta1

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.
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
@@ -2,23 +2,25 @@ require 'spec_helper'
2
2
  require 'spree/testing_support/bar_ability'
3
3
 
4
4
  module Spree
5
- describe Api::OrdersController, :type => :controller do
5
+ describe Api::OrdersController, type: :controller do
6
6
  render_views
7
7
  let!(:order) { create(:order) }
8
8
  let(:variant) { create(:variant) }
9
9
  let(:line_item) { create(:line_item) }
10
10
 
11
- let(:attributes) { [:number, :item_total, :display_total, :total,
12
- :state, :adjustment_total,
13
- :user_id, :created_at, :updated_at,
14
- :completed_at, :payment_total, :shipment_state,
15
- :payment_state, :email, :special_instructions,
16
- :total_quantity, :display_item_total, :currency] }
11
+ let(:attributes) {
12
+ [:number, :item_total, :display_total, :total,
13
+ :state, :adjustment_total,
14
+ :user_id, :created_at, :updated_at,
15
+ :completed_at, :payment_total, :shipment_state,
16
+ :payment_state, :email, :special_instructions,
17
+ :total_quantity, :display_item_total, :currency]
18
+ }
17
19
 
18
- let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } }
20
+ let(:address_params) { { country_id: Country.first.id, state_id: State.first.id } }
19
21
 
20
22
  let(:current_api_user) do
21
- user = Spree.user_class.new(:email => "spree@example.com")
23
+ user = Spree.user_class.new(email: "spree@example.com")
22
24
  user.generate_spree_api_key!
23
25
  user
24
26
  end
@@ -29,62 +31,46 @@ module Spree
29
31
 
30
32
  describe "POST create" do
31
33
  let(:target_user) { create :user }
32
- let(:date_override) { Time.parse('2015-01-01') }
33
- let(:attributes) { { user_id: target_user.id, created_at: date_override, email: target_user.email } }
34
+ let(:date_override) { 3.days.ago }
34
35
 
35
- subject { api_post :create, order: attributes }
36
+ before do
37
+ allow_any_instance_of(Spree::Ability).to receive(:can?).
38
+ and_return(true)
39
+
40
+ allow_any_instance_of(Spree::Ability).to receive(:can?).
41
+ with(:admin, Spree::Order).
42
+ and_return(can_admin)
43
+
44
+ allow(Spree.user_class).to receive(:find).
45
+ with(target_user.id).
46
+ and_return(target_user)
47
+ end
48
+
49
+ subject { api_post :create, order: { user_id: target_user.id, created_at: date_override, email: target_user.email } }
36
50
 
37
51
  context "when the current user cannot administrate the order" do
38
- stub_authorization! do |_|
39
- can :create, Spree::Order
40
- end
52
+ let(:can_admin) { false }
41
53
 
42
54
  it "does not include unpermitted params, or allow overriding the user", focus: true do
55
+ expect(Spree::Core::Importer::Order).to receive(:import).
56
+ once.
57
+ with(current_api_user, { "email" => target_user.email }).
58
+ and_call_original
43
59
  subject
44
- expect(response).to be_success
45
- order = Spree::Order.last
46
- expect(order.user).to eq current_api_user
47
- expect(order.email).to eq target_user.email
48
60
  end
49
61
 
50
62
  it { is_expected.to be_success }
51
-
52
- context 'creating payment' do
53
- let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
54
-
55
- context "with allowed payment method" do
56
- let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
57
- it { is_expected.to be_success }
58
- it "creates a payment" do
59
- expect {
60
- subject
61
- }.to change { Spree::Payment.count }.by(1)
62
- end
63
- end
64
-
65
- context "with disallowed payment method" do
66
- let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
67
- it { is_expected.to be_not_found }
68
- it "creates no payments" do
69
- expect {
70
- subject
71
- }.not_to change { Spree::Payment.count }
72
- end
73
- end
74
- end
75
63
  end
76
64
 
77
65
  context "when the current user can administrate the order" do
78
- stub_authorization! do |_|
79
- can [:admin, :create], Spree::Order
80
- end
66
+ let(:can_admin) { true }
81
67
 
82
68
  it "it permits all params and allows overriding the user" do
69
+ expect(Spree::Core::Importer::Order).to receive(:import).
70
+ once.
71
+ with(target_user, { "user_id" => target_user.id, "created_at" => date_override, "email" => target_user.email }).
72
+ and_call_original
83
73
  subject
84
- order = Spree::Order.last
85
- expect(order.user).to eq target_user
86
- expect(order.email).to eq target_user.email
87
- expect(order.created_at).to eq date_override
88
74
  end
89
75
 
90
76
  it { is_expected.to be_success }
@@ -97,72 +83,59 @@ module Spree
97
83
  let(:can_admin) { false }
98
84
  subject { api_put :update, id: order.to_param, order: order_params }
99
85
 
100
- context "when the user cannot administer the order" do
101
- stub_authorization! do |_|
102
- can [:update], Spree::Order
103
- end
104
-
105
- it "updates the user's email" do
106
- expect {
107
- subject
108
- }.to change { order.reload.email }.to("foo@foobar.com")
109
- end
110
-
111
- it { is_expected.to be_success }
112
-
113
- it "does not associate users" do
114
- expect {
115
- subject
116
- }.not_to change { order.reload.user }
117
- end
86
+ before do
87
+ allow_any_instance_of(Spree::Ability).to receive(:can?).
88
+ and_return(true)
118
89
 
119
- it "does not change forbidden attributes" do
120
- expect {
121
- subject
122
- }.to_not change{ order.reload.number }
123
- end
90
+ allow(Spree::Order).to receive(:find_by!).
91
+ with(number: order.number).
92
+ and_return(order)
124
93
 
125
- context 'creating payment' do
126
- let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
94
+ allow(Spree.user_class).to receive(:find).
95
+ with(user.id).
96
+ and_return(user)
127
97
 
128
- context "with allowed payment method" do
129
- let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
130
- it { is_expected.to be_success }
131
- it "creates a payment" do
132
- expect {
133
- subject
134
- }.to change { Spree::Payment.count }.by(1)
135
- end
136
- end
98
+ allow_any_instance_of(Spree::Ability).to receive(:can?).
99
+ with(:admin, Spree::Order).
100
+ and_return(can_admin)
101
+ end
137
102
 
138
- context "with disallowed payment method" do
139
- let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
140
- it { is_expected.to be_not_found }
141
- it "creates no payments" do
142
- expect {
143
- subject
144
- }.not_to change { Spree::Payment.count }
145
- end
146
- end
147
- end
103
+ it "updates the cart contents" do
104
+ expect(order.contents).to receive(:update_cart).
105
+ once.
106
+ with({ "email" => "foo@foobar.com" })
107
+ subject
148
108
  end
149
109
 
110
+ it { is_expected.to be_success }
111
+
150
112
  context "when the user can administer the order" do
151
- stub_authorization! do |_|
152
- can [:admin, :update], Spree::Order
153
- end
113
+ let(:can_admin) { true }
154
114
 
155
115
  it "will associate users" do
156
- expect {
157
- subject
158
- }.to change { order.reload.user }.to(user)
116
+ expect(order).to receive(:associate_user!).
117
+ once.
118
+ with(user)
119
+
120
+ subject
159
121
  end
160
122
 
161
123
  it "updates the otherwise forbidden attributes" do
162
- expect{subject}.to change{order.reload.number}.
124
+ expect{ subject }.to change{ order.reload.number }.
163
125
  to("anothernumber")
164
126
  end
165
127
  end
128
+
129
+ context "when the user cannot administer the order" do
130
+ it "does not associate users" do
131
+ expect(order).to_not receive(:associate_user!)
132
+ subject
133
+ end
134
+
135
+ it "does not change forbidden attributes" do
136
+ expect{ subject }.to_not change{ order.reload.number }
137
+ end
138
+ end
166
139
  end
167
140
 
168
141
  it "cannot view all orders" do
@@ -207,7 +180,7 @@ module Spree
207
180
 
208
181
  it "can filter the returned results" do
209
182
  request.env['SERVER_NAME'] = store.url
210
- api_get :mine, q: {completed_at_not_null: 1}
183
+ api_get :mine, q: { completed_at_not_null: 1 }
211
184
 
212
185
  expect(response.status).to eq(200)
213
186
  expect(json_response["orders"].length).to eq(0)
@@ -246,8 +219,8 @@ module Spree
246
219
  end
247
220
 
248
221
  it "can view their own order" do
249
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
250
- api_get :show, :id => order.to_param
222
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
223
+ api_get :show, id: order.to_param
251
224
  expect(response.status).to eq(200)
252
225
  expect(json_response).to have_attributes(attributes)
253
226
  expect(json_response["adjustments"]).to be_empty
@@ -260,7 +233,7 @@ module Spree
260
233
  subject { api_get :show, id: order.to_param }
261
234
 
262
235
  before do
263
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
236
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
264
237
  end
265
238
 
266
239
  context 'when inventory information is present' do
@@ -307,33 +280,33 @@ module Spree
307
280
  end
308
281
 
309
282
  it "orders contain the basic checkout steps" do
310
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
311
- api_get :show, :id => order.to_param
283
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
284
+ api_get :show, id: order.to_param
312
285
  expect(response.status).to eq(200)
313
286
  expect(json_response["checkout_steps"]).to eq(%w[address delivery confirm complete])
314
287
  end
315
288
 
316
289
  # Regression test for https://github.com/spree/spree/issues/1992
317
290
  it "can view an order not in a standard state" do
318
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
291
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
319
292
  order.update_column(:state, 'shipped')
320
- api_get :show, :id => order.to_param
293
+ api_get :show, id: order.to_param
321
294
  end
322
295
 
323
296
  it "can not view someone else's order" do
324
- allow_any_instance_of(Order).to receive_messages :user => stub_model(Spree::LegacyUser)
325
- api_get :show, :id => order.to_param
297
+ allow_any_instance_of(Order).to receive_messages user: stub_model(Spree::LegacyUser)
298
+ api_get :show, id: order.to_param
326
299
  assert_unauthorized!
327
300
  end
328
301
 
329
302
  it "can view an order if the token is known" do
330
- api_get :show, :id => order.to_param, :order_token => order.guest_token
303
+ api_get :show, id: order.to_param, order_token: order.guest_token
331
304
  expect(response.status).to eq(200)
332
305
  end
333
306
 
334
307
  it "can view an order if the token is passed in header" do
335
308
  request.headers["X-Spree-Order-Token"] = order.guest_token
336
- api_get :show, :id => order.to_param
309
+ api_get :show, id: order.to_param
337
310
  expect(response.status).to eq(200)
338
311
  end
339
312
 
@@ -344,7 +317,7 @@ module Spree
344
317
  it "can view an order" do
345
318
  user = build(:user, spree_roles: [Spree::Role.new(name: 'bar')])
346
319
  allow(Spree.user_class).to receive_messages find_by: user
347
- api_get :show, :id => order.to_param
320
+ api_get :show, id: order.to_param
348
321
  expect(response.status).to eq(200)
349
322
  end
350
323
  end
@@ -352,12 +325,12 @@ module Spree
352
325
  it "cannot cancel an order that doesn't belong to them" do
353
326
  order.update_attribute(:completed_at, Time.current)
354
327
  order.update_attribute(:shipment_state, "ready")
355
- api_put :cancel, :id => order.to_param
328
+ api_put :cancel, id: order.to_param
356
329
  assert_unauthorized!
357
330
  end
358
331
 
359
332
  it "can create an order" do
360
- api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
333
+ api_post :create, order: { line_items: { "0" => { variant_id: variant.to_param, quantity: 5 } } }
361
334
  expect(response.status).to eq(201)
362
335
 
363
336
  order = Order.last
@@ -374,20 +347,23 @@ module Spree
374
347
  end
375
348
 
376
349
  it "assigns email when creating a new order" do
377
- api_post :create, :order => { :email => "guest@spreecommerce.com" }
350
+ api_post :create, order: { email: "guest@spreecommerce.com" }
378
351
  expect(json_response['email']).not_to eq controller.current_api_user
379
352
  expect(json_response['email']).to eq "guest@spreecommerce.com"
380
353
  end
381
354
 
382
355
  # Regression test for https://github.com/spree/spree/issues/3404
383
356
  it "can specify additional parameters for a line item" do
384
- expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
357
+ expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
358
+ allow(order).to receive(:associate_user!)
359
+ allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
360
+ expect(line_item).to receive(:update_attributes!).with("special" => true)
385
361
 
386
362
  allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
387
- api_post :create, :order => {
388
- :line_items => {
363
+ api_post :create, order: {
364
+ line_items: {
389
365
  "0" => {
390
- variant_id: variant.to_param, quantity: 5, special: "foo"
366
+ variant_id: variant.to_param, quantity: 5, special: true
391
367
  }
392
368
  }
393
369
  }
@@ -395,10 +371,10 @@ module Spree
395
371
  end
396
372
 
397
373
  it "cannot arbitrarily set the line items price" do
398
- api_post :create, :order => {
399
- :line_items => {
374
+ api_post :create, order: {
375
+ line_items: {
400
376
  "0" => {
401
- :price => 33.0, :variant_id => variant.to_param, :quantity => 5
377
+ price: 33.0, variant_id: variant.to_param, quantity: 5
402
378
  }
403
379
  }
404
380
  }
@@ -411,7 +387,7 @@ module Spree
411
387
  let!(:current_api_user) { create :admin_user }
412
388
 
413
389
  it "is able to set any default unpermitted attribute" do
414
- api_post :create, :order => { number: "WOW" }
390
+ api_post :create, order: { number: "WOW" }
415
391
  expect(response.status).to eq 201
416
392
  expect(json_response['number']).to eq "WOW"
417
393
  end
@@ -424,26 +400,29 @@ module Spree
424
400
  end
425
401
 
426
402
  context "working with an order" do
427
-
428
403
  let(:variant) { create(:variant) }
429
404
  let!(:line_item) { order.contents.add(variant, 1) }
430
405
  let!(:payment_method) { create(:check_payment_method) }
431
406
 
432
- let(:address_params) { { :country_id => country.id } }
433
- let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
434
- :city => "Sao Paulo", :zipcode => "01310-300", :phone => "12345678",
435
- :country_id => country.id} }
436
- let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
437
- :city => "Sao Paulo", :zipcode => "01310-300", :phone => "12345678",
438
- :country_id => country.id} }
439
- let(:country) { create(:country, {name: "Brazil", iso_name: "BRAZIL", iso: "BR", iso3: "BRA", numcode: 76 })}
407
+ let(:address_params) { { country_id: country.id } }
408
+ let(:billing_address) {
409
+ { firstname: "Tiago", lastname: "Motta", address1: "Av Paulista",
410
+ city: "Sao Paulo", zipcode: "01310-300", phone: "12345678",
411
+ country_id: country.id }
412
+ }
413
+ let(:shipping_address) {
414
+ { firstname: "Tiago", lastname: "Motta", address1: "Av Paulista",
415
+ city: "Sao Paulo", zipcode: "01310-300", phone: "12345678",
416
+ country_id: country.id }
417
+ }
418
+ let(:country) { create(:country, { name: "Brazil", iso_name: "BRAZIL", iso: "BR", iso3: "BRA", numcode: 76 }) }
440
419
 
441
420
  before { allow_any_instance_of(Order).to receive_messages user: current_api_user }
442
421
 
443
422
  it "updates quantities of existing line items" do
444
- api_put :update, :id => order.to_param, :order => {
445
- :line_items => {
446
- "0" => { :id => line_item.id, :quantity => 10 }
423
+ api_put :update, id: order.to_param, order: {
424
+ line_items: {
425
+ "0" => { id: line_item.id, quantity: 10 }
447
426
  }
448
427
  }
449
428
 
@@ -454,10 +433,10 @@ module Spree
454
433
 
455
434
  it "adds an extra line item" do
456
435
  variant2 = create(:variant)
457
- api_put :update, :id => order.to_param, :order => {
458
- :line_items => {
459
- "0" => { :id => line_item.id, :quantity => 10 },
460
- "1" => { :variant_id => variant2.id, :quantity => 1}
436
+ api_put :update, id: order.to_param, order: {
437
+ line_items: {
438
+ "0" => { id: line_item.id, quantity: 10 },
439
+ "1" => { variant_id: variant2.id, quantity: 1 }
461
440
  }
462
441
  }
463
442
 
@@ -469,9 +448,9 @@ module Spree
469
448
  end
470
449
 
471
450
  it "cannot change the price of an existing line item" do
472
- api_put :update, :id => order.to_param, :order => {
473
- :line_items => {
474
- 0 => { :id => line_item.id, :price => 0 }
451
+ api_put :update, id: order.to_param, order: {
452
+ line_items: {
453
+ 0 => { id: line_item.id, price: 0 }
475
454
  }
476
455
  }
477
456
 
@@ -482,7 +461,7 @@ module Spree
482
461
  end
483
462
 
484
463
  it "can add billing address" do
485
- api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
464
+ api_put :update, id: order.to_param, order: { bill_address_attributes: billing_address }
486
465
 
487
466
  expect(order.reload.bill_address).to_not be_nil
488
467
  end
@@ -490,7 +469,7 @@ module Spree
490
469
  it "receives error message if trying to add billing address with errors" do
491
470
  billing_address[:firstname] = ""
492
471
 
493
- api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
472
+ api_put :update, id: order.to_param, order: { bill_address_attributes: billing_address }
494
473
 
495
474
  expect(json_response['error']).not_to be_nil
496
475
  expect(json_response['errors']).not_to be_nil
@@ -501,7 +480,7 @@ module Spree
501
480
  order.update_attributes!(ship_address_id: nil)
502
481
 
503
482
  expect {
504
- api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
483
+ api_put :update, id: order.to_param, order: { ship_address_attributes: shipping_address }
505
484
  }.to change { order.reload.ship_address }.from(nil)
506
485
  end
507
486
 
@@ -510,7 +489,7 @@ module Spree
510
489
 
511
490
  shipping_address[:firstname] = ""
512
491
 
513
- api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
492
+ api_put :update, id: order.to_param, order: { ship_address_attributes: shipping_address }
514
493
 
515
494
  expect(json_response['error']).not_to be_nil
516
495
  expect(json_response['errors']).not_to be_nil
@@ -520,7 +499,7 @@ module Spree
520
499
  it "cannot set the user_id for the order" do
521
500
  user = Spree.user_class.create
522
501
  original_id = order.user_id
523
- api_post :update, :id => order.to_param, :order => { user_id: user.id }
502
+ api_post :update, id: order.to_param, order: { user_id: user.id }
524
503
  expect(response.status).to eq 200
525
504
  expect(json_response["user_id"]).to eq(original_id)
526
505
  end
@@ -529,10 +508,9 @@ module Spree
529
508
  before { order.create_proposed_shipments }
530
509
 
531
510
  it "clears out all existing shipments on line item udpate" do
532
- previous_shipments = order.shipments
533
- api_put :update, :id => order.to_param, :order => {
534
- :line_items => {
535
- 0 => { :id => line_item.id, :quantity => 10 }
511
+ api_put :update, id: order.to_param, order: {
512
+ line_items: {
513
+ 0 => { id: line_item.id, quantity: 10 }
536
514
  }
537
515
  }
538
516
  expect(order.reload.shipments).to be_empty
@@ -544,7 +522,7 @@ module Spree
544
522
 
545
523
  it "can empty an order" do
546
524
  create(:adjustment, order: order, adjustable: order)
547
- api_put :empty, :id => order.to_param
525
+ api_put :empty, id: order.to_param
548
526
  expect(response.status).to eq(204)
549
527
  order.reload
550
528
  expect(order.line_items).to be_empty
@@ -552,21 +530,21 @@ module Spree
552
530
  end
553
531
 
554
532
  it "can list its line items with images" do
555
- order.line_items.first.variant.images.create!(:attachment => image("thinking-cat.jpg"))
533
+ order.line_items.first.variant.images.create!(attachment: image("thinking-cat.jpg"))
556
534
 
557
- api_get :show, :id => order.to_param
535
+ api_get :show, id: order.to_param
558
536
 
559
537
  expect(json_response['line_items'].first['variant']).to have_attributes([:images])
560
538
  end
561
539
 
562
540
  it "lists variants product id" do
563
- api_get :show, :id => order.to_param
541
+ api_get :show, id: order.to_param
564
542
 
565
543
  expect(json_response['line_items'].first['variant']).to have_attributes([:product_id])
566
544
  end
567
545
 
568
546
  it "includes the tax_total in the response" do
569
- api_get :show, :id => order.to_param
547
+ api_get :show, id: order.to_param
570
548
 
571
549
  expect(json_response['included_tax_total']).to eq('0.0')
572
550
  expect(json_response['additional_tax_total']).to eq('0.0')
@@ -576,11 +554,11 @@ module Spree
576
554
 
577
555
  it "lists line item adjustments" do
578
556
  adjustment = create(:adjustment,
579
- :label => "10% off!",
580
- :order => order,
581
- :adjustable => order.line_items.first)
557
+ label: "10% off!",
558
+ order: order,
559
+ adjustable: order.line_items.first)
582
560
  adjustment.update_column(:amount, 5)
583
- api_get :show, :id => order.to_param
561
+ api_get :show, id: order.to_param
584
562
 
585
563
  adjustment = json_response['line_items'].first['adjustments'].first
586
564
  expect(adjustment['label']).to eq("10% off!")
@@ -589,7 +567,7 @@ module Spree
589
567
 
590
568
  it "lists payments source without gateway info" do
591
569
  order.payments.push payment = create(:payment)
592
- api_get :show, :id => order.to_param
570
+ api_get :show, id: order.to_param
593
571
 
594
572
  source = json_response[:payments].first[:source]
595
573
  expect(source[:name]).to eq payment.source.name
@@ -597,8 +575,8 @@ module Spree
597
575
  expect(source[:last_digits]).to eq payment.source.last_digits
598
576
  expect(source[:month]).to eq payment.source.month
599
577
  expect(source[:year]).to eq payment.source.year
600
- expect(source.has_key?(:gateway_customer_profile_id)).to be false
601
- expect(source.has_key?(:gateway_payment_profile_id)).to be false
578
+ expect(source.key?(:gateway_customer_profile_id)).to be false
579
+ expect(source.key?(:gateway_payment_profile_id)).to be false
602
580
  end
603
581
 
604
582
  context "when in delivery" do
@@ -623,7 +601,7 @@ module Spree
623
601
  end
624
602
 
625
603
  it "returns available shipments for an order" do
626
- api_get :show, :id => order.to_param
604
+ api_get :show, id: order.to_param
627
605
  expect(response.status).to eq(200)
628
606
  expect(json_response["shipments"]).not_to be_empty
629
607
  shipment = json_response["shipments"][0]
@@ -686,7 +664,7 @@ module Spree
686
664
 
687
665
  it "lists payments source with gateway info" do
688
666
  order.payments.push payment = create(:payment)
689
- api_get :show, :id => order.to_param
667
+ api_get :show, id: order.to_param
690
668
 
691
669
  source = json_response[:payments].first[:source]
692
670
  expect(source[:name]).to eq payment.source.name
@@ -711,7 +689,7 @@ module Spree
711
689
 
712
690
  # Test for https://github.com/spree/spree/issues/1763
713
691
  it "can control the page size through a parameter" do
714
- api_get :index, :per_page => 1
692
+ api_get :index, per_page: 1
715
693
  expect(json_response["orders"].count).to eq(1)
716
694
  expect(json_response["orders"].first).to have_attributes(attributes)
717
695
  expect(json_response["count"]).to eq(1)
@@ -729,7 +707,7 @@ module Spree
729
707
  let(:expected_result) { Spree::Order.last }
730
708
 
731
709
  it "can query the results through a parameter" do
732
- api_get :index, :q => { :email_cont => 'spree' }
710
+ api_get :index, q: { email_cont: 'spree' }
733
711
  expect(json_response["orders"].count).to eq(1)
734
712
  expect(json_response["orders"].first).to have_attributes(attributes)
735
713
  expect(json_response["orders"].first["email"]).to eq(expected_result.email)
@@ -743,15 +721,14 @@ module Spree
743
721
  it "can create an order without any parameters" do
744
722
  api_post :create
745
723
  expect(response.status).to eq(201)
746
- order = Order.last
747
724
  expect(json_response["state"]).to eq("cart")
748
725
  end
749
726
 
750
727
  it "can arbitrarily set the line items price" do
751
- api_post :create, :order => {
752
- :line_items => {
728
+ api_post :create, order: {
729
+ line_items: {
753
730
  "0" => {
754
- :price => 33.0, :variant_id => variant.to_param, :quantity => 5
731
+ price: 33.0, variant_id: variant.to_param, quantity: 5
755
732
  }
756
733
  }
757
734
  }
@@ -761,7 +738,7 @@ module Spree
761
738
 
762
739
  it "can set the user_id for the order" do
763
740
  user = Spree.user_class.create
764
- api_post :create, :order => { user_id: user.id }
741
+ api_post :create, order: { user_id: user.id }
765
742
  expect(response.status).to eq 201
766
743
  expect(json_response["user_id"]).to eq(user.id)
767
744
  end
@@ -770,7 +747,7 @@ module Spree
770
747
  context "updating" do
771
748
  it "can set the user_id for the order" do
772
749
  user = Spree.user_class.create
773
- api_post :update, :id => order.number, :order => { user_id: user.id }
750
+ api_post :update, id: order.number, order: { user_id: user.id }
774
751
  expect(response.status).to eq 200
775
752
  expect(json_response["user_id"]).to eq(user.id)
776
753
  end
@@ -787,8 +764,9 @@ module Spree
787
764
  end
788
765
 
789
766
  specify do
790
- api_put :cancel, :id => order.to_param
767
+ api_put :cancel, id: order.to_param
791
768
  expect(json_response["state"]).to eq("canceled")
769
+ expect(json_response["canceler_id"]).to eq(current_api_user.id)
792
770
  end
793
771
  end
794
772
  end
@@ -798,7 +776,7 @@ module Spree
798
776
  let(:promo_code) { promo.codes.first }
799
777
 
800
778
  before do
801
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
779
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
802
780
  end
803
781
 
804
782
  context 'when successful' do
@@ -813,7 +791,7 @@ module Spree
813
791
  "success" => Spree.t(:coupon_code_applied),
814
792
  "error" => nil,
815
793
  "successful" => true,
816
- "status_code" => "coupon_code_applied",
794
+ "status_code" => "coupon_code_applied"
817
795
  })
818
796
  end
819
797
  end
@@ -830,7 +808,7 @@ module Spree
830
808
  "success" => nil,
831
809
  "error" => Spree.t(:coupon_code_unknown_error),
832
810
  "successful" => false,
833
- "status_code" => "coupon_code_unknown_error",
811
+ "status_code" => "coupon_code_unknown_error"
834
812
  })
835
813
  end
836
814
  end