solidus_core 2.3.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29ed210ae918b867c39b7a290b44b0d843304c79
4
- data.tar.gz: d673428c249f2b2821cb73c478f9d0ec9db77ce6
3
+ metadata.gz: 81d6032a716d2aa2fb21390574017b2837180df8
4
+ data.tar.gz: e7fa707fa0b92207c25f4c15fedc66cbadaf6e7d
5
5
  SHA512:
6
- metadata.gz: 337f2c207f605c39c9546616e35ee49f39f1e016192e1a07bcb04e4b8987fdfe19e5ef75aeafeefff8a1819f9fbc3e43c8f0e3af46cce2113ccb1bca428c8537
7
- data.tar.gz: 5412e85a7e4b999652ac4fb747aa887eb0795dbbb5cb7d62c943d273c642057472b79df91d8a6201d6315233fc42b51d4ea8f18d8983f7bb91894eba4622ac25
6
+ metadata.gz: 991ba48b8ae7d0b5f39654ee498f2a9b063908ea39b036e6698917928a434bb7978a66ec4eae443a70e51bff52b8789fd8621c2f30d4a2f2222ad3f2185bf8af
7
+ data.tar.gz: 9dd2388898217a51fe858f9258c860c3d3f41f79574dc91f87c5becec0eda3d3b603c823f14ff7a10d912bb0413d960c3a96c16b982959e0f73e30a9648cee0e
@@ -748,6 +748,23 @@ module Spree
748
748
  end
749
749
  end
750
750
 
751
+ def payments_attributes=(attributes)
752
+ validate_payments_attributes(attributes)
753
+ super(attributes)
754
+ end
755
+
756
+ def validate_payments_attributes(attributes)
757
+ attributes = Array(attributes)
758
+ # Ensure the payment methods specified are allowed for this user
759
+ payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
760
+ attributes.each do |payment_attributes|
761
+ payment_method_id = payment_attributes[:payment_method_id]
762
+
763
+ # raise RecordNotFound unless it is an allowed payment method
764
+ payment_methods.find(payment_method_id) if payment_method_id
765
+ end
766
+ end
767
+
751
768
  private
752
769
 
753
770
  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
 
@@ -40,6 +40,7 @@ module Spree
40
40
 
41
41
  validates :amount, numericality: true
42
42
  validates :source, presence: true, if: :source_required?
43
+ validates :payment_method, presence: true
43
44
 
44
45
  default_scope -> { order(:created_at) }
45
46
 
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  def self.solidus_version
3
- "2.3.0"
3
+ "2.3.1"
4
4
  end
5
5
 
6
6
  def self.solidus_gem_version
@@ -1534,4 +1534,66 @@ describe Spree::Order, type: :model do
1534
1534
  end
1535
1535
  end
1536
1536
  end
1537
+
1538
+ context 'update_params_payment_source' do
1539
+ subject { described_class.new }
1540
+
1541
+ it 'is deprecated' do
1542
+ subject.instance_variable_set('@updating_params', {})
1543
+ expect(Spree::Deprecation).to receive(:warn)
1544
+ subject.update_params_payment_source
1545
+ end
1546
+ end
1547
+
1548
+ describe "#validate_payments_attributes" do
1549
+ let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
1550
+ subject do
1551
+ order.validate_payments_attributes(attributes)
1552
+ end
1553
+
1554
+ context "with empty array" do
1555
+ let(:attributes) { [] }
1556
+ it "doesn't error" do
1557
+ subject
1558
+ end
1559
+ end
1560
+
1561
+ context "with no payment method specified" do
1562
+ let(:attributes) { [ActionController::Parameters.new({})] }
1563
+ it "doesn't error" do
1564
+ subject
1565
+ end
1566
+ end
1567
+
1568
+ context "with valid payment method" do
1569
+ let(:payment_method) { create(:check_payment_method) }
1570
+ it "doesn't error" do
1571
+ subject
1572
+ end
1573
+ end
1574
+
1575
+ context "with inactive payment method" do
1576
+ let(:payment_method) { create(:check_payment_method, active: false) }
1577
+
1578
+ it "raises RecordNotFound" do
1579
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1580
+ end
1581
+ end
1582
+
1583
+ context "with unavailable payment method" do
1584
+ let(:payment_method) { create(:check_payment_method, available_to_users: false) }
1585
+
1586
+ it "raises RecordNotFound" do
1587
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1588
+ end
1589
+ end
1590
+
1591
+ context "with soft-deleted payment method" do
1592
+ let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
1593
+
1594
+ it "raises RecordNotFound" do
1595
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1596
+ end
1597
+ end
1598
+ end
1537
1599
  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
- { source_attributes: attributes_for(:credit_card) }
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
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.3.0
4
+ version: 2.3.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-07-31 00:00:00.000000000 Z
11
+ date: 2017-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant