solidus_core 2.1.0 → 2.1.1
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 +18 -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_inventory_spec.rb +5 -3
- 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 +22 -20
- data/spec/models/spree/promotion_spec.rb +6 -3
- 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: 3c934b38bc5fe5c396b4c0eff48366ee4d0191b7
|
4
|
+
data.tar.gz: 909b4d8df7e9fae8bc877f2ea3ba94e9e4678cc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 663ef73baabdcb94f31638b3a84913f10b853748de77376c1018b9f026f703fdf8f3d2c78cc69bd6edb4997e3c506f2aff348fbbd7d7a03442863147c054a056
|
7
|
+
data.tar.gz: dcfa1557ad792104c88a4f9eea1648711888417f8169594da523534d64e230caefbc86a759161ab5525e0b55c45fa123da14a6910a88b8bd6300593d7bacb934
|
data/app/models/spree/order.rb
CHANGED
@@ -431,6 +431,7 @@ module Spree
|
|
431
431
|
@available_payment_methods ||= Spree::PaymentMethod
|
432
432
|
.available_to_store(store)
|
433
433
|
.available_to_users
|
434
|
+
.active
|
434
435
|
.sort_by(&:position)
|
435
436
|
end
|
436
437
|
|
@@ -689,6 +690,23 @@ module Spree
|
|
689
690
|
Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: currency })
|
690
691
|
end
|
691
692
|
|
693
|
+
def payments_attributes=(attributes)
|
694
|
+
validate_payments_attributes(attributes)
|
695
|
+
super(attributes)
|
696
|
+
end
|
697
|
+
|
698
|
+
def validate_payments_attributes(attributes)
|
699
|
+
attributes = Array.wrap(attributes)
|
700
|
+
# Ensure the payment methods specified are allowed for this user
|
701
|
+
payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
|
702
|
+
attributes.each do |payment_attributes|
|
703
|
+
payment_method_id = payment_attributes[:payment_method_id]
|
704
|
+
|
705
|
+
# raise RecordNotFound unless it is an allowed payment method
|
706
|
+
payment_methods.find(payment_method_id) if payment_method_id
|
707
|
+
end
|
708
|
+
end
|
709
|
+
|
692
710
|
private
|
693
711
|
|
694
712
|
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
@@ -201,10 +201,12 @@ describe Spree::OrderInventory, type: :model do
|
|
201
201
|
end
|
202
202
|
|
203
203
|
it 'should destroy self if not inventory units remain' do
|
204
|
-
|
205
|
-
|
204
|
+
shipment.inventory_units[1...999].each(&:destroy)
|
205
|
+
shipment.inventory_units.reload
|
206
206
|
|
207
|
-
expect
|
207
|
+
expect {
|
208
|
+
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
|
209
|
+
}.to change{ order.shipments.count }.from(1).to(0)
|
208
210
|
end
|
209
211
|
|
210
212
|
context "inventory unit line item and variant points to different products" do
|
@@ -1459,4 +1459,56 @@ describe Spree::Order, type: :model do
|
|
1459
1459
|
end
|
1460
1460
|
end
|
1461
1461
|
end
|
1462
|
+
|
1463
|
+
describe "#validate_payments_attributes" do
|
1464
|
+
let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
|
1465
|
+
subject do
|
1466
|
+
order.validate_payments_attributes(attributes)
|
1467
|
+
end
|
1468
|
+
|
1469
|
+
context "with empty array" do
|
1470
|
+
let(:attributes) { [] }
|
1471
|
+
it "doesn't error" do
|
1472
|
+
subject
|
1473
|
+
end
|
1474
|
+
end
|
1475
|
+
|
1476
|
+
context "with no payment method specified" do
|
1477
|
+
let(:attributes) { [ActionController::Parameters.new({})] }
|
1478
|
+
it "doesn't error" do
|
1479
|
+
subject
|
1480
|
+
end
|
1481
|
+
end
|
1482
|
+
|
1483
|
+
context "with valid payment method" do
|
1484
|
+
let(:payment_method) { create(:check_payment_method) }
|
1485
|
+
it "doesn't error" do
|
1486
|
+
subject
|
1487
|
+
end
|
1488
|
+
end
|
1489
|
+
|
1490
|
+
context "with inactive payment method" do
|
1491
|
+
let(:payment_method) { create(:check_payment_method, active: false) }
|
1492
|
+
|
1493
|
+
it "raises RecordNotFound" do
|
1494
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1495
|
+
end
|
1496
|
+
end
|
1497
|
+
|
1498
|
+
context "with unavailable payment method" do
|
1499
|
+
let(:payment_method) { create(:check_payment_method, available_to_users: false) }
|
1500
|
+
|
1501
|
+
it "raises RecordNotFound" do
|
1502
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1503
|
+
end
|
1504
|
+
end
|
1505
|
+
|
1506
|
+
context "with soft-deleted payment method" do
|
1507
|
+
let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
|
1508
|
+
|
1509
|
+
it "raises RecordNotFound" do
|
1510
|
+
expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
|
1511
|
+
end
|
1512
|
+
end
|
1513
|
+
end
|
1462
1514
|
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
|
@@ -17,12 +17,12 @@ describe Spree::Payment, type: :model do
|
|
17
17
|
let(:card) { create :credit_card }
|
18
18
|
|
19
19
|
let(:payment) do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
Spree::Payment.create! do |payment|
|
21
|
+
payment.source = card
|
22
|
+
payment.order = order
|
23
|
+
payment.payment_method = gateway
|
24
|
+
payment.amount = 5
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
let(:amount_in_cents) { (payment.amount * 100).round }
|
@@ -39,11 +39,6 @@ describe Spree::Payment, type: :model do
|
|
39
39
|
ActiveMerchant::Billing::Response.new(false, '', {}, {})
|
40
40
|
end
|
41
41
|
|
42
|
-
before(:each) do
|
43
|
-
# So it doesn't create log entries every time a processing method is called
|
44
|
-
allow(payment.log_entries).to receive(:create!)
|
45
|
-
end
|
46
|
-
|
47
42
|
context '.risky' do
|
48
43
|
let!(:payment_1) { create(:payment, avs_response: 'Y', cvv_response_code: 'M', cvv_response_message: 'Match') }
|
49
44
|
let!(:payment_2) { create(:payment, avs_response: 'Y', cvv_response_code: 'M', cvv_response_message: '') }
|
@@ -246,8 +241,9 @@ describe Spree::Payment, type: :model do
|
|
246
241
|
|
247
242
|
it "should log the response" do
|
248
243
|
payment.save!
|
249
|
-
expect
|
250
|
-
|
244
|
+
expect {
|
245
|
+
payment.authorize!
|
246
|
+
}.to change { payment.log_entries.count }.by(1)
|
251
247
|
end
|
252
248
|
|
253
249
|
describe 'billing_address option' do
|
@@ -355,8 +351,9 @@ describe Spree::Payment, type: :model do
|
|
355
351
|
|
356
352
|
it "should log the response" do
|
357
353
|
payment.save!
|
358
|
-
expect
|
359
|
-
|
354
|
+
expect {
|
355
|
+
payment.purchase!
|
356
|
+
}.to change { payment.log_entries.count }.by(1)
|
360
357
|
end
|
361
358
|
|
362
359
|
context "if successful" do
|
@@ -532,8 +529,9 @@ describe Spree::Payment, type: :model do
|
|
532
529
|
end
|
533
530
|
|
534
531
|
it "should log the response" do
|
535
|
-
expect
|
536
|
-
|
532
|
+
expect {
|
533
|
+
payment.void_transaction!
|
534
|
+
}.to change { payment.log_entries.count }.by(1)
|
537
535
|
end
|
538
536
|
|
539
537
|
context "if successful" do
|
@@ -655,12 +653,13 @@ describe Spree::Payment, type: :model do
|
|
655
653
|
end
|
656
654
|
|
657
655
|
context "completed orders" do
|
656
|
+
let(:payment_method) { create(:check_payment_method) }
|
658
657
|
before { allow(order).to receive_messages completed?: true }
|
659
658
|
|
660
659
|
it "updates payment_state and shipments" do
|
661
660
|
expect(order.updater).to receive(:update_payment_state)
|
662
661
|
expect(order.updater).to receive(:update_shipment_state)
|
663
|
-
Spree::Payment.create(amount: 100, order: order)
|
662
|
+
Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
|
664
663
|
end
|
665
664
|
end
|
666
665
|
|
@@ -688,6 +687,8 @@ describe Spree::Payment, type: :model do
|
|
688
687
|
let(:attributes) { attributes_for(:credit_card) }
|
689
688
|
|
690
689
|
it "should not try to create profiles on old failed payment attempts" do
|
690
|
+
order.payments.destroy_all
|
691
|
+
|
691
692
|
allow_any_instance_of(Spree::Payment).to receive(:payment_method) { gateway }
|
692
693
|
|
693
694
|
Spree::PaymentCreate.new(order, {
|
@@ -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.1.
|
4
|
+
version: 2.1.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
|
@@ -1402,7 +1402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1402
1402
|
version: 1.8.23
|
1403
1403
|
requirements: []
|
1404
1404
|
rubyforge_project:
|
1405
|
-
rubygems_version: 2.6.
|
1405
|
+
rubygems_version: 2.6.11
|
1406
1406
|
signing_key:
|
1407
1407
|
specification_version: 4
|
1408
1408
|
summary: Essential models, mailers, and classes for the Solidus e-commerce project.
|