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
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CheckoutsController, :type => :controller do
4
+ describe Api::CheckoutsController do
5
5
  render_views
6
6
 
7
7
  before(:each) do
@@ -31,39 +31,39 @@ module Spree
31
31
  end
32
32
 
33
33
  before(:each) do
34
- allow_any_instance_of(Order).to receive_messages(:confirmation_required? => true)
35
- allow_any_instance_of(Order).to receive_messages(:payment_required? => true)
34
+ Order.any_instance.stub(:confirmation_required? => true)
35
+ Order.any_instance.stub(:payment_required? => true)
36
36
  end
37
37
 
38
38
  it "should transition a recently created order from cart to address" do
39
- expect(order.state).to eq "cart"
40
- expect(order.email).not_to be_nil
39
+ order.state.should eq "cart"
40
+ order.email.should_not be_nil
41
41
  api_put :update, :id => order.to_param, :order_token => order.guest_token
42
- expect(order.reload.state).to eq "address"
42
+ order.reload.state.should eq "address"
43
43
  end
44
44
 
45
45
  it "should transition a recently created order from cart to address with order token in header" do
46
- expect(order.state).to eq "cart"
47
- expect(order.email).not_to be_nil
46
+ order.state.should eq "cart"
47
+ order.email.should_not be_nil
48
48
  request.headers["X-Spree-Order-Token"] = order.guest_token
49
49
  api_put :update, :id => order.to_param
50
- expect(order.reload.state).to eq "address"
50
+ order.reload.state.should eq "address"
51
51
  end
52
52
 
53
53
  it "can take line_items_attributes as a parameter" do
54
54
  line_item = order.line_items.first
55
55
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
56
56
  :order => { :line_items_attributes => { 0 => { :id => line_item.id, :quantity => 1 } } }
57
- expect(response.status).to eq(200)
58
- expect(order.reload.state).to eq "address"
57
+ response.status.should == 200
58
+ order.reload.state.should eq "address"
59
59
  end
60
60
 
61
61
  it "can take line_items as a parameter" do
62
62
  line_item = order.line_items.first
63
63
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
64
64
  :order => { :line_items => { 0 => { :id => line_item.id, :quantity => 1 } } }
65
- expect(response.status).to eq(200)
66
- expect(order.reload.state).to eq "address"
65
+ response.status.should == 200
66
+ order.reload.state.should eq "address"
67
67
  end
68
68
 
69
69
  it "will return an error if the order cannot transition" do
@@ -73,7 +73,7 @@ module Spree
73
73
  order.update_column(:state, "address")
74
74
  api_put :update, :id => order.to_param, :order_token => order.guest_token
75
75
  # Order has not transitioned
76
- expect(response.status).to eq(422)
76
+ response.status.should == 422
77
77
  end
78
78
 
79
79
  context "transitioning to delivery" do
@@ -101,10 +101,10 @@ module Spree
101
101
  :bill_address_attributes => address,
102
102
  :ship_address_attributes => address
103
103
  }
104
- expect(json_response['state']).to eq('delivery')
105
- expect(json_response['bill_address']['firstname']).to eq('John')
106
- expect(json_response['ship_address']['firstname']).to eq('John')
107
- expect(response.status).to eq(200)
104
+ json_response['state'].should == 'delivery'
105
+ json_response['bill_address']['firstname'].should == 'John'
106
+ json_response['ship_address']['firstname'].should == 'John'
107
+ response.status.should == 200
108
108
  end
109
109
 
110
110
  # Regression test for #4498
@@ -129,25 +129,25 @@ module Spree
129
129
  shipping_rate = shipment.shipping_rates.where(:selected => false).first
130
130
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
131
131
  :order => { :shipments_attributes => { "0" => { :selected_shipping_rate_id => shipping_rate.id, :id => shipment.id } } }
132
- expect(response.status).to eq(200)
132
+ response.status.should == 200
133
133
  # Find the correct shipment...
134
134
  json_shipment = json_response['shipments'].detect { |s| s["id"] == shipment.id }
