Skip to content
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
25 changes: 25 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint

on: [pull_request]

concurrency:
group: lint-${{ github.ref_name }}
cancel-in-progress: ${{ github.ref_name != 'main' }}

permissions:
contents: read

jobs:
ruby:
name: Check Ruby
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true
- name: Lint Ruby files
run: bundle exec rubocop -ESP
78 changes: 29 additions & 49 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,86 +1,66 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-09-24 12:23:52 UTC using RuboCop version 0.91.1.
# on 2025-02-13 10:58:32 UTC using RuboCop version 1.71.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
Lint/MissingSuper:
Exclude:
- 'app/services/solidus_subscriptions/user_mismatch_error.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
# Offense count: 3
# Configuration parameters: EnforcedStyle.
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
Exclude:
- 'lib/solidus_subscriptions/processor.rb'
- 'spec/controllers/concerns/create_subscription_spec.rb'

# Offense count: 2
# Offense count: 9
RSpec/MultipleExpectations:
Max: 2
Max: 7

# Offense count: 90
# Configuration parameters: IgnoreSharedExamples.
# Offense count: 24
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Enabled: false
Exclude:
- 'spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb'
- 'spec/models/solidus_subscriptions/subscription_spec.rb'

# Offense count: 11
# Offense count: 24
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4

# Offense count: 4
# Offense count: 3
RSpec/SubjectStub:
Exclude:
- 'spec/controllers/concerns/create_subscription_spec.rb'

# Offense count: 5
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Exclude:
- 'app/models/solidus_subscriptions/installment.rb'
- 'app/models/solidus_subscriptions/subscription.rb'

# Offense count: 2
# Configuration parameters: Include.
# Include: db/migrate/*.rb
Rails/ReversibleMigration:
Exclude:
- 'db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb'
- 'db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb'

# Offense count: 5
# Configuration parameters: ForbiddenMethods, AllowedMethods.
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
Rails/SkipsModelValidations:
Exclude:
- 'app/services/solidus_subscriptions/failure_dispatcher.rb'
- 'app/services/solidus_subscriptions/order_builder.rb'
- 'app/services/solidus_subscriptions/payment_failed_dispatcher.rb'

# Offense count: 1
# Cop supports --auto-correct.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'app/controllers/spree/admin/subscriptions_controller.rb'

# Offense count: 4
# Configuration parameters: MinBodyLength.
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
Style/GuardClause:
Exclude:
- 'app/models/solidus_subscriptions/subscription.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Exclude:
- 'app/services/solidus_subscriptions/checkout.rb'

# Offense count: 11
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Offense count: 25
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 290
Max: 145
8 changes: 4 additions & 4 deletions app/models/solidus_subscriptions/installment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Installment < ApplicationRecord
unfulfilled.where("#{table_name}.actionable_date <= ?", Time.zone.today)
end)

def self.ransackable_attributes(_auth_object = nil)
%w[actionable_date created_at updated_at]
end

# Mark this installment as out of stock.
#
# @return [SolidusSubscriptions::InstallmentDetail] The record of the failed
Expand Down Expand Up @@ -131,9 +135,5 @@ def next_actionable_date

(DateTime.current + SolidusSubscriptions.configuration.reprocessing_interval).beginning_of_minute
end

def self.ransackable_attributes(_auth_object = nil)
%w[actionable_date created_at updated_at]
end
end
end
16 changes: 8 additions & 8 deletions app/models/solidus_subscriptions/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def self.ransackable_scopes(_auth_object = nil)
[:in_processing_state, :with_subscribable]
end

def self.ransackable_attributes(_auth_object = nil)
%w[actionable_date created_at end_date state updated_at user_id]
end

def self.ransackable_associations(_auth_object = nil)
%w[events user]
end

def self.processing_states
PROCESSING_STATES
end
Expand Down Expand Up @@ -432,13 +440,5 @@ def emit_events_for_update
emit_event(type: 'subscription_payment_method_changed')
end
end

def self.ransackable_attributes(_auth_object = nil)
%w[actionable_date created_at end_date state updated_at user_id]
end

def self.ransackable_associations(_auth_object = nil)
%w[events user]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.prepended(base)
private

def handle_subscription_line_items
line_item = @current_order.line_items.find_by(variant_id: params[:variant_id])
line_item = current_order.line_items.find_by(variant_id: params[:variant_id])
create_subscription_line_item(line_item)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module CreateSubscription
private

