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

Commit

Permalink
Merge pull request #321 from gsmendoza/gsmendoza/eng-355-fix-autoload…
Browse files Browse the repository at this point in the history
…ing-issues-with

Make gem compatible with Rails 7
  • Loading branch information
kennyadsl authored Jun 16, 2022
2 parents 42e3a0a + f96066d commit 806d20b
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 43 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
version: 2.1

orbs:
browser-tools: circleci/[email protected]

# Always take the latest version of the orb, this allows us to
# run specs against Solidus supported versions only without the need
# to change this configuration every time a Solidus version is released
Expand All @@ -11,10 +13,12 @@ jobs:
run-specs-with-postgres:
executor: solidusio_extensions/postgres
steps:
- browser-tools/install-browser-tools
- solidusio_extensions/run-tests
run-specs-with-mysql:
executor: solidusio_extensions/mysql
steps:
- browser-tools/install-browser-tools
- solidusio_extensions/run-tests
lint-code:
executor: solidusio_extensions/sqlite-memory
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.project
.sass-cache
coverage
Gemfile-local
Gemfile.lock
tmp
nbproject
Expand Down
7 changes: 2 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
gem 'solidus', github: 'solidusio/solidus', branch: branch

# 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'
gem 'rails', ENV.fetch('RAILS_VERSION', nil)

# Provides basic authentication functionality for testing parts of your engine
gem 'solidus_auth_devise'
Expand All @@ -20,7 +17,7 @@ gem 'sassc-rails', platforms: :mri

gem 'bourbon'

case ENV['DB']
case ENV.fetch('DB', nil)
when 'mysql'
gem 'mysql2'
when 'postgresql'
Expand Down
4 changes: 2 additions & 2 deletions app/models/solidus_paypal_braintree/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Transaction
errors.add(:payment_method, 'Must be braintree')
end
if address && !address.valid?
address.errors.each do |field, error|
errors.add(:address, "#{field} #{error}")
address.errors.each do |error|
errors.add(:address, error.full_message)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/solidus_paypal_braintree/transaction_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class InvalidImportError < StandardError; end
errors.add("Address", "is invalid") if address && !address.valid?

if !transaction.valid?
transaction.errors.each do |field, error|
errors.add(field, error)
transaction.errors.each do |error|
errors.add(error.attribute, error.message)
end
end
errors.none?
Expand Down
8 changes: 5 additions & 3 deletions lib/solidus_paypal_braintree/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class Engine < Rails::Engine
end

initializer "register_solidus_paypal_braintree_gateway", after: "spree.register.payment_methods" do |app|
app.config.spree.payment_methods << SolidusPaypalBraintree::Gateway
SolidusPaypalBraintree::Gateway.allowed_admin_form_preference_types << :preference_select
Spree::PermittedAttributes.source_attributes.concat [:nonce, :payment_type, :paypal_funding_source]
config.to_prepare do
app.config.spree.payment_methods << SolidusPaypalBraintree::Gateway
SolidusPaypalBraintree::Gateway.allowed_admin_form_preference_types.push(:preference_select).uniq!
::Spree::PermittedAttributes.source_attributes.concat([:nonce, :payment_type, :paypal_funding_source]).uniq!
end
end

if SolidusSupport.frontend_available?
Expand Down
1 change: 0 additions & 1 deletion solidus_paypal_braintree.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Gem::Specification.new do |s|
s.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
s.test_files = Dir['spec/**/*']
s.bindir = "exe"
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.require_paths = ["lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

it 'creates a payment source' do
expect { patch_update }.
to change { SolidusPaypalBraintree::Source.count }.
to change(SolidusPaypalBraintree::Source, :count).
from(0).
to(1)
end
Expand Down Expand Up @@ -88,11 +88,11 @@
end

it "does not change the number of payments in the system" do
expect{ patch_update }.not_to(change{ ::Spree::Payment.count })
expect{ patch_update }.not_to(change(::Spree::Payment, :count))
end

it "does not change the number of sources in the system" do
expect{ patch_update }.not_to(change{ SolidusPaypalBraintree::Source.count })
expect{ patch_update }.not_to(change(SolidusPaypalBraintree::Source, :count))
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
SolidusPaypalBraintree::TransactionsController::InvalidImportError,
"Import invalid: " \
"Address is invalid, " \
"Address city can't be blank"
"Address City can't be blank"
)
end
end
Expand Down Expand Up @@ -100,7 +100,7 @@
# Creating the order also creates 3 addresses, we want to make sure
# the transaction import only creates 1 new one
order
expect { post_create }.to change { Spree::Address.count }.by(1)
expect { post_create }.to change(Spree::Address, :count).by(1)
expect(Spree::Address.last.address1).to eq "123 Fake Street"
end
end
Expand All @@ -113,7 +113,7 @@

it "creates a new address, looking up the ISO by country name" do
order
expect { post_create }.to change { Spree::Address.count }.by(1)
expect { post_create }.to change(Spree::Address, :count).by(1)
expect(Spree::Address.last.country.iso).to eq "US"
end
end
Expand All @@ -123,7 +123,7 @@

it "does not create a new address" do
order
expect { post_create }.not_to(change { Spree::Address.count })
expect { post_create }.not_to(change(Spree::Address, :count))
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/features/frontend/venmo_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
end
end

