solidus_core 1.3.1 → 1.3.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/generators/spree/dummy/dummy_generator.rb +1 -1
- 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 +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11dfded4cc7b83741076ed919b7e304c7c4f3cf6
|
4
|
+
data.tar.gz: 93326ebc65ba22635c8dc11cd971d84c5a457b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897b31dab736b86bf7606a03312e623aaab7a144110d832df807f33fab4046a43466c81b18c634eb7fe24e3d1e92280567dfb93531785f201bc25c70e78bf166
|
7
|
+
data.tar.gz: 2a91a9348afeb72e55c48efacbc00dcb260422f04734ba0aea8e8c13eae0e0b100202c6b9fa3bba56bef3f8ad7888a2e32ac0e564bed7b60b7f5584ba1f0b54c
|
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
@@ -1476,4 +1476,56 @@ describe Spree::Order, type: :model do
|
|
1476
1476
|
end
|
1477
1477
|
end
|
1478
1478
|
end
|
1479
|
+
|
1480
|
+
describe "#validate_payments_attributes" do
|
1481
|
+
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
1482
|
+
subject do
|
1483
|
+
order.validate_payments_attributes(attributes)
|
1484
|
+
end
|
1485
|
+
|
1486
|
+
context "with empty array" do
|
1487
|
+
let(:attributes) { [] }
|
1488
|
+
it "doesn't error" do
|
1489
|
+
subject
|
1490
|
+
end
|
1491
|
+
end
|
1492
|
+
|
1493
|
+
context "with no payment method specified" do
|
1494
|
+
let(:attributes) { [ActionController::Parameters.new({})] }
|
1495
|
+
it "doesn't error" do
|
1496
|
+
subject
|
1497
|
+
end
|
1498
|
+
end
|
1499
|
+
|
1500
|
+
context "with valid payment method" do
|
1501
|
+
let(:payment_method) { create(:check_payment_method) }
|
1502
|
+
it "doesn't error" do
|
1503
|
+
subject
|
1504
|
+
end
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
context "with inactive payment method" do
|
1508
|
+
let(:payment_method) { create(:check_payment_method, active: false) }
|
1509
|
+
|
1510
|
+
it "raises RecordNotFound" do
|
1511
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1512
|
+
end
|
1513
|
+
end
|
1514
|
+
|
1515
|
+
context "with unavailable payment method" do
|
1516
|
+
let(:payment_method) { create(:check_payment_method, display_on: "back_end") }
|
1517
|
+
|
1518
|
+
it "raises RecordNotFound" do
|
1519
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1520
|
+
end
|
1521
|
+
end
|
1522
|
+
|
1523
|
+
context "with soft-deleted payment method" do
|
1524
|
+
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
1525
|
+
|
1526
|
+
it "raises RecordNotFound" do
|
1527
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1528
|
+
end
|
1529
|
+
end
|
1530
|
+
end
|
1479
1531
|
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
|
@@ -655,12 +655,13 @@ describe Spree::Payment, type: :model do
|
|
655
655
|
end
|
656
656
|
|
657
657
|
context "completed orders" do
|
658
|
+
let(:payment_method) { create(:check_payment_method) }
|
658
659
|
before { allow(order).to receive_messages completed?: true }
|
659
660
|
|
660
661
|
it "updates payment_state and shipments" do
|
661
662
|
expect(order.updater).to receive(:update_payment_state)
|
662
663
|
expect(order.updater).to receive(:update_shipment_state)
|
663
|
-
Spree::Payment.create(amount: 100, order: order)
|
664
|
+
Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
|
664
665
|
end
|
665
666
|
end
|
666
667
|
|
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: 1.3.
|
4
|
+
version: 1.3.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:
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|
@@ -1395,7 +1395,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1395
1395
|
version: '0'
|
1396
1396
|
requirements: []
|
1397
1397
|
rubyforge_project:
|
1398
|
-
rubygems_version: 2.
|
1398
|
+
rubygems_version: 2.6.11
|
1399
1399
|
signing_key:
|
1400
1400
|
specification_version: 4
|
1401
1401
|
summary: Essential models, mailers, and classes for the Solidus e-commerce project.
|