solidus_core 2.11.5 → 2.11.10

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
  SHA256:
3
- metadata.gz: 5e525e5e27176da6331f5bce6a0075f2c06f2da77f9d8aad9d78a861a121219c
4
- data.tar.gz: f828d4522d8c58822fc71daa609b7411102dbdcf55e7abb4f582102c23ddbfbd
3
+ metadata.gz: 8eb3e5a4b41af8809472fc7d7875fd2be9101bc2673b2d289bc32e5f6bc0cabc
4
+ data.tar.gz: 48aac9f88550bbaa4ce69271426877fed50459b23c5fe3109bed565e553fe0b3
5
5
  SHA512:
6
- metadata.gz: ca14ba69f5a7347fd1bc88d8d209e4ffbe2d4a9419fd257f036391d55581250569ac66683a6b5c27a1342f4b5f8120b0483ba16538f8107ded796bda44551c6d
7
- data.tar.gz: f36de4fb9dc7addc88b586277f111b854dbbcfba3d586d52a62c2c4aaddc19e6bf536b74151a461df11566d3609df6fbc60889e70b9bbded67dc6ae740ae64dc
6
+ metadata.gz: 7b3adaf152c0e1a8bf34de8bf8577a8a369e51a6acb0215b558f055a1235b1b7499e50778cc040cf08221ee98d79df07d72b9112f61ad3158dd226b5c8af73e1
7
+ data.tar.gz: dd950b0d62311e85c9e72cea449650b04d9388c2443e1dbb187bc885bf24f128338fb96e0b0b5eb177b9b444c2bb738b8d59d6bfdb298eb774b7391367e15b2d
@@ -107,6 +107,8 @@ module Spree
107
107
 
108
108
  def url(style = default_style)
109
109
  attachment.url(style)
110
+ rescue ActiveStorage::FileNotFoundError
111
+ "noimage/#{style}.png"
110
112
  end
111
113
 
112
114
  def destroy_attachment(_name)
@@ -9,11 +9,9 @@ module Spree
9
9
  class Attachment
10
10
  delegate_missing_to :@attachment
11
11
 
12
- DEFAULT_SIZE = '100%'
13
-
14
12
  def initialize(attachment, styles: {})
15
13
  @attachment = attachment
16
- @styles = styles
14
+ @styles = normalize_styles(styles)
17
15
  end
18
16
 
19
17
  def exists?
@@ -21,20 +19,18 @@ module Spree
21
19
  end
22
20
 
23
21
  def filename
24
- blob.filename.to_s
22
+ blob&.filename.to_s
25
23
  end
26
24
 
27
25
  def url(style = nil)
28
- variant(style).url
26
+ variant(style)&.url
29
27
  end
30
28
 
31
29
  def variant(style = nil)
32
- size = style_to_size(style&.to_sym)
30
+ size = style_to_size(style)
33
31
  @attachment.variant(
34
- resize: size,
35
- strip: true,
36
- 'auto-orient': true,
37
- colorspace: 'sRGB',
32
+ resize_to_limit: size,
33
+ strip: true
38
34
  ).processed
39
35
  end
40
36
 
@@ -61,8 +57,12 @@ module Spree
61
57
  @attachment.metadata
62
58
  end
63
59
 
60
+ def normalize_styles(styles)
61
+ styles.transform_values { |v| v.split('x') }
62
+ end
63
+
64
64
  def style_to_size(style)
65
- @styles.fetch(style) { DEFAULT_SIZE }
65
+ @styles.fetch(style&.to_sym) { [width, height] }
66
66
  end
67
67
  end
68
68
  end
@@ -1,24 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  class Spree::Base < ActiveRecord::Base
4
- include Spree::Preferences::Preferable
5
6
  include Spree::Core::Permalinks
6
7
  include Spree::RansackableAttributes
7
8
 
8
- def initialize_preference_defaults
9
- if has_attribute?(:preferences)
10
- self.preferences = default_preferences.merge(preferences)
11
- end
9
+ def self.preference(*args)
10
+ Spree::Deprecation.warn <<~WARN
11
+ #{name} has a `preferences` column, but does not explicitly (de)serialize this column.
12
+ In order to make #{name} work with future versions of Solidus (and Rails), please add the
13
+ following line to your class:
14
+ ```
15
+ class #{name}
16
+ include Spree::Preferences::Persistable
17
+ ...
18
+ end
19
+ ```
20
+ WARN
21
+ include Spree::Preferences::Persistable
22
+ preference(*args)
12
23
  end
