Skip to content

Commit

Permalink
Merge pull request #14898 from opf/chore/mass-lint
Browse files Browse the repository at this point in the history
Run `rubocop -a` on all files
  • Loading branch information
aaron-contreras authored Mar 2, 2024
2 parents a47a104 + fa9a44d commit 4e96b8d
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 50 deletions.
1 change: 0 additions & 1 deletion app/components/open_project/common/attribute_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
module OpenProject
module Common
class AttributeComponent < Primer::Component

def initialize(id, name, description, **args)
super
@id = id
Expand Down
9 changes: 7 additions & 2 deletions app/components/projects/row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,19 @@ def status_explanation
return nil unless user_can_view_project?

if project.status_explanation.present? && project.status_explanation
render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-status-explanation", I18n.t('activerecord.attributes.project.status_explanation'), project.status_explanation)
render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-status-explanation",
I18n.t('activerecord.attributes.project.status_explanation'),
project.status_explanation)
end
end

def description
return nil unless user_can_view_project?

if project.description.present?
render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-description", I18n.t('activerecord.attributes.project.description'), project.description)
render OpenProject::Common::AttributeComponent.new("dialog-#{project.id}-description",
I18n.t('activerecord.attributes.project.description'),
project.description)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/toolbar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def editable_toolbar(form:, field_name:, html: {})
end
end

def breadcrumb_toolbar(*elements, subtitle: '', html: {}, &block)
toolbar(title: safe_join(elements, ' &raquo '.html_safe), subtitle:, html:, &block)
def breadcrumb_toolbar(*elements, subtitle: '', html: {}, &)
toolbar(title: safe_join(elements, ' &raquo '.html_safe), subtitle:, html:, &)
end

protected
Expand Down
4 changes: 2 additions & 2 deletions app/models/journable/historic_active_record_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def journals_join_statement
# The `created_at` column is not present in the `work_package_journals` table.
#
def add_join_on_journables_table_with_created_at_column(relation)
relation \
relation
.joins("INNER JOIN (SELECT id, created_at " \
"FROM \"#{model.table_name}\") AS journables " \
"ON \"journables\".\"id\" = \"journals\".\"journable_id\"")
Expand Down Expand Up @@ -319,7 +319,7 @@ def column_select_definitions
"journals.updated_at as updated_at",
"CASE #{timestamp_case_when_statements} END as timestamp",
"journals.id as journal_id"
] + \
] +
model.column_names_missing_in_journal.collect do |missing_column_name|
"null as #{missing_column_name}"
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/base_services/base_contracted.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def initialize(user:, contract_class: nil, contract_options: {})
# Determine the type of context
# this service is running in
# e.g., within a resource lock or just executing as the given user
def service_context(send_notifications:, &block)
in_context(model, send_notifications:, &block)
def service_context(send_notifications:, &)
in_context(model, send_notifications:, &)
end

def perform(params = {})
Expand Down
4 changes: 2 additions & 2 deletions app/services/base_services/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ module BaseServices
class Create < Write
protected

def service_context(send_notifications:, &block)
in_user_context(send_notifications:, &block)
def service_context(send_notifications:, &)
in_user_context(send_notifications:, &)
end

def instance(_params)
Expand Down
4 changes: 2 additions & 2 deletions app/services/custom_actions/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class CustomActions::BaseService

def call(attributes:,
action:,
&block)
&)
set_attributes(action, attributes)

contract = CustomActions::CuContract.new(action)
result = ServiceResult.new(success: contract.validate && action.save,
result: action,
errors: contract.errors)

block_with_result(result, &block)
block_with_result(result, &)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/services/custom_actions/update_work_package_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def initialize(action:, user:)
self.contract_class = ::WorkPackages::UpdateContract
end

def call(work_package:, &block)
def call(work_package:, &)
apply_actions(work_package, action.actions)

result = ::WorkPackages::UpdateService
.new(user:,
model: work_package)
.call

block_with_result(result, &block)
block_with_result(result, &)
end

private
Expand Down
8 changes: 4 additions & 4 deletions app/services/work_packages/copy_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def copy_watchers(copied)
def copy_work_package_attachments(copy)
copy_attachments(
'WorkPackage',
from: work_package,
to: copy,
references: %i[description]
)
from: work_package,
to: copy,
references: %i[description]
)
end
end
6 changes: 3 additions & 3 deletions config/initializers/friendly_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
# Work around for issue norman/friendly_id#959
module FriendlyIdPatch
def to_param
if friendly_id_config.routes == :friendly \
&& errors.key?(friendly_id_config.query_field) \
&& attribute_changed?(friendly_id_config.query_field)
if friendly_id_config.routes == :friendly &&
errors.key?(friendly_id_config.query_field) &&
attribute_changed?(friendly_id_config.query_field)
diff = changes[friendly_id_config.query_field]
diff.first || diff.second
else
Expand Down
24 changes: 12 additions & 12 deletions lib/api/root_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ def authorize_by_with_raise(callable)
# @param project [Project] the project the permission needs to be checked on
#
# @raise [API::Errors::Unauthorized] when permission is not met
def authorize_in_project(permission_or_permissions, project:, user: current_user, &block)
def authorize_in_project(permission_or_permissions, project:, user: current_user, &)
permissions = Array.wrap(permission_or_permissions)
authorized = permissions.any? do |permission|
user.allowed_in_project?(permission, project)
end

