Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 7.1 support #5359

Merged
merged 24 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ee30487
Update ransack to last released v4 version.
peterberkenbosch Aug 26, 2023
0a276d2
Specifiy coder for serialize attributes.
peterberkenbosch Aug 26, 2023
7906cf5
Remove unused action on the before_action callback
peterberkenbosch Aug 26, 2023
aab04a3
Use 'main' instead of 'master'
peterberkenbosch Aug 26, 2023
db5fd5f
Add Rails 7.1 supported database_cleaner gem
peterberkenbosch Aug 26, 2023
8f1ec11
Fix `alias_method` used on an aliased attribute
peterberkenbosch Sep 1, 2023
a4aea38
Allow Rails 7.1 and up
peterberkenbosch Oct 8, 2023
bf87f5a
Use correct renamed behavior module for testing.
peterberkenbosch Oct 12, 2023
e683524
Use up-to-date rspec-rails gem
peterberkenbosch Oct 12, 2023
eeaf72c
Add Rails 7.1 to Circle CI Matrix
peterberkenbosch Oct 12, 2023
6e6d66e
Bump axe-core specs to fix false negative in admin
peterberkenbosch Oct 12, 2023
a240dab
Default to Rails 7.1 in development
kennyadsl Dec 6, 2023
e78a836
Remove deprecated usage of alias_attributes
kennyadsl Dec 6, 2023
0a97cc2
Fix Set-Cookie header domain in tests for Rails 7.1
kennyadsl Dec 6, 2023
fb15c4c
Fix warining about SchemaMigration no longer inheriting from ActiveRe…
spaghetticode Dec 13, 2023
de9d3ad
Replace explicit shipping_address and billing_address attributes
spaghetticode Dec 14, 2023
9b194e2
Convert helper output_buffer to string
spaghetticode Dec 14, 2023
532dec4
Fix the encrypted preference spec by allowing other calls to ENV
elia Dec 20, 2023
5ef1803
Setup the active storage configuration
elia Dec 20, 2023
85b35ad
Fix preview paths to work with Rails 7.1
kennyadsl Dec 6, 2023
f6047e7
Don't define the `with_values` scope for Rails 7.1+
peterberkenbosch Aug 26, 2023
95a0b09
Avoid using deprecated constants when logging VC rendering
elia Dec 21, 2023
2739f7b
Add a note about the value of `action_dispatch.show_exceptions`
elia Dec 21, 2023
66b325f
Run the solidus installer on Rails 7.1
elia Dec 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ commands:
ruby -v >> /tmp/.ruby-versions
gem --version >> /tmp/.gems-versions
bundle --version >> /tmp/.gems-versions
gem search -eq rails -v "~> 7" -v"< 7.1" >> /tmp/.gems-versions # get the latest rails from rubygems
gem search -eq rails -v "~> 7" -v "< 7.2" >> /tmp/.gems-versions # get the latest rails from rubygems
gem search -eq solidus >> /tmp/.gems-versions # get the latest solidus from rubygems

cat /tmp/.ruby-versions
Expand Down Expand Up @@ -358,10 +358,10 @@ workflows:
# https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html.
- test_solidus:
name: &name "test-rails-<<matrix.rails>>-ruby-<<matrix.ruby>>-<<matrix.database>>-<<#matrix.paperclip>>paperclip<</matrix.paperclip>><<^matrix.paperclip>>activestorage<</matrix.paperclip>>"
matrix: { parameters: { rails: ['7.0'], ruby: ['3.0'], database: ['mysql'], paperclip: [true] } }
matrix: { parameters: { rails: ['7.0', '7.1'], ruby: ['3.0'], database: ['mysql'], paperclip: [true] } }
- test_solidus:
name: *name
matrix: { parameters: { rails: ['7.0'], ruby: ['3.1'], database: ['postgres'], paperclip: [false] } }
matrix: { parameters: { rails: ['7.0', '7.1'], ruby: ['3.1'], database: ['postgres'], paperclip: [false] } }
- test_solidus:
name: *name
matrix: { parameters: { rails: ['7.0'], ruby: ['3.2'], database: ['sqlite'], paperclip: [false] } }
matrix: { parameters: { rails: ['7.0', '7.1'], ruby: ['3.2'], database: ['sqlite'], paperclip: [false] } }
12 changes: 6 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ source 'https://rubygems.org'
gemspec require: false

