diff --git a/.circleci/config.yml b/.circleci/config.yml index 12bb10e..2fd7722 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,6 +1,9 @@ version: 2.1 orbs: + # Required for feature specs. + browser-tools: circleci/browser-tools@1.1 + # Always take the latest version of the orb, this allows us to # run specs against Solidus supported versions only without the need # to change this configuration every time a Solidus version is released @@ -8,20 +11,42 @@ orbs: solidusio_extensions: solidusio/extensions@volatile jobs: + run-specs-with-sqlite: + executor: + name: solidusio_extensions/sqlite + ruby_version: "3.0" + steps: + - browser-tools/install-chrome + - solidusio_extensions/run-tests run-specs-with-postgres: - executor: solidusio_extensions/postgres + executor: + name: solidusio_extensions/postgres + ruby_version: "3.0" steps: + - browser-tools/install-chrome - solidusio_extensions/run-tests run-specs-with-mysql: - executor: solidusio_extensions/mysql + executor: + name: solidusio_extensions/mysql + ruby_version: "3.0" steps: + - browser-tools/install-chrome - solidusio_extensions/run-tests + lint-code: + executor: + name: solidusio_extensions/sqlite-memory + ruby_version: "3.0" + steps: + - solidusio_extensions/lint-code workflows: "Run specs on supported Solidus versions": jobs: + - run-specs-with-sqlite - run-specs-with-postgres - run-specs-with-mysql + - lint-code + "Weekly run specs against master": triggers: - schedule: @@ -31,5 +56,6 @@ workflows: only: - master jobs: + - run-specs-with-sqlite - run-specs-with-postgres - run-specs-with-mysql diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..0d0b1c9 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1 @@ +_extends: .github diff --git a/.rubocop.yml b/.rubocop.yml index 6207a64..ed101eb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,2 +1,7 @@ +inherit_from: .rubocop_todo.yml + require: - solidus_dev_support/rubocop + +AllCops: + NewCops: disable diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..86490aa --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,67 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-10-13 08:30:45 UTC using RuboCop version 1.36.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'solidus_static_content.gemspec' + +# Offense count: 1 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'lib/solidus_static_content/factories.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/NonDeterministicRequireOrder: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/OrAssignmentToConstant: + Exclude: + - 'app/models/solidus_static_content/configuration.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopDisableDirective: + Exclude: + - 'bin/rails' + +# Offense count: 1 +RSpec/AnyInstance: + Exclude: + - 'spec/features/admin/homepage_spec.rb' + +# Offense count: 3 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/features/admin/homepage_spec.rb' + +# Offense count: 2 +RSpec/MultipleExpectations: + Max: 2 + +# Offense count: 1 +# Style/ClassVars: + # Exclude: + # - 'app/controllers/spree/admin/reports_controller.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedVars. +Style/FetchEnvVar: + Exclude: + - 'Gemfile' diff --git a/Gemfile b/Gemfile index 661491e..4488642 100644 --- a/Gemfile +++ b/Gemfile @@ -3,14 +3,17 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -branch = ENV.fetch('SOLIDUS_BRANCH', 'master') -solidus_git, solidus_frontend_git = if (branch == 'master') || (branch >= 'v3.2') - %w[solidusio/solidus solidusio/solidus_frontend] - else - %w[solidusio/solidus] * 2 - end -gem 'solidus', github: solidus_git, branch: branch -gem 'solidus_frontend', github: solidus_frontend_git, branch: branch +branch = ENV.fetch('SOLIDUS_BRANCH', 'main') +gem 'solidus', github: 'solidusio/solidus', branch: branch + +# The solidus_frontend gem has been pulled out since v3.2 +if branch >= 'v3.2' + gem 'solidus_frontend' +elsif branch == 'main' + gem 'solidus_frontend', github: 'solidusio/solidus_frontend', branch: branch +else + gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch +end # Needed to help Bundler figure out how to resolve dependencies, # otherwise it takes forever to resolve them. @@ -20,7 +23,7 @@ gem 'rails', '>0.a' # Provides basic authentication functionality for testing parts of your engine gem 'solidus_auth_devise' -case ENV['DB'] +case ENV.fetch('DB', nil) when 'mysql' gem 'mysql2' when 'postgresql' @@ -29,6 +32,20 @@ else gem 'sqlite3' end +group :development, :test do + gem 'factory_bot', '> 4.10.0' + gem 'pry-rails' +end + +group :test do + gem 'rails-controller-testing' +end + +# While we still support Ruby < 3 we need to workaround a limitation in +# the 'async' gem that relies on the latest ruby, since RubyGems doesn't +# resolve gems based on the required ruby version. +gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3') + gemspec # Use a local Gemfile to include development dependencies that might not be diff --git a/lib/solidus_static_content.rb b/lib/solidus_static_content.rb index dfea099..ef430d9 100644 --- a/lib/solidus_static_content.rb +++ b/lib/solidus_static_content.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require 'solidus_core' -require 'solidus_support' -require 'deface' - require 'solidus_static_content/version' require 'solidus_static_content/route_matcher' require 'solidus_static_content/engine' diff --git a/lib/solidus_static_content/engine.rb b/lib/solidus_static_content/engine.rb index 8c5a536..8dc07a7 100644 --- a/lib/solidus_static_content/engine.rb +++ b/lib/solidus_static_content/engine.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require 'spree/core' -require 'solidus_static_content' +require 'solidus_core' +require 'solidus_support' module SolidusStaticContent class Engine < Rails::Engine diff --git a/lib/solidus_static_content/factories.rb b/lib/solidus_static_content/testing_support/factories.rb similarity index 100% rename from lib/solidus_static_content/factories.rb rename to lib/solidus_static_content/testing_support/factories.rb diff --git a/solidus_static_content.gemspec b/solidus_static_content.gemspec index 2cbea7a..e02bd91 100644 --- a/solidus_static_content.gemspec +++ b/solidus_static_content.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_static_content#readme' spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_static_content/releases' - spec.required_ruby_version = Gem::Requirement.new('>= 2.5') + spec.required_ruby_version = '>= 2.5' # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. @@ -25,13 +25,13 @@ Gem::Specification.new do |spec| spec.files = files.grep_v(%r{^(test|spec|features)/}) spec.test_files = files.grep(%r{^(test|spec|features)/}) - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_dependency 'deface', '~> 1.0' - spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 4'] - spec.add_dependency 'solidus_support', '~> 0.6' + spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5'] + spec.add_dependency 'solidus_support', '~> 0.8' - spec.add_development_dependency 'solidus_dev_support' + spec.add_development_dependency 'rails-controller-testing' + spec.add_development_dependency 'solidus_dev_support', '~> 2.7' end diff --git a/spec/features/spree/static_content_spec.rb b/spec/features/spree/static_content_spec.rb index 7204d83..bac64e9 100644 --- a/spec/features/spree/static_content_spec.rb +++ b/spec/features/spree/static_content_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' feature 'Static Content Page', js: true do - let!(:store) { create(:store, default: true) } context 'render page' do @@ -29,10 +28,10 @@ expect(page).to have_text 'Root Page Test' end - scenario 'is limited within its own constraints', js: false do - create(:taxon, permalink: 'test', name: 'The Taxon') - create(:page, slug: '/t/test', title: 'The Page', stores: [store]) - visit '/t/test' + scenario 'is limited within its own constraints' do + taxon = create(:taxon, permalink: 'test', name: 'The Taxon') + create(:page, slug: "/t/#{taxon.permalink}", title: 'The Page', stores: [store]) + visit "/t/#{taxon.permalink}" expect(page).to have_content('The Taxon') expect(page).not_to have_content('The Page') end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bc06322..88fe267 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,25 +3,33 @@ # Configure Rails Environment ENV['RAILS_ENV'] = 'test' +require 'rails-controller-testing' +Rails::Controller::Testing.install + # Run Coverage report require 'solidus_dev_support/rspec/coverage' -require File.expand_path('dummy/config/environment.rb', __dir__).tap { |file| - # Create the dummy app if it's still missing. - system 'bin/rake extension:test_app' unless File.exist? file -} +# Create the dummy app if it's still missing. +dummy_env = "#{__dir__}/dummy/config/environment.rb" +system 'bin/rake extension:test_app' unless File.exist? dummy_env +require dummy_env # Requires factories and other useful helpers defined in spree_core. require 'solidus_dev_support/rspec/feature_helper' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. -Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } +Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f } -# Requires factories defined in lib/solidus_static_content/factories.rb -require 'solidus_static_content/factories' +# Requires factories defined in Solidus core and this extension. +# See: lib/solidus_static_content/testing_support/factories.rb +SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStaticContent::Engine) RSpec.configure do |config| config.infer_spec_type_from_file_location! config.use_transactional_fixtures = false + + if Spree.solidus_gem_version < Gem::Version.new('2.11') + config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system + end end