spree_api 2.3.13 → 2.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -43
  3. data/Gemfile +1 -1
  4. data/app/controllers/spree/api/addresses_controller.rb +1 -1
  5. data/app/controllers/spree/api/base_controller.rb +22 -9
  6. data/app/controllers/spree/api/checkouts_controller.rb +2 -2
  7. data/app/controllers/spree/api/countries_controller.rb +2 -2
  8. data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
  9. data/app/controllers/spree/api/images_controller.rb +5 -0
  10. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  11. data/app/controllers/spree/api/line_items_controller.rb +7 -7
  12. data/app/controllers/spree/api/option_types_controller.rb +2 -2
  13. data/app/controllers/spree/api/orders_controller.rb +17 -6
  14. data/app/controllers/spree/api/payments_controller.rb +3 -11
  15. data/app/controllers/spree/api/product_properties_controller.rb +2 -2
  16. data/app/controllers/spree/api/promotions_controller.rb +26 -0
  17. data/app/controllers/spree/api/properties_controller.rb +1 -1
  18. data/app/controllers/spree/api/return_authorizations_controller.rb +0 -10
  19. data/app/controllers/spree/api/shipments_controller.rb +71 -4
  20. data/app/controllers/spree/api/states_controller.rb +3 -3
  21. data/app/controllers/spree/api/stock_items_controller.rb +1 -1
  22. data/app/controllers/spree/api/stock_movements_controller.rb +1 -1
  23. data/app/controllers/spree/api/taxons_controller.rb +1 -1
  24. data/app/controllers/spree/api/variants_controller.rb +1 -2
  25. data/app/helpers/spree/api/api_helpers.rb +19 -5
  26. data/app/views/spree/api/images/index.v1.rabl +4 -0
  27. data/app/views/spree/api/products/show.v1.rabl +4 -1
  28. data/app/views/spree/api/promotions/handler.v1.rabl +2 -1
  29. data/app/views/spree/api/promotions/show.v1.rabl +2 -0
  30. data/app/views/spree/api/shipments/big.v1.rabl +48 -0
  31. data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
  32. data/app/views/spree/api/shipments/small.v1.rabl +1 -5
  33. data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -2
  34. data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
  35. data/app/views/spree/api/variants/big.v1.rabl +6 -1
  36. data/app/views/spree/api/variants/show.v1.rabl +1 -1
  37. data/app/views/spree/api/variants/small.v1.rabl +2 -3
  38. data/config/routes.rb +9 -0
  39. data/lib/spree/api/responders/rabl_template.rb +1 -1
  40. data/lib/spree/api/testing_support/helpers.rb +6 -6
  41. data/lib/spree/api/testing_support/setup.rb +2 -2
  42. data/spec/controllers/spree/api/addresses_controller_spec.rb +7 -7
  43. data/spec/controllers/spree/api/base_controller_spec.rb +66 -19
  44. data/spec/controllers/spree/api/checkouts_controller_spec.rb +54 -54
  45. data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
  46. data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
  47. data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
  48. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
  49. data/spec/controllers/spree/api/images_controller_spec.rb +37 -11
  50. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
  51. data/spec/controllers/spree/api/line_items_controller_spec.rb +34 -35
  52. data/spec/controllers/spree/api/option_types_controller_spec.rb +18 -18
  53. data/spec/controllers/spree/api/option_values_controller_spec.rb +21 -21
  54. data/spec/controllers/spree/api/orders_controller_spec.rb +177 -161
  55. data/spec/controllers/spree/api/payments_controller_spec.rb +52 -89
  56. data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
  57. data/spec/controllers/spree/api/products_controller_spec.rb +103 -60
  58. data/spec/controllers/spree/api/promotion_application_spec.rb +14 -12
  59. data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
  60. data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
  61. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +42 -66
  62. data/spec/controllers/spree/api/shipments_controller_spec.rb +69 -21
  63. data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
  64. data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
  65. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
  66. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
  67. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
  68. data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
  69. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +5 -5
  70. data/spec/controllers/spree/api/users_controller_spec.rb +41 -41
  71. data/spec/controllers/spree/api/variants_controller_spec.rb +47 -37
  72. data/spec/controllers/spree/api/zones_controller_spec.rb +40 -18
  73. data/spec/models/spree/legacy_user_spec.rb +5 -5
  74. data/spec/requests/rabl_cache_spec.rb +9 -9
  75. data/spec/spec_helper.rb +1 -0
  76. metadata +14 -9
  77. data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -2,7 +2,7 @@ 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 do
