diff --git a/.circleci/config.yml b/.circleci/config.yml index 82880900eec..f9cee07c97a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,6 +117,9 @@ commands: - run: name: "Run Sample Tests" command: ./bin/build-ci sample + - run: + name: "Run Legacy Promotion Tests" + command: ./bin/build-ci legacy_promotions - store_artifacts: path: /tmp/test-artifacts diff --git a/bin/build-ci b/bin/build-ci index 650113d8611..0569fac0418 100755 --- a/bin/build-ci +++ b/bin/build-ci @@ -21,12 +21,13 @@ class Project def self.all [ - new('admin', weight: 215), - new('api', weight: 50), - new('backend', weight: 215), - new('backend', test_type: :teaspoon, title: "backend JS", weight: 15), - new('core', weight: 220), - new('sample', weight: 22) + new('admin', weight: 102), + new('api', weight: 69), + new('backend', weight: 282), + new('backend', test_type: :teaspoon, title: "backend JS", weight: 18), + new('core', weight: 266), + new('sample', weight: 28), + new('legacy_promotions', weight: 63) ] end diff --git a/bin/rspec b/bin/rspec index e573a4a625d..d9b88dab572 100755 --- a/bin/rspec +++ b/bin/rspec @@ -8,6 +8,7 @@ LIBS = %w[ backend core sample + legacy_promotions ] # Ignore line info, e.g. foo/bar.rb:123 would become foo/bar.rb diff --git a/legacy_promotions/Rakefile b/legacy_promotions/Rakefile new file mode 100644 index 00000000000..c4633164579 --- /dev/null +++ b/legacy_promotions/Rakefile @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'rubygems' +require 'rake' +require 'rake/testtask' +require 'rspec/core/rake_task' +require 'spree/testing_support/dummy_app/rake_tasks' +require 'bundler/gem_tasks' + +RSpec::Core::RakeTask.new +task default: :spec + +DummyApp::RakeTasks.new( + gem_root: File.dirname(__FILE__), + lib_name: 'solidus_legacy_promotions' +) + +require 'yard/rake/yardoc_task' +YARD::Rake::YardocTask.new(:yard) +# The following workaround can be removed +# once https://github.com/lsegal/yard/pull/1457 is merged. +task('yard:require') { require 'yard' } +task yard: 'yard:require' + +namespace :spec do + task :isolated do + spec_files = Dir['spec/**/*_spec.rb'] + failed_specs = + spec_files.reject do |file| + puts "rspec #{file}" + system('rspec', file) + end + + if !failed_specs.empty? + puts "Failed specs:" + puts failed_specs + exit 1 + end + end +end + +task test_app: 'db:reset' diff --git a/legacy_promotions/bin/rails b/legacy_promotions/bin/rails new file mode 100755 index 00000000000..35347a1f6a8 --- /dev/null +++ b/legacy_promotions/bin/rails @@ -0,0 +1,13 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails gems +# installed from the root of your application. + +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/spree/core/engine', __dir__) + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __dir__) +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) + +require "rails/all" +require "rails/engine/commands" diff --git a/legacy_promotions/lib/solidus_legacy_promotions.rb b/legacy_promotions/lib/solidus_legacy_promotions.rb new file mode 100644 index 00000000000..3f5857cad20 --- /dev/null +++ b/legacy_promotions/lib/solidus_legacy_promotions.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "solidus_core" +require "solidus_support" + +module SolidusLegacyPromotions + VERSION = Spree.solidus_version +end + +require "solidus_legacy_promotions/engine" diff --git a/legacy_promotions/lib/solidus_legacy_promotions/engine.rb b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb new file mode 100644 index 00000000000..7ebf4f2288a --- /dev/null +++ b/legacy_promotions/lib/solidus_legacy_promotions/engine.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module SolidusLegacyPromotions + class Engine < ::Rails::Engine + include SolidusSupport::EngineExtensions + end +end diff --git a/legacy_promotions/solidus_legacy_promotions.gemspec b/legacy_promotions/solidus_legacy_promotions.gemspec new file mode 100644 index 00000000000..778d9fc367f --- /dev/null +++ b/legacy_promotions/solidus_legacy_promotions.gemspec @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require_relative '../core/lib/spree/core/version' + +Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = 'solidus_legacy_promotions' + s.version = Spree.solidus_version + s.summary = 'Legacy Solidus promotion system' + s.description = s.summary + + s.author = 'Solidus Team' + s.email = 'contact@solidus.io' + s.homepage = 'http://solidus.io' + s.license = 'BSD-3-Clause' + + s.metadata['rubygems_mfa_required'] = 'true' + + s.files = `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(spec|script)/}) + end + + s.required_ruby_version = '>= 3.0.0' + s.required_rubygems_version = '>= 1.8.23' + + s.add_dependency 'solidus_core', s.version + s.add_dependency 'solidus_support' +end diff --git a/legacy_promotions/spec/lib/solidus_legacy_promotions_spec.rb b/legacy_promotions/spec/lib/solidus_legacy_promotions_spec.rb new file mode 100644 index 00000000000..1e2b5254d91 --- /dev/null +++ b/legacy_promotions/spec/lib/solidus_legacy_promotions_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe SolidusLegacyPromotions do + it "has a version number" do + expect(SolidusLegacyPromotions::VERSION).not_to be nil + end +end diff --git a/legacy_promotions/spec/rails_helper.rb b/legacy_promotions/spec/rails_helper.rb new file mode 100644 index 00000000000..c86a7eba5e9 --- /dev/null +++ b/legacy_promotions/spec/rails_helper.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +ENV["RAILS_ENV"] ||= 'test' + +require 'spree/testing_support/dummy_app' +DummyApp.setup( + gem_root: File.expand_path('..', __dir__), + lib_name: 'solidus_legacy_promotions' +) + +require 'rspec/rails' +require 'rspec-activemodel-mocks' +require 'database_cleaner' + +Dir["./spec/support/**/*.rb"].sort.each { |f| require f } + +require 'spree/testing_support/factory_bot' +require 'spree/testing_support/preferences' +require 'spree/testing_support/rake' +require 'spree/testing_support/job_helpers' +require 'cancan/matchers' + +ActiveJob::Base.queue_adapter = :test + +Spree::TestingSupport::FactoryBot.add_paths_and_load! + +RSpec.configure do |config| + config.fixture_path = File.join(__dir__, "fixtures") + + config.infer_spec_type_from_file_location! + + # If you're not using ActiveRecord, or you'd prefer not to run each of your + # examples within a transaction, comment the following line or assign false + # instead of true. + config.use_transactional_fixtures = true + + config.before :suite do + FileUtils.rm_rf(Rails.configuration.active_storage.service_configurations[:test][:root]) unless ENV['DISABLE_ACTIVE_STORAGE'] == 'true' + DatabaseCleaner.clean_with :truncation + end + + config.before :each do + Rails.cache.clear + end + + config.include Spree::TestingSupport::JobHelpers + + config.include FactoryBot::Syntax::Methods +end diff --git a/legacy_promotions/spec/spec_helper.rb b/legacy_promotions/spec/spec_helper.rb new file mode 100644 index 00000000000..d2ba4e945dd --- /dev/null +++ b/legacy_promotions/spec/spec_helper.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +if ENV["COVERAGE"] + require 'simplecov' + if ENV["COVERAGE_DIR"] + SimpleCov.coverage_dir(ENV["COVERAGE_DIR"]) + end + SimpleCov.command_name('solidus:core') + SimpleCov.merge_timeout(3600) + SimpleCov.start('rails') +end + +require 'rspec/core' + +require 'spree/testing_support/flaky' +require 'spree/testing_support/partial_double_verification' +require 'spree/testing_support/silence_deprecations' +require 'spree/testing_support/preferences' +require 'spree/deprecator' +require 'spree/config' + +require "solidus_legacy_promotions" + +RSpec.configure do |config| + config.disable_monkey_patching! + config.color = true + config.expect_with :rspec do |c| + c.syntax = :expect + end + config.mock_with :rspec do |c| + c.syntax = :expect + end + + config.include Spree::TestingSupport::Preferences + + config.filter_run focus: true + config.run_all_when_everything_filtered = true + + config.example_status_persistence_file_path = "./spec/examples.txt" + + config.order = :random + + Kernel.srand config.seed +end diff --git a/solidus.gemspec b/solidus.gemspec index 4a040ee6acb..92d782ec448 100644 --- a/solidus.gemspec +++ b/solidus.gemspec @@ -25,4 +25,5 @@ Gem::Specification.new do |s| s.add_dependency 'solidus_backend', s.version s.add_dependency 'solidus_core', s.version s.add_dependency 'solidus_sample', s.version + s.add_dependency 'solidus_legacy_promotions', s.version end