135
135
  # Find the correct shipping rate for that shipment...
136
136
  json_shipping_rate = json_shipment['shipping_rates'].detect { |sr| sr["id"] == shipping_rate.id }
137
137
  # ... And finally ensure that it's selected
138
- expect(json_shipping_rate['selected']).to be true
138
+ json_shipping_rate['selected'].should be true
139
139
  # Order should automatically transfer to payment because all criteria are met
140
- expect(json_response['state']).to eq('payment')
140
+ json_response['state'].should == 'payment'
141
141
  end
142
142
 
143
143
  it "can update payment method and transition from payment to confirm" do
144
144
  order.update_column(:state, "payment")
145
145
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
146
146
  :order => { :payments_attributes => [{ :payment_method_id => @payment_method.id }] }
147
- expect(json_response['state']).to eq('confirm')
148
- expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
149
- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
150
- expect(response.status).to eq(200)
147
+ json_response['state'].should == 'confirm'
148
+ json_response['payments'][0]['payment_method']['name'].should == @payment_method.name
149
+ json_response['payments'][0]['amount'].should == order.total.to_s
150
+ response.status.should == 200
151
151
  end
152
152
 
153
153
  it "can update payment method with source and transition from payment to confirm" do
@@ -163,27 +163,27 @@ module Spree
163
163
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
164
164
  :order => { :payments_attributes => [{ :payment_method_id => @payment_method.id.to_s }],
165
165
  :payment_source => { @payment_method.id.to_s => source_attributes } }
166
- expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
167
- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
168
- expect(response.status).to eq(200)
166
+ json_response['payments'][0]['payment_method']['name'].should == @payment_method.name
167
+ json_response['payments'][0]['amount'].should == order.total.to_s
168
+ response.status.should == 200
169
169
  end
170
170
 
171
171
  it "returns errors when source is missing attributes" do
172
172
  order.update_column(:state, "payment")
173
173
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
174
174
  :order => {
175
- :payments_attributes => [{ :payment_method_id => @payment_method.id.to_s }]
175
+ :payments_attributes => [{ :payment_method_id => @payment_method.id }]
176
176
  },
177
177
  :payment_source => {
178
178
  @payment_method.id.to_s => { name: "Spree" }
179
179
  }
180
180
 
181
- expect(response.status).to eq(422)
181
+ response.status.should == 422
182
182
  cc_errors = json_response['errors']['payments.Credit Card']
183
- expect(cc_errors).to include("Number can't be blank")
184
- expect(cc_errors).to include("Month is not a number")
185
- expect(cc_errors).to include("Year is not a number")
186
- expect(cc_errors).to include("Verification Value can't be blank")
183
+ cc_errors.should include("Number can't be blank")
184
+ cc_errors.should include("Month is not a number")
185
+ cc_errors.should include("Year is not a number")
186
+ cc_errors.should include("Verification Value can't be blank")
187
187
  end
188
188
 
189
189
  it "allow users to reuse a credit card" do
@@ -199,17 +199,17 @@ module Spree
199
199
 
200
200
  it "can transition from confirm to complete" do
201
201
  order.update_column(:state, "confirm")
202
- allow_any_instance_of(Spree::Order).to receive_messages(:payment_required? => false)
202
+ Spree::Order.any_instance.stub(:payment_required? => false)
203
203
  api_put :update, :id => order.to_param, :order_token => order.guest_token
204
- expect(json_response['state']).to eq('complete')
205
- expect(response.status).to eq(200)
204
+ json_response['state'].should == 'complete'
205
+ response.status.should == 200
206
206
  end
207
207
 
208
208
  it "returns the order if the order is already complete" do
209
209
  order.update_column(:state, "complete")
210
210
  api_put :update, :id => order.to_param, :order_token => order.guest_token
211
- expect(json_response['number']).to eq(order.number)
212
- expect(response.status).to eq(200)
211
+ json_response['number'].should == order.number
212
+ response.status.should == 200
213
213
  end
214
214
 
