solidus_core 2.2.1 → 2.2.2
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
- data/spec/models/spree/promotion_spec.rb +6 -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: 2a2dec32c7e551a4cccda16f58059e05cbb507ea
|
4
|
+
data.tar.gz: 0f1687d7691c96cb0a0aae2b13cc53c1e4f90692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9215d5df94bc2bb98df3f74e33b670af7fa9a7f00edec4ee4367e9f28da1d386cde1982f3f770c6eba3676e29253dd7c3b1c2c2d1640dec5fd6fd9a4eff31242
|
7
|
+
data.tar.gz: d2b86bb28e9673ddf3f32d98a67d274bf580f057f812e662d4c4f43e7f9cb6cd67dbe0628d58fc839e78ba15636f8528c4b416caeeece6dd5ca98a9046e677e6
|
data/app/models/spree/order.rb
CHANGED
@@ -736,6 +736,23 @@ module Spree
|
|
736
736
|
alias_method :assign_default_credit_card, :add_default_payment_from_wallet
|
737
737
|
deprecate assign_default_credit_card: :add_default_payment_from_wallet, deprecator: Spree::Deprecation
|
738
738
|
|
739
|
+
def payments_attributes=(attributes)
|
740
|
+
validate_payments_attributes(attributes)
|
741
|
+
super(attributes)
|
742
|
+
end
|
743
|
+
|
744
|
+
def validate_payments_attributes(attributes)
|
745
|
+
attributes = Array.wrap(attributes)
|
746
|
+
# Ensure the payment methods specified are allowed for this user
|
747
|
+
payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
|
748
|
+
attributes.each do |payment_attributes|
|
749
|
+
payment_method_id = payment_attributes[:payment_method_id]
|
750
|
+
|
751
|
+
# raise RecordNotFound unless it is an allowed payment method
|
752
|
+
payment_methods.find(payment_method_id) if payment_method_id
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
739
756
|
private
|
740
757
|
|
741
758
|
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
@@ -1409,4 +1409,56 @@ describe Spree::Order, type: :model do
|
|
1409
1409
|
end
|
1410
1410
|
end
|
1411
1411
|
end
|
1412
|
+
|
1413
|
+
describe "#validate_payments_attributes" do
|
1414
|
+
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
1415
|
+
subject do
|
1416
|
+
order.validate_payments_attributes(attributes)
|
1417
|
+
end
|
1418
|
+
|
1419
|
+
context "with empty array" do
|
1420
|
+
let(:attributes) { [] }
|
1421
|
+
it "doesn't error" do
|
1422
|
+
subject
|
1423
|
+
end
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
context "with no payment method specified" do
|
1427
|
+
let(:attributes) { [ActionController::Parameters.new({})] }
|
1428
|
+
it "doesn't error" do
|
1429
|
+
subject
|
1430
|
+
end
|
1431
|
+
end
|
1432
|
+
|
1433
|
+
context "with valid payment method" do
|
1434
|
+
let(:payment_method) { create(:check_payment_method) }
|
1435
|
+
it "doesn't error" do
|
1436
|
+
subject
|
1437
|
+
end
|
1438
|
+
end
|
1439
|
+
|
1440
|
+
context "with inactive payment method" do
|
1441
|
+
let(:payment_method) { create(:check_payment_method, active: false) }
|
1442
|
+
|
1443
|
+
it "raises RecordNotFound" do
|
1444
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1445
|
+
end
|
1446
|
+
end
|
1447
|
+
|
1448
|
+
context "with unavailable payment method" do
|
1449
|
+
let(:payment_method) { create(:check_payment_method, available_to_users: false) }
|
1450
|
+
|
1451
|
+
it "raises RecordNotFound" do
|
1452
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1453
|
+
end
|
1454
|
+
end
|
1455
|
+
|
1456
|
+
context "with soft-deleted payment method" do
|
1457
|
+
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
1458
|
+
|
1459
|
+
it "raises RecordNotFound" do
|
1460
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1461
|
+
end
|
1462
|
+
end
|
1463
|
+
end
|
1412
1464
|
end
|
@@ -3,6 +3,7 @@ require 'spec_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
|
@@ -653,12 +653,13 @@ describe Spree::Payment, type: :model do
|
|
653
653
|
end
|
654
654
|
|
655
655
|
context "completed orders" do
|
656
|
+
let(:payment_method) { create(:check_payment_method) }
|
656
657
|
before { allow(order).to receive_messages completed?: true }
|
657
658
|
|
658
659
|
it "updates payment_state and shipments" do
|
659
660
|
expect(order.updater).to receive(:update_payment_state)
|
660
661
|
expect(order.updater).to receive(:update_shipment_state)
|
661
|
-
Spree::Payment.create(amount: 100, order: order)
|
662
|
+
Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
|
662
663
|
end
|
663
664
|
end
|
664
665
|
|
@@ -742,12 +743,13 @@ describe Spree::Payment, type: :model do
|
|
742
743
|
end
|
743
744
|
|
744
745
|
describe "invalidating payments updates in memory objects" do
|
746
|
+
let(:payment_method) { create(:check_payment_method) }
|
745
747
|
before do
|
746
|
-
Spree::PaymentCreate.new(order, amount: 1).build.save!
|
748
|
+
Spree::PaymentCreate.new(order, amount: 1, payment_method_id: payment_method.id).build.save!
|
747
749
|
expect(order.payments.map(&:state)).to contain_exactly(
|
748
750
|
'checkout'
|
749
751
|
)
|
750
|
-
Spree::PaymentCreate.new(order, amount: 2).build.save!
|
752
|
+
Spree::PaymentCreate.new(order, amount: 2, payment_method_id: payment_method.id).build.save!
|
751
753
|
end
|
752
754
|
|
753
755
|
it 'should not have stale payments' do
|
@@ -597,7 +597,8 @@ describe Spree::Promotion, type: :model do
|
|
597
597
|
allow(rule2).to receive_messages(eligible?: true, applicable?: true)
|
598
598
|
|
599
599
|
promotion.promotion_rules = [rule1, rule2]
|
600
|
-
allow(promotion
|
600
|
+
allow(promotion).to receive_message_chain(:rules, :none?).and_return(false)
|
601
|
+
allow(promotion).to receive_message_chain(:rules, :for).and_return(promotion.promotion_rules)
|
601
602
|
end
|
602
603
|
it "returns the eligible rules" do
|
603
604
|
expect(promotion.eligible_rules(promotable)).to eq [rule1, rule2]
|
@@ -615,7 +616,8 @@ describe Spree::Promotion, type: :model do
|
|
615
616
|
allow(rule2).to receive_messages(eligible?: false, applicable?: true, eligibility_errors: errors)
|
616
617
|
|
617
618
|
promotion.promotion_rules = [rule1, rule2]
|
618
|
-
allow(promotion
|
619
|
+
allow(promotion).to receive_message_chain(:rules, :none?).and_return(false)
|
620
|
+
allow(promotion).to receive_message_chain(:rules, :for).and_return(promotion.promotion_rules)
|
619
621
|
end
|
620
622
|
it "returns nil" do
|
621
623
|
expect(promotion.eligible_rules(promotable)).to be_nil
|
@@ -647,7 +649,8 @@ describe Spree::Promotion, type: :model do
|
|
647
649
|
allow(rule).to receive_messages(eligible?: false, applicable?: true, eligibility_errors: errors)
|
648
650
|
|
649
651
|
promotion.promotion_rules = [rule]
|
650
|
-
allow(promotion
|
652
|
+
allow(promotion).to receive_message_chain(:rules, :for).and_return(promotion.promotion_rules)
|
653
|
+
allow(promotion).to receive_message_chain(:rules, :none?).and_return(false)
|
651
654
|
end
|
652
655
|
it "returns nil" do
|
653
656
|
expect(promotion.eligible_rules(promotable)).to be_nil
|
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.2.
|
4
|
+
version: 2.2.2
|
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
|