forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize legacy event bus deprecation and test legacy on CI
This commit adds a new job on CI to perform the test suite with the legacy adapter configured. Besides that, it extracts the deprecation logic into its module to avoid having it scattered through different parts of the system. Relates to discussion: solidusio#4130 (comment)
- Loading branch information
1 parent
3130803
commit 85dae08
Showing
9 changed files
with
234 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spree/event/adapters/active_support_notifications' | ||
require 'spree/deprecation' | ||
|
||
module Spree | ||
module Event | ||
module Adapters | ||
# @api private | ||
module DeprecationHandler | ||
LEGACY_ADAPTER = ActiveSupportNotifications | ||
|
||
CI_LEGACY_ADAPTER_ENV_KEY = 'CI_LEGACY_EVENT_BUS_ADAPTER' | ||
|
||
def self.legacy_adapter?(adapter) | ||
adapter == LEGACY_ADAPTER | ||
end | ||
|
||
def self.legacy_adapter_set_by_env | ||
return LEGACY_ADAPTER if ENV[CI_LEGACY_ADAPTER_ENV_KEY].present? | ||
end | ||
|
||
def self.render_deprecation_message?(adapter) | ||
legacy_adapter?(adapter) && legacy_adapter_set_by_env.nil? | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,8 +135,11 @@ class Application < ::Rails::Application | |
Spree.config do |config| | ||
config.mails_from = "[email protected]" | ||
# TODO: Remove on Solidus 4.0 as it'll be the default | ||
require 'spree/event/adapters/default' | ||
config.events.adapter = Spree::Event::Adapters::Default.new | ||
require 'spree/event/adapters/deprecation_handler' | ||
if Spree::Event::Adapters::DeprecationHandler.legacy_adapter_set_by_env.nil? | ||
require 'spree/event/adapters/default' | ||
config.events.adapter = Spree::Event::Adapters::Default.new | ||
end | ||
|
||
if ENV['DISABLE_ACTIVE_STORAGE'] | ||
config.image_attachment_module = 'Spree::Image::PaperclipAttachment' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
core/spec/lib/spree/event/adapters/deprecation_handler_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'spree/event/adapters/deprecation_handler' | ||
require 'spree/event/adapters/default' | ||
|
||
module Spree | ||
module Event | ||
module Adapters | ||
RSpec.describe DeprecationHandler do | ||
let(:env_key) { described_class::CI_LEGACY_ADAPTER_ENV_KEY } | ||
|
||
let(:reset_env_key) do | ||
lambda do |example| | ||
old_value = ENV[env_key] | ||
example.run | ||
ENV[env_key] = old_value | ||
end | ||
end | ||
|
||
describe '#legacy_adapter?' do | ||
context 'when the events adapter is the legacy' do | ||
it 'returns true' do | ||
expect(described_class.legacy_adapter?(ActiveSupportNotifications)).to be(true) | ||
end | ||
end | ||
|
||
context 'when the events adapter is not the legacy' do | ||
it 'returns false' do | ||
expect(described_class.legacy_adapter?(Default.new)).to be(false) | ||
end | ||
end | ||
end | ||
|
||
describe '#legacy_adapter_set_by_env' do | ||
around { |example| reset_env_key.(example) } | ||
|
||
context 'when env var is set' do | ||
it 'returns the legacy adapter' do | ||
ENV[env_key] = '1' | ||
|
||
expect(described_class.legacy_adapter_set_by_env).to be(ActiveSupportNotifications) | ||
end | ||
end | ||
|
||
context 'when env var is not set' do | ||
it 'returns nil' do | ||
ENV[env_key] = nil | ||
|
||
expect(described_class.legacy_adapter_set_by_env).to be(nil) | ||
end | ||
end | ||
end | ||
|
||
describe '#render_deprecation_message?' do | ||
context 'when adapter is legacy and is not set by env' do | ||
around { |example| reset_env_key.(example) } | ||
|
||
it 'returns true' do | ||
ENV[env_key] = nil | ||
|
||
expect(described_class.render_deprecation_message?(ActiveSupportNotifications)).to be(true) | ||
end | ||
end | ||
|
||
context 'when adapter is legacy and is set by env' do | ||
around { |example| reset_env_key.(example) } | ||
|
||
it 'returns true' do | ||
ENV[env_key] = '1' | ||
|
||
expect(described_class.render_deprecation_message?(ActiveSupportNotifications)).to be(false) | ||
end | ||
end | ||
|
||
context 'when adapter is not legacy' do | ||
it 'returns false' do | ||
expect(described_class.render_deprecation_message?(Default.new)).to be(false) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'spree/event/configuration' | ||
|
||
RSpec.describe Spree::Event::Configuration do | ||
describe '#adapter' do | ||
context "when it hasn't been explicitly set" do | ||
let(:supress_warning_env_key) { Spree::Event::Adapters::DeprecationHandler::CI_LEGACY_ADAPTER_ENV_KEY } | ||
|
||
it 'is ActiveSupportNotifications adapter' do | ||
allow(Spree::Deprecation).to receive(:warn) | ||
|
||
expect(described_class.new.adapter).to be(Spree::Event::Adapters::ActiveSupportNotifications) | ||
end | ||
|
||
it 'renders a deprecation message when no supressed via env' do | ||
old_value = ENV[supress_warning_env_key] | ||
ENV[supress_warning_env_key] = nil | ||
expect(Spree::Deprecation).to receive(:warn).with(/adapter is.*deprecated/m) | ||
|
||
described_class.new.adapter | ||
ensure | ||
ENV[supress_warning_env_key] = old_value | ||
end | ||
|
||
it "doesn't render a deprecation message when supressed via env" do | ||
old_value = ENV[supress_warning_env_key] | ||
ENV[supress_warning_env_key] = '1' | ||
expect(Spree::Deprecation).not_to receive(:warn).with(/adapter is.*deprecated/m) | ||
|
||
described_class.new.adapter | ||
ensure | ||
ENV[supress_warning_env_key] = old_value | ||
end | ||
end | ||
|
||
context "when it has been explicitly set" do | ||
it "doesn't render a deprecation message" do | ||
expect(Spree::Deprecation).not_to receive(:warn) | ||
|
||
config = described_class.new | ||
config.adapter = Spree::Event::Adapters::ActiveSupportNotifications | ||
|
||
config.adapter | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.