Skip to content

Commit

Permalink
Merge pull request #8 from tvdeyen/add-payment_method_parent_class
Browse files Browse the repository at this point in the history
Add payment method parent class
  • Loading branch information
kennyadsl authored Oct 9, 2018
2 parents f8c5941 + c8d890a commit cc5c37f
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/pkg/
/spec/reports/
/tmp/
/log/
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sudo: false
language: ruby
dist: trusty
cache:
bundler: true
before_install:
- "gem install bundler --pre"
- "bundler -v"
rvm:
- 2.4.2
env:
matrix:
- SOLIDUS_BRANCH=v1.0
- SOLIDUS_BRANCH=v1.1
- SOLIDUS_BRANCH=v1.2
- SOLIDUS_BRANCH=v1.3
- SOLIDUS_BRANCH=v1.4
- SOLIDUS_BRANCH=v2.0
- SOLIDUS_BRANCH=v2.1
- SOLIDUS_BRANCH=v2.2
- SOLIDUS_BRANCH=v2.3
- SOLIDUS_BRANCH=v2.4
- SOLIDUS_BRANCH=master
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
source 'https://rubygems.org'

branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
gem 'solidus', github: 'solidusio/solidus', branch: branch
gem 'solidus_core', github: 'solidusio/solidus', branch: branch

# Specify your gem's dependencies in solidus_support.gemspec
gemspec

gem 'sqlite3'
gem 'sprockets-rails'
12 changes: 12 additions & 0 deletions lib/solidus_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ def payment_source_parent_class
end
end

def payment_method_parent_class(credit_card: false)
if credit_card
if solidus_gem_version >= Gem::Version.new('2.3.x')
Spree::PaymentMethod::CreditCard
else
Spree::Gateway
end
else
Spree::PaymentMethod
end
end

def frontend_available?
defined?(Spree::Frontend::Engine)
end
Expand Down
2 changes: 2 additions & 0 deletions solidus_support.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Gem::Specification.new do |spec|
spec.files = `git ls-files -z`.split("\x0")
spec.require_paths = ["lib"]

spec.add_development_dependency "solidus_core"
spec.add_development_dependency "bundler", "~> 1.14"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec-rails", "~> 3.7"
end
29 changes: 29 additions & 0 deletions spec/solidus_support_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
RSpec.describe SolidusSupport do
describe '.payment_method_parent_class' do
subject { described_class.payment_method_parent_class(credit_card: credit_card) }

let(:credit_card) { nil }

it { is_expected.to eq(Spree::PaymentMethod) }

context 'with credit_card: true' do
let(:credit_card) { true }

before do
expect(described_class).to receive(:solidus_gem_version) do
Gem::Version.new(solidus_version)
end
end

context 'For Solidus < 2.3' do
let(:solidus_version) { '2.2.x' }
it { is_expected.to eq(Spree::Gateway) }
end

context 'For Solidus >= 2.3' do
let(:solidus_version) { '2.3.x' }
it { is_expected.to eq(Spree::PaymentMethod::CreditCard) }
end
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require_relative 'support/dummy_app'
require 'solidus_support/extension/spec_helper'
18 changes: 18 additions & 0 deletions spec/support/dummy_app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ENV['RAILS_ENV'] = 'test'
ENV['DISABLE_DATABASE_ENVIRONMENT_CHECK'] = '1'

Bundler.setup

require 'rails'
require 'solidus_core'

Bundler.require(:default, :test)

module DummyApp
class Application < ::Rails::Application
config.eager_load = false
config.paths["config/database"] = File.expand_path('../dummy_app/database.yml', __FILE__)
end
end

DummyApp::Application.initialize!
4 changes: 4 additions & 0 deletions spec/support/dummy_app/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test:
adapter: sqlite3
database: ':memory:'
timeout: 10000

0 comments on commit cc5c37f

Please sign in to comment.