Skip to content

Commit

Permalink
Merge pull request #44 from ikraamg/bump-required-ruby-version
Browse files Browse the repository at this point in the history
Bump required ruby version and align controller behaviour
  • Loading branch information
ikraamg authored Jul 5, 2024
2 parents 1b9567b + ab58f36 commit b8989ad
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 74 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ RSpec/MultipleMemoizedHelpers:

RSpec/NestedGroups:
Enabled: false

Rspec/RemoveConst:
Enabled: false

RSpec/DescribeClass:
Enabled: false

Gemspec/DevelopmentDependencies:
Enabled: false
9 changes: 6 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

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

# Needed to help Bundler figure out how to resolve dependencies,
Expand All @@ -14,13 +14,16 @@ gem 'rails', '>0.a'
# Provides basic authentication functionality for testing parts of your engine
gem 'solidus_auth_devise'

case ENV['DB']
# The inclusion of this gem has been removed from the dev support gem in recent versions.
gem 'solidus_frontend'

case ENV.fetch('DB', nil)
when 'mysql'
gem 'mysql2'
when 'postgresql'
gem 'pg'
else
gem 'sqlite3'
gem 'sqlite3', '~> 1.4'
end

gemspec
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Solidus Afterpay

<!-- Explain what your extension does. -->
> [!IMPORTANT]
> This gem still depends on the legacy [solidus_frontend](https://github.com/solidusio/solidus_frontend) gem being available in the Solidus application.
## Installation

Expand Down Expand Up @@ -43,6 +45,7 @@ Spree::Config.configure do |config|
'afterpay_credentials', {
merchant_id: ENV['AFTERPAY_MERCHANT_ID'],
secret_key: ENV['AFTERPAY_SECRET_KEY'],
test_mode: ENV.fetch('AFTERPAY_ENVIRONMENT', '') != 'production'
}
)
end
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/solidus_afterpay/callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def order
end

def payment_method
@payment_method ||= SolidusAfterpay::PaymentMethod.active.find(params[:payment_method_id])
@payment_method ||= if params[:payment_method_id]
SolidusAfterpay::PaymentMethod.active.find(params[:payment_method_id])
else
SolidusAfterpay::PaymentMethod.active.first
end
end

def afterpay_order_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def order
end

def payment_method
@payment_method ||= SolidusAfterpay::PaymentMethod.active.find(params[:payment_method_id])
@payment_method ||= if params[:payment_method_id]
SolidusAfterpay::PaymentMethod.active.find(params[:payment_method_id])
else
SolidusAfterpay::PaymentMethod.active.first
end
end
end
end
2 changes: 1 addition & 1 deletion app/models/solidus_afterpay/order_component_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def estimated_shipment_date_variant(line_item)

def estimated_shipment_date(line_item)
@estimated_shipment_date ||=
(estimated_shipment_date_variant(line_item) || estimated_shipment_date_product(line_item))
estimated_shipment_date_variant(line_item) || estimated_shipment_date_product(line_item)
end

def pre_order?(line_item)
Expand Down
2 changes: 1 addition & 1 deletion bin/sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [ ! -z $SOLIDUS_BRANCH ]
then
BRANCH=$SOLIDUS_BRANCH
else
BRANCH="master"
BRANCH="main"
fi

extension_name="solidus_afterpay"
Expand Down
11 changes: 9 additions & 2 deletions lib/solidus_afterpay/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ def api_base_controller_parent_class
SolidusAfterpay::BaseController
end

delegate :shipping_rate_builder_service_class, to: :configuration
delegate :update_order_attributes_service_class, to: :configuration
# rubocop:disable Rails/Delegate
def shipping_rate_builder_service_class
configuration.shipping_rate_builder_service_class
end

def update_order_attributes_service_class
configuration.update_order_attributes_service_class
end
# rubocop:enable Rails/Delegate
end
end
2 changes: 1 addition & 1 deletion lib/solidus_afterpay/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Engine < Rails::Engine
initializer "spree.payment_methods.register_afterpay_payment_method",
after: "spree.register.payment_methods" do |app|
app.config.spree.payment_methods << "SolidusAfterpay::PaymentMethod"
Spree::PermittedAttributes.source_attributes.concat [:token]
Spree::PermittedAttributes.source_attributes.push :token
end
end
end
2 changes: 1 addition & 1 deletion lib/solidus_afterpay/testing_support/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
factory :order_with_variant_property, class: "Spree::Order", parent: :order_with_line_items do
after(:build) do |order|
variant_property_rule_value = create(:variant_property_rule_value, value: "2021-09-19",
property: create(:property, name: "estimatedShipmentDate"))
property: create(:property, name: "estimatedShipmentDate"))
order.line_items.first.variant.product.variant_property_rules << variant_property_rule_value.variant_property_rule
order.line_items.first.variant.option_values << variant_property_rule_value.variant_property_rule
.option_values.first
Expand Down
2 changes: 1 addition & 1 deletion lib/solidus_afterpay/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SolidusAfterpay
VERSION = '0.2.0'
VERSION = '0.3.0'
end
8 changes: 4 additions & 4 deletions solidus_afterpay.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ Gem::Specification.new do |spec|
spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_afterpay'
spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_afterpay/blob/master/CHANGELOG.md'

