From c61ad8d2d0981c801b04234ea394b717c36974db Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Sun, 1 Dec 2024 19:39:59 -0800 Subject: [PATCH] Fixing rubocop violations --- .rubocop.yml | 8 ++---- Gemfile | 2 +- app/classes/fnf/event_reporter.rb | 2 +- app/controllers/payments_controller.rb | 9 +++--- app/mailers/application_mailer.rb | 4 +-- app/models/payment.rb | 2 +- config/application.rb | 2 +- lib/array.rb | 10 +++---- spec/controllers/payments_controller_spec.rb | 1 - spec/models/event_spec.rb | 2 +- spec/models/payment_spec.rb | 16 +++++------ spec/spec_helper.rb | 7 +++-- spec/support/example_helper.rb | 29 ++++++++++---------- 13 files changed, 44 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d0ecd843..8048e847 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,20 +2,16 @@ inherit_from: .rubocop_todo.yml AllCops: NewCops: enable + SuggestExtensions: false require: - - rubocop-factory_bot - rubocop-rails - rubocop-rake - rubocop-rspec - - rubocop-rspec_rails Style/IfUnlessModifier: Enabled: false -RSpecRails/InferredSpecType: - Enabled: false - Metrics/ClassLength: Enabled: false @@ -31,3 +27,5 @@ Layout/HashAlignment: EnforcedLastArgumentHashStyle: ignore_implicit EnforcedHashRocketStyle: table +Style/NumericPredicate: + Enabled: false diff --git a/Gemfile b/Gemfile index c831105a..38cdfa2b 100644 --- a/Gemfile +++ b/Gemfile @@ -98,7 +98,7 @@ group :development, :test do gem 'relaxed-rubocop' gem 'rubocop' gem 'rubocop-rails' - gem 'rubocop-rails-omakase', require: false + gem 'rubocop-rails-omakase' gem 'rubocop-rake' gem 'rubocop-rspec' gem 'vcr' diff --git a/app/classes/fnf/event_reporter.rb b/app/classes/fnf/event_reporter.rb index 13115ee8..651596d0 100644 --- a/app/classes/fnf/event_reporter.rb +++ b/app/classes/fnf/event_reporter.rb @@ -29,7 +29,7 @@ def event_name(event) 'unknown' end name = "Custom/#{event.class.name.split('::').reject { |n| %w[FnF Events].include?(n) }.join('/')}" - name = "#{name}/user-#{event.user.id}-#{event.user.email}" if event.user&.id && event.user&.email + name = "#{name}/user-#{event.user.id}-#{event.user.email}" if event.user&.id && event.user.email name = "#{name}/#{target_name.downcase}" name.gsub(/ */, '-') end diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 1462e7ed..8b593e8e 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -105,11 +105,10 @@ def sent def mark_payment_completed @payment.request_completed flash.now[:notice] = 'Payment has been received and marked as completed.' - - rescue StandardError => e - Rails.logger.error("#mark_payment_completed() => error marking payment as received: #{e.message}") - flash.now[:error] = "ERROR: #{e.message}" - render_flash(flash) + rescue StandardError => e + Rails.logger.error("#mark_payment_completed() => error marking payment as received: #{e.message}") + flash.now[:error] = "ERROR: #{e.message}" + render_flash(flash) end def ticket_request_id diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 321d6ff3..186d753e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -11,10 +11,10 @@ class ApplicationMailer < ActionMailer::Base protected def from_email - "#{@event.name} <#{DEFAULT_SENDER_EMAIL}>" if defined?(:@event) + "#{@event.name} <#{DEFAULT_SENDER_EMAIL}>" if @event end def reply_to_email - "#{@event.name} Ticketing <#{DEFAULT_REPLY_TO_EMAIL}>" if defined?(:@event) + "#{@event.name} Ticketing <#{DEFAULT_REPLY_TO_EMAIL}>" if @event end end diff --git a/app/models/payment.rb b/app/models/payment.rb index 155f0ffe..b93c3022 100644 --- a/app/models/payment.rb +++ b/app/models/payment.rb @@ -141,7 +141,7 @@ def retrieve_payment_intent end Rails.logger.debug { "retrieve_payment_intent payment => #{inspect}}" } - self.payment_intent + payment_intent end # cancel Stripe PaymentIntent if is in progress diff --git a/config/application.rb b/config/application.rb index 9e8fe051..6590e39b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative 'boot' -require_relative '../lib/array.rb' +require_relative '../lib/array' require 'time' require 'etc' diff --git a/lib/array.rb b/lib/array.rb index d85119ab..d967c813 100644 --- a/lib/array.rb +++ b/lib/array.rb @@ -1,13 +1,11 @@ # frozen_string_literal: true -unless Array.new.respond_to?(:avg) +unless [].respond_to?(:avg) class Array def avg - if all?(Numeric) && size > 0 - sum.to_f / size.to_f - else - raise ArgumentError, 'Array must contain only numbers, and have size greater than 0, got ' + inspect - end + raise ArgumentError, "Array must contain only numbers, and have size greater than 0, got #{inspect}" unless all?(Numeric) && size > 0 + + sum / size.to_f end end end diff --git a/spec/controllers/payments_controller_spec.rb b/spec/controllers/payments_controller_spec.rb index 8abb7680..91bcc881 100644 --- a/spec/controllers/payments_controller_spec.rb +++ b/spec/controllers/payments_controller_spec.rb @@ -40,7 +40,6 @@ it { is_expected.to have_http_status(:redirect) } end - end describe 'GET #show' do diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 24b37776..a43abe74 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -64,7 +64,7 @@ describe '#starting' do subject { event.starting.to_s } - it { is_expected.to eq "Tuesday, October 1, 2030 @ 05:00 AM" } + it { is_expected.to eq 'Tuesday, October 1, 2030 @ 05:00 AM' } end describe '#long_name' do diff --git a/spec/models/payment_spec.rb b/spec/models/payment_spec.rb index 495a6c5b..7cc2d8f9 100644 --- a/spec/models/payment_spec.rb +++ b/spec/models/payment_spec.rb @@ -285,28 +285,28 @@ let(:payment) { build(:payment) } it 'marks the payment status as received' do - expect { + expect do payment.request_completed - }.to change { payment.status_received? }.to be_truthy + end.to change(payment, :status_received?) end it 'marks the ticket request as complete' do - expect { + expect do payment.request_completed - }.to change { payment.ticket_request.completed? }.to be_truthy + end.to change { payment.ticket_request.completed? }.to be_truthy end it 'enqueues the PaymentMailer for payment received' do - expect { + expect do payment.request_completed - }.to have_enqueued_mail(PaymentMailer, :payment_received).once + end.to have_enqueued_mail(PaymentMailer, :payment_received).once end it 'raises error when ticket request fails to mark complete', :vcr do - expect { + expect do payment.ticket_request = nil payment.request_completed - }.to raise_error(StandardError) + end.to raise_error(StandardError) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9952aad6..e044c809 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,14 +23,15 @@ require 'vcr' VCR.configure do |config| - config.cassette_library_dir = "spec/fixtures/vcr_cassettes" + config.cassette_library_dir = 'spec/fixtures/vcr_cassettes' config.hook_into :webmock config.ignore_localhost = true config.configure_rspec_metadata! - config.filter_sensitive_data("") { Rails.configuration.stripe[:secret_api_key] } + config.filter_sensitive_data('') { Rails.configuration.stripe[:secret_api_key] } end -20.times { puts }; puts "\033[20A" +20.times { puts } +puts "\033[20A" require_relative 'support/example_helper' diff --git a/spec/support/example_helper.rb b/spec/support/example_helper.rb index 588866ad..06934a5d 100644 --- a/spec/support/example_helper.rb +++ b/spec/support/example_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ExampleHelper attr_accessor :example_count, :example_timings attr_reader :config, :timeout, :max_width, :wrap_on_width @@ -20,7 +22,6 @@ def initialize(config:, timeout: 20, max_width: 80) def wrap_example! this = self @config.around do |example| - if this.example_count % this.max_width == 0 this.example_timings.clear if this.wrap_on_width puts if this.wrap_on_width @@ -32,23 +33,21 @@ def wrap_example! end def example_with_timeout(example) - begin - Timeout.timeout(timeout) do - t1 = Time.now.to_f + Timeout.timeout(timeout) do + t1 = Time.now.to_f - example.run + example.run - t2 = Time.now.to_f - duration = ((t2 - t1) * 1000).to_i - @example_timings << duration - print_timings(duration, example) - end - rescue Timeout::Error - warn "\033[31m" - warn "[ 𐄂 ] RSpec Failed with timeout of #{timeout} seconds" - warn " • Example: #{example.full_description}" - warn " • Location: #{example.location}" + t2 = Time.now.to_f + duration = ((t2 - t1) * 1000).to_i + @example_timings << duration + print_timings(duration, example) end + rescue Timeout::Error + warn "\033[31m" + warn "[ 𐄂 ] RSpec Failed with timeout of #{timeout} seconds" + warn " • Example: #{example.full_description}" + warn " • Location: #{example.location}" end def print_timings(duration, example)