solidus_api 2.8.5 → 2.8.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2599ecc3468198cbb624826230a1f3f9ed602714aa449bb7035a0ab2b7ddf202
4
- data.tar.gz: 4bca9448d94cb75e435cba18db8a63ee00dc73cca44491c16020c63c2736b4f5
3
+ metadata.gz: 04c64c177896dab37dae312ae08fd93f1c044ea416ad2ca7184dde05a5faeb5c
4
+ data.tar.gz: cb6b60e062b48cb68fd5e73172015877ffe3ee84ebbb58b56ee58cf5844610df
5
5
  SHA512:
6
- metadata.gz: 50fb3ff7327ec8636525dee71e728f50730d36792c96717ff603e844aa4e775d9cf3fc63ed22438b5d13f23d0f6aa1bd21bbddfbfd488f8c5b1f575c4ad058c1
7
- data.tar.gz: 75aa7aab776b16f883ef76eb45d421f3c1766eeff1f6a213376b086de69ce3af75950e2ffed0a177f20b66945b9ba05e53aca86eae0fa6d4c54db0b91a546676
6
+ metadata.gz: c2d2e3c4df97047d23b464b722bc32d6efee403aba8f80891d31e896e15ccfd050a419329855209e31843cfc19283661cd6845857320d989edf718a6455a3223
7
+ data.tar.gz: 521dc0e421fda8eb0bc9ef9dc7f029800bca98bae82889dee2cabe4a8d242341a285e528db58eed8613d41f5648fe0910f9593ad5505071a475f6cec7bab36c6
@@ -76,11 +76,24 @@ module Spree
76
76
  end
77
77
 
78
78
  def update_params
79
- if update_params = massaged_params[:order]
80
- update_params.permit(permitted_checkout_attributes)
79
+ state = @order.state
80
+ case state.to_sym
81
+ when :cart, :address
82
+ massaged_params.fetch(:order, {}).permit(
83
+ permitted_checkout_address_attributes
84
+ )
85
+ when :delivery
86
+ massaged_params.require(:order).permit(
87
+ permitted_checkout_delivery_attributes
88
+ )
89
+ when :payment
90
+ massaged_params.require(:order).permit(
91
+ permitted_checkout_payment_attributes
92
+ )
81
93
  else
82
- # We current allow update requests without any parameters in them.
83
- {}
94
+ massaged_params.fetch(:order, {}).permit(
95
+ permitted_checkout_confirm_attributes
96
+ )
84
97
  end
85
98
  end
86
99
 
@@ -128,7 +128,13 @@ module Spree
128
128
  end
129
129
 
130
130
  def normalize_params
131
- params[:order][:payments_attributes] = params[:order].delete(:payments) if params[:order][:payments]
131
+ if params[:order][:payments]
132
+ payments_params = params[:order].delete(:payments)
133
+ params[:order][:payments_attributes] = payments_params.map do |payment_params|
134
+ payment_params[:source_attributes] = payment_params.delete(:source) if payment_params[:source].present?
135
+ payment_params
136
+ end
137
+ end
132
138
  params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]
133
139
  params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]
134
140
  params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address].present?
@@ -176,6 +176,7 @@ module Spree
176
176
  end
177
177
 
178
178
  describe 'setting the payment amount' do
179
+ let(:order) { create(:order_with_line_items, state: :payment) }
179
180
  let(:params) do
180
181
  {
181
182
  order_token: order.guest_token,
@@ -326,17 +327,44 @@ module Spree
326
327
  end
327
328
  end
328
329
 
330
+ it "cannot update attributes of another step" do
331
+ order.update_column(:state, "payment")
332
+
333
+ params = {
334
+ order_token: order.guest_token,
335
+ order: {
336
+ payments_attributes: [
337
+ {
338
+ payment_method_id: @payment_method.id.to_s,
339
+ source_attributes: attributes_for(:credit_card)
340
+ }
341
+ ],
342
+ ship_address_attributes: {
343
+ zipcode: 'MALICIOUS ZIPCODE'
344
+ }
345
+ }
346
+ }
347
+ expect do
348
+ put spree.api_checkout_path(order), params: params
349
+ end.not_to change { order.reload.ship_address.zipcode }
350
+ expect(response.status).to eq(200)
351
+ end
352
+
329
353
  it "returns the order if the order is already complete" do
330
354
  order.update_columns(completed_at: Time.current, state: 'complete')
331
355
  put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
332
356
  assert_unauthorized!
333
357
  end
334
358
 
335
- # Regression test for https://github.com/spree/spree/issues/3784
336
- it "can update the special instructions for an order" do
337
- instructions = "Don't drop it. (Please)"
338
- put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
339
- expect(json_response['special_instructions']).to eql(instructions)
359
+ context "in delivery state" do
360
+ let(:order) { create(:order_with_line_items, state: :delivery) }
361
+
362
+ # Regression test for https://github.com/spree/spree/issues/3784
363
+ it "can update the special instructions for an order" do
364
+ instructions = "Don't drop it. (Please)"
365
+ put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
366
+ expect(json_response['special_instructions']).to eql(instructions)
367
+ end
340
368
  end
341
369
 
342
370
  context "as an admin" do
@@ -156,6 +156,7 @@ module Spree
156
156
  end
157
157
 
158
158
  context 'creating payment' do
159
+ let!(:order) { create(:order_with_line_items) }
159
160
  let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
160
161
 
161
162
  context "with allowed payment method" do
@@ -166,6 +167,28 @@ module Spree
166
167
  subject
167
168
  }.to change { Spree::Payment.count }.by(1)
168
169
  end
170
+
171
+ context 'trying to change the address' do
172
+ let(:order_params) do
173
+ super().merge(
174
+ ship_address_attributes: {
175
+ zipcode: '90100'
176
+ }
177
+ )
178
+ end
179
+
180
+ it 'changes the address' do
181
+ expect {
182
+ subject
183
+ }.to change { order.reload.ship_address.zipcode }
184
+ end
185
+
186
+ it 'invalidates the shipments' do
187
+ expect {
188
+ subject
189
+ }.to change { order.reload.shipments }.to([])
190
+ end
191
+ end
169
192
  end
170
193
 
171
194
  context "with disallowed payment method" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.5
4
+ version: 2.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2020-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.8.5
61
+ version: 2.8.6
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.8.5
68
+ version: 2.8.6
69
69
  description: REST API for the Solidus e-commerce framework.
70
70
  email: contact@solidus.io
71
71
  executables: []
@@ -309,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
309
  - !ruby/object:Gem::Version
310
310
  version: 1.8.23
311
311
  requirements: []
312
- rubygems_version: 3.0.6
312
+ rubygems_version: 3.0.3
313
313
  signing_key:
314
314
  specification_version: 4
315
315
  summary: REST API for the Solidus e-commerce framework.