Skip to content

Commit

Permalink
autofix rails
Browse files Browse the repository at this point in the history
  • Loading branch information
thejonroberts committed Dec 11, 2024
1 parent a99b9cb commit d479dee
Show file tree
Hide file tree
Showing 45 changed files with 103 additions and 117 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def authenticate_user!
if user && token && ActiveSupport::SecurityUtils.secure_compare(user.token, token)
@current_user = user
else
render json: {message: "Wrong password or email"}, status: 401
render json: {message: "Wrong password or email"}, status: :unauthorized
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ class Api::V1::Users::SessionsController < Api::V1::BaseController
def create
load_resource
if @user
render json: Api::V1::SessionBlueprint.render(@user), status: 201
render json: Api::V1::SessionBlueprint.render(@user), status: :created
else
render json: {message: "Wrong password or email"}, status: 401
render json: {message: "Wrong password or email"}, status: :unauthorized
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/casa_admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create

begin
casa_admin = service.create!
if !casa_admin.phone_number.blank?
if casa_admin.phone_number.present?
raw_token = casa_admin.raw_invitation_token
base_domain = request.base_url + "/users/edit"
invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: raw_token, host: request.base_url)
Expand Down
18 changes: 7 additions & 11 deletions app/controllers/case_contacts/form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,13 @@ def get_contact_types
.where(casa_case_contact_types: {casa_case_id: @casa_cases.pluck(:id)})
.distinct

if case_contact_types.present?
case_contact_types
else
ContactType
.includes(:contact_type_group)
.joins(:contact_type_group)
.active
.where(contact_type_group: {casa_org: current_organization})
.order("contact_type_group.name ASC", :name)
.distinct
end
case_contact_types.presence || ContactType
.includes(:contact_type_group)
.joins(:contact_type_group)
.active
.where(contact_type_group: {casa_org: current_organization})
.order("contact_type_group.name ASC", :name)
.distinct
end

def get_contact_topics
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def valid_params?(email, phone_number)
end

def email?
!@email.blank?
@email.present?
end

def phone_number?
!@phone_number.blank?
@phone_number.present?
end

def empty_fields_error
Expand Down
2 changes: 1 addition & 1 deletion app/lib/importers/file_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def export_failed_imports
end

def failed?
!failed_imports.blank?
failed_imports.present?
end

def message
Expand Down
2 changes: 1 addition & 1 deletion app/models/all_casa_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AllCasaAdmin < ApplicationRecord

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :invitable, :recoverable, :validatable, :timeoutable, invite_for: 1.weeks
devise :database_authenticatable, :invitable, :recoverable, :validatable, :timeoutable, invite_for: 1.week

def casa_admin?
false
Expand Down
4 changes: 2 additions & 2 deletions app/models/banner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Banner < ApplicationRecord

scope :active, -> { where(active: true) }

validates_presence_of :name
validates_presence_of :content
validates :name, presence: true
validates :content, presence: true
validate :only_one_banner_is_active_per_organization
validate :expires_at_must_be_in_future

Expand Down
8 changes: 3 additions & 5 deletions app/models/casa_org.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class CasaOrg < ApplicationRecord
prepend ActiveSupport::ToJsonWithActiveSupportEncoder
# NOTE: location of the default report template
CASA_DEFAULT_COURT_REPORT = File.new(Rails.root.join("app", "documents", "templates", "default_report_template.docx"), "r")
CASA_DEFAULT_LOGO = Rails.root.join("public", "logo.jpeg")
CASA_DEFAULT_COURT_REPORT = File.new(Rails.root.join("app/documents/templates/default_report_template.docx"), "r")
CASA_DEFAULT_LOGO = Rails.root.join("public/logo.jpeg")

scope :with_logo, -> { joins(:logo_attachment) }

Expand Down Expand Up @@ -57,9 +57,7 @@ def followups
Followup.in_organization(self)
end

def case_contacts_count
case_contacts.count
end
delegate :count, to: :case_contacts, prefix: true

def org_logo
if logo.attached?
Expand Down
10 changes: 4 additions & 6 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ def volunteer_address_is_valid
end
end