6
6
  render_views
7
7
 
8
8
  let!(:order) { create(:order) }
@@ -46,7 +46,7 @@ module Spree
46
46
 
47
47
  it "returns a 401" do
48
48
  api_get :mine
49
- expect(response.status).to eq(401)
49
+ response.status.should == 401
50
50
  end
51
51
  end
52
52
 
@@ -57,110 +57,123 @@ module Spree
57
57
  it "can view all of their own orders" do
58
58
  api_get :mine
59
59
 
60
- expect(response.status).to eq(200)
61
- expect(json_response["pages"]).to eq(1)
62
- expect(json_response["current_page"]).to eq(1)
63
- expect(json_response["orders"].length).to eq(1)
64
- expect(json_response["orders"].first["number"]).to eq(order.number)
65
- expect(json_response["orders"].first["line_items"].length).to eq(1)
66
- expect(json_response["orders"].first["line_items"].first["id"]).to eq(line_item.id)
60
+ response.status.should == 200
61
+ json_response["pages"].should == 1
62
+ json_response["current_page"].should == 1
63
+ json_response["orders"].length.should == 1
64
+ json_response["orders"].first["number"].should == order.number
65
+ json_response["orders"].first["line_items"].length.should == 1
66
+ json_response["orders"].first["line_items"].first["id"].should == line_item.id
67
67
  end
68
68
 
69
69
  it "can filter the returned results" do
70
70
  api_get :mine, q: {completed_at_not_null: 1}
71
71
 
72
- expect(response.status).to eq(200)
73
- expect(json_response["orders"].length).to eq(0)
72
+ response.status.should == 200
73
+ json_response["orders"].length.should == 0
74
74
  end
75
75
 
76
- it "returns orders in reverse chronological order" do
77
- order2 = create(:order, line_items: [line_item], user: order.user)
78
- expect(order2.created_at).to be > order.created_at
76
+ it "returns orders in reverse chronological order by completed_at" do
77
+ order.update_columns completed_at: Time.now
78
+
79
+ order2 = Order.create user: order.user, completed_at: Time.now - 1.day
80
+ order2.created_at.should > order.created_at
81
+ order3 = Order.create user: order.user, completed_at: nil
82
+ order3.created_at.should > order2.created_at
83
+ order4 = Order.create user: order.user, completed_at: nil
84
+ order4.created_at.should > order3.created_at
79
85
 
80
86
  api_get :mine
81
- expect(response.status).to eq(200)
82
- expect(json_response["pages"]).to eq(1)
83
- expect(json_response["orders"].length).to eq(2)
84
- expect(json_response["orders"][0]["number"]).to eq(order2.number)
85
- expect(json_response["orders"][1]["number"]).to eq(order.number)
87
+ response.status.should == 200
88
+ json_response["pages"].should == 1
89
+ json_response["orders"].length.should == 4
90
+ json_response["orders"][0]["number"].should == order.number
91
+ json_response["orders"][1]["number"].should == order2.number
92
+ json_response["orders"][2]["number"].should == order4.number
93
+ json_response["orders"][3]["number"].should == order3.number
86
94
  end
87
95
  end
88
96
 