# rubocop:disable Bundler/DuplicatedGem
if ENV['RAILS_VERSION'] == 'master'
if ENV['RAILS_VERSION'] == 'main'
gem 'rails', github: 'rails', require: false
else
gem 'rails', ENV['RAILS_VERSION'] || '~> 7.0.2', require: false
gem 'rails', ENV['RAILS_VERSION'] || '~> 7.1.0', require: false
end
# rubocop:enable Bundler/DuplicatedGem

Expand All @@ -25,9 +25,9 @@ gem 'mysql2', '~> 0.5.0', require: false if dbs.match?(/all|mysql/)
gem 'pg', '~> 1.0', require: false if dbs.match?(/all|postgres/)
gem 'fast_sqlite', require: false if dbs.match?(/all|sqlite/)

gem 'database_cleaner', '~> 1.3', require: false
gem 'database_cleaner', '~> 2.0', require: false
gem 'rspec-activemodel-mocks', '~> 1.1', require: false
gem 'rspec-rails', '~> 4.0.1', require: false
gem 'rspec-rails', '~> 6.0.3', require: false
gem 'rspec-retry', '~> 0.6.2', require: false
gem 'simplecov', require: false
gem 'simplecov-cobertura', require: false
Expand Down Expand Up @@ -55,8 +55,8 @@ end
group :admin do
gem 'solidus_admin', path: 'admin', require: false
gem 'tailwindcss-rails', '~> 2.0', require: false
gem 'axe-core-rspec', '~> 4.7', require: false
gem 'axe-core-capybara', '~> 4.7', require: false
gem 'axe-core-rspec', '~> 4.8', require: false
gem 'axe-core-capybara', '~> 4.8', require: false
end

group :lint do
Expand Down
4 changes: 2 additions & 2 deletions admin/config/initializers/view_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
Rails.application.config.view_component.instrumentation_enabled = true
Rails.application.config.view_component.use_deprecated_instrumentation_name = false

bold = ActiveSupport::LogSubscriber::BOLD
clear = ActiveSupport::LogSubscriber::CLEAR
bold = "\e[1m"
clear = "\e[0m"

ActiveSupport::Notifications.subscribe("render.view_component") do |*args|
next unless args.last[:name].starts_with?("SolidusAdmin::")
Expand Down
4 changes: 2 additions & 2 deletions admin/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
require "rails/version"
require "rails/generators"
require "rails/generators/app_base"
require "rails/generators/testing/behaviour"
require "rails/generators/testing/behavior"

# AXE - ACCESSIBILITY
require 'axe-rspec'
Expand Down Expand Up @@ -119,7 +119,7 @@
config.include ViewComponent::SystemTestHelpers, type: :component
config.include SolidusAdmin::ComponentHelpers, type: :component

config.include Rails::Generators::Testing::Behaviour, type: :generator
config.include Rails::Generators::Testing::Behavior, type: :generator
config.include FileUtils, type: :generator
config.before type: :generator do
self.generator_class = described_class
Expand Down
4 changes: 2 additions & 2 deletions backend/app/controllers/spree/admin/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module Spree
module Admin
class OrdersController < Spree::Admin::BaseController
before_action :initialize_order_events
before_action :load_order, only: [:edit, :update, :complete, :advance, :cancel, :resume, :approve, :resend, :unfinalize_adjustments, :finalize_adjustments, :cart, :confirm]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good finding! Did you check if we also have a (unused) route for this action?

