solidus_core 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_core might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/models/spree/order.rb +17 -0
- data/app/models/spree/order_update_attributes.rb +2 -0
- data/app/models/spree/payment.rb +1 -0
- data/lib/spree/core/version.rb +1 -1
- data/spec/models/spree/order_spec.rb +52 -0
- data/spec/models/spree/order_update_attributes_spec.rb +5 -1
- data/spec/models/spree/payment_spec.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfbaab05af3945cfa3851f30385796b958081539
|
4
|
+
data.tar.gz: 0ce9487cd7d65d53c29a521604e88f1c7c2cccee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ded1d464481cb7560a968170df60ee2b4fb7f41cd5f5270cac8459aa65d987cf74aca0f6bb0089235669db0fc40109080249178316c2d596a5c094f5409a815f
|
7
|
+
data.tar.gz: a1b690aed55aea7da4e8f7d20147479f966ea1d36953a85bed3ab91307443c6b1aa40a3152f4be8ac3719c3af6c0aa2d31e7bedd2548e178c05364bfede90faa
|
data/app/models/spree/order.rb
CHANGED
@@ -759,6 +759,23 @@ module Spree
|
|
759
759
|
end
|
760
760
|
end
|
761
761
|
|
762
|
+
def payments_attributes=(attributes)
|
763
|
+
validate_payments_attributes(attributes)
|
764
|
+
super(attributes)
|
765
|
+
end
|
766
|
+
|
767
|
+
def validate_payments_attributes(attributes)
|
768
|
+
attributes = Array(attributes)
|
769
|
+
# Ensure the payment methods specified are allowed for this user
|
770
|
+
payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
|
771
|
+
attributes.each do |payment_attributes|
|
772
|
+
payment_method_id = payment_attributes[:payment_method_id]
|
773
|
+
|
774
|
+
# raise RecordNotFound unless it is an allowed payment method
|
775
|
+
payment_methods.find(payment_method_id) if payment_method_id
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
762
779
|
private
|
763
780
|
|
764
781
|
def process_payments_before_complete
|
@@ -14,6 +14,8 @@ module Spree
|
|
14
14
|
# Assign the attributes to the order and save the order
|
15
15
|
# @return true if saved, otherwise false and errors will be set on the order
|
16
16
|
def apply
|
17
|
+
order.validate_payments_attributes(@payments_attributes)
|
18
|
+
|
17
19
|
assign_order_attributes
|
18
20
|
assign_payments_attributes
|
19
21
|
|
data/app/models/spree/payment.rb
CHANGED
data/lib/spree/core/version.rb
CHANGED
@@ -1548,4 +1548,56 @@ RSpec.describe Spree::Order, type: :model do
|
|
1548
1548
|
subject.update_params_payment_source
|
1549
1549
|
end
|
1550
1550
|
end
|
1551
|
+
|
1552
|
+
describe "#validate_payments_attributes" do
|
1553
|
+
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
1554
|
+
subject do
|
1555
|
+
order.validate_payments_attributes(attributes)
|
1556
|
+
end
|
1557
|
+
|
1558
|
+
context "with empty array" do
|
1559
|
+
let(:attributes) { [] }
|
1560
|
+
it "doesn't error" do
|
1561
|
+
subject
|
1562
|
+
end
|
1563
|
+
end
|
1564
|
+
|
1565
|
+
context "with no payment method specified" do
|
1566
|
+
let(:attributes) { [ActionController::Parameters.new({})] }
|
1567
|
+
it "doesn't error" do
|
1568
|
+
subject
|
1569
|
+
end
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
context "with valid payment method" do
|
1573
|
+
let(:payment_method) { create(:check_payment_method) }
|
1574
|
+
it "doesn't error" do
|
1575
|
+
subject
|
1576
|
+
end
|
1577
|
+
end
|
1578
|
+
|
1579
|
+
context "with inactive payment method" do
|
1580
|
+
let(:payment_method) { create(:check_payment_method, active: false) }
|
1581
|
+
|
1582
|
+
it "raises RecordNotFound" do
|
1583
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1584
|
+
end
|
1585
|
+
end
|
1586
|
+
|
1587
|
+
context "with unavailable payment method" do
|
1588
|
+
let(:payment_method) { create(:check_payment_method, available_to_users: false) }
|
1589
|
+
|
1590
|
+
it "raises RecordNotFound" do
|
1591
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1592
|
+
end
|
1593
|
+
end
|
1594
|
+
|
1595
|
+
context "with soft-deleted payment method" do
|
1596
|
+
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
1597
|
+
|
1598
|
+
it "raises RecordNotFound" do
|
1599
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1600
|
+
end
|
1601
|
+
end
|
1602
|
+
end
|
1551
1603
|
end
|
@@ -3,6 +3,7 @@ require 'rails_helper'
|
|
3
3
|
module Spree
|
4
4
|
RSpec.describe OrderUpdateAttributes do
|
5
5
|
let(:order) { create(:order) }
|
6
|
+
let(:payment_method) { create(:payment_method) }
|
6
7
|
let(:request_env) { nil }
|
7
8
|
let(:update) { described_class.new(order, attributes, request_env: request_env) }
|
8
9
|
|
@@ -25,7 +26,10 @@ module Spree
|
|
25
26
|
let(:attributes) do
|
26
27
|
{
|
27
28
|
payments_attributes: [
|
28
|
-
{
|
29
|
+
{
|
30
|
+
payment_method_id: payment_method.id,
|
31
|
+
source_attributes: attributes_for(:credit_card)
|
32
|
+
}
|
29
33
|
]
|
30
34
|
}
|
31
35
|
end
|
@@ -662,12 +662,13 @@ RSpec.describe Spree::Payment, type: :model do
|
|
662
662
|
end
|
663
663
|
|
664
664
|
context "completed orders" do
|
665
|
+
let(:payment_method) { create(:check_payment_method) }
|
665
666
|
before { allow(order).to receive_messages completed?: true }
|
666
667
|
|
667
668
|
it "updates payment_state and shipments" do
|
668
669
|
expect(order.updater).to receive(:update_payment_state)
|
669
670
|
expect(order.updater).to receive(:update_shipment_state)
|
670
|
-
Spree::Payment.create(amount: 100, order: order)
|
671
|
+
Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
|
671
672
|
end
|
672
673
|
end
|
673
674
|
|
@@ -798,12 +799,13 @@ RSpec.describe Spree::Payment, type: :model do
|
|
798
799
|
end
|
799
800
|
|
800
801
|
describe "invalidating payments updates in memory objects" do
|
802
|
+
let(:payment_method) { create(:check_payment_method) }
|
801
803
|
before do
|
802
|
-
Spree::PaymentCreate.new(order, amount: 1).build.save!
|
804
|
+
Spree::PaymentCreate.new(order, amount: 1, payment_method_id: payment_method.id).build.save!
|
803
805
|
expect(order.payments.map(&:state)).to contain_exactly(
|
804
806
|
'checkout'
|
805
807
|
)
|
806
|
-
Spree::PaymentCreate.new(order, amount: 2).build.save!
|
808
|
+
Spree::PaymentCreate.new(order, amount: 2, payment_method_id: payment_method.id).build.save!
|
807
809
|
end
|
808
810
|
|
809
811
|
it 'should not have stale payments' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|