Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payment method parent class #8

Merged
merged 3 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only useful when credit_card is true (otherwise it is Spree::PaymentMethod in all versions).

Maybe we should call this credit_card_payment_method_parent_class instead, and only deal with that case?

Either way 👍

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 @@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
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