Skip to content

Commit

Permalink
Fixing rubocop violations
Browse files Browse the repository at this point in the history
  • Loading branch information
kigster committed Dec 5, 2024
1 parent 9bc6ef2 commit c61ad8d
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 50 deletions.
8 changes: 3 additions & 5 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -31,3 +27,5 @@ Layout/HashAlignment:
EnforcedLastArgumentHashStyle: ignore_implicit
EnforcedHashRocketStyle: table

Style/NumericPredicate:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion app/classes/fnf/event_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/models/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative 'boot'
require_relative '../lib/array.rb'
require_relative '../lib/array'

require 'time'
require 'etc'
Expand Down
10 changes: 4 additions & 6 deletions lib/array.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion spec/controllers/payments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

it { is_expected.to have_http_status(:redirect) }
end

end

describe 'GET #show' do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions spec/models/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 4 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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("<STRIPE_API_KEY>") { Rails.configuration.stripe[:secret_api_key] }
config.filter_sensitive_data('<STRIPE_API_KEY>') { Rails.configuration.stripe[:secret_api_key] }
end

20.times { puts }; puts "\033[20A"
20.times { puts }
puts "\033[20A"

require_relative 'support/example_helper'

Expand Down
29 changes: 14 additions & 15 deletions spec/support/example_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit c61ad8d

Please sign in to comment.