13
24
 
14
- # Only run preference initialization on models which requires it. Improves
15
- # performance of record initialization slightly.
16
- def self.preference(*args)
17
- # after_initialize can be called multiple times with the same symbol, it
18
- # will only be called once on initialization.
19
- serialize :preferences, Hash
20
- after_initialize :initialize_preference_defaults
21
- super
25
+ def preferences
26
+ value = read_attribute(:preferences)
27
+ if !value.is_a?(Hash)
28
+ Spree::Deprecation.warn <<~WARN
29
+ #{self.class.name} has a `preferences` column, but does not explicitly (de)serialize this column.
30
+ In order to make #{self.class.name} work with future versions of Solidus (and Rails), please add the
31
+ following lines to your class:
32
+ ```
33
+ class #{self.class.name}
34
+ include Spree::Preferences::Persistable
35
+ ...
36
+ end
37
+ ```
38
+ WARN
39
+ self.class.include Spree::Preferences::Persistable
40
+
41
+ ActiveRecord::Type::Serialized.new(
42
+ ActiveRecord::Type::Text.new,
43
+ ActiveRecord::Coders::YAMLColumn.new(:preferences, Hash)
44
+ ).deserialize(value)
45
+ else
46
+ value
47
+ end
22
48
  end
23
49
 
24
50
  if Kaminari.config.page_method_name != :page
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  module Spree
4
6
  class Calculator < Spree::Base
7
+ include Spree::Preferences::Persistable
8
+
5
9
  belongs_to :calculable, polymorphic: true, optional: true
6
10
 
7
11
  # This method calls a compute_<computable> method. must be overriden in concrete calculator.
@@ -7,6 +7,10 @@ module Spree::Image::ActiveStorageAttachment
7
7
  delegate :width, :height, to: :attachment, prefix: true
8
8
 
9
9
  included do
10
+ validates :attachment, presence: true
11
+ validate :attachment_is_an_image
12
+ validate :supported_content_type
13
+
10
14
  has_attachment :attachment,
11
15
  styles: {
12
16
  mini: '48x48>',
@@ -15,7 +19,11 @@ module Spree::Image::ActiveStorageAttachment
15
19
  large: '1200x1200>'
16
20
  },
17
21
  default_style: :product
18
- validates :attachment, presence: true
19
- validate :attachment_is_an_image
22
+
23
+ def supported_content_type
24
+ unless attachment.content_type.in?(Spree::Config.allowed_image_mime_types)
25
+ errors.add(:attachment, :content_type_not_supported)
26
+ end
27
+ end
20
28
  end
21
29
  end
@@ -15,7 +15,7 @@ module Spree::Image::PaperclipAttachment
15
15
  convert_options: { all: '-strip -auto-orient -colorspace sRGB' }
16
16
  validates_attachment :attachment,
17
17
  presence: true,
18
- content_type: { content_type: %w[image/jpeg image/jpg image/png image/gif] }
18
+ content_type: { content_type: Spree::Config.allowed_image_mime_types }
19
19
 
20
20
  # save the w,h of the original image (from which others can be calculated)
21
21
  # we need to look at the write-queue for images which have not been saved yet
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
3
4
  require 'spree/preferences/statically_configurable'
4
5
 
5
6
  module Spree
@@ -11,6 +12,8 @@ module Spree
11
12
  # This class is not meant to be instantiated. Please create instances of concrete payment methods.
12
13
  #
13
14
  class PaymentMethod < Spree::Base
15
+ include Spree::Preferences::Persistable
16
+
14
17
  preference :server, :string, default: 'test'
15
18
  preference :test_mode, :boolean, default: true
16
19
 
@@ -9,6 +9,10 @@ module Spree
9
9
 
10
10
  VALID_CCS = ['1', TEST_VISA, TEST_MC, TEST_AMEX, TEST_DISC].flatten
11
11
 
12
+ AUTHORIZATION_CODE = '12345'
13
+ FAILURE_MESSAGE = 'Bogus Gateway: Forced failure'
14
+ SUCCESS_MESSAGE = 'Bogus Gateway: Forced success'
15
+
12
16
  attr_accessor :test
13
17
 
14
18
  def gateway_class
@@ -26,40 +30,40 @@ module Spree
26
30
  def authorize(_money, credit_card, _options = {})
27
31
  profile_id = credit_card.gateway_customer_profile_id