89
- it "can view their own order" do
90
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
91
- api_get :show, :id => order.to_param
92
- expect(response.status).to eq(200)
93
- expect(json_response).to have_attributes(attributes)
94
- expect(json_response["adjustments"]).to be_empty
95
- end
96
-
97
- describe 'GET #show' do
98
- let(:order) { create :order_with_line_items }
99
- let(:adjustment) { FactoryGirl.create(:adjustment, order: order) }
97
+ describe 'current' do
98
+ let(:current_api_user) { order.user }
99
+ let!(:order) { create(:order, line_items: [line_item]) }
100
100
 
101
- subject { api_get :show, id: order.to_param }
101
+ subject do
102
+ api_get :current, format: 'json'
103
+ end
102
104
 
103
- before do
104
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
105
+ context "an incomplete order exists" do
106
+ it "returns that order" do
107
+ expect(JSON.parse(subject.body)['id']).to eq order.id
108
+ expect(subject).to be_success
109
+ end
105
110
  end
106
111
 
107
- context 'when inventory information is present' do
108
- it 'contains stock information on variant' do
109
- subject
110
- variant = json_response['line_items'][0]['variant']
111
- expect(variant).to_not be_nil
112
- expect(variant['in_stock']).to eq(false)
113
- expect(variant['total_on_hand']).to eq(0)
114
- expect(variant['is_backorderable']).to eq(true)
112
+ context "multiple incomplete orders exist" do
113
+ it "returns the latest incomplete order" do
114
+ new_order = Spree::Order.create! user: order.user
115
+ expect(new_order.created_at).to be > order.created_at
116
+ expect(JSON.parse(subject.body)['id']).to eq new_order.id
115
117
  end
116
118
  end
117
119
 
118
- context 'when shipment adjustments are present' do
120
+ context "an incomplete order does not exist" do
121
+
119
122
  before do
120
- order.shipments.first.adjustments << adjustment
123
+ order.update_attribute(:state, order_state)
124
+ order.update_attribute(:completed_at, 5.minutes.ago)
121
125
  end
122
126
 
123
- it 'contains adjustments on shipment' do
124
- subject
127
+ ["complete", "returned", "awaiting_return"].each do |order_state|
128
+ context "order is in the #{order_state} state" do
129
+ let(:order_state) { order_state }
125
130
 
126
- # Test to insure shipment has adjustments
127
- shipment = json_response['shipments'][0]
128
- expect(shipment).to_not be_nil
129
- expect(shipment['adjustments'][0]).not_to be_empty
130
- expect(shipment['adjustments'][0]['label']).to eq(adjustment.label)
131
+ it "returns no content" do
132
+ expect(subject.status).to eq 204
133
+ expect(subject.body).to be_blank
134
+ end
135
+ end
131
136
  end
132
137
  end
133
138
  end
134
139
 
140
+ it "can view their own order" do
141
+ Order.any_instance.stub :user => current_api_user
142
+ api_get :show, :id => order.to_param
143
+ response.status.should == 200
144
+ json_response.should have_attributes(attributes)
145
+ json_response["adjustments"].should be_empty
146
+ end
147
+
135
148
  it "orders contain the basic checkout steps" do
136
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
149
+ Order.any_instance.stub :user => current_api_user
137
150
  api_get :show, :id => order.to_param
138
- expect(response.status).to eq(200)
139
- expect(json_response["checkout_steps"]).to eq(["address", "delivery", "complete"])
151
+ response.status.should == 200
152
+ json_response["checkout_steps"].should == ["address", "delivery", "complete"]
140
153
  end
141
154
 
142
155
  # Regression test for #1992
143
156
  it "can view an order not in a standard state" do
144
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
157
+ Order.any_instance.stub :user => current_api_user
145
158
  order.update_column(:state, 'shipped')
146
159
  api_get :show, :id => order.to_param
147
160
  end
148
161
 
149
162
  it "can not view someone else's order" do
150
- allow_any_instance_of(Order).to receive_messages :user => stub_model(Spree::LegacyUser)
163
+ Order.any_instance.stub :user => stub_model(Spree::LegacyUser)
151
164
  api_get :show, :id => order.to_param
152
165
  assert_unauthorized!
153
166
  end
154
167
 
