solidus_core 1.2.2 → 1.2.3

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: 9a74c842726347bde057601765d2a6401987bb21
4
- data.tar.gz: aa32d37bd70ac5bb4c7f06c35cd35b3ab165e1d1
3
+ metadata.gz: 0c0fea50cb0031d9a121c7abfb25c015c86542f5
4
+ data.tar.gz: 9294f4effa7875921c5deef2e05c69c52d6abddf
5
5
  SHA512:
6
- metadata.gz: 576bef445deb2e4f067d1dcb51ab0a1df2391e41d252b4a842a2eaffca9b7697c511e91988bdd2f34aeb740368ec1cd94b44ba3fb6837be35c86e7df6a4ab9a6
7
- data.tar.gz: 35be043f25fb4163902ee555e8dbe2103e1960cd1930df23836879dc94477c71c80231a4ac2dc3c3490c7912097db038db6d7b6ecd09afdd06819c81edda4f57
6
+ metadata.gz: 6e213a7266228cd8167cf8e1dab29442079d1bbb5a9eb885a9d30058b9110e95662b4984c4bb54248f1d9c98c7550e78b2483374b2895474b2ca38c2fbba94e9
7
+ data.tar.gz: 84b512524dc615c1803c2f4cd35039076f7e27b76bbe2a1ef8950a3a17d9423a21c64f0da75a4c177deff0db762cbbcc32bbdceb2b34c06e0ef09581ca98ea6f
@@ -681,6 +681,23 @@ module Spree
681
681
  Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: currency })
682
682
  end
683
683
 
684
+ def payments_attributes=(attributes)
685
+ validate_payments_attributes(attributes)
686
+ super(attributes)
687
+ end
688
+
689
+ def validate_payments_attributes(attributes)
690
+ attributes = Array.wrap(attributes)
691
+ # Ensure the payment methods specified are allowed for this user
692
+ payment_methods = Spree::PaymentMethod.where(id: available_payment_methods)
693
+ attributes.each do |payment_attributes|
694
+ payment_method_id = payment_attributes[:payment_method_id]
695
+
696
+ # raise RecordNotFound unless it is an allowed payment method
697
+ payment_methods.find(payment_method_id) if payment_method_id
698
+ end
699
+ end
700
+
684
701
  private
685
702
 
686
703
  def link_by_email
@@ -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
 
@@ -22,14 +22,14 @@ module Spree
22
22
  if respond_to?(:preference_source) && preference_source
23
23
  self.class.preference_sources[preference_source] || {}
24
24
  else
25
- super
25
+ self[:preferences]
26
26
  end
27
27
  end
28
28
 
29
29
  def preferences=(val)
30
30
  if respond_to?(:preference_source) && preference_source
31
31
  else
32
- super
32
+ self[:preferences] = val
33
33
  end
34
34
  end
35
35
  end
@@ -1,7 +1,7 @@
1
1
  eu_vat = Spree::Zone.find_or_create_by!(name: "EU_VAT", description: "Countries that make up the EU VAT zone.")
2
2
  north_america = Spree::Zone.find_or_create_by!(name: "North America", description: "USA + Canada")
3
3
 
4
- %w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG GB LT CY LU MT DK NL EE).
4
+ %w(PL FI PT RO DE FR SK HU SI IE AT ES IT BE SE LV BG GB LT CY LU MT DK NL EE HR CZ GR).
5
5
  each do |symbol|
6
6
  eu_vat.zone_members.create!(zoneable: Spree::Country.find_by!(iso: symbol))
7
7
  end
@@ -1,17 +1,19 @@
1
1
  class AddManyMissingIndexes < ActiveRecord::Migration
2
+ include Spree::MigrationHelpers
3
+
2
4
  def change
3
- add_index :spree_adjustments, [:adjustable_id, :adjustable_type]
4
- add_index :spree_adjustments, :eligible
5
- add_index :spree_adjustments, :order_id
6
- add_index :spree_promotions, :code
7
- add_index :spree_promotions, :expires_at
8
- add_index :spree_states, :country_id
9
- add_index :spree_stock_items, :deleted_at
10
- add_index :spree_option_types, :position
11
- add_index :spree_option_values, :position
12
- add_index :spree_product_option_types, :option_type_id
13
- add_index :spree_product_option_types, :product_id
14
- add_index :spree_products_taxons, :position
15
- add_index :spree_promotions, :starts_at
5
+ safe_add_index :spree_adjustments, [:adjustable_id, :adjustable_type]
6
+ safe_add_index :spree_adjustments, :eligible
7
+ safe_add_index :spree_adjustments, :order_id
8
+ safe_add_index :spree_promotions, :code
9
+ safe_add_index :spree_promotions, :expires_at
10
+ safe_add_index :spree_states, :country_id
11
+ safe_add_index :spree_stock_items, :deleted_at
12
+ safe_add_index :spree_option_types, :position
13
+ safe_add_index :spree_option_values, :position
14
+ safe_add_index :spree_product_option_types, :option_type_id
15
+ safe_add_index :spree_product_option_types, :product_id
16
+ safe_add_index :spree_products_taxons, :position
17
+ safe_add_index :spree_promotions, :starts_at
16
18
  end
17
19
  end
@@ -1,63 +1,65 @@
1
1
  class CorrectSomePolymorphicIndexAndAddMoreMissing < ActiveRecord::Migration
2
+ include Spree::MigrationHelpers
3
+
2
4
  def change
3
- add_index :spree_addresses, :country_id
4
- add_index :spree_addresses, :state_id
5
+ safe_add_index :spree_addresses, :country_id
6
+ safe_add_index :spree_addresses, :state_id
5
7
 
6
- remove_index :spree_adjustments, [:source_type, :source_id]
7
- add_index :spree_adjustments, [:source_id, :source_type]
8
+ safe_remove_index :spree_adjustments, [:source_type, :source_id]
9
+ safe_add_index :spree_adjustments, [:source_id, :source_type]
8
10
 
9
- add_index :spree_inventory_units, :return_authorization_id
11
+ safe_add_index :spree_inventory_units, :return_authorization_id
10
12
 
11
- add_index :spree_log_entries, [:source_id, :source_type]
13
+ safe_add_index :spree_log_entries, [:source_id, :source_type]
12
14
 
13
- add_index :spree_orders, :approver_id
14
- add_index :spree_orders, :created_by_id
15
- add_index :spree_orders, :ship_address_id
16
- add_index :spree_orders, :bill_address_id
17
- add_index :spree_orders, :considered_risky
15
+ safe_add_index :spree_orders, :approver_id
16
+ safe_add_index :spree_orders, :created_by_id
17
+ safe_add_index :spree_orders, :ship_address_id
18
+ safe_add_index :spree_orders, :bill_address_id
19
+ safe_add_index :spree_orders, :considered_risky
18
20
 
19
- add_index :spree_orders_promotions, [:order_id, :promotion_id]
21
+ safe_add_index :spree_orders_promotions, [:order_id, :promotion_id]
20
22
 
21
- add_index :spree_payments, [:source_id, :source_type]
23
+ safe_add_index :spree_payments, [:source_id, :source_type]
22
24
 
23
- add_index :spree_product_option_types, :position
25
+ safe_add_index :spree_product_option_types, :position
24
26
 
25
- add_index :spree_product_properties, :position
26
- add_index :spree_product_properties, :property_id
27
+ safe_add_index :spree_product_properties, :position
28
+ safe_add_index :spree_product_properties, :property_id
27
29
 
28
- add_index :spree_promotion_action_line_items, :promotion_action_id
29
- add_index :spree_promotion_action_line_items, :variant_id
30
+ safe_add_index :spree_promotion_action_line_items, :promotion_action_id
31
+ safe_add_index :spree_promotion_action_line_items, :variant_id
30
32
 
31
- add_index :spree_promotion_rules, :promotion_id
33
+ safe_add_index :spree_promotion_rules, :promotion_id
32
34
 
33
- add_index :spree_promotions, :advertise
35
+ safe_add_index :spree_promotions, :advertise
34
36
 
35
- add_index :spree_return_authorizations, :number
36
- add_index :spree_return_authorizations, :order_id
37
- add_index :spree_return_authorizations, :stock_location_id
37
+ safe_add_index :spree_return_authorizations, :number
38
+ safe_add_index :spree_return_authorizations, :order_id
39
+ safe_add_index :spree_return_authorizations, :stock_location_id
38
40
 
39
- add_index :spree_shipments, :address_id
41
+ safe_add_index :spree_shipments, :address_id
40
42
 
41
- add_index :spree_shipping_methods, :tax_category_id
43
+ safe_add_index :spree_shipping_methods, :tax_category_id
42
44
 
43
- add_index :spree_state_changes, [:stateful_id, :stateful_type]
44
- add_index :spree_state_changes, :user_id
45
+ safe_add_index :spree_state_changes, [:stateful_id, :stateful_type]
46
+ safe_add_index :spree_state_changes, :user_id
45
47
 
46
- add_index :spree_stock_locations, :country_id
47
- add_index :spree_stock_locations, :state_id
48
+ safe_add_index :spree_stock_locations, :country_id
49
+ safe_add_index :spree_stock_locations, :state_id
48
50
 