28
32
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
29
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'D' })
33
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'D' })
30
34
  else
31
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
35
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, { message: FAILURE_MESSAGE }, test: true)
32
36
  end
33
37
  end
34
38
 
35
39
  def purchase(_money, credit_card, _options = {})
36
40
  profile_id = credit_card.gateway_customer_profile_id
37
41
  if VALID_CCS.include?(credit_card.number) || (profile_id && profile_id.starts_with?('BGS-'))
38
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'M' })
42
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'M' })
39
43
  else
40
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
44
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true)
41
45
  end
42
46
  end
43
47
 
44
48
  def credit(_money, _credit_card, _response_code, _options = {})
45
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
49
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
46
50
  end
47
51
 
48
52
  def capture(_money, authorization, _gateway_options)
49
53
  if authorization == '12345'
50
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true)
54
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true)
51
55
  else
52
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', error: 'Bogus Gateway: Forced failure', test: true)
56
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, error: FAILURE_MESSAGE, test: true)
53
57
  end
54
58
  end
55
59
 
56
60
  def void(_response_code, _credit_card, _options = {})
57
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
61
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
58
62
  end
59
63
 
60
64
  # @see Spree::PaymentMethod#try_void
61
65
  def try_void(_payment)
62
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
66
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE)
63
67
  end
64
68
 
65
69
  def test?
@@ -9,17 +9,17 @@ module Spree
9
9
 
10
10
  def authorize(_money, credit_card, _options = {})
11
11
  if VALID_CCS.include? credit_card.number
12
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'A' })
12
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' })
13
13
  else
14
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
14
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, { message: FAILURE_MESSAGE }, test: true)
15
15
  end
16
16
  end
17
17
 
18
18
  def purchase(_money, credit_card, _options = {})
19
19
  if VALID_CCS.include? credit_card.number
20
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'A' })
20
+ ActiveMerchant::Billing::Response.new(true, SUCCESS_MESSAGE, {}, test: true, authorization: AUTHORIZATION_CODE, avs_result: { code: 'A' })
21
21
  else
22
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
22
+ ActiveMerchant::Billing::Response.new(false, FAILURE_MESSAGE, message: FAILURE_MESSAGE, test: true)
23
23
  end
24
24
  end
25
25
  end
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  module Spree
4
6
  # Base class for all types of promotion action.
5
7
  #
6
8
  # PromotionActions perform the necessary tasks when a promotion is activated
7
9
  # by an event and determined to be eligible.
8
10
  class PromotionAction < Spree::Base
11
+ include Spree::Preferences::Persistable
9
12
  include Spree::SoftDeletable
10
13
 
11
14
  belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_actions, optional: true
@@ -1,8 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spree/preferences/persistable'
4
+
3
5
  module Spree
4
6
  # Base class for all promotion rules
5
7
  class PromotionRule < Spree::Base
8
+ include Spree::Preferences::Persistable
9
+
6
10
  belongs_to :promotion, class_name: 'Spree::Promotion', inverse_of: :promotion_rules, optional: true
7
11
 
8
12
  scope :of_type, ->(type) { where(type: type) }
@@ -48,6 +48,10 @@ module Spree
48
48
  return true if perform_after_create == false
49
49
  return true if transaction_id.present?
50
50
 
51
+ # This is needed otherwise set_perform_after_create_default callback
52
+ # will print a deprecation warning when save! creates a record
53
+ self.perform_after_create = false unless persisted?
54
+
51
55
  credit_cents = money.cents
52
56
 
53
57
  @perform_response = process!(credit_cents)
@@ -63,9 +67,7 @@ module Spree
63
67
  log_entries.build(details: perform_response.to_yaml)
64
68
 
65
69
  self.transaction_id = perform_response.authorization
66
- # This is needed otherwise set_perform_after_create_default callback
67
- # will print a deprecation warning when save! creates a record.
68
- self.perform_after_create = false unless persisted?
70
+
69
71
  save!
70
72
 
71
73
  update_order
@@ -171,7 +171,7 @@ module Solidus
171
171
  end
172
172
 
173
173
  bundle_cleanly{ run "bundle install" } if @plugins_to_be_installed.any?
174
- run "spring stop"
174
+ run "spring stop" if defined?(Spring)
175
175
 
176
176
  @plugin_generators_to_run.each do |plugin_generator_name|
177
177
  generate "#{plugin_generator_name} --skip_migrations=false"
@@ -504,6 +504,14 @@ module Spree
504
504
  # Enumerable of images adhering to the present_image_class interface