around_action :lock_order, only: [:update, :advance, :complete, :confirm, :cancel, :resume, :approve, :resend]
before_action :load_order, only: [:edit, :complete, :advance, :cancel, :resume, :approve, :resend, :unfinalize_adjustments, :finalize_adjustments, :cart, :confirm]
around_action :lock_order, only: [:advance, :complete, :confirm, :cancel, :resume, :approve, :resend]

rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
respond_to :html
Expand Down
6 changes: 4 additions & 2 deletions core/app/models/spree/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class Address < Spree::Base

self.allowed_ransackable_attributes = %w[name]

scope :with_values, ->(attributes) do
where(value_attributes(attributes))
unless ActiveRecord::Relation.method_defined? :with_values # Rails 7.1+
scope :with_values, ->(attributes) do
where(value_attributes(attributes))
end
end

# @return [Address] an address with default attributes
Expand Down
9 changes: 6 additions & 3 deletions core/app/models/spree/credit_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class CreditCard < Spree::PaymentSource

scope :with_payment_profile, -> { where('gateway_customer_profile_id IS NOT NULL') }

# needed for some of the ActiveMerchant gateways (eg. SagePay)
alias_attribute :brand, :cc_type

# Taken from ActiveMerchant
# https://github.com/activemerchant/active_merchant/blob/2f2acd4696e8de76057b5ed670b9aa022abc1187/lib/active_merchant/billing/credit_card_methods.rb#L5
CARD_TYPES = {
Expand Down Expand Up @@ -95,6 +92,12 @@ def cc_type=(type)
end
end

# needed for some of the ActiveMerchant gateways (eg. SagePay)
alias_attribute :brand, :cc_type

# Rails 7.1+ won't use the custom setter with alias_attribute
alias_method :brand=, :cc_type=

# Sets the last digits field based on the assigned credit card number.
def set_last_digits
self.last_digits ||= number.to_s.length <= 4 ? number : number.to_s.slice(-4..)
Expand Down
8 changes: 6 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ class CannotRebuildShipments < StandardError; end

# Customer info
belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true

belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address', optional: true
alias_attribute :billing_address, :bill_address
alias_method :billing_address, :bill_address
elia marked this conversation as resolved.
Show resolved Hide resolved
alias_method :billing_address=, :bill_address=

belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address', optional: true
alias_attribute :shipping_address, :ship_address
alias_method :shipping_address, :ship_address
alias_method :shipping_address=, :ship_address=

alias_attribute :ship_total, :shipment_total

belongs_to :store, class_name: 'Spree::Store', optional: true
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/preference.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class Spree::Preference < Spree::Base
serialize :value
serialize :value, coder: YAML

validates :key, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }
end
2 changes: 1 addition & 1 deletion core/app/models/spree/return_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ReturnItem < Spree::Base
scope :exchange_processed, -> { where.not(exchange_inventory_unit: nil) }
scope :exchange_required, -> { exchange_requested.where(exchange_inventory_unit: nil) }

serialize :acceptance_status_errors
serialize :acceptance_status_errors, coder: YAML

delegate :eligible_for_return?, :requires_manual_intervention?, to: :validator
delegate :variant, to: :inventory_unit
Expand Down
3 changes: 1 addition & 2 deletions core/app/models/spree/shipping_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class ShippingRate < Spree::Base
delegate :name, :tax_category, :tax_category_id, to: :shipping_method
delegate :code, to: :shipping_method, prefix: true
alias_attribute :amount, :cost

alias_method :total_before_tax, :amount
alias_attribute :total_before_tax, :cost

extend DisplayMoney
money_methods :amount
Expand Down
2 changes: 1 addition & 1 deletion core/lib/generators/spree/dummy/templates/rails/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
config.eager_load = false

# Raise exceptions instead of rendering exception templates
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = false # Should be :none for Rails 7.1+

# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
Expand Down
2 changes: 2 additions & 0 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
require 'ransack'
require 'state_machines-activerecord'

require_relative './ransack_4_1_patch'

# This is required because ActiveModel::Validations#invalid? conflicts with the
# invalid state of a Payment. In the future this should be removed.
StateMachines::Machine.ignore_method_conflicts = true
Expand Down
12 changes: 7 additions & 5 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ class Engine < ::Rails::Engine
end

# Load in mailer previews for apps to use in development.
initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_configs" do |app|
original_preview_path = app.config.action_mailer.preview_path
solidus_preview_path = Spree::Core::Engine.root.join 'lib/spree/mailer_previews'
initializer "spree.core.action_mailer.set_preview_path", after: "action_mailer.set_autoload_paths" do
solidus_preview_path = Spree::Core::Engine.root.join("lib/spree/mailer_previews")

app.config.action_mailer.preview_path = "{#{original_preview_path},#{solidus_preview_path}}"
ActionMailer::Base.preview_path = app.config.action_mailer.preview_path
if ActionMailer::Base.respond_to? :preview_paths # Rails 7.1+
ActionMailer::Base.preview_paths << solidus_preview_path.to_s
else
ActionMailer::Base.preview_path = "{#{ActionMailer::Base.preview_path},#{solidus_preview_path}}"
end
end

initializer "spree.deprecator" do |app|
Expand Down
8 changes: 7 additions & 1 deletion core/lib/spree/preferences/persistable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ module Persistable

included do
include Spree::Preferences::Preferable
serialize :preferences, Hash

if method(:serialize).parameters.include?([:key, :type]) # Rails 7.1+
serialize :preferences, type: Hash, coder: YAML
else
serialize :preferences, Hash, coder: YAML
end

after_initialize :initialize_preference_defaults
end

Expand Down
16 changes: 16 additions & 0 deletions core/lib/spree/ransack_4_1_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "ransack/version"

return unless Ransack::VERSION.start_with?("4.1.")

module RansackNodeConditionPatch
private

# Waiting for https://github.com/activerecord-hackery/ransack/pull/1468
def casted_array?(predicate)
predicate.is_a?(Arel::Nodes::Casted) && predicate.value.is_a?(Array)
end

Ransack::Nodes::Condition.prepend(self)
end
26 changes: 14 additions & 12 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Application < ::Rails::Application

# Make debugging easier:
config.consider_all_requests_local = true
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = false # Should be :none for Rails 7.1+
config.active_support.deprecation = :stderr
config.log_level = :debug

Expand All @@ -82,22 +82,24 @@ class Application < ::Rails::Application
config.secret_key_base = 'SECRET_TOKEN'

# Set the preview path within the dummy app:
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
if ActionMailer::Base.respond_to? :preview_paths # Rails 7.1+
config.action_mailer.preview_paths << File.expand_path('dummy_app/mailer_previews', __dir__)
else
config.action_mailer.preview_path = File.expand_path('dummy_app/mailer_previews', __dir__)
end

config.active_record.dump_schema_after_migration = false

