Skip to content

Commit 3ec1eff

Browse files
authored
Merge pull request #322 from mamhoff/lint
Enable linting workflow
2 parents 01f08bd + 30c451b commit 3ec1eff

File tree

11 files changed

+85
-86
lines changed

11 files changed

+85
-86
lines changed

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint
2+
3+
on: [pull_request]
4+
5+
concurrency:
6+
group: lint-${{ github.ref_name }}
7+
cancel-in-progress: ${{ github.ref_name != 'main' }}
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
ruby:
14+
name: Check Ruby
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
- name: Install Ruby and gems
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: "3.2"
23+
bundler-cache: true
24+
- name: Lint Ruby files
25+
run: bundle exec rubocop -ESP

.rubocop_todo.yml

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,66 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-09-24 12:23:52 UTC using RuboCop version 0.91.1.
3+
# on 2025-02-13 10:58:32 UTC using RuboCop version 1.71.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
Lint/MissingSuper:
11-
Exclude:
12-
- 'app/services/solidus_subscriptions/user_mismatch_error.rb'
13-
14-
# Offense count: 1
15-
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
16-
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
17-
Naming/MemoizedInstanceVariableName:
9+
# Offense count: 3
10+
# Configuration parameters: EnforcedStyle.
11+
# SupportedStyles: have_received, receive
12+
RSpec/MessageSpies:
1813
Exclude:
19-
- 'lib/solidus_subscriptions/processor.rb'
14+
- 'spec/controllers/concerns/create_subscription_spec.rb'
2015

21-
# Offense count: 2
16+
# Offense count: 9
2217
RSpec/MultipleExpectations:
23-
Max: 2
18+
Max: 7
2419

25-
# Offense count: 90
26-
# Configuration parameters: IgnoreSharedExamples.
20+
# Offense count: 24
21+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
22+
# SupportedStyles: always, named_only
2723
RSpec/NamedSubject:
28-
Enabled: false
24+
Exclude:
25+
- 'spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb'
26+
- 'spec/models/solidus_subscriptions/subscription_spec.rb'
2927

30-
# Offense count: 11
28+
# Offense count: 24
29+
# Configuration parameters: AllowedGroups.
3130
RSpec/NestedGroups:
3231
Max: 4
3332

34-
# Offense count: 4
33+
# Offense count: 3
34+
RSpec/SubjectStub:
35+
Exclude:
36+
- 'spec/controllers/concerns/create_subscription_spec.rb'
37+
38+
# Offense count: 5
3539
# Configuration parameters: Include.
3640
# Include: app/models/**/*.rb
3741
Rails/HasManyOrHasOneDependent:
3842
Exclude:
3943
- 'app/models/solidus_subscriptions/installment.rb'
4044
- 'app/models/solidus_subscriptions/subscription.rb'
4145

42-
# Offense count: 2
43-
# Configuration parameters: Include.
44-
# Include: db/migrate/*.rb
45-
Rails/ReversibleMigration:
46-
Exclude:
47-
- 'db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb'
48-
- 'db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb'
49-
50-
# Offense count: 5
51-
# Configuration parameters: ForbiddenMethods, AllowedMethods.
52-
# 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
53-
Rails/SkipsModelValidations:
54-
Exclude:
55-
- 'app/services/solidus_subscriptions/failure_dispatcher.rb'
56-
- 'app/services/solidus_subscriptions/order_builder.rb'
57-
- 'app/services/solidus_subscriptions/payment_failed_dispatcher.rb'
58-
5946
# Offense count: 1
60-
# Cop supports --auto-correct.
47+
# This cop supports safe autocorrection (--autocorrect).
6148
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
6249
# SupportedStyles: assign_to_condition, assign_inside_condition
6350
Style/ConditionalAssignment:
6451
Exclude:
6552
- 'app/controllers/spree/admin/subscriptions_controller.rb'
6653

6754
# Offense count: 4
68-
# Configuration parameters: MinBodyLength.
55+
# This cop supports safe autocorrection (--autocorrect).
56+
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
6957
Style/GuardClause:
7058
Exclude:
7159
- 'app/models/solidus_subscriptions/subscription.rb'
7260

73-
# Offense count: 1
74-
# Cop supports --auto-correct.
75-
# Configuration parameters: EnforcedStyle.
76-
# SupportedStyles: compact, exploded
77-
Style/RaiseArgs:
78-
Exclude:
79-
- 'app/services/solidus_subscriptions/checkout.rb'
80-
81-
# Offense count: 11
82-
# Cop supports --auto-correct.
83-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
61+
# Offense count: 25
62+
# This cop supports safe autocorrection (--autocorrect).
63+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
8464
# URISchemes: http, https
8565
Layout/LineLength:
86-
Max: 290
66+
Max: 145

app/models/solidus_subscriptions/installment.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class Installment < ApplicationRecord
3030
unfulfilled.where("#{table_name}.actionable_date <= ?", Time.zone.today)
3131
end)
3232

33+
def self.ransackable_attributes(_auth_object = nil)
34+
%w[actionable_date created_at updated_at]
35+
end
36+
3337
# Mark this installment as out of stock.
3438
#
3539
# @return [SolidusSubscriptions::InstallmentDetail] The record of the failed
@@ -131,9 +135,5 @@ def next_actionable_date
131135