215
215
  # Regression test for #3784
@@ -227,24 +227,24 @@ module Spree
227
227
  # Need to pass email as well so that validations succeed
228
228
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
229
229
  :order => { :user_id => user.id, :email => "guest@spreecommerce.com" }
230
- expect(response.status).to eq(200)
231
- expect(json_response['user_id']).to eq(user.id)
230
+ response.status.should == 200
231
+ json_response['user_id'].should == user.id
232
232
  end
233
233
  end
234
234
 
235
235
  it "can assign an email to the order" do
236
236
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
237
237
  :order => { :email => "guest@spreecommerce.com" }
238
- expect(json_response['email']).to eq("guest@spreecommerce.com")
239
- expect(response.status).to eq(200)
238
+ json_response['email'].should == "guest@spreecommerce.com"
239
+ response.status.should == 200
240
240
  end
241
241
 
242
242
  it "can apply a coupon code to an order" do
243
243
  skip "ensure that the order totals are properly updated, see frontend orders_controller or checkout_controller as example"
244
244
 
245
245
  order.update_column(:state, "payment")
246
- expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
247
- expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({:coupon_applied? => true})
246
+ PromotionHandler::Coupon.should_receive(:new).with(order).and_call_original
247
+ PromotionHandler::Coupon.any_instance.should_receive(:apply).and_return({:coupon_applied? => true})
248
248
  api_put :update, :id => order.to_param, :order_token => order.guest_token, :order => { :coupon_code => "foobar" }
249
249
  end
250
250
  end
@@ -255,16 +255,16 @@ module Spree
255
255
  order.line_items.delete_all
256
256
  order.update_column(:email, "spree@example.com")
257
257
  api_put :next, :id => order.to_param, :order_token => order.guest_token
258
- expect(response.status).to eq(422)
259
- expect(json_response["errors"]["base"]).to include(Spree.t(:there_are_no_items_for_this_order))
258
+ response.status.should == 422
259
+ json_response["errors"]["base"].should include(Spree.t(:there_are_no_items_for_this_order))
260
260
  end
261
261
 
262
262
  it "can transition an order to the next state" do
263
263
  order.update_column(:email, "spree@example.com")
264
264
 
265
265
  api_put :next, :id => order.to_param, :order_token => order.guest_token
266
- expect(response.status).to eq(200)
267
- expect(json_response['state']).to eq('address')
266
+ response.status.should == 200
267
+ json_response['state'].should == 'address'
268
268
  end
269
269
 
270
270
  it "cannot transition if order email is blank" do
@@ -274,14 +274,14 @@ module Spree
274
274
  )
275
275
 
276
276
  api_put :next, :id => order.to_param, :order_token => order.guest_token
277
- expect(response.status).to eq(422)
278
- expect(json_response['error']).to match(/could not be transitioned/)
277
+ response.status.should == 422
278
+ json_response['error'].should =~ /could not be transitioned/
279
279
  end
280
280
 
281
281
  it "doesnt advance payment state if order has no payment" do
282
282
  order.update_column(:state, "payment")
283
283
  api_put :next, :id => order.to_param, :order_token => order.guest_token, :order => {}
284
- expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
284
+ json_response["errors"]["base"].should include(Spree.t(:no_payment_found))
285
285
  end
286
286
  end
287
287
 
@@ -289,13 +289,13 @@ module Spree
289
289
  let!(:order) { create(:order_with_line_items) }
290
290
 
291
291
  it 'continues to advance advances an order while it can move forward' do
292
- expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
292
+ Spree::Order.any_instance.should_receive(:next).exactly(3).times.and_return(true, true, false)
293
293
  api_put :advance, :id => order.to_param, :order_token => order.guest_token
294
294
  end
295
295
 
296
296
  it 'returns the order' do
297
297
  api_put :advance, :id => order.to_param, :order_token => order.guest_token
298
- expect(json_response['id']).to eq(order.id)
298
+ json_response['id'].should == order.id
299
299
  end
300
300
  end
