spree_api 2.0.13 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -1
  3. data/app/controllers/spree/api/addresses_controller.rb +5 -2
  4. data/app/controllers/spree/api/base_controller.rb +14 -21
  5. data/app/controllers/spree/api/checkouts_controller.rb +30 -27
  6. data/app/controllers/spree/api/config_controller.rb +6 -0
  7. data/app/controllers/spree/api/countries_controller.rb +7 -7
  8. data/app/controllers/spree/api/images_controller.rb +10 -8
  9. data/app/controllers/spree/api/inventory_units_controller.rb +7 -4
  10. data/app/controllers/spree/api/line_items_controller.rb +14 -14
  11. data/app/controllers/spree/api/option_types_controller.rb +14 -11
  12. data/app/controllers/spree/api/option_values_controller.rb +13 -11
  13. data/app/controllers/spree/api/orders_controller.rb +56 -53
  14. data/app/controllers/spree/api/payments_controller.rb +25 -33
  15. data/app/controllers/spree/api/product_properties_controller.rb +20 -13
  16. data/app/controllers/spree/api/products_controller.rb +11 -58
  17. data/app/controllers/spree/api/properties_controller.rb +19 -16
  18. data/app/controllers/spree/api/return_authorizations_controller.rb +30 -25
  19. data/app/controllers/spree/api/shipments_controller.rb +24 -19
  20. data/app/controllers/spree/api/states_controller.rb +9 -7
  21. data/app/controllers/spree/api/stock_items_controller.rb +9 -11
  22. data/app/controllers/spree/api/stock_locations_controller.rb +9 -7
  23. data/app/controllers/spree/api/stock_movements_controller.rb +7 -5
  24. data/app/controllers/spree/api/taxonomies_controller.rb +14 -8
  25. data/app/controllers/spree/api/taxons_controller.rb +25 -20
  26. data/app/controllers/spree/api/users_controller.rb +7 -5
  27. data/app/controllers/spree/api/variants_controller.rb +35 -33
  28. data/app/controllers/spree/api/zones_controller.rb +18 -17
  29. data/app/helpers/spree/api/api_helpers.rb +7 -6
  30. data/app/models/spree/option_value_decorator.rb +0 -4
  31. data/app/models/spree/order_decorator.rb +33 -54
  32. data/app/views/spree/api/adjustments/show.v1.rabl +2 -1
  33. data/app/views/spree/api/config/money.v1.rabl +6 -0
  34. data/app/views/spree/api/config/show.v1.rabl +2 -0
  35. data/app/views/spree/api/images/show.v1.rabl +0 -1
  36. data/app/views/spree/api/line_items/show.v1.rabl +3 -0
  37. data/app/views/spree/api/orders/index.v1.rabl +1 -1
  38. data/app/views/spree/api/orders/order.v1.rabl +6 -0
  39. data/app/views/spree/api/orders/payment.v1.rabl +1 -1
  40. data/app/views/spree/api/orders/show.v1.rabl +1 -1
  41. data/app/views/spree/api/payments/credit_over_limit.v1.rabl +1 -1
  42. data/app/views/spree/api/payments/new.v1.rabl +1 -0
  43. data/app/views/spree/api/products/index.v1.rabl +2 -2
  44. data/app/views/spree/api/products/show.v1.rabl +1 -0
  45. data/app/views/spree/api/shipments/show.v1.rabl +22 -5
  46. data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -0
  47. data/app/views/spree/api/taxons/index.v1.rabl +2 -4
  48. data/app/views/spree/api/variants/index.v1.rabl +1 -1
  49. data/config/locales/en.yml +1 -3
  50. data/config/routes.rb +4 -1
  51. data/lib/spree/api/responders/rabl_template.rb +1 -1
  52. data/lib/spree/api/testing_support/helpers.rb +5 -0
  53. data/spec/controllers/spree/api/addresses_controller_spec.rb +2 -2
  54. data/spec/controllers/spree/api/checkouts_controller_spec.rb +32 -22
  55. data/spec/controllers/spree/api/config_controller_spec.rb +27 -0
  56. data/spec/controllers/spree/api/images_controller_spec.rb +2 -2
  57. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +28 -24
  58. data/spec/controllers/spree/api/line_items_controller_spec.rb +25 -27
  59. data/spec/controllers/spree/api/option_types_controller_spec.rb +2 -2
  60. data/spec/controllers/spree/api/option_values_controller_spec.rb +2 -2
  61. data/spec/controllers/spree/api/orders_controller_spec.rb +130 -119
  62. data/spec/controllers/spree/api/payments_controller_spec.rb +77 -118
  63. data/spec/controllers/spree/api/products_controller_spec.rb +13 -143
  64. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +4 -19
  65. data/spec/controllers/spree/api/shipments_controller_spec.rb +3 -3
  66. data/spec/controllers/spree/api/states_controller_spec.rb +1 -1
  67. data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -62
  68. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +29 -56
  69. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +27 -51
  70. data/spec/controllers/spree/api/taxons_controller_spec.rb +18 -48
  71. data/spec/controllers/spree/api/users_controller_spec.rb +4 -6
  72. data/spec/controllers/spree/api/variants_controller_spec.rb +21 -38
  73. data/spec/controllers/spree/api/zones_controller_spec.rb +2 -2
  74. data/spec/models/spree/order_spec.rb +19 -111
  75. data/spec/spec_helper.rb +2 -26
  76. data/spec/support/controller_hacks.rb +1 -1
  77. data/spree_api.gemspec +1 -1
  78. metadata +19 -15
  79. data/app/models/spree/line_item_decorator.rb +0 -3
  80. data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
  81. data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -5,12 +5,11 @@ module Spree
