Skip to content

Commit

Permalink
chore: Update to Rails 7. Rubocopped.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieing committed Jul 3, 2024
1 parent bde6f4e commit 9d3d337
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 80 deletions.
50 changes: 16 additions & 34 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ Lint/DuplicateMethods:
# Offense count: 7
Lint/MissingSuper:
Exclude:
- 'app/presenters/asset/asset.rb'
- 'app/presenters/asset/index.rb'
- 'app/presenters/asset_type/asset_type.rb'
- 'app/presenters/batch/show.rb'
- 'app/presenters/report/new.rb'
- 'app/presenters/report/show.rb'
- 'app/presenters/workflow/show.rb'
- 'app/presenters/asset_presenter/asset.rb'
- 'app/presenters/asset_presenter/index.rb'
- 'app/presenters/asset_type_presenter/asset_type.rb'
- 'app/presenters/batch_presenter/show.rb'
- 'app/presenters/report_presenter/new.rb'
- 'app/presenters/report_presenter/show.rb'
- 'app/presenters/workflow_presenter/show.rb'

# Offense count: 6
Lint/UselessAssignment:
Expand Down Expand Up @@ -329,14 +329,14 @@ Style/CaseEquality:
Style/ClassAndModuleChildren:
Exclude:
- 'app/presenters/admin/index.rb'
- 'app/presenters/asset/asset.rb'
- 'app/presenters/asset/index.rb'
- 'app/presenters/asset_type/asset_type.rb'
- 'app/presenters/batch/new.rb'
- 'app/presenters/batch/show.rb'
- 'app/presenters/report/new.rb'
- 'app/presenters/report/show.rb'
- 'app/presenters/workflow/show.rb'
- 'app/presenters/asset_presenter/asset.rb'
- 'app/presenters/asset_presenter/index.rb'
- 'app/presenters/asset_type_presenter/asset_type.rb'
- 'app/presenters/batch_presenter/new.rb'
- 'app/presenters/batch_presenter/show.rb'
- 'app/presenters/report_presenter/new.rb'
- 'app/presenters/report_presenter/show.rb'
- 'app/presenters/workflow_presenter/show.rb'

# Offense count: 69
Style/Documentation:
Expand All @@ -359,15 +359,6 @@ Style/Documentation:
- 'app/models/event.rb'
- 'app/models/report.rb'
- 'app/models/workflow.rb'
- 'app/presenters/asset/asset.rb'
- 'app/presenters/asset/index.rb'
- 'app/presenters/asset_type/asset_type.rb'
- 'app/presenters/batch/new.rb'
- 'app/presenters/batch/show.rb'
- 'app/presenters/presenter.rb'
- 'app/presenters/report/new.rb'
- 'app/presenters/report/show.rb'
- 'app/presenters/workflow/show.rb'
- 'config/application.rb'
- 'config/data/asset_types.rb'
- 'config/data/pipeline_destinations.rb'
Expand Down Expand Up @@ -436,16 +427,7 @@ Style/FrozenStringLiteralComment:
- 'app/models/report.rb'
- 'app/models/state.rb'
- 'app/models/workflow.rb'
- 'app/presenters/admin/index.rb'
- 'app/presenters/asset/asset.rb'
- 'app/presenters/asset/index.rb'
- 'app/presenters/asset_type/asset_type.rb'
- 'app/presenters/batch/new.rb'
- 'app/presenters/batch/show.rb'
- 'app/presenters/presenter.rb'
- 'app/presenters/report/new.rb'
- 'app/presenters/report/show.rb'
- 'app/presenters/workflow/show.rb'
- 'app/presenters/report_presenter/show.rb'
- 'config.ru'
- 'config/application.rb'
- 'config/boot.rb'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require './app/presenters/asset/index'
require './app/presenters/asset_presenter/index'

class AssetsController < ApplicationController
def index
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/batches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require './app/presenters/batch/new'
require './app/presenters/batch/show'
require './app/presenters/batch_presenter/new'
require './app/presenters/batch_presenter/show'

