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

[pull] main from solidusio:main #405

Merged
merged 13 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ commands:
cd /tmp/dummy_extension
bundle init
bundle add rails -v "< 7.1" --skip-install
bundle add sqlite3 <<parameters.extra_gems>> --skip-install
bundle add sqlite3 -v "~> 1.3" --skip-install
test -n "<<parameters.extra_gems>>" && bundle add <<parameters.extra_gems>> --skip-install
bundle add solidus --path "$(ruby -e"puts File.expand_path ENV['CIRCLE_WORKING_DIRECTORY']")"
export LIB_NAME=set # dummy requireable file
bundle exec rake -rrails -rspree/testing_support/extension_rake -e'Rake::Task["extension:test_app"].invoke'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dbs = ENV['DB_ALL'] ? 'all' : ENV.fetch('DB', 'sqlite')
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 'sqlite3', '~> 1.4', require: false if dbs.match?(/all|sqlite/)

gem 'database_cleaner', '~> 2.0', require: false
gem 'rspec-activemodel-mocks', '~> 1.1', require: false
Expand Down Expand Up @@ -56,6 +57,13 @@ group :admin do
gem 'axe-core-capybara', '~> 4.8', require: false
end

group :legacy_promotions do
gem 'solidus_legacy_promotions', path: 'legacy_promotions', require: false
gem 'solidus_admin', path: 'admin', require: false
gem 'axe-core-rspec', '~> 4.8', require: false
gem 'axe-core-capybara', '~> 4.8', require: false
end

group :lint do
gem 'erb-formatter', '~> 0.7', require: false
gem 'rubocop', '~> 1', require: false
Expand Down
1 change: 0 additions & 1 deletion admin/lib/solidus_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "solidus_core"
require "solidus_backend"
require "solidus_legacy_promotions"

module SolidusAdmin
require "solidus_admin/version"
Expand Down
7 changes: 0 additions & 7 deletions admin/lib/solidus_admin/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,6 @@ def menu_items
]
},

{
key: "promotions",
route: -> { spree.admin_promotions_path },
icon: "megaphone-line",
position: 30,
},