def supervisor_id
supervisor.id
end
delegate :id, to: :supervisor, prefix: true

def has_casa_case_transitioned
casa_case.in_transition_age?
Expand All @@ -258,7 +256,7 @@ def should_send_reimbursement_email?
end

def supervisor_active?
!supervisor.blank? && supervisor.active?
supervisor.present? && supervisor.active?
end

def address_field_disabled?
Expand All @@ -279,8 +277,8 @@ def self.options_for_sorted_by

def self.case_hash_from_cases(cases)
casa_case_ids = cases.map(&:draft_case_ids).flatten.uniq.sort
casa_case_ids.each_with_object({}) do |casa_case_id, hash|
hash[casa_case_id] = cases.select { |c| c.casa_case_id == casa_case_id || c.draft_case_ids.include?(casa_case_id) }
casa_case_ids.index_with do |casa_case_id|
cases.select { |c| c.casa_case_id == casa_case_id || c.draft_case_ids.include?(casa_case_id) }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/case_court_report_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def court_topics
}

formatted_date = CourtReportFormatContactDate.new(topic).format_long
answer_value = topic.value.blank? ? "No Answer Provided" : topic.value
answer_value = topic.value.presence || "No Answer Provided"
answer = {
date: formatted_date,
medium: topic.medium_types,
Expand Down
2 changes: 1 addition & 1 deletion app/models/case_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class CaseGroup < ApplicationRecord
has_many :casa_cases, through: :case_group_memberships
before_validation :strip_name

validates_presence_of :case_group_memberships
validates :case_group_memberships, presence: true

validates :name, presence: true, uniqueness: {scope: :casa_org, case_sensitive: false}

Expand Down
6 changes: 3 additions & 3 deletions app/models/concerns/CasaCase/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ module CasaCase::Validations

validates :case_number, uniqueness: {scope: :casa_org_id, case_sensitive: false}, presence: true

validates_presence_of :casa_case_contact_types,
message: ": At least one contact type must be selected",
if: :validate_contact_type
validates :casa_case_contact_types,
presence: {message: ": At least one contact type must be selected",
if: :validate_contact_type}

# Validation to check timestamp and submission status of a case
validates_with CourtReportValidator, fields: [:court_report_status, :court_report_submitted_at]
Expand Down
2 changes: 1 addition & 1 deletion app/models/contact_topic.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ContactTopic < ApplicationRecord
CASA_DEFAULT_COURT_TOPICS = Rails.root.join("db", "seeds", "default_contact_topics.yml")
CASA_DEFAULT_COURT_TOPICS = Rails.root.join("db/seeds/default_contact_topics.yml")
belongs_to :casa_org

has_many :contact_topic_answers
Expand Down
2 changes: 1 addition & 1 deletion app/models/health.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Health < ApplicationRecord
# The "singleton_guard" column is a unique column which must always be set to '0'
# This ensures that only one Health row is created
validates_inclusion_of :singleton_guard, in: [0]
validates :singleton_guard, inclusion: {in: [0]}

def self.instance
first_or_create!(singleton_guard: 0)
Expand Down
2 changes: 1 addition & 1 deletion app/models/note.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Note < ApplicationRecord
belongs_to :notable, polymorphic: true
belongs_to :creator, class_name: "User", foreign_key: "creator_id"
belongs_to :creator, class_name: "User"
end

# == Schema Information
Expand Down
2 changes: 1 addition & 1 deletion app/models/other_duty.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class OtherDuty < ApplicationRecord
belongs_to :creator, class_name: "User", foreign_key: "creator_id"
belongs_to :creator, class_name: "User"
delegate :type, to: :creator, prefix: true

validates :notes, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/supervisor.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Supervisor < User
devise :invitable, invite_for: 2.weeks

has_many :supervisor_volunteers, foreign_key: "supervisor_id"
has_many :supervisor_volunteers
has_many :active_supervisor_volunteers, -> { where(is_active: true) }, class_name: "SupervisorVolunteer", foreign_key: "supervisor_id"
has_many :unassigned_supervisor_volunteers, -> { where(is_active: false) }, class_name: "SupervisorVolunteer", foreign_key: "supervisor_id"

Expand Down
12 changes: 3 additions & 9 deletions app/notifications/base_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ def url
end

# Utility methods
def read?
record.read?
end
delegate :read?, to: :record

def created_at
record.created_at
end
delegate :created_at, to: :record

def updated_at
record.updated_at
end
delegate :updated_at, to: :record

def created_by
created_by_name
Expand Down
8 changes: 4 additions & 4 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class Application < Rails::Application
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.action_mailer.preview_paths << (defined?(Rails.root) ? Rails.root.join("lib", "mailers", "previews") : nil)
config.action_mailer.preview_paths << (defined?(Rails.root) ? Rails.root.join("lib/mailers/previews") : nil)

config.eager_load_paths << Rails.root.join("app", "lib", "importers")
config.assets.paths << Rails.root.join("app", "assets", "webfonts")
config.eager_load_paths << Rails.root.join("app/lib/importers")
config.assets.paths << Rails.root.join("app/assets/webfonts")
config.active_storage.variant_processor = :mini_magick
config.active_storage.content_types_to_serve_as_binary.delete("image/svg+xml")
config.serve_static_assets = true

# to use ViewComponent previews
config.view_component.preview_paths << "#{Rails.root}/spec/components/previews"
config.view_component.preview_paths << "#{Rails.root.join("spec/components/previews")}"
end
end
6 changes: 3 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def create_org_related_data(db_populator, casa_org, options)

SeederMain.new.seed

load(Rails.root.join("db", "seeds", "emancipation_data.rb"))
load(Rails.root.join("db/seeds/emancipation_data.rb"))
begin
load(Rails.root.join("db", "seeds", "emancipation_options_prune.rb"))
load(Rails.root.join("db/seeds/emancipation_options_prune.rb"))
rescue => e
Rails.logger.error { "Caught error during db seed emancipation_options_prune, continuing. Message: #{e}" }
end
load(Rails.root.join("db", "seeds", "placement_data.rb"))
load(Rails.root.join("db/seeds/placement_data.rb"))
4 changes: 2 additions & 2 deletions db/seeds/db_populator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def create_cases(casa_org, options)
court_report_submitted = index.even?

new_casa_case = CasaCase.find_by(case_number: case_number)
birth_month_year_youth = @case_fourteen_years_old ? ((Date.today - 18.year)..(Date.today - CasaCase::TRANSITION_AGE.year)).to_a.sample : ((Date.today - 18.year)..(Date.today - 1.year)).to_a.sample
birth_month_year_youth = @case_fourteen_years_old ? ((Date.today - 18.years)..(Date.today - CasaCase::TRANSITION_AGE.year)).to_a.sample : ((Date.today - 18.years)..(Date.today - 1.year)).to_a.sample
new_casa_case ||= CasaCase.find_or_create_by!(
casa_org_id: casa_org.id,
case_number: case_number,
Expand Down Expand Up @@ -209,7 +209,7 @@ def create_cases(casa_org, options)
volunteer1 = Volunteer.find_by(email: "[email protected]")
if volunteer1.casa_cases.where(birth_month_year_youth: ..CasaCase::TRANSITION_AGE.years.ago).blank?
rand(1..3).times do
birth_month_year_youth = ((Date.today - 18.year)..(Date.today - CasaCase::TRANSITION_AGE.year)).to_a.sample
birth_month_year_youth = ((Date.today - 18.years)..(Date.today - CasaCase::TRANSITION_AGE.year)).to_a.sample
new_casa_case = volunteer1.casa_cases.find_or_create_by!(
casa_org_id: volunteer1.casa_org.id,
case_number: generate_case_number,
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/no_contact_made_reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def valid_past_reminders(volunteer)
return false
end

if reminder&.no_contact_made && reminder.no_contact_made >= 1.months.ago
if reminder&.no_contact_made && reminder.no_contact_made >= 1.month.ago
return false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/send_case_contact_types_reminder.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
desc "Send an SMS to volunteers reminding them to connect with the contact types they have not connected with in the past 60 or more days"
require_relative "case_contact_types_reminder"
task send_case_contact_types_reminder: :environment do
every 1.weeks do
every 1.week do
CaseContactTypesReminder.new.send!
end
end
2 changes: 1 addition & 1 deletion lib/tasks/send_no_contact_made_reminder.rake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
desc "Send an SMS to volunteers reminding them to make contact if two weeks have passed since they logged a case contact but contact was not made"
require_relative "case_contact_types_reminder"
task send_case_contact_types_reminder: :environment do
every 1.days do
every 1.day do
CaseContactTypesReminder.new.send!
end
end
4 changes: 2 additions & 2 deletions lib/tasks/test_checker.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ desc "Check app rb files to verify that there are corresponding spec files."
task test_checker: :environment do
# File containing app filespecs that should not be flagged as errors for not having spec files.
def deny_filespec
File.join(Rails.root, ".allow_skipping_tests")
Rails.root.join(".allow_skipping_tests").to_s
end

def dashed_line
Expand All @@ -21,7 +21,7 @@ task test_checker: :environment do

# @return absolute filespec of a Rails project's top level directory.
def top_level_dir(name)
File.absolute_path(File.join(Rails.root, name))
File.absolute_path(Rails.root.join(name).to_s)
end

# @return .rb files in a directory tree, relative to the passed directory
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/casa_orgs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
twilio_phone_number { "+15555555555" }

trait :with_logo do
logo { Rack::Test::UploadedFile.new(Rails.root.join("spec", "fixtures", "files", "org_logo.jpeg")) }
logo { Rack::Test::UploadedFile.new(Rails.root.join("spec/fixtures/files/org_logo.jpeg")) }
end

trait :all_reimbursements_enabled do
Expand Down
4 changes: 2 additions & 2 deletions spec/factories/case_court_report_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
court_date { nil }
volunteer { nil }
case_court_orders { nil }
path_to_report { Rails.root.join("tmp", "test_report.docx").to_s }
path_to_template { Rails.root.join("app", "documents", "templates", "default_report_template.docx").to_s }
path_to_report { Rails.root.join("tmp/test_report.docx").to_s }
path_to_template { Rails.root.join("app/documents/templates/default_report_template.docx").to_s }
start_date { nil }
end_date { nil }
time_zone { nil }
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tasks/case_contact_types_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

context "volunteer with contacted contact types within last 60 days, sms notifications on, and no reminder in last quarter" do
it "does not send sms reminder" do
CaseContact.update_all(occurred_at: 1.months.ago)
CaseContact.update_all(occurred_at: 1.month.ago)
responses = CaseContactTypesReminder.new.send!
expect(responses.count).to match 0
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tasks/no_contact_made_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
end

context "volunteer with no contact made reminder sent within last 30 days" do
let(:no_contact_made_reminder) { create(:user_reminder_time, no_contact_made: 1.weeks.ago) }
let(:no_contact_made_reminder) { create(:user_reminder_time, no_contact_made: 1.week.ago) }

it "sends not sms reminder" do
CaseContact.destroy_all
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/previews/casa_admin_mailer_preview_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "rails_helper"
require File.join(Rails.root, "lib", "mailers", "previews", "casa_admin_mailer_preview")
require Rails.root.join("lib/mailers/previews/casa_admin_mailer_preview").to_s

RSpec.describe CasaAdminMailerPreview do
let!(:casa_admin) { create(:casa_admin) }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/previews/devise_mailer_preview_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "rails_helper"
require File.join(Rails.root, "lib", "mailers", "previews", "devise_mailer_preview")
require Rails.root.join("lib/mailers/previews/devise_mailer_preview").to_s

RSpec.describe DeviseMailerPreview do
let(:subject) { described_class.new }
Expand Down
2 changes: 1 addition & 1 deletion spec/mailers/previews/supervisor_mailer_preview_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "rails_helper"
require File.join(Rails.root, "lib", "mailers", "previews", "supervisor_mailer_preview")
require Rails.root.join("lib/mailers/previews/supervisor_mailer_preview").to_s

RSpec.describe SupervisorMailerPreview do
let!(:supervisor) { create(:supervisor) }
Expand Down
Loading

0 comments on commit d479dee

Please sign in to comment.