301
301
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::ClassificationsController, :type => :controller do
4
+ describe Api::ClassificationsController do
5
5
  let(:taxon) do
6
6
  taxon = create(:taxon)
7
7
  3.times do
@@ -18,7 +18,7 @@ module Spree
18
18
  context "as a user" do
19
19
  it "cannot change the order of a product" do
20
20
  api_put :update, :taxon_id => taxon, :product_id => taxon.products.first, :position => 1
21
- expect(response.status).to eq(401)
21
+ response.status.should == 401
22
22
  end
23
23
  end
24
24
 
@@ -28,10 +28,10 @@ module Spree
28
28
  it "can change the order a product" do
29
29
  last_product = taxon.products.last
30
30
  classification = taxon.classifications.find_by(:product_id => last_product.id)
31
- expect(classification.position).to eq(3)
31
+ classification.position.should == 3
32
32
  api_put :update, :taxon_id => taxon, :product_id => last_product, :position => 0
33
- expect(response.status).to eq(200)
34
- expect(classification.reload.position).to eq(1)
33
+ response.status.should == 200
34
+ classification.reload.position.should == 1
35
35
  end
36
36
  end
37
37
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::ConfigController, :type => :controller do
4
+ describe Api::ConfigController do
5
5
  render_views
6
6
 
7
7
  before do
@@ -10,18 +10,18 @@ module Spree
10
10
 
11
11
  it "returns Spree::Money settings" do
12
12
  api_get :money
13
- expect(response).to be_success
14
- expect(json_response["symbol"]).to eq("$")
15
- expect(json_response["symbol_position"]).to eq("before")
16
- expect(json_response["no_cents"]).to eq(false)
17
- expect(json_response["decimal_mark"]).to eq(".")
18
- expect(json_response["thousands_separator"]).to eq(",")
13
+ response.should be_success
14
+ json_response["symbol"].should == "$"
15
+ json_response["symbol_position"].should == "before"
16
+ json_response["no_cents"].should == false
17
+ json_response["decimal_mark"].should == "."
18
+ json_response["thousands_separator"].should == ","
19
19
  end
20
20
 
21
21
  it "returns some configuration settings" do
22
22
  api_get :show
23
- expect(response).to be_success
24
- expect(json_response["default_country_id"]).to eq(Spree::Config[:default_country_id])
23
+ response.should be_success
24
+ json_response["default_country_id"].should == Spree::Config[:default_country_id]
25
25
  end
26
26
  end
27
27
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CountriesController, :type => :controller do
4
+ describe Api::CountriesController do
5
5
  render_views
6
6
 
7
7
  before do
@@ -12,7 +12,7 @@ module Spree
12
12
 
13
13
  it "gets all countries" do
14
14
  api_get :index
15
- expect(json_response['countries'].first['iso3']).to eq @country.iso3
15
+ json_response['countries'].first['iso3'].should eq @country.iso3
16
16
  end
17
17
 
18
18
  context "with two countries" do
@@ -20,29 +20,29 @@ module Spree
20
20
 
21
21
  it "can view all countries" do
22
22
  api_get :index
23
- expect(json_response['count']).to eq(2)
24
- expect(json_response['current_page']).to eq(1)
25
- expect(json_response['pages']).to eq(1)
23
+ json_response['count'].should == 2
24
+ json_response['current_page'].should == 1
25
+ json_response['pages'].should == 1
26
26
  end
27
27
 
28
28
  it 'can query the results through a paramter' do
29
29
  api_get :index, :q => { :name_cont => 'zam' }
30
- expect(json_response['count']).to eq(1)
31
- expect(json_response['countries'].first['name']).to eq @zambia.name
30
+ json_response['count'].should == 1
31
+ json_response['countries'].first['name'].should eq @zambia.name
32
32
  end
33
33
 
34
34
  it 'can control the page size through a parameter' do
35
35
  api_get :index, :per_page => 1
