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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c7402622fc30f6fef2fc3cad846e07adaeac3bf
4
- data.tar.gz: 808c7fc752dbe3298afc6131a49509df4086202d
3
+ metadata.gz: 11dfded4cc7b83741076ed919b7e304c7c4f3cf6
4
+ data.tar.gz: 93326ebc65ba22635c8dc11cd971d84c5a457b85
5
5
  SHA512:
6
- metadata.gz: ff019cdef35791c28148b68397ac795b78ec86f2eed1d0d7cd33c34383b7bc5cd24342d79fe0e7c7fb95a3c77a3242df739419d821aca59ac6f5b5007d786250
7
- data.tar.gz: ceabe9026cfb4469481120ab7ad9152fc02fe20e03435950f42b92149a3347eb64538d14d822760821204fd211830ad05b0a8afba6dbe76258bc454ec5f0f44b
6
+ metadata.gz: 897b31dab736b86bf7606a03312e623aaab7a144110d832df807f33fab4046a43466c81b18c634eb7fe24e3d1e92280567dfb93531785f201bc25c70e78bf166
7
+ data.tar.gz: 2a91a9348afeb72e55c48efacbc00dcb260422f04734ba0aea8e8c13eae0e0b100202c6b9fa3bba56bef3f8ad7888a2e32ac0e564bed7b60b7f5584ba1f0b54c
@@ -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
 
@@ -39,6 +39,7 @@ module Spree
39
39
 
40
40
  validates :amount, numericality: true
41
41
  validates :source, presence: true, if: :source_required?
42
+ validates :payment_method, presence: true
42
43
 
43
44
  default_scope -> { order(:created_at) }
44
45
 
@@ -124,7 +124,7 @@ end
124
124
  core_gems = ["spree/core", "spree/api", "spree/backend", "spree/frontend"]
125
125
 
126
126
  if core_gems.include?(lib_name)
127
- '../../../../../Gemfile'
127
+ '../../../../Gemfile'
128
128
  else
129
129
  '../../../../Gemfile'
130
130
  end
@@ -5,7 +5,7 @@ module Spree
5
5
  end
6
6
 
7
7
  def self.solidus_version
8
- "1.3.1"
8
+ "1.3.2"
9
9
  end
10
10
 
11
11
  def self.solidus_gem_version
@@ -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
- { 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
@@ -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.1
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: 2016-07-06 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
@@ -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.5.1
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.