155
168
  it "can view an order if the token is known" do
156
169
  api_get :show, :id => order.to_param, :order_token => order.guest_token
157
- expect(response.status).to eq(200)
170
+ response.status.should == 200
158
171
  end
159
172
 
160
173
  it "can view an order if the token is passed in header" do
161
174
  request.headers["X-Spree-Order-Token"] = order.guest_token
162
175
  api_get :show, :id => order.to_param
163
- expect(response.status).to eq(200)
176
+ response.status.should == 200
164
177
  end
165
178
 
166
179
  context "with BarAbility registered" do
@@ -169,12 +182,12 @@ module Spree
169
182
 
170
183
  it "can view an order" do
171
184
  user = mock_model(Spree::LegacyUser)
172
- allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
173
- allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
174
- allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
175
- allow(Spree.user_class).to receive_messages find_by: user
185
+ user.stub_chain(:spree_roles, :pluck).and_return(["bar"])
186
+ user.stub(:has_spree_role?).with('bar').and_return(true)
187
+ user.stub(:has_spree_role?).with('admin').and_return(false)
188
+ controller.stub try_spree_current_user: user
176
189
  api_get :show, :id => order.to_param
177
- expect(response.status).to eq(200)
190
+ response.status.should == 200
178
191
  end
179
192
  end
180
193
 
@@ -192,19 +205,19 @@ module Spree
192
205
 
193
206
  it "can create an order" do
194
207
  api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
195
- expect(response.status).to eq(201)
208
+ response.status.should == 201
196
209
 
197
210
  order = Order.last
198
- expect(order.line_items.count).to eq(1)
199
- expect(order.line_items.first.variant).to eq(variant)
200
- expect(order.line_items.first.quantity).to eq(5)
201
-
202
- expect(json_response['number']).to be_present
203
- expect(json_response["token"]).not_to be_blank
204
- expect(json_response["state"]).to eq("cart")
205
- expect(order.user).to eq(current_api_user)
206
- expect(order.email).to eq(current_api_user.email)
207
- expect(json_response["user_id"]).to eq(current_api_user.id)
211
+ order.line_items.count.should == 1
212
+ order.line_items.first.variant.should == variant
213
+ order.line_items.first.quantity.should == 5
214
+
215
+ json_response['number'].should be_present
216
+ json_response["token"].should_not be_blank
217
+ json_response["state"].should == "cart"
218
+ order.user.should == current_api_user
219
+ order.email.should == current_api_user.email
220
+ json_response["user_id"].should == current_api_user.id
208
221
  end
209
222
 
210
223
  it "assigns email when creating a new order" do
@@ -215,12 +228,12 @@ module Spree
215
228
 
216
229
  # Regression test for #3404
217
230
  it "can specify additional parameters for a line item" do
218
- expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
219
- allow(order).to receive(:associate_user!)
220
- allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
221
- expect(line_item).to receive(:update_attributes!).with("special" => true)
231
+ Order.should_receive(:create!).and_return(order = Spree::Order.new)
232
+ order.stub(:associate_user!)
233
+ order.stub_chain(:contents, :add).and_return(line_item = double('LineItem'))
234
+ line_item.should_receive(:update_attributes!).with("special" => true)
222
235
 
