Skip to content

Commit

Permalink
Rename bogus gateways into payment methods
Browse files Browse the repository at this point in the history
To remove confusion around payment methods, gateways and providers we rename the `Spree::Gateway::Bogus` and `Spree::Gateway::BogusSimple` payment methods into `Spree::PaymentMethod::BogusCreditCard` and `Spree::PaymentMethod::SimpleBogusCreditCard`.
  • Loading branch information
tvdeyen committed Jun 8, 2017
1 parent 567fa49 commit d1082af
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Solidus 2.3.0 (master, unreleased)

- Renamed bogus payment methods [\#2000](https://github.com/solidusio/solidus/pull/2000) ([tvdeyen](https://github.com/tvdeyen))
`Spree::Gateway::BogusSimple` and `Spree::Gateway::Bogus` were renamed into `Spree::PaymentMethod::SimpleBogusCreditCard` and `Spree::PaymentMethod::BogusCreditCard`
Run `rake solidus:migrations:rename_gateways:up` to migrate your data.

- Deprecate `Spree::Core::CurrentStore` in favor of `Spree::CurrentStoreSelector`. [\#1993](https://github.com/solidusio/solidus/pull/1993)
- Deprecate `Spree::Order#assign_default_addresses!` in favor of `Order.new.assign_default_user_addresses`. [\#1954](https://github.com/solidusio/solidus/pull/1954) ([kennyadsl](https://github.com/kennyadsl))
- Change how line item options are allowed in line items controller. [\#1943](https://github.com/solidusio/solidus/pull/1943)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ module Spree

it "can update payment method and transition from payment to confirm" do
order.update_column(:state, "payment")
allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
api_put :update, id: order.to_param, order_token: order.guest_token,
order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
expect(json_response['state']).to eq('confirm')
Expand Down
10 changes: 5 additions & 5 deletions api/spec/controllers/spree/api/payments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module Spree

context "payment source is not required" do
before do
allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
end

it "can create a new payment" do
Expand Down Expand Up @@ -160,7 +160,7 @@ module Spree
context "authorization fails" do
before do
fake_response = double(success?: false, to_s: "Could not authorize card")
expect_any_instance_of(Spree::Gateway::Bogus).to receive(:authorize).and_return(fake_response)
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:authorize).and_return(fake_response)
api_put :authorize, id: payment.to_param
end

Expand All @@ -187,7 +187,7 @@ module Spree
context "capturing fails" do
before do
fake_response = double(success?: false, to_s: "Insufficient funds")
expect_any_instance_of(Spree::Gateway::Bogus).to receive(:capture).and_return(fake_response)
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:capture).and_return(fake_response)
end

it "returns a 422 status" do
Expand All @@ -209,7 +209,7 @@ module Spree
context "purchasing fails" do
before do
fake_response = double(success?: false, to_s: "Insufficient funds")
expect_any_instance_of(Spree::Gateway::Bogus).to receive(:purchase).and_return(fake_response)
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:purchase).and_return(fake_response)
end

it "returns a 422 status" do
Expand All @@ -231,7 +231,7 @@ module Spree
context "voiding fails" do
before do
fake_response = double(success?: false, to_s: "NO REFUNDS")
expect_any_instance_of(Spree::Gateway::Bogus).to receive(:void).and_return(fake_response)
expect_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:void).and_return(fake_response)
end

it "returns a 422 status" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class GatewayWithPassword < PaymentMethod

context "tries to save invalid payment" do
it "doesn't break, responds nicely" do
post :create, params: { payment_method: { name: "", type: "Spree::Gateway::Bogus" } }
post :create, params: { payment_method: { name: "", type: "Spree::PaymentMethod::BogusCreditCard" } }
end
end

it "can create a payment method of a valid type" do
expect {
post :create, params: { payment_method: { name: "Test Method", type: "Spree::Gateway::Bogus" } }
post :create, params: { payment_method: { name: "Test Method", type: "Spree::PaymentMethod::BogusCreditCard" } }
}.to change(Spree::PaymentMethod, :count).by(1)

expect(response).to be_redirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
context "changing type and payment_source", js: true do
after do
# cleanup
Spree::Config.static_model_preferences.for_class(Spree::Gateway::Bogus).clear
Spree::Config.static_model_preferences.for_class(Spree::PaymentMethod::BogusCreditCard).clear
end