49
- add_index :spree_tax_rates, :deleted_at
50
- add_index :spree_tax_rates, :tax_category_id
51
- add_index :spree_tax_rates, :zone_id
51
+ safe_add_index :spree_tax_rates, :deleted_at
52
+ safe_add_index :spree_tax_rates, :tax_category_id
53
+ safe_add_index :spree_tax_rates, :zone_id
52
54
 
53
- add_index :spree_taxonomies, :position
55
+ safe_add_index :spree_taxonomies, :position
54
56
 
55
- add_index :spree_taxons, :position
57
+ safe_add_index :spree_taxons, :position
56
58
 
57
- add_index :spree_variants, :position
58
- add_index :spree_variants, :track_inventory
59
+ safe_add_index :spree_variants, :position
60
+ safe_add_index :spree_variants, :track_inventory
59
61
 
60
- add_index :spree_zone_members, :zone_id
61
- add_index :spree_zone_members, [:zoneable_id, :zoneable_type]
62
+ safe_add_index :spree_zone_members, :zone_id
63
+ safe_add_index :spree_zone_members, [:zoneable_id, :zoneable_type]
62
64
  end
63
65
  end
@@ -1,6 +1,8 @@
1
1
  class UpdateProductSlugIndex < ActiveRecord::Migration
2
+ include Spree::MigrationHelpers
3
+
2
4
  def change
3
- remove_index :spree_products, :slug
4
- add_index :spree_products, :slug, unique: true
5
+ safe_remove_index :spree_products, :slug
6
+ safe_add_index :spree_products, :slug, unique: true
5
7
  end
6
8
  end
@@ -4,6 +4,8 @@
4
4
  # migration deletes any of the indexes left around in stores using the
5
5
  # out-dated version of that migration
6
6
  class RemoveUnnecessaryIndexes < ActiveRecord::Migration
7
+ include Spree::MigrationHelpers
8
+
7
9
  def up
8
10
  safe_remove_index :spree_credit_cards, :address_id
9
11
  safe_remove_index :spree_gateways, :active
@@ -59,14 +61,4 @@ class RemoveUnnecessaryIndexes < ActiveRecord::Migration
59
61
  safe_add_index :spree_variants, :deleted_at
60
62
  safe_add_index :spree_zones, :default_tax
61
63
  end
62
-
63
- private
64
-
65
- def safe_remove_index(table, column)
66
- remove_index(table, column) if index_exists?(table, column)
67
- end
68
-
69
- def safe_add_index(table, column)
70
- add_index(table, column) if column_exists?(table, column)
71
- end
72
64
  end
@@ -126,7 +126,7 @@ end
126
126
  core_gems = ["spree/core", "spree/api", "spree/backend", "spree/frontend"]
127
127
 
128
128
  if core_gems.include?(lib_name)
129
- '../../../../../Gemfile'
129
+ '../../../../Gemfile'
130
130
  else
131
131
  '../../../../Gemfile'
132
132
  end
@@ -7,7 +7,4 @@
7
7
  //= require jquery
8
8
  //= require jquery_ujs
9
9
  //= require spree/backend
10
- <% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/backend' %>
11
- //= require spree/backend/<%= options[:lib_name].gsub("/", "_") %>
12
- <% end %>
13
10
  //= require_tree .
@@ -7,7 +7,4 @@
7
7
  //= require jquery
8
8
  //= require jquery_ujs
9
9
  //= require spree/frontend
10
- <% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/frontend' %>
11
- //= require spree/frontend/<%= options[:lib_name].gsub("/", "_") %>
12
- <% end %>
13
10
  //= require_tree .
@@ -4,9 +4,6 @@
4
4
  * the top of the compiled file, but it's generally better to create a new file per style scope.
5
5
  *
6
6
  *= require spree/backend
7
- <% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/backend' %>
8
- *= require spree/backend/<%= options[:lib_name].gsub("/", "_") %>
9
- <% end %>
10
7
  *= require_self
11
8
  *= require_tree .
12
9
  */
@@ -4,9 +4,6 @@
4
4
  * the top of the compiled file, but it's generally better to create a new file per style scope.
5
5
  *
6
6
  *= require spree/frontend
7
- <% unless options[:lib_name] == 'spree' || options[:lib_name] == 'spree/frontend' %>
8
- *= require spree/frontend/<%= options[:lib_name].gsub("/", "_") %>
9
- <% end %>
10
7
  *= require_self
11
8
  *= require_tree .
12
9
  */
data/lib/spree/core.rb CHANGED
@@ -70,6 +70,7 @@ require 'spree/core/environment/calculators'
70
70
  require 'spree/core/environment'
71
71
  require 'spree/promo/environment'