36
- expect(json_response['count']).to eq(1)
37
- expect(json_response['current_page']).to eq(1)
38
- expect(json_response['pages']).to eq(2)
36
+ json_response['count'].should == 1
37
+ json_response['current_page'].should == 1
38
+ json_response['pages'].should == 2
39
39
  end
40
40
  end
41
41
 
42
42
  it "includes states" do
43
43
  api_get :show, :id => @country.id
44
44
  states = json_response['states']
45
- expect(states.first['name']).to eq @state.name
45
+ states.first['name'].should eq @state.name
46
46
  end
47
47
  end
48
48
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CreditCardsController, :type => :controller do
4
+ describe Api::CreditCardsController do
5
5
  render_views
6
6
 
7
7
  let!(:admin_user) do
8
8
  user = Spree.user_class.new(:email => "spree@example.com", :id => 1)
9
9
  user.generate_spree_api_key!
10
- allow(user).to receive(:has_spree_role?).with('admin').and_return(true)
10
+ user.stub(:has_spree_role?).with('admin').and_return(true)
11
11
  user
12
12
  end
13
13
 
@@ -25,7 +25,7 @@ module Spree
25
25
 
26
26
  it "the user id doesn't exist" do
27
27
  api_get :index, user_id: 1000
28
- expect(response.status).to eq(404)
28
+ response.status.should == 404
29
29
  end
30
30
 
31
31
  context "calling user is in admin role" do
@@ -37,18 +37,18 @@ module Spree
37
37
  it "no credit cards exist for user" do
38
38
  api_get :index, user_id: normal_user.id
39
39
 
40
- expect(response.status).to eq(200)
41
- expect(json_response["pages"]).to eq(0)
40
+ response.status.should == 200
41
+ json_response["pages"].should == 0
42
42
  end
43
43
 
44
44
  it "can view all credit cards for user" do
45
45
  api_get :index, user_id: current_api_user.id
46
46
 
47
- expect(response.status).to eq(200)
48
- expect(json_response["pages"]).to eq(1)
49
- expect(json_response["current_page"]).to eq(1)
50
- expect(json_response["credit_cards"].length).to eq(1)
51
- expect(json_response["credit_cards"].first["id"]).to eq(card.id)
47
+ response.status.should == 200
48
+ json_response["pages"].should == 1
49
+ json_response["current_page"].should == 1
50
+ json_response["credit_cards"].length.should == 1
51
+ json_response["credit_cards"].first["id"].should == card.id
52
52
  end
53
53
  end
54
54
 
@@ -63,17 +63,17 @@ module Spree
63
63
  it "can not view user" do
64
64
  api_get :index, user_id: admin_user.id
65
65
 
66
- expect(response.status).to eq(404)
66
+ response.status.should == 404
67
67
  end
68
68
 
69
69
  it "can view own credit cards" do
70
70
  api_get :index, user_id: normal_user.id
71
71
 
72
- expect(response.status).to eq(200)
73
- expect(json_response["pages"]).to eq(1)
74
- expect(json_response["current_page"]).to eq(1)
75
- expect(json_response["credit_cards"].length).to eq(1)
76
- expect(json_response["credit_cards"].first["id"]).to eq(card.id)
72
+ response.status.should == 200
73
+ json_response["pages"].should == 1
74
+ json_response["current_page"].should == 1
75
+ json_response["credit_cards"].length.should == 1
76
+ json_response["credit_cards"].first["id"].should == card.id
77
77
  end
78
78
  end
79
79
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Spree::Api::ImagesController, :type => :controller do
4
+ describe Spree::Api::ImagesController do
5
5
  render_views
6
6
 
7
7
  let!(:product) { create(:product) }
@@ -17,32 +17,58 @@ module Spree
17
17
  sign_in_as_admin!
18
18
 
19
19
  it "can upload a new image for a variant" do
20
- expect do
20
+ lambda do
21
21
  api_post :create,
22
22
  :image => { :attachment => upload_image('thinking-cat.jpg'),
23
23
  :viewable_type => 'Spree::Variant',
24
24
  :viewable_id => product.master.to_param },