223
- allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
236
+ controller.stub(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
224
237
  api_post :create, :order => {
225
238
  :line_items => {
226
239
  "0" => {
@@ -228,7 +241,7 @@ module Spree
228
241
  }
229
242
  }
230
243
  }
231
- expect(response.status).to eq(201)
244
+ response.status.should == 201
232
245
  end
233
246
 
234
247
  it "cannot arbitrarily set the line items price" do
@@ -246,8 +259,8 @@ module Spree
246
259
 
247
260
  context "admin user imports order" do
248
261
  before do
249
- allow(current_api_user).to receive_messages has_spree_role?: true
250
- allow(current_api_user).to receive_message_chain :spree_roles, pluck: ["admin"]
262
+ current_api_user.stub has_spree_role?: true
263
+ current_api_user.stub_chain :spree_roles, pluck: ["admin"]
251
264
  end
252
265
 
253
266
  it "is able to set any default unpermitted attribute" do
@@ -259,10 +272,10 @@ module Spree
259
272
 
260
273
  # Regression test for #3404
261
274
  it "does not update line item needlessly" do
262
- expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
263
- allow(order).to receive(:associate_user!)
264
- allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
265
- expect(line_item).not_to receive(:update_attributes)
275
+ Order.should_receive(:create!).and_return(order = Spree::Order.new)
276
+ order.stub(:associate_user!)
277
+ order.stub_chain(:contents, :add).and_return(line_item = double('LineItem'))
278
+ line_item.should_not_receive(:update_attributes)
266
279
  api_post :create, :order => {
267
280
  :line_items => {
268
281
  "0" => {
@@ -273,10 +286,10 @@ module Spree
273
286
  end
274
287
 
275
288
  it "can create an order without any parameters" do
276
- expect { api_post :create }.not_to raise_error
277
- expect(response.status).to eq(201)
289
+ lambda { api_post :create }.should_not raise_error
290
+ response.status.should == 201
278
291
  order = Order.last
279
- expect(json_response["state"]).to eq("cart")
292
+ json_response["state"].should == "cart"
280
293
  end
281
294
 
282
295
  context "working with an order" do
@@ -294,12 +307,13 @@ module Spree
294
307
  :country_id => Country.first.id, :state_id => State.first.id} }
295
308
 
296
309
  before do
297
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
310
+ Spree::LineItem.stub(:find_by_id).and_return(Spree::LineItem.new)
311
+ Order.any_instance.stub :user => current_api_user
298
312
  order.next # Switch from cart to address
299
313
  order.bill_address = nil
300
314
  order.ship_address = nil
301
315
  order.save
302
- expect(order.state).to eq("address")
316
+ order.state.should == "address"
303
317
  end
304
318
 
305
319
  def clean_address(address)
@@ -325,9 +339,9 @@ module Spree
325
339
  }
326
340
  }
327
341
 
328
- expect(response.status).to eq(200)
329
- expect(json_response['line_items'].count).to eq(1)
330
- expect(json_response['line_items'].first['quantity']).to eq(10)
342
+ response.status.should == 200
343
+ json_response['line_items'].count.should == 1
344
+ json_response['line_items'].first['quantity'].should == 10
331
345
  end
332
346
 
333
347
  it "adds an extra line item" do
@@ -339,11 +353,11 @@ module Spree
339
353
  }
340
354
  }
341
355
 
342
- expect(response.status).to eq(200)
343
- expect(json_response['line_items'].count).to eq(2)
344
- expect(json_response['line_items'][0]['quantity']).to eq(10)
345
- expect(json_response['line_items'][1]['variant_id']).to eq(variant2.id)
346
- expect(json_response['line_items'][1]['quantity']).to eq(1)
356
+ response.status.should == 200
357
+ json_response['line_items'].count.should == 2
358
+ json_response['line_items'][0]['quantity'].should == 10
359
+ json_response['line_items'][1]['variant_id'].should == variant2.id
360
+ json_response['line_items'][1]['quantity'].should == 1
347
361
  end
348
362
 
349
363
  it "cannot change the price of an existing line item" do
@@ -353,8 +367,8 @@ module Spree
353
367
  }
354
368
  }
355
369
 
356
- expect(response.status).to eq(200)
357
- expect(json_response['line_items'].count).to eq(1)
370
+ response.status.should == 200
371
+ json_response['line_items'].count.should == 1
358
372
  expect(json_response['line_items'].first['price'].to_f).to_not eq(0)
359
373
  expect(json_response['line_items'].first['price'].to_f).to eq(line_item.variant.price)
360
374
  end
@@ -362,7 +376,7 @@ module Spree
362
376
  it "can add billing address" do
363
377
  api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
364
378
 
