Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #289 from nebulab/mm/dev-support
Browse files Browse the repository at this point in the history
Make extension compliant to solidus_dev_support
  • Loading branch information
kennyadsl authored Nov 16, 2022
2 parents d15364a + f53fe59 commit 920a4e7
Show file tree
Hide file tree
Showing 25 changed files with 270 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand All @@ -23,6 +24,7 @@ jobs:
lint-code:
executor: solidusio_extensions/sqlite-memory
steps:
- browser-tools/install-browser-tools
- solidusio_extensions/lint-code

workflows:
Expand All @@ -31,6 +33,7 @@ workflows:
- run-specs-with-postgres
- run-specs-with-mysql
- lint-code

"Weekly run specs against master":
triggers:
- schedule:
Expand Down
2 changes: 2 additions & 0 deletions .github_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
issues=false
exclude-labels=infrastructure
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
.project
.sass-cache
coverage
Gemfile-local
Gemfile.lock
tmp
nbproject
pkg
*.swp
spec/dummy
spec/examples.txt
.bundle/
.env
/sandbox
.rvmrc
.ruby-version
.ruby-gemset
38 changes: 18 additions & 20 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,20 @@ 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
gem 'solidus', github: 'solidusio/solidus', branch: branch

gem 'rails', ENV.fetch('RAILS_VERSION', nil)
# The solidus_frontend gem has been pulled out since v3.2
gem 'solidus_frontend', github: 'solidusio/solidus_frontend' if branch == 'master'
gem 'solidus_frontend' if branch >= 'v3.2' # rubocop:disable Bundler/DuplicatedGem

# 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'

# Asset compilation speed
gem 'mini_racer'
gem 'sassc-rails', platforms: :mri

gem 'bourbon'

case ENV.fetch('DB', nil)
when 'mysql'
gem 'mysql2'
Expand All @@ -32,13 +27,16 @@ else
gem 'sqlite3'
end

group :test do
gem 'rails-controller-testing'
gem 'webdrivers'
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.: `gem 'pry-debug'`.
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'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Placeholder manifest file.
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
*/
1 change: 1 addition & 0 deletions app/models/solidus_paypal_braintree/gateway.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'braintree'
require 'solidus_paypal_braintree/request_protection'

module SolidusPaypalBraintree
class Gateway < ::Spree::PaymentMethod
Expand Down
4 changes: 3 additions & 1 deletion app/models/solidus_paypal_braintree/source.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

require 'solidus_paypal_braintree/request_protection'

module SolidusPaypalBraintree
class Source < SolidusSupport.payment_source_parent_class
class Source < ::Spree::PaymentSource
include RequestProtection

PAYPAL = "PayPalAccount"
Expand Down
1 change: 1 addition & 0 deletions app/models/solidus_paypal_braintree/transaction_address.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'active_model'
require 'solidus_paypal_braintree/country_mapper'

module SolidusPaypalBraintree
class TransactionAddress
Expand Down
16 changes: 4 additions & 12 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -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
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
13 changes: 13 additions & 0 deletions bin/rails-engine
Original file line number Diff line number Diff line change
@@ -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_paypal_braintree/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'
16 changes: 16 additions & 0 deletions bin/rails-sandbox
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "rubygems"
require "bundler/setup"

load Gem.bin_path("rake", "rake")
102 changes: 102 additions & 0 deletions bin/sandbox
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash

set -e
if [ ! -z $DEBUG ]
then
set -x
fi

case "$DB" in
postgres|postgresql)
RAILSDB="postgresql"
;;
mysql)
RAILSDB="mysql"
;;
sqlite3|sqlite)
RAILSDB="sqlite3"
;;
'')
echo "~~> Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
RAILSDB="sqlite3"
;;
*)
echo "Invalid value specified for the Solidus sandbox: DB=\"$DB\"."
echo "Please use 'postgres', 'mysql', or 'sqlite' instead."
exit 1
;;
esac
echo "~~> Using $RAILSDB as the database engine"

if [ -n $SOLIDUS_BRANCH ]
then
BRANCH=$SOLIDUS_BRANCH
else
echo "~~> Use 'export SOLIDUS_BRANCH=[master|v3.2|...]' to control the Solidus branch"
BRANCH="master"
fi
echo "~~> Using branch $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_paypal_braintree"

# 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 '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 \
--enforce_available_locales=true \
--with-authentication=true \
--payment-method=none \
--frontend=${SOLIDUS_FRONTEND} \
$@

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."
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -vx

gem install bundler --conservative
bundle update
bundle exec rake clobber
bin/rake clobber
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ module SolidusPaypalBraintree
module Generators
class InstallGenerator < Rails::Generators::Base
class_option :auto_run_migrations, type: :boolean, default: false
source_root File.expand_path('templates', __dir__)

def copy_initializer
template 'initializer.rb', 'config/initializers/solidus_paypal_braintree.rb'
end

def add_javascripts
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require solidus_paypal_braintree/frontend\n"
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_braintree\n" # rubocop:disable Layout/LineLength
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_braintree\n" # rubocop:disable Layout/LineLength
end

Expand All @@ -16,7 +21,7 @@ def add_stylesheets
end

def add_migrations
run 'bundle exec rake railties:install:migrations FROM=solidus_paypal_braintree'
run 'bin/rails railties:install:migrations FROM=solidus_paypal_braintree'
end

def mount_engine
Expand All @@ -28,9 +33,9 @@ def mount_engine
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 Layout/LineLength
if run_migrations
run 'bundle exec rake db:migrate'
run 'bin/rails db:migrate'
else
say_status :skipping, 'rake db:migrate, don\'t forget to run it!'
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

SolidusPaypalBraintree.configure do |config|
# TODO: Remember to change this with the actual preferences you have implemented!
# config.sample_preference = 'sample_value'
end
8 changes: 5 additions & 3 deletions lib/solidus_paypal_braintree.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

require 'solidus_core'
require 'solidus_paypal_braintree/version'
require 'solidus_paypal_braintree/engine'
require 'solidus_support'

require 'solidus_paypal_braintree/country_mapper'
require 'solidus_paypal_braintree/request_protection'
require 'solidus_support'
require 'solidus_paypal_braintree/extension_configuration'
require 'solidus_paypal_braintree/version'
require 'solidus_paypal_braintree/engine'

module SolidusPaypalBraintree
def self.table_name_prefix
Expand Down
11 changes: 6 additions & 5 deletions lib/solidus_paypal_braintree/engine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'solidus_core'
require 'solidus_support'

module SolidusPaypalBraintree
Expand All @@ -13,11 +14,6 @@ class Engine < Rails::Engine
inflect.acronym 'AVS'
end

# use rspec for tests
config.generators do |g|
g.test_framework :rspec
end

initializer "register_solidus_paypal_braintree_gateway", after: "spree.register.payment_methods" do |app|
config.to_prepare do
app.config.spree.payment_methods << SolidusPaypalBraintree::Gateway
Expand Down Expand Up @@ -64,5 +60,10 @@ class Engine < Rails::Engine
end
end
end

# use rspec for tests
config.generators do |g|
g.test_framework :rspec
end
end
end
Loading

0 comments on commit 920a4e7

Please sign in to comment.