Skip to content

Commit

Permalink
Run rubocop autocorrect -A & add remaining offenses to todo file
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Vick <[email protected]>
  • Loading branch information
benjaminwood and natevick committed Nov 3, 2023
1 parent ad1e9c5 commit d3f8b91
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 103 deletions.
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rspec
- rubocop-rails
Expand Down Expand Up @@ -49,7 +51,7 @@ Layout/EmptyLinesAroundModuleBody:
Layout/EmptyLinesAroundBlockBody:
Enabled: false
Layout/LineLength:
Max: 100
Max: 243
Metrics/BlockLength:
Exclude:
- Rakefile
Expand All @@ -64,7 +66,7 @@ Metrics/ClassLength:
Metrics/MethodLength:
Max: 20
Metrics/AbcSize:
Max: 30
Max: 35
Layout/CaseIndentation:
Enabled: true
EnforcedStyle: case
Expand Down
71 changes: 71 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-11-03 23:21:49 UTC using RuboCop version 1.57.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: 9
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 243

# Offense count: 1
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
Lint/DuplicateBranch:
Exclude:
- 'app/policies/user_policy.rb'

# Offense count: 2
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- 'app/policies/dashboard_policy.rb'
- 'app/policies/user_policy.rb'

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 34

# Offense count: 4
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 81

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 9

# Offense count: 2
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Exclude:
- 'app/models/need.rb'
- 'app/models/user.rb'

# Offense count: 16
Rails/I18nLocaleTexts:
Exclude:
- 'app/admin/site_status.rb'
- 'app/admin/users.rb'
- 'app/controllers/application_controller.rb'
- 'app/controllers/needs_controller.rb'
- 'app/controllers/shift_surveys_controller.rb'
- 'app/controllers/shifts_controller.rb'
- 'app/controllers/verifications_controller.rb'
- 'app/mailers/user_mailer.rb'
- 'app/models/age_range.rb'
- 'app/models/need.rb'
- 'app/models/user.rb'
51 changes: 15 additions & 36 deletions app/admin/shift_survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,54 +32,35 @@ def to_param

show do
attributes_table do
row 'Shift Survey ID' do |s|
s.id
end
row 'Survey Status' do |s|
s.status
end
row 'Shift Survey ID', &:id
row 'Survey Status', &:status
row 'Questions' do
table_for shift_survey do
column 'Did you have adequate supplies to care for the child(ren) during your time at the office?' do |s|
s.supplies
end
column 'Comments' do |s|
s.supplies_text
end
column 'Did you have adequate supplies to care for the child(ren) during your time at the office?',
&:supplies
column 'Comments', &:supplies_text
end
table_for shift_survey do
column 'Did the assigned social worker respond to questions or concerns in a timely manner?' do |s|
s.response_time
end
column 'Comments' do |s|
s.response_time_text
end
column 'Did the assigned social worker respond to questions or concerns in a timely manner?',
&:response_time
column 'Comments', &:response_time_text
end
table_for shift_survey do
column 'Did the hours you signed up for match the hours you volunteered?' do |s|
s.hours_match
end
column 'Comments' do |s|
s.hours_match_text
end
column 'Did the hours you signed up for match the hours you volunteered?', &:hours_match
column 'Comments', &:hours_match_text
end
table_for shift_survey do
column 'How are you feeling after your shift at the child welfare office? (check all that apply)' do |s|
s.ratings.nil? ? nil : JSON.parse(s.ratings)
end
column 'Comments' do |s|
s.ratings_text
end
column 'Comments', &:ratings_text
end
table_for shift_survey do
column 'Your feedback is important to us, and we love hearing from our volunteers! Do you have any comments or kudos you’d like to pass along?' do |s|
s.comments
end
column 'Your feedback is important to us, and we love hearing from our volunteers! Do you have any comments or kudos you’d like to pass along?',
&:comments
end
table_for shift_survey do
column 'Any questions for your Volunteer Coordinator?' do |s|
s.questions
end
column 'Any questions for your Volunteer Coordinator?', &:questions
end
end

Expand All @@ -95,9 +76,7 @@ def to_param
end
row :shifts do
table_for shift_survey.need.shifts.where(user_id: shift_survey.user_id) do
column 'Shift Duration(s)' do |s|
s.duration_in_words
end
column 'Shift Duration(s)', &:duration_in_words
end
end
row 'Children' do |shift_survey|
Expand Down
6 changes: 2 additions & 4 deletions app/admin/users.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

ActiveAdmin.register User do # rubocop:disable Metrics/BlockLength
ActiveAdmin.register User do

config.sort_order = 'last_name_asc'

Expand All @@ -18,9 +18,7 @@

%w(deactivate activate).each do |activation_type|
member_action activation_type.to_sym, method: :post do
unless resource.update(deactivated: !resource.deactivated)
flash[:alert] = 'There was an issue updating this user.'
end
flash[:alert] = 'There was an issue updating this user.' unless resource.update(deactivated: !resource.deactivated)
redirect_to admin_users_path
end
end
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ def query

@office = Office.find(params[:office_id]) if params[:office_id].present?

params[:start_date] = Time.now.beginning_of_month.to_date.to_s if params[:start_date].blank?
if params[:start_date].blank?
params[:start_date] =
Time.zone.now.beginning_of_month.to_date.to_s
end

@start_date = params[:start_date]

params[:end_date] = Time.now.end_of_month.to_date.to_s if params[:end_date].blank?
params[:end_date] = Time.zone.now.end_of_month.to_date.to_s if params[:end_date].blank?

@end_date = params[:end_date]

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/needs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def office_social_workers
private

def check_need_creation_disabled?
return unless need_creation_disabled?
return false unless need_creation_disabled?

