From a6cc39bb85fb2786c5ed8e9e0f68a689a4f88822 Mon Sep 17 00:00:00 2001 From: Alessandro Desantis Date: Fri, 24 Jan 2020 11:13:11 +0100 Subject: [PATCH] Upgrade infrastructure with solidus_dev_support --- .gem_release.yml | 5 + .github/stale.yml | 17 ++ .gitignore | 1 + .rspec | 4 +- .rubocop.yml | 236 +----------------- Gemfile | 48 ++-- LICENSE | 4 +- Rakefile | 29 +-- .../spree/frontend/solidus_affirm.js | 2 +- bin/console | 17 ++ bin/rails | 18 +- bin/setup | 8 + .../install/install_generator.rb | 8 +- lib/solidus_affirm.rb | 6 +- lib/solidus_affirm/engine.rb | 10 +- lib/solidus_affirm/version.rb | 2 + solidus_affirm.gemspec | 50 ++-- spec/spec_helper.rb | 57 +---- spec/support/solidus.rb | 5 + spec/support/vcr.rb | 5 + 20 files changed, 154 insertions(+), 378 deletions(-) create mode 100644 .gem_release.yml create mode 100644 .github/stale.yml create mode 100755 bin/console mode change 100644 => 100755 bin/rails create mode 100755 bin/setup create mode 100644 spec/support/solidus.rb diff --git a/.gem_release.yml b/.gem_release.yml new file mode 100644 index 0000000..d86d8dc --- /dev/null +++ b/.gem_release.yml @@ -0,0 +1,5 @@ +bump: + recurse: false + file: 'lib/solidus_affirm/version.rb' + message: Bump SolidusAffirm to %{version} + tag: true diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..d9f6563 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,17 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security +# Label to use when marking an issue as stale +staleLabel: wontfix +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 39de5bc..bcd4aea 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ nbproject pkg *.swp spec/dummy +spec/examples.txt diff --git a/.rspec b/.rspec index 7ab5f55..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1,4 +1,2 @@ --color ---format -progress ---backtrace +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index 2ffca3f..6207a64 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,234 +1,2 @@ -# Relaxed.Ruby.Style - -AllCops: - Exclude: - - 'solidus_affirm.gemspec' - - 'spec/dummy/**/*' - - 'vendor/bundle/**/*' - TargetRubyVersion: 2.2 - -# Sometimes I believe this reads better -# This also causes spacing issues on multi-line fixes -Style/BracesAroundHashParameters: - Enabled: false - -# We use class vars and will have to continue doing so for compatability -Style/ClassVars: - Enabled: false - -# We need these names for backwards compatability -Naming/PredicateName: - Enabled: false - -Naming/AccessorMethodName: - Enabled: false - -# This has been used for customization -Style/MutableConstant: - Enabled: false - -Style/ClassAndModuleChildren: - Enabled: false - -Style/GuardClause: - Enabled: false - -Style/WordArray: - Enabled: false - -Style/ConditionalAssignment: - Enabled: false - -Performance/Count: - Enabled: false - -Style/RaiseArgs: - Enabled: false - -# We can use good judgement here -Style/RegexpLiteral: - Enabled: false - -# Unicode comments are useful -Style/AsciiComments: - Enabled: false - -Layout/EndAlignment: - Enabled: false - -Layout/ElseAlignment: - Enabled: false - -Layout/IndentationWidth: - Enabled: false - -Layout/AlignParameters: - Enabled: false - -Layout/ClosingParenthesisIndentation: - Enabled: false - -Layout/MultilineMethodCallIndentation: - Enabled: false - -Layout/IndentArray: - Enabled: false - -Layout/IndentHash: - Enabled: false - -Layout/AlignHash: - Enabled: false - -# From http://relaxed.ruby.style/ - -Style/Alias: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylealias - -Style/BeginBlock: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylebeginblock - -Style/BlockDelimiters: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters - -Style/Documentation: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledocumentation - -Layout/DotPosition: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledotposition - -Style/DoubleNegation: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styledoublenegation - -Style/EndBlock: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleendblock - -Style/FormatString: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleformatstring - -Style/IfUnlessModifier: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier - -Style/Lambda: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylelambda - -Style/ModuleFunction: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylemodulefunction - -Style/MultilineBlockChain: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain - -Style/NegatedIf: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylenegatedif - -Style/NegatedWhile: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile - -Style/ParallelAssignment: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleparallelassignment - -Style/PercentLiteralDelimiters: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters - -Style/PerlBackrefs: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs - -Style/Semicolon: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesemicolon - -Style/SignalException: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesignalexception - -Style/SingleLineBlockParams: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams - -Style/SingleLineMethods: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods - -Layout/SpaceBeforeBlockBraces: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces - -Layout/SpaceInsideParens: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens - -Style/SpecialGlobalVars: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars - -Style/StringLiterals: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylestringliterals - -Style/SymbolProc: - Enabled: false - -Style/WhileUntilModifier: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier - -Lint/AmbiguousRegexpLiteral: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral - -Lint/AssignmentInCondition: - Enabled: false - StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition - -Lint/HandleExceptions: - Exclude: - - 'Rakefile' - -Metrics/AbcSize: - Enabled: false - -Metrics/BlockNesting: - Enabled: false - -Metrics/ClassLength: - Enabled: false - -Metrics/ModuleLength: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/LineLength: - Enabled: false - -Metrics/MethodLength: - Enabled: false - -Metrics/ParameterLists: - Enabled: false - -Metrics/BlockLength: - Exclude: - - 'spec/**/*.rb' - - '*.gemspec' - -Naming/BinaryOperatorParameterName: - Enabled: false +require: + - solidus_dev_support/rubocop diff --git a/Gemfile b/Gemfile index c63d850..e3c4c59 100644 --- a/Gemfile +++ b/Gemfile @@ -1,38 +1,32 @@ +# frozen_string_literal: true + source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } branch = ENV.fetch('SOLIDUS_BRANCH', 'master') - gem 'solidus', github: 'solidusio/solidus', branch: branch -if ENV['DB'] == 'mysql' - gem 'mysql2' -else - gem 'pg', '~> 0.21' -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' -# Needed to help Bundler figure out how to resolve dependencies, otherwise it takes forever to -# resolve them -if branch == 'master' || Gem::Version.new(branch[1..-1]) >= Gem::Version.new('2.10.0') - gem 'rails', '~> 6.0' -else - gem 'rails', '~> 5.0' -end +# Provides basic authentication functionality for testing parts of your engine +gem 'solidus_auth_devise' -group :development, :test do - gem "pry-rails" +case ENV['DB'] +when 'mysql' + gem 'mysql2' +when 'postgresql' + gem 'pg' +else + gem 'sqlite3' end -group :test do - gem 'solidus_support', github: 'solidusio/solidus_support' - - factory_bot_version = if branch < 'v2.5' - '4.10.0' - else - '> 4.10.0' - end - - gem 'factory_bot', factory_bot_version - gem 'rails-controller-testing' -end +gem 'rails-controller-testing', group: :test 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'`. +eval_gemfile 'Gemfile-local' if File.exist? 'Gemfile-local' diff --git a/LICENSE b/LICENSE index 3218ef6..d6f1b1d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2016 [name of plugin creator] +Copyright (c) 2020 Peter Berkenbosch All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -9,7 +9,7 @@ are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name Spree nor the names of its contributors may be used to + * Neither the name Solidus nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. diff --git a/Rakefile b/Rakefile index 1b12f5d..c08aa46 100644 --- a/Rakefile +++ b/Rakefile @@ -1,27 +1,6 @@ -require 'bundler' +# frozen_string_literal: true -Bundler::GemHelper.install_tasks +require 'solidus_dev_support/rake_tasks' +SolidusDevSupport::RakeTasks.install -begin - require 'spree/testing_support/extension_rake' - require 'rspec/core/rake_task' - - RSpec::Core::RakeTask.new(:spec) - - task default: %i(first_run spec) -rescue LoadError - # no rspec available -end - -task :first_run do - if Dir['spec/dummy'].empty? - Rake::Task[:test_app].invoke - Dir.chdir('../../') - end -end - -desc 'Generates a dummy app for testing' -task :test_app do - ENV['LIB_NAME'] = 'solidus_affirm' - Rake::Task['extension:test_app'].invoke -end +task default: 'extension:specs' diff --git a/app/assets/javascripts/spree/frontend/solidus_affirm.js b/app/assets/javascripts/spree/frontend/solidus_affirm.js index 103cdc7..a79f2e9 100644 --- a/app/assets/javascripts/spree/frontend/solidus_affirm.js +++ b/app/assets/javascripts/spree/frontend/solidus_affirm.js @@ -1,2 +1,2 @@ // Placeholder manifest file. -// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js' +// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js' \ No newline at end of file diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..aeb99da --- /dev/null +++ b/bin/console @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# frozen_string_literal: true + +require "bundler/setup" +require "solidus_affirm" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. +$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"]) + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/rails b/bin/rails old mode 100644 new mode 100755 index bd983d9..c535fd2 --- a/bin/rails +++ b/bin/rails @@ -1,7 +1,15 @@ -# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. +#!/usr/bin/env ruby -ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/solidus_affirm/engine', __FILE__) +# frozen_string_literal: true -require 'rails/all' -require 'rails/engine/commands' +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 +end + +Dir.chdir app_root +exec 'bin/rails', *ARGV diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..40d7811 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +gem install bundler --conservative +bundle update +bundle exec rake clobber diff --git a/lib/generators/solidus_affirm/install/install_generator.rb b/lib/generators/solidus_affirm/install/install_generator.rb index f7327f7..387f2da 100644 --- a/lib/generators/solidus_affirm/install/install_generator.rb +++ b/lib/generators/solidus_affirm/install/install_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidusAffirm module Generators class InstallGenerator < Rails::Generators::Base @@ -9,8 +11,8 @@ def add_javascripts end def add_stylesheets - inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_affirm\n", before: /\*\//, verbose: true - inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_affirm\n", before: /\*\//, verbose: true + inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_affirm\n", before: %r{\*/}, verbose: true + inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_affirm\n", before: %r{\*/}, verbose: true end def add_migrations @@ -22,7 +24,7 @@ def run_migrations if run_migrations run 'bundle exec rake db:migrate' else - puts 'Skipping rake db:migrate, don\'t forget to run it!' + puts 'Skipping rake db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output end end end diff --git a/lib/solidus_affirm.rb b/lib/solidus_affirm.rb index 2c0b784..48c6c3f 100644 --- a/lib/solidus_affirm.rb +++ b/lib/solidus_affirm.rb @@ -1,5 +1,9 @@ +# frozen_string_literal: true + require 'solidus_core' -require "solidus_support" +require 'solidus_support' + +require 'solidus_affirm/version' require 'solidus_affirm/engine' require 'solidus_affirm/callback_hook/base' require 'solidus_affirm/affirm_client' diff --git a/lib/solidus_affirm/engine.rb b/lib/solidus_affirm/engine.rb index b9436b5..c14ffb5 100644 --- a/lib/solidus_affirm/engine.rb +++ b/lib/solidus_affirm/engine.rb @@ -1,7 +1,13 @@ +# frozen_string_literal: true + +require 'spree/core' + module SolidusAffirm class Engine < Rails::Engine - require 'spree/core' - isolate_namespace Spree + include SolidusSupport::EngineExtensions::Decorators + + isolate_namespace ::Spree + engine_name 'solidus_affirm' # use rspec for tests diff --git a/lib/solidus_affirm/version.rb b/lib/solidus_affirm/version.rb index 1f8fed5..cef8787 100644 --- a/lib/solidus_affirm/version.rb +++ b/lib/solidus_affirm/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SolidusAffirm VERSION = '0.0.1' end diff --git a/solidus_affirm.gemspec b/solidus_affirm.gemspec index 9131c73..f55eda9 100644 --- a/solidus_affirm.gemspec +++ b/solidus_affirm.gemspec @@ -1,39 +1,39 @@ -$:.push File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +$:.push File.expand_path('lib', __dir__) require 'solidus_affirm/version' Gem::Specification.new do |s| - s.name = 'solidus_affirm' - s.version = SolidusAffirm::VERSION - s.summary = 'Solidus extension for using Affirm in your store' - s.description = s.summary + s.name = 'solidus_affirm' + s.version = SolidusAffirm::VERSION + s.summary = 'Solidus extension for using Affirm in your store' + s.license = 'BSD-3-Clause' + + s.author = 'Peter Berkenbosch' + s.email = 'peter@stembolt.com' + s.homepage = 'https://stembolt.com/' - s.required_ruby_version = ">= 2.1" + 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.author = 'Peter Berkenbosch' - s.email = 'peter@stembolt.com' - s.homepage = 'https://stembolt.com/' - s.license = 'BSD-3' + s.required_ruby_version = '~> 2.4' - s.files = Dir["{app,config,db,lib}/**/*", 'LICENSE', 'Rakefile', 'README.md'] - s.test_files = Dir['test/**/*'] + 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 'active_model_serializers', '~> 0.10' s.add_dependency 'affirm-ruby', '1.1.0' - s.add_dependency 'solidus', ['>= 2.0', '< 3'] + s.add_dependency 'solidus_core', ['>= 2.0', '< 3'] s.add_dependency "solidus_support", '>= 0.2.2' - s.add_development_dependency 'capybara', '~> 3.29' - s.add_development_dependency "capybara-screenshot" - s.add_development_dependency 'coffee-rails' - s.add_development_dependency 'database_cleaner' - s.add_development_dependency 'factory_bot' - s.add_development_dependency 'ffaker' - s.add_development_dependency 'selenium-webdriver' - s.add_development_dependency 'rspec-rails' - s.add_development_dependency 'rubocop', '>= 0.38' - s.add_development_dependency 'rubocop-rspec', '1.4.0' - s.add_development_dependency 'simplecov' - s.add_development_dependency 'sqlite3' + s.add_development_dependency 'solidus_dev_support' s.add_development_dependency 'vcr' s.add_development_dependency 'webmock' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3378ad7..3a0a041 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,67 +1,24 @@ -# Run Coverage report -require 'simplecov' - -SimpleCov.start do - add_filter 'spec/dummy' - add_group 'Controllers', 'app/controllers' - add_group 'Helpers', 'app/helpers' - add_group 'Mailers', 'app/mailers' - add_group 'Models', 'app/models' - add_group 'Views', 'app/views' - add_group 'Libraries', 'lib' -end +# frozen_string_literal: true # Configure Rails Environment ENV['RAILS_ENV'] = 'test' +# Run Coverage report +require 'solidus_dev_support/rspec/coverage' + require File.expand_path('dummy/config/environment.rb', __dir__) -require 'solidus_support/extension/feature_helper' -require 'vcr' + +# 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 } -require 'spree/testing_support/controller_requests' - # Requires factories defined in lib/solidus_affirm/factories.rb require 'solidus_affirm/factories' -Spree::Core::Engine.routes.default_url_options = { - host: 'shop.localhost:3000' -} - RSpec.configure do |config| - # Infer an example group's spec type from the file location. config.infer_spec_type_from_file_location! - - # == Mock Framework - # - # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: - # - # config.mock_with :mocha - # config.mock_with :flexmock - # config.mock_with :rr - - # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" - - # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner - # to cleanup after each test instead. Without transactional fixtures set to false the records created - # to setup a test will be unavailable to the browser, which runs under a separate server instance. config.use_transactional_fixtures = false - - # Ensure Suite is set to use transactions for speed. - config.before :suite do - DatabaseCleaner.strategy = :transaction - end - - config.before :each do - DatabaseCleaner.start - end - - # After each spec clean the database. - config.after :each do - DatabaseCleaner.clean - end end diff --git a/spec/support/solidus.rb b/spec/support/solidus.rb new file mode 100644 index 0000000..1daf281 --- /dev/null +++ b/spec/support/solidus.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Spree::Core::Engine.routes.default_url_options = { + host: 'shop.localhost:3000' +} diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb index 5d51d0e..86fbde1 100644 --- a/spec/support/vcr.rb +++ b/spec/support/vcr.rb @@ -1,3 +1,8 @@ +# frozen_string_literal: true + +require 'webmock' +require 'vcr' + VCR.configure do |config| config.ignore_localhost = true config.cassette_library_dir = "spec/fixtures/vcr_casettes"