it "displays message when changing type" do
Expand All @@ -81,13 +81,13 @@
expect(page).to have_no_content('Test Mode')

# change back
select2_search 'Spree::Gateway::Bogus', from: 'Provider'
select2_search 'Spree::PaymentMethod::BogusCreditCard', from: 'Provider'
expect(page).to have_no_content('you must save first')
expect(page).to have_content('Test Mode')
end

it "displays message when changing preference source" do
Spree::Config.static_model_preferences.add(Spree::Gateway::Bogus, 'my_prefs', {})
Spree::Config.static_model_preferences.add(Spree::PaymentMethod::BogusCreditCard, 'my_prefs', {})

create(:credit_card_payment_method)
click_link "Payment Methods"
Expand All @@ -105,7 +105,7 @@
end

it "updates successfully and keeps secrets" do
Spree::Config.static_model_preferences.add(Spree::Gateway::Bogus, 'my_prefs', { server: 'secret' })
Spree::Config.static_model_preferences.add(Spree::PaymentMethod::BogusCreditCard, 'my_prefs', { server: 'secret' })

create(:credit_card_payment_method)
click_link "Payment Methods"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Spree
class Gateway::Bogus < Gateway
class PaymentMethod::BogusCreditCard < Gateway
TEST_VISA = ['4111111111111111', '4012888888881881', '4222222222222']
TEST_MC = ['5500000000000004', '5555555555554444', '5105105105105100']
TEST_AMEX = ['378282246310005', '371449635398431', '378734493671000', '340000000000009']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Spree
# Bogus Gateway that doesn't support payment profiles.
class Gateway::BogusSimple < Gateway::Bogus
class PaymentMethod::SimpleBogusCreditCard < PaymentMethod::BogusCreditCard
def payment_profiles_supported?
false
end
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Engine < ::Rails::Engine