flash[:error] = redis.get('need_creation_disabled_msg').presence || 'Need creation disabled'
redirect_to root_path
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/shift_surveys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ def edit

return unless @shift_survey.status == 'Complete'

flash[:notice] = 'You have already submitted your survey'
flash.now[:notice] = 'You have already submitted your survey'
render 'thanks'
end

def update
@shift_survey = ShiftSurvey.find_by(token: params[:token])
params[:shift_survey][:ratings] = params[:shift_survey][:ratings].select do |feeling|
feeling.present?
end
params[:shift_survey][:ratings] = params[:shift_survey][:ratings].select(&:present?)
@shift_survey.assign_attributes(permitted_attributes(@shift_survey))
if @shift_survey.save
@shift_survey.update(status: 'Complete')
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def flash_classes
end

def invite_options_for_select
User::ROLES.map do |role|
User::ROLES.filter_map do |role|
u = User.new(role: role)
[u.role_display, role] if policy(u).new?
end.compact
end
end

def offices_for_select(scope)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/includers/shift_update_event_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def notifiable_office_users_and_need_user
end

def notifiable_office_users
users_with_notifiable_role = User.where('role IN (?)', NOTIFIABLE_ROLES)
users_with_notifiable_role = User.where(role: NOTIFIABLE_ROLES)
need.office
.users
.merge(User.notifiable(users_with_notifiable_role))
Expand Down
2 changes: 1 addition & 1 deletion app/lib/services/dashboard_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def users_by_hours_volunteered
end

def hours_volunteered
find_users_by_hours.map { |_key, value| value }.sum
find_users_by_hours.sum { |_key, value| value }
end

def users_by_needs_created
Expand Down
4 changes: 1 addition & 3 deletions app/lib/services/notifications/shifts/recipients/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class Update
to: :shift

def recipients
if shift_user_is_current_user? || current_user_left_shift?
return notifiable_office_users_and_need_user
end
return notifiable_office_users_and_need_user if shift_user_is_current_user? || current_user_left_shift?
return notifiable_office_users_and_need_user | [user] if scheduler_with_user?
return notifiable_office_users_and_need_user | [user_was] if scheduler_without_user?

Expand Down
2 changes: 1 addition & 1 deletion app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def validate_and_geocode?
end

def validate_and_geocode
address = ADDRESS_FIELDS.map { |v| send(v).presence }.compact.join(', ')
address = ADDRESS_FIELDS.filter_map { |v| send(v).presence }.join(', ')
return if address.blank?

verifier = MainStreet::AddressVerifier.new(address)
Expand Down
3 changes: 1 addition & 2 deletions app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
class Announcement < ApplicationRecord
belongs_to :author, class_name: 'User'

validates :author,
:user_ids,
validates :user_ids,
presence: true

validates :message,
Expand Down
2 changes: 2 additions & 0 deletions app/models/child.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Child < ApplicationRecord
belongs_to :need
enum sex: { male: 0, female: 1, non_binary: 2 }
Expand Down
2 changes: 0 additions & 2 deletions app/models/need.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class Need < ApplicationRecord

validates :start_at,
:expected_duration,
:office,
:user,
presence: true
validates :expected_duration,
numericality: { greater_than_or_equal_to: 60,
Expand Down
4 changes: 2 additions & 2 deletions app/models/shift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.for_survey_notification
.group(:user_id, :need_id)

# Get whole records based on subquery above
join_sql = <<~SQL
join_sql = <<~SQL.squish
INNER JOIN (#{subquery.to_sql}) sub ON (
sub.user_id = shifts.user_id
AND sub.need_id = shifts.need_id
Expand All @@ -44,7 +44,7 @@ def self.for_survey_notification
joins(join_sql)
.where('start_at + make_interval(mins := duration) < ?', 30.minutes.ago)
.joins('LEFT JOIN shift_surveys on (shift_surveys.need_id = shifts.need_id AND shift_surveys.user_id = shifts.user_id)')
.where('shift_surveys.id IS NULL')
.where(shift_surveys: { id: nil })
end

def duration_in_words
Expand Down
2 changes: 2 additions & 0 deletions app/models/shift_survey.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ShiftSurvey < ApplicationRecord
extend DateRangeFilterHelper

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ def role_display

# standard E.164 format used by Twilio
def e164_phone
'+1' + phone.gsub(/\D/, '')
"+1#{phone.gsub(/\D/, '')}"
end

def office_notification_ids
office_users.notifiable.pluck(:office_id)
end

def office_notification_ids=(ids)
ids = ids.reject(&:blank?).map(&:to_i)
ids = ids.compact_blank.map(&:to_i)
office_users.each do |ou|
ou.update!(send_notifications: ou.office_id.in?(ids))
end
Expand Down
2 changes: 2 additions & 0 deletions app/policies/shift_survey_policy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ShiftSurveyPolicy < ApplicationPolicy
def permitted_attributes
[
Expand Down
4 changes: 2 additions & 2 deletions app/workers/remind_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def send_daily_messages
needs = Need.joins(:shifts)
.where('shifts.start_at > ?', 12.hours.from_now)
.where('needs.created_at < ?', 12.hours.ago)
.where('shifts.user_id IS NULL').distinct
.where(shifts: { user_id: nil }).distinct
send_messages(needs)
end

def send_hourly_messages
needs = Need.joins(:shifts)
.where('shifts.created_at BETWEEN ? AND ?', 12.hours.ago, 1.hour.ago)
.where('shifts.start_at BETWEEN ? AND ?', Time.zone.now, 12.hours.from_now)
.where('shifts.user_id IS NULL').distinct
.where(shifts: { user_id: nil }).distinct
send_messages(needs)
end

Expand Down
Loading

0 comments on commit d3f8b91

Please sign in to comment.