5
5
  render_views
6
6
  let!(:order) { create(:order) }
7
7
  let!(:payment) { create(:payment, :order => order) }
8
- let!(:attributes) { [:id, :source_type, :source_id, :amount, :display_amount,
8
+ let!(:attributes) { [:id, :source_type, :source_id, :amount,
9
9
  :payment_method_id, :response_code, :state, :avs_response,
10
10
  :created_at, :updated_at] }
11
11
 
12
12
  let(:resource_scoping) { { :order_id => order.to_param } }
13
-
14
13
  before do
15
14
  stub_authentication!
16
15
  end
@@ -44,11 +43,6 @@ module Spree
44
43
  json_response.should have_attributes(attributes)
45
44
  end
46
45
 
47
- it "cannot update a payment" do
48
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
49
- assert_unauthorized!
50
- end
51
-
52
46
  it "cannot authorize a payment" do
53
47
  api_put :authorize, :id => payment.to_param
54
48
  assert_unauthorized!
@@ -99,120 +93,84 @@ module Spree
99
93
  end
100
94
 
101
95
  context "for a given payment" do
102
- context "updating" do
103
- it "can update" do
104
- payment.update_column(:state, 'pending')
105
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
106
- response.status.should == 200
107
- payment.reload.amount.should == 2.01
108
- end
109
96
 
110
- context "update fails" do
111
- it "returns a 422 status when the amount is invalid" do
112
- payment.update_column(:state, 'pending')
113
- api_put :update, :id => payment.to_param, :payment => { :amount => 'invalid' }
114
- response.status.should == 422
115
- json_response["error"].should == "Invalid resource. Please fix errors and try again."
116
- end
117
-
118
- it "returns a 403 status when the payment is not pending" do
119
- payment.update_column(:state, 'complete')
120
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
121
- response.status.should == 403
122
- json_response["error"].should == "This payment cannot be updated because it is complete."
123
- end
124
- end
97
+ it "can authorize" do
98
+ api_put :authorize, :id => payment.to_param
99
+ response.status.should == 200
100
+ payment.reload
101
+ payment.state.should == "pending"
125
102
  end
126
103
 
127
- context "authorizing" do
128
- it "can authorize" do
104
+ context "authorization fails" do
105
+ before do
106
+ fake_response = double(:success? => false, :to_s => "Could not authorize card")
107
+ Spree::Gateway::Bogus.any_instance.should_receive(:authorize).and_return(fake_response)
129
108
  api_put :authorize, :id => payment.to_param
130
- response.status.should == 200
131
- payment.reload.state.should == "pending"
109
+ end
110
+
111
+ it "returns a 422 status" do
112
+ response.status.should == 422
113
+ json_response["error"].should == "There was a problem with the payment gateway: Could not authorize card"
132
114
  end
133
115
 
134
- context "authorization fails" do
135
- before do
136
- fake_response = double(:success? => false, :to_s => "Could not authorize card")
137
- Spree::Gateway::Bogus.any_instance.should_receive(:authorize).and_return(fake_response)
138
- api_put :authorize, :id => payment.to_param
139
- end
140
-
141
- it "returns a 422 status" do
142
- response.status.should == 422
143
- json_response["error"].should == "There was a problem with the payment gateway: Could not authorize card"
144
- end
145
-
146
- it "does not raise a stack level error" do
147
- pending "Investigate why a payment.reload after the request raises 'stack level too deep'"
148
- payment.reload.state.should == "failed"
149
- end
116
+ it "returns a 422 status" do
117
+ pending "Investigate why a payment.reload after the request raises 'stack level too deep'"
118
+ payment.reload
119
+ payment.state.should == "failed"
150
120
  end
151
121
  end
152
122
 
153
- context "capturing" do
154
- it "can capture" do
155
- api_put :capture, :id => payment.to_param
156
- response.status.should == 200
157
- payment.reload.state.should == "completed"
158
- end
123
+ it "can capture" do
124
+ api_put :capture, :id => payment.to_param
125
+ response.status.should == 200
126
+ payment.reload
127
+ payment.state.should == "completed"
128
+ end
159
129
 
160
- context "capturing fails" do
161
- before do
162
- fake_response = double(:success? => false, :to_s => "Insufficient funds")
163
- Spree::Gateway::Bogus.any_instance.should_receive(:capture).and_return(fake_response)
164
- end
165
-
166
- it "returns a 422 status" do
167
- api_put :capture, :id => payment.to_param
168
- response.status.should == 422
169
- json_response["error"].should == "There was a problem with the payment gateway: Insufficient funds"
170
- end
171
- end
130
+ it "returns a 422 status when purchasing fails" do
131
+ fake_response = double(:success? => false, :to_s => "Insufficient funds")
132
+ Spree::Gateway::Bogus.any_instance.should_receive(:capture).and_return(fake_response)
133
+ api_put :capture, :id => payment.to_param
134
+ response.status.should == 422
135
+ json_response["error"].should == "There was a problem with the payment gateway: Insufficient funds"
172
136
  end
173
137
 
174
- context "purchasing" do
175
- it "can purchase" do
176
- api_put :purchase, :id => payment.to_param
177
- response.status.should == 200
178
- payment.reload.state.should == "completed"
179
- end
138
+ it "can purchase" do
139
+ api_put :purchase, :id => payment.to_param
140
+ response.status.should == 200
141
+ payment.reload
142
+ payment.state.should == "completed"
143
+ end
180
144
 
181
- context "purchasing fails" do
182
- before do
183
- fake_response = double(:success? => false, :to_s => "Insufficient funds")
184
- Spree::Gateway::Bogus.any_instance.should_receive(:purchase).and_return(fake_response)
185
- end
186
-
187
- it "returns a 422 status" do
188
- api_put :purchase, :id => payment.to_param
189
- response.status.should == 422
190
- json_response["error"].should == "There was a problem with the payment gateway: Insufficient funds"
191
- end
145
+ context "purchasing fails" do
146
+ before do
147
+ fake_response = double(:success? => false, :to_s => "Insufficient funds")
148
+ Spree::Gateway::Bogus.any_instance.should_receive(:purchase).and_return(fake_response)
192
149
  end
193
- end
194
150
 
195
- context "voiding" do
196
- it "can void" do
197
- api_put :void, :id => payment.to_param
198
- response.status.should == 200
199
- payment.reload.state.should == "void"
151
+ it "returns a 422" do
152
+ api_put :purchase, :id => payment.to_param
153
+ response.status.should == 422
154
+ json_response["error"].should == "There was a problem with the payment gateway: Insufficient funds"
200
155
  end
156
+ end
201
157
 
202
- context "voiding fails" do
203
- before do
204
- fake_response = double(:success? => false, :to_s => "NO REFUNDS")
205
- Spree::Gateway::Bogus.any_instance.should_receive(:void).and_return(fake_response)
206
- end
158
+ it "can void" do
159
+ api_put :void, :id => payment.to_param
160
+ response.status.should == 200
161
+ payment.reload
162
+ payment.state.should == "void"
163
+ end
207
164
 
208
- it "returns a 422 status" do
209
- api_put :void, :id => payment.to_param
210
- response.status.should == 422
211
- json_response["error"].should == "There was a problem with the payment gateway: NO REFUNDS"
165
+ it "returns a 422 status when voiding fails" do
166
+ fake_response = double(:success? => false, :to_s => "NO REFUNDS")
167
+ Spree::Gateway::Bogus.any_instance.should_receive(:void).and_return(fake_response)
168
+ api_put :void, :id => payment.to_param
169
+ response.status.should == 422
170
+ json_response["error"].should == "There was a problem with the payment gateway: NO REFUNDS"
212
171
 
213
- payment.reload.state.should == "checkout"
214
- end
215
- end
172
+ payment.reload
173
+ payment.state.should == "checkout"
216
174
  end
217
175
 
218
176
  context "crediting" do
@@ -223,30 +181,31 @@ module Spree
223
181
  it "can credit" do
224
182
  api_put :credit, :id => payment.to_param
225
183
  response.status.should == 200
226
- payment.reload.state.should == "completed"
184
+ payment.reload
185
+ payment.state.should == "completed"
227
186
 
228
- # Ensure that a credit payment was created, and it has correct credit amount
187
+ # Ensur that a credit payment was created, and it has correct credit amount
229
188
  credit_payment = Payment.where(:source_type => 'Spree::Payment', :source_id => payment.id).last
230
189
  credit_payment.amount.to_f.should == -45.75
231
190
  end
232
191
 
233
- context "crediting fails" do
234
- it "returns a 422 status" do
235
- fake_response = double(:success? => false, :to_s => "NO CREDIT FOR YOU")
236
- Spree::Gateway::Bogus.any_instance.should_receive(:credit).and_return(fake_response)
237
- api_put :credit, :id => payment.to_param
238
- response.status.should == 422
239
- json_response["error"].should == "There was a problem with the payment gateway: NO CREDIT FOR YOU"
240
- end
241
-
242
- it "cannot credit over credit_allowed limit" do
243
- api_put :credit, :id => payment.to_param, :amount => 1000000
244
- response.status.should == 422
245
- json_response["error"].should == "This payment can only be credited up to 45.75. Please specify an amount less than or equal to this number."
246
- end
192
+ it "returns a 422 status when crediting fails" do
193
+ fake_response = double(:success? => false, :to_s => "NO CREDIT FOR YOU")
194
+ Spree::Gateway::Bogus.any_instance.should_receive(:credit).and_return(fake_response)
195
+ api_put :credit, :id => payment.to_param
196
+ response.status.should == 422
197
+ json_response["error"].should == "There was a problem with the payment gateway: NO CREDIT FOR YOU"
198
+ end
199
+
200
+ it "cannot credit over credit_allowed limit" do
201
+ api_put :credit, :id => payment.to_param, :amount => 1000000
202
+ response.status.should == 422
203
+ json_response["error"].should == "This payment can only be credited up to 45.75. Please specify an amount less than or equal to this number."
247
204
  end
248
205
  end
249
206
  end
207
+
250
208
  end
209
+
251
210
  end
252
211
  end
@@ -7,22 +7,7 @@ module Spree
7
7
 
8
8
  let!(:product) { create(:product) }
9
9
  let!(:inactive_product) { create(:product, :available_on => Time.now.tomorrow, :name => "inactive") }
10
- let(:attributes) { [:id, :name, :description, :price, :available_on, :permalink, :meta_description, :meta_keywords, :shipping_category_id, :taxon_ids] }
11
- let(:product_hash) do
12
- { :name => "The Other Product",
13
- :price => 19.99,
14
- :shipping_category_id => create(:shipping_category).id }
15
- end
16
- let(:attributes_for_variant) do
17
- h = attributes_for(:variant).except(:is_master, :product)
18
- h.delete(:option_values)
19
- h.merge({
20
- options: [
21
- { name: "size", value: "small" },
22
- { name: "color", value: "black" }
23
- ]
24
- })
25
- end
10
+ let(:attributes) { [:id, :name, :description, :price, :display_price, :available_on, :permalink, :meta_description, :meta_keywords, :shipping_category_id, :taxon_ids] }
26
11
 
27
12
  before do
28
13
  stub_authentication!
@@ -32,25 +17,16 @@ module Spree
32
17
  it "retrieves a list of products" do
33
18
  api_get :index
34
19
  json_response["products"].first.should have_attributes(attributes)
35
- json_response["count"].should == 1
20
+ json_response["total_count"].should == 1
36
21
  json_response["current_page"].should == 1
37
22
  json_response["pages"].should == 1
23
+ json_response["per_page"].should == Kaminari.config.default_per_page
38
24
  end
39
25
 
40
26
  it "retrieves a list of products by id" do
41
27
  api_get :index, :ids => [product.id]
42
28
  json_response["products"].first.should have_attributes(attributes)
43
- json_response["count"].should == 1
44
- json_response["current_page"].should == 1
45
- json_response["pages"].should == 1
46
- end
47
-
48
- it "retrieves a list of products by ids string" do
49
- second_product = create(:product)
50
- api_get :index, :ids => [product.id, second_product.id].join(",")
51
- json_response["products"].first.should have_attributes(attributes)
52
- json_response["products"][1].should have_attributes(attributes)
53
- json_response["total_count"].should == 2
29
+ json_response["total_count"].should == 1
54
30
  json_response["current_page"].should == 1
55
31
  json_response["pages"].should == 1
56
32
  json_response["per_page"].should == Kaminari.config.default_per_page
@@ -92,13 +68,6 @@ module Spree
92
68
  response.body.should =~ /^callback\(.*\)$/
93
69
  response.header['Content-Type'].should include('application/javascript')
94
70
  end
95
-
96
- # Regression test for #4332
97
- it "does not escape quotes" do
98
- api_get :index, {:callback => 'callback'}
99
- response.body.should =~ /^callback\({"count":1,"total_count":1/
100
- response.header['Content-Type'].should include('application/javascript')
101
- end
102
71
  end
103
72
 
104
73
  it "can search for products" do
@@ -124,7 +93,10 @@ module Spree
124
93
  :attachment_width,
125
94
  :attachment_height,
126
95
  :attachment_content_type,
127
- :attachment_url])
96
+ :mini_url,
97
+ :small_url,
98
+ :product_url,
99
+ :large_url])
128
100
 
