solidus_core 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +2 -1
- 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: 5a6f386d4b02423363675c20943ec411a624d36d
|
4
|
+
data.tar.gz: c651d02f3bed317f62d21268d60f90981897fc0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1018c8b201487476b9684120b094bc414bc0dfebb49a29fb768b855c16462cae88d6224e54964eb307a36f28be21cef04311ee15c93faf302065c39aff8929f3
|
7
|
+
data.tar.gz: 2c1499844ad3177827d67dbf554eccb46d228c1a5142207b5ce66e84bb06a74fd477fbbb83bb8efe4793ab49d8155f87157ad1352de7dd2c97e49de649bf3314
|
data/app/models/spree/order.rb
CHANGED
@@ -689,6 +689,23 @@ module Spree
|
|
689
689
|
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: currency })
|
690
690
|
end
|
691
691
|
|
692
|
+
def payments_attributes=(attributes)
|
693
|
+
validate_payments_attributes(attributes)
|
694
|
+
super(attributes)
|
695
|
+
end
|
696
|
+
|
697
|
+
def validate_payments_attributes(attributes)
|
698
|
+
attributes = Array.wrap(attributes)
|
699
|
+
# Ensure the payment methods specified are allowed for this user
|
700
|
+
payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
|
701
|
+
attributes.each do |payment_attributes|
|
702
|
+
payment_method_id = payment_attributes[:payment_method_id]
|
703
|
+
|
704
|
+
# raise RecordNotFound unless it is an allowed payment method
|
705
|
+
payment_methods.find(payment_method_id) if payment_method_id
|
706
|
+
end
|
707
|
+
end
|
708
|
+
|
692
709
|
private
|
693
710
|
|
694
711
|
def associate_store
|
@@ -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
@@ -1488,4 +1488,56 @@ describe Spree::Order, type: :model do
|
|
1488
1488
|
end
|
1489
1489
|
end
|
1490
1490
|
end
|
1491
|
+
|
1492
|
+
describe "#validate_payments_attributes" do
|
1493
|
+
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
1494
|
+
subject do
|
1495
|
+
order.validate_payments_attributes(attributes)
|
1496
|
+
end
|
1497
|
+
|
1498
|
+
context "with empty array" do
|
1499
|
+
let(:attributes) { [] }
|
1500
|
+
it "doesn't error" do
|
1501
|
+
subject
|
1502
|
+
end
|
1503
|
+
end
|
1504
|
+
|
1505
|
+
context "with no payment method specified" do
|
1506
|
+
let(:attributes) { [ActionController::Parameters.new({})] }
|
1507
|
+
it "doesn't error" do
|
1508
|
+
subject
|
1509
|
+
end
|
1510
|
+
end
|
1511
|
+
|
1512
|
+
context "with valid payment method" do
|
1513
|
+
let(:payment_method) { create(:check_payment_method) }
|
1514
|
+
it "doesn't error" do
|
1515
|
+
subject
|
1516
|
+
end
|
1517
|
+
end
|
1518
|
+
|
1519
|
+
context "with inactive payment method" do
|
1520
|
+
let(:payment_method) { create(:check_payment_method, active: false) }
|
1521
|
+
|
1522
|
+
it "raises RecordNotFound" do
|
1523
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1524
|
+
end
|
1525
|
+
end
|
1526
|
+
|
1527
|
+
context "with unavailable payment method" do
|
1528
|
+
let(:payment_method) { create(:check_payment_method, display_on: "back_end") }
|
1529
|
+
|
1530
|
+
it "raises RecordNotFound" do
|
1531
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1532
|
+
end
|
1533
|
+
end
|
1534
|
+
|
1535
|
+
context "with soft-deleted payment method" do
|
1536
|
+
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
1537
|
+
|
1538
|
+
it "raises RecordNotFound" do
|
1539
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1540
|
+
end
|
1541
|
+
end
|
1542
|
+
end
|
1491
1543
|
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
|
|
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.0.
|
4
|
+
version: 2.0.3
|
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
|