solidus_core 1.4.1 → 1.4.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: aa867922c3f2c7b2a572608fca5fc204bf79432f
4
- data.tar.gz: de1aa771c6053d950b07ec3cebabdf018e10edc3
3
+ metadata.gz: 7ed91e331714aac66f2d62d0cd91f38a017ccc33
4
+ data.tar.gz: d44b301719f10414d45cd960a1d6d9ead7fc8347
5
5
  SHA512:
6
- metadata.gz: 65ce96cb639eea0ebb1e23357cec01c05e1ac6b2c31393124e91a226229f5a1726b7f84d066365ae716f55e9ef480a3e1fbd916c6ceed781b1c0f61d5a6d7a76
7
- data.tar.gz: 8cd7b7d60518a7cf6c5d8cbd405a5bdd72f64fdfa08f9b92801a51f489956f5ed0e942063551a9f4aa335dca2f30800cfd20a37f2553052e41277f7646d820ef
6
+ metadata.gz: ea89683585bf67ec9c2dcab332eef19f5badab7780b0534b85cdea8bc645c1ce053decc62859f1f33a14affc1f34df61983e98da3335d2e1f4b05bc60477ea91
7
+ data.tar.gz: f7d0fe364457ace7463e77540ea14bfce8df7857b8a157fa717d76b3a3ba16e4a74fc8178bd61939940bcbc107ec649f589e245d3bdf731b0304ed5976a8a87c
@@ -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.4.1"
8
+ "1.4.2"
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
@@ -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.4.1
4
+ version: 1.4.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: 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