class BatchesController < ApplicationController
before_action :batch, only: %i[show update remove]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require './app/presenters/report/new'
require './app/presenters/report/show'
require './app/presenters/report_presenter/new'
require './app/presenters/report_presenter/show'

class ReportsController < ApplicationController
def show; end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workflows_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require './app/presenters/workflow/show'
require './app/presenters/workflow_presenter/show'

class WorkflowsController < ApplicationController
include InitialState
Expand Down
4 changes: 3 additions & 1 deletion app/presenters/admin/index.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require './app/presenters/presenter'
require './app/presenters/asset/asset'
require './app/presenters/asset_presenter/asset'

module Presenter::AdminPresenter
class Index < Presenter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require './app/presenters/presenter'

module Presenter::AssetPresenter
# Presenter for showing an asset
class Asset < Presenter
attr_reader :asset

Expand Down Expand Up @@ -62,15 +65,15 @@ def completed_status_label
end

def completed_at_status
"#{asset.completed_at.strftime('%d/%m/%Y')} #{'(' + completed_status_label + ')' if completed_status_label}"
"#{asset.completed_at.strftime('%d/%m/%Y')} #{"(#{completed_status_label})" if completed_status_label}"
end

def completed_at
return completed_at_status if asset.completed_at
return 'Due today' if due_today?
return "Overdue (#{overdue_by} #{'day'.pluralize(overdue_by)})" if overdue?

'In progress' + in_progress_status
"In progress#{in_progress_status}"
end

def days_left
Expand All @@ -86,7 +89,7 @@ def in_progress_status
def due_today?
return false if asset.workflow.turn_around_days.nil?

(0..1).include?(time_from_due_date)
(0..1).cover?(time_from_due_date)
end

def time_from_due_date
Expand Down Expand Up @@ -118,7 +121,7 @@ def overdue_by
end

def overdue?
asset.completed_at.nil? && overdue_by > 0
asset.completed_at.nil? && overdue_by.positive?
end

def completed?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

require './app/presenters/presenter'
require './app/presenters/asset/asset'
require './app/presenters/asset_presenter/asset'

module Presenter::AssetPresenter
# Presenter for showing a list of assets
class Index < Presenter
attr_reader :search, :assets, :total

Expand All @@ -16,8 +19,8 @@ def asset_identifiers
assets.values.flatten.map(&:identifier)
end

def has_assets?(type)
assets[type].length > 0
def assets?(type)
assets[type].length.positive?
end

def num_assets(type)
Expand All @@ -37,10 +40,10 @@ def each_asset(type)
end

def search_parameters
yield search if is_search?
yield search if search?
end

def is_search?
def search?
search.present?
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require './app/presenters/presenter'

module Presenter::AssetTypePresenter
# Presenter for showing an asset type
class AssetType < Presenter
attr_reader :asset_type

Expand Down Expand Up @@ -44,7 +47,7 @@ def asset_fields
:created_at, :completed_at].compact
end

def is_field_value_shared_inside_batch?(asset_field)
def field_value_shared_inside_batch?(asset_field)
%i[batch_id workflow cost_code study project].include?(asset_field)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require './app/presenters/presenter'

module Presenter::BatchPresenter
# Presenter for creating a new batch
class New < Presenter
def each_asset; end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

require './app/presenters/presenter'
require './app/presenters/asset/asset'
require './app/presenters/asset_presenter/asset'

module Presenter::BatchPresenter
# Presenter for showing a batch
class Show < Presenter
attr_reader :batch

Expand Down Expand Up @@ -38,11 +41,11 @@ def workflow
end

def prohibited_workflow(reportable, qc_flow, cherrypick_flow)
if workflow.present?
(workflow.reportable != reportable) ||
(workflow.qc_flow != qc_flow) ||
(workflow.cherrypick_flow != cherrypick_flow)
end
return if workflow.blank?

(workflow.reportable != reportable) ||
(workflow.qc_flow != qc_flow) ||
(workflow.cherrypick_flow != cherrypick_flow)
end

def workflow_name
Expand All @@ -62,7 +65,7 @@ def cost_code
end

def comment
return first_asset.comment.comment if first_asset && first_asset.comment
return first_asset.comment.comment if first_asset&.comment