{
key: "stock",
route: -> { spree.admin_stock_items_path },
Expand Down
1 change: 0 additions & 1 deletion admin/solidus_admin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Gem::Specification.new do |s|
s.add_dependency 'geared_pagination', '~> 1.1'
s.add_dependency 'importmap-rails', '~> 1.2', '>= 1.2.1'
s.add_dependency 'solidus_backend'
s.add_dependency 'solidus_legacy_promotions'
s.add_dependency 'solidus_core', '> 4.2'
s.add_dependency 'stimulus-rails', '~> 1.2'
s.add_dependency 'turbo-rails', '~> 2.0'
Expand Down
8 changes: 8 additions & 0 deletions core/lib/spree/core/null_promotion_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ class NullPromotionConfiguration < Spree::Preferences::Configuration
# Spree::NullPromotionFinder.
class_name_attribute :promotion_finder_class, default: 'Spree::NullPromotionFinder'

# Allows providing a different promotion shipping promotion handler.
# @!attribute [rw] shipping_promotion_handler_class
# @see Spree::NullPromotionHandler
# @return [Class] an object that conforms to the API of
# the standard promotion finder class
# Spree::NullPromotionHandler.
class_name_attribute :shipping_promotion_handler_class, default: 'Spree::NullPromotionHandler'

# !@attribute [rw] promotion_api_attributes
# @return [Array<Symbol>] Attributes to be returned by the API for a promotion
preference :promotion_api_attributes, :array, default: []
Expand Down
4 changes: 4 additions & 0 deletions core/spec/lib/spree/core/null_promotion_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
it "uses the null promotion finder class by default" do
expect(config.promotion_finder_class).to eq Spree::NullPromotionFinder
end

it "uses the null promotion handler as the shipping promo handler" do
expect(config.shipping_promotion_handler_class).to eq Spree::NullPromotionHandler
end
end
10 changes: 10 additions & 0 deletions legacy_promotions/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
resources :promotion_categories, except: [:show]
end
end

if SolidusSupport.admin_available?
SolidusAdmin::Engine.routes.draw do
require "solidus_admin/admin_resources"
extend SolidusAdmin::AdminResources

admin_resources :promotions, only: [:index, :destroy]
admin_resources :promotion_categories, only: [:index, :destroy]
end
end
8 changes: 8 additions & 0 deletions legacy_promotions/lib/solidus_legacy_promotions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
require "solidus_backend"
require "solidus_support"

# If `solidus_admin` is available, it needs to load before
# our engine is initialized, so that our load paths can
# be initialized.
begin
require 'solidus_admin'
rescue LoadError
# Solidus Admin is not available
end
module SolidusLegacyPromotions
VERSION = Spree.solidus_version
end
Expand Down
13 changes: 13 additions & 0 deletions legacy_promotions/lib/solidus_legacy_promotions/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ class Engine < ::Rails::Engine
Spree::Backend::Config.menu_items.insert(product_menu_item_index + 1, promotions_menu_item)
end

initializer "solidus_legacy_promotions.add_solidus_admin_menu_items" do
if SolidusSupport.admin_available?
SolidusAdmin::Config.configure do |config|
config.menu_items << {
key: "promotions",
route: -> { spree.admin_promotions_path },
icon: "megaphone-line",
position: 30
}
end
end
end

initializer "solidus_legacy_promotions.assets" do |app|
app.config.assets.precompile << "solidus_legacy_promotions/manifest.js"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'spec_helper'
require 'rails_helper'

RSpec.feature 'Promotions' do
stub_authorization!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'spec_helper'
require 'rails_helper'

describe "Promotion Categories", :js, type: :feature do
RSpec.describe "Promotion Categories", :js, type: :feature, solidus_admin: true do
before { sign_in create(:admin_user, email: 'admin@example.com') }

it "lists promotion categories and allows deleting them" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'spec_helper'
require 'rails_helper'

describe "Promotions", :js, type: :feature do
RSpec.describe "Promotions", :js, type: :feature, solidus_admin: true do
before { sign_in create(:admin_user, email: 'admin@example.com') }

it "lists promotions and allows deleting them" do
Expand Down
31 changes: 30 additions & 1 deletion legacy_promotions/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,30 @@

ENV["RAILS_ENV"] ||= 'test'

# SOLIDUS DUMMY APP
require 'spree/testing_support/dummy_app'
DummyApp.setup(
gem_root: File.expand_path('..', __dir__),
lib_name: 'solidus_legacy_promotions'
)

DummyApp.mattr_accessor :use_solidus_admin

# Calling `draw` will completely rewrite the routes defined in the dummy app,
# so we need to include the main solidus route.
DummyApp::Application.routes.draw do
mount SolidusAdmin::Engine, at: "/admin", constraints: ->(_req) {
DummyApp.use_solidus_admin
}
mount Spree::Core::Engine, at: "/"
end

unless SolidusAdmin::Engine.root.join('app/assets/builds/solidus_admin/tailwind.css').exist?
Dir.chdir(SolidusAdmin::Engine.root) do
system 'bundle exec rake tailwindcss:build' or abort 'Failed to build Tailwind CSS'
end
end

require 'rails-controller-testing'
require 'rspec/rails'
require 'rspec-activemodel-mocks'
Expand All @@ -25,6 +43,7 @@
require 'spree/testing_support/url_helpers'
require 'spree/testing_support/authorization_helpers'
require 'spree/testing_support/controller_requests'
require "solidus_admin/testing_support/feature_helpers"
require 'cancan/matchers'
require 'spree/testing_support/capybara_ext'

Expand All @@ -51,6 +70,10 @@
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
end

# AXE - ACCESSIBILITY
require 'axe-rspec'
require 'axe-capybara'

Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_chrome_headless).to_sym

RSpec.configure do |config|
Expand All @@ -72,8 +95,14 @@
Rails.cache.clear
end

config.include Spree::TestingSupport::JobHelpers
config.around :each, :solidus_admin do |example|
DummyApp.use_solidus_admin = true
example.run
DummyApp.use_solidus_admin = false
end

config.include Spree::TestingSupport::JobHelpers
config.include SolidusAdmin::TestingSupport::FeatureHelpers, type: :feature
config.include FactoryBot::Syntax::Methods
config.include Spree::Api::TestingSupport::Helpers, type: :request
config.include Spree::TestingSupport::UrlHelpers, type: :controller
Expand Down
1 change: 1 addition & 0 deletions lib/solidus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
require 'solidus_api'
require 'solidus_backend'
require 'solidus_sample'
require 'solidus_legacy_promotions'
Loading