def handle_subscription_line_items
line_item = @current_order.line_items.find_by(variant_id: params[:variant_id])
line_item = current_order.line_items.find_by(variant_id: params[:variant_id])
create_subscription_line_item(line_item)
end

Expand Down
30 changes: 15 additions & 15 deletions spec/controllers/concerns/create_subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
subject(:controller_instance) do
Class.new(ApplicationController) do
include CreateSubscription
attr_accessor :params, :current_order

def initialize(params = {})
@params = params
@current_order = nil
end
end.new
end

let(:variant) { create(:variant) }
let(:order) { create(:order) }

before do
controller_instance.current_order = order
allow(controller_instance).to receive(:current_order).and_return(order)
end

describe '#subscription_line_item_params_present?' do
Expand Down Expand Up @@ -50,15 +44,19 @@ def initialize(params = {})
end

describe '#handle_subscription_line_items' do
context 'when subscription params are missing' do
it 'does not invoke handle_subscription_line_items and does not create a subscription line item' do
order.line_items.count
before do
allow(controller_instance).to receive(:params).and_return(params)
end

controller_instance.params = {
context 'when subscription params are missing' do
let(:params) do
{
variant_id: variant.id,
subscription_line_item: {}
}
end

it 'does not invoke handle_subscription_line_items and does not create a subscription line item' do
expect(controller_instance.send(:valid_subscription_line_item_params?)).to be false

expect(controller_instance).not_to receive(:handle_subscription_line_items)
Expand All @@ -68,17 +66,19 @@ def initialize(params = {})
end

context 'when subscription params are present' do
it 'calls create_subscription_line_item with the correct line item' do
line_item = create(:line_item, order: order, variant: variant)

controller_instance.params = {
let(:params) do
{
variant_id: variant.id,
subscription_line_item: {
subscribable_id: 1,
quantity: 2,
interval_length: 1
}
}
end

it 'calls create_subscription_line_item with the correct line item' do
line_item = create(:line_item, order: order, variant: variant)

allow(order.line_items).to receive(:find_by).with(variant_id: variant.id).and_return(line_item)

Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
expect(subscription.billing_address.zipcode).to eq('33167')
end

it 'Creates a subscription' do # rubocop:disable RSpec/MultipleExpectations
it 'Creates a subscription' do
variant = create(:variant, subscribable: true)
create(:user)
create(:store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

context 'when handling #perform errors' do
it 'by default logs exception data without raising exceptions' do # rubocop:disable RSpec/MultipleExpectations
it 'by default logs exception data without raising exceptions' do
installment = build_stubbed(:installment)
checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
allow(c).to receive(:process).and_raise('test error')
Expand Down
2 changes: 0 additions & 2 deletions spec/lib/solidus_subscriptions/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

RSpec.describe SolidusSubscriptions::Checkout, :checkout do
context 'when the order can be created and paid' do
# rubocop:disable RSpec/MultipleExpectations
it 'creates and finalizes a new order for the installment' do
stub_spree_preferences(auto_capture: true)
installment = create(:installment, :actionable)
Expand Down Expand Up @@ -39,7 +38,6 @@
expect(order.subscription).to eq(subscription)
expect(order.subscription_order).to eq(true)
end
# rubocop:enable RSpec/MultipleExpectations

it 'matches the total on the subscription' do
stub_spree_preferences(auto_capture: true)
Expand Down
4 changes: 0 additions & 4 deletions spec/requests/api/v1/subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
end

context 'when valid payment attributes are provided' do
# rubocop:disable RSpec/MultipleExpectations
it 'creates the subscription using the specified payment' do
user = create(:user, &:generate_spree_api_key!)
payment_source = create(:credit_card, user: user)
Expand All @@ -53,10 +52,8 @@
end.to change(SolidusSubscriptions::Subscription, :count).from(0).to(1)
expect(SolidusSubscriptions::Subscription.last).to have_attributes(payment_params)
end
# rubocop:enable RSpec/MultipleExpectations
end

# rubocop:disable RSpec/MultipleExpectations
context 'when an invalid payment method is provided' do
it "doesn't create the subscription and responds with 422 Unprocessable Entity" do
user = create(:user, &:generate_spree_api_key!)
Expand Down Expand Up @@ -98,7 +95,6 @@
expect(response.status).to eq(422)
end
end
# rubocop:enable RSpec/MultipleExpectations
end

describe 'PATCH /:id' do
Expand Down