Skip to content

Commit

Permalink
Merge pull request solidusio#5724 from mamhoff/move-solidus-admin-pro…
Browse files Browse the repository at this point in the history
…motion-to-legacy-promotions

Move solidus admin promotion to legacy promotions
  • Loading branch information
kennyadsl authored Apr 18, 2024
2 parents 7ba0f98 + bce5114 commit 68b294f
Show file tree
Hide file tree
Showing 25 changed files with 73 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,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
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

0 comments on commit 68b294f

Please sign in to comment.