365
- expect(order.reload.bill_address).not_to be_nil
379
+ order.reload.bill_address.should_not be_nil
366
380
  end
367
381
 
368
382
  it "receives error message if trying to add billing address with errors" do
@@ -370,28 +384,28 @@ module Spree
370
384
 
371
385
  api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
372
386
 
373
- expect(json_response['error']).not_to be_nil
374
- expect(json_response['errors']).not_to be_nil
375
- expect(json_response['errors']['bill_address.firstname'].first).to eq "can't be blank"
387
+ json_response['error'].should_not be_nil
388
+ json_response['errors'].should_not be_nil
389
+ json_response['errors']['bill_address.firstname'].first.should eq "can't be blank"
376
390
  end
377
391
 
378
392
  it "can add shipping address" do
379
- expect(order.ship_address).to be_nil
393
+ order.ship_address.should be_nil
380
394
 
381
395
  api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
382
396
 
383
- expect(order.reload.ship_address).not_to be_nil
397
+ order.reload.ship_address.should_not be_nil
384
398
  end
385
399
 
386
400
  it "receives error message if trying to add shipping address with errors" do
387
- expect(order.ship_address).to be_nil
401
+ order.ship_address.should be_nil
388
402
  shipping_address[:firstname] = ""
389
403
 
390
404
  api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
391
405
 
392
- expect(json_response['error']).not_to be_nil
393
- expect(json_response['errors']).not_to be_nil
394
- expect(json_response['errors']['ship_address.firstname'].first).to eq "can't be blank"
406
+ json_response['error'].should_not be_nil
407
+ json_response['errors'].should_not be_nil
408
+ json_response['errors']['ship_address.firstname'].first.should eq "can't be blank"
395
409
  end
396
410
 
397
411
  it "cannot set the user_id for the order" do
@@ -399,7 +413,7 @@ module Spree
399
413
  original_id = order.user_id
400
414
  api_post :update, :id => order.to_param, :order => { user_id: user.id }
401
415
  expect(response.status).to eq 200
402
- expect(json_response["user_id"]).to eq(original_id)
416
+ json_response["user_id"].should == original_id
403
417
  end
404
418
 
405
419
  context "order has shipments" do
@@ -419,17 +433,17 @@ module Spree
419
433
  context "with a line item" do
420
434
  let(:order_with_line_items) do
421
435
  order = create(:order_with_line_items)
422
- create(:adjustment, order: order, adjustable: order)
436
+ create(:adjustment, :adjustable => order)
423
437
  order
424
438
  end
425
439
 
426
440
  it "can empty an order" do
427
- expect(order_with_line_items.adjustments.count).to eq(1)
441
+ order_with_line_items.adjustments.count.should be == 1
428
442
  api_put :empty, :id => order_with_line_items.to_param
429
- expect(response.status).to eq(200)
443
+ response.status.should == 204
430
444
  order_with_line_items.reload
431
- expect(order_with_line_items.line_items).to be_empty
432
- expect(order_with_line_items.adjustments).to be_empty
445
+ order_with_line_items.line_items.should be_empty
446
+ order_with_line_items.adjustments.should be_empty
433
447
  end
434
448
 
435
449
  it "can list its line items with images" do
@@ -437,22 +451,22 @@ module Spree
437
451
 
438
452
  api_get :show, :id => order.to_param
439
453
 
440
- expect(json_response['line_items'].first['variant']).to have_attributes([:images])
454
+ json_response['line_items'].first['variant'].should have_attributes([:images])
441
455
  end
442
456
 
443
457
  it "lists variants product id" do
444
458
  api_get :show, :id => order.to_param
445
459
 
446
- expect(json_response['line_items'].first['variant']).to have_attributes([:product_id])
460
+ json_response['line_items'].first['variant'].should have_attributes([:product_id])
447
461
  end
448
462
 
449
463
  it "includes the tax_total in the response" do
450
464
  api_get :show, :id => order.to_param
451
465
 
