spree_api 2.4.2 → 2.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/checkouts_controller.rb +7 -2
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +1 -1
- data/config/routes.rb +1 -1
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +81 -68
- data/spec/controllers/spree/api/classifications_controller_spec.rb +16 -6
- data/spec/controllers/spree/api/stores_controller_spec.rb +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0baeb34a841cbeec0a8b478e5412b14747e28433
|
4
|
+
data.tar.gz: 26e9a4951c2d5875a51bd4c3454c2b64b152116b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cb502eefc6a43572559fee484fba1bd6f880d3d2d7bc8c835c63ad6685700adbd71b5f6002ff9cd011b450f682f8cfa44d1c702b1262d3e2e3dff55b57ce4a
|
7
|
+
data.tar.gz: d5f37aebf55c5d8efacdd9f6221cc67e0822e1d7201ed85c0229c85387f56e49ef4f092bcf54aa3d2a6f7b915ad76509db4a2de24720bab7950d3b69f32cc4b8
|
@@ -34,8 +34,13 @@ module Spree
|
|
34
34
|
end
|
35
35
|
|
36
36
|
return if after_update_attributes
|
37
|
-
|
38
|
-
|
37
|
+
|
38
|
+
if @order.next || @order.completed?
|
39
|
+
state_callback(:after)
|
40
|
+
respond_with(@order, default_template: 'spree/api/orders/show')
|
41
|
+
else
|
42
|
+
respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
|
43
|
+
end
|
39
44
|
else
|
40
45
|
invalid_resource!(@order)
|
41
46
|
end
|
data/config/routes.rb
CHANGED
@@ -62,7 +62,7 @@ Spree::Core::Engine.add_routes do
|
|
62
62
|
end
|
63
63
|
|
64
64
|
get '/orders/mine', to: 'orders#mine', as: 'my_orders'
|
65
|
-
get "/orders/current", to: "orders#current",
|
65
|
+
get "/orders/current", to: "orders#current", as: "current_order"
|
66
66
|
|
67
67
|
resources :orders, concerns: :order_routes
|
68
68
|
|
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::CheckoutsController, :
|
4
|
+
describe Api::CheckoutsController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before(:each) do
|
8
8
|
stub_authentication!
|
9
9
|
Spree::Config[:track_inventory_levels] = false
|
10
|
-
country_zone = create(:zone, :
|
10
|
+
country_zone = create(:zone, name: 'CountryZone')
|
11
11
|
@state = create(:state)
|
12
12
|
@country = @state.country
|
13
|
-
country_zone.members.create(:
|
13
|
+
country_zone.members.create(zoneable: @country)
|
14
14
|
create(:stock_location)
|
15
15
|
|
16
|
-
@shipping_method = create(:shipping_method, :
|
16
|
+
@shipping_method = create(:shipping_method, zones: [country_zone])
|
17
17
|
@payment_method = create(:credit_card_payment_method)
|
18
18
|
end
|
19
19
|
|
@@ -31,14 +31,14 @@ module Spree
|
|
31
31
|
end
|
32
32
|
|
33
33
|
before(:each) do
|
34
|
-
allow_any_instance_of(Order).to receive_messages(
|
35
|
-
allow_any_instance_of(Order).to receive_messages(
|
34
|
+
allow_any_instance_of(Order).to receive_messages(confirmation_required?: true)
|
35
|
+
allow_any_instance_of(Order).to receive_messages(payment_required?: true)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should transition a recently created order from cart to address" do
|
39
39
|
expect(order.state).to eq "cart"
|
40
40
|
expect(order.email).not_to be_nil
|
41
|
-
api_put :update, :
|
41
|
+
api_put :update, id: order.to_param, order_token: order.guest_token
|
42
42
|
expect(order.reload.state).to eq "address"
|
43
43
|
end
|
44
44
|
|
@@ -52,16 +52,16 @@ module Spree
|
|
52
52
|
|
53
53
|
it "can take line_items_attributes as a parameter" do
|
54
54
|
line_item = order.line_items.first
|
55
|
-
api_put :update, :
|
56
|
-
:
|
55
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
56
|
+
order: { line_items_attributes: { 0 => { id: line_item.id, quantity: 1 } } }
|
57
57
|
expect(response.status).to eq(200)
|
58
58
|
expect(order.reload.state).to 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
|
-
api_put :update, :
|
64
|
-
:
|
63
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
64
|
+
order: { line_items: { 0 => { id: line_item.id, quantity: 1 } } }
|
65
65
|
expect(response.status).to eq(200)
|
66
66
|
expect(order.reload.state).to eq "address"
|
67
67
|
end
|
@@ -71,7 +71,7 @@ module Spree
|
|
71
71
|
order.bill_address = nil
|
72
72
|
order.save
|
73
73
|
order.update_column(:state, "address")
|
74
|
-
api_put :update, :
|
74
|
+
api_put :update, id: order.to_param, order_token: order.guest_token
|
75
75
|
# Order has not transitioned
|
76
76
|
expect(response.status).to eq(422)
|
77
77
|
end
|
@@ -83,38 +83,51 @@ module Spree
|
|
83
83
|
|
84
84
|
let(:address) do
|
85
85
|
{
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
93
|
-
:
|
86
|
+
firstname: 'John',
|
87
|
+
lastname: 'Doe',
|
88
|
+
address1: '7735 Old Georgetown Road',
|
89
|
+
city: 'Bethesda',
|
90
|
+
phone: '3014445002',
|
91
|
+
zipcode: '20814',
|
92
|
+
state_id: @state.id,
|
93
|
+
country_id: @country.id
|
94
94
|
}
|
95
95
|
end
|
96
96
|
|
97
97
|
it "can update addresses and transition from address to delivery" do
|
98
98
|
api_put :update,
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
id: order.to_param, order_token: order.guest_token,
|
100
|
+
order: {
|
101
|
+
bill_address_attributes: address,
|
102
|
+
ship_address_attributes: address
|
103
|
+
}
|
104
104
|
expect(json_response['state']).to eq('delivery')
|
105
105
|
expect(json_response['bill_address']['firstname']).to eq('John')
|
106
106
|
expect(json_response['ship_address']['firstname']).to eq('John')
|
107
107
|
expect(response.status).to eq(200)
|
108
108
|
end
|
109
109
|
|
110
|
+
# Regression Spec for #5389 & #5880
|
111
|
+
it "can update addresses but not transition to delivery w/o shipping setup" do
|
112
|
+
Spree::ShippingMethod.destroy_all
|
113
|
+
api_put :update,
|
114
|
+
id: order.to_param, order_token: order.guest_token,
|
115
|
+
order: {
|
116
|
+
bill_address_attributes: address,
|
117
|
+
ship_address_attributes: address
|
118
|
+
}
|
119
|
+
expect(json_response['error']).to eq(I18n.t(:could_not_transition, scope: "spree.api.order"))
|
120
|
+
expect(response.status).to eq(422)
|
121
|
+
end
|
122
|
+
|
110
123
|
# Regression test for #4498
|
111
124
|
it "does not contain duplicate variant data in delivery return" do
|
112
125
|
api_put :update,
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
126
|
+
id: order.to_param, order_token: order.guest_token,
|
127
|
+
order: {
|
128
|
+
bill_address_attributes: address,
|
129
|
+
ship_address_attributes: address
|
130
|
+
}
|
118
131
|
# Shipments manifests should not return the ENTIRE variant
|
119
132
|
# This information is already present within the order's line items
|
120
133
|
expect(json_response['shipments'].first['manifest'].first['variant']).to be_nil
|
@@ -124,11 +137,11 @@ module Spree
|
|
124
137
|
|
125
138
|
it "can update shipping method and transition from delivery to payment" do
|
126
139
|
order.update_column(:state, "delivery")
|
127
|
-
shipment = create(:shipment, :
|
140
|
+
shipment = create(:shipment, order: order)
|
128
141
|
shipment.refresh_rates
|
129
|
-
shipping_rate = shipment.shipping_rates.where(:
|
130
|
-
api_put :update, :
|
131
|
-
:
|
142
|
+
shipping_rate = shipment.shipping_rates.where(selected: false).first
|
143
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
144
|
+
order: { shipments_attributes: { "0" => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } }
|
132
145
|
expect(response.status).to eq(200)
|
133
146
|
# Find the correct shipment...
|
134
147
|
json_shipment = json_response['shipments'].detect { |s| s["id"] == shipment.id }
|
@@ -142,8 +155,8 @@ module Spree
|
|
142
155
|
|
143
156
|
it "can update payment method and transition from payment to confirm" do
|
144
157
|
order.update_column(:state, "payment")
|
145
|
-
api_put :update, :
|
146
|
-
:
|
158
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
159
|
+
order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
|
147
160
|
expect(json_response['state']).to eq('confirm')
|
148
161
|
expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
|
149
162
|
expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
|
@@ -153,16 +166,16 @@ module Spree
|
|
153
166
|
it "can update payment method with source and transition from payment to confirm" do
|
154
167
|
order.update_column(:state, "payment")
|
155
168
|
source_attributes = {
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
169
|
+
number: "4111111111111111",
|
170
|
+
month: 1.month.from_now.month,
|
171
|
+
year: 1.month.from_now.year,
|
172
|
+
verification_value: "123",
|
173
|
+
name: "Spree Commerce"
|
161
174
|
}
|
162
175
|
|
163
|
-
api_put :update, :
|
164
|
-
:
|
165
|
-
:
|
176
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
177
|
+
order: { payments_attributes: [{ payment_method_id: @payment_method.id.to_s }],
|
178
|
+
payment_source: { @payment_method.id.to_s => source_attributes } }
|
166
179
|
expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
|
167
180
|
expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
|
168
181
|
expect(response.status).to eq(200)
|
@@ -170,11 +183,11 @@ module Spree
|
|
170
183
|
|
171
184
|
it "returns errors when source is missing attributes" do
|
172
185
|
order.update_column(:state, "payment")
|
173
|
-
api_put :update, :
|
174
|
-
:
|
175
|
-
:
|
186
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
187
|
+
order: {
|
188
|
+
payments_attributes: [{ payment_method_id: @payment_method.id }]
|
176
189
|
},
|
177
|
-
:
|
190
|
+
payment_source: {
|
178
191
|
@payment_method.id.to_s => { name: "Spree" }
|
179
192
|
}
|
180
193
|
|
@@ -190,24 +203,24 @@ module Spree
|
|
190
203
|
order.update_column(:state, "payment")
|
191
204
|
credit_card = create(:credit_card, user_id: order.user_id, payment_method_id: @payment_method.id)
|
192
205
|
|
193
|
-
api_put :update, :
|
194
|
-
:
|
206
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
207
|
+
order: { existing_card: credit_card.id }
|
195
208
|
|
196
209
|
expect(response.status).to eq 200
|
197
210
|
expect(order.credit_cards).to match_array [credit_card]
|
198
211
|
end
|
199
212
|
|
200
213
|
it "can transition from confirm to complete" do
|
201
|
-
order.
|
202
|
-
allow_any_instance_of(Spree::Order).to receive_messages(
|
203
|
-
api_put :update, :
|
214
|
+
order.update_columns(completed_at: Time.now, state: 'complete')
|
215
|
+
allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)
|
216
|
+
api_put :update, id: order.to_param, order_token: order.guest_token
|
204
217
|
expect(json_response['state']).to eq('complete')
|
205
218
|
expect(response.status).to eq(200)
|
206
219
|
end
|
207
220
|
|
208
221
|
it "returns the order if the order is already complete" do
|
209
|
-
order.
|
210
|
-
api_put :update, :
|
222
|
+
order.update_columns(completed_at: Time.now, state: 'complete')
|
223
|
+
api_put :update, id: order.to_param, order_token: order.guest_token
|
211
224
|
expect(json_response['number']).to eq(order.number)
|
212
225
|
expect(response.status).to eq(200)
|
213
226
|
end
|
@@ -215,8 +228,8 @@ module Spree
|
|
215
228
|
# Regression test for #3784
|
216
229
|
it "can update the special instructions for an order" do
|
217
230
|
instructions = "Don't drop it. (Please)"
|
218
|
-
api_put :update, :
|
219
|
-
:
|
231
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
232
|
+
order: { special_instructions: instructions }
|
220
233
|
expect(json_response['special_instructions']).to eql(instructions)
|
221
234
|
end
|
222
235
|
|
@@ -225,16 +238,16 @@ module Spree
|
|
225
238
|
it "can assign a user to the order" do
|
226
239
|
user = create(:user)
|
227
240
|
# Need to pass email as well so that validations succeed
|
228
|
-
api_put :update, :
|
229
|
-
:
|
241
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
242
|
+
order: { user_id: user.id, email: "guest@spreecommerce.com" }
|
230
243
|
expect(response.status).to eq(200)
|
231
244
|
expect(json_response['user_id']).to eq(user.id)
|
232
245
|
end
|
233
246
|
end
|
234
247
|
|
235
248
|
it "can assign an email to the order" do
|
236
|
-
api_put :update, :
|
237
|
-
:
|
249
|
+
api_put :update, id: order.to_param, order_token: order.guest_token,
|
250
|
+
order: { email: "guest@spreecommerce.com" }
|
238
251
|
expect(json_response['email']).to eq("guest@spreecommerce.com")
|
239
252
|
expect(response.status).to eq(200)
|
240
253
|
end
|
@@ -244,8 +257,8 @@ module Spree
|
|
244
257
|
|
245
258
|
order.update_column(:state, "payment")
|
246
259
|
expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
|
247
|
-
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({
|
248
|
-
api_put :update, :id => order.to_param, :
|
260
|
+
expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
|
261
|
+
api_put :update, :id => order.to_param, order_token: order.guest_token, order: { coupon_code: "foobar" }
|
249
262
|
end
|
250
263
|
end
|
251
264
|
|
@@ -254,7 +267,7 @@ module Spree
|
|
254
267
|
it "cannot transition to address without a line item" do
|
255
268
|
order.line_items.delete_all
|
256
269
|
order.update_column(:email, "spree@example.com")
|
257
|
-
api_put :next, :
|
270
|
+
api_put :next, id: order.to_param, order_token: order.guest_token
|
258
271
|
expect(response.status).to eq(422)
|
259
272
|
expect(json_response["errors"]["base"]).to include(Spree.t(:there_are_no_items_for_this_order))
|
260
273
|
end
|
@@ -262,7 +275,7 @@ module Spree
|
|
262
275
|
it "can transition an order to the next state" do
|
263
276
|
order.update_column(:email, "spree@example.com")
|
264
277
|
|
265
|
-
api_put :next, :
|
278
|
+
api_put :next, id: order.to_param, order_token: order.guest_token
|
266
279
|
expect(response.status).to eq(200)
|
267
280
|
expect(json_response['state']).to eq('address')
|
268
281
|
end
|
@@ -280,7 +293,7 @@ module Spree
|
|
280
293
|
|
281
294
|
it "doesnt advance payment state if order has no payment" do
|
282
295
|
order.update_column(:state, "payment")
|
283
|
-
api_put :next, :
|
296
|
+
api_put :next, id: order.to_param, order_token: order.guest_token, order: {}
|
284
297
|
expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
|
285
298
|
end
|
286
299
|
end
|
@@ -290,11 +303,11 @@ module Spree
|
|
290
303
|
|
291
304
|
it 'continues to advance advances an order while it can move forward' do
|
292
305
|
expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
|
293
|
-
api_put :advance, :
|
306
|
+
api_put :advance, id: order.to_param, order_token: order.guest_token
|
294
307
|
end
|
295
308
|
|
296
309
|
it 'returns the order' do
|
297
|
-
api_put :advance, :
|
310
|
+
api_put :advance, id: order.to_param, order_token: order.guest_token
|
298
311
|
expect(json_response['id']).to eq(order.id)
|
299
312
|
end
|
300
313
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ClassificationsController, :
|
4
|
+
describe Api::ClassificationsController, type: :controller do
|
5
5
|
let(:taxon) do
|
6
6
|
taxon = create(:taxon)
|
7
|
+
|
7
8
|
3.times do
|
8
9
|
product = create(:product)
|
9
10
|
product.taxons << taxon
|
@@ -17,7 +18,7 @@ module Spree
|
|
17
18
|
|
18
19
|
context "as a user" do
|
19
20
|
it "cannot change the order of a product" do
|
20
|
-
api_put :update, :
|
21
|
+
api_put :update, taxon_id: taxon, product_id: taxon.products.first, position: 1
|
21
22
|
expect(response.status).to eq(401)
|
22
23
|
end
|
23
24
|
end
|
@@ -25,14 +26,23 @@ module Spree
|
|
25
26
|
context "as an admin" do
|
26
27
|
sign_in_as_admin!
|
27
28
|
|
29
|
+
let(:last_product) { taxon.products.last }
|
30
|
+
|
28
31
|
it "can change the order a product" do
|
29
|
-
|
30
|
-
classification = taxon.classifications.find_by(:product_id => last_product.id)
|
32
|
+
classification = taxon.classifications.find_by(product_id: last_product.id)
|
31
33
|
expect(classification.position).to eq(3)
|
32
|
-
api_put :update, :
|
34
|
+
api_put :update, taxon_id: taxon, product_id: last_product, position: 0
|
33
35
|
expect(response.status).to eq(200)
|
34
36
|
expect(classification.reload.position).to eq(1)
|
35
37
|
end
|
38
|
+
|
39
|
+
it "should touch the taxon" do
|
40
|
+
taxon.update_attributes(updated_at: Time.now - 10.seconds)
|
41
|
+
taxon_last_updated_at = taxon.updated_at
|
42
|
+
api_put :update, taxon_id: taxon, product_id: last_product, position: 0
|
43
|
+
taxon.reload
|
44
|
+
expect(taxon_last_updated_at.to_i).to_not eq(taxon.updated_at.to_i)
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
|
-
end
|
48
|
+
end
|
@@ -35,7 +35,7 @@ module Spree
|
|
35
35
|
"seo_title" => nil,
|
36
36
|
"mail_from_address" => "spree@example.org",
|
37
37
|
"default_currency" => nil,
|
38
|
-
"code" =>
|
38
|
+
"code" => store.code,
|
39
39
|
"default" => true
|
40
40
|
},
|
41
41
|
{
|
@@ -47,7 +47,7 @@ module Spree
|
|
47
47
|
"seo_title" => nil,
|
48
48
|
"mail_from_address" => "spree@example.org",
|
49
49
|
"default_currency" => nil,
|
50
|
-
"code" =>
|
50
|
+
"code" => non_default_store.code,
|
51
51
|
"default" => false
|
52
52
|
}
|
53
53
|
])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bigg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.4.
|
19
|
+
version: 2.4.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.4.
|
26
|
+
version: 2.4.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -266,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
266
|
version: '0'
|
267
267
|
requirements: []
|
268
268
|
rubyforge_project:
|
269
|
-
rubygems_version: 2.
|
269
|
+
rubygems_version: 2.4.5
|
270
270
|
signing_key:
|
271
271
|
specification_version: 4
|
272
272
|
summary: Spree's API
|