authorize_by_with_raise(authorized, &block)
authorize_by_with_raise(authorized, &)
end

# Checks that the current user has the given permission in any of the given projects or raise {API::Errors::Unauthorized}.
Expand All @@ -168,7 +168,7 @@ def authorize_in_project(permission_or_permissions, project:, user: current_user
# @param projects [[Project]] the projects the permission needs to be checked on
#
# @raise [API::Errors::Unauthorized] when permission is not met
def authorize_in_projects(permission_or_permissions, projects:, user: current_user, &block)
def authorize_in_projects(permission_or_permissions, projects:, user: current_user, &)
raise ArgumentError if projects.blank?

permissions = Array.wrap(permission_or_permissions)
Expand All @@ -180,7 +180,7 @@ def authorize_in_projects(permission_or_permissions, projects:, user: current_us
projects.intersect?(allowed_projects)
end

authorize_by_with_raise(authorized, &block)
authorize_by_with_raise(authorized, &)
end

# Checks that the current user has the given permission on any project or raise {API::Errors::Unauthorized}.
Expand All @@ -190,13 +190,13 @@ def authorize_in_projects(permission_or_permissions, projects:, user: current_us
# those permissions, not all.
#
# @raise [API::Errors::Unauthorized] when permission is not met
def authorize_in_any_project(permission_or_permissions, user: current_user, &block)
def authorize_in_any_project(permission_or_permissions, user: current_user, &)
permissions = Array.wrap(permission_or_permissions)
authorized = permissions.any? do |permission|
user.allowed_in_any_project?(permission)
end

authorize_by_with_raise(authorized, &block)
authorize_by_with_raise(authorized, &)
end

# Checks that the current user has the given permission on any work package or project or raise {API::Errors::Unauthorized}.
Expand All @@ -206,13 +206,13 @@ def authorize_in_any_project(permission_or_permissions, user: current_user, &blo
# those permissions, not all.
#
# @raise [API::Errors::Unauthorized] when permission is not met
def authorize_in_any_work_package(permission_or_permissions, user: current_user, in_project: nil, &block)
def authorize_in_any_work_package(permission_or_permissions, user: current_user, in_project: nil, &)
permissions = Array.wrap(permission_or_permissions)
authorized = permissions.any? do |permission|
user.allowed_in_any_work_package?(permission, in_project:)
end

authorize_by_with_raise(authorized, &block)
authorize_by_with_raise(authorized, &)
end

# Checks that the current user has the given permission on the given work package or raise {API::Errors::Unauthorized}.
Expand All @@ -224,13 +224,13 @@ def authorize_in_any_work_package(permission_or_permissions, user: current_user,
# @param work_package [Project] the work package the permission needs to be checked on
#
# @raise [API::Errors::Unauthorized] when permission is not met
def authorize_in_work_package(permission_or_permissions, work_package:, user: current_user, &block)
def authorize_in_work_package(permission_or_permissions, work_package:, user: current_user, &)
permissions = Array.wrap(permission_or_permissions)
authorized = permissions.any? do |permission|
user.allowed_in_work_package?(permission, work_package)
end

authorize_by_with_raise(authorized, &block)
authorize_by_with_raise(authorized, &)
end

# Checks that the current user has the given permission globally or raise {API::Errors::Unauthorized}.
Expand All @@ -240,13 +240,13 @@ def authorize_in_work_package(permission_or_permissions, work_package:, user: cu
# those permissions, not all.
#
# @raise [API::Errors::Unauthorized] when permission is not met
def authorize_globally(permission_or_permissions, user: current_user, &block)
def authorize_globally(permission_or_permissions, user: current_user, &)
permissions = Array.wrap(permission_or_permissions)
authorized = permissions.any? do |permission|
user.allowed_globally?(permission)
end

authorize_by_with_raise(authorized, &block)
authorize_by_with_raise(authorized, &)
end

def authorize_admin
Expand Down
1 change: 0 additions & 1 deletion modules/meeting/spec/requests/meetings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
RSpec.describe 'Meeting requests',
:skip_csrf,
type: :rails_request do

shared_let(:project) { create(:project, enabled_module_names: %i[meetings]) }
shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_meetings create_meetings] }) }

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
it 'sends an email to the correct user in the correct language' do
perform_enqueued_jobs
mail = ActionMailer::Base.deliveries.last
refute_nil mail
expect(mail).not_to be_nil
expect([registered_user.mail]).to eq(mail.to)
mail.parts.each do |part|
expect(part.body.encoded).to include(I18n.t(:notice_account_activated, locale: 'de'))
Expand Down
15 changes: 10 additions & 5 deletions spec/features/projects/projects_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,14 @@ def expect_projects_in_order(*projects)
development_project.update(
description: 'I am a nice project with a very long long long long long long long long long description',
status_explanation: '<figure>I am a nice project status description with a figure</figure>',
custom_field_values: { custom_field.id => 'This is a short value', long_text_custom_field.id => 'This is a very long long long long long long long value' }
custom_field_values: { custom_field.id => 'This is a short value',
long_text_custom_field.id => 'This is a very long long long long long long long value' }
)

development_project.save!
login_as(admin)
Setting.enabled_projects_columns += [custom_field.column_name, long_text_custom_field.column_name, 'description', 'status_explanation']
Setting.enabled_projects_columns += [custom_field.column_name, long_text_custom_field.column_name, 'description',
'status_explanation']
projects_page.visit!

tr_project_development = page.first('tr', text: 'Development project')
Expand All @@ -275,12 +277,15 @@ def expect_projects_in_order(*projects)
expect(td_project_development_status_description).to have_css('button', text: 'Expand')
expect(td_project_development_status_description).to have_text('Preview not available')

# Check if a long-text costum field which has a short text as value is not truncated and there is no Expand button there
# Check if a long-text custom field which has a short text as value is not truncated and there is no Expand button there
td_project_development_short_cf = tr_project_development.first('td', text: 'This is a short value')
expect(td_project_development_short_cf).to have_no_css('button', text: 'Expand')

# Check if a long-text costum field which has a long text as value is truncated and there is an Expand button there
td_project_development_long_cf = tr_project_development.first('td', text: 'This is a very long long long long long long long value')
# Check if a long-text custom field which has a long text as value is truncated and there is an Expand button there
td_project_development_long_cf = tr_project_development.first(
'td',
text: 'This is a very long long long long long long long value'
)
expect(td_project_development_long_cf).to have_css('button', text: 'Expand')
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
subject: "WP 1->1, 2->2").tap do |wp|
wp.custom_field_values = {
version_cf1.id => [version_1.id.to_s],
version_cf2.id => [version_2.id.to_s],
version_cf2.id => [version_2.id.to_s]
}
wp.save!
end
Expand Down
10 changes: 8 additions & 2 deletions spec/services/workflows/bulk_update_service_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@
expect(Workflow.where(type_id: type.id, role_id: role.id).count)
.to be 3

refute_nil Workflow.where(role_id: role.id, type_id: type.id, old_status_id: status3.id, new_status_id: status2.id).first
assert_nil Workflow.where(role_id: role.id, type_id: type.id, old_status_id: status5.id, new_status_id: status4.id).first
expect(Workflow.where(role_id: role.id,
type_id: type.id,
old_status_id: status3.id,
new_status_id: status2.id).first).not_to be_nil
expect(Workflow.where(role_id: role.id,
type_id: type.id,
old_status_id: status5.id,
new_status_id: status4.id).first).to be_nil
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/rspec_retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
##
# Helper to pass options to retriable while logging
# failures
def retry_block(args: {}, screenshot: false, &block)
def retry_block(args: {}, screenshot: false, &)
if ENV["RSPEC_RETRY_RETRY_COUNT"] == "0"
yield
return
Expand Down Expand Up @@ -76,7 +76,7 @@ def retry_block(args: {}, screenshot: false, &block)
end
end

Retriable.retriable(on_retry: log_errors, **args, &block)
Retriable.retriable(on_retry: log_errors, **args, &)
end

def backtrace_up_to_spec_file(exception)
Expand Down
8 changes: 4 additions & 4 deletions spec/support/shared_let.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#
# Since test-prof added `let_it_be` this is only a wrapper for it
# before_all / let_it_be fixture
def shared_let(key, reload: true, refind: false, &block)
let_it_be(key, reload:, refind:, &block)
def shared_let(key, reload: true, refind: false, &)
let_it_be(key, reload:, refind:, &)
end

# Defines an object to be used by default for all FactoryBot association
Expand All @@ -55,9 +55,9 @@ def shared_let(key, reload: true, refind: false, &block)
#
# shared_association_default(:user) { create(:user) }
#
def shared_association_default(key, factory_name: key, &block)
def shared_association_default(key, factory_name: key, &)
# unique let identifier to prevent clashes
let_it_be(key, reload: true, &block)
let_it_be(key, reload: true, &)

before_all do
set_factory_default(factory_name, send(key))
Expand Down

0 comments on commit 4e96b8d

Please sign in to comment.