132136
(DateTime.current + SolidusSubscriptions.configuration.reprocessing_interval).beginning_of_minute
133137
end
134-
135-
def self.ransackable_attributes(_auth_object = nil)
136-
%w[actionable_date created_at updated_at]
137-
end
138138
end
139139
end

app/models/solidus_subscriptions/subscription.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def self.ransackable_scopes(_auth_object = nil)
9292
[:in_processing_state, :with_subscribable]
9393
end
9494

95+
def self.ransackable_attributes(_auth_object = nil)
96+
%w[actionable_date created_at end_date state updated_at user_id]
97+
end
98+
99+
def self.ransackable_associations(_auth_object = nil)
100+
%w[events user]
101+
end
102+
95103
def self.processing_states
96104
PROCESSING_STATES
97105
end
@@ -432,13 +440,5 @@ def emit_events_for_update
432440
emit_event(type: 'subscription_payment_method_changed')
433441
end
434442
end
435-
436-
def self.ransackable_attributes(_auth_object = nil)
437-
%w[actionable_date created_at end_date state updated_at user_id]
438-
end
439-
440-
def self.ransackable_associations(_auth_object = nil)
441-
%w[events user]
442-
end
443443
end
444444
end

lib/decorators/frontend/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def self.prepended(base)
2424
private
2525

2626
def handle_subscription_line_items
27-
line_item = @current_order.line_items.find_by(variant_id: params[:variant_id])
27+
line_item = current_order.line_items.find_by(variant_id: params[:variant_id])
2828
create_subscription_line_item(line_item)
2929
end
3030
end

lib/generators/solidus_subscriptions/install/templates/app/controllers/concerns/create_subscription.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module CreateSubscription
1111
private
1212

1313
def handle_subscription_line_items
14-
line_item = @current_order.line_items.find_by(variant_id: params[:variant_id])
14+
line_item = current_order.line_items.find_by(variant_id: params[:variant_id])
1515
create_subscription_line_item(line_item)
1616
end
1717

spec/controllers/concerns/create_subscription_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
subject(:controller_instance) do
66
Class.new(ApplicationController) do
77
include CreateSubscription
8-
attr_accessor :params, :current_order
9-
10-
def initialize(params = {})
11-
@params = params
12-
@current_order = nil
13-
end
148
end.new
159
end
1610

1711
let(:variant) { create(:variant) }
1812
let(:order) { create(:order) }
1913

2014
before do
21-
controller_instance.current_order = order
15+
allow(controller_instance).to receive(:current_order).and_return(order)
2216
end
2317

2418
describe '#subscription_line_item_params_present?' do
@@ -50,15 +44,19 @@ def initialize(params = {})
5044
end
5145

5246
describe '#handle_subscription_line_items' do
53-
context 'when subscription params are missing' do
54-
it 'does not invoke handle_subscription_line_items and does not create a subscription line item' do
55-
order.line_items.count
47+
before do
48+
allow(controller_instance).to receive(:params).and_return(params)
49+
end
5650

57-
controller_instance.params = {
51+
context 'when subscription params are missing' do
52+
let(:params) do
53+
{
5854
variant_id: variant.id,
5955
subscription_line_item: {}
6056
}
57+
end
6158

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

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

7068
context 'when subscription params are present' do
71-
it 'calls create_subscription_line_item with the correct line item' do
72-
line_item = create(:line_item, order: order, variant: variant)
73-
74-
controller_instance.params = {
69+
let(:params) do
70+
{
7571
variant_id: variant.id,
7672
subscription_line_item: {
7773
subscribable_id: 1,
7874
quantity: 2,
7975
interval_length: 1
8076
}
8177
}
78+
end
79+
80+
it 'calls create_subscription_line_item with the correct line item' do
81+
line_item = create(:line_item, order: order, variant: variant)
8282

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

spec/features/admin/subscriptions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
expect(subscription.billing_address.zipcode).to eq('33167')
2626
end
2727

28-
it 'Creates a subscription' do # rubocop:disable RSpec/MultipleExpectations
28+
it 'Creates a subscription' do
2929
variant = create(:variant, subscribable: true)
3030
create(:user)
3131
create(:store)

spec/jobs/solidus_subscriptions/process_installment_job_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
end
1313

1414
context 'when handling #perform errors' do
15-
it 'by default logs exception data without raising exceptions' do # rubocop:disable RSpec/MultipleExpectations
15+
it 'by default logs exception data without raising exceptions' do
1616
installment = build_stubbed(:installment)
1717
checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
1818
allow(c).to receive(:process).and_raise('test error')

spec/lib/solidus_subscriptions/checkout_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
RSpec.describe SolidusSubscriptions::Checkout, :checkout do
44
context 'when the order can be created and paid' do
5-
# rubocop:disable RSpec/MultipleExpectations
65
it 'creates and finalizes a new order for the installment' do
76
stub_spree_preferences(auto_capture: true)
87
installment = create(:installment, :actionable)
@@ -39,7 +38,6 @@
3938
expect(order.subscription).to eq(subscription)
4039
expect(order.subscription_order).to eq(true)
4140
end
42-
# rubocop:enable RSpec/MultipleExpectations
4341

4442
it 'matches the total on the subscription' do
4543
stub_spree_preferences(auto_capture: true)

0 commit comments

Comments
 (0)