# Configure active storage to use storage within tmp folder
unless (ENV['DISABLE_ACTIVE_STORAGE'] == 'true')
initializer 'solidus.active_storage' do
config.active_storage.service_configurations = {
test: {
service: 'Disk',
root: Rails.root.join('tmp', 'storage')
}
initializer 'solidus.active_storage' do
config.active_storage.service_configurations = {
test: {
service: 'Disk',
root: Rails.root.join('tmp', 'storage')
}
config.active_storage.service = :test
config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR', :vips).to_sym
end
}
config.active_storage.service = :test
config.active_storage.variant_processor = ENV.fetch('ACTIVE_STORAGE_VARIANT_PROCESSOR', :vips).to_sym
end

# Avoid issues if an old spec/dummy still exists
Expand Down
5 changes: 1 addition & 4 deletions core/lib/spree/testing_support/dummy_app/rake_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ def initialize(gem_root:, lib_name:)
# railties:install:migrations and then db:migrate.
# Migrations should be run one directory at a time
ActiveRecord::Migrator.migrations_paths.each do |path|
ActiveRecord::MigrationContext.new(
[path],
ActiveRecord::SchemaMigration
).migrate
ActiveRecord::MigrationContext.new([path]).migrate
end

ActiveRecord::Base.clear_cache!
Expand Down
4 changes: 2 additions & 2 deletions core/solidus_core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Gem::Specification.new do |s|
actionmailer actionpack actionview activejob activemodel activerecord
activestorage activesupport railties
].each do |rails_dep|
s.add_dependency rails_dep, ['>= 7.0', '< 7.1']
s.add_dependency rails_dep, ['>= 7.0', '< 7.2']
end

s.add_dependency 'activemerchant', '~> 1.66'
Expand All @@ -43,7 +43,7 @@ Gem::Specification.new do |s|
s.add_dependency 'monetize', '~> 1.8'
s.add_dependency 'kt-paperclip', ['>= 6.3', '< 8']
s.add_dependency 'psych', ['>= 4.0.1', '< 5.0']
s.add_dependency 'ransack', '~> 2.0'
s.add_dependency 'ransack', '~> 4.0'
s.add_dependency 'sprockets-rails'
s.add_dependency 'state_machines-activerecord', '~> 0.6'
s.add_dependency 'omnes', '~> 0.2.2'
Expand Down
2 changes: 1 addition & 1 deletion core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
expect(html.css(".notice").text).to eq("ok")
expect(html.css(".foo").text).to be_empty
expect(html.css(".bar").text).to be_empty
expect(helper.output_buffer).to eq("<div class=\"flash notice\">ok</div>")
expect(helper.output_buffer.to_s).to eq("<div class=\"flash notice\">ok</div>")
end
end

Expand Down
2 changes: 1 addition & 1 deletion core/spec/lib/spree/core/controller_helpers/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def controller.index
path: '/api'
})
get :index
expect(response.headers["Set-Cookie"]).to match(/domain=\.test\.host; path=\/api/)
expect(response.headers["Set-Cookie"]).to match(/domain=(\.)?test\.host; path=\/api/)
end

it 'never overwrites httponly' do
Expand Down
4 changes: 3 additions & 1 deletion core/spec/models/spree/preferences/preferable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def self.allowed_admin_form_preference_types
end

it "with string, encryption key provided as env variable" do
expect(ENV).to receive(:[]).with("SOLIDUS_PREFERENCES_MASTER_KEY").and_return("VkYp3s6v9y$B?E(H+MbQeThWmZq4t7w!")
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with("SOLIDUS_PREFERENCES_MASTER_KEY").and_return("VkYp3s6v9y$B?E(H+MbQeThWmZq4t7w!")
expect(Spree::Encryptor).to receive(:new).with("VkYp3s6v9y$B?E(H+MbQeThWmZq4t7w!").and_call_original

config_class_a.preference :secret, :encrypted_string

Expand Down
9 changes: 5 additions & 4 deletions sample/db/samples/orders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
store = Spree::Store.first!

orders = []

orders << Spree::Order.create!(
number: "R123456789",
email: "[email protected]",
item_total: 150.95,
adjustment_total: 150.95,
total: 301.90,
shipping_address: Spree::Address.first,
billing_address: Spree::Address.last
ship_address: Spree::Address.first,
bill_address: Spree::Address.last
)

orders << Spree::Order.create!(
Expand All @@ -23,8 +24,8 @@
item_total: 15.95,
adjustment_total: 15.95,
total: 31.90,
shipping_address: Spree::Address.first,
billing_address: Spree::Address.last
ship_address: Spree::Address.first,
bill_address: Spree::Address.last
)

orders[0].line_items.create!(
Expand Down