spec.required_ruby_version = Gem::Requirement.new('~> 2.5')
spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }

spec.files = files.grep_v(%r{^(test|spec|features)/})
spec.test_files = files.grep(%r{^(test|spec|features)/})
spec.bindir = "exe"
spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency 'afterpay', '~> 0.5.0'
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 4']
spec.add_dependency 'afterpay', '~> 0.6.0'
spec.add_dependency 'solidus_core', ['>= 2.0.0']
spec.add_dependency 'solidus_support', '~> 0.5'

spec.add_development_dependency 'solidus_dev_support', '~> 2.5'
spec.add_development_dependency 'vcr', '~> 6.0'
spec.add_development_dependency 'webmock', '~> 3.14'
spec.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion spec/helpers/solidus_afterpay/afterpay_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe SolidusAfterpay::AfterpayHelper, type: :helper do
RSpec.describe SolidusAfterpay::AfterpayHelper do
describe '#include_afterpay_js' do
subject { helper.include_afterpay_js(test_mode: test_mode) }

Expand Down
18 changes: 9 additions & 9 deletions spec/models/solidus_afterpay/gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@

context 'with a timeout error' do
before do
allow(::Afterpay::API::Payment::Auth).to receive(:call).and_raise(
::Afterpay::RequestTimeoutError.new('request_timeout'), 'Request Timeout'
allow(Afterpay::API::Payment::Auth).to receive(:call).and_raise(
Afterpay::RequestTimeoutError.new('request_timeout'), 'Request Timeout'
)
allow(::Afterpay::API::Payment::Reversal).to receive(:call)
allow(Afterpay::API::Payment::Reversal).to receive(:call)
end

it 'returns an unsuccesfull response' do
Expand All @@ -94,7 +94,7 @@

it 'calls the ::Afterpay::API::Payment::Reversal with order token' do
response
expect(::Afterpay::API::Payment::Reversal).to have_received(:call).with(token: order_token)
expect(Afterpay::API::Payment::Reversal).to have_received(:call).with(token: order_token)
end
end
end
Expand Down Expand Up @@ -182,10 +182,10 @@

context 'with a timeout error' do
before do
allow(::Afterpay::API::Payment::DeferredCapture).to receive(:call).and_raise(
::Afterpay::RequestTimeoutError.new('request_timeout'), 'Request Timeout'
allow(Afterpay::API::Payment::DeferredCapture).to receive(:call).and_raise(
Afterpay::RequestTimeoutError.new('request_timeout'), 'Request Timeout'
)
allow(::Afterpay::API::Payment::Reversal).to receive(:call)
allow(Afterpay::API::Payment::Reversal).to receive(:call)
end

it 'returns an unsuccesfull response' do
Expand All @@ -202,7 +202,7 @@

it 'calls the ::Afterpay::API::Payment::Reversal with order token' do
response
expect(::Afterpay::API::Payment::Reversal).to have_received(:call).with(token: order_token)
expect(Afterpay::API::Payment::Reversal).to have_received(:call).with(token: order_token)
end
end
end
Expand Down Expand Up @@ -481,7 +481,7 @@

context 'with invalid response' do
before do
allow(::Afterpay::API::Configuration::Retrieve).to receive(:call).and_raise(::Afterpay::BaseError.new(nil))
allow(Afterpay::API::Configuration::Retrieve).to receive(:call).and_raise(Afterpay::BaseError.new(nil))
end

it 'retrieves the afterpay configuration' do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/solidus_afterpay/payment_method_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe SolidusAfterpay::PaymentMethod, type: :model do
RSpec.describe SolidusAfterpay::PaymentMethod do
let(:payment_method) { described_class.new }

describe "#gateway_class" do
Expand Down Expand Up @@ -84,7 +84,7 @@
let(:payment_method) { create(:afterpay_payment_method, preferred_excluded_products: excluded_product_ids) }
let(:order) {
build(:order_with_line_items, currency: order_currency,
line_items_attributes: line_items_attributes)
line_items_attributes: line_items_attributes)
}
let(:line_items_attributes) do
[{ product: product }]
Expand Down
2 changes: 1 addition & 1 deletion spec/models/solidus_afterpay/payment_source_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

RSpec.describe SolidusAfterpay::PaymentSource, type: :model do
RSpec.describe SolidusAfterpay::PaymentSource do
let(:payment_source) { described_class.new }

describe '#actions' do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/solidus_afterpay/user_agent_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

before do
stub_const('SolidusAfterpay::VERSION', '0.1.0')
allow(::Spree).to receive(:solidus_gem_version).and_return('3.0.1')
allow(Spree).to receive(:solidus_gem_version).and_return('3.0.1')
stub_const('RUBY_VERSION', '2.6.6')
allow(::Spree::Store).to receive(:default).and_return(default_store)
allow(Spree::Store).to receive(:default).and_return(default_store)
end

it 'includes the production javascript' do
Expand Down
23 changes: 9 additions & 14 deletions spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

RSpec.describe Spree::Order, type: :model do
RSpec.describe Spree::Order do
let(:store) { create(:store) }
let(:user) { create(:user, email: "solidus@example.com") }
let(:order) { create(:order, user: user, store: store) }
Expand Down Expand Up @@ -55,12 +55,12 @@
subject { order.available_payment_methods }

let!(:first_method) {
FactoryBot.create(:payment_method, available_to_users: true,
available_to_admin: true)
create(:payment_method, available_to_users: true,
available_to_admin: true)
}
let!(:second_method) {
FactoryBot.create(:payment_method, available_to_users: true,
available_to_admin: true)
create(:payment_method, available_to_users: true,
available_to_admin: true)
}

before do
Expand Down Expand Up @@ -120,9 +120,7 @@
before { order.update!(store: store_with_payment_methods) }

it 'returns only the matching payment methods for that store' do
expect(order.available_payment_methods).to match_array(
[payment_method_with_store]
)
expect(order.available_payment_methods).to contain_exactly(payment_method_with_store)
end

context 'when the store has an extra payment method unavailable to users' do
Expand All @@ -137,9 +135,7 @@
end

it 'returns only the payment methods available to users for that store' do
expect(order.available_payment_methods).to match_array(
[payment_method_with_store]
)
expect(order.available_payment_methods).to contain_exactly(payment_method_with_store)
end
end
end
Expand All @@ -148,9 +144,8 @@
before { order.update!(store: store_without_payment_methods) }

it 'returns all matching payment methods regardless of store' do
expect(order.available_payment_methods).to match_array(
[payment_method_with_store, payment_method_without_store]
)
expect(order.available_payment_methods).to contain_exactly(payment_method_with_store,
payment_method_without_store)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:order) { create(:order_with_line_items ) }
let(:shipment) { create(:shipment, order: order) }
let(:shipping_rate) { create(:shipping_rate, cost: 5, shipment: shipment) }
let(:shipping_rate_tax) { ::Spree::ShippingRateTax.create(amount: 0.75, shipping_rate: shipping_rate) }
let(:shipping_rate_tax) { Spree::ShippingRateTax.create(amount: 0.75, shipping_rate: shipping_rate) }

before { shipping_rate.taxes << shipping_rate_tax }

Expand Down
6 changes: 3 additions & 3 deletions spec/requests/solidus_afterpay/callbacks_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'spec_helper'

describe SolidusAfterpay::CallbacksController, type: :request do
describe SolidusAfterpay::CallbacksController do
describe 'GET cancel' do
subject(:request) { get '/solidus_afterpay/callbacks/cancel', params: params }

Expand All @@ -29,7 +29,7 @@

let(:params) { { orderToken: order_token, order_number: order_number, payment_method_id: payment_method_id } }

context 'when the user is logged in', with_signed_in_user: true do
context 'when the user is logged in', :with_signed_in_user do
context 'with valid data' do
it 'redirects to the order next checkout state page' do
request
Expand Down Expand Up @@ -110,7 +110,7 @@
end
end

context 'when the user is a guest user', with_guest_session: true do
context 'when the user is a guest user', :with_guest_session do
it 'redirects to the order next checkout state page' do
request
expect(response).to redirect_to('/checkout/confirm')
Expand Down
Loading

0 comments on commit b8989ad

Please sign in to comment.