initializer "spree.register.payment_methods", before: :load_config_initializers do |app|
app.config.spree.payment_methods = %w[
Spree::Gateway::Bogus
Spree::Gateway::BogusSimple
Spree::PaymentMethod::BogusCreditCard
Spree::PaymentMethod::SimpleBogusCreditCard
Spree::PaymentMethod::StoreCredit
Spree::PaymentMethod::Check
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryGirl.define do
factory :payment_method, aliases: [:credit_card_payment_method], class: Spree::Gateway::Bogus do
factory :payment_method, aliases: [:credit_card_payment_method], class: Spree::PaymentMethod::BogusCreditCard do
name 'Credit Card'
available_to_admin true
available_to_users true
Expand All @@ -13,7 +13,7 @@

# authorize.net was moved to spree_gateway.
# Leaving this factory in place with bogus in case anyone is using it.
factory :simple_credit_card_payment_method, class: Spree::Gateway::BogusSimple do
factory :simple_credit_card_payment_method, class: Spree::PaymentMethod::SimpleBogusCreditCard do
name 'Credit Card'
available_to_admin true
available_to_users true
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def provider_class
end

context 'using preference_source' do
let(:klass){ Spree::Gateway::Bogus }
let(:klass){ Spree::PaymentMethod::BogusCreditCard }
before do
Spree::Config.static_model_preferences.add(klass, 'test_preference_source', server: 'bar')
end
Expand Down
14 changes: 7 additions & 7 deletions core/spec/models/spree/order_capturing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
context "payment method ordering" do
let(:secondary_payment_method) { SecondaryBogusPaymentMethod }

class SecondaryBogusPaymentMethod < Spree::Gateway::Bogus; end
class SecondaryBogusPaymentMethod < Spree::PaymentMethod::BogusCreditCard; end

context "SecondaryBogusPaymentMethod payments are prioritized" do
let(:payment_methods) { [SecondaryBogusPaymentMethod, Spree::Gateway::Bogus] }
let(:payment_methods) { [SecondaryBogusPaymentMethod, Spree::PaymentMethod::BogusCreditCard] }

it "captures SecondaryBogusPaymentMethod payments first" do
@bogus_payment.update!(amount: bogus_total + 100)
Expand All @@ -72,7 +72,7 @@ class SecondaryBogusPaymentMethod < Spree::Gateway::Bogus; end
end

context "Bogus payments are prioritized" do
let(:payment_methods) { [Spree::Gateway::Bogus, SecondaryBogusPaymentMethod] }
let(:payment_methods) { [Spree::PaymentMethod::BogusCreditCard, SecondaryBogusPaymentMethod] }

it "captures Bogus payments first" do
@secondary_bogus_payment.update!(amount: secondary_total + 100)
Expand All @@ -89,7 +89,7 @@ class SecondaryBogusPaymentMethod < Spree::Gateway::Bogus; end

before do
allow(Spree::OrderCapturing).to receive(:sorted_payment_method_classes).and_return(
[SecondaryBogusPaymentMethod, Spree::Gateway::Bogus]
[SecondaryBogusPaymentMethod, Spree::PaymentMethod::BogusCreditCard]
)
end

Expand All @@ -103,7 +103,7 @@ class SecondaryBogusPaymentMethod < Spree::Gateway::Bogus; end

context "when a payment is not needed to capture the entire order" do
let(:secondary_payment_method) { SecondaryBogusPaymentMethod }
let(:payment_methods) { [Spree::Gateway::Bogus, SecondaryBogusPaymentMethod] }
let(:payment_methods) { [Spree::PaymentMethod::BogusCreditCard, SecondaryBogusPaymentMethod] }

before do
@bogus_payment.update!(amount: order.total)
Expand Down Expand Up @@ -132,9 +132,9 @@ class SecondaryBogusPaymentMethod < Spree::Gateway::Bogus; end
let(:secondary_payment_method) { ExceptionallyBogusPaymentMethod }
let(:bogus_total) { order.total - 1 }
let(:secondary_total) { 1 }
let(:payment_methods) { [Spree::Gateway::Bogus, ExceptionallyBogusPaymentMethod] }
let(:payment_methods) { [Spree::PaymentMethod::BogusCreditCard, ExceptionallyBogusPaymentMethod] }

class ExceptionallyBogusPaymentMethod < Spree::Gateway::Bogus
class ExceptionallyBogusPaymentMethod < Spree::PaymentMethod::BogusCreditCard
def capture(*_args)
raise ActiveMerchant::ConnectionError.new("foo", nil)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

module Spree
describe Gateway::Bogus, type: :model do
describe PaymentMethod::BogusCreditCard, type: :model do
let(:bogus) { create(:credit_card_payment_method) }
let!(:cc) { create(:credit_card, payment_method: bogus, gateway_customer_profile_id: "BGS-RERTERT") }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Spree::Gateway::BogusSimple, type: :model do
subject { Spree::Gateway::BogusSimple.new }
describe Spree::PaymentMethod::SimpleBogusCreditCard, type: :model do
subject { Spree::PaymentMethod::SimpleBogusCreditCard.new }

# regression test for https://github.com/spree/spree/issues/3824
describe "#capture" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:refund_reason) { create(:refund_reason) }

let(:gateway) do
gateway = Spree::Gateway::Bogus.new(active: true, name: 'Bogus gateway')
gateway = Spree::PaymentMethod::BogusCreditCard.new(active: true, name: 'Bogus gateway')
allow(gateway).to receive_messages source_required: true
gateway
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module Spree
context "multiple payment methods" do
let(:simulate) { true }
let!(:check_payment) { create(:check_payment, order: reimbursement.order, amount: 5.0, state: "completed") }
let(:payment) { reimbursement.order.payments.detect { |p| p.payment_method.is_a? Spree::Gateway::Bogus } }
let(:payment) { reimbursement.order.payments.detect { |p| p.payment_method.is_a? Spree::PaymentMethod::BogusCreditCard } }
let(:refund_amount) { 10.0 }

let(:refund_payment_methods) { subject.map { |refund| refund.payment.payment_method } }
Expand Down
2 changes: 1 addition & 1 deletion sample/db/samples/payment_methods.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Spree::Gateway::Bogus.create!(
Spree::PaymentMethod::BogusCreditCard.create!(
{
name: "Credit Card",
description: "Bogus payment gateway",
Expand Down

0 comments on commit d1082af

Please sign in to comment.