diff --git a/.circleci/config.yml b/.circleci/config.yml index f0bf36a..4370b73 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,58 +11,43 @@ orbs: solidusio_extensions: solidusio/extensions@volatile jobs: - run-specs-with-postgres: - executor: - name: solidusio_extensions/postgres - ruby_version: "3.2" + run-specs-with-sqlite: + executor: solidusio_extensions/sqlite steps: - - checkout - browser-tools/install-chrome - - solidusio_extensions/run-tests-solidus-master - - solidusio_extensions/store-test-results - - run-specs-with-mysql: - executor: - name: solidusio_extensions/mysql - ruby_version: "3.1" + - solidusio_extensions/run-tests + run-specs-with-postgres: + executor: solidusio_extensions/postgres steps: - - checkout - browser-tools/install-chrome - - solidusio_extensions/run-tests-solidus-current - - solidusio_extensions/store-test-results - - run-specs-with-sqlite: - executor: - name: solidusio_extensions/sqlite - ruby_version: "3.0" + - solidusio_extensions/run-tests + run-specs-with-mysql: + executor: solidusio_extensions/mysql steps: - - checkout - browser-tools/install-chrome - - solidusio_extensions/run-tests-solidus-older - - solidusio_extensions/store-test-results - + - solidusio_extensions/run-tests lint-code: - executor: solidusio_extensions/sqlite + executor: solidusio_extensions/sqlite-memory 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 - - run-specs-with-sqlite - lint-code - "Weekly run specs against master": + "Weekly run specs against main": triggers: - schedule: cron: "0 0 * * 4" # every Thursday filters: branches: only: - - master + - main jobs: + - run-specs-with-sqlite - run-specs-with-postgres - run-specs-with-mysql - - run-specs-with-sqlite diff --git a/.gem_release.yml b/.gem_release.yml index 97844f4..4b87acf 100644 --- a/.gem_release.yml +++ b/.gem_release.yml @@ -2,4 +2,4 @@ bump: recurse: false file: 'lib/solidus_reports/version.rb' message: Bump SolidusReports to %{version} - branch: true + tag: true diff --git a/.github_changelog_generator b/.github_changelog_generator new file mode 100644 index 0000000..eac0962 --- /dev/null +++ b/.github_changelog_generator @@ -0,0 +1,2 @@ +issues=false +exclude-labels=infrastructure diff --git a/.gitignore b/.gitignore index 6ad1ffe..1ba2096 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,14 @@ .sass-cache coverage Gemfile.lock +Gemfile-local tmp nbproject pkg *.swp spec/dummy spec/examples.txt +/sandbox +.rvmrc .ruby-version +.ruby-gemset diff --git a/.rspec b/.rspec index 5052887..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ ---color \ No newline at end of file +--color +--require spec_helper diff --git a/Gemfile b/Gemfile index aafc521..880c1a3 100644 --- a/Gemfile +++ b/Gemfile @@ -3,25 +3,28 @@ 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' +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. # See https://github.com/bundler/bundler/issues/6677 gem 'rails', '>0.a' + # Provides basic authentication functionality for testing parts of your engine gem 'solidus_auth_devise' -gem 'solidus_dev_support' -case ENV['DB'] +case ENV.fetch('DB', nil) when 'mysql' gem 'mysql2' when 'postgresql' @@ -35,4 +38,16 @@ group :test do gem 'rspec-activemodel-mocks' 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 +# relevant for the project or for other contributors, e.g. pry-byebug. +# +# We use `send` instead of calling `eval_gemfile` to work around an issue with +# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658. +send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local' diff --git a/Rakefile b/Rakefile index ecdfc67..a6562a8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ # frozen_string_literal: true +require "bundler/gem_tasks" require 'solidus_dev_support/rake_tasks' SolidusDevSupport::RakeTasks.install -task default: %w[extension:test_app extension:specs] +task default: 'extension:specs' diff --git a/app/models/solidus_reports/configuration.rb b/app/models/solidus_reports/configuration.rb deleted file mode 100644 index e03ce99..0000000 --- a/app/models/solidus_reports/configuration.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -module SolidusReports - class Configuration < Spree::Preferences::Configuration - REPORT_TABS ||= [:reports].freeze - - new_item = Spree::BackendConfiguration::MenuItem.new( - REPORT_TABS, - 'file', - condition: -> { can?(:admin, :reports) } - ) - Spree::Backend::Config.menu_items << new_item - end -end diff --git a/bin/rails b/bin/rails index c535fd2..6dbbbc3 100755 --- a/bin/rails +++ b/bin/rails @@ -1,15 +1,7 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -app_root = 'spec/dummy' - -unless File.exist? "#{app_root}/bin/rails" - system "bin/rake", app_root or begin # rubocop:disable Style/AndOr - warn "Automatic creation of the dummy app failed" - exit 1 - end +if %w[g generate].include? ARGV.first + exec "#{__dir__}/rails-engine", *ARGV +else + exec "#{__dir__}/rails-sandbox", *ARGV end - -Dir.chdir app_root -exec 'bin/rails', *ARGV diff --git a/bin/rails-engine b/bin/rails-engine new file mode 100755 index 0000000..4436f64 --- /dev/null +++ b/bin/rails-engine @@ -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/solidus_reports/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/bin/rails-sandbox b/bin/rails-sandbox new file mode 100755 index 0000000..ad2df04 --- /dev/null +++ b/bin/rails-sandbox @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +app_root = 'sandbox' + +unless File.exist? "#{app_root}/bin/rails" + warn 'Creating the sandbox app...' + Dir.chdir "#{__dir__}/.." do + system "#{__dir__}/sandbox" or begin + warn 'Automatic creation of the sandbox app failed' + exit 1 + end + end +end + +Dir.chdir app_root +exec 'bin/rails', *ARGV diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..1e6eacd --- /dev/null +++ b/bin/rake @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/sandbox b/bin/sandbox new file mode 100755 index 0000000..3c9b9f3 --- /dev/null +++ b/bin/sandbox @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +set -e +test -z "${DEBUG+empty_string}" || set -x + +test "$DB" = "sqlite" && export DB="sqlite3" + +if [ -z "$SOLIDUS_BRANCH" ] +then + echo "~~> Use 'export SOLIDUS_BRANCH=[main|v3.2|...]' to control the Solidus branch" + SOLIDUS_BRANCH="main" +fi +echo "~~> Using branch $SOLIDUS_BRANCH of solidus" + +# if [ -z "$SOLIDUS_FRONTEND" ] +# then +# echo "~~> Use 'export SOLIDUS_FRONTEND=[solidus_frontend|solidus_starter_frontend]' to control the Solidus frontend" +# SOLIDUS_FRONTEND="solidus_frontend" +# fi +# echo "~~> Using branch $SOLIDUS_FRONTEND as the solidus frontend" + +extension_name="solidus_reports" + +# Stay away from the bundler env of the containing extension. +function unbundled { + ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@ +} + +rm -rf ./sandbox +unbundled bundle exec rails new sandbox \ + --database="${DB:-sqlite3}" \ + --skip-bundle \ + --skip-git \ + --skip-keeps \ + --skip-rc \ + --skip-spring \ + --skip-test \ + --skip-javascript + +if [ ! -d "sandbox" ]; then + echo 'sandbox rails application failed' + exit 1 +fi + +cd ./sandbox +cat <> Gemfile +gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH' +gem 'rails-i18n' +gem 'solidus_i18n' + +gem '$extension_name', path: '..' + +group :test, :development do + platforms :mri do + gem 'pry-byebug' + end +end +RUBY + +unbundled bundle install --gemfile Gemfile + +unbundled bundle exec rake db:drop db:create + +unbundled bundle exec rails generate solidus:install \ + --auto-accept \ + --user_class=Spree::User \ + --payment-method=none \ + $@ + +# unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations +unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations + +echo +echo "๐Ÿš€ Sandbox app successfully created for $extension_name!" +echo "๐Ÿงช This app is intended for test purposes." diff --git a/bin/setup b/bin/setup index c3563af..67d9193 100755 --- a/bin/setup +++ b/bin/setup @@ -5,4 +5,4 @@ set -vx gem install bundler --conservative bundle update -bundle exec rake extension:test_app +bin/rake clobber diff --git a/lib/generators/solidus_reports/install/install_generator.rb b/lib/generators/solidus_reports/install/install_generator.rb index 5e75ea1..19df435 100644 --- a/lib/generators/solidus_reports/install/install_generator.rb +++ b/lib/generators/solidus_reports/install/install_generator.rb @@ -4,6 +4,15 @@ module SolidusReports module Generators class InstallGenerator < Rails::Generators::Base class_option :auto_run_migrations, type: :boolean, default: false + source_root File.expand_path('templates', __dir__) + + def self.exit_on_failure? + true + end + + def copy_initializer + template 'initializer.rb', 'config/initializers/solidus_reports.rb' + end def add_javascripts append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_reports\n" @@ -11,20 +20,20 @@ def add_javascripts end def add_stylesheets - inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_reports\n", before: %r{\*/}, verbose: true - inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_reports\n", before: %r{\*/}, verbose: true + inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_reports\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength + inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_reports\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength end def add_migrations - run 'bundle exec rake railties:install:migrations FROM=solidus_reports' + run 'bin/rails railties:install:migrations FROM=solidus_reports' end def run_migrations - run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) + run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength if run_migrations - run 'bundle exec rake db:migrate' + run 'bin/rails db:migrate' else - puts 'Skipping rake db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output + puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output end end end diff --git a/lib/generators/solidus_reports/install/templates/initializer.rb b/lib/generators/solidus_reports/install/templates/initializer.rb new file mode 100644 index 0000000..dd2becd --- /dev/null +++ b/lib/generators/solidus_reports/install/templates/initializer.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +SolidusReports.configure do |config| + # TODO: Remember to change this with the actual preferences you have implemented! + # config.sample_preference = 'sample_value' +end diff --git a/lib/solidus_reports.rb b/lib/solidus_reports.rb index 85ee088..125e8c0 100644 --- a/lib/solidus_reports.rb +++ b/lib/solidus_reports.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'solidus_core' -require 'solidus_support' - +require 'solidus_reports/configuration' +require 'solidus_reports/version' require 'solidus_reports/engine' diff --git a/lib/solidus_reports/configuration.rb b/lib/solidus_reports/configuration.rb new file mode 100644 index 0000000..ae00232 --- /dev/null +++ b/lib/solidus_reports/configuration.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module SolidusReports + class Configuration + # Define here the settings for this extension, e.g.: + # + # attr_accessor :my_setting + end + + class << self + def configuration + @configuration ||= Configuration.new + end + + alias config configuration + + def configure + yield configuration + end + end +end diff --git a/lib/solidus_reports/engine.rb b/lib/solidus_reports/engine.rb index 02115a9..beb3447 100644 --- a/lib/solidus_reports/engine.rb +++ b/lib/solidus_reports/engine.rb @@ -1,14 +1,15 @@ # frozen_string_literal: true -require "spree/core" +require 'solidus_core' +require 'solidus_support' module SolidusReports class Engine < Rails::Engine include SolidusSupport::EngineExtensions - isolate_namespace Spree + isolate_namespace ::Spree - engine_name "solidus_reports" + engine_name 'solidus_reports' # use rspec for tests config.generators do |g| @@ -16,8 +17,14 @@ class Engine < Rails::Engine end initializer "solidus_reports.environment", before: :load_config_initializers do - require_dependency "solidus_reports/configuration" - SolidusReports::Config = SolidusReports::Configuration.new + REPORT_TABS ||= [:reports].freeze + + new_item = Spree::BackendConfiguration::MenuItem.new( + REPORT_TABS, + 'file', + condition: -> { can?(:admin, :reports) } + ) + Spree::Backend::Config.menu_items << new_item end end end diff --git a/lib/solidus_reports/testing_support/factories.rb b/lib/solidus_reports/testing_support/factories.rb new file mode 100644 index 0000000..745a01e --- /dev/null +++ b/lib/solidus_reports/testing_support/factories.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +FactoryBot.define do +end diff --git a/solidus_reports.gemspec b/solidus_reports.gemspec index b5e563c..a3e1b3e 100644 --- a/solidus_reports.gemspec +++ b/solidus_reports.gemspec @@ -1,34 +1,36 @@ # frozen_string_literal: true -$:.push File.expand_path("lib", __dir__) -require "solidus_reports/version" - -Gem::Specification.new do |s| - s.name = "solidus_reports" - s.version = SolidusReports::VERSION - s.summary = "Reports module from Solidus core" - s.description = s.summary - s.license = "BSD-3-Clause" - - s.author = "Jonathan Tapia" - s.email = "jonathan.tapia@magmalabs.io" - s.homepage = "http://github.com/solidusio-contrib/solidus_reports" - - if s.respond_to?(:metadata) - s.metadata["homepage_uri"] = s.homepage - s.metadata["source_code_uri"] = s.homepage - end - - s.required_ruby_version = [">= 2.5", "< 4.0"] - - s.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - end - s.test_files = Dir["spec/**/*"] - s.bindir = "exe" - s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } - s.require_paths = ["lib"] - - s.add_dependency "solidus_core", [">= 2.5", "< 4.0"] - s.add_dependency "solidus_support", "~> 0.5" +require_relative 'lib/solidus_reports/version' + +Gem::Specification.new do |spec| + spec.name = 'solidus_reports' + spec.version = SolidusReports::VERSION + spec.authors = ['Jonathan Tapia'] + spec.email = 'jonathan.tapia@magmalabs.io' + + spec.summary = 'Reports module from Solidus core' + spec.description = 'Reports module from Solidus core' + spec.homepage = 'http://github.com/solidusio-contrib/solidus_reports' + spec.license = 'BSD-3-Clause' + + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'http://github.com/solidusio-contrib/solidus_reports' + spec.metadata['changelog_uri'] = 'https://github.com/DanielePalombo/solidus_reports/blob/master/CHANGELOG.md' + + spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4') + + # 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. + files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") } + + spec.files = files.grep_v(%r{^(test|spec|features)/}) + spec.test_files = files.grep(%r{^(test|spec|features)/}) + spec.bindir = "exe" + spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5'] + spec.add_dependency 'solidus_support', '~> 0.5' + + spec.add_development_dependency 'solidus_dev_support', '~> 2.7' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bc7e469..aa2c701 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,19 +6,27 @@ # Run Coverage report require 'solidus_dev_support/rspec/coverage' -require File.expand_path('dummy/config/environment.rb', __dir__) +# 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_reports/factories.rb -require 'solidus_reports/factories' +# Requires factories defined in Solidus core and this extension. +# See: lib/solidus_reports/testing_support/factories.rb +SolidusDevSupport::TestingSupport::Factories.load_for(SolidusReports::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 diff --git a/spec/support/factories.rb b/spec/support/factories.rb index ba25edd..c87a8e6 100644 --- a/spec/support/factories.rb +++ b/spec/support/factories.rb @@ -1,3 +1,4 @@ # frozen_string_literal: true +SolidusDevSupport::TestingSupport::Factories.load_for(SolidusReports::Engine) require 'solidus_reports/factories'