129
101
  json_response["product_properties"].first.should have_attributes([:value,
130
102
  :product_id,
@@ -151,14 +123,12 @@ module Spree
151
123
 
152
124
  it "cannot see inactive products" do
153
125
  api_get :show, :id => inactive_product.to_param
154
- json_response["error"].should == "The resource you were looking for could not be found."
155
- response.status.should == 404
126
+ assert_not_found!
156
127
  end
157
128
 
158
129
  it "returns a 404 error when it cannot find a product" do
159
130
  api_get :show, :id => "non-existant"
160
- json_response["error"].should == "The resource you were looking for could not be found."
161
- response.status.should == 404
131
+ assert_not_found!
162
132
  end
163
133
 
164
134
  it "can learn how to create a new product" do
@@ -202,71 +172,13 @@ module Spree
202
172
  end
203
173
 
204
174
  it "can create a new product" do
205
- api_post :create, :product => product_hash
175
+ api_post :create, :product => { :name => "The Other Product",
176
+ :price => 19.99,
177
+ :shipping_category_id => create(:shipping_category).id }
206
178
  json_response.should have_attributes(attributes)
207
179
  response.status.should == 201
208
180
  end
209
181
 
210
- describe "creating products with" do
211
- it "embedded variants" do
212
- product_hash.merge!({
213
- variants_attributes: [
214
- attributes_for_variant,
215
- attributes_for_variant
216
- ]
217
- })
218
-
219
- api_post :create, :product => product_hash
220
- expect(response.status).to eq 201
221
-
222
- variants = json_response['variants'].select { |v| !v['is_master'] }
223
- expect(variants.first['option_values'][0]['name']).to eq('small')
224
- expect(variants.first['option_values'][0]['option_type_name']).to eq('size')
225
-
226
- expect(json_response['option_types'].count).to eq(2) # size, color
227
- end
228
-
229
- it "embedded product_properties" do
230
- product_hash.merge!({
231
- shipping_category_id: 1,
232
-
233
- product_properties_attributes: [{
234
- property_name: "fabric",
235
- value: "cotton"
236
- }]
237
- })
238
-
239
- api_post :create, :product => product_hash
240
-
241
- expect(json_response['product_properties'][0]['property_name']).to eq('fabric')
242
- expect(json_response['product_properties'][0]['value']).to eq('cotton')
243
- end
244
-
245
- it "option_types even if without variants" do
246
- product_hash.merge!({
247
- shipping_category_id: 1,
248
-
249
- option_types: ['size', 'color']
250
- })
251
-
252
- api_post :create, :product => product_hash
253
-
254
- expect(json_response['option_types'].count).to eq(2)
255
- end
256
-
257
- it "creates with shipping categories" do
258
- hash = { :name => "The Other Product",
259
- :price => 19.99,
260
- :shipping_category => "Free Ships" }
261
-
262
- api_post :create, :product => hash
263
- expect(response.status).to eq 201
264
-
265
- shipping_id = ShippingCategory.find_by_name("Free Ships").id
266
- expect(json_response['shipping_category_id']).to eq shipping_id
267
- end
268
- end
269
-
270
182
  # Regression test for #2140
271
183
  context "with authentication_required set to false" do
272
184
  before do
@@ -301,13 +213,6 @@ module Spree
301
213
  response.status.should == 200
302
214
  end
303
215
 
304
- it "updates shipping category properly if provided" do
305
- api_put :update, :id => product.to_param, :product => { :shipping_category => "New Ships" }
306
- expect(response.status).to eq 200
307
- shipping_id = ShippingCategory.find_by_name("New Ships").id
308
- expect(json_response['shipping_category_id']).to eq shipping_id
309
- end
310
-
311
216
  it "cannot update a product with an invalid attribute" do
312
217
  api_put :update, :id => product.to_param, :product => { :name => "" }
313
218
  response.status.should == 422
@@ -321,41 +226,6 @@ module Spree
321
226
  response.status.should == 204
322
227
  product.reload.deleted_at.should_not be_nil
323
228
  end
324
-
325
- describe "updating products with" do
326
- it "embedded option types" do
327
- api_put :update, :id => product.to_param, :product => { :option_types => ['shape', 'color'] }
328
- json_response['option_types'].count.should eq(2)
329
- end
330
-
331
- it "new variants" do
332
- api_put :update, :id => product.to_param, :product => { :variants_attributes => [attributes_for_variant, attributes_for_variant] }
333
- response.status.should == 200
334
- json_response['variants'].count.should == 3 # 1 master + 2 variants
335
-
336
- variants = json_response['variants'].select { |v| !v['is_master'] }
337
- variants.last['option_values'][0]['name'].should == 'small'
338
- variants.last['option_values'][0]['option_type_name'].should == 'size'
339
-
340
- json_response['option_types'].count.should == 2 # size, color
341
- end
342
-
343
- it "updating an existing variant" do
344
- variant_hash = {
345
- :sku => '123', :price => 19.99, :options => [{:name => "size", :value => "small"}]
346
- }
347
- variant = product.variants.new
348
- variant.update_attributes(variant_hash)
349
-
350
- api_put :update, :id => product.to_param, :product => { :variants_attributes => [variant_hash.merge(:id => variant.id.to_s, :sku => '456', :options => [{:name => "size", :value => "large" }])] }
351
-
352
- json_response['variants'].count.should == 2 # 1 master + 2 variants
353
- variants = json_response['variants'].select { |v| !v['is_master'] }
354
- variants.last['option_values'][0]['name'].should == 'large'
355
- variants.last['sku'].should == '456'
356
- variants.count.should == 1
357
- end
358
- end
359
229
  end
360
230
  end
361
231
  end
@@ -41,27 +41,12 @@ module Spree
41
41
 
42
42
  it "cannot update a return authorization" do
43
43
  api_put :update
44
- assert_unauthorized!
45
- end
46
-
47
- it "cannot add a variant to a return authorization" do
48
- api_put :add
49
- assert_unauthorized!
50
- end
51
-
52
- it "cannot mark a return authorization as received" do
53
- api_put :receive
54
- assert_unauthorized!
55
- end
56
-
57
- it "cannot cancel a return authorization" do
58
- api_put :cancel
59
- assert_unauthorized!
44
+ assert_not_found!
60
45
  end
61
46
 
62
47
  it "cannot delete a return authorization" do
63
48
  api_delete :destroy
64
- assert_unauthorized!
49
+ assert_not_found!
65
50
  end
66
51
  end
67
52
 
@@ -133,7 +118,7 @@ module Spree
133
118
  end
134
119
 
135
120
  it "can mark a return authorization as received on the order with an inventory unit" do
136
- FactoryGirl.create(:new_return_authorization, :order => order, :stock_location_id => order.shipments.first.stock_location.id)
121
+ FactoryGirl.create(:new_return_authorization, :order => order)
137
122
  return_authorization = order.return_authorizations.first
138
123
  return_authorization.state.should == "authorized"
139
124
 
@@ -176,7 +161,7 @@ module Spree
176
161
  end
177
162
 
178
163
  it "can add a new return authorization to an existing order" do
179
- api_post :create, :return_autorization => { :order_id => order.number, :amount => 14.22, :reason => "Defective" }
164
+ api_post :create, :order_id => order.number, :return_authorization => { :amount => 14.22, :reason => "Defective" }
180
165
  response.status.should == 201
181
166
  json_response.should have_attributes(attributes)
182
167
  json_response["state"].should_not be_blank
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Spree::Api::ShipmentsController do
4
4
  render_views
5
5
  let!(:shipment) { create(:shipment) }
6
- let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_method, :inventory_units] }
6
+ let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
7
7
 
