solidus_core 2.4.0 → 2.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bdaf7748b13daf199a4d23fcb00bfc0a5f38bc4
4
- data.tar.gz: a108fea214ee54d7ad879c3fed81e6d3f55421c8
3
+ metadata.gz: bfbaab05af3945cfa3851f30385796b958081539
4
+ data.tar.gz: 0ce9487cd7d65d53c29a521604e88f1c7c2cccee
5
5
  SHA512:
6
- metadata.gz: 586b29252a401eec1003c8c109647c583d1d0819f17d23f0ea096fba058113f3bbda2b998d6ff1e8d10ac627a9bf1b52ead4386edce414ab9aecefe05129971d
7
- data.tar.gz: f4abefa2f9cbbb0c2ea33364a1fce3f7146468bce407047c01c56cab231591bac607adca89e1b4cfa4a022c180d6aad98060725c5ac464c863ac45cce5dba2d5
6
+ metadata.gz: ded1d464481cb7560a968170df60ee2b4fb7f41cd5f5270cac8459aa65d987cf74aca0f6bb0089235669db0fc40109080249178316c2d596a5c094f5409a815f
7
+ data.tar.gz: a1b690aed55aea7da4e8f7d20147479f966ea1d36953a85bed3ab91307443c6b1aa40a3152f4be8ac3719c3af6c0aa2d31e7bedd2548e178c05364bfede90faa
@@ -759,6 +759,23 @@ module Spree
759
759
  end
760
760
  end
761
761
 
762
+ def payments_attributes=(attributes)
763
+ validate_payments_attributes(attributes)
764
+ super(attributes)
765
+ end
766
+
767
+ def validate_payments_attributes(attributes)
768
+ attributes = Array(attributes)
769
+ # Ensure the payment methods specified are allowed for this user
770
+ payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
771
+ attributes.each do |payment_attributes|
772
+ payment_method_id = payment_attributes[:payment_method_id]
773
+
774
+ # raise RecordNotFound unless it is an allowed payment method
775
+ payment_methods.find(payment_method_id) if payment_method_id
776
+ end
777
+ end
778
+
762
779
  private
763
780
 
764
781
  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.4.0"
3
+ "2.4.1"
4
4
  end
5
5
 
6
6
  def self.solidus_gem_version
@@ -1548,4 +1548,56 @@ RSpec.describe Spree::Order, type: :model do
1548
1548
  subject.update_params_payment_source
1549
1549
  end
1550
1550
  end
1551
+
1552
+ describe "#validate_payments_attributes" do
1553
+ let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
1554
+ subject do
1555
+ order.validate_payments_attributes(attributes)
1556
+ end
1557
+
1558
+ context "with empty array" do
1559
+ let(:attributes) { [] }
1560
+ it "doesn't error" do
1561
+ subject
1562
+ end
1563
+ end
1564
+
1565
+ context "with no payment method specified" do
1566
+ let(:attributes) { [ActionController::Parameters.new({})] }
1567
+ it "doesn't error" do
1568
+ subject
1569
+ end
1570
+ end
1571
+
1572
+ context "with valid payment method" do
1573
+ let(:payment_method) { create(:check_payment_method) }
1574
+ it "doesn't error" do
1575
+ subject
1576
+ end
1577
+ end
1578
+
1579
+ context "with inactive payment method" do
1580
+ let(:payment_method) { create(:check_payment_method, active: false) }
1581
+
1582
+ it "raises RecordNotFound" do
1583
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1584
+ end
1585
+ end
1586
+
1587
+ context "with unavailable payment method" do
1588
+ let(:payment_method) { create(:check_payment_method, available_to_users: false) }
1589
+
1590
+ it "raises RecordNotFound" do
1591
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1592
+ end
1593
+ end
1594
+
1595
+ context "with soft-deleted payment method" do
1596
+ let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
1597
+
1598
+ it "raises RecordNotFound" do
1599
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1600
+ end
1601
+ end
1602
+ end
1551
1603
  end
@@ -3,6 +3,7 @@ require 'rails_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
@@ -662,12 +662,13 @@ RSpec.describe Spree::Payment, type: :model do
662
662
  end
663
663
 
664
664
  context "completed orders" do
665
+ let(:payment_method) { create(:check_payment_method) }
665
666
  before { allow(order).to receive_messages completed?: true }
666
667
 
667
668
  it "updates payment_state and shipments" do
668
669
  expect(order.updater).to receive(:update_payment_state)
669
670
  expect(order.updater).to receive(:update_shipment_state)
670
- Spree::Payment.create(amount: 100, order: order)
671
+ Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
671
672
  end
672
673
  end
673
674
 
@@ -798,12 +799,13 @@ RSpec.describe Spree::Payment, type: :model do
798
799
  end
799
800
 
800
801
  describe "invalidating payments updates in memory objects" do
802
+ let(:payment_method) { create(:check_payment_method) }
801
803
  before do
802
- Spree::PaymentCreate.new(order, amount: 1).build.save!
804
+ Spree::PaymentCreate.new(order, amount: 1, payment_method_id: payment_method.id).build.save!
803
805
  expect(order.payments.map(&:state)).to contain_exactly(
804
806
  'checkout'
805
807
  )
806
- Spree::PaymentCreate.new(order, amount: 2).build.save!
808
+ Spree::PaymentCreate.new(order, amount: 2, payment_method_id: payment_method.id).build.save!
807
809
  end
808
810
 
809
811
  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.4.0
4
+ version: 2.4.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-07 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