From 9b7547d443f633e69767e2235bbf4f53f9bcc222 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 15 Jan 2021 17:05:51 +0100 Subject: [PATCH 1/3] Update gem with the latest dev_support with solidus extension . Co-authored-by: Rainer Dema --- .circleci/config.yml | 6 ++ .gem_release.yml | 2 +- .github/stale.yml | 8 +- .github_changelog_generator | 2 + .gitignore | 5 +- .rubocop.yml | 4 +- Gemfile | 12 +-- LICENSE | 4 +- README.md | 80 +++++++++++-------- bin/rails | 16 +--- bin/rails-engine | 13 +++ bin/rails-sandbox | 16 ++++ bin/sandbox | 2 + config/locales/en.yml | 5 ++ .../install/install_generator.rb | 6 +- lib/solidus_stripe.rb | 10 +-- lib/solidus_stripe/configuration.rb | 21 +++++ lib/solidus_stripe/engine.rb | 15 +--- .../{ => testing_support}/factories.rb | 0 lib/solidus_stripe/version.rb | 2 +- solidus_stripe.gemspec | 2 +- spec/spec_helper.rb | 17 ++-- 22 files changed, 152 insertions(+), 96 deletions(-) create mode 100644 .github_changelog_generator create mode 100755 bin/rails-engine create mode 100755 bin/rails-sandbox create mode 100644 config/locales/en.yml create mode 100644 lib/solidus_stripe/configuration.rb rename lib/solidus_stripe/{ => testing_support}/factories.rb (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 12bb10ef..e7e2f713 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,12 +16,18 @@ jobs: executor: solidusio_extensions/mysql steps: - solidusio_extensions/run-tests + lint-code: + executor: solidusio_extensions/sqlite-memory + steps: + - solidusio_extensions/lint-code workflows: "Run specs on supported Solidus versions": jobs: - run-specs-with-postgres - run-specs-with-mysql + - lint-code + "Weekly run specs against master": triggers: - schedule: diff --git a/.gem_release.yml b/.gem_release.yml index 3d21bb76..29f0df51 100644 --- a/.gem_release.yml +++ b/.gem_release.yml @@ -1,5 +1,5 @@ bump: recurse: false file: 'lib/solidus_stripe/version.rb' - message: Bump Solidus Stripe to %{version} + message: Bump SolidusStripe to %{version} tag: true diff --git a/.github/stale.yml b/.github/stale.yml index d9f65632..03407b31 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -1,17 +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 +daysUntilClose: false # Issues with these labels will never be considered stale exemptLabels: - pinned - security # Label to use when marking an issue as stale -staleLabel: wontfix +staleLabel: stale # 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 + recent activity. It might 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 +closeComment: false diff --git a/.github_changelog_generator b/.github_changelog_generator new file mode 100644 index 00000000..eac09621 --- /dev/null +++ b/.github_changelog_generator @@ -0,0 +1,2 @@ +issues=false +exclude-labels=infrastructure diff --git a/.gitignore b/.gitignore index a15c4e82..325c3c99 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,6 @@ .DS_Store .idea .project -.ruby-version -.rvmrc .sass-cache coverage Gemfile.lock @@ -17,3 +15,6 @@ pkg spec/dummy spec/examples.txt /sandbox +.rvmrc +.ruby-version +.ruby-gemset diff --git a/.rubocop.yml b/.rubocop.yml index 98a59b9b..b075a8f6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,4 @@ require: - solidus_dev_support/rubocop AllCops: - Exclude: - - sandbox/**/* - - spec/dummy/**/* + NewCops: disable diff --git a/Gemfile b/Gemfile index 595334e1..24c83d8f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,10 @@ # frozen_string_literal: true -source "https://rubygems.org" +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 +gem 'solidus', github: 'solidusio/solidus', branch: branch # Needed to help Bundler figure out how to resolve dependencies, # otherwise it takes forever to resolve them. @@ -12,7 +12,7 @@ gem "solidus", github: "solidusio/solidus", branch: branch gem 'rails', '>0.a' # Provides basic authentication functionality for testing parts of your engine -gem "solidus_auth_devise" +gem 'solidus_auth_devise' case ENV['DB'] when 'mysql' @@ -23,12 +23,6 @@ else gem 'sqlite3' end -group :development, :test do - gem "pry-rails" - gem "ffaker" - gem "rails-controller-testing" -end - gemspec # Use a local Gemfile to include development dependencies that might not be diff --git a/LICENSE b/LICENSE index 7a80e31d..3a3d70a8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ Copyright (c) 2014 Spree Commerce Inc. and other contributors. -Copyright (c) 2020 Solidus Team and other contributors. +Copyright (c) 2021 Solidus Team and other contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -10,7 +10,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/README.md b/README.md index 761c2837..0f75dabb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -Solidus Stripe -=============== +# Solidus Stripe -[![CircleCI](https://circleci.com/gh/solidusio/solidus_stripe.svg?style=svg)](https://circleci.com/gh/solidusio/solidus_stripe) +[![CircleCI](https://circleci.com/gh/solidusio/solidus_stripe.svg?style=shield)](https://circleci.com/gh/solidusio/solidus_stripe) +[![codecov](https://codecov.io/gh/solidusio/solidus_stripe/branch/master/graph/badge.svg)](https://codecov.io/gh/solidusio/solidus_stripe) Stripe Payment Method for Solidus. It works as a wrapper for the ActiveMerchant Stripe gateway. @@ -21,7 +21,6 @@ Then run from the command line: ```shell bundle install bundle exec rails g solidus_stripe:install -bundle exec rails db:migrate ``` Usage @@ -259,53 +258,68 @@ SolidusStripe.Payment.prototype.elementsBaseOptions = function () { }; ``` - -Migrating from solidus_gateway ------------------------------- +## Migrating from solidus_gateway If you were previously using `solidus_gateway` gem you might want to check out our [Wiki page](https://github.com/solidusio/solidus_stripe/wiki/Migrating-from-solidus_gateway) that describes how to handle this migration. -Testing -------- +## Development + +### Testing the extension -Then just run the following to automatically build a dummy app if necessary and -run the tests: +First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy +app if it does not exist, then it will run specs. The dummy app can be regenerated by using +`bin/rake extension:test_app`. ```shell -bundle exec rake +bin/rake ``` -Releasing ---------- +To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run -We use [gem-release](https://github.com/svenfuchs/gem-release) to release this -extension with ease. +```shell +bundle exec rubocop +``` -Supposing you are on the master branch and you are working on a fork of this -extension, `upstream` is the main remote and you have write access to it, you -can simply run: +When testing your application's integration with this extension you may use its factories. +Simply add this require statement to your spec_helper: -``` -gem bump --version minor --tag --release --remote upstream +```ruby +require '<%= file_name %>/factories' ``` -This command will: +### Running the sandbox -- bump the gem version to the next minor (changing the `version.rb` file) -- commit the change and push it to upstream master -- create a git tag -- push the tag to the upstream remote -- release the new version on RubyGems +To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for +the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to +`sandbox/bin/rails`. -Or you can run these commands individually: +Here's an example: ``` -gem bump --version minor --remote upstream -gem tag --remote upstream -gem release +$ bin/rails server +=> Booting Puma +=> Rails 6.0.2.1 application starting in development +* Listening on tcp://127.0.0.1:3000 +Use Ctrl-C to stop ``` -Copyright (c) 2020 Spree Commerce Inc., released under the New BSD License -Copyright (c) 2020 Solidus Team, released under the New BSD License +### Updating the changelog + +Before and after releases the changelog should be updated to reflect the up-to-date status of +the project: + +```shell +bin/rake changelog +git add CHANGELOG.md +git commit -m "Update the changelog" +``` + +### Releasing new versions + +Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki. + +## License +Copyright (c) 2014 Spree Commerce Inc., released under the New BSD License +Copyright (c) 2021 Solidus Team, released under the New BSD License diff --git a/bin/rails b/bin/rails index c535fd20..6dbbbc36 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 00000000..c33336de --- /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_stripe/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 00000000..ad2df04d --- /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/sandbox b/bin/sandbox index 0f365776..8736bef9 100755 --- a/bin/sandbox +++ b/bin/sandbox @@ -72,9 +72,11 @@ unbundled bundle exec rails generate spree:install \ --user_class=Spree::User \ --enforce_available_locales=true \ --with-authentication=false \ + --payment-method=none \ $@ unbundled bundle exec rails generate solidus:auth:install +unbundled bundle exec rails generate ${extension_name}:install echo echo "🚀 Sandbox app successfully created for $extension_name!" diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 00000000..f341cf45 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,5 @@ +# Sample localization file for English. Add more files in this directory for other locales. +# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. + +en: + hello: Hello world diff --git a/lib/generators/solidus_stripe/install/install_generator.rb b/lib/generators/solidus_stripe/install/install_generator.rb index 64380a6d..59643de5 100644 --- a/lib/generators/solidus_stripe/install/install_generator.rb +++ b/lib/generators/solidus_stripe/install/install_generator.rb @@ -9,16 +9,12 @@ def add_javascripts append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_stripe\n" end - def add_migrations - run 'bundle exec rake railties:install:migrations FROM=solidus_stripe' - end - def add_migrations run 'bin/rails railties:install:migrations FROM=solidus_stripe' end def run_migrations - run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Metrics/LineLength + 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 'bin/rails db:migrate' else diff --git a/lib/solidus_stripe.rb b/lib/solidus_stripe.rb index b3c76b30..2b7ca2a0 100644 --- a/lib/solidus_stripe.rb +++ b/lib/solidus_stripe.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -require "active_merchant" -require "solidus_core" -require "solidus_support" -require "solidus_stripe/engine" -require "solidus_stripe/version" +require 'active_merchant' + +require 'solidus_stripe/configuration' +require 'solidus_stripe/version' +require 'solidus_stripe/engine' diff --git a/lib/solidus_stripe/configuration.rb b/lib/solidus_stripe/configuration.rb new file mode 100644 index 00000000..0c6eb54f --- /dev/null +++ b/lib/solidus_stripe/configuration.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module SolidusStripe + class Configuration + # Define here the settings for this extensions, 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_stripe/engine.rb b/lib/solidus_stripe/engine.rb index b9bfe2e3..8bb925d4 100644 --- a/lib/solidus_stripe/engine.rb +++ b/lib/solidus_stripe/engine.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require 'spree/core' +require 'solidus_core' +require 'solidus_support' module SolidusStripe class Engine < Rails::Engine @@ -15,18 +16,6 @@ class Engine < Rails::Engine g.test_framework :rspec end - if SolidusSupport.backend_available? - paths["app/views"] << "lib/views/backend" - end - - if SolidusSupport.frontend_available? - paths["app/views"] << "lib/views/frontend" - end - - if SolidusSupport.api_available? - paths["app/views"] << "lib/views/api" - end - initializer "spree.payment_method.add_stripe_credit_card", after: "spree.register.payment_methods" do |app| app.config.spree.payment_methods << "Spree::PaymentMethod::StripeCreditCard" end diff --git a/lib/solidus_stripe/factories.rb b/lib/solidus_stripe/testing_support/factories.rb similarity index 100% rename from lib/solidus_stripe/factories.rb rename to lib/solidus_stripe/testing_support/factories.rb diff --git a/lib/solidus_stripe/version.rb b/lib/solidus_stripe/version.rb index e6eb55db..4fa50f1c 100644 --- a/lib/solidus_stripe/version.rb +++ b/lib/solidus_stripe/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SolidusStripe - VERSION = "4.2.0" + VERSION = '4.2.0' end diff --git a/solidus_stripe.gemspec b/solidus_stripe.gemspec index 151a6c3b..56333ea4 100644 --- a/solidus_stripe.gemspec +++ b/solidus_stripe.gemspec @@ -33,5 +33,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'solidus_support', '~> 0.5' spec.add_dependency 'activemerchant', '>= 1.100' - spec.add_development_dependency 'solidus_dev_support' + spec.add_development_dependency 'solidus_dev_support', '~> 2.3' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 46a595ee..a466b60c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,25 +6,32 @@ # 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_stripe/factories.rb -require 'solidus_stripe/factories' +# Requires factories defined in lib/solidus_stripe/testing_support/factories.rb +SolidusDevSupport::TestingSupport::Factories.load_for(SolidusStripe::Engine) # Requires card input helper defined in lib/solidus_stripe/testing_support/card_input_helper.rb require 'solidus_stripe/testing_support/card_input_helper' RSpec.configure do |config| config.infer_spec_type_from_file_location! - FactoryBot.find_definitions config.use_transactional_fixtures = false + config.include SolidusAddressNameHelper, type: :feature config.include SolidusCardInputHelper, type: :feature + + if Spree.solidus_gem_version < Gem::Version.new('2.11') + config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system + end end From f35a20d9e7ff11eb1803900ea83ad88501a049d3 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Tue, 19 Jan 2021 09:53:09 +0100 Subject: [PATCH 2/3] Disable code linting This gem is not ready for Rubocop linting and making it ready is not part of this PR scope. --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e7e2f713..aae317df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,6 @@ workflows: jobs: - run-specs-with-postgres - run-specs-with-mysql - - lint-code "Weekly run specs against master": triggers: From e8cfd158a1f1c988556b149af8d47143f23ed672 Mon Sep 17 00:00:00 2001 From: Filippo Liverani Date: Fri, 15 Jan 2021 17:54:00 +0100 Subject: [PATCH 3/3] Fix card input in feature specs --- .../testing_support/card_input_helper.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/solidus_stripe/testing_support/card_input_helper.rb b/lib/solidus_stripe/testing_support/card_input_helper.rb index 024fc057..0e62e748 100644 --- a/lib/solidus_stripe/testing_support/card_input_helper.rb +++ b/lib/solidus_stripe/testing_support/card_input_helper.rb @@ -9,16 +9,26 @@ def fill_in_card(card = {}) if preferred_v3_elements || preferred_v3_intents within_frame find('#card_number iframe') do - card[:number].split('').each { |n| find_field('cardnumber').native.send_keys(n) } + fill_in_number("cardnumber", card) end within_frame(find '#card_cvc iframe') { fill_in 'cvc', with: card[:code] } within_frame(find '#card_expiry iframe') do - "#{card[:exp_month]}#{card[:exp_year].last(2)}".split('').each { |n| find_field('exp-date').native.send_keys(n) } + fill_in_expiration("exp-date", card) end else - fill_in "Card Number", with: card[:number] + fill_in_number("Card Number", card) fill_in "Card Code", with: card[:code] - fill_in "Expiration", with: "#{card[:exp_month]} / #{card[:exp_year]}" + fill_in_expiration("Expiration", card) end end + + private + + def fill_in_number(field_name, card) + card[:number].split('').each { |n| find_field(field_name).native.send_keys(n) } + end + + def fill_in_expiration(field_name, card) + "#{card[:exp_month]}#{card[:exp_year].last(2)}".split('').each { |n| find_field(field_name).native.send_keys(n) } + end end