8
8
  before do
9
9
  stub_authentication!
@@ -96,7 +96,7 @@ describe Spree::Api::ShipmentsController do
96
96
  it 'adds a variant to a shipment' do
97
97
  api_put :add, { variant_id: variant.to_param, quantity: 2 }
98
98
  response.status.should == 200
99
- json_response['inventory_units'].select { |h| h['variant_id'] == variant.id }.size.should == 2
99
+ json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 2
100
100
  end
101
101
 
102
102
  it 'removes a variant from a shipment' do
@@ -104,7 +104,7 @@ describe Spree::Api::ShipmentsController do
104
104
 
105
105
  api_put :remove, { variant_id: variant.to_param, quantity: 1 }
106
106
  response.status.should == 200
107
- json_response['inventory_units'].select { |h| h['variant_id'] == variant.id }.size.should == 1
107
+ json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
108
108
  end
109
109
  end
110
110
 
@@ -19,7 +19,7 @@ module Spree
19
19
 
20
20
  context "pagination" do
21
21
  before do
22
- State.should_receive(:scoped).and_return(@scope = double)
22
+ State.should_receive(:accessible_by).and_return(@scope = double)
23
23
  @scope.stub_chain(:ransack, :result, :includes, :order).and_return(@scope)
24
24
  end
25
25