solidus_core 2.0.2 → 2.0.3

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: f4cd6430d3c1e5e19bb9548632a70531888a50fd
4
- data.tar.gz: 8ebdda8f5f4cbb1f4a1aff2d9c9aeb4590a5ac99
3
+ metadata.gz: 5a6f386d4b02423363675c20943ec411a624d36d
4
+ data.tar.gz: c651d02f3bed317f62d21268d60f90981897fc0f
5
5
  SHA512:
6
- metadata.gz: 7949cdb760035f8934188282eda1bdb3e847f96b86f65fb1af42c6e9c295a9373f8801d15a2c6eb51c371d18b26cbbf1920055ab710198039b97173699453db3
7
- data.tar.gz: f64d4a9cb6429ac91d365022386edabec822ac6f54b7b57588fd8c8264f584ca409a4063e71df4484dd6c00dc44f8e1c841df1f2e42110f2c16dbafd07121e00
6
+ metadata.gz: 1018c8b201487476b9684120b094bc414bc0dfebb49a29fb768b855c16462cae88d6224e54964eb307a36f28be21cef04311ee15c93faf302065c39aff8929f3
7
+ data.tar.gz: 2c1499844ad3177827d67dbf554eccb46d228c1a5142207b5ce66e84bb06a74fd477fbbb83bb8efe4793ab49d8155f87157ad1352de7dd2c97e49de649bf3314
@@ -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
 
@@ -5,7 +5,7 @@ module Spree
5
5
  end
6
6
 
7
7
  def self.solidus_version
8
- "2.0.2"
8
+ "2.0.3"
9
9
  end
10
10
 
11
11
  def self.solidus_gem_version
@@ -1488,4 +1488,56 @@ describe Spree::Order, type: :model do
1488
1488
  end
1489
1489
  end
1490
1490
  end
1491
+
1492
+ describe "#validate_payments_attributes" do
1493
+ let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
1494
+ subject do
1495
+ order.validate_payments_attributes(attributes)
1496
+ end
1497
+
1498
+ context "with empty array" do
1499
+ let(:attributes) { [] }
1500
+ it "doesn't error" do
1501
+ subject
1502
+ end
1503
+ end
1504
+
1505
+ context "with no payment method specified" do
1506
+ let(:attributes) { [ActionController::Parameters.new({})] }
1507
+ it "doesn't error" do
1508
+ subject
1509
+ end
1510
+ end
1511
+
1512
+ context "with valid payment method" do
1513
+ let(:payment_method) { create(:check_payment_method) }
1514
+ it "doesn't error" do
1515
+ subject
1516
+ end
1517
+ end
1518
+
1519
+ context "with inactive payment method" do
1520
+ let(:payment_method) { create(:check_payment_method, active: false) }
1521
+
1522
+ it "raises RecordNotFound" do
1523
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1524
+ end
1525
+ end
1526
+
1527
+ context "with unavailable payment method" do
1528
+ let(:payment_method) { create(:check_payment_method, display_on: "back_end") }
1529
+
1530
+ it "raises RecordNotFound" do
1531
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1532
+ end
1533
+ end
1534
+
1535
+ context "with soft-deleted payment method" do
1536
+ let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
1537
+
1538
+ it "raises RecordNotFound" do
1539
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1540
+ end
1541
+ end
1542
+ end
1491
1543
  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
 
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.0.2
4
+ version: 2.0.3
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-06-08 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