452
- expect(json_response['included_tax_total']).to eq('0.0')
453
- expect(json_response['additional_tax_total']).to eq('0.0')
454
- expect(json_response['display_included_tax_total']).to eq('$0.00')
455
- expect(json_response['display_additional_tax_total']).to eq('$0.00')
466
+ json_response['included_tax_total'].should == '0.0'
467
+ json_response['additional_tax_total'].should == '0.0'
468
+ json_response['display_included_tax_total'].should == '$0.00'
469
+ json_response['display_additional_tax_total'].should == '$0.00'
456
470
  end
457
471
 
458
472
  it "lists line item adjustments" do
@@ -464,8 +478,8 @@ module Spree
464
478
  api_get :show, :id => order.to_param
465
479
 
466
480
  adjustment = json_response['line_items'].first['adjustments'].first
467
- expect(adjustment['label']).to eq("10% off!")
468
- expect(adjustment['amount']).to eq("5.0")
481
+ adjustment['label'].should == "10% off!"
482
+ adjustment['amount'].should == "5.0"
469
483
  end
470
484
 
471
485
  it "lists payments source without gateway info" do
@@ -506,31 +520,33 @@ module Spree
506
520
 
507
521
  it "returns available shipments for an order" do
508
522
  api_get :show, :id => order.to_param
509
- expect(response.status).to eq(200)
510
- expect(json_response["shipments"]).not_to be_empty
523
+ response.status.should == 200
524
+ json_response["shipments"].should_not be_empty
511
525
  shipment = json_response["shipments"][0]
512
526
  # Test for correct shipping method attributes
513
527
  # Regression test for #3206
514
- expect(shipment["shipping_methods"]).not_to be_nil
528
+ shipment["shipping_methods"].should_not be_nil
515
529
  json_shipping_method = shipment["shipping_methods"][0]
516
- expect(json_shipping_method["id"]).to eq(shipping_method.id)
517
- expect(json_shipping_method["name"]).to eq(shipping_method.name)
518
- expect(json_shipping_method["zones"]).not_to be_empty
519
- expect(json_shipping_method["shipping_categories"]).not_to be_empty
530
+ json_shipping_method["id"].should == shipping_method.id
531
+ json_shipping_method["name"].should == shipping_method.name
532
+ json_shipping_method["code"].should == shipping_method.code
533
+ json_shipping_method["zones"].should_not be_empty
534
+ json_shipping_method["shipping_categories"].should_not be_empty
520
535
 
521
536
  # Test for correct shipping rates attributes
522
537
  # Regression test for #3206
523
- expect(shipment["shipping_rates"]).not_to be_nil
538
+ shipment["shipping_rates"].should_not be_nil
524
539
  shipping_rate = shipment["shipping_rates"][0]
525
- expect(shipping_rate["name"]).to eq(json_shipping_method["name"])
526
- expect(shipping_rate["cost"]).to eq("10.0")
527
- expect(shipping_rate["selected"]).to be true
528
- expect(shipping_rate["display_cost"]).to eq("$10.00")
540
+ shipping_rate["name"].should == json_shipping_method["name"]
541
+ shipping_rate["cost"].should == "10.0"
542
+ shipping_rate["selected"].should be true
543
+ shipping_rate["display_cost"].should == "$10.00"
544
+ shipping_rate["shipping_method_code"].should == json_shipping_method["code"]
529
545
 
530
- expect(shipment["stock_location_name"]).not_to be_blank
546
+ shipment["stock_location_name"].should_not be_blank
531
547
  manifest_item = shipment["manifest"][0]
532
- expect(manifest_item["quantity"]).to eq(1)
533
- expect(manifest_item["variant_id"]).to eq(order.line_items.first.variant_id)
548
+ manifest_item["quantity"].should == 1
549
+ manifest_item["variant_id"].should == order.line_items.first.variant_id
534
550
  end
535
551
  end
536
552
  end
@@ -543,7 +559,7 @@ module Spree
543
559
  before { Spree::Order.delete_all }