25
25
  :product_id => product.id
26
- expect(response.status).to eq(201)
27
- expect(json_response).to have_attributes(attributes)
28
- end.to change(Image, :count).by(1)
26
+ response.status.should == 201
27
+ json_response.should have_attributes(attributes)
28
+ end.should change(Image, :count).by(1)
29
29
  end
30
30
 
31
31
  context "working with an existing image" do
32
32
  let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
33
33
 
34
+ it "can get a single product image" do
35
+ api_get :show, :id => product_image.id, :product_id => product.id
36
+ response.status.should == 200
37
+ json_response.should have_attributes(attributes)
38
+ end
39
+
40
+ it "can get a single variant image" do
41
+ api_get :show, :id => product_image.id, :variant_id => product.master.id
42
+ response.status.should == 200
43
+ json_response.should have_attributes(attributes)
44
+ end
45
+
46
+ it "can get a list of product images" do
47
+ api_get :index, :product_id => product.id
48
+ response.status.should == 200
49
+ json_response.should have_key("images")
50
+ json_response["images"].first.should have_attributes(attributes)
51
+ end
52
+
53
+ it "can get a list of variant images" do
54
+ api_get :index, :variant_id => product.master.id
55
+ response.status.should == 200
56
+ json_response.should have_key("images")
57
+ json_response["images"].first.should have_attributes(attributes)
58
+ end
59
+
34
60
  it "can update image data" do
35
- expect(product_image.position).to eq(1)
61
+ product_image.position.should == 1
36
62
  api_post :update, :image => { :position => 2 }, :id => product_image.id, :product_id => product.id
37
- expect(response.status).to eq(200)
38
- expect(json_response).to have_attributes(attributes)
39
- expect(product_image.reload.position).to eq(2)
63
+ response.status.should == 200
64
+ json_response.should have_attributes(attributes)
65
+ product_image.reload.position.should == 2
40
66
  end
41
67
 
42
68
  it "can delete an image" do
43
69
  api_delete :destroy, :id => product_image.id, :product_id => product.id
44
- expect(response.status).to eq(204)
45
- expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
70
+ response.status.should == 204
71
+ lambda { product_image.reload }.should raise_error(ActiveRecord::RecordNotFound)
46
72
  end
47
73
  end
48
74
  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 do
5
5
  render_views
6
6
 
7
7
  before do
@@ -14,13 +14,13 @@ module Spree
14
14
 
15
15
  it "gets an inventory unit" do
16
16
  api_get :show, :id => @inventory_unit.id
17
- expect(json_response['state']).to eq @inventory_unit.state
17
+ json_response['state'].should eq @inventory_unit.state
18
18
  end
19
19
 
20
20
  it "updates an inventory unit (only shipment is accessable by default)" do
21
21
  api_put :update, :id => @inventory_unit.id,
22
22
  :inventory_unit => { :shipment => nil }
23
- expect(json_response['shipment_id']).to be_nil
23
+ json_response['shipment_id'].should be_nil
24
24
  end
25
25
 
26
26
  context 'fires state event' do
@@ -29,19 +29,19 @@ module Spree
29
29
  :fire => 'ship',
30
30
  :inventory_unit => { :shipment => nil }
31
31
 
32
- expect(json_response['state']).to eq 'shipped'
32
+ json_response['state'].should eq 'shipped'
33
33
  end
34
34
 
35
35
  it 'and returns exception if cannot fire' do
36
36
  api_put :update, :id => @inventory_unit.id,
37
37
  :fire => 'return'
38
- expect(json_response['exception']).to match /cannot transition to return/
38
+ json_response['exception'].should match /cannot transition to return/
39
39
  end
40
40
 
41
41
  it 'and returns exception bad state' do
42
42
  api_put :update, :id => @inventory_unit.id,
43
43
  :fire => 'bad'
44
- expect(json_response['exception']).to match /cannot transition to bad/
44
+ json_response['exception'].should match /cannot transition to bad/
45
45
  end
46
46
  end
47
47
  end