context 'with Venmo transactions', vcr: { cassette_name: 'checkout/valid_venmo_transaction' } do
# TODO: Reenable these specs once Venmo is enabled on the Braintree sandbox.
xcontext 'with Venmo transactions', vcr: { cassette_name: 'checkout/valid_venmo_transaction' } do
before do
fake_venmo_successful_tokenization
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/solidus_paypal_braintree/avs_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

context 'with avs_error_response_code' do
let(:transaction) do
instance_double('Braintree::Transaction',
instance_double(Braintree::Transaction,
avs_error_response_code: error_code,
avs_street_address_response_code: nil,
avs_postal_code_response_code: nil)
Expand All @@ -27,7 +27,7 @@

context 'without avs_error_response_code' do
let(:transaction) do
instance_double('Braintree::Transaction',
instance_double(Braintree::Transaction,
avs_error_response_code: nil,
avs_street_address_response_code: codes.first,
avs_postal_code_response_code: codes.last)
Expand Down
12 changes: 6 additions & 6 deletions spec/models/solidus_paypal_braintree/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,22 +420,22 @@
end

describe '#try_void' do
subject { gateway.try_void(instance_double('Spree::Payment', response_code: source.token)) }
subject { gateway.try_void(instance_double(Spree::Payment, response_code: source.token)) }

let(:transaction_request) do
class_double('Braintree::Transaction',
class_double(Braintree::Transaction,
find: transaction_response)
end

before do
client = instance_double('Braintree::Gateway')
client = instance_double(Braintree::Gateway)
allow(client).to receive(:transaction) { transaction_request }
allow(gateway).to receive(:braintree) { client }
end

context 'with voidable payment' do
let(:transaction_response) do
instance_double('Braintree::Transaction',
instance_double(Braintree::Transaction,
status: Braintree::Transaction::Status::Authorized)
end

Expand Down Expand Up @@ -473,7 +473,7 @@

context 'with voidable paypal payment' do
let(:transaction_response) do
instance_double('Braintree::Transaction',
instance_double(Braintree::Transaction,
status: Braintree::Transaction::Status::SettlementPending)
end

Expand All @@ -485,7 +485,7 @@

context 'with non-voidable payment' do
let(:transaction_response) do
instance_double('Braintree::Transaction',
instance_double(Braintree::Transaction,
status: Braintree::Transaction::Status::Settled)
end

Expand Down
22 changes: 11 additions & 11 deletions spec/models/solidus_paypal_braintree/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
let(:failed_transaction) { nil }
let(:error) do
instance_double(
'Braintree::ValidationError',
Braintree::ValidationError,
code: '12345',
message: "Cannot refund a transaction unless it is settled."
)
end

let(:error_result) do
instance_double(
'Braintree::ErrorResult',
Braintree::ErrorResult,
success?: false,
errors: [error],
transaction: failed_transaction,
Expand All @@ -26,7 +26,7 @@

let(:successful_result) do
transaction = instance_double(
'Braintree::Transaction',
Braintree::Transaction,
status: 'ok',
id: 'abcdef',
avs_error_response_code: nil,
Expand All @@ -36,7 +36,7 @@
)

instance_double(
'Braintree::SuccessfulResult',
Braintree::SuccessfulResult,
success?: true,
transaction: transaction
)
Expand Down Expand Up @@ -80,7 +80,7 @@
let(:error) { nil }
let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
status: "settlement_declined",
processor_settlement_response_code: "4001",
Expand All @@ -99,7 +99,7 @@
let(:error) { nil }
let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
status: "gateway_rejected",
gateway_rejection_reason: "cvv",
Expand All @@ -117,7 +117,7 @@
let(:error) { nil }
let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
status: "processor_declined",
processor_response_code: '2001',
Expand All @@ -136,7 +136,7 @@
let(:error) { nil }
let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
status: "authorization_expired",
avs_error_response_code: nil,
Expand All @@ -153,7 +153,7 @@
let(:error) { nil }
let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
status: "something_bad_happened",
avs_error_response_code: nil,
Expand Down Expand Up @@ -186,7 +186,7 @@

let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
avs_error_response_code: 'E',
avs_street_address_response_code: nil,
Expand Down Expand Up @@ -232,7 +232,7 @@

let(:failed_transaction) do
instance_double(
'Braintree::Transaction',
Braintree::Transaction,
id: 'abcdef',
avs_error_response_code: nil,
avs_street_address_response_code: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
it "sets useful error messages" do
transaction_import.valid?
expect(transaction_import.errors.full_messages).
to eq ["Address is invalid", "Address zip can't be blank"]
to eq ["Address is invalid", "Address Zip can't be blank"]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/solidus_paypal_braintree/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
it "sets useful error messages" do
transaction.valid?
expect(transaction.errors.full_messages).
to eq ["Address zip can't be blank"]
to eq ["Address Zip can't be blank"]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
end
end

Capybara.javascript_driver = (ENV['CAPYBARA_DRIVER'] || :selenium_chrome).to_sym
Capybara.javascript_driver = ENV.fetch('CAPYBARA_DRIVER', :selenium_chrome).to_sym

0 comments on commit 806d20b

Please sign in to comment.