544
560
  it "still returns a root :orders key" do
545
561
  api_get :index
546
- expect(json_response["orders"]).to eq([])
562
+ json_response["orders"].should == []
547
563
  end
548
564
  end
549
565
 
@@ -596,20 +612,20 @@ module Spree
596
612
 
597
613
  it "can view all orders" do
598
614
  api_get :index
599
- expect(json_response["orders"].first).to have_attributes(attributes)
600
- expect(json_response["count"]).to eq(2)
601
- expect(json_response["current_page"]).to eq(1)
602
- expect(json_response["pages"]).to eq(1)
615
+ json_response["orders"].first.should have_attributes(attributes)
616
+ json_response["count"].should == 2
617
+ json_response["current_page"].should == 1
618
+ json_response["pages"].should == 1
603
619
  end
604
620
 
605
621
  # Test for #1763
606
622
  it "can control the page size through a parameter" do
607
623
  api_get :index, :per_page => 1
608
- expect(json_response["orders"].count).to eq(1)
609
- expect(json_response["orders"].first).to have_attributes(attributes)
610
- expect(json_response["count"]).to eq(1)
611
- expect(json_response["current_page"]).to eq(1)
612
- expect(json_response["pages"]).to eq(2)
624
+ json_response["orders"].count.should == 1
625
+ json_response["orders"].first.should have_attributes(attributes)
626
+ json_response["count"].should == 1
627
+ json_response["current_page"].should == 1
628
+ json_response["pages"].should == 2
613
629
  end
614
630
  end
615
631
 
@@ -623,21 +639,21 @@ module Spree
623
639
 
624
640
  it "can query the results through a parameter" do
625
641
  api_get :index, :q => { :email_cont => 'spree' }
626
- expect(json_response["orders"].count).to eq(1)
627
- expect(json_response["orders"].first).to have_attributes(attributes)
628
- expect(json_response["orders"].first["email"]).to eq(expected_result.email)
629
- expect(json_response["count"]).to eq(1)
630
- expect(json_response["current_page"]).to eq(1)
631
- expect(json_response["pages"]).to eq(1)
642
+ json_response["orders"].count.should == 1
643
+ json_response["orders"].first.should have_attributes(attributes)
644
+ json_response["orders"].first["email"].should == expected_result.email
645
+ json_response["count"].should == 1
646
+ json_response["current_page"].should == 1
647
+ json_response["pages"].should == 1
632
648
  end
633
649
  end
634
650
 
635
651
  context "creation" do
636
652
  it "can create an order without any parameters" do
637
- expect { api_post :create }.not_to raise_error
638
- expect(response.status).to eq(201)
653
+ lambda { api_post :create }.should_not raise_error
654
+ response.status.should == 201
639
655
  order = Order.last
640
- expect(json_response["state"]).to eq("cart")
656
+ json_response["state"].should == "cart"
641
657
  end
642
658
 
643
659
  it "can arbitrarily set the line items price" do
@@ -656,7 +672,7 @@ module Spree
656
672
  user = Spree.user_class.create
657
673
  api_post :create, :order => { user_id: user.id }
658
674
  expect(response.status).to eq 201
659
- expect(json_response["user_id"]).to eq(user.id)
675
+ json_response["user_id"].should == user.id
660
676
  end
661
677
  end
662
678
 
@@ -665,7 +681,7 @@ module Spree
665
681
  user = Spree.user_class.create
666
682
  api_post :update, :id => order.number, :order => { user_id: user.id }
667
683
  expect(response.status).to eq 200
668
- expect(json_response["user_id"]).to eq(user.id)
684
+ json_response["user_id"].should == user.id
669
685
  end
670
686
  end
671
687
 
@@ -681,7 +697,7 @@ module Spree
681
697
 
682
698
  specify do
683
699
  api_put :cancel, :id => order.to_param
684
- expect(json_response["state"]).to eq("canceled")
700
+ json_response["state"].should == "canceled"
685
701
  end
686
702
  end
687
703
  end