505
505
  class_name_attribute :image_attachment_module, default: 'Spree::Image::PaperclipAttachment'
506
506
 
507
+ # @!attribute [rw] allowed_image_mime_types
508
+ #
509
+ # Defines which MIME types are allowed for images
510
+ # `%w(image/jpeg image/jpg image/png image/gif).freeze` is the default.
511
+ #
512
+ # @return [Array]
513
+ class_name_attribute :allowed_image_mime_types, default: %w(image/jpeg image/jpg image/png image/gif).freeze
514
+
507
515
  # Allows switching attachment library for Taxon
508
516
  #
509
517
  # `Spree::Taxon::PaperclipAttachment`
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Spree
4
- VERSION = "2.11.5"
4
+ VERSION = "2.11.10"
5
5
 
6
6
  def self.solidus_version
7
7
  VERSION
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Preferences
5
+ module Persistable
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ include Spree::Preferences::Preferable
10
+ serialize :preferences, Hash
11
+ after_initialize :initialize_preference_defaults
12
+ end
13
+
14
+ private
15
+
16
+ def initialize_preference_defaults
17
+ if has_attribute?(:preferences)
18
+ self.preferences = default_preferences.merge(preferences)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -25,7 +25,7 @@ module Spree
25
25
  factory_bot_paths: "Spree::TestingSupport::FactoryBot.definition_file_paths",
26
26
  check_factory_bot_version: "Spree::TestingSupport::FactoryBot.check_version",
27
27
  load_all_factories: "Spree::TestingSupport::FactoryBot.add_paths_and_load!",
28
- deprecator: Spree::Deprecator
28
+ deprecator: Spree::Deprecation
29
29
  )
30
30
  end
31
31
  end
@@ -0,0 +1 @@
1
+ This is a text file
@@ -6,26 +6,14 @@ namespace :solidus do
6
6
  task up: :environment do
7
7
  print "Migrating default billing addresses to address book ... "
8
8
  if Spree::UserAddress.where(default_billing: true).any?
9
- Spree::LegacyUser.joins(:bill_address).update_all(bill_address_id: nil) # rubocop:disable Rails/SkipsModelValidations
9
+ Spree.user_class.joins(:bill_address).update_all(bill_address_id: nil) # rubocop:disable Rails/SkipsModelValidations
10
10
  end
11
- adapter_type = Spree::Base.connection.adapter_name.downcase.to_sym
12
- if adapter_type == :mysql2
13
- sql = <<~SQL
14
- UPDATE spree_user_addresses
11
+ Spree::UserAddress.joins(
12
+ <<~SQL
15
13
  JOIN spree_users ON spree_user_addresses.user_id = spree_users.id
16
- AND spree_user_addresses.address_id = spree_users.bill_address_id
17
- SET spree_user_addresses.default_billing = true
14
+ AND spree_user_addresses.address_id = spree_users.bill_address_id
18
15
  SQL
19
- else
20
- sql = <<~SQL
21
- UPDATE spree_user_addresses
22
- SET default_billing = true
23
- FROM spree_users
24
- WHERE spree_user_addresses.address_id = spree_users.bill_address_id
25
- AND spree_user_addresses.user_id = spree_users.id;
26
- SQL
27
- end
28
- Spree::Base.connection.execute sql
16
+ ).update_all(default_billing: true)
29
17
  puts "Success"
30
18
  end
31
19
 
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.11.5
4
+ version: 2.11.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-10 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -829,6 +829,7 @@ files:
829
829
  - lib/spree/permission_sets/user_management.rb
830
830
  - lib/spree/permitted_attributes.rb
831
831
  - lib/spree/preferences/configuration.rb
832
+ - lib/spree/preferences/persistable.rb
832
833
  - lib/spree/preferences/preferable.rb
833
834
  - lib/spree/preferences/preferable_class_methods.rb
834
835
  - lib/spree/preferences/scoped_store.rb
@@ -918,6 +919,7 @@ files:
918
919
  - lib/spree/testing_support/factories/zone_factory.rb
919
920
  - lib/spree/testing_support/factory_bot.rb
920
921
  - lib/spree/testing_support/fixtures/blank.jpg
922
+ - lib/spree/testing_support/fixtures/file.txt
921
923
  - lib/spree/testing_support/flash.rb
922
924
  - lib/spree/testing_support/job_helpers.rb
923
925
  - lib/spree/testing_support/order_walkthrough.rb