''
end
Expand Down
7 changes: 6 additions & 1 deletion app/presenters/presenter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

# This file contains the Presenter module, which is included in all presenters.
class Presenter
# Provides information about the deployed version
module DeploymentInfo
require './lib/deployed_version'

Expand All @@ -25,8 +29,9 @@ def release_name
end
include DeploymentInfo

# Presenter::SharedBehaviour
module SharedBehaviour
require './app/presenters/asset_type/asset_type'
require './app/presenters/asset_type_presenter/asset_type'

def each_asset_type
AssetType.find_each do |asset_type|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require './app/presenters/presenter'

module Presenter::ReportPresenter
# Presenter for creating a new report
class New < Presenter
attr_reader :report

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require './app/presenters/presenter'

module Presenter::ReportPresenter
# Presenter for showing a report
class Show < Presenter
attr_reader :report

Expand All @@ -17,19 +18,17 @@ def flash; end
delegate :title, to: :report

def column_names
"<th class='text-center'>" +
report.column_names.map(&:humanize).join("</th><th class='text-center'>") +
'</th>'
"<th class='text-center'>#{report.column_names.map(&:humanize).join("</th><th class='text-center'>")}</th>"
end

def rows
''.tap do |html|
report.rows.each_with_index do |row, index|
html_for_row = '<tr>' +
"<td class='text-center'> #{index + 1} </td>" +
html_for_row = '<tr>' \
"<td class='text-center'> #{index + 1} </td>" \
"<td class='text-center'>" +
row.data_for(report.column_names).join("</td><td class='text-center'>") +
'</td>' +
'</td>' \
'</tr>'
html << html_for_row
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

require './app/presenters/presenter'

module Presenter::WorkflowPresenter
# Presenter for showing a workflow
class Show < Presenter
attr_reader :workflow

Expand Down
4 changes: 2 additions & 2 deletions app/views/assets/_asset_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<% if new_batch != previous_batch %>

<td rowspan=<%= presenter.assets_from_batch(asset_type.name, new_batch).count %> class="batch-box" style="text-align: center;">
<% if !presenter.is_search? %>
<% if !presenter.search? %>
<div class="checkbox">
<input name="batch_id" type="checkbox" data-psg-select-batch="true" data-psg-batch-id="<%= asset.batch_id %>" />
</div>
Expand All @@ -21,7 +21,7 @@
<% end %>
<% else %>
<td class="common-attribute">
<% if ((asset_field == :identifier) && (!presenter.is_search?)) %>
<% if ((asset_field == :identifier) && (!presenter.search?)) %>
<div class="checkbox">
<input name="assets[<%= asset.id %>]" type="checkbox" data-psg-select-asset="true" data-psg-batch-id="<%= asset.batch_id %>" />
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/assets/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="search-view">
<% if (@presenter.is_search?) %>
<% if (@presenter.search?) %>
<% @presenter.search_parameters do |param| %>
<div class="alert alert-info">Search results where <%= param %></div>
<% end %>
Expand Down Expand Up @@ -35,8 +35,8 @@
<h3><%= asset_type.name %> <span class="badge"><%= @presenter.num_assets(asset_type.name) %></span>
</h3>

<% if @presenter.has_assets?(asset_type.name) %>
<% if (!@presenter.is_search?) %>
<% if @presenter.assets?(asset_type.name) %>
<% if (!@presenter.search?) %>
<small><span><a class="selectable">Select all</a> | <a class="selectable">Unselect</a></small>
<% end %>

Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ class Application < Rails::Application
# Enabling the behaviour where 'belongs_to' associations are required by default.
# (https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#active-record-belongs-to-required-by-default-option)
config.active_record.belongs_to_required_by_default = true

config.active_record.legacy_connection_handling = false
end
end
1 change: 1 addition & 0 deletions config/initializers/asset_types.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require './config/data/asset_types'
require './lib/utils/dependent_loader'

DependentLoader.start(:asset_types) do |on|
on.success do
Expand Down
Loading

0 comments on commit 9d3d337

Please sign in to comment.