diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | Gemfile | 9 | ||||
-rw-r--r-- | Rakefile | 2 | ||||
-rwxr-xr-x | bin/rails | 16 | ||||
-rwxr-xr-x | bin/rails-engine | 13 | ||||
-rwxr-xr-x | bin/rails-sandbox | 16 | ||||
-rwxr-xr-x | bin/rake | 7 | ||||
-rwxr-xr-x | bin/sandbox | 84 | ||||
-rwxr-xr-x | bin/setup | 2 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | lib/generators/solidus_subscriptions/install/install_generator.rb | 18 | ||||
-rw-r--r-- | lib/solidus_subscriptions.rb | 11 | ||||
-rw-r--r-- | lib/solidus_subscriptions/engine.rb | 21 | ||||
-rw-r--r-- | lib/solidus_subscriptions/version.rb | 2 | ||||
-rw-r--r-- | solidus_subscriptions.gemspec | 79 | ||||
-rw-r--r-- | spec/spec_helper.rb | 7 |
16 files changed, 213 insertions, 80 deletions
@@ -14,3 +14,7 @@ pkg *.swp spec/dummy spec/examples.txt +/sandbox +.rvmrc +.ruby-version +.ruby-gemset @@ -23,10 +23,11 @@ else gem 'sqlite3' end -gem 'listen' - gemspec # Use a local Gemfile to include development dependencies that might not be -# relevant for the project or for other contributors, e.g.: `gem 'pry-debug'`. -send :eval_gemfile, 'Gemfile-local' if File.exist? 'Gemfile-local' +# 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' @@ -3,4 +3,4 @@ require 'solidus_dev_support/rake_tasks' SolidusDevSupport::RakeTasks.install -task default: %w[extension:test_app extension:specs] +task default: 'extension:specs' @@ -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..9b4844e --- /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_subscriptions/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..c89b2ae --- /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 # rubocop:disable Style/AndOr + 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..6b848ab --- /dev/null +++ b/bin/sandbox @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +set -e + +case "$DB" in +postgres|postgresql) + RAILSDB="postgresql" + ;; +mysql) + RAILSDB="mysql" + ;; +sqlite|'') + RAILSDB="sqlite3" + ;; +*) + echo "Invalid DB specified: $DB" + exit 1 + ;; +esac + +if [ ! -z $SOLIDUS_BRANCH ] +then + BRANCH=$SOLIDUS_BRANCH +else + BRANCH="master" +fi + +extension_name="solidus_subscriptions" + +# 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="$RAILSDB" \ + --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 <<RUBY >> Gemfile +gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH' +gem 'solidus_auth_devise', '>= 2.1.0' +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 spree:install \ + --auto-accept \ + --user_class=Spree::User \ + --enforce_available_locales=true \ + --with-authentication=false \ + $@ + +unbundled bundle exec rails generate solidus:auth:install + +echo +echo "🚀 Sandbox app successfully created for $extension_name!" +echo "🚀 Using $RAILSDB and Solidus $BRANCH" +echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter" +echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version" +echo "🚀 This app is intended for test purposes." @@ -5,4 +5,4 @@ set -vx gem install bundler --conservative bundle update -bundle exec rake extension:test_app +bin/rake clobber diff --git a/config/routes.rb b/config/routes.rb index 0d1aa5f..e854295 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + SolidusSubscriptions::Engine.routes.draw do namespace :api do namespace :v1 do diff --git a/lib/generators/solidus_subscriptions/install/install_generator.rb b/lib/generators/solidus_subscriptions/install/install_generator.rb index 7214153..ec380b1 100644 --- a/lib/generators/solidus_subscriptions/install/install_generator.rb +++ b/lib/generators/solidus_subscriptions/install/install_generator.rb @@ -1,28 +1,30 @@ +# frozen_string_literal: true + module SolidusSubscriptions module Generators class InstallGenerator < Rails::Generators::Base class_option :auto_run_migrations, type: :boolean, default: false def add_javascripts - append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_subscriptions\n" - append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n" + append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_subscriptions\n" # rubocop:disable Metrics/LineLength + append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_subscriptions\n" # rubocop:disable Metrics/LineLength end def add_stylesheets - inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_subscriptions\n", before: /\*\//, verbose: true - inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_subscriptions\n", before: /\*\//, verbose: true + inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_subscriptions\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength + inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_subscriptions\n", before: %r{\*/}, verbose: true # rubocop:disable Metrics/LineLength end def add_migrations - run 'bundle exec rake railties:install:migrations FROM=solidus_subscriptions' + run 'bin/rails railties:install:migrations FROM=solidus_subscriptions' 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 Metrics/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/solidus_subscriptions.rb b/lib/solidus_subscriptions.rb index aa31ea5..69c7b7a 100644 --- a/lib/solidus_subscriptions.rb +++ b/lib/solidus_subscriptions.rb @@ -1,6 +1,11 @@ -require 'solidus' +# frozen_string_literal: true + +require 'solidus_core' require 'solidus_support' -require 'solidus_subscriptions/ability' -require 'solidus_subscriptions/engine' + require 'deface' require 'state_machines' + +require 'solidus_subscriptions/ability' +require 'solidus_subscriptions/version' +require 'solidus_subscriptions/engine' diff --git a/lib/solidus_subscriptions/engine.rb b/lib/solidus_subscriptions/engine.rb index 822f9b2..7b9f336 100644 --- a/lib/solidus_subscriptions/engine.rb +++ b/lib/solidus_subscriptions/engine.rb @@ -1,11 +1,18 @@ +# frozen_string_literal: true + +require 'spree/core' + +require 'solidus_subscriptions' +require 'solidus_subscriptions/permitted_attributes' +require 'solidus_subscriptions/config' +require 'solidus_subscriptions/processor' + module SolidusSubscriptions class Engine < Rails::Engine - require 'spree/core' - require 'solidus_subscriptions/permitted_attributes' - require 'solidus_subscriptions/config' - require 'solidus_subscriptions/processor' + include SolidusSupport::EngineExtensions isolate_namespace SolidusSubscriptions + engine_name 'solidus_subscriptions' # use rspec for tests @@ -13,8 +20,6 @@ module SolidusSubscriptions g.test_framework :rspec end - config.autoload_paths << config.root.join('app', 'jobs') - initializer 'configure spree subcription permitted attributes', after: 'require subscription lib helpers' do PermittedAttributes.update_spree_permiteed_attributes end @@ -40,10 +45,6 @@ module SolidusSubscriptions end def self.activate - Dir.glob(File.join(File.dirname(__FILE__), '../../app/decorators/**/*.rb')) do |c| - Rails.configuration.cache_classes ? require(c) : load(c) - end - Spree::Ability.register_ability(SolidusSubscriptions::Ability) end diff --git a/lib/solidus_subscriptions/version.rb b/lib/solidus_subscriptions/version.rb index 0b77f6d..20e95e7 100644 --- a/lib/solidus_subscriptions/version.rb +++ b/lib/solidus_subscriptions/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidusSubscriptions VERSION = '0.0.1' end diff --git a/solidus_subscriptions.gemspec b/solidus_subscriptions.gemspec index 2c8cfc7..05779be 100644 --- a/solidus_subscriptions.gemspec +++ b/solidus_subscriptions.gemspec @@ -1,42 +1,43 @@ # frozen_string_literal: true -$:.push File.expand_path('lib', __dir__) -require 'solidus_subscriptions/version' - -Gem::Specification.new do |s| - s.name = 'solidus_subscriptions' - s.version = SolidusSubscriptions::VERSION - s.summary = 'Add subscription support to Solidus' - s.description = s.summary - s.license = 'BSD-3-Clause' - - s.author = 'Solidus Team' - s.email = 'contact@solidus.io' - - if s.respond_to?(:metadata) - s.metadata["homepage_uri"] = s.homepage if s.homepage - s.metadata["source_code_uri"] = s.homepage if s.homepage - end - - 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 'deface' - s.add_dependency 'i18n' - s.add_dependency 'solidus' - s.add_dependency 'solidus_core', ['>= 2.0.0', '< 3'] - s.add_dependency 'solidus_support', '~> 0.5' - s.add_dependency 'state_machines' - - s.add_development_dependency 'rspec-activemodel-mocks' - s.add_development_dependency 'shoulda-matchers', '~> 3.1' - s.add_development_dependency 'solidus_dev_support' - s.add_development_dependency 'timecop' - s.add_development_dependency 'versioncake' - s.add_development_dependency 'yard' +require_relative 'lib/solidus_subscriptions/version' + +Gem::Specification.new do |spec| + spec.name = 'solidus_subscriptions' + spec.version = SolidusSubscriptions::VERSION + spec.authors = ['Solidus Team'] + spec.email = 'contact@solidus.io' + + spec.summary = 'Add subscription support to Solidus' + spec.description = 'Add subscription support to Solidus' + spec.homepage = 'https://github.com/solidusio-contrib/solidus_subscriptions' + spec.license = 'BSD-3-Clause' + + spec.metadata['homepage_uri'] = spec.homepage + spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_subscriptions' + + spec.required_ruby_version = Gem::Requirement.new('~> 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. + 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', '< 3'] + spec.add_dependency 'solidus_support', '~> 0.5' + spec.add_dependency 'deface' + spec.add_dependency 'i18n' + spec.add_dependency 'state_machines' + + spec.add_development_dependency 'rspec-activemodel-mocks' + spec.add_development_dependency 'shoulda-matchers', '~> 3.1' + spec.add_development_dependency 'solidus_dev_support' + spec.add_development_dependency 'timecop' + spec.add_development_dependency 'versioncake' + spec.add_development_dependency 'yard' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c18636..2f15fad 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,15 @@ # frozen_string_literal: true # Configure Rails Environment -ENV['RAILS_ENV'] ||= 'test' +ENV['RAILS_ENV'] = 'test' # Run Coverage report require 'solidus_dev_support/rspec/coverage' -require File.expand_path('dummy/config/environment.rb', __dir__) +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 +} # Requires factories and other useful helpers defined in spree_core. require 'solidus_dev_support/rspec/feature_helper' |