Skip to content

Commit cbd75ba

Browse files
committed
Rubocop fixes
1 parent 33d28ac commit cbd75ba

File tree

8 files changed

+45
-30
lines changed

8 files changed

+45
-30
lines changed

app/controllers/better_together/platform_invitations_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class PlatformInvitationsController < ApplicationController # rubocop:todo Style
1313
end
1414

1515
# GET /platforms/:platform_id/platform_invitations
16-
def index
16+
def index # rubocop:todo Metrics/MethodLength
1717
authorize BetterTogether::PlatformInvitation
1818

1919
# Build filtered and sorted collection with pagination
@@ -45,7 +45,7 @@ def create # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
4545

4646
authorize @platform_invitation
4747

48-
respond_to do |format|
48+
respond_to do |format| # rubocop:todo Metrics/BlockLength
4949
if @platform_invitation.save
5050
flash[:notice] = t('flash.generic.created', resource: t('resources.invitation'))
5151
format.html { redirect_to @platform, notice: flash[:notice] }
@@ -145,7 +145,7 @@ def set_platform_invitation
145145
@platform_invitation = @platform.invitations.find(params[:id])
146146
end
147147

148-
def build_filtered_collection
148+
def build_filtered_collection # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/PerceivedComplexity
149149
collection = base_collection
150150
collection = apply_status_filter(collection) if filter_params[:status].present? || params[:status].present?
151151
collection = apply_email_filter(collection) if filter_params[:search].present? || params[:search].present?
@@ -156,7 +156,7 @@ def build_filtered_collection
156156
collection
157157
end
158158

159-
def apply_sorting(collection)
159+
def apply_sorting(collection) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
160160
sort_by = params[:sort_by]
161161
sort_direction = params[:sort_direction] == 'asc' ? :asc : :desc
162162

app/controllers/better_together/platforms_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module BetterTogether
4-
class PlatformsController < FriendlyResourceController # rubocop:todo Style/Documentation
4+
class PlatformsController < FriendlyResourceController # rubocop:todo Style/Documentation, Metrics/ClassLength
55
before_action :set_platform, only: %i[show edit update destroy]
66
before_action :authorize_platform, only: %i[show edit update destroy]
77
after_action :verify_authorized, except: :index
@@ -126,7 +126,7 @@ def resource_class
126126
::BetterTogether::Platform
127127
end
128128

129-
def resource_collection
129+
def resource_collection # rubocop:todo Metrics/MethodLength
130130
# Comprehensive eager loading to prevent N+1 queries across all platform associations
131131
resource_class.includes(
132132
# Platform's own translations and attachments

app/helpers/better_together/platform_invitations_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def default_column_sort_info_for_invitations
3939
}
4040
end
4141