72
72
  require 'spree/migrations'
73
+ require 'spree/migration_helpers'
73
74
  require 'spree/core/engine'
74
75
 
75
76
  require 'spree/i18n'
@@ -5,7 +5,7 @@ module Spree
5
5
  end
6
6
 
7
7
  def self.solidus_version
8
- "1.2.2"
8
+ "1.2.3"
9
9
  end
10
10
 
11
11
  def self.solidus_gem_version
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module MigrationHelpers
3
+ def safe_remove_index(table, column)
4
+ remove_index(table, column) if index_exists?(table, column)
5
+ end
6
+
7
+ def safe_add_index(table, column, options = {})
8
+ if columns_exist?(table, column) && !index_exists?(table, column, options)
9
+ add_index(table, column, options)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def columns_exist?(table, columns)
16
+ Array.wrap(columns).all? { |column| column_exists?(table, column) }
17
+ end
18
+ end
19
+ end
@@ -1411,4 +1411,56 @@ describe Spree::Order, :type => :model do
1411
1411
  end
1412
1412
  end
1413
1413
  end
1414
+
1415
+ describe "#validate_payments_attributes" do
1416
+ let(:attributes) { [ActionController::Parameters.new(payment_method_id: payment_method.id)] }
1417
+ subject do
1418
+ order.validate_payments_attributes(attributes)
1419
+ end
1420
+
1421
+ context "with empty array" do
1422
+ let(:attributes) { [] }
1423
+ it "doesn't error" do
1424
+ subject
1425
+ end
1426
+ end
1427
+
1428
+ context "with no payment method specified" do
1429
+ let(:attributes) { [ActionController::Parameters.new({})] }
1430
+ it "doesn't error" do
1431
+ subject
1432
+ end
1433
+ end
1434
+
1435
+ context "with valid payment method" do
1436
+ let(:payment_method) { create(:check_payment_method) }
1437
+ it "doesn't error" do
1438
+ subject
1439
+ end
1440
+ end
1441
+
1442
+ context "with inactive payment method" do
1443
+ let(:payment_method) { create(:check_payment_method, active: false) }
1444
+
1445
+ it "raises RecordNotFound" do
1446
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1447
+ end
1448
+ end
1449
+
1450
+ context "with unavailable payment method" do
1451
+ let(:payment_method) { create(:check_payment_method, display_on: "back_end") }
1452
+
1453
+ it "raises RecordNotFound" do
1454
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1455
+ end
1456
+ end
1457
+
1458
+ context "with soft-deleted payment method" do
1459
+ let(:payment_method) { create(:check_payment_method, deleted_at: Time.current) }
1460
+
1461
+ it "raises RecordNotFound" do
1462
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
1463
+ end
1464
+ end
1465
+ end
1414
1466
  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
@@ -661,12 +661,13 @@ describe Spree::Payment, :type => :model do
661
661
  end
662
662
 
663
663
  context "completed orders" do
664
+ let(:payment_method) { create(:check_payment_method) }
664
665
  before { allow(order).to receive_messages completed?: true }
665
666
 
666
667
  it "updates payment_state and shipments" do
667
668
  expect(order.updater).to receive(:update_payment_state)
668
669
  expect(order.updater).to receive(:update_shipment_state)
669
- Spree::Payment.create(:amount => 100, :order => order)
670
+ Spree::Payment.create!(amount: 100, order: order, payment_method: payment_method)
670
671
  end
671
672
  end
672
673
 
@@ -9,6 +9,10 @@ module Spree
9
9
  def initialize
10
10
  @preferences = {color: 'blue'}
11
11
  end
12
+
13
+ def [](key)
14
+ return @preferences if key == :preferences
15
+ end
12
16
  end
13
17
  end
14
18
  let(:klass) 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: 1.2.2
4
+ version: 1.2.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: 2016-03-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
@@ -936,6 +936,7 @@ files:
936
936
  - lib/spree/localized_number.rb
937
937
  - lib/spree/mailer_previews/carton_preview.rb
938
938
  - lib/spree/mailer_previews/order_preview.rb
939
+ - lib/spree/migration_helpers.rb
939
940
  - lib/spree/migrations.rb
940
941
  - lib/spree/money.rb
941
942
  - lib/spree/permission_sets.rb
@@ -1367,7 +1368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1367
1368
  version: '0'
1368
1369
  requirements: []
1369
1370
  rubyforge_project:
1370
- rubygems_version: 2.5.1
1371
+ rubygems_version: 2.6.11
1371
1372
  signing_key:
1372
1373
  specification_version: 4
1373
1374
  summary: Essential models, mailers, and classes for the Solidus e-commerce project.