42-
def build_sort_path_for_invitations(column, direction, platform)
42+
def build_sort_path_for_invitations(column, direction, platform) # rubocop:todo Metrics/MethodLength
4343
platform_platform_invitations_path(platform,
4444
filters: {
4545
search: current_search_filter_for_invitations,

app/models/better_together/platform.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def primary_community_extra_attrs
8282

8383
# Efficiently load platform memberships with all necessary associations
8484
# to prevent N+1 queries in views
85-
def memberships_with_associations
85+
def memberships_with_associations # rubocop:todo Metrics/MethodLength
8686
person_platform_memberships.includes(
8787
{
8888
member: [

lib/tasks/mobility_translation_migration.rake

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Mobility Translation Migration Tasks
24
#
35
# These tasks handle migrating community and partner name translations from the
@@ -19,10 +21,10 @@
1921
# The migration can also be executed through Rails migrations via:
2022
# bin/dc-run rails db:migrate
2123

22-
namespace :translations do
23-
namespace :mobility do
24+
namespace :translations do # rubocop:todo Metrics/BlockLength
25+
namespace :mobility do # rubocop:todo Metrics/BlockLength
2426
desc 'Migrate community and partner name translations from text to string translations'
25-
task migrate_names_to_string: :environment do
27+
task migrate_names_to_string: :environment do # rubocop:todo Metrics/BlockLength
2628
puts 'Starting migration of names from text to string translations...'
2729
puts '=' * 80
2830

@@ -66,7 +68,7 @@ namespace :translations do
6668
records_to_create = []
6769
records_to_delete = []
6870

69-
all_text_translations.each_with_index do |text_translation, index|
71+
all_text_translations.each_with_index do |text_translation, index| # rubocop:todo Metrics/BlockLength
7072
begin
7173
# Check if a string translation already exists for this record
7274
existing_string = string_translation_class.find_by(
@@ -88,22 +90,28 @@ namespace :translations do
8890
updated_at: text_translation.updated_at
8991
}
9092

93+
# rubocop:todo Layout/LineLength
9194
puts "✓ Prepared for migration: #{text_translation.translatable_type} ##{text_translation.translatable_id} name (#{text_translation.locale}): '#{text_translation.value}'"
95+
# rubocop:enable Layout/LineLength
9296
migration_count += 1
9397
else
98+
# rubocop:todo Layout/LineLength
9499
puts "⚠ String translation already exists for #{text_translation.translatable_type} ##{text_translation.translatable_id} name (#{text_translation.locale}), skipping"
100+
# rubocop:enable Layout/LineLength
95101
skipped_count += 1
96102
end
97103

98104
# Always prepare text translation for bulk deletion
99105
records_to_delete << text_translation.id
100106
rescue StandardError => e
107+
# rubocop:todo Layout/LineLength
101108
puts "✗ Error preparing #{text_translation.translatable_type} ##{text_translation.translatable_id}: #{e.message}"
109+
# rubocop:enable Layout/LineLength
102110
error_count += 1
103111
end
104112

105113
# Progress indicator for large datasets
106-
if (index + 1) % 10 == 0 || (index + 1) == all_text_translations.count
114+
if ((index + 1) % 10).zero? || (index + 1) == all_text_translations.count
107115
puts "Progress: #{index + 1}/#{all_text_translations.count} prepared"
108116
end
109117
end
@@ -145,7 +153,7 @@ namespace :translations do
145153
end
146154
end
147155

148-
puts "\n" + ('=' * 80)
156+
puts "\n#{'=' * 80}"
149157
puts 'Migration Summary:'
150158
puts " ✓ Successfully migrated: #{migration_count}"
151159
puts " ⚠ Skipped (already exist): #{skipped_count}"
@@ -155,7 +163,7 @@ namespace :translations do
155163
end
156164

157165
desc 'Clean up remaining text translations after successful migration (DANGEROUS: removes data)'
158-
task clean_up_text_translations: :environment do
166+
task clean_up_text_translations: :environment do # rubocop:todo Metrics/BlockLength
159167
puts 'Cleaning up remaining text translations for community/partner names...'
160168
puts '⚠️ WARNING: This will permanently delete records from the text_translations table!'
161169
puts '=' * 80
@@ -194,10 +202,14 @@ namespace :translations do
194202
if string_exists
195203
# Safe to delete the text translation - add to bulk deletion list
196204
records_to_delete << text_translation.id
205+
# rubocop:todo Layout/LineLength
197206
puts "🗑️ Prepared for cleanup: #{text_translation.translatable_type} ##{text_translation.translatable_id} name (#{text_translation.locale})"
207+
# rubocop:enable Layout/LineLength
198208
cleanup_count += 1
199209
else
210+
# rubocop:todo Layout/LineLength
200211
puts "⚠️ String translation missing for #{text_translation.translatable_type} ##{text_translation.translatable_id} (#{text_translation.locale}) - skipping cleanup"
212+
# rubocop:enable Layout/LineLength
201213
verification_failures += 1
202214
end
203215
end
@@ -217,7 +229,7 @@ namespace :translations do
217229
end
218230
end
219231

220-
puts "\n" + ('=' * 80)
232+
puts "\n#{'=' * 80}"
221233
puts 'Cleanup Summary:'
222234
puts " 🗑️ Records cleaned up: #{cleanup_count}"
223235
puts " ⚠️ Verification failures: #{verification_failures}"
@@ -226,7 +238,7 @@ namespace :translations do
226238
end
227239

228240
desc 'Check status of community/partner name translations (dry run)'
229-
task check_names_status: :environment do
241+
task check_names_status: :environment do # rubocop:todo Metrics/BlockLength
230242
puts 'Checking status of community/partner name translations...'
231243
puts '=' * 80
232244

@@ -278,7 +290,7 @@ namespace :translations do
278290
end
279291
end
280292

281-
puts "\n" + ('=' * 80)
293+
puts "\n#{'=' * 80}"
282294
if all_text_translations.empty?
283295
puts '✅ Migration appears complete - no name translations found in text_translations'
284296
else

spec/controllers/better_together/platform_invitations_controller_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
end
2222

2323
describe 'GET #index' do
24-
let!(:invitation1) do
24+
let!(:invitation1) do # rubocop:todo RSpec/IndexedLet
2525
create(:better_together_platform_invitation, invitee_email: '[email protected]', invitable: platform)
2626
end
27-
let!(:invitation2) do
27+
let!(:invitation2) do # rubocop:todo RSpec/IndexedLet
2828
create(:better_together_platform_invitation, invitee_email: '[email protected]', invitable: platform)
2929
end
3030

@@ -53,7 +53,7 @@
5353
expect(invitations.first.association(:invitee)).to be_loaded if invitations.first.invitee.present?
5454
end
5555

56-
context 'with filtering' do
56+
context 'with filtering' do # rubocop:todo RSpec/NestedGroups
5757
let!(:pending_invitation) do
5858
create(:better_together_platform_invitation, status: 'pending', invitable: platform)
5959
end
@@ -68,7 +68,7 @@
6868
end
6969
end
7070

71-
context 'with search' do
71+
context 'with search' do # rubocop:todo RSpec/NestedGroups
7272
let!(:john_invitation) do
7373
create(:better_together_platform_invitation, invitee_email: '[email protected]', invitable: platform)
7474
end
@@ -83,7 +83,7 @@
8383
end
8484
end
8585

86-
context 'with pagination' do
86+
context 'with pagination' do # rubocop:todo RSpec/NestedGroups
8787
before do
8888
# Create more invitations than the per-page limit (25)
8989
30.times do |i|
@@ -106,7 +106,7 @@
106106
end
107107
end
108108

109-
context 'with sorting' do
109+
context 'with sorting' do # rubocop:todo RSpec/NestedGroups
110110
let!(:old_invitation) do
111111
create(:better_together_platform_invitation, invitee_email: '[email protected]', invitable: platform,
112112
created_at: 2.days.ago)

spec/helpers/better_together/image_helper_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
require 'rails_helper'
24

3-
RSpec.describe BetterTogether::ImageHelper, type: :helper do
4-
include BetterTogether::ImageHelper
5+
RSpec.describe BetterTogether::ImageHelper do
6+
include described_class
57

68
describe '#profile_image_tag' do
79
let(:person) { create(:better_together_person) }
@@ -16,16 +18,15 @@
1618

1719
context 'when person has profile_image_url method' do
1820
before do
19-
allow(person).to receive(:respond_to?).and_return(false)
2021
allow(person).to receive(:respond_to?).with(:profile_image).and_return(true)
2122
allow(person).to receive(:respond_to?).with(:profile_image, anything).and_return(true)
2223
allow(person).to receive(:respond_to?).with(:profile_image_url).and_return(true)
2324
allow(person).to receive(:respond_to?).with(:profile_image_url, anything).and_return(true)
24-
allow(person).to receive(:profile_image_url).and_return('http://example.com/optimized.jpg')
2525

2626
# Mock profile_image.attached? to return true
27-
profile_image_double = double('profile_image', attached?: true)
28-
allow(person).to receive(:profile_image).and_return(profile_image_double)
27+
profile_image_double = double('profile_image', attached?: true) # rubocop:todo RSpec/VerifiedDoubles
28+
allow(person).to receive_messages(respond_to?: false, profile_image_url: 'http://example.com/optimized.jpg',
29+
profile_image: profile_image_double)
2930
end
3031

3132
it 'uses the optimized profile_image_url method' do

spec/performance/profile_image_performance_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'rails_helper'
24

35
RSpec.describe 'Profile Image Performance', type: :request do

0 commit comments

Comments
 (0)