diff --git a/Dangerfile b/Dangerfile index 9e4e9173bb..89fb8d9cb5 100644 --- a/Dangerfile +++ b/Dangerfile @@ -16,9 +16,9 @@ git.modified_files # Check for missing onPush unless lines.grep(/changeDetection:\s+ChangeDetectionStrategy.OnPush/).length > 0 warn( - "Please use `ChangeDetectionStrategy.OnPush` for this component", - file: path, - line: lines.index(component_line) || 0 - ) + "Please use `ChangeDetectionStrategy.OnPush` for this component", + file: path, + line: lines.index(component_line) || 0 + ) end end diff --git a/Gemfile b/Gemfile index f3d9699940..be10b6597d 100644 --- a/Gemfile +++ b/Gemfile @@ -41,8 +41,8 @@ gem 'rdoc', '>= 2.4.2' # Maintain our own omniauth due to relative URL root issues # see upstream PR: https://github.com/omniauth/omniauth/pull/903 -gem 'omniauth', git: 'https://github.com/opf/omniauth', ref: 'fe862f986b2e846e291784d2caa3d90a658c67f0' gem 'doorkeeper', '~> 5.4.0' +gem 'omniauth', git: 'https://github.com/opf/omniauth', ref: 'fe862f986b2e846e291784d2caa3d90a658c67f0' gem 'request_store', '~> 1.5.0' gem 'warden', '~> 1.2' @@ -110,8 +110,8 @@ gem 'multi_json', '~> 1.15.0' gem 'oj', '~> 3.11.0' gem 'daemons' -gem 'delayed_job_active_record', '~> 4.1.5' gem 'delayed_cron_job', '~> 0.7.4' +gem 'delayed_job_active_record', '~> 4.1.5' gem 'rack-protection', '~> 2.1.0' @@ -252,8 +252,8 @@ group :development do gem 'rubocop' # Gems for living styleguide - gem 'sassc-rails' gem 'livingstyleguide', '~> 2.1.0' + gem 'sassc-rails' end group :development, :test do @@ -307,14 +307,14 @@ platforms :mri, :mingw, :x64_mingw do end gem 'openproject-translations', - git: 'https://github.com/opf/openproject-translations.git', - branch: 'dev' + git: 'https://github.com/opf/openproject-translations.git', + branch: 'dev' gem 'newrelic_rpm', require: ENV.has_key?('NEW_RELIC_LICENSE_KEY') # Load Gemfile.local, Gemfile.plugins, plugins', and custom Gemfiles -gemfiles = Dir.glob File.expand_path('../{Gemfile.plugins,Gemfile.modules,Gemfile.local,lib/plugins/*/Gemfile}', - __FILE__) +gemfiles = Dir.glob File.expand_path('{Gemfile.plugins,Gemfile.modules,Gemfile.local,lib/plugins/*/Gemfile}', + __dir__) gemfiles << ENV['CUSTOM_PLUGIN_GEMFILE'] unless ENV['CUSTOM_PLUGIN_GEMFILE'].nil? gemfiles.each do |file| next unless File.readable?(file) diff --git a/Guardfile b/Guardfile index 319038e439..69108177ba 100644 --- a/Guardfile +++ b/Guardfile @@ -34,7 +34,9 @@ guard :rspec do # , :cli => "--drb" do # Rails example watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } - watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m| + ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] + end watch(%r{^spec/support/(.+)\.rb$}) { 'spec' } watch('config/routes.rb') { 'spec/routing' } watch('app/controllers/application_controller.rb') { 'spec/controllers' } @@ -44,5 +46,5 @@ guard :rspec do # , :cli => "--drb" do # Turnip features and steps watch(%r{^spec/acceptance/(.+)\.feature$}) - watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } end diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index fe78de6417..99b3f623e6 --- a/Rakefile +++ b/Rakefile @@ -30,7 +30,7 @@ # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -require File.expand_path('../config/application', __FILE__) +require File.expand_path('config/application', __dir__) OpenProject::Application.load_rake_tasks diff --git a/app/cells/custom_actions/table_cell.rb b/app/cells/custom_actions/table_cell.rb index a9fe42288b..3b3fd4f184 100644 --- a/app/cells/custom_actions/table_cell.rb +++ b/app/cells/custom_actions/table_cell.rb @@ -27,9 +27,9 @@ module CustomActions def headers [ - ['name', caption: CustomAction.human_attribute_name(:name)], - ['description', caption: CustomAction.human_attribute_name(:description)], - ['sort', caption: I18n.t(:label_sort)] + ['name', { caption: CustomAction.human_attribute_name(:name) }], + ['description', { caption: CustomAction.human_attribute_name(:description) }], + ['sort', { caption: I18n.t(:label_sort) }] ] end end diff --git a/app/cells/enumerations/table_cell.rb b/app/cells/enumerations/table_cell.rb index b788d4097b..837a7ca72e 100644 --- a/app/cells/enumerations/table_cell.rb +++ b/app/cells/enumerations/table_cell.rb @@ -2,7 +2,6 @@ require_dependency 'enumerations/row_cell' module Enumerations class TableCell < ::TableCell - def initial_sort %i[id asc] end @@ -42,13 +41,13 @@ module Enumerations def headers [ - ['name', caption: Enumeration.human_attribute_name(:name)], - ['is_default', caption: Enumeration.human_attribute_name(:is_default)], - ['is_default', caption: Enumeration.human_attribute_name(:active)], - ['sort', caption: I18n.t(:label_sort)] + ['name', { caption: Enumeration.human_attribute_name(:name) }], + ['is_default', { caption: Enumeration.human_attribute_name(:is_default) }], + ['is_default', { caption: Enumeration.human_attribute_name(:active) }], + ['sort', { caption: I18n.t(:label_sort) }] ].tap do |default| if with_colors - default.insert 3, ['color', caption: Enumeration.human_attribute_name(:color)] + default.insert 3, ['color', { caption: Enumeration.human_attribute_name(:color) }] end end end diff --git a/app/cells/oauth/applications/table_cell.rb b/app/cells/oauth/applications/table_cell.rb index 86c508ac4d..fcc915cf2c 100644 --- a/app/cells/oauth/applications/table_cell.rb +++ b/app/cells/oauth/applications/table_cell.rb @@ -3,8 +3,6 @@ require_dependency 'oauth/applications/row_cell' module OAuth module Applications class TableCell < ::TableCell - - class << self def row_class ::OAuth::Applications::RowCell @@ -38,11 +36,11 @@ module OAuth def headers [ - ['name', caption: ::Doorkeeper::Application.human_attribute_name(:name)], - ['owner', caption: ::Doorkeeper::Application.human_attribute_name(:owner)], - ['client_credentials', caption: I18n.t('oauth.client_credentials')], - ['redirect_uri', caption: ::Doorkeeper::Application.human_attribute_name(:redirect_uri)], - ['confidential', caption: ::Doorkeeper::Application.human_attribute_name(:confidential)], + ['name', { caption: ::Doorkeeper::Application.human_attribute_name(:name) }], + ['owner', { caption: ::Doorkeeper::Application.human_attribute_name(:owner) }], + ['client_credentials', { caption: I18n.t('oauth.client_credentials') }], + ['redirect_uri', { caption: ::Doorkeeper::Application.human_attribute_name(:redirect_uri) }], + ['confidential', { caption: ::Doorkeeper::Application.human_attribute_name(:confidential) }] ] end end diff --git a/app/cells/projects/row_cell.rb b/app/cells/projects/row_cell.rb index 0c0315532e..2a19b7a7ab 100644 --- a/app/cells/projects/row_cell.rb +++ b/app/cells/projects/row_cell.rb @@ -123,7 +123,7 @@ module Projects def custom_field(name) table.project_custom_fields.fetch(name) end - + def additional_css_class(column) case column when :name diff --git a/app/cells/projects/table_cell.rb b/app/cells/projects/table_cell.rb index d8d6e8d62b..c02ee50fc2 100644 --- a/app/cells/projects/table_cell.rb +++ b/app/cells/projects/table_cell.rb @@ -6,7 +6,7 @@ module Projects options :current_user # adds this option to those of the base class def initial_sort - [:lft, :asc] + %i[lft asc] end def table_id @@ -52,11 +52,11 @@ module Projects def all_columns @all_columns ||= begin [ - [:hierarchy, builtin: true], - [:name, builtin: true, caption: Project.human_attribute_name(:name)], - [:project_status, caption: Project.human_attribute_name(:status)], - [:status_explanation, caption: Projects::Status.human_attribute_name(:explanation)], - [:public, caption: Project.human_attribute_name(:public)], + [:hierarchy, { builtin: true }], + [:name, { builtin: true, caption: Project.human_attribute_name(:name) }], + [:project_status, { caption: Project.human_attribute_name(:status) }], + [:status_explanation, { caption: Projects::Status.human_attribute_name(:explanation) }], + [:public, { caption: Project.human_attribute_name(:public) }], *custom_field_columns, *admin_columns ] @@ -82,15 +82,15 @@ module Projects return [] unless current_user.admin? [ - [:created_at, caption: Project.human_attribute_name(:created_at)], - [:latest_activity_at, caption: Project.human_attribute_name(:latest_activity_at)], - [:required_disk_space, caption: I18n.t(:label_required_disk_storage)] + [:created_at, { caption: Project.human_attribute_name(:created_at) }], + [:latest_activity_at, { caption: Project.human_attribute_name(:latest_activity_at) }], + [:required_disk_space, { caption: I18n.t(:label_required_disk_storage) }] ] end def custom_field_columns project_custom_fields.values.map do |custom_field| - [:"cf_#{custom_field.id}", caption: custom_field.name, custom_field: true] + [:"cf_#{custom_field.id}", { caption: custom_field.name, custom_field: true }] end end diff --git a/app/cells/settings/numeric_setting_cell.rb b/app/cells/settings/numeric_setting_cell.rb index 11915fd58a..20acc0d442 100644 --- a/app/cells/settings/numeric_setting_cell.rb +++ b/app/cells/settings/numeric_setting_cell.rb @@ -7,7 +7,8 @@ module Settings options :unit, :title options size: 3 - def name # name of setting and tag + # name of setting and tag + def name model end end diff --git a/app/cells/settings/time_zone_setting_cell.rb b/app/cells/settings/time_zone_setting_cell.rb index b0c5f1ecfd..63de481930 100644 --- a/app/cells/settings/time_zone_setting_cell.rb +++ b/app/cells/settings/time_zone_setting_cell.rb @@ -9,7 +9,8 @@ module Settings options container_class: "-wide" options include_blank: true - def name # name of setting and tag + # name of setting and tag + def name model end @@ -48,7 +49,7 @@ module Settings ## # Returns time zone (label, value) tuples to be used for a select field. def time_zone_entries - time_zones.map { |tz| [tz.to_s, tz.name ] } + time_zones.map { |tz| [tz.to_s, tz.name] } end end end diff --git a/app/cells/statuses/table_cell.rb b/app/cells/statuses/table_cell.rb index e91241a681..f79f2af48d 100644 --- a/app/cells/statuses/table_cell.rb +++ b/app/cells/statuses/table_cell.rb @@ -2,7 +2,6 @@ require_dependency 'statuses/row_cell' module Statuses class TableCell < ::TableCell - def initial_sort %i[id asc] end @@ -34,15 +33,15 @@ module Statuses def headers [ - [:name, caption: Status.human_attribute_name(:name)], - [:color, caption: Status.human_attribute_name(:color)], - [:is_default, caption: Status.human_attribute_name(:is_default)], - [:is_closed, caption: Status.human_attribute_name(:is_closed)], - [:is_readonly, caption: Status.human_attribute_name(:is_readonly)], - [:sort, caption: I18n.t(:label_sort)] + [:name, { caption: Status.human_attribute_name(:name) }], + [:color, { caption: Status.human_attribute_name(:color) }], + [:is_default, { caption: Status.human_attribute_name(:is_default) }], + [:is_closed, { caption: Status.human_attribute_name(:is_closed) }], + [:is_readonly, { caption: Status.human_attribute_name(:is_readonly) }], + [:sort, { caption: I18n.t(:label_sort) }] ].tap do |default| if WorkPackage.use_status_for_done_ratio? - default.insert 2, [:done_ratio, caption: WorkPackage.human_attribute_name(:done_ratio)] + default.insert 2, [:done_ratio, { caption: WorkPackage.human_attribute_name(:done_ratio) }] end end end diff --git a/app/cells/users/table_cell.rb b/app/cells/users/table_cell.rb index dc2e7ffd34..cc90388164 100644 --- a/app/cells/users/table_cell.rb +++ b/app/cells/users/table_cell.rb @@ -4,7 +4,7 @@ module Users columns :login, :firstname, :lastname, :mail, :admin, :created_at, :last_login_on def initial_sort - [:id, :asc] + %i[id asc] end def headers @@ -22,7 +22,7 @@ module Users end def desc_by_default - [:admin, :created_at, :last_login_on] + %i[admin created_at last_login_on] end end end diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rb index b4dfe1ae2c..be5bbe32ef 100644 --- a/app/contracts/base_contract.rb +++ b/app/contracts/base_contract.rb @@ -146,7 +146,7 @@ class BaseContract < Disposable::Twin writable_attributes.include?(attribute.to_s) end - def valid?(*args) + def valid?(*_args) super() errors.empty? diff --git a/app/contracts/members/base_contract.rb b/app/contracts/members/base_contract.rb index 49683a649f..7a4c7158ac 100644 --- a/app/contracts/members/base_contract.rb +++ b/app/contracts/members/base_contract.rb @@ -62,7 +62,7 @@ module Members def role_grantable?(role) role.builtin == Role::NON_BUILTIN && - ((model.project && role.class == Role) || (!model.project && role.class == GlobalRole)) + ((model.project && role.instance_of?(Role)) || (!model.project && role.instance_of?(GlobalRole))) end def user_allowed_to_manage? diff --git a/app/contracts/model_contract.rb b/app/contracts/model_contract.rb index 401d75a463..ef2f84de87 100644 --- a/app/contracts/model_contract.rb +++ b/app/contracts/model_contract.rb @@ -34,7 +34,7 @@ require_relative './base_contract' # Model contract for AR records that # support change tracking class ModelContract < BaseContract - def valid?(*args) + def valid?(*_args) super() readonly_attributes_unchanged diff --git a/app/contracts/queries/copy_contract.rb b/app/contracts/queries/copy_contract.rb index 5211315114..01c2c644d5 100644 --- a/app/contracts/queries/copy_contract.rb +++ b/app/contracts/queries/copy_contract.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/contracts/queries/create_contract.rb b/app/contracts/queries/create_contract.rb index 3c3e8f3591..efbc2b0d0f 100644 --- a/app/contracts/queries/create_contract.rb +++ b/app/contracts/queries/create_contract.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/contracts/queries/update_contract.rb b/app/contracts/queries/update_contract.rb index cbcff2061f..09d788f997 100644 --- a/app/contracts/queries/update_contract.rb +++ b/app/contracts/queries/update_contract.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/contracts/queries/update_form_contract.rb b/app/contracts/queries/update_form_contract.rb index 6d7f816ddd..46b7b17404 100644 --- a/app/contracts/queries/update_form_contract.rb +++ b/app/contracts/queries/update_form_contract.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/contracts/types/base_contract.rb b/app/contracts/types/base_contract.rb index 5abad84570..1ec2a7c678 100644 --- a/app/contracts/types/base_contract.rb +++ b/app/contracts/types/base_contract.rb @@ -32,7 +32,6 @@ require 'model_contract' module Types class BaseContract < ::ModelContract - def self.model Type end @@ -97,7 +96,7 @@ module Types errors.add( :attribute_groups, I18n.t('activerecord.errors.models.type.attributes.attribute_groups.attribute_unknown_name', - attribute: key) + attribute: key) ) end end diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb index 2ce7710ab6..eb840f8590 100644 --- a/app/contracts/work_packages/base_contract.rb +++ b/app/contracts/work_packages/base_contract.rb @@ -199,8 +199,8 @@ module WorkPackages def validate_enabled_type # Checks that the issue can not be added/moved to a disabled type - if type_context_changed? - errors.add :type_id, :inclusion unless model.project.types.include?(model.type) + if type_context_changed? && !model.project.types.include?(model.type) + errors.add :type_id, :inclusion end end diff --git a/app/contracts/work_packages/create_note_contract.rb b/app/contracts/work_packages/create_note_contract.rb index 6374896a5c..b9c078e2c2 100644 --- a/app/contracts/work_packages/create_note_contract.rb +++ b/app/contracts/work_packages/create_note_contract.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 5f36dc9096..b41674b0f9 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -77,6 +78,7 @@ class AccountController < ApplicationController if params[:token] @token = ::Token::Recovery.find_by_plaintext_value(params[:token]) redirect_to(home_url) && return unless @token and !@token.expired? + @user = @token.user if request.post? call = ::Users::ChangePasswordService.new(current_user: @user, session: session).call(params) @@ -116,7 +118,7 @@ class AccountController < ApplicationController UserMailer.password_lost(token).deliver_later flash[:notice] = I18n.t(:notice_account_lost_email_sent) redirect_to action: 'login', back_url: home_url - return + nil end end end @@ -277,7 +279,7 @@ class AccountController < ApplicationController show_sso_error_for user flash.now[:error] = I18n.t(:error_auth_source_sso_failed, value: failure[:login]) + - ": " + String(flash.now[:error]) + ": " + String(flash.now[:error]) render action: 'login', back_url: failure[:back_url] end @@ -413,10 +415,13 @@ class AccountController < ApplicationController account_inactive(user, flash_now: true) elsif user.force_password_change return if redirect_if_password_change_not_allowed(user) + render_password_change(user, I18n.t(:notice_account_new_password_forced), show_user_name: true) elsif user.password_expired? return if redirect_if_password_change_not_allowed(user) - render_password_change(user, I18n.t(:notice_account_password_expired, days: Setting.password_days_valid.to_i), show_user_name: true) + + render_password_change(user, I18n.t(:notice_account_password_expired, days: Setting.password_days_valid.to_i), + show_user_name: true) else flash_and_log_invalid_credentials end @@ -546,7 +551,7 @@ class AccountController < ApplicationController end end - def invited_account_not_activated(user) + def invited_account_not_activated(_user) flash_error_message(log_reason: 'invited, NOT ACTIVATED', flash_now: false) do 'account.error_inactive_activation_by_mail' end diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index c3349ada4f..89666ac37e 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -72,7 +72,7 @@ class ActivitiesController < ApplicationController @days = Setting.activity_days_default.to_i if params[:from] - begin; @date_to = params[:from].to_date + 1.day; rescue; end + begin; @date_to = params[:from].to_date + 1.day; rescue StandardError; end end @date_to ||= User.current.today + 1.day diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index ac1ea85d7b..987793f24f 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -63,7 +64,7 @@ class AdminController < ApplicationController begin @test = UserMailer.test_mail(User.current).deliver_now flash[:notice] = I18n.t(:notice_email_sent, value: User.current.mail) - rescue => e + rescue StandardError => e flash[:error] = I18n.t(:notice_email_error, value: Redmine::CodesetUtil.replace_invalid_utf8(e.message.dup)) end ActionMailer::Base.raise_delivery_errors = raise_delivery_errors @@ -131,7 +132,7 @@ class AdminController < ApplicationController def image_conversion_libs_available? Open3.capture2e('convert', '-version').first.include?('ImageMagick') - rescue + rescue StandardError false end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5262fda7cc..1e1d22a25d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -120,7 +121,7 @@ class ApplicationController < ActionController::Base end rescue_from ActionController::ParameterMissing do |exception| - render body: "Required parameter missing: #{exception.param}", + render body: "Required parameter missing: #{exception.param}", status: :bad_request end @@ -188,8 +189,11 @@ class ApplicationController < ActionController::Base def log_requesting_user return unless Setting.log_requesting_user? - login_and_mail = " (#{escape_for_logging(User.current.login)} ID: #{User.current.id} " \ - "<#{escape_for_logging(User.current.mail)}>)" unless User.current.anonymous? + + unless User.current.anonymous? + login_and_mail = " (#{escape_for_logging(User.current.login)} ID: #{User.current.id} " \ + "<#{escape_for_logging(User.current.mail)}>)" + end logger.info "OpenProject User: #{escape_for_logging(User.current.name)}#{login_and_mail}" end @@ -198,7 +202,7 @@ class ApplicationController < ActionController::Base # replaces all invalid characters with # def escape_for_logging(string) # only allow numbers, ASCII letters, space and the following characters: @.-"'!?=/ - string.gsub(/[^0-9a-zA-Z@._\-"\'!\?=\/ ]{1}/, '#') + string.gsub(/[^0-9a-zA-Z@._\-"'!?=\/ ]{1}/, '#') end def reset_i18n_fallbacks @@ -314,7 +318,6 @@ class ApplicationController < ActionController::Base associated.each do |a| instance_variable_set('@' + a.class.to_s.downcase, a) end - rescue ActiveRecord::RecordNotFound render_404 end @@ -326,14 +329,18 @@ class ApplicationController < ActionController::Base # then message.forum and board.project def find_belongs_to_chained_objects(associations, start_object = nil) associations.inject([start_object].compact) do |instances, association| - scope_name, scope_association = association.is_a?(Hash) ? - [association.keys.first.to_s.downcase, association.values.first] : + scope_name, scope_association = if association.is_a?(Hash) + [association.keys.first.to_s.downcase, association.values.first] + else [association.to_s.downcase, association.to_s.downcase] + end # TODO: Remove this hidden dependency on params - instances << (instances.last.nil? ? - scope_name.camelize.constantize.find(params[:"#{scope_name}_id"]) : - instances.last.send(scope_association.to_sym)) + instances << (if instances.last.nil? + scope_name.camelize.constantize.find(params[:"#{scope_name}_id"]) + else + instances.last.send(scope_association.to_sym) + end) instances end end @@ -349,6 +356,7 @@ class ApplicationController < ActionController::Base .where(id: params[:work_package_id] || params[:ids]) .order('id ASC') fail ActiveRecord::RecordNotFound if @work_packages.empty? + @projects = @work_packages.map(&:project).compact.uniq @project = @projects.first if @projects.size == 1 rescue ActiveRecord::RecordNotFound diff --git a/app/controllers/auth_sources_controller.rb b/app/controllers/auth_sources_controller.rb index c852e1cd94..fd81bc2b62 100644 --- a/app/controllers/auth_sources_controller.rb +++ b/app/controllers/auth_sources_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -79,8 +80,8 @@ class AuthSourcesController < ApplicationController begin @auth_method.test_connection flash[:notice] = I18n.t(:notice_successful_connection) - rescue => text - flash[:error] = I18n.t(:error_unable_to_connect, value: text.message) + rescue StandardError => e + flash[:error] = I18n.t(:error_unable_to_connect, value: e.message) end redirect_to action: 'index' end diff --git a/app/controllers/authentication_controller.rb b/app/controllers/authentication_controller.rb index a2749d54a7..5a87bf5357 100644 --- a/app/controllers/authentication_controller.rb +++ b/app/controllers/authentication_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 42e7b227f7..936718b57d 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,9 +31,9 @@ class CategoriesController < ApplicationController menu_item :settings_categories model_object Category - before_action :find_model_object, except: [:new, :create] - before_action :find_project_from_association, except: [:new, :create] - before_action :find_project, only: [:new, :create] + before_action :find_model_object, except: %i[new create] + before_action :find_project_from_association, except: %i[new create] + before_action :find_project, only: %i[new create] before_action :authorize def new diff --git a/app/controllers/colors_controller.rb b/app/controllers/colors_controller.rb index c6ff70dde0..ac1d1c58b0 100644 --- a/app/controllers/colors_controller.rb +++ b/app/controllers/colors_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/concerns/accounts/authentication_stages.rb b/app/controllers/concerns/accounts/authentication_stages.rb index ca1db60f0c..8a2478e787 100644 --- a/app/controllers/concerns/accounts/authentication_stages.rb +++ b/app/controllers/concerns/accounts/authentication_stages.rb @@ -14,10 +14,10 @@ module Accounts::AuthenticationStages end else flash[:error] = I18n.t( - :notice_auth_stage_wrong_stage, - expected: stage || '(none)', - actual: params[:stage] - ) + :notice_auth_stage_wrong_stage, + expected: stage || '(none)', + actual: params[:stage] + ) redirect_to signin_path end @@ -33,7 +33,7 @@ module Accounts::AuthenticationStages def authentication_stages(after_activation: false, reset: true) if OpenProject::Authentication::Stage.stages.select(&:active?).any? - session.delete [:authentication_stages, :stage_secrets, :back_url] if reset + session.delete %i[authentication_stages stage_secrets back_url] if reset if session.include?(:authentication_stages) lookup_authentication_stages @@ -82,7 +82,7 @@ module Accounts::AuthenticationStages .to_h end - def stage_secret(ident) + def stage_secret(_ident) SecureRandom.hex(16) end end diff --git a/app/controllers/concerns/accounts/user_password_change.rb b/app/controllers/concerns/accounts/user_password_change.rb index 3e9ccf0aef..9b8725534d 100644 --- a/app/controllers/concerns/accounts/user_password_change.rb +++ b/app/controllers/concerns/accounts/user_password_change.rb @@ -91,7 +91,7 @@ module Accounts::UserPasswordChange def redirect_if_password_change_not_allowed(user) if user and not user.change_password_allowed? logger.warn "Password change for user '#{user}' forced, but user is not allowed " + - 'to change password' + 'to change password' flash[:error] = I18n.t(:notice_can_t_change_password) redirect_to action: 'login' return true diff --git a/app/controllers/copy_projects_controller.rb b/app/controllers/copy_projects_controller.rb index 437435652b..847812e3b5 100644 --- a/app/controllers/copy_projects_controller.rb +++ b/app/controllers/copy_projects_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/custom_actions_controller.rb b/app/controllers/custom_actions_controller.rb index b5d315d16b..470bc41a3e 100644 --- a/app/controllers/custom_actions_controller.rb +++ b/app/controllers/custom_actions_controller.rb @@ -92,9 +92,9 @@ class CustomActionsController < ApplicationController if request.get? render template: 'common/upsale', locals: { - feature_title: I18n.t('custom_actions.upsale.title'), - feature_description: I18n.t('custom_actions.upsale.description'), - feature_reference: 'custom_actions_admin' + feature_title: I18n.t('custom_actions.upsale.title'), + feature_description: I18n.t('custom_actions.upsale.description'), + feature_reference: 'custom_actions_admin' } else render_403 diff --git a/app/controllers/custom_fields_controller.rb b/app/controllers/custom_fields_controller.rb index c8149cc11c..722f641c97 100644 --- a/app/controllers/custom_fields_controller.rb +++ b/app/controllers/custom_fields_controller.rb @@ -89,7 +89,7 @@ class CustomFieldsController < ApplicationController def destroy begin @custom_field.destroy - rescue + rescue StandardError flash[:error] = I18n.t(:error_can_not_delete_custom_field) end redirect_to custom_fields_path(tab: @custom_field.class.name) diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rb index cd07771922..0c196bf8f6 100644 --- a/app/controllers/custom_styles_controller.rb +++ b/app/controllers/custom_styles_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,9 +32,9 @@ class CustomStylesController < ApplicationController layout 'admin' menu_item :custom_style - before_action :require_admin, except: [:logo_download, :favicon_download, :touch_icon_download] - before_action :require_ee_token, except: [:upsale, :logo_download, :favicon_download, :touch_icon_download] - skip_before_action :check_if_login_required, only: [:logo_download, :favicon_download, :touch_icon_download] + before_action :require_admin, except: %i[logo_download favicon_download touch_icon_download] + before_action :require_ee_token, except: %i[upsale logo_download favicon_download touch_icon_download] + skip_before_action :check_if_login_required, only: %i[logo_download favicon_download touch_icon_download] def show @custom_style = CustomStyle.current || CustomStyle.new @@ -123,7 +124,10 @@ class CustomStylesController < ApplicationController def options_for_theme_select options = OpenProject::CustomStyles::ColorThemes.themes.map { |val| val[:theme] } - options << [t('admin.custom_styles.color_theme_custom'), '', selected: true, disabled: true] unless @current_theme.present? + unless @current_theme.present? + options << [t('admin.custom_styles.color_theme_custom'), '', + { selected: true, disabled: true }] + end options end diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb index 2e9f5ec247..0c1b1af658 100644 --- a/app/controllers/enumerations_controller.rb +++ b/app/controllers/enumerations_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,7 +32,7 @@ class EnumerationsController < ApplicationController layout 'admin' before_action :require_admin - before_action :find_enumeration, only: [:edit, :update, :destroy] + before_action :find_enumeration, only: %i[edit update destroy] include CustomFieldsHelper @@ -117,6 +118,7 @@ class EnumerationsController < ApplicationController def enumeration_class(type) klass = type.to_s.constantize raise NameError unless klass.ancestors.include? Enumeration + klass rescue NameError nil diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 8a402998bb..f184a209ec 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 8a608b05cf..d506794083 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index b390b702a4..1c6d752478 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/highlighting_controller.rb b/app/controllers/highlighting_controller.rb index 0e02db1f46..4ce23db945 100644 --- a/app/controllers/highlighting_controller.rb +++ b/app/controllers/highlighting_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/homescreen_controller.rb b/app/controllers/homescreen_controller.rb index 0295a625fb..553790ae94 100644 --- a/app/controllers/homescreen_controller.rb +++ b/app/controllers/homescreen_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index dbd5cdb31f..481697f969 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -101,7 +101,7 @@ class JournalsController < ApplicationController def valid_diff? valid_field?(params[:field]) && - @journal.journable.class == WorkPackage + @journal.journable.instance_of?(WorkPackage) end def journals_index_title diff --git a/app/controllers/ldap_auth_sources_controller.rb b/app/controllers/ldap_auth_sources_controller.rb index d7a87b8bbe..001e6a8336 100644 --- a/app/controllers/ldap_auth_sources_controller.rb +++ b/app/controllers/ldap_auth_sources_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index a5ea28e33e..ee3ef999b3 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -228,7 +228,7 @@ class MembersController < ApplicationController # The invitation can pretty much only fail due to the user already # having been invited. So look them up if it does. user = UserInvitation.invite_new_user(email: id) || - User.find_by_mail(id) + User.find_by_mail(id) user.id if user end @@ -243,17 +243,18 @@ class MembersController < ApplicationController end def each_comma_seperated(array, &block) - array.map { |e| + array.map do |e| if e.to_s.match /\d(,\d)*/ block.call(e) else e end - }.flatten + end.flatten end def transform_array_of_comma_seperated_ids(array) return array unless array.present? + each_comma_seperated(array) do |elem| elem.to_s.split(',') end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index ad2e8df002..4cb7fc324f 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -33,7 +33,7 @@ class MessagesController < ApplicationController default_search_scope :messages model_object Message, scope: Forum before_action :find_object_and_scope - before_action :authorize, except: [:edit, :update, :destroy] + before_action :authorize, except: %i[edit update destroy] include AttachmentsHelper include PaginationHelper diff --git a/app/controllers/news/comments_controller.rb b/app/controllers/news/comments_controller.rb index d939df5d8c..f03b51c023 100644 --- a/app/controllers/news/comments_controller.rb +++ b/app/controllers/news/comments_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index be7ee58759..25a0652c83 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -117,6 +117,7 @@ class NewsController < ApplicationController def find_optional_project return true unless params[:project_id] + @project = Project.find(params[:project_id]) authorize rescue ActiveRecord::RecordNotFound diff --git a/app/controllers/oauth/applications_controller.rb b/app/controllers/oauth/applications_controller.rb index 06c6a9715e..28ceba1fa3 100644 --- a/app/controllers/oauth/applications_controller.rb +++ b/app/controllers/oauth/applications_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - module OAuth class ApplicationsController < ::ApplicationController before_action :require_admin @@ -42,6 +42,7 @@ module OAuth end def new; end + def edit; end def show @@ -88,7 +89,6 @@ module OAuth redirect_to action: :index end - protected def default_breadcrumb diff --git a/app/controllers/oauth/auth_base_controller.rb b/app/controllers/oauth/auth_base_controller.rb index 29abc53178..c41935f055 100644 --- a/app/controllers/oauth/auth_base_controller.rb +++ b/app/controllers/oauth/auth_base_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/oauth/grants_controller.rb b/app/controllers/oauth/grants_controller.rb index b1307b3694..fbe9fd3bb4 100644 --- a/app/controllers/oauth/grants_controller.rb +++ b/app/controllers/oauth/grants_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - module OAuth class GrantsController < ::ApplicationController before_action :require_login diff --git a/app/controllers/onboarding_controller.rb b/app/controllers/onboarding_controller.rb index 77cc85a30b..4eef36792b 100644 --- a/app/controllers/onboarding_controller.rb +++ b/app/controllers/onboarding_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/activities_controller.rb b/app/controllers/project_settings/activities_controller.rb index 9d4e75571a..24eee13c7b 100644 --- a/app/controllers/project_settings/activities_controller.rb +++ b/app/controllers/project_settings/activities_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/categories_controller.rb b/app/controllers/project_settings/categories_controller.rb index 5ec7bd836b..b0bc7f1110 100644 --- a/app/controllers/project_settings/categories_controller.rb +++ b/app/controllers/project_settings/categories_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/custom_fields_controller.rb b/app/controllers/project_settings/custom_fields_controller.rb index 25658d4f97..a8ef56ffd8 100644 --- a/app/controllers/project_settings/custom_fields_controller.rb +++ b/app/controllers/project_settings/custom_fields_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/generic_controller.rb b/app/controllers/project_settings/generic_controller.rb index a889032f0e..389a466f58 100644 --- a/app/controllers/project_settings/generic_controller.rb +++ b/app/controllers/project_settings/generic_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/modules_controller.rb b/app/controllers/project_settings/modules_controller.rb index 29cabfdc05..62eeb006f5 100644 --- a/app/controllers/project_settings/modules_controller.rb +++ b/app/controllers/project_settings/modules_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/repository_controller.rb b/app/controllers/project_settings/repository_controller.rb index 2fc51fbee6..f2a3751ae8 100644 --- a/app/controllers/project_settings/repository_controller.rb +++ b/app/controllers/project_settings/repository_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings/types_controller.rb b/app/controllers/project_settings/types_controller.rb index d285c571e1..a3d53894d0 100644 --- a/app/controllers/project_settings/types_controller.rb +++ b/app/controllers/project_settings/types_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/project_settings_controller.rb b/app/controllers/project_settings_controller.rb index f5c83a6d9e..c43dab86f6 100644 --- a/app/controllers/project_settings_controller.rb +++ b/app/controllers/project_settings_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c6dd9272bc..a6e9cc6df8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -103,7 +103,6 @@ class ProjectsController < ApplicationController model: @altered_project) .call(permitted_params.project) - if service_call.success? flash[:notice] = t(:notice_successful_update) redirect_to settings_generic_project_path(@altered_project) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 598b7a4baf..487c10114c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -34,6 +35,7 @@ require_dependency 'open_project/scm/adapters' class ChangesetNotFound < StandardError end + class InvalidRevisionParam < StandardError end @@ -42,12 +44,12 @@ class RepositoriesController < ApplicationController include RepositoriesHelper menu_item :repository - menu_item :settings, only: [:edit, :destroy_info] + menu_item :settings, only: %i[edit destroy_info] default_search_scope :changesets before_action :find_project_by_project_id before_action :authorize - before_action :find_repository, except: [:edit, :update, :create, :destroy, :destroy_info] + before_action :find_repository, except: %i[edit update create destroy destroy_info] accept_key_auth :revisions rescue_from OpenProject::SCM::Exceptions::SCMError, with: :show_error_command_failed @@ -82,10 +84,10 @@ class RepositoriesController < ApplicationController if request.post? && params.key?(:committers) # Build a hash with repository usernames as keys and corresponding user ids as values @repository.committer_ids = params[:committers].values - .inject({}) { |h, c| + .inject({}) do |h, c| h[c.first] = c.last h - } + end flash[:notice] = I18n.t(:notice_successful_update) redirect_to action: 'committers', project_id: @project end @@ -207,6 +209,7 @@ class RepositoriesController < ApplicationController # TODO: need to handle edge cases of non-binary content that isn't UTF-8 return false end + true end @@ -228,12 +231,13 @@ class RepositoriesController < ApplicationController def revision raise ChangesetNotFound if @rev.blank? + @changeset = @repository.find_changeset_by_name(@rev) raise ChangesetNotFound unless @changeset respond_to do |format| format.html - format.js do render layout: false end + format.js { render layout: false } end rescue ChangesetNotFound show_error_not_found @@ -297,6 +301,7 @@ class RepositoriesController < ApplicationController unless current_user.allowed_to_in_project?(:view_commit_author_statistics, @project) return deny_access end + data = graph_commits_per_author(@repository) end @@ -341,10 +346,8 @@ class RepositoriesController < ApplicationController @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip @rev_to = params[:rev_to] - unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) - if @repository.branches.blank? - raise InvalidRevisionParam - end + if !@rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) && @repository.branches.blank? + raise InvalidRevisionParam end rescue OpenProject::SCM::Exceptions::SCMEmpty render 'empty' @@ -427,10 +430,10 @@ class RepositoriesController < ApplicationController .references(:changesets) .group(:committer) .size - h = changes_by_author.inject({}) { |o, i| + h = changes_by_author.inject({}) do |o, i| o[i.first] = i.last o - } + end fields = commits_by_author.map(&:first) commits_data = commits_by_author.map(&:last) diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index c098112756..89b5449c88 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -86,7 +87,7 @@ class RolesController < ApplicationController flash[:notice] = I18n.t(:notice_successful_delete) redirect_to action: 'index' notify_changed_roles(:removed, @role) - rescue + rescue StandardError flash[:error] = I18n.t(:error_can_not_remove_role) redirect_to action: 'index' end diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 8af178bd9f..2eccc440d3 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -85,8 +86,8 @@ class SearchController < ApplicationController @pagination_next_date = @results[-1].event_datetime if offset && @results[-1] if @results.size > LIMIT - @pagination_previous_date = @results[-(LIMIT)].event_datetime - @results = @results[-(LIMIT), LIMIT] + @pagination_previous_date = @results[-LIMIT].event_datetime + @results = @results[-LIMIT, LIMIT] end end diff --git a/app/controllers/settings/api_controller.rb b/app/controllers/settings/api_controller.rb index e5ffc94b52..32f83793eb 100644 --- a/app/controllers/settings/api_controller.rb +++ b/app/controllers/settings/api_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/settings/display_controller.rb b/app/controllers/settings/display_controller.rb index 33231e52ae..9b2cdb722d 100644 --- a/app/controllers/settings/display_controller.rb +++ b/app/controllers/settings/display_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/settings/general_controller.rb b/app/controllers/settings/general_controller.rb index 65ee375fd2..250b0341cb 100644 --- a/app/controllers/settings/general_controller.rb +++ b/app/controllers/settings/general_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/settings/projects_controller.rb b/app/controllers/settings/projects_controller.rb index 066b652383..80d9723bba 100644 --- a/app/controllers/settings/projects_controller.rb +++ b/app/controllers/settings/projects_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/settings/repositories_controller.rb b/app/controllers/settings/repositories_controller.rb index 46c7562788..f1b50fb468 100644 --- a/app/controllers/settings/repositories_controller.rb +++ b/app/controllers/settings/repositories_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index 4724235e81..4966e68f59 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -78,7 +79,7 @@ class StatusesController < ApplicationController flash[:notice] = I18n.t(:notice_successful_delete) end redirect_to action: 'index' - rescue + rescue StandardError flash[:error] = I18n.t(:error_unable_delete_status) redirect_to action: 'index' end diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb index d12798a49a..086ed2c2f6 100644 --- a/app/controllers/sys_controller.rb +++ b/app/controllers/sys_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -99,7 +100,7 @@ class SysController < ActionController::Base unless Setting.sys_api_enabled? && params[:key].to_s == Setting.sys_api_key render plain: 'Access denied. Repository management WS is disabled or key is invalid.', status: 403 - return false + false end end @@ -125,6 +126,7 @@ class SysController < ActionController::Base render plain: "Project ##{@project.id} does not have a repository.", status: 404 else return true if @repository.scm.storage_available? + render plain: 'repositories.storage.not_available', status: 400 end @@ -150,12 +152,13 @@ class SysController < ActionController::Base unless Setting.repository_authentication_caching_enabled? return user_login(username, password) end + user = nil user_id = Rails.cache.fetch(OpenProject::RepositoryAuthentication::CACHE_PREFIX + Digest::SHA1.hexdigest("#{username}#{password}"), - expires_in: OpenProject::RepositoryAuthentication::CACHE_EXPIRES_AFTER) { + expires_in: OpenProject::RepositoryAuthentication::CACHE_EXPIRES_AFTER) do user = user_login(username, password) user ? user.id.to_s : '-1' - } + end return nil if user_id.blank? or user_id == '-1' diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb index b37152c30d..abcc709075 100644 --- a/app/controllers/types_controller.rb +++ b/app/controllers/types_controller.rb @@ -53,7 +53,6 @@ class TypesController < ApplicationController CreateTypeService .new(current_user) .call(permitted_type_params, copy_workflow_from: params[:copy_workflow_from]) do |call| - @type = call.result call.on_success do @@ -87,7 +86,6 @@ class TypesController < ApplicationController UpdateTypeService .new(@type, current_user) .call(permitted_type_params) do |call| - call.on_success do redirect_to_type_tab_path(@type, t(:notice_successful_update)) end diff --git a/app/controllers/users/memberships_controller.rb b/app/controllers/users/memberships_controller.rb index a2f300af27..90740ef2cc 100644 --- a/app/controllers/users/memberships_controller.rb +++ b/app/controllers/users/memberships_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 290c3dcf95..93cb88f7ca 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,18 +36,18 @@ class UsersController < ApplicationController before_action :authorize_global, except: %i[show deletion_info destroy] before_action :find_user, only: %i[show - edit - update - change_status_info - change_status - destroy - deletion_info - resend_invitation] + edit + update + change_status_info + change_status + destroy + deletion_info + resend_invitation] # should also contain destroy but post data can not be redirected before_action :require_login, only: [:deletion_info] before_action :authorize_for_user, only: [:destroy] before_action :check_if_deletion_allowed, only: %i[deletion_info - destroy] + destroy] # Password confirmation helpers and actions include PasswordConfirmation diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 08cc336f6c..25ee81aebb 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 8053da4ff1..f16fff07cf 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 1875747d56..15bcf1552e 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -192,6 +192,7 @@ class WikiController < ApplicationController # rename a page def rename return render_403 unless editable? + @page.redirect_existing_links = true # used to display the *original* title if some AR validation errors occur @original_title = @page.title @@ -205,7 +206,8 @@ class WikiController < ApplicationController old_name: @page.title, new_name: attributes["title"], existing_caption: item.caption, - existing_identifier: item.name) + existing_identifier: item.name + ) redirect_to_show elsif @page.update(attributes) @@ -305,6 +307,7 @@ class WikiController < ApplicationController # Reassign children to another parent page reassign_to = @wiki.pages.find_by(id: params[:reassign_to_id].presence) return unless reassign_to + @page.children.each do |child| child.update_attribute(:parent, reassign_to) end diff --git a/app/controllers/wiki_menu_items_controller.rb b/app/controllers/wiki_menu_items_controller.rb index 7c7113f964..e7c21e1aee 100644 --- a/app/controllers/wiki_menu_items_controller.rb +++ b/app/controllers/wiki_menu_items_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -137,7 +138,8 @@ class WikiMenuItemsController < ApplicationController private def wiki_menu_item_params - @wiki_menu_item_params ||= params.require(:menu_items_wiki_menu_item).permit(:name, :title, :navigatable_id, :parent_id, :setting, :new_wiki_page, :index_page) + @wiki_menu_item_params ||= params.require(:menu_items_wiki_menu_item).permit(:name, :title, :navigatable_id, :parent_id, + :setting, :new_wiki_page, :index_page) end def get_data_from_params(params) @@ -157,7 +159,7 @@ class WikiMenuItemsController < ApplicationController @wiki_menu_item.parent.id else @page.nearest_main_item.try :id - end + end end def assign_wiki_menu_item_params(menu_item) @@ -181,7 +183,7 @@ class WikiMenuItemsController < ApplicationController item.tap { |item| item.parent_id = nil } else wiki.wiki_menu_items.build(name: page.slug, title: page.title) - end + end menu_item.options = options menu_item.save diff --git a/app/controllers/work_packages/auto_completes_controller.rb b/app/controllers/work_packages/auto_completes_controller.rb index 45eb778d17..d79422f12e 100644 --- a/app/controllers/work_packages/auto_completes_controller.rb +++ b/app/controllers/work_packages/auto_completes_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/work_packages/bulk_controller.rb b/app/controllers/work_packages/bulk_controller.rb index cfc4c9cffe..bfcea9dcdd 100644 --- a/app/controllers/work_packages/bulk_controller.rb +++ b/app/controllers/work_packages/bulk_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/work_packages/moves_controller.rb b/app/controllers/work_packages/moves_controller.rb index 34fb0f0b87..0638bbf035 100644 --- a/app/controllers/work_packages/moves_controller.rb +++ b/app/controllers/work_packages/moves_controller.rb @@ -104,7 +104,7 @@ class WorkPackages::MovesController < ApplicationController .compact if ids.present? - joined = ids.map {|id| "##{id}" }.join(" ") + joined = ids.map { |id| "##{id}" }.join(" ") ["#{parent_id} (+ children errors: #{joined})"] else [parent_id] @@ -122,7 +122,7 @@ class WorkPackages::MovesController < ApplicationController unless @project # TODO: let users bulk move/copy work packages from different projects render_error message: :'work_packages.move.unsupported_for_multiple_projects', status: 400 - return false + false end end diff --git a/app/controllers/work_packages/reports_controller.rb b/app/controllers/work_packages/reports_controller.rb index cb198e3973..606896902b 100644 --- a/app/controllers/work_packages/reports_controller.rb +++ b/app/controllers/work_packages/reports_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb index 0eab55a9cd..bdf3328b0f 100644 --- a/app/controllers/workflows_controller.rb +++ b/app/controllers/workflows_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -67,16 +68,16 @@ class WorkflowsController < ApplicationController end def copy - if params[:source_type_id].blank? || params[:source_type_id] == 'any' - @source_type = nil - else - @source_type = ::Type.find_by(id: params[:source_type_id].to_i) - end - if params[:source_role_id].blank? || params[:source_role_id] == 'any' - @source_role = nil - else - @source_role = Role.find_by(id: params[:source_role_id].to_i) - end + @source_type = if params[:source_type_id].blank? || params[:source_type_id] == 'any' + nil + else + ::Type.find_by(id: params[:source_type_id].to_i) + end + @source_role = if params[:source_role_id].blank? || params[:source_role_id] == 'any' + nil + else + Role.find_by(id: params[:source_role_id].to_i) + end @target_types = params[:target_type_ids].blank? ? nil : ::Type.where(id: params[:target_type_ids]) @target_roles = params[:target_role_ids].blank? ? nil : Role.where(id: params[:target_role_ids]) diff --git a/app/helpers/accessibility_helper.rb b/app/helpers/accessibility_helper.rb index c0406423c4..10901e4669 100644 --- a/app/helpers/accessibility_helper.rb +++ b/app/helpers/accessibility_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -52,15 +53,17 @@ module AccessibilityHelper return nil if english_locale_set? caption_content = menu_item.instance_variable_get(:@caption) - locale_label = caption_content.is_a?(Symbol) ? caption_content : :"label_#{menu_item.name.to_s}" + locale_label = caption_content.is_a?(Symbol) ? caption_content : :"label_#{menu_item.name}" - (!locale_exists?(locale_label) || equals_english_locale(locale_label)) ? :en : nil + !locale_exists?(locale_label) || equals_english_locale(locale_label) ? :en : nil end private def locale_exists?(key, locale = I18n.locale) - I18n.t(key, locale: locale, raise: true) rescue false + I18n.t(key, locale: locale, raise: true) + rescue StandardError + false end def english_locale_set? diff --git a/app/helpers/additional_url_helpers.rb b/app/helpers/additional_url_helpers.rb index 363714a843..46792c941e 100644 --- a/app/helpers/additional_url_helpers.rb +++ b/app/helpers/additional_url_helpers.rb @@ -8,7 +8,7 @@ module AdditionalUrlHelpers end def add_params_to_uri(uri, args = {}) - uri = URI.parse uri + uri = URI.parse uri query = URI.decode_www_form String(uri.query) args.each do |k, v| diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 836e5fa1d7..3336f578fd 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/angular_helper.rb b/app/helpers/angular_helper.rb index 70bc5592dc..49ea0c6c2a 100644 --- a/app/helpers/angular_helper.rb +++ b/app/helpers/angular_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e2f98a3bb9..8650b6e611 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -127,7 +127,7 @@ module ApplicationHelper # Renders flash messages def render_flash_messages messages = flash - .reject { |k,_| k.start_with? '_' } + .reject { |k, _| k.start_with? '_' } .map { |k, v| render_flash_message(k, v) } safe_join messages, "\n" @@ -166,7 +166,7 @@ module ApplicationHelper identifier = element[:project].id tag_options = { value: h(identifier), - title: h(element[:project].name), + title: h(element[:project].name) } if !selected.nil? && selected.id == identifier @@ -223,13 +223,13 @@ module ApplicationHelper end def labeled_check_box_tags(name, collection, options = {}) - collection.sort.map { |object| + collection.sort.map do |object| id = name.gsub(/[\[\]]+/, '_') + object.id.to_s - object_options = options.inject({}) { |h, (k, v)| + object_options = options.inject({}) do |h, (k, v)| h[k] = v.is_a?(Symbol) ? send(v, object) : v h - } + end object_options[:class] = Array(object_options[:class]) + %w(form--label-with-check-box) @@ -238,7 +238,7 @@ module ApplicationHelper styled_check_box_tag(name, object.id, false, id: id) + object end end - }.join.html_safe + end.join.html_safe end def html_hours(text) @@ -323,7 +323,7 @@ module ApplicationHelper text.to_s .gsub(/\r\n?/, "\n") # \r\n and \r -> \n .gsub(/\n\n+/, '

') # 2+ newline -> 2 br - .gsub(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br + .gsub(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br .html_safe end @@ -415,7 +415,7 @@ module ApplicationHelper end end - def calendar_for(*args) + def calendar_for(*_args) ActiveSupport::Deprecation.warn "calendar_for has been removed. Please add the class '-augmented-datepicker' instead.", caller end diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb index 050d487637..5dcfcb6abb 100644 --- a/app/helpers/attachments_helper.rb +++ b/app/helpers/attachments_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/attribute_help_texts_helper.rb b/app/helpers/attribute_help_texts_helper.rb index 075eae98e2..f6bf3448ca 100644 --- a/app/helpers/attribute_help_texts_helper.rb +++ b/app/helpers/attribute_help_texts_helper.rb @@ -36,6 +36,6 @@ module AttributeHelpTextsHelper available .reject { |key,| used.include? key } .map { |key, label| [label, key] } - .sort_by { |label, key| label.downcase } + .sort_by { |label, _key| label.downcase } end end diff --git a/app/helpers/augmenting_helper.rb b/app/helpers/augmenting_helper.rb index 65b5da8f45..687e8d8ffc 100644 --- a/app/helpers/augmenting_helper.rb +++ b/app/helpers/augmenting_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,6 @@ #++ module AugmentingHelper - ## # Create a collapsible section and yield to render the block # diff --git a/app/helpers/avatar_helper.rb b/app/helpers/avatar_helper.rb index 5fb3738635..f698369732 100644 --- a/app/helpers/avatar_helper.rb +++ b/app/helpers/avatar_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index f3bb16ec24..265e37796b 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/colors_helper.rb b/app/helpers/colors_helper.rb index bd513ae509..f559565251 100644 --- a/app/helpers/colors_helper.rb +++ b/app/helpers/colors_helper.rb @@ -94,7 +94,7 @@ module ColorsHelper styles = color.color_styles - background_style = styles.map { |k,v| "#{k}:#{v} !important"}.join(';') + background_style = styles.map { |k, v| "#{k}:#{v} !important" }.join(';') border_color = color.bright? ? '#555555' : color.hexcode if name === 'type' diff --git a/app/helpers/content_for_helper.rb b/app/helpers/content_for_helper.rb index fdd47329df..ea7059dc83 100644 --- a/app/helpers/content_for_helper.rb +++ b/app/helpers/content_for_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb index ed36231a11..97acb83ceb 100644 --- a/app/helpers/custom_fields_helper.rb +++ b/app/helpers/custom_fields_helper.rb @@ -79,7 +79,7 @@ module CustomFieldsHelper path: custom_fields_path(tab: :IssuePriorityCustomField), label: IssuePriority::OptionName } - ] + ] end # Return custom field html tag corresponding to its format @@ -92,12 +92,15 @@ module CustomFieldsHelper tag = case field_format.try(:edit_as) when 'date' - styled_text_field_tag(field_name, custom_value.value, id: field_id, class: '-augmented-datepicker', size: 10, container_class: '-slim', required: custom_field.is_required) + styled_text_field_tag(field_name, custom_value.value, id: field_id, class: '-augmented-datepicker', size: 10, + container_class: '-slim', required: custom_field.is_required) when 'text' - styled_text_area_tag(field_name, custom_value.value, id: field_id, rows: 3, container_class: '-middle', required: custom_field.is_required) + styled_text_area_tag(field_name, custom_value.value, id: field_id, rows: 3, container_class: '-middle', + required: custom_field.is_required) when 'bool' hidden_tag = hidden_field_tag(field_name, '0') - checkbox_tag = styled_check_box_tag(field_name, '1', custom_value.typed_value, id: field_id, required: custom_field.is_required) + checkbox_tag = styled_check_box_tag(field_name, '1', custom_value.typed_value, id: field_id, + required: custom_field.is_required) hidden_tag + checkbox_tag when 'list' blank_option = if custom_field.is_required? && custom_field.default_value.blank? @@ -108,32 +111,36 @@ module CustomFieldsHelper '' end - options = blank_option.html_safe + options_for_select(custom_field.possible_values_options(custom_value.customized), custom_value.value) + options = blank_option.html_safe + options_for_select(custom_field.possible_values_options(custom_value.customized), + custom_value.value) styled_select_tag(field_name, options, id: field_id, container_class: '-middle', required: custom_field.is_required) else - styled_text_field_tag(field_name, custom_value.value, id: field_id, container_class: '-middle', required: custom_field.is_required) - end + styled_text_field_tag(field_name, custom_value.value, id: field_id, container_class: '-middle', + required: custom_field.is_required) + end tag = content_tag :span, tag, lang: custom_field.name_locale, class: 'form--field-container' - custom_value.errors.empty? ? - tag : + if custom_value.errors.empty? + tag + else ActionView::Base.wrap_with_error_span(tag, custom_value, 'value') + end end # Return custom field label tag def custom_field_label_tag(name, custom_value) content_tag 'label', h(custom_value.custom_field.name) + - (custom_value.custom_field.is_required? ? content_tag('span', ' *', class: 'required') : ''), + (custom_value.custom_field.is_required? ? content_tag('span', ' *', class: 'required') : ''), for: "#{name}_custom_field_values_#{custom_value.custom_field.id}", - class: "form--label #{(custom_value.errors.empty? ? nil : 'error')}", + class: "form--label #{custom_value.errors.empty? ? nil : 'error'}", lang: custom_value.custom_field.name_locale end def hidden_custom_field_label_tag(name, custom_value) content_tag 'label', h(custom_value.custom_field.name) + - (custom_value.custom_field.is_required? ? content_tag('span', ' *', class: 'required') : ''), + (custom_value.custom_field.is_required? ? content_tag('span', ' *', class: 'required') : ''), for: "#{name}_custom_field_values_#{custom_value.custom_field.id}", class: "hidden-for-sighted", lang: custom_value.custom_field.name_locale @@ -141,7 +148,7 @@ module CustomFieldsHelper def blank_custom_field_label_tag(name, custom_field) content_tag 'label', h(custom_field.name) + - (custom_field.is_required? ? content_tag('span', ' *', class: 'required') : ''), + (custom_field.is_required? ? content_tag('span', ' *', class: 'required') : ''), for: "#{name}_custom_field_values_#{custom_field.id}", class: 'form--label' end @@ -151,7 +158,7 @@ module CustomFieldsHelper custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value) end - def custom_field_tag_for_bulk_edit(name, custom_field, project=nil) + def custom_field_tag_for_bulk_edit(name, custom_field, project = nil) field_name = "#{name}[custom_field_values][#{custom_field.id}]" field_id = "#{name}_custom_field_values_#{custom_field.id}" field_format = OpenProject::CustomFieldFormat.find_by_name(custom_field.field_format) @@ -165,7 +172,8 @@ module CustomFieldsHelper [I18n.t(:general_text_yes), '1'], [I18n.t(:general_text_no), '0']]), id: field_id) when 'list' - styled_select_tag(field_name, options_for_select([[I18n.t(:label_no_change_option), '']] + custom_field.possible_values_options(project)), id: field_id) + styled_select_tag(field_name, + options_for_select([[I18n.t(:label_no_change_option), '']] + custom_field.possible_values_options(project)), id: field_id) else styled_text_field_tag(field_name, '', id: field_id) end diff --git a/app/helpers/frontend_asset_helper.rb b/app/helpers/frontend_asset_helper.rb index 270dba517f..8d81d8d462 100644 --- a/app/helpers/frontend_asset_helper.rb +++ b/app/helpers/frontend_asset_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index f209296387..7bbb5ba280 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/homescreen_helper.rb b/app/helpers/homescreen_helper.rb index 0db0dc2ace..a5e12a39e4 100644 --- a/app/helpers/homescreen_helper.rb +++ b/app/helpers/homescreen_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -61,6 +62,6 @@ module HomescreenHelper ## # Determine whether we should render the onboarding modal def show_onboarding_modal? - return OpenProject::Configuration.onboarding_enabled? && params[:first_time_user] + OpenProject::Configuration.onboarding_enabled? && params[:first_time_user] end end diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 9ef8fdc213..6ae0a6e9c3 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 86d524c464..f1b083a9d6 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -44,4 +45,4 @@ module MembersHelper { method: :patch, class: 'icon icon-delete', title: t(:button_delete) }) end end -end \ No newline at end of file +end diff --git a/app/helpers/no_results_helper.rb b/app/helpers/no_results_helper.rb index c424d7a574..29ce48c442 100644 --- a/app/helpers/no_results_helper.rb +++ b/app/helpers/no_results_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -54,9 +55,9 @@ module NoResultsHelper render partial: '/common/no_results', locals: { - title_text: title, + title_text: title, action_text: display_action ? action_text : '', - action_url: action_url || '' + action_url: action_url || '' } end end diff --git a/app/helpers/omniauth_helper.rb b/app/helpers/omniauth_helper.rb index 0685cf70b2..58fe1353c7 100644 --- a/app/helpers/omniauth_helper.rb +++ b/app/helpers/omniauth_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/pagination_helper.rb b/app/helpers/pagination_helper.rb index 42c8a4b9fb..dbde874f0c 100644 --- a/app/helpers/pagination_helper.rb +++ b/app/helpers/pagination_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -90,14 +91,14 @@ module PaginationHelper # Constructs the 'n items per page' entries # determined from available options in the settings. def per_page_links(paginator, options) - Setting.per_page_options_array.inject('') { |html, n| + Setting.per_page_options_array.inject('') do |html, n| if n == paginator.per_page html + content_tag(:li, n, class: 'pagination--item -current') else link = link_to_content_update(n, options.merge(page: 1, per_page: n)) html + content_tag(:li, link.html_safe, class: 'pagination--item') end - }.html_safe + end.html_safe end # Returns page option used for pagination @@ -130,9 +131,11 @@ module PaginationHelper end - page > 0 ? - page : + if page > 0 + page + else 1 + end end # Returns per_page option used for pagination @@ -146,20 +149,20 @@ module PaginationHelper def per_page_param(options = params) per_page_candidates = [options[:per_page].to_i, session[:per_page].to_i, options[:limit].to_i] - unless (union = per_page_candidates & Setting.per_page_options_array).empty? + if (union = per_page_candidates & Setting.per_page_options_array).empty? + Setting.per_page_options_array.min + else session[:per_page] = union.first union.first - else - Setting.per_page_options_array.sort.first end end class LinkRenderer < ::WillPaginate::ActionView::LinkRenderer def to_html - pagination.inject('') { |html, item| + pagination.inject('') do |html, item| html + (item.is_a?(Integer) ? page_number(item) : send(item)) - }.html_safe + end.html_safe end protected diff --git a/app/helpers/password_helper.rb b/app/helpers/password_helper.rb index 6b1d0be193..29979edae8 100644 --- a/app/helpers/password_helper.rb +++ b/app/helpers/password_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -86,6 +87,7 @@ module PasswordHelper # the minimum number of rules to adhere to and the total number of rules. def password_rules_description return '' if OpenProject::Passwords::Evaluator.min_adhered_rules == 0 + OpenProject::Passwords::Evaluator.rules_description_locale(password_active_rules) end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 8d9c768514..d7d1d0a102 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -78,8 +78,8 @@ module ProjectsHelper if User.current.allowed_to? :add_subprojects, project [t(:label_subproject_new), new_project_path(parent_id: project.id), - class: 'icon-context icon-add', - title: t(:label_subproject_new)] + { class: 'icon-context icon-add', + title: t(:label_subproject_new) }] end end @@ -87,8 +87,8 @@ module ProjectsHelper if User.current.allowed_to?({ controller: '/project_settings/generic', action: 'show' }, project) [t(:label_project_settings), { controller: '/project_settings/generic', action: 'show', id: project }, - class: 'icon-context icon-settings', - title: t(:label_project_settings)] + { class: 'icon-context icon-settings', + title: t(:label_project_settings) }] end end @@ -96,10 +96,10 @@ module ProjectsHelper if User.current.admin? && project.active? [t(:button_archive), archive_project_path(project, status: params[:status]), - data: { confirm: t('project.archive.are_you_sure', name: project.name) }, - method: :put, - class: 'icon-context icon-locked', - title: t(:button_archive)] + { data: { confirm: t('project.archive.are_you_sure', name: project.name) }, + method: :put, + class: 'icon-context icon-locked', + title: t(:button_archive) }] end end @@ -107,9 +107,9 @@ module ProjectsHelper if User.current.admin? && !project.active? && (project.parent.nil? || project.parent.active?) [t(:button_unarchive), unarchive_project_path(project, status: params[:status]), - method: :put, - class: 'icon-context icon-unlocked', - title: t(:button_unarchive)] + { method: :put, + class: 'icon-context icon-unlocked', + title: t(:button_unarchive) }] end end @@ -117,8 +117,8 @@ module ProjectsHelper if User.current.allowed_to?(:copy_projects, project) && !project.archived? [t(:button_copy), copy_from_project_path(project, :admin), - class: 'icon-context icon-copy', - title: t(:button_copy)] + { class: 'icon-context icon-copy', + title: t(:button_copy) }] end end @@ -126,8 +126,8 @@ module ProjectsHelper if User.current.admin [t(:button_delete), confirm_destroy_project_path(project), - class: 'icon-context icon-delete', - title: t(:button_delete)] + { class: 'icon-context icon-delete', + title: t(:button_delete) }] end end diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index ac28632749..09e0750d46 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/query_menu_items_helper.rb b/app/helpers/query_menu_items_helper.rb index e8ded0ac26..1df71b3664 100644 --- a/app/helpers/query_menu_items_helper.rb +++ b/app/helpers/query_menu_items_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,6 +30,11 @@ module QueryMenuItemsHelper def update_query_menu_item_path(project, query_menu_item) - query_menu_item.persisted? ? query_menu_item_path(project, query_menu_item.query, query_menu_item) : query_menu_items_path(project, query_menu_item.query) + if query_menu_item.persisted? + query_menu_item_path(project, query_menu_item.query, + query_menu_item) + else + query_menu_items_path(project, query_menu_item.query) + end end end diff --git a/app/helpers/relations_helper.rb b/app/helpers/relations_helper.rb index 6ab0a78f94..2e8ce80137 100644 --- a/app/helpers/relations_helper.rb +++ b/app/helpers/relations_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/removed_js_helpers_helper.rb b/app/helpers/removed_js_helpers_helper.rb index e2442321d4..77127c5904 100644 --- a/app/helpers/removed_js_helpers_helper.rb +++ b/app/helpers/removed_js_helpers_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 5891feddc7..e9e2cd79c7 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,7 +33,9 @@ module ReportsHelper def aggregate(data, criteria) data&.inject(0) do |sum, row| - match = criteria&.all? { |k, v| row[k].to_s == v.to_s || (k == 'closed' && row[k] == ActiveRecord::Type::Boolean.new.cast(v)) } + match = criteria&.all? do |k, v| + row[k].to_s == v.to_s || (k == 'closed' && row[k] == ActiveRecord::Type::Boolean.new.cast(v)) + end sum += row['total'].to_i if match diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 00624fc0e1..9bd9b57c27 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -63,7 +64,7 @@ module RepositoriesHelper end def render_changeset_changes - changes = @changeset.file_changes.limit(1000).order(Arel.sql('path')).map { |change| + changes = @changeset.file_changes.limit(1000).order(Arel.sql('path')).map do |change| case change.action when 'A' # Detects moved/copied files @@ -77,7 +78,7 @@ module RepositoriesHelper else change end - }.compact + end.compact tree = {} changes.each do |change| @@ -170,6 +171,7 @@ module RepositoriesHelper def to_utf8_for_repositories(str) return str if str.nil? + str = to_utf8_internal(str) if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') @@ -179,21 +181,21 @@ module RepositoriesHelper def to_utf8_internal(str) return str if str.nil? + if str.respond_to?(:force_encoding) str.force_encoding('ASCII-8BIT') end return str if str.empty? return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii + if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') end @encodings ||= Setting.repositories_encodings.split(',').map(&:strip) @encodings.each do |encoding| - begin - return str.to_s.encode('UTF-8', encoding) - rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError - # do nothing here and try the next encoding - end + return str.to_s.encode('UTF-8', encoding) + rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError + # do nothing here and try the next encoding end str = replace_invalid_utf8(str) end @@ -202,11 +204,12 @@ module RepositoriesHelper def replace_invalid_utf8(str) return str if str.nil? + if str.respond_to?(:force_encoding) str.force_encoding('UTF-8') if !str.valid_encoding? str = str.encode("US-ASCII", invalid: :replace, - undef: :replace, replace: '?').encode("UTF-8") + undef: :replace, replace: '?').encode("UTF-8") end else # removes invalid UTF8 sequences @@ -251,10 +254,9 @@ module RepositoriesHelper data: { url: url_for(controller: '/project_settings/repository', action: 'show', - id: @project.id), + id: @project.id) }, - disabled: (repository && !repository.new_record?) - ) + disabled: (repository && !repository.new_record?)) end def git_path_encoding_options(repository) @@ -265,7 +267,7 @@ module RepositoriesHelper ## # Determines whether the repository settings save button should be shown. # By default, it is not shown when repository exists and is managed. - def show_settings_save_button?(repository) + def show_settings_save_button?(_repository) @repository.nil? || @repository.new_record? || !@repository.managed? diff --git a/app/helpers/roles_helper.rb b/app/helpers/roles_helper.rb index defdb77781..1f75723c66 100644 --- a/app/helpers/roles_helper.rb +++ b/app/helpers/roles_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index bdcbf6db96..41d510e901 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,6 +31,7 @@ module SearchHelper def highlight_tokens(text, tokens) return text unless text && tokens && !tokens.empty? + re_tokens = tokens.map { |t| Regexp.escape(t) } regexp = Regexp.new "(#{re_tokens.join('|')})", Regexp::IGNORECASE result = '' @@ -80,7 +82,7 @@ module SearchHelper def with_notes_anchor(event, tokens) if has_tokens? last_journal(event).try(:notes), tokens - event.event_url.merge anchor: notes_anchor(last_journal event) + event.event_url.merge anchor: notes_anchor(last_journal(event)) else event.event_url end diff --git a/app/helpers/security_badge_helper.rb b/app/helpers/security_badge_helper.rb index f48fea12c9..915ee50c03 100644 --- a/app/helpers/security_badge_helper.rb +++ b/app/helpers/security_badge_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,7 +37,7 @@ module SecurityBadgeHelper version: OpenProject::VERSION.to_semver, db: ActiveRecord::Base.connection.adapter_name.downcase, lang: User.current.try(:language), - ee: EnterpriseToken.current.present?, + ee: EnterpriseToken.current.present? }.merge(args.symbolize_keys) uri.query = info.to_query uri.to_s diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index a64149228a..5504148d3d 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -108,7 +109,7 @@ module SettingsHelper unit_html = content_tag(:span, unit, class: 'form--field-affix', - :'aria-hidden' => true, + 'aria-hidden': true, id: unit_id) end diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rb index 64001c71e7..ec6f691de5 100644 --- a/app/helpers/sort_helper.rb +++ b/app/helpers/sort_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -130,12 +131,12 @@ module SortHelper .to_h end - def map_each - to_a.map { |criteria| yield criteria } + def map_each(&block) + to_a.map(&block) end def add!(key, asc) - @criteria.delete_if do |k, _o| k == key end + @criteria.delete_if { |k, _o| k == key } @criteria = [[key, asc]] + @criteria normalize! end @@ -162,10 +163,10 @@ module SortHelper def normalize! @criteria ||= [] - @criteria = @criteria.map { |s| + @criteria = @criteria.map do |s| s = s.to_a [s.first, !(s.last == false || s.last == 'desc')] - } + end if @available_criteria @criteria = @criteria.select { |k, _o| @available_criteria.has_key?(k) } @@ -340,13 +341,11 @@ module SortHelper end end - def within_sort_header_tag_hierarchy(options, classes) + def within_sort_header_tag_hierarchy(options, classes, &block) content_tag 'th', options do content_tag 'div', class: 'generic-table--sort-header-outer' do content_tag 'div', class: 'generic-table--sort-header' do - content_tag 'span', class: classes do - yield - end + content_tag 'span', class: classes, &block end end end diff --git a/app/helpers/static_links_helper.rb b/app/helpers/static_links_helper.rb index 9f904f7023..6b0e718def 100644 --- a/app/helpers/static_links_helper.rb +++ b/app/helpers/static_links_helper.rb @@ -29,7 +29,6 @@ #++ module StaticLinksHelper - ## # Create a static link to the given key entry def static_link_to(key) diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb index e3fd51a914..98969af8ed 100644 --- a/app/helpers/tabs_helper.rb +++ b/app/helpers/tabs_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/text_formatting_helper.rb b/app/helpers/text_formatting_helper.rb index f66be24f5a..276ac4bb36 100644 --- a/app/helpers/text_formatting_helper.rb +++ b/app/helpers/text_formatting_helper.rb @@ -43,7 +43,7 @@ module TextFormattingHelper end end - #TODO remove + # TODO remove def current_formatting_helper helper_class = OpenProject::TextFormatting::Formats.rich_helper helper_class.new(self) diff --git a/app/helpers/toolbar_helper.rb b/app/helpers/toolbar_helper.rb index 01854545f9..d1edfab07c 100644 --- a/app/helpers/toolbar_helper.rb +++ b/app/helpers/toolbar_helper.rb @@ -67,10 +67,9 @@ module ToolbarHelper end end - def dom_toolbar + def dom_toolbar(&block) return '' unless block_given? - content_tag :ul, class: 'toolbar-items' do - yield - end + + content_tag :ul, class: 'toolbar-items', &block end end diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rb index afbb1f182d..333184d80c 100644 --- a/app/helpers/types_helper.rb +++ b/app/helpers/types_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/user_consent_helper.rb b/app/helpers/user_consent_helper.rb index 6a9e5b351c..1e274bd1cf 100644 --- a/app/helpers/user_consent_helper.rb +++ b/app/helpers/user_consent_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -45,7 +46,7 @@ module ::UserConsentHelper # `I18n.locale` is set for each request individually depending # among other things on the user's Accept-Language headers. # @return [String] Instructions in the respective language. - def user_consent_instructions(user, locale: I18n.locale) + def user_consent_instructions(_user, locale: I18n.locale) all = Setting.consent_info all.fetch(locale) { all.values.first } diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 5fb3f9908d..29faa65813 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -77,13 +78,13 @@ module UsersHelper STATUS_CHANGE_ACTIONS = { # status, blocked => [[button_title, button_name], ...] - [:active, false] => [[:lock, 'lock']], - [:active, true] => [[:reset_failed_logins, 'unlock'], - [:lock, 'lock']], - [:locked, false] => [[:unlock, 'unlock']], - [:locked, true] => [[:unlock_and_reset_failed_logins, 'unlock']], + [:active, false] => [[:lock, 'lock']], + [:active, true] => [[:reset_failed_logins, 'unlock'], + [:lock, 'lock']], + [:locked, false] => [[:unlock, 'unlock']], + [:locked, true] => [[:unlock_and_reset_failed_logins, 'unlock']], [:registered, false] => [[:activate, 'activate']], - [:registered, true] => [[:activate_and_reset_failed_logins, 'activate']], + [:registered, true] => [[:activate_and_reset_failed_logins, 'activate']] } # Create buttons to lock/unlock a user and reset failed logins diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb index 33164433d5..63cf37dafe 100644 --- a/app/helpers/watchers_helper.rb +++ b/app/helpers/watchers_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -49,7 +50,7 @@ module WatchersHelper label = watched ? I18n.t(:button_unwatch) : I18n.t(:button_watch) - link_to(content_tag(:i,'', class: watched ? 'button--icon icon-watched' : ' button--icon icon-unwatched') + ' ' + + link_to(content_tag(:i, '', class: watched ? 'button--icon icon-watched' : ' button--icon icon-unwatched') + ' ' + content_tag(:span, label, class: 'button--text'), path, html_options.merge(method: method)) end end diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb index 7cac2ccbfa..8829a4f29b 100644 --- a/app/helpers/wiki_helper.rb +++ b/app/helpers/wiki_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/helpers/work_packages_helper.rb b/app/helpers/work_packages_helper.rb index 3e2fddd4fa..a6cc0782db 100644 --- a/app/helpers/work_packages_helper.rb +++ b/app/helpers/work_packages_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -70,7 +71,7 @@ module WorkPackagesHelper # Prefix part - parts[:prefix] << "#{package.project}" if options[:project] + parts[:prefix] << package.project.to_s if options[:project] # Link part @@ -80,7 +81,7 @@ module WorkPackagesHelper parts[:link] << "##{h(package.id)}" if options[:id] - parts[:link] << "#{h(package.status)}" if options[:id] && options[:status] && package.status_id + parts[:link] << h(package.status).to_s if options[:id] && options[:status] && package.status_id # Hidden link part @@ -148,7 +149,7 @@ module WorkPackagesHelper [[prefix, html_link].reject(&:empty?).join(' - '), suffix].reject(&:empty?).join(': ') - end.html_safe + end.html_safe end def work_package_list(work_packages, &_block) @@ -196,13 +197,13 @@ module WorkPackagesHelper ret += content_tag(:p, I18n.t(:text_destroy_with_associated), class: 'bold') - ret += content_tag(:ul) { + ret += content_tag(:ul) do associated.inject(''.html_safe) do |list, associated_class| list += content_tag(:li, associated_class.model_name.human, class: 'decorated') list end - } + end ret end @@ -215,6 +216,7 @@ module WorkPackagesHelper def last_work_package_note(work_package) note_journals = work_package.journals.select(&:notes?) return t(:text_no_notes) if note_journals.empty? + note_journals.last.notes end @@ -246,12 +248,12 @@ module WorkPackagesHelper def info_user_attributes(work_package) responsible = if work_package.responsible_id.present? "#{WorkPackage.human_attribute_name(:responsible)}: " + - "#{h(work_package.responsible.name)}" + h(work_package.responsible.name).to_s end assignee = if work_package.assigned_to_id.present? "#{WorkPackage.human_attribute_name(:assigned_to)}: " + - "#{h(work_package.assigned_to.name)}" + h(work_package.assigned_to.name).to_s end [responsible, assignee].compact.join('
').html_safe diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb index 2ba532321d..323400b493 100644 --- a/app/mailers/base_mailer.rb +++ b/app/mailers/base_mailer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -71,8 +72,8 @@ class BaseMailer < ActionMailer::Base end def remove_self_notifications(message, author) - if author.pref && author.pref[:no_self_notified] - message.to = message.to.reject { |address| address == author.mail } if message.to.present? + if author.pref && author.pref[:no_self_notified] && message.to.present? + message.to = message.to.reject { |address| address == author.mail } end end @@ -84,7 +85,7 @@ class BaseMailer < ActionMailer::Base if OpenProject::Configuration.rails_relative_url_root.blank? Setting.host_name else - Setting.host_name.to_s.gsub(%r{\/.*\z}, '') + Setting.host_name.to_s.gsub(%r{/.*\z}, '') end end diff --git a/app/mailers/project_mailer.rb b/app/mailers/project_mailer.rb index 2d11d99c64..663b3a150e 100644 --- a/app/mailers/project_mailer.rb +++ b/app/mailers/project_mailer.rb @@ -29,7 +29,6 @@ #++ class ProjectMailer < BaseMailer - def delete_project_completed(project, user:) open_project_headers Project: project.identifier, Author: user.login @@ -59,7 +58,7 @@ class ProjectMailer < BaseMailer @errors = errors open_project_headers 'Source-Project' => source_project.identifier, - 'Author' => user.login + 'Author' => user.login message_id source_project, user @@ -77,7 +76,7 @@ class ProjectMailer < BaseMailer open_project_headers 'Source-Project' => source_project.identifier, 'Target-Project' => target_project.identifier, - 'Author' => user.login + 'Author' => user.login message_id target_project, user diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 26e9bcaf07..4ee2055b36 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,6 @@ #++ class UserMailer < BaseMailer - def test_mail(user) @welcome_url = url_for(controller: '/homescreen') @@ -95,8 +95,8 @@ class UserMailer < BaseMailer @token = token @reset_password_url = url_for(controller: '/account', - action: :lost_password, - token: @token.value) + action: :lost_password, + token: @token.value) open_project_headers 'Type' => 'Account' @@ -113,7 +113,7 @@ class UserMailer < BaseMailer @errors = errors open_project_headers 'Source-Project' => source_project.identifier, - 'Author' => user.login + 'Author' => user.login message_id source_project, user @@ -131,7 +131,7 @@ class UserMailer < BaseMailer open_project_headers 'Source-Project' => source_project.identifier, 'Target-Project' => target_project.identifier, - 'Author' => user.login + 'Author' => user.login message_id target_project, user @@ -163,8 +163,8 @@ class UserMailer < BaseMailer @user = token.user @token = token @activation_url = url_for(controller: '/account', - action: :activate, - token: @token.value) + action: :activate, + token: @token.value) open_project_headers 'Type' => 'Account' @@ -194,9 +194,9 @@ class UserMailer < BaseMailer def wiki_content_added(user, wiki_content, author) @wiki_content = wiki_content - open_project_headers 'Project' => @wiki_content.project.identifier, + open_project_headers 'Project' => @wiki_content.project.identifier, 'Wiki-Page-Id' => @wiki_content.page.id, - 'Type' => 'Wiki' + 'Type' => 'Wiki' message_id @wiki_content, user @@ -209,14 +209,14 @@ class UserMailer < BaseMailer def wiki_content_updated(user, wiki_content, author) @wiki_content = wiki_content @wiki_diff_url = url_for(controller: '/wiki', - action: :diff, + action: :diff, project_id: wiki_content.project, - id: wiki_content.page.slug, - version: wiki_content.version) + id: wiki_content.page.slug, + version: wiki_content.version) - open_project_headers 'Project' => @wiki_content.project.identifier, + open_project_headers 'Project' => @wiki_content.project.identifier, 'Wiki-Page-Id' => @wiki_content.page.id, - 'Type' => 'Wiki' + 'Type' => 'Wiki' message_id @wiki_content, user @@ -230,9 +230,9 @@ class UserMailer < BaseMailer @message = message @message_url = topic_url(@message.root, r: @message.id, anchor: "message-#{@message.id}") - open_project_headers 'Project' => @message.project.identifier, + open_project_headers 'Project' => @message.project.identifier, 'Wiki-Page-Id' => @message.parent_id || @message.id, - 'Type' => 'Forum' + 'Type' => 'Forum' message_id @message, user references @message.parent, user if @message.parent @@ -269,9 +269,9 @@ class UserMailer < BaseMailer def account_activation_requested(admin, user) @user = user @activation_url = url_for(controller: '/users', - action: :index, - status: 'registered', - sort: 'created_at:desc') + action: :index, + status: 'registered', + sort: 'created_at:desc') open_project_headers 'Type' => 'Account' @@ -344,10 +344,10 @@ class UserMailer < BaseMailer end def set_work_package_headers(work_package) - open_project_headers 'Project' => work_package.project.identifier, - 'Issue-Id' => work_package.id, - 'Issue-Author' => work_package.author.login, - 'Type' => 'WorkPackage' + open_project_headers 'Project' => work_package.project.identifier, + 'Issue-Id' => work_package.id, + 'Issue-Author' => work_package.author.login, + 'Type' => 'WorkPackage' if work_package.assigned_to open_project_headers 'Issue-Assignee' => work_package.assigned_to.login @@ -370,11 +370,11 @@ class DefaultHeadersInterceptor def self.default_headers { - 'X-Mailer' => 'OpenProject', + 'X-Mailer' => 'OpenProject', 'X-OpenProject-Host' => Setting.host_name, 'X-OpenProject-Site' => Setting.app_title, - 'Precedence' => 'bulk', - 'Auto-Submitted' => 'auto-generated' + 'Precedence' => 'bulk', + 'Auto-Submitted' => 'auto-generated' } end end diff --git a/app/models/activities/fetcher.rb b/app/models/activities/fetcher.rb index 6d7079684f..508ad7ddc2 100644 --- a/app/models/activities/fetcher.rb +++ b/app/models/activities/fetcher.rb @@ -49,20 +49,20 @@ module Activities # Returns an array of available event types def event_types @event_types ||= begin - if @project - OpenProject::Activity.available_event_types.select do |o| - @project.self_and_descendants.detect do |_p| - permissions = constantized_providers(o).map do |p| - p.activity_provider_options[:permission] - end.compact - - permissions.all? { |p| @user.allowed_to?(p, @project) } - end - end - else - OpenProject::Activity.available_event_types - end - end + if @project + OpenProject::Activity.available_event_types.select do |o| + @project.self_and_descendants.detect do |_p| + permissions = constantized_providers(o).map do |p| + p.activity_provider_options[:permission] + end.compact + + permissions.all? { |p| @user.allowed_to?(p, @project) } + end + end + else + OpenProject::Activity.available_event_types + end + end end # Returns an array of events for the given date range diff --git a/app/models/activities/news_activity_provider.rb b/app/models/activities/news_activity_provider.rb index 3847ce89bf..1d68a4e60a 100644 --- a/app/models/activities/news_activity_provider.rb +++ b/app/models/activities/news_activity_provider.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/activities/work_package_activity_provider.rb b/app/models/activities/work_package_activity_provider.rb index 8d9a021447..c5c530a750 100644 --- a/app/models/activities/work_package_activity_provider.rb +++ b/app/models/activities/work_package_activity_provider.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -48,7 +49,7 @@ class Activities::WorkPackageActivityProvider < Activities::BaseActivityProvider end def self.work_package_title(id, subject, type_name, status_name, is_standard) - title = "#{is_standard ? '' : "#{type_name}"} ##{id}: #{subject}" + title = "#{is_standard ? '' : type_name.to_s} ##{id}: #{subject}" title << " (#{status_name})" unless status_name.blank? end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 5eb43230aa..b2b8189158 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -189,7 +189,7 @@ class Attachment < ApplicationRecord content_type || fallback end - def copy(&block) + def copy attachment = dup attachment.file = diskfile diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb index e168d4066e..cb28024947 100644 --- a/app/models/auth_source.rb +++ b/app/models/auth_source.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -79,7 +80,7 @@ class AuthSource < ApplicationRecord begin Rails.logger.debug { "Authenticating '#{login}' against '#{source.name}'" } attrs = source.authenticate(login, password) - rescue => e + rescue StandardError => e Rails.logger.error "Error during authentication: #{e.message}" attrs = nil end @@ -93,7 +94,7 @@ class AuthSource < ApplicationRecord begin Rails.logger.debug { "Looking up '#{login}' in '#{source.name}'" } attrs = source.find_user login - rescue => e + rescue StandardError => e Rails.logger.error "Error during authentication: #{e.message}" attrs = nil end diff --git a/app/models/category.rb b/app/models/category.rb index 61660d6c0f..071d88edff 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -38,8 +39,8 @@ class Category < ApplicationRecord # validates that assignee is member of the issue category's project validates_each :assigned_to_id do |record, attr, value| - if value # allow nil - record.errors.add(attr, I18n.t(:error_must_be_project_member)) unless record.project.principals.map(&:id).include? value + if value && !(record.project.principals.map(&:id).include? value) # allow nil + record.errors.add(attr, I18n.t(:error_must_be_project_member)) end end @@ -54,8 +55,8 @@ class Category < ApplicationRecord destroy_without_reassign end - def <=>(category) - name <=> category.name + def <=>(other) + name <=> other.name end def to_s; name end diff --git a/app/models/change.rb b/app/models/change.rb index c976e319ae..9752b2aa9e 100644 --- a/app/models/change.rb +++ b/app/models/change.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 3c1cb70d23..e751ec81b1 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,8 +37,8 @@ class Changeset < ApplicationRecord acts_as_journalized timestamp: :committed_on acts_as_event title: Proc.new { |o| - "#{I18n.t(:label_revision)} #{o.format_identifier}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments)) - }, + "#{I18n.t(:label_revision)} #{o.format_identifier}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments)) + }, description: :long_comments, datetime: :committed_on, url: Proc.new { |o| @@ -60,7 +61,7 @@ class Changeset < ApplicationRecord validates_uniqueness_of :revision, scope: :repository_id validates_uniqueness_of :scmid, scope: :repository_id, allow_nil: true - scope :visible, -> (*args) { + scope :visible, ->(*args) { includes(repository: :project) .references(:projects) .merge(Project.allowed_to(args.first || User.current, :view_changesets)) @@ -128,12 +129,13 @@ class Changeset < ApplicationRecord | (\d+):(\d+) | - (\d+([\.,]\d+)?)h? + (\d+([.,]\d+)?)h? ) /x def scan_comment_for_work_package_ids return if comments.blank? + # keywords used to reference work packages ref_keywords = Setting.commit_ref_keywords.downcase.split(',').map(&:strip) ref_keywords_any = ref_keywords.delete('*') @@ -144,7 +146,7 @@ class Changeset < ApplicationRecord referenced_work_packages = [] - comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match| + comments.scan(/([\s(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match| action = match[2] refs = match[3] next unless action.present? || ref_keywords_any @@ -241,8 +243,8 @@ class Changeset < ApplicationRecord end Redmine::Hook.call_hook(:model_changeset_scan_commit_for_issue_ids_pre_issue_update, changeset: self, issue: work_package) - unless work_package.save(validate: false) - logger.warn("Work package ##{work_package.id} could not be saved by changeset #{id}: #{work_package.errors.full_messages}") if logger + if !work_package.save(validate: false) && logger + logger.warn("Work package ##{work_package.id} could not be saved by changeset #{id}: #{work_package.errors.full_messages}") end work_package @@ -267,15 +269,11 @@ class Changeset < ApplicationRecord [@short_comments, @long_comments] end - public - # Strips and reencodes a commit log before insertion into the database def self.normalize_comments(str, encoding) Changeset.to_utf8(str.to_s.strip, encoding) end - private - def sanitize_attributes self.committer = self.class.to_utf8(committer, repository.repo_log_encoding) self.comments = self.class.normalize_comments(comments, repository.repo_log_encoding) @@ -289,6 +287,7 @@ class Changeset < ApplicationRecord # TODO: refactor to a standard helper method def self.to_utf8(str, encoding) return str if str.nil? + str.force_encoding('ASCII-8BIT') if str.respond_to?(:force_encoding) if str.empty? str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) @@ -316,7 +315,7 @@ class Changeset < ApplicationRecord txtar += $!.success str = '?' + $!.failed[1, $!.failed.length] retry - rescue + rescue StandardError txtar += $!.success end str = txtar diff --git a/app/models/color.rb b/app/models/color.rb index ef82fc55ae..aedeb205fe 100644 --- a/app/models/color.rb +++ b/app/models/color.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,9 +31,9 @@ class Color < ApplicationRecord self.table_name = 'colors' - has_many :planning_element_types, class_name: 'Type', + has_many :planning_element_types, class_name: 'Type', foreign_key: 'color_id', - dependent: :nullify + dependent: :nullify before_validation :normalize_hexcode @@ -83,7 +84,7 @@ class Color < ApplicationRecord # Same as in frontend color-contrast.functions.ts def brightness_yiq r, g, b = rgb_colors - ((r * 299) + (g * 587) + (b * 114)) / 1000; + ((r * 299) + (g * 587) + (b * 114)) / 1000 end ## diff --git a/app/models/comment.rb b/app/models/comment.rb index 8e66925a16..bd8207d079 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/custom_action.rb b/app/models/custom_action.rb index 384d953f90..c872891d33 100644 --- a/app/models/custom_action.rb +++ b/app/models/custom_action.rb @@ -119,7 +119,7 @@ class CustomAction < ApplicationRecord def persist_conditions available_conditions.map do |condition_class| - condition = conditions.detect { |c| c.class == condition_class } + condition = conditions.detect { |c| c.instance_of?(condition_class) } condition_class.setter(self, condition) end diff --git a/app/models/custom_actions/actions/serializer.rb b/app/models/custom_actions/actions/serializer.rb index 30d779571d..c91a037fd2 100644 --- a/app/models/custom_actions/actions/serializer.rb +++ b/app/models/custom_actions/actions/serializer.rb @@ -31,6 +31,7 @@ class CustomActions::Actions::Serializer def self.load(value) return [] unless value + YAML .safe_load(value, [Symbol]) .map do |key, values| diff --git a/app/models/custom_actions/conditions/base.rb b/app/models/custom_actions/conditions/base.rb index 4e6c88849c..f4feccbcd1 100644 --- a/app/models/custom_actions/conditions/base.rb +++ b/app/models/custom_actions/conditions/base.rb @@ -30,6 +30,7 @@ class CustomActions::Conditions::Base attr_reader :values + prepend CustomActions::ValuesToInteger include CustomActions::ValidateAllowedValue diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 38be53d224..db0430ead3 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -188,7 +188,7 @@ class CustomField < ApplicationRecord when 'string', 'text', 'list' casted = value when 'date' - casted = begin; value.to_date; rescue; nil end + casted = begin; value.to_date; rescue StandardError; nil end when 'bool' casted = ActiveRecord::Type::Boolean.new.cast(value) when 'int' @@ -202,11 +202,11 @@ class CustomField < ApplicationRecord casted end - def <=>(field) + def <=>(other) if type == 'WorkPackageCustomField' - name.downcase <=> field.name.downcase + name.downcase <=> other.name.downcase else - position <=> field.position + position <=> other.position end end @@ -214,7 +214,7 @@ class CustomField < ApplicationRecord name =~ /\A(.+)CustomField\z/ begin $1.constantize - rescue + rescue StandardError nil end end diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rb index f00fecfd99..ba941052cc 100644 --- a/app/models/custom_field/order_statements.rb +++ b/app/models/custom_field/order_statements.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -155,8 +156,6 @@ module CustomField::OrderStatements SQL end - private - def cv_sort_only_custom_field_condition_sql <<-SQL cv_sort.customized_type='#{self.class.customized_class.name}' diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb index 76d5769fea..f75b15354a 100644 --- a/app/models/custom_value.rb +++ b/app/models/custom_value.rb @@ -65,8 +65,8 @@ class CustomValue < ApplicationRecord end def validate_format_of_value - if value.present? && custom_field.has_regexp? - errors.add(:value, :invalid) unless value =~ Regexp.new(custom_field.regexp) + if value.present? && custom_field.has_regexp? && !(value =~ Regexp.new(custom_field.regexp)) + errors.add(:value, :invalid) end rescue RegexpError => e errors.add(:base, :regex_invalid) diff --git a/app/models/custom_value/date_strategy.rb b/app/models/custom_value/date_strategy.rb index 30fecb675b..3a817f5be8 100644 --- a/app/models/custom_value/date_strategy.rb +++ b/app/models/custom_value/date_strategy.rb @@ -39,7 +39,7 @@ class CustomValue::DateStrategy < CustomValue::FormatStrategy def formatted_value format_date(value.to_date) - rescue + rescue StandardError value.to_s end @@ -49,7 +49,7 @@ class CustomValue::DateStrategy < CustomValue::FormatStrategy begin Date.iso8601(value) nil - rescue + rescue StandardError :not_a_date end end diff --git a/app/models/custom_value/empty_strategy.rb b/app/models/custom_value/empty_strategy.rb index a89b75d930..5f4b971f01 100644 --- a/app/models/custom_value/empty_strategy.rb +++ b/app/models/custom_value/empty_strategy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/custom_value/float_strategy.rb b/app/models/custom_value/float_strategy.rb index 7a721ad6ff..4901fa286a 100644 --- a/app/models/custom_value/float_strategy.rb +++ b/app/models/custom_value/float_strategy.rb @@ -44,7 +44,7 @@ class CustomValue::FloatStrategy < CustomValue::FormatStrategy def validate_type_of_value Kernel.Float(value) nil - rescue + rescue StandardError :not_a_number end end diff --git a/app/models/custom_value/format_strategy.rb b/app/models/custom_value/format_strategy.rb index 370344c30c..7147709111 100644 --- a/app/models/custom_value/format_strategy.rb +++ b/app/models/custom_value/format_strategy.rb @@ -30,6 +30,7 @@ class CustomValue::FormatStrategy attr_reader :custom_value + delegate :custom_field, :value, to: :custom_value def initialize(custom_value) diff --git a/app/models/custom_value/formattable_strategy.rb b/app/models/custom_value/formattable_strategy.rb index 89ea2845bc..a60e53efa4 100644 --- a/app/models/custom_value/formattable_strategy.rb +++ b/app/models/custom_value/formattable_strategy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,6 @@ class CustomValue::FormattableStrategy < CustomValue::FormatStrategy - def formatted_value OpenProject::TextFormatting::Renderer.format_text value end diff --git a/app/models/custom_value/int_strategy.rb b/app/models/custom_value/int_strategy.rb index 357128e070..11d9312332 100644 --- a/app/models/custom_value/int_strategy.rb +++ b/app/models/custom_value/int_strategy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,7 +41,7 @@ class CustomValue::IntStrategy < CustomValue::FormatStrategy begin Kernel.Integer(value) nil - rescue + rescue StandardError :not_an_integer end end diff --git a/app/models/custom_value/string_strategy.rb b/app/models/custom_value/string_strategy.rb index 2f1e81f26b..e7bf0885c7 100644 --- a/app/models/custom_value/string_strategy.rb +++ b/app/models/custom_value/string_strategy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/design_color.rb b/app/models/design_color.rb index b8221d0afa..be2d78a3aa 100644 --- a/app/models/design_color.rb +++ b/app/models/design_color.rb @@ -47,7 +47,7 @@ class DesignColor < ApplicationRecord class << self def setables - overwritten_values = self.overwritten + overwritten_values = overwritten OpenProject::CustomStyles::Design.customizable_variables.map do |varname| overwritten_value = overwritten_values.detect { |var| var.variable == varname } overwritten_value || new(variable: varname) diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb index 0bec0a0dc4..83033e9d35 100644 --- a/app/models/enabled_module.rb +++ b/app/models/enabled_module.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rb index 0f056aac96..09b4ece4b9 100644 --- a/app/models/enterprise_token.rb +++ b/app/models/enterprise_token.rb @@ -34,7 +34,7 @@ class EnterpriseToken < ApplicationRecord end def table_exists? - connection.data_source_exists? self.table_name + connection.data_source_exists? table_name end def allows_to?(action) @@ -102,8 +102,8 @@ class EnterpriseToken < ApplicationRecord def load_token! @token_object = OpenProject::Token.import(encoded_token) - rescue OpenProject::Token::ImportError => error - Rails.logger.error "Failed to load EE token: #{error}" + rescue OpenProject::Token::ImportError => e + Rails.logger.error "Failed to load EE token: #{e}" nil end diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index f7c8dfad78..dc9276457d 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -125,8 +125,8 @@ class Enumeration < ApplicationRecord destroy_without_reassign end - def <=>(enumeration) - position <=> enumeration.position + def <=>(other) + position <=> other.position end def to_s; name end @@ -144,8 +144,8 @@ class Enumeration < ApplicationRecord def self.same_custom_values?(new, previous) previous.custom_field_values.each do |custom_value| if new && - new['custom_field_values'] && - custom_value.value != new['custom_field_values'][custom_value.custom_field_id.to_s] + new['custom_field_values'] && + custom_value.value != new['custom_field_values'][custom_value.custom_field_id.to_s] return false end end diff --git a/app/models/forum.rb b/app/models/forum.rb index 85f4b2eef2..2aaaaac181 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/group.rb b/app/models/group.rb index cadb0257b3..f94ed3f8ed 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,7 @@ class Group < Principal has_and_belongs_to_many :users, - join_table: "#{table_name_prefix}group_users#{table_name_suffix}", + join_table: "#{table_name_prefix}group_users#{table_name_suffix}", before_add: :fail_add, after_remove: :user_removed @@ -106,7 +107,7 @@ class Group < Principal end def uniqueness_of_groupname - groups_with_name = Group.where('lastname = ? AND id <> ?', groupname, id ? id : 0).count + groups_with_name = Group.where('lastname = ? AND id <> ?', groupname, id || 0).count if groups_with_name > 0 errors.add :groupname, :taken end diff --git a/app/models/group_custom_field.rb b/app/models/group_custom_field.rb index 5c7a00baec..be331efad7 100644 --- a/app/models/group_custom_field.rb +++ b/app/models/group_custom_field.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/group_user.rb b/app/models/group_user.rb index 42798c8f8e..80f6d55aff 100644 --- a/app/models/group_user.rb +++ b/app/models/group_user.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/issue_priority.rb b/app/models/issue_priority.rb index 6e5676562b..0db50d715f 100644 --- a/app/models/issue_priority.rb +++ b/app/models/issue_priority.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/issue_priority_custom_field.rb b/app/models/issue_priority_custom_field.rb index f164f3ff80..a4ca8e88f4 100644 --- a/app/models/issue_priority_custom_field.rb +++ b/app/models/issue_priority_custom_field.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/journal.rb b/app/models/journal.rb index b0f78fb70f..23368eb948 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -41,7 +42,7 @@ class Journal < ApplicationRecord register_journal_formatter :schedule_manually, OpenProject::JournalFormatter::ScheduleManually # Make sure each journaled model instance only has unique version ids - validates_uniqueness_of :version, scope: [:journable_id, :journable_type] + validates_uniqueness_of :version, scope: %i[journable_id journable_type] belongs_to :user belongs_to :journable, polymorphic: true diff --git a/app/models/journal/attachable_journal.rb b/app/models/journal/attachable_journal.rb index e9c5c127fc..defb5b0d8b 100644 --- a/app/models/journal/attachable_journal.rb +++ b/app/models/journal/attachable_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/journal/changeset_journal.rb b/app/models/journal/changeset_journal.rb index c0ca6c219e..0a3384004a 100644 --- a/app/models/journal/changeset_journal.rb +++ b/app/models/journal/changeset_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/journal/message_journal.rb b/app/models/journal/message_journal.rb index 4b9ca44c03..3f3f479ba4 100644 --- a/app/models/journal/message_journal.rb +++ b/app/models/journal/message_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/journal/news_journal.rb b/app/models/journal/news_journal.rb index fb2d2cc17a..f50d6b817b 100644 --- a/app/models/journal/news_journal.rb +++ b/app/models/journal/news_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/journal/work_package_journal.rb b/app/models/journal/work_package_journal.rb index eed763daab..f4c3f6a39a 100644 --- a/app/models/journal/work_package_journal.rb +++ b/app/models/journal/work_package_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/ldap_auth_source.rb b/app/models/ldap_auth_source.rb index 87f7e4a8ff..0a5429cf77 100644 --- a/app/models/ldap_auth_source.rb +++ b/app/models/ldap_auth_source.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -46,26 +47,28 @@ class LdapAuthSource < AuthSource def authenticate(login, password) return nil if login.blank? || password.blank? + attrs = get_user_dn(login) if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password) Rails.logger.debug { "Authentication successful for '#{login}'" } - return attrs.except(:dn) + attrs.except(:dn) end - rescue Net::LDAP::Error => error - raise 'LdapError: ' + error.message + rescue Net::LDAP::Error => e + raise 'LdapError: ' + e.message end def find_user(login) return nil if login.blank? + attrs = get_user_dn(login) if attrs && attrs[:dn] Rails.logger.debug { "Lookup successful for '#{login}'" } - return attrs.except(:dn) + attrs.except(:dn) end - rescue Net::LDAP::Error => error - raise 'LdapError: ' + error.message + rescue Net::LDAP::Error => e + raise 'LdapError: ' + e.message end # Open and return a system connection @@ -78,8 +81,8 @@ class LdapAuthSource < AuthSource unless authenticate_dn(account, account_password) raise I18n.t('auth_source.ldap_error', error_message: I18n.t('auth_source.ldap_auth_failed')) end - rescue Net::LDAP::Error => text - raise I18n.t('auth_source.ldap_error', error_message: text.to_s) + rescue Net::LDAP::Error => e + raise I18n.t('auth_source.ldap_error', error_message: e.to_s) end def auth_method_name @@ -118,7 +121,7 @@ class LdapAuthSource < AuthSource private def strip_ldap_attributes - [:attr_login, :attr_firstname, :attr_lastname, :attr_mail, :attr_admin].each do |attr| + %i[attr_login attr_firstname attr_lastname attr_mail attr_admin].each do |attr| write_attribute(attr, read_attribute(attr).strip) unless read_attribute(attr).nil? end end @@ -127,9 +130,11 @@ class LdapAuthSource < AuthSource options = { host: host, port: port, force_no_page: true, - encryption: ldap_encryption - } - options.merge!(auth: { method: :simple, username: ldap_user, password: ldap_password }) unless ldap_user.blank? && ldap_password.blank? + encryption: ldap_encryption } + unless ldap_user.blank? && ldap_password.blank? + options.merge!(auth: { method: :simple, username: ldap_user, + password: ldap_password }) + end Net::LDAP.new options end @@ -156,17 +161,17 @@ class LdapAuthSource < AuthSource attrs = {} - Rails.logger.debug { - "LDAP initializing search (BASE=#{base_dn}), (FILTER=#{(default_filter & login_filter).to_s})" - } + Rails.logger.debug do + "LDAP initializing search (BASE=#{base_dn}), (FILTER=#{default_filter & login_filter})" + end ldap_con.search(base: base_dn, filter: default_filter & login_filter, attributes: search_attributes) do |entry| - if onthefly_register? - attrs = get_user_attributes_from_ldap_entry(entry) - else - attrs = { dn: entry.dn } - end + attrs = if onthefly_register? + get_user_attributes_from_ldap_entry(entry) + else + { dn: entry.dn } + end Rails.logger.debug { "DN found for #{login}: #{attrs[:dn]}" } end @@ -188,8 +193,6 @@ class LdapAuthSource < AuthSource Net::LDAP::Filter.from_rfc2254(filter_string) if filter_string.present? end - private - def validate_filter_string parsed_filter_string rescue Net::LDAP::FilterSyntaxInvalidError diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 537e538d12..fe587dbd52 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,6 +33,7 @@ class MailHandler < ActionMailer::Base include Redmine::I18n class UnauthorizedAction < StandardError; end + class MissingInformation < StandardError; end attr_reader :email, :user, :options @@ -130,7 +132,7 @@ class MailHandler < ActionMailer::Base private - MESSAGE_ID_RE = %r{^(member) - a = roles.sort.first - b = member.roles.sort.first - a == b ? (principal <=> member.principal) : (a <=> b) + def <=>(other) + a = roles.min + b = other.roles.min + a == b ? (principal <=> other.principal) : (a <=> b) end def deletable? diff --git a/app/models/member_role.rb b/app/models/member_role.rb index adb4714bb8..051fa1c396 100644 --- a/app/models/member_role.rb +++ b/app/models/member_role.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -52,11 +53,11 @@ class MemberRole < ApplicationRecord # and prevents or at least discourages working on persistence objects from controllers # or unrelated business logic. def destroy(*args) - unless caller[2] =~ /has_many_association\.rb:[0-9]+:in `delete_records'/ - raise 'MemberRole.destroy called from method other than HasManyAssociation.delete_records' + - "\n on #{inspect}\n from #{caller.first} / #{caller[6]}" - else + if caller[2] =~ /has_many_association\.rb:[0-9]+:in `delete_records'/ super + else + raise 'MemberRole.destroy called from method other than HasManyAssociation.delete_records' + + "\n on #{inspect}\n from #{caller.first} / #{caller[6]}" end end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 109eab4dc5..cec33c3bac 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/menu_items/query_menu_item.rb b/app/models/menu_items/query_menu_item.rb index fcfe531c76..7a87fd9df8 100644 --- a/app/models/menu_items/query_menu_item.rb +++ b/app/models/menu_items/query_menu_item.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/menu_items/wiki_menu_item.rb b/app/models/menu_items/wiki_menu_item.rb index c574717d7b..6ad764dc46 100644 --- a/app/models/menu_items/wiki_menu_item.rb +++ b/app/models/menu_items/wiki_menu_item.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/message.rb b/app/models/message.rb index 8dabb7fbcf..1af15f20dd 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -119,11 +120,13 @@ class Message < ApplicationRecord end def editable_by?(usr) - usr && usr.logged? && (usr.allowed_to?(:edit_messages, project) || (author == usr && usr.allowed_to?(:edit_own_messages, project))) + usr && usr.logged? && (usr.allowed_to?(:edit_messages, + project) || (author == usr && usr.allowed_to?(:edit_own_messages, project))) end def destroyable_by?(usr) - usr && usr.logged? && (usr.allowed_to?(:delete_messages, project) || (author == usr && usr.allowed_to?(:delete_own_messages, project))) + usr && usr.logged? && (usr.allowed_to?(:delete_messages, + project) || (author == usr && usr.allowed_to?(:delete_own_messages, project))) end private diff --git a/app/models/news.rb b/app/models/news.rb index e82cea29d5..c44cfcdfab 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb index c571e474a5..7d16e70ac3 100644 --- a/app/models/permitted_params.rb +++ b/app/models/permitted_params.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -109,9 +110,7 @@ class PermittedParams def group permitted_params = params.require(:group).permit(*self.class.permitted_attributes[:group]) - permitted_params = permitted_params.merge(custom_field_values(:group)) - - permitted_params + permitted_params.merge(custom_field_values(:group)) end def group_membership @@ -124,9 +123,7 @@ class PermittedParams permitted_params = params.require(:work_package).permit(*permitted) - permitted_params = permitted_params.merge(custom_field_values(:work_package)) - - permitted_params + permitted_params.merge(custom_field_values(:work_package)) end def member @@ -183,9 +180,7 @@ class PermittedParams def user(additional_params = []) permitted_params = params.require(:user).permit(*self.class.permitted_attributes[:user] + additional_params) - permitted_params = permitted_params.merge(custom_field_values(:user)) - - permitted_params + permitted_params.merge(custom_field_values(:user)) end def my_account_settings @@ -196,9 +191,7 @@ class PermittedParams permitted_params = params .require(:user) .permit(:login, :firstname, :lastname, :mail, :language) - permitted_params = permitted_params.merge(custom_field_values(:user)) - - permitted_params + permitted_params.merge(custom_field_values(:user)) end def user_create_as_admin(external_authentication, @@ -247,9 +240,7 @@ class PermittedParams def wiki_page permitted = permitted_attributes(:wiki_page) - permitted_params = params.require(:content).require(:page).permit(*permitted) - - permitted_params + params.require(:content).require(:page).permit(*permitted) end def wiki_content @@ -401,13 +392,13 @@ class PermittedParams def permitted_attributes(key, additions = {}) merged_args = { params: params, current_user: current_user }.merge(additions) - self.class.permitted_attributes[key].map { |permission| + self.class.permitted_attributes[key].map do |permission| if permission.respond_to?(:call) permission.call(merged_args) else permission end - }.compact + end.compact end def self.permitted_attributes @@ -467,7 +458,7 @@ class PermittedParams :multi_value, :content_right_to_left, { custom_options_attributes: %i(id value default_value position) }, - type_ids: [] + { type_ids: [] } ], enumeration: %i( active @@ -481,18 +472,18 @@ class PermittedParams ], membership: [ :project_id, - role_ids: [] + { role_ids: [] } ], group_membership: [ :membership_id, - membership: [ + { membership: [ :project_id, - role_ids: [] + { role_ids: [] } ], - new_membership: [ - :project_id, - role_ids: [] - ] + new_membership: [ + :project_id, + { role_ids: [] } + ] } ], member: [ role_ids: [] @@ -517,25 +508,27 @@ class PermittedParams Proc.new do |args| # avoid costly allowed_to? if the param is not there at all if args[:params]['work_package'] && - args[:params]['work_package'].has_key?('watcher_user_ids') && - args[:current_user].allowed_to?(:add_work_package_watchers, args[:project]) + args[:params]['work_package'].has_key?('watcher_user_ids') && + args[:current_user].allowed_to?(:add_work_package_watchers, args[:project]) { watcher_user_ids: [] } end end, # attributes unique to :new_work_package :journal_notes, - :lock_version], + :lock_version + ], oauth_application: [ :name, :redirect_uri, :confidential, :client_credentials_user_id, - scopes: [] + { scopes: [] } ], project_type: [ :name, - type_ids: []], + { type_ids: [] } + ], query: %i( name display_sums @@ -546,7 +539,8 @@ class PermittedParams :name, :assignable, :move_to, - permissions: []], + { permissions: [] } + ], search: %i( q offset @@ -577,7 +571,7 @@ class PermittedParams :color_id, :default, :description, - project_ids: [] + { project_ids: [] } ], user: %i( firstname diff --git a/app/models/principal.rb b/app/models/principal.rb index 9aa793070d..41799b47f8 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -123,7 +123,7 @@ class Principal < ApplicationRecord end def <=>(other) - if self.class.name == other.class.name + if instance_of?(other.class) to_s.downcase <=> other.to_s.downcase else # groups after users diff --git a/app/models/principals/scopes/like.rb b/app/models/principals/scopes/like.rb index 0620989ff0..5253dc741b 100644 --- a/app/models/principals/scopes/like.rb +++ b/app/models/principals/scopes/like.rb @@ -48,7 +48,7 @@ module Principals::Scopes "LOWER(#{firstnamelastname}) LIKE :s OR " + "LOWER(#{lastnamefirstname}) LIKE :s OR " + 'LOWER(mail) LIKE :s', - { s: s }]) + { s: s }]) .order(:type, :login, :lastname, :firstname, :mail) end end diff --git a/app/models/project.rb b/app/models/project.rb index 1d0cdc983a..d7771ce4b8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -311,8 +311,8 @@ class Project < ApplicationRecord self end - def <=>(project) - name.downcase <=> project.name.downcase + def <=>(other) + name.downcase <=> other.name.downcase end def to_s @@ -339,7 +339,11 @@ class Project < ApplicationRecord def enabled_module_names=(module_names) if module_names&.is_a?(Array) module_names = module_names.map(&:to_s).reject(&:blank?) - self.enabled_modules = module_names.map { |name| enabled_modules.detect { |mod| mod.name == name } || EnabledModule.new(name: name) } + self.enabled_modules = module_names.map do |name| + enabled_modules.detect do |mod| + mod.name == name + end || EnabledModule.new(name: name) + end else enabled_modules.clear end diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb index 242f9b8485..a68c39b69e 100644 --- a/app/models/project_custom_field.rb +++ b/app/models/project_custom_field.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/projects/activity.rb b/app/models/projects/activity.rb index d221aa0b7f..f7a4ca0b1f 100644 --- a/app/models/projects/activity.rb +++ b/app/models/projects/activity.rb @@ -36,7 +36,7 @@ module Projects::Activity end module ActivityScopes - def register_latest_project_activity(on:, chain: [], attribute:) + def register_latest_project_activity(on:, attribute:, chain: []) Constants::ProjectActivity.register(on: on, chain: chain, attribute: attribute) diff --git a/app/models/queries/available_filters.rb b/app/models/queries/available_filters.rb index a54965a9c7..6147aa33d5 100644 --- a/app/models/queries/available_filters.rb +++ b/app/models/queries/available_filters.rb @@ -95,6 +95,7 @@ module Queries::AvailableFilters def initialize_filter(filter) return if already_initialized_filters.include?(filter) + already_initialized_filters << filter new_filters = filter.all_for(context) diff --git a/app/models/queries/available_orders.rb b/app/models/queries/available_orders.rb index 6ac483c24d..1e1dbe7a46 100644 --- a/app/models/queries/available_orders.rb +++ b/app/models/queries/available_orders.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/columns/base.rb b/app/models/queries/columns/base.rb index 4e48641449..655c8483b0 100644 --- a/app/models/queries/columns/base.rb +++ b/app/models/queries/columns/base.rb @@ -58,7 +58,7 @@ class Queries::Columns::Base end end - def sortable_join_statement(query) + def sortable_join_statement(_query) sortable_join end diff --git a/app/models/queries/filters.rb b/app/models/queries/filters.rb index 1c6ba4f4e7..998ea98f78 100644 --- a/app/models/queries/filters.rb +++ b/app/models/queries/filters.rb @@ -47,5 +47,6 @@ module Queries::Filters ## # Wrapper class for invalid filters being created class InvalidError < StandardError; end + class MissingError < StandardError; end end diff --git a/app/models/queries/filters/serializable.rb b/app/models/queries/filters/serializable.rb index ddefa18326..a13956e769 100644 --- a/app/models/queries/filters/serializable.rb +++ b/app/models/queries/filters/serializable.rb @@ -38,12 +38,10 @@ module Queries # (de-)serialization def from_hash(filter_hash) filter_hash.keys.map do |field| - begin - create!(name, filter_hash[field]) - rescue ::Queries::Filters::InvalidError - Rails.logger.error "Failed to constantize field filter #{field} from hash." - ::Queries::NotExistingFilter.create!(field) - end + create!(name, filter_hash[field]) + rescue ::Queries::Filters::InvalidError + Rails.logger.error "Failed to constantize field filter #{field} from hash." + ::Queries::NotExistingFilter.create!(field) end end end diff --git a/app/models/queries/filters/shared/any_user_name_attribute_filter.rb b/app/models/queries/filters/shared/any_user_name_attribute_filter.rb index 8b6c0b0091..a553f1f718 100644 --- a/app/models/queries/filters/shared/any_user_name_attribute_filter.rb +++ b/app/models/queries/filters/shared/any_user_name_attribute_filter.rb @@ -42,7 +42,7 @@ module Queries::Filters::Shared::AnyUserNameAttributeFilter private def sql_concat_name - <<-SQL + <<-SQL LOWER( CONCAT( users.firstname, ' ', users.lastname, @@ -54,7 +54,7 @@ module Queries::Filters::Shared::AnyUserNameAttributeFilter users.mail ) ) - SQL + SQL end end diff --git a/app/models/queries/filters/shared/custom_fields/base.rb b/app/models/queries/filters/shared/custom_fields/base.rb index 41da8f8d30..e11f71fa3c 100644 --- a/app/models/queries/filters/shared/custom_fields/base.rb +++ b/app/models/queries/filters/shared/custom_fields/base.rb @@ -33,8 +33,7 @@ module Queries::Filters::Shared class Base < Queries::Filters::Base include Queries::Filters::Serializable - attr_reader :custom_field - attr_reader :custom_field_context + attr_reader :custom_field, :custom_field_context validate :custom_field_valid diff --git a/app/models/queries/filters/shared/group_filter.rb b/app/models/queries/filters/shared/group_filter.rb index a0dbea6833..868dd82aea 100644 --- a/app/models/queries/filters/shared/group_filter.rb +++ b/app/models/queries/filters/shared/group_filter.rb @@ -75,7 +75,6 @@ module Queries::Filters::Shared::GroupFilter def any_group_subselect User.within_group([]).select(:id).to_sql end - end module ClassMethods diff --git a/app/models/queries/filters/strategies/cf_list_optional.rb b/app/models/queries/filters/strategies/cf_list_optional.rb index 8ae9d8f123..71ab602f7a 100644 --- a/app/models/queries/filters/strategies/cf_list_optional.rb +++ b/app/models/queries/filters/strategies/cf_list_optional.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/filters/strategies/inexistent.rb b/app/models/queries/filters/strategies/inexistent.rb index ef30e64b7c..cde4b42df0 100644 --- a/app/models/queries/filters/strategies/inexistent.rb +++ b/app/models/queries/filters/strategies/inexistent.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/filters/strategies/validations.rb b/app/models/queries/filters/strategies/validations.rb index ba62d6fe96..7f4cf294d9 100644 --- a/app/models/queries/filters/strategies/validations.rb +++ b/app/models/queries/filters/strategies/validations.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,7 @@ module Queries::Filters::Strategies def date?(str) true if Date.parse(str) - rescue + rescue StandardError false end @@ -45,7 +46,7 @@ module Queries::Filters::Strategies def integer?(str) true if Integer(str) - rescue + rescue StandardError false end end diff --git a/app/models/queries/members/filters/group_filter.rb b/app/models/queries/members/filters/group_filter.rb index fff6b15d82..69a7930954 100644 --- a/app/models/queries/members/filters/group_filter.rb +++ b/app/models/queries/members/filters/group_filter.rb @@ -37,7 +37,6 @@ class Queries::Members::Filters::GroupFilter < Queries::Members::Filters::Member def scope scope = model.joins(:principal).merge(User.joins(:groups)) - scope = scope.where(where) - scope + scope.where(where) end end diff --git a/app/models/queries/not_existing_filter.rb b/app/models/queries/not_existing_filter.rb index 9a6007db81..41db42a1ce 100644 --- a/app/models/queries/not_existing_filter.rb +++ b/app/models/queries/not_existing_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/not_existing_order.rb b/app/models/queries/not_existing_order.rb index c6c2adead0..161445895b 100644 --- a/app/models/queries/not_existing_order.rb +++ b/app/models/queries/not_existing_order.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators.rb b/app/models/queries/operators.rb index 85cf0d957f..4ae871844f 100644 --- a/app/models/queries/operators.rb +++ b/app/models/queries/operators.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/ago.rb b/app/models/queries/operators/ago.rb index 80eb14e09a..ce4c585c52 100644 --- a/app/models/queries/operators/ago.rb +++ b/app/models/queries/operators/ago.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/all.rb b/app/models/queries/operators/all.rb index 346d613658..c67e94c5ad 100644 --- a/app/models/queries/operators/all.rb +++ b/app/models/queries/operators/all.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/all_and_non_blank.rb b/app/models/queries/operators/all_and_non_blank.rb index aef9e93c36..068a27ebcf 100644 --- a/app/models/queries/operators/all_and_non_blank.rb +++ b/app/models/queries/operators/all_and_non_blank.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/between_date.rb b/app/models/queries/operators/between_date.rb index c4cd0c2950..35f51858a4 100644 --- a/app/models/queries/operators/between_date.rb +++ b/app/models/queries/operators/between_date.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/between_date_time.rb b/app/models/queries/operators/between_date_time.rb index 8d6d67cf31..277a1996dd 100644 --- a/app/models/queries/operators/between_date_time.rb +++ b/app/models/queries/operators/between_date_time.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/casted_greater_or_equal.rb b/app/models/queries/operators/casted_greater_or_equal.rb index 73ba41fb7e..14444c0f2f 100644 --- a/app/models/queries/operators/casted_greater_or_equal.rb +++ b/app/models/queries/operators/casted_greater_or_equal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/casted_less_or_equal.rb b/app/models/queries/operators/casted_less_or_equal.rb index ba8d544302..f60ee2968b 100644 --- a/app/models/queries/operators/casted_less_or_equal.rb +++ b/app/models/queries/operators/casted_less_or_equal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/closed_work_packages.rb b/app/models/queries/operators/closed_work_packages.rb index ddcf005580..ab060f8271 100644 --- a/app/models/queries/operators/closed_work_packages.rb +++ b/app/models/queries/operators/closed_work_packages.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/date_range_clauses.rb b/app/models/queries/operators/date_range_clauses.rb index 5c0b701d07..4f353af510 100644 --- a/app/models/queries/operators/date_range_clauses.rb +++ b/app/models/queries/operators/date_range_clauses.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/datetime_range_clauses.rb b/app/models/queries/operators/datetime_range_clauses.rb index a6db19299f..a1a096be6d 100644 --- a/app/models/queries/operators/datetime_range_clauses.rb +++ b/app/models/queries/operators/datetime_range_clauses.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/equals.rb b/app/models/queries/operators/equals.rb index 6316a53a01..9f6b119642 100644 --- a/app/models/queries/operators/equals.rb +++ b/app/models/queries/operators/equals.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/greater_or_equal.rb b/app/models/queries/operators/greater_or_equal.rb index 24dded1b12..6b1470c620 100644 --- a/app/models/queries/operators/greater_or_equal.rb +++ b/app/models/queries/operators/greater_or_equal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/in.rb b/app/models/queries/operators/in.rb index 292fccc90d..b26531629d 100644 --- a/app/models/queries/operators/in.rb +++ b/app/models/queries/operators/in.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/in_less_than.rb b/app/models/queries/operators/in_less_than.rb index 3dd99a06c3..a446801a61 100644 --- a/app/models/queries/operators/in_less_than.rb +++ b/app/models/queries/operators/in_less_than.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/in_more_than.rb b/app/models/queries/operators/in_more_than.rb index 1aa9aa48ba..dbd8abce2e 100644 --- a/app/models/queries/operators/in_more_than.rb +++ b/app/models/queries/operators/in_more_than.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/less_or_equal.rb b/app/models/queries/operators/less_or_equal.rb index bb03565ad1..14704c77b8 100644 --- a/app/models/queries/operators/less_or_equal.rb +++ b/app/models/queries/operators/less_or_equal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/less_than_ago.rb b/app/models/queries/operators/less_than_ago.rb index 0a96a81e73..71e3ef4f47 100644 --- a/app/models/queries/operators/less_than_ago.rb +++ b/app/models/queries/operators/less_than_ago.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/more_than_ago.rb b/app/models/queries/operators/more_than_ago.rb index ac2e38cc8d..f6602fdd03 100644 --- a/app/models/queries/operators/more_than_ago.rb +++ b/app/models/queries/operators/more_than_ago.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/none.rb b/app/models/queries/operators/none.rb index 8268c8645e..2439754ddd 100644 --- a/app/models/queries/operators/none.rb +++ b/app/models/queries/operators/none.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/none_or_blank.rb b/app/models/queries/operators/none_or_blank.rb index 8240e0e278..26c3642573 100644 --- a/app/models/queries/operators/none_or_blank.rb +++ b/app/models/queries/operators/none_or_blank.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/not_equals.rb b/app/models/queries/operators/not_equals.rb index 7e3920a20d..771c38ce0c 100644 --- a/app/models/queries/operators/not_equals.rb +++ b/app/models/queries/operators/not_equals.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -39,14 +40,12 @@ module Queries::Operators sql = '' if values.present? - sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + - values.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + '))' + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + + values.map { |val| "'#{connection.quote_string(val)}'" }.join(',') + '))' else # empty set of forbidden values allows all results - sql = '1=1' + '1=1' end - - sql end end end diff --git a/app/models/queries/operators/on_date.rb b/app/models/queries/operators/on_date.rb index fb36f941fa..479d8917b9 100644 --- a/app/models/queries/operators/on_date.rb +++ b/app/models/queries/operators/on_date.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/on_date_time.rb b/app/models/queries/operators/on_date_time.rb index 0b7fee58e9..027031c029 100644 --- a/app/models/queries/operators/on_date_time.rb +++ b/app/models/queries/operators/on_date_time.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/open_work_packages.rb b/app/models/queries/operators/open_work_packages.rb index e8fd44d9ff..a7acf1a73a 100644 --- a/app/models/queries/operators/open_work_packages.rb +++ b/app/models/queries/operators/open_work_packages.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/this_week.rb b/app/models/queries/operators/this_week.rb index 278b5dbd75..eb58cb4274 100644 --- a/app/models/queries/operators/this_week.rb +++ b/app/models/queries/operators/this_week.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/operators/today.rb b/app/models/queries/operators/today.rb index b5cd9d50b3..f8874303ab 100644 --- a/app/models/queries/operators/today.rb +++ b/app/models/queries/operators/today.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/principals/filters/member_filter.rb b/app/models/queries/principals/filters/member_filter.rb index b7ad70d313..f4303f76bc 100644 --- a/app/models/queries/principals/filters/member_filter.rb +++ b/app/models/queries/principals/filters/member_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/principals/filters/status_filter.rb b/app/models/queries/principals/filters/status_filter.rb index 124f320af3..7fcc65b533 100644 --- a/app/models/queries/principals/filters/status_filter.rb +++ b/app/models/queries/principals/filters/status_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/principals/filters/type_filter.rb b/app/models/queries/principals/filters/type_filter.rb index ade893ba0c..cb1ac31f99 100644 --- a/app/models/queries/principals/filters/type_filter.rb +++ b/app/models/queries/principals/filters/type_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/projects/filters/ancestor_filter.rb b/app/models/queries/projects/filters/ancestor_filter.rb index a004a9cff8..011676d69d 100644 --- a/app/models/queries/projects/filters/ancestor_filter.rb +++ b/app/models/queries/projects/filters/ancestor_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/projects/filters/custom_field_filter.rb b/app/models/queries/projects/filters/custom_field_filter.rb index 38088ea287..3dc9564e2e 100644 --- a/app/models/queries/projects/filters/custom_field_filter.rb +++ b/app/models/queries/projects/filters/custom_field_filter.rb @@ -30,7 +30,6 @@ class Queries::Projects::Filters::CustomFieldFilter < Queries::Projects::Filters::ProjectFilter - include Queries::Filters::Shared::CustomFieldFilter self.custom_field_context = ::Queries::Projects::Filters::CustomFieldContext end diff --git a/app/models/queries/projects/filters/type_filter.rb b/app/models/queries/projects/filters/type_filter.rb index 0abfcae723..7600ff645e 100644 --- a/app/models/queries/projects/filters/type_filter.rb +++ b/app/models/queries/projects/filters/type_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/queries.rb b/app/models/queries/queries.rb index 22176c8519..ad061b97c2 100644 --- a/app/models/queries/queries.rb +++ b/app/models/queries/queries.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/queries/filters/hidden_filter.rb b/app/models/queries/queries/filters/hidden_filter.rb index e27cfcf54e..a1322abac9 100644 --- a/app/models/queries/queries/filters/hidden_filter.rb +++ b/app/models/queries/queries/filters/hidden_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/queries/filters/project_identifier_filter.rb b/app/models/queries/queries/filters/project_identifier_filter.rb index 62e76665b1..d690cd7451 100644 --- a/app/models/queries/queries/filters/project_identifier_filter.rb +++ b/app/models/queries/queries/filters/project_identifier_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/queries/filters/query_filter.rb b/app/models/queries/queries/filters/query_filter.rb index 71709cf855..42816fdeb8 100644 --- a/app/models/queries/queries/filters/query_filter.rb +++ b/app/models/queries/queries/filters/query_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations.rb b/app/models/queries/relations.rb index ce3374140a..0d0cfb5b48 100644 --- a/app/models/queries/relations.rb +++ b/app/models/queries/relations.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations/filters/from_filter.rb b/app/models/queries/relations/filters/from_filter.rb index e75548d361..e702f30db2 100644 --- a/app/models/queries/relations/filters/from_filter.rb +++ b/app/models/queries/relations/filters/from_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations/filters/id_filter.rb b/app/models/queries/relations/filters/id_filter.rb index b34590b48a..7c2030bfa2 100644 --- a/app/models/queries/relations/filters/id_filter.rb +++ b/app/models/queries/relations/filters/id_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations/filters/involved_filter.rb b/app/models/queries/relations/filters/involved_filter.rb index a3e934831d..64ea11690f 100644 --- a/app/models/queries/relations/filters/involved_filter.rb +++ b/app/models/queries/relations/filters/involved_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations/filters/relation_filter.rb b/app/models/queries/relations/filters/relation_filter.rb index bbcef10105..bf8afe45c9 100644 --- a/app/models/queries/relations/filters/relation_filter.rb +++ b/app/models/queries/relations/filters/relation_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations/filters/to_filter.rb b/app/models/queries/relations/filters/to_filter.rb index 645d268c2d..3067933d5c 100644 --- a/app/models/queries/relations/filters/to_filter.rb +++ b/app/models/queries/relations/filters/to_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/relations/orders/default_order.rb b/app/models/queries/relations/orders/default_order.rb index a69a4f6165..9726e0e39a 100644 --- a/app/models/queries/relations/orders/default_order.rb +++ b/app/models/queries/relations/orders/default_order.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/users/filters/login_filter.rb b/app/models/queries/users/filters/login_filter.rb index 98cc653267..52dfea01e3 100644 --- a/app/models/queries/users/filters/login_filter.rb +++ b/app/models/queries/users/filters/login_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/users/filters/user_filter.rb b/app/models/queries/users/filters/user_filter.rb index df33f9c2f8..bd798303ee 100644 --- a/app/models/queries/users/filters/user_filter.rb +++ b/app/models/queries/users/filters/user_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/users/orders/default_order.rb b/app/models/queries/users/orders/default_order.rb index 7f5a47d763..6af729dfbe 100644 --- a/app/models/queries/users/orders/default_order.rb +++ b/app/models/queries/users/orders/default_order.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/users/orders/group_order.rb b/app/models/queries/users/orders/group_order.rb index d04caf9048..38420c581e 100644 --- a/app/models/queries/users/orders/group_order.rb +++ b/app/models/queries/users/orders/group_order.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/versions/filters/sharing_filter.rb b/app/models/queries/versions/filters/sharing_filter.rb index 314569e2ee..f38ecdaaa4 100644 --- a/app/models/queries/versions/filters/sharing_filter.rb +++ b/app/models/queries/versions/filters/sharing_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/versions/filters/version_filter.rb b/app/models/queries/versions/filters/version_filter.rb index cd94533a68..6a3a69b2af 100644 --- a/app/models/queries/versions/filters/version_filter.rb +++ b/app/models/queries/versions/filters/version_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/common/manual_sorting.rb b/app/models/queries/work_packages/common/manual_sorting.rb index 86fc6b3e6a..3cabfb677e 100644 --- a/app/models/queries/work_packages/common/manual_sorting.rb +++ b/app/models/queries/work_packages/common/manual_sorting.rb @@ -31,7 +31,6 @@ module Queries::WorkPackages module Common module ManualSorting - ## # We depend on ordered_work_packages association # for determining sort and filter for manual sorting. diff --git a/app/models/queries/work_packages/filter.rb b/app/models/queries/work_packages/filter.rb index 2fceee8c8f..ee0b7c2816 100644 --- a/app/models/queries/work_packages/filter.rb +++ b/app/models/queries/work_packages/filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/blocked_filter.rb b/app/models/queries/work_packages/filter/blocked_filter.rb index 353650168d..52d36205eb 100644 --- a/app/models/queries/work_packages/filter/blocked_filter.rb +++ b/app/models/queries/work_packages/filter/blocked_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::BlockedFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/blocks_filter.rb b/app/models/queries/work_packages/filter/blocks_filter.rb index c479ee5eb9..4748e87fcd 100644 --- a/app/models/queries/work_packages/filter/blocks_filter.rb +++ b/app/models/queries/work_packages/filter/blocks_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::BlocksFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/created_at_filter.rb b/app/models/queries/work_packages/filter/created_at_filter.rb index 78321e1686..aa936e670c 100644 --- a/app/models/queries/work_packages/filter/created_at_filter.rb +++ b/app/models/queries/work_packages/filter/created_at_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/custom_field_filter.rb b/app/models/queries/work_packages/filter/custom_field_filter.rb index f27bd39869..03ce346f19 100644 --- a/app/models/queries/work_packages/filter/custom_field_filter.rb +++ b/app/models/queries/work_packages/filter/custom_field_filter.rb @@ -30,7 +30,6 @@ class Queries::WorkPackages::Filter::CustomFieldFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include Queries::Filters::Shared::CustomFieldFilter self.custom_field_context = ::Queries::WorkPackages::Filter::CustomFieldContext end diff --git a/app/models/queries/work_packages/filter/done_ratio_filter.rb b/app/models/queries/work_packages/filter/done_ratio_filter.rb index 4ed2a78a0c..185ff1c03c 100644 --- a/app/models/queries/work_packages/filter/done_ratio_filter.rb +++ b/app/models/queries/work_packages/filter/done_ratio_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/due_date_filter.rb b/app/models/queries/work_packages/filter/due_date_filter.rb index 7406e3ebe1..ac334bb9cd 100644 --- a/app/models/queries/work_packages/filter/due_date_filter.rb +++ b/app/models/queries/work_packages/filter/due_date_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/duplicated_filter.rb b/app/models/queries/work_packages/filter/duplicated_filter.rb index 9bbebff8fb..93cf1ce031 100644 --- a/app/models/queries/work_packages/filter/duplicated_filter.rb +++ b/app/models/queries/work_packages/filter/duplicated_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::DuplicatedFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/duplicates_filter.rb b/app/models/queries/work_packages/filter/duplicates_filter.rb index ec2c2d7b8d..c3ce39a194 100644 --- a/app/models/queries/work_packages/filter/duplicates_filter.rb +++ b/app/models/queries/work_packages/filter/duplicates_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::DuplicatesFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/estimated_hours_filter.rb b/app/models/queries/work_packages/filter/estimated_hours_filter.rb index 8ebde5071a..e5fd78abcf 100644 --- a/app/models/queries/work_packages/filter/estimated_hours_filter.rb +++ b/app/models/queries/work_packages/filter/estimated_hours_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,7 +33,7 @@ class Queries::WorkPackages::Filter::EstimatedHoursFilter < def type :integer end - + def where if operator == Queries::Operators::None.to_sym.to_s super + " OR #{WorkPackage.table_name}.estimated_hours=0" diff --git a/app/models/queries/work_packages/filter/filter_configuration.rb b/app/models/queries/work_packages/filter/filter_configuration.rb index f277081df0..498406e4ef 100644 --- a/app/models/queries/work_packages/filter/filter_configuration.rb +++ b/app/models/queries/work_packages/filter/filter_configuration.rb @@ -28,7 +28,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - class Queries::WorkPackages::Filter::FilterConfiguration attr_accessor(:filter_class, :filter_name, :operator) diff --git a/app/models/queries/work_packages/filter/follows_filter.rb b/app/models/queries/work_packages/filter/follows_filter.rb index 9524ff5c82..b732d7f1ae 100644 --- a/app/models/queries/work_packages/filter/follows_filter.rb +++ b/app/models/queries/work_packages/filter/follows_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::FollowsFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/group_filter.rb b/app/models/queries/work_packages/filter/group_filter.rb index c9459d078c..feb5bdbc7f 100644 --- a/app/models/queries/work_packages/filter/group_filter.rb +++ b/app/models/queries/work_packages/filter/group_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/id_filter.rb b/app/models/queries/work_packages/filter/id_filter.rb index b5032f9299..2d65071a03 100644 --- a/app/models/queries/work_packages/filter/id_filter.rb +++ b/app/models/queries/work_packages/filter/id_filter.rb @@ -30,6 +30,5 @@ class Queries::WorkPackages::Filter::IdFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterForWpMixin end diff --git a/app/models/queries/work_packages/filter/includes_filter.rb b/app/models/queries/work_packages/filter/includes_filter.rb index 602efbaab6..01a50b5c75 100644 --- a/app/models/queries/work_packages/filter/includes_filter.rb +++ b/app/models/queries/work_packages/filter/includes_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::IncludesFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/manual_sort_filter.rb b/app/models/queries/work_packages/filter/manual_sort_filter.rb index 98b5e478aa..3409d15e10 100644 --- a/app/models/queries/work_packages/filter/manual_sort_filter.rb +++ b/app/models/queries/work_packages/filter/manual_sort_filter.rb @@ -30,7 +30,6 @@ class Queries::WorkPackages::Filter::ManualSortFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Common::ManualSorting def available_operators diff --git a/app/models/queries/work_packages/filter/parent_filter.rb b/app/models/queries/work_packages/filter/parent_filter.rb index c4ca113ff5..0fd36bea40 100644 --- a/app/models/queries/work_packages/filter/parent_filter.rb +++ b/app/models/queries/work_packages/filter/parent_filter.rb @@ -30,7 +30,6 @@ class Queries::WorkPackages::Filter::ParentFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/partof_filter.rb b/app/models/queries/work_packages/filter/partof_filter.rb index 74b178fd86..02282e8ae5 100644 --- a/app/models/queries/work_packages/filter/partof_filter.rb +++ b/app/models/queries/work_packages/filter/partof_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::PartofFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/precedes_filter.rb b/app/models/queries/work_packages/filter/precedes_filter.rb index 84b5f546a4..fcc163f602 100644 --- a/app/models/queries/work_packages/filter/precedes_filter.rb +++ b/app/models/queries/work_packages/filter/precedes_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::PrecedesFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/priority_filter.rb b/app/models/queries/work_packages/filter/priority_filter.rb index 9ae654692f..be4231a476 100644 --- a/app/models/queries/work_packages/filter/priority_filter.rb +++ b/app/models/queries/work_packages/filter/priority_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/required_filter.rb b/app/models/queries/work_packages/filter/required_filter.rb index 0302aee9b3..efd22a022c 100644 --- a/app/models/queries/work_packages/filter/required_filter.rb +++ b/app/models/queries/work_packages/filter/required_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::RequiredFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/requires_filter.rb b/app/models/queries/work_packages/filter/requires_filter.rb index bbf1207a49..afd62af5e9 100644 --- a/app/models/queries/work_packages/filter/requires_filter.rb +++ b/app/models/queries/work_packages/filter/requires_filter.rb @@ -32,7 +32,6 @@ class Queries::WorkPackages::Filter::RequiresFilter < Queries::WorkPackages::Filter::WorkPackageFilter - include ::Queries::WorkPackages::Filter::FilterOnDirectedRelationsMixin def relation_type diff --git a/app/models/queries/work_packages/filter/responsible_filter.rb b/app/models/queries/work_packages/filter/responsible_filter.rb index e5676b1564..ae3191bad6 100644 --- a/app/models/queries/work_packages/filter/responsible_filter.rb +++ b/app/models/queries/work_packages/filter/responsible_filter.rb @@ -30,7 +30,6 @@ class Queries::WorkPackages::Filter::ResponsibleFilter < Queries::WorkPackages::Filter::PrincipalBaseFilter - def type :list_optional end diff --git a/app/models/queries/work_packages/filter/role_filter.rb b/app/models/queries/work_packages/filter/role_filter.rb index 4548f5d443..bd1fe27504 100644 --- a/app/models/queries/work_packages/filter/role_filter.rb +++ b/app/models/queries/work_packages/filter/role_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/start_date_filter.rb b/app/models/queries/work_packages/filter/start_date_filter.rb index b7d44a493a..e13b4856f6 100644 --- a/app/models/queries/work_packages/filter/start_date_filter.rb +++ b/app/models/queries/work_packages/filter/start_date_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/queries/work_packages/filter/updated_at_filter.rb b/app/models/queries/work_packages/filter/updated_at_filter.rb index d710e30ef1..1f123220e0 100644 --- a/app/models/queries/work_packages/filter/updated_at_filter.rb +++ b/app/models/queries/work_packages/filter/updated_at_filter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/query/highlighting.rb b/app/models/query/highlighting.rb index 074e10b616..209b23f43c 100644 --- a/app/models/query/highlighting.rb +++ b/app/models/query/highlighting.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/query/manual_sorting.rb b/app/models/query/manual_sorting.rb index 8dc6f57c0a..2e7be27b6b 100644 --- a/app/models/query/manual_sorting.rb +++ b/app/models/query/manual_sorting.rb @@ -39,8 +39,6 @@ module Query::ManualSorting sort_criteria_columns.any? { |clz, _| clz.is_a?(::Queries::WorkPackages::Columns::ManualSortingColumn) } end - private - def self.manual_sorting_column ::Queries::WorkPackages::Columns::ManualSortingColumn.new end diff --git a/app/models/query/statement_invalid.rb b/app/models/query/statement_invalid.rb index fea21d8a86..6ec299cd3e 100644 --- a/app/models/query/statement_invalid.rb +++ b/app/models/query/statement_invalid.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/query/timelines.rb b/app/models/query/timelines.rb index 60dfef8152..e159978f10 100644 --- a/app/models/query/timelines.rb +++ b/app/models/query/timelines.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/repository.rb b/app/models/repository.rb index 2591eae7b8..99fc7faed5 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -217,6 +218,7 @@ class Repository < ApplicationRecord def find_changeset_by_name(name) name = name.to_s return nil if name.blank? + changesets.where((name.match(/\A\d*\z/) ? ['revision = ?', name] : ['revision LIKE ?', name + '%'])).first end @@ -317,7 +319,6 @@ class Repository < ApplicationRecord all.each(&:scan_changesets_for_work_package_ids) end - ## # Builds a model instance of type +Repository::#{vendor}+ with the given parameters. # diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index a1a4b1b5ba..e8aaf4a25c 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -116,8 +117,10 @@ class Repository::Git < Repository def find_changeset_by_name(name) return nil if name.nil? || name.empty? + e = changesets.where(['revision = ?', name.to_s]).first return e if e + changesets.where(['scmid LIKE ?', "#{name}%"]).first end @@ -139,11 +142,11 @@ class Repository::Git < Repository recent_changesets = changesets.where(['committed_on >= ?', since]) # Clean out revisions that are no longer in git - recent_changesets.each do |c| c.destroy unless revisions.detect { |r| r.scmid.to_s == c.scmid.to_s } end + recent_changesets.each { |c| c.destroy unless revisions.detect { |r| r.scmid.to_s == c.scmid.to_s } } # Subtract revisions that redmine already knows about recent_revisions = recent_changesets.map(&:scmid) - revisions.reject! do |r| recent_revisions.include?(r.scmid) end + revisions.reject! { |r| recent_revisions.include?(r.scmid) } # Save the remaining ones to the database unless revisions.nil? @@ -151,18 +154,20 @@ class Repository::Git < Repository transaction do changeset = Changeset.new( repository: self, - revision: rev.identifier, - scmid: rev.scmid, - committer: rev.author, + revision: rev.identifier, + scmid: rev.scmid, + committer: rev.author, committed_on: rev.time, - comments: rev.message) + comments: rev.message + ) if changeset.save rev.paths.each do |file| Change.create( changeset: changeset, - action: file[:action], - path: file[:path]) + action: file[:action], + path: file[:path] + ) end end end @@ -185,7 +190,7 @@ class Repository::Git < Repository if parsed.scheme == 'ssh' errors.add :url, :must_not_be_ssh end - rescue => e + rescue StandardError => e Rails.logger.error "Failed to parse repository url for validation: #{e}" errors.add :url, :invalid_url end diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb index 3fb9998e53..2c07e4aa4e 100644 --- a/app/models/repository/subversion.rb +++ b/app/models/repository/subversion.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -98,34 +99,38 @@ class Repository::Subversion < Repository db_revision = latest_changeset&.revision&.to_i # first revision to fetch - identifier_from = db_revision ? db_revision + 1 : scm.start_revision + identifier_from = db_revision ? db_revision + 1 : scm.start_revision # latest revision in the repository scm_revision = scm_info.lastrev.identifier.to_i if db_revision.nil? || db_revision < scm_revision Rails.logger.debug { "Fetching changesets for repository #{url}" } - while (identifier_from <= scm_revision) + while identifier_from <= scm_revision # loads changesets by batches of 200 identifier_to = [identifier_from + 199, scm_revision].min revisions = scm.revisions('', identifier_to, identifier_from, with_paths: true) - revisions.reverse_each do |revision| - transaction do - changeset = Changeset.create(repository: self, - revision: revision.identifier, - committer: revision.author, - committed_on: revision.time, - comments: revision.message) - - revision.paths.each do |change| - changeset.create_change(change) - end unless changeset.new_record? + unless revisions.nil? + revisions.reverse_each do |revision| + transaction do + changeset = Changeset.create(repository: self, + revision: revision.identifier, + committer: revision.author, + committed_on: revision.time, + comments: revision.message) + + unless changeset.new_record? + revision.paths.each do |change| + changeset.create_change(change) + end + end + end end - end unless revisions.nil? + end identifier_from = identifier_to + 1 end end end - rescue => e + rescue StandardError => e Rails.logger.error("Failed to fetch changesets from repository: #{e.message}") end diff --git a/app/models/role.rb b/app/models/role.rb index 0b00b4bb3d..fa9fec56f1 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -95,9 +95,9 @@ class Role < ApplicationRecord perms = perms.map(&:to_s) - self.role_permissions = role_permissions.reject { |rp| + self.role_permissions = role_permissions.reject do |rp| perms.include?(rp.permission) - } + end end # Returns true if the role has the given permission diff --git a/app/models/role_permission.rb b/app/models/role_permission.rb index 4451fa1902..21d8663ec4 100644 --- a/app/models/role_permission.rb +++ b/app/models/role_permission.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/setting.rb b/app/models/setting.rb index 6e75dedc85..b3d12a722a 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -93,6 +94,7 @@ class Setting < ApplicationRecord def self.create_setting_accessors(name) return if [:installation_uuid].include?(name.to_sym) + # Defines getter and setter for each setting # Then setting values can be read using: Setting.some_setting_name # or set using Setting.some_setting_name = "some value" @@ -131,8 +133,12 @@ class Setting < ApplicationRecord end validates_uniqueness_of :name - validates_inclusion_of :name, in: lambda { |_setting| @@available_settings.keys } # lambda, because @available_settings changes at runtime - validates_numericality_of :value, only_integer: true, if: Proc.new { |setting| @@available_settings[setting.name]['format'] == 'int' } + validates_inclusion_of :name, in: lambda { |_setting| + @@available_settings.keys + } # lambda, because @available_settings changes at runtime + validates_numericality_of :value, only_integer: true, if: Proc.new { |setting| + @@available_settings[setting.name]['format'] == 'int' + } def value self.class.deserialize(name, read_attribute(:value)) @@ -210,7 +216,7 @@ class Setting < ApplicationRecord end end - [:emails_header, :emails_footer].each do |mail| + %i[emails_header emails_footer].each do |mail| src = <<-END_SRC def self.localized_#{mail} I18n.fallbacks[I18n.locale].each do |lang| @@ -238,8 +244,6 @@ class Setting < ApplicationRecord RequestStore.delete :settings_updated_at end - private - # Returns the Setting instance for the setting named name # and allows to filter the returned value def self.filtered_cached_or_default(name) @@ -273,11 +277,11 @@ class Setting < ApplicationRecord # Unless one cache hits, it plucks from the database # Returns a hash of setting => (possibly serialized) value def self.cached_settings - RequestStore.fetch(:cached_settings) { - Rails.cache.fetch(cache_key) { + RequestStore.fetch(:cached_settings) do + Rails.cache.fetch(cache_key) do Hash[Setting.pluck(:name, :value)] - } - } + end + end end def self.cache_key diff --git a/app/models/setting/aliases.rb b/app/models/setting/aliases.rb index c18cc4ff87..9f9f34b4d5 100644 --- a/app/models/setting/aliases.rb +++ b/app/models/setting/aliases.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,11 +29,9 @@ #++ class Setting - ## # Shorthand to common setting aliases to avoid checking values module Aliases - ## # Whether the application is configured to use or force SSL output # for cookie storage et al. diff --git a/app/models/setting/callbacks.rb b/app/models/setting/callbacks.rb index 52df691c66..e398424dd0 100644 --- a/app/models/setting/callbacks.rb +++ b/app/models/setting/callbacks.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/setting/self_registration.rb b/app/models/setting/self_registration.rb index 8e9d0cd48d..1d95ed9df2 100644 --- a/app/models/setting/self_registration.rb +++ b/app/models/setting/self_registration.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -47,7 +48,7 @@ class Setting end def self.key(value:) - VALUES.find { |k, v| v == value || v.to_s == value.to_s }&.first + VALUES.find { |_k, v| v == value || v.to_s == value.to_s }&.first end def self.disabled diff --git a/app/models/status.rb b/app/models/status.rb index 71f7bca829..977e5b0264 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -81,8 +81,8 @@ class Status < ApplicationRecord order(:position) end - def <=>(status) - position <=> status.position + def <=>(other) + position <=> other.position end def to_s; name end diff --git a/app/models/system_user.rb b/app/models/system_user.rb index 0e0c30ef61..935b9e8338 100644 --- a/app/models/system_user.rb +++ b/app/models/system_user.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/token/expirable_token.rb b/app/models/token/expirable_token.rb index dc33413455..dc0857fb46 100644 --- a/app/models/token/expirable_token.rb +++ b/app/models/token/expirable_token.rb @@ -29,6 +29,7 @@ module Token def valid_plaintext?(input) return false if expired? + super end @@ -53,7 +54,6 @@ module Token end module ClassMethods - ## # Return a scope of active tokens def not_expired diff --git a/app/models/type.rb b/app/models/type.rb index bbaa538749..1638e7b0d6 100644 --- a/app/models/type.rb +++ b/app/models/type.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -83,7 +84,7 @@ class ::Type < ApplicationRecord def self.statuses(types) workflow_table, status_table = [Workflow, Status].map(&:arel_table) - old_id_subselect, new_id_subselect = [:old_status_id, :new_status_id].map do |foreign_key| + old_id_subselect, new_id_subselect = %i[old_status_id new_status_id].map do |foreign_key| workflow_table.project(workflow_table[foreign_key]).where(workflow_table[:type_id].in(types)) end Status.where(status_table[:id].in(old_id_subselect).or(status_table[:id].in(new_id_subselect))) diff --git a/app/models/type/attribute_groups.rb b/app/models/type/attribute_groups.rb index 5d0f7eac1a..190367d8e0 100644 --- a/app/models/type/attribute_groups.rb +++ b/app/models/type/attribute_groups.rb @@ -119,12 +119,10 @@ module Type::AttributeGroups def default_attribute_groups values = work_package_attributes_by_default_group_key - groups = default_groups.keys.each_with_object([]) do |groupkey, array| + default_groups.keys.each_with_object([]) do |groupkey, array| members = values[groupkey] array << [groupkey, members] if members.present? end - - groups end def reload(*args) diff --git a/app/models/user.rb b/app/models/user.rb index b295aefa14..648f7a1ad4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -32,10 +32,10 @@ require 'digest/sha1' class User < Principal USER_FORMATS_STRUCTURE = { - firstname_lastname: [:firstname, :lastname], + firstname_lastname: %i[firstname lastname], firstname: [:firstname], - lastname_firstname: [:lastname, :firstname], - lastname_coma_firstname: [:lastname, :firstname], + lastname_firstname: %i[lastname firstname], + lastname_coma_firstname: %i[lastname firstname], username: [:login] }.freeze @@ -106,8 +106,7 @@ class User < Principal acts_as_customizable - attr_accessor :password, :password_confirmation - attr_accessor :last_before_login_on + attr_accessor :password, :password_confirmation, :last_before_login_on validates_presence_of :login, :firstname, @@ -118,7 +117,7 @@ class User < Principal validates_uniqueness_of :login, if: Proc.new { |user| !user.login.blank? }, case_sensitive: false validates_uniqueness_of :mail, allow_blank: true, case_sensitive: false # Login must contain letters, numbers, underscores only - validates_format_of :login, with: /\A[a-z0-9_\-@\.+ ]*\z/i + validates_format_of :login, with: /\A[a-z0-9_\-@.+ ]*\z/i validates_length_of :login, maximum: 256 validates_length_of :firstname, :lastname, maximum: 256 validates_format_of :mail, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, allow_blank: true @@ -281,7 +280,7 @@ class User < Principal user.reload Rails.logger.info("User '#{user.login}' created from external auth source: #{user.auth_source&.type} - #{user.auth_source&.name}") else - Rails.logger.error("User '#{user.login}' could not be created: #{user.errors.full_messages.join(". ")}") + Rails.logger.error("User '#{user.login}' could not be created: #{user.errors.full_messages.join('. ')}") end end end @@ -290,11 +289,9 @@ class User < Principal def self.try_to_autologin(key) token = Token::AutoLogin.find_by_plaintext_value(key) # Make sure there's only 1 token that matches the key - if token - if (token.created_at > Setting.autologin.to_i.day.ago) && token.user && token.user.active? - token.user.log_successful_login - token.user - end + if token && ((token.created_at > Setting.autologin.to_i.day.ago) && token.user && token.user.active?) + token.user.log_successful_login + token.user end end @@ -358,6 +355,7 @@ class User < Principal auth_source.authenticate(login, clear_password) else return false if current_password.nil? + current_password.matches_plaintext?(clear_password, update_legacy: update_legacy) end end @@ -367,6 +365,7 @@ class User < Principal return false if uses_external_authentication? || OpenProject::Configuration.disable_password_login? return true if auth_source_id.blank? + auth_source.allow_password_changes? end @@ -394,7 +393,8 @@ class User < Principal # def failed_too_many_recent_login_attempts? block_threshold = Setting.brute_force_block_after_failed_logins.to_i - return false if block_threshold == 0 # disabled + return false if block_threshold == 0 # disabled + (last_failed_login_within_block_time? and failed_login_count >= block_threshold) end @@ -703,18 +703,18 @@ class User < Principal # save. Otherwise, password is nil. unless password.nil? or anonymous? password_errors = OpenProject::Passwords::Evaluator.errors_for_password(password) - password_errors.each do |error| errors.add(:password, error) end + password_errors.each { |error| errors.add(:password, error) } if former_passwords_include?(password) errors.add(:password, I18n.t(:reused, count: Setting[:password_count_former_banned].to_i, - scope: [:activerecord, - :errors, - :models, - :user, - :attributes, - :password])) + scope: %i[activerecord + errors + models + user + attributes + password])) end end end @@ -740,6 +740,7 @@ class User < Principal def former_passwords_include?(password) return false if Setting[:password_count_former_banned].to_i == 0 + ban_count = Setting[:password_count_former_banned].to_i # make reducing the number of banned former passwords immediately effective # by only checking this number of former passwords diff --git a/app/models/user_custom_field.rb b/app/models/user_custom_field.rb index e9733fd64b..d9a2d18e68 100644 --- a/app/models/user_custom_field.rb +++ b/app/models/user_custom_field.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/user_password.rb b/app/models/user_password.rb index 7fe7210c84..266da02e5d 100644 --- a/app/models/user_password.rb +++ b/app/models/user_password.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -70,7 +71,7 @@ class UserPassword < ApplicationRecord active end - rescue => e + rescue StandardError => e Rails.logger.error("Unable to re-hash UserPassword for #{user.login}: #{e.message}") end @@ -86,6 +87,7 @@ class UserPassword < ApplicationRecord def expired? days_valid = Setting.password_days_valid.to_i.days return false if days_valid == 0 + created_at < (Time.now - days_valid) end @@ -95,6 +97,7 @@ class UserPassword < ApplicationRecord # if it is is set. def salt_and_hash_password! return if plain_password.nil? + self.hashed_password = derive_password!(plain_password) end diff --git a/app/models/user_password/bcrypt.rb b/app/models/user_password/bcrypt.rb index 23da994ac9..641648ed23 100644 --- a/app/models/user_password/bcrypt.rb +++ b/app/models/user_password/bcrypt.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/user_password/sha1.rb b/app/models/user_password/sha1.rb index 7739857464..6406bb907d 100644 --- a/app/models/user_password/sha1.rb +++ b/app/models/user_password/sha1.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -44,10 +45,11 @@ class UserPassword::SHA1 < UserPassword # constant-time comparison algorithm to prevent timing attacks def secure_equals?(a, b) return false if a.blank? || b.blank? || a.bytesize != b.bytesize + l = a.unpack "C#{a.bytesize}" res = 0 - b.each_byte do |byte| res |= byte ^ l.shift end + b.each_byte { |byte| res |= byte ^ l.shift } res == 0 end diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 605bb8d5f9..c8e2776ad7 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/user_session.rb b/app/models/user_session.rb index 369eb70dff..764d7d2c5c 100644 --- a/app/models/user_session.rb +++ b/app/models/user_session.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/version_custom_field.rb b/app/models/version_custom_field.rb index 5c5b885c37..616acce3ac 100644 --- a/app/models/version_custom_field.rb +++ b/app/models/version_custom_field.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 5314a43e95..0f3ceff508 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,7 +33,7 @@ class Watcher < ApplicationRecord belongs_to :user validates_presence_of :watchable, :user - validates_uniqueness_of :user_id, scope: [:watchable_type, :watchable_id] + validates_uniqueness_of :user_id, scope: %i[watchable_type watchable_id] validate :validate_active_user validate :validate_user_allowed_to_watch @@ -57,6 +58,7 @@ class Watcher < ApplicationRecord def validate_user_allowed_to_watch # TODO add informative error message return if user.blank? || watchable.blank? + errors.add :user_id, :invalid unless watchable.possible_watcher?(user) end diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 27848724e8..0b08e9cddb 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -82,7 +83,7 @@ class Wiki < ApplicationRecord # Wiki.find_page("foo:bar") def self.find_page(title, options = {}) project = options[:project] - if title.to_s =~ %r{\A([^\:]+)\:(.*)\z} + if title.to_s =~ %r{\A([^:]+):(.*)\z} project_identifier = $1 title = $2 project = Project.find_by(identifier: project_identifier) || Project.find_by(name: project_identifier) @@ -96,9 +97,9 @@ class Wiki < ApplicationRecord end def create_menu_item_for_start_page - wiki_menu_item = wiki_menu_items.find_or_initialize_by(title: start_page) { |item| + wiki_menu_item = wiki_menu_items.find_or_initialize_by(title: start_page) do |item| item.name = 'wiki' - } + end wiki_menu_item.new_wiki_page = true wiki_menu_item.index_page = true diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb index a5b5cec936..f96c5a2f95 100644 --- a/app/models/wiki_content.rb +++ b/app/models/wiki_content.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 67dcfbf852..413167c33d 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -49,7 +49,7 @@ class WikiPage < ApplicationRecord acts_as_searchable columns: ["#{WikiPage.table_name}.title", "#{WikiContent.table_name}.text"], include: [{ wiki: :project }, :content], - references: [:wikis, :wiki_contents], + references: %i[wikis wiki_contents], project_key: "#{Wiki.table_name}.project_id" attr_accessor :redirect_existing_links @@ -131,14 +131,14 @@ class WikiPage < ApplicationRecord def content_for_version(version = nil) journal = content.versions.find_by(version: version.to_i) if version - unless journal.nil? || content.version == journal.version + if journal.nil? || content.version == journal.version + content + else content_version = WikiContent.new journal.data.attributes.except('id', 'journal_id') content_version.updated_at = journal.created_at content_version.journals = content.journals.select { |j| j.version <= version.to_i } content_version - else - content end end @@ -150,7 +150,7 @@ class WikiPage < ApplicationRecord content_to = content.versions.find_by(version: version_to) content_from = content.versions.find_by(version: version_from) - (content_to && content_from) ? Wikis::Diff.new(content_to, content_from) : nil + content_to && content_from ? Wikis::Diff.new(content_to, content_from) : nil end def annotate(version = nil) @@ -168,7 +168,11 @@ class WikiPage < ApplicationRecord if (time = read_attribute(:updated_at)) # content updated_at was eager loaded with the page unless time.is_a? Time - time = Time.zone.parse(time) rescue nil + time = begin + Time.zone.parse(time) + rescue StandardError + nil + end end @updated_at = time else @@ -188,7 +192,7 @@ class WikiPage < ApplicationRecord end def parent_title - @parent_title || (parent&.title) + @parent_title || parent&.title end def parent_title=(t) diff --git a/app/models/wiki_redirect.rb b/app/models/wiki_redirect.rb index 6cbaf61c82..a5acb8be09 100644 --- a/app/models/wiki_redirect.rb +++ b/app/models/wiki_redirect.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/wikis/annotate.rb b/app/models/wikis/annotate.rb index 6057e4ede9..0f1bdd31ae 100644 --- a/app/models/wikis/annotate.rb +++ b/app/models/wikis/annotate.rb @@ -43,11 +43,9 @@ class Wikis::Annotate d.each_slice(3) do |s| sign = s[0] line = s[1] - if sign == '+' && positions[line] && positions[line] != -1 - if @lines[positions[line]][0].nil? - @lines[positions[line]][0] = current.version - @lines[positions[line]][1] = current.data.author - end + if sign == '+' && positions[line] && positions[line] != -1 && @lines[positions[line]][0].nil? + @lines[positions[line]][0] = current.version + @lines[positions[line]][1] = current.data.author end end d.each_slice(3) do |s| diff --git a/app/models/work_package.rb b/app/models/work_package.rb index e5aa9fc09d..db8d5c54ff 100644 --- a/app/models/work_package.rb +++ b/app/models/work_package.rb @@ -354,6 +354,7 @@ class WorkPackage < ApplicationRecord # Overrides attributes= so that type_id gets assigned first def attributes=(new_attributes) return if new_attributes.nil? + new_type_id = new_attributes['type_id'] || new_attributes[:type_id] if new_type_id self.type_id = new_type_id @@ -373,6 +374,7 @@ class WorkPackage < ApplicationRecord # Is the amount of work done less than it should for the finish date def behind_schedule? return false if start_date.nil? || due_date.nil? + done_date = start_date + (duration * done_ratio / 100).floor done_date <= Date.today end diff --git a/app/models/work_package/ancestors.rb b/app/models/work_package/ancestors.rb index ed7e025911..8613da6e47 100644 --- a/app/models/work_package/ancestors.rb +++ b/app/models/work_package/ancestors.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/work_package/ask_before_destruction.rb b/app/models/work_package/ask_before_destruction.rb index e719e4d92a..65e822568f 100644 --- a/app/models/work_package/ask_before_destruction.rb +++ b/app/models/work_package/ask_before_destruction.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/work_package/exporter/result/success.rb b/app/models/work_package/exporter/result/success.rb index c4a6767bff..c808cc3798 100644 --- a/app/models/work_package/exporter/result/success.rb +++ b/app/models/work_package/exporter/result/success.rb @@ -34,7 +34,7 @@ class WorkPackage::Exporter::Result::Success < WorkPackage::Exporter::Result :content, :mime_type - def initialize(format:, title:, content: nil, mime_type:) + def initialize(format:, title:, mime_type:, content: nil) self.format = format self.title = title self.content = content diff --git a/app/models/work_package/pdf_export/attachments.rb b/app/models/work_package/pdf_export/attachments.rb index 6a741da7ce..3f8fc7c5ae 100644 --- a/app/models/work_package/pdf_export/attachments.rb +++ b/app/models/work_package/pdf_export/attachments.rb @@ -58,7 +58,7 @@ module WorkPackage::PDFExport::Attachments # Fit the image roughly in the center of each cell pdf.make_cell(image: resized_file_path, fit: [available_width, 125], position: :center) - rescue => e + rescue StandardError => e Rails.logger.error { "Failed to attach work package image to PDF: #{e} #{e.message}" } nil end diff --git a/app/models/work_package/pdf_export/to_pdf_helper.rb b/app/models/work_package/pdf_export/to_pdf_helper.rb index dc3712363a..88f4e9ea10 100644 --- a/app/models/work_package/pdf_export/to_pdf_helper.rb +++ b/app/models/work_package/pdf_export/to_pdf_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,7 @@ #++ module WorkPackage::PDFExport::ToPdfHelper - def get_pdf(language) + def get_pdf(_language) ::WorkPackage::PDFExport::View.new(current_language) end end diff --git a/app/models/work_package/pdf_export/view.rb b/app/models/work_package/pdf_export/view.rb index 6c8e2dfb54..f2dff6ddef 100644 --- a/app/models/work_package/pdf_export/view.rb +++ b/app/models/work_package/pdf_export/view.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,6 @@ #++ class WorkPackage::PDFExport::View - include Prawn::View include Redmine::I18n diff --git a/app/models/work_package/pdf_export/work_package_to_pdf.rb b/app/models/work_package/pdf_export/work_package_to_pdf.rb index a153790468..d56d0157a1 100644 --- a/app/models/work_package/pdf_export/work_package_to_pdf.rb +++ b/app/models/work_package/pdf_export/work_package_to_pdf.rb @@ -90,10 +90,10 @@ class WorkPackage::PDFExport::WorkPackageToPdf < WorkPackage::Exporter::Base def make_attributes attrs = [ - [:status, :priority], - [:author, :category], - [:created_at, :assigned_to], - [:updated_at, :due_date] + %i[status priority], + %i[author category], + %i[created_at assigned_to], + %i[updated_at due_date] ] attrs.map do |first, second| @@ -192,7 +192,7 @@ class WorkPackage::PDFExport::WorkPackageToPdf < WorkPackage::Exporter::Base end newline! - for changeset in work_package.changesets + work_package.changesets.each do |changeset| pdf.font style: :bold, size: 8 pdf.text(format_time(changeset.committed_on) + ' - ' + changeset.author.to_s) newline! @@ -218,7 +218,7 @@ class WorkPackage::PDFExport::WorkPackageToPdf < WorkPackage::Exporter::Base newline! - for journal in work_package.journals.includes(:user).order("#{Journal.table_name}.created_at ASC") + work_package.journals.includes(:user).order("#{Journal.table_name}.created_at ASC").each do |journal| next if journal.initial? pdf.font style: :bold, size: 8 @@ -229,7 +229,7 @@ class WorkPackage::PDFExport::WorkPackageToPdf < WorkPackage::Exporter::Base journal.details.each do |detail| text = journal .render_detail(detail, no_html: true, only_path: false) - .gsub(/\((https?[^\)]+)\)$/, "(\\1)") + .gsub(/\((https?[^)]+)\)$/, "(\\1)") pdf.text('- ' + text, inline_format: true) newline! diff --git a/app/models/work_package/status_transitions.rb b/app/models/work_package/status_transitions.rb index 2de0341b8d..0930ece9f0 100644 --- a/app/models/work_package/status_transitions.rb +++ b/app/models/work_package/status_transitions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/work_package/time_entries_cleaner.rb b/app/models/work_package/time_entries_cleaner.rb index f2ec099600..34d01164cd 100644 --- a/app/models/work_package/time_entries_cleaner.rb +++ b/app/models/work_package/time_entries_cleaner.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/models/work_packages/costs.rb b/app/models/work_packages/costs.rb index 5b5f6ecb75..7d4f09c49a 100644 --- a/app/models/work_packages/costs.rb +++ b/app/models/work_packages/costs.rb @@ -49,10 +49,8 @@ module WorkPackages::Costs end def validate_budget - if budget_id_changed? - unless budget_id.blank? || project.budget_ids.include?(budget_id) - errors.add :budget, :inclusion - end + if budget_id_changed? && !(budget_id.blank? || project.budget_ids.include?(budget_id)) + errors.add :budget, :inclusion end end diff --git a/app/models/work_packages/scopes/for_scheduling.rb b/app/models/work_packages/scopes/for_scheduling.rb index 28eff2fcc3..100f9ec0e5 100644 --- a/app/models/work_packages/scopes/for_scheduling.rb +++ b/app/models/work_packages/scopes/for_scheduling.rb @@ -120,45 +120,45 @@ module WorkPackages::Scopes values = work_packages.map { |wp| "(#{wp.id}, false)" }.join(', ') <<~SQL - to_schedule (id, manually) AS ( - SELECT * FROM (VALUES#{values}) AS t(id, manually) + to_schedule (id, manually) AS ( + SELECT * FROM (VALUES#{values}) AS t(id, manually) - UNION + UNION - SELECT - CASE - WHEN relations.to_id = to_schedule.id - THEN relations.from_id - ELSE relations.to_id - END id, - (work_packages.schedule_manually OR COALESCE(descendants.schedule_manually, false)) manually - FROM - to_schedule - JOIN - relations - ON NOT to_schedule.manually - AND (#{relations_condition_sql}) - AND - ((relations.to_id = to_schedule.id) - OR (relations.from_id = to_schedule.id AND relations.follows = 0)) - LEFT JOIN work_packages - ON (CASE - WHEN relations.to_id = to_schedule.id - THEN relations.from_id - ELSE relations.to_id - END) = work_packages.id - LEFT JOIN ( - SELECT - relations.from_id, - bool_and(COALESCE(work_packages.schedule_manually, false)) schedule_manually - FROM relations relations - JOIN work_packages - ON - work_packages.id = relations.to_id - AND relations.follows = 0 AND #{relations_condition_sql(transitive: true)} - GROUP BY relations.from_id - ) descendants ON work_packages.id = descendants.from_id - ) + SELECT + CASE + WHEN relations.to_id = to_schedule.id + THEN relations.from_id + ELSE relations.to_id + END id, + (work_packages.schedule_manually OR COALESCE(descendants.schedule_manually, false)) manually + FROM + to_schedule + JOIN + relations + ON NOT to_schedule.manually + AND (#{relations_condition_sql}) + AND + ((relations.to_id = to_schedule.id) + OR (relations.from_id = to_schedule.id AND relations.follows = 0)) + LEFT JOIN work_packages + ON (CASE + WHEN relations.to_id = to_schedule.id + THEN relations.from_id + ELSE relations.to_id + END) = work_packages.id + LEFT JOIN ( + SELECT + relations.from_id, + bool_and(COALESCE(work_packages.schedule_manually, false)) schedule_manually + FROM relations relations + JOIN work_packages + ON + work_packages.id = relations.to_id + AND relations.follows = 0 AND #{relations_condition_sql(transitive: true)} + GROUP BY relations.from_id + ) descendants ON work_packages.id = descendants.from_id + ) SQL end diff --git a/app/policies/scm/git_authorization_policy.rb b/app/policies/scm/git_authorization_policy.rb index 6d950aec93..3b4140077b 100644 --- a/app/policies/scm/git_authorization_policy.rb +++ b/app/policies/scm/git_authorization_policy.rb @@ -33,6 +33,6 @@ class SCM::GitAuthorizationPolicy < SCM::AuthorizationPolicy uri = params[:uri] location = params[:location] - !%r{^#{location}/*[^/]+/+(info/refs\?service=)?git\-receive\-pack$}o.match(uri) + !%r{^#{location}/*[^/]+/+(info/refs\?service=)?git-receive-pack$}o.match(uri) end end diff --git a/app/policies/version_policy.rb b/app/policies/version_policy.rb index d3c2d6741d..dec198fd4e 100644 --- a/app/policies/version_policy.rb +++ b/app/policies/version_policy.rb @@ -41,11 +41,11 @@ class VersionPolicy < BasePolicy def show_allowed?(version) @show_cache ||= Hash.new do |hash, queried_version| - permissions = [:view_work_packages, :manage_versions] + permissions = %i[view_work_packages manage_versions] - hash[queried_version] = permissions.any? { |permission| + hash[queried_version] = permissions.any? do |permission| queried_version.projects.allowed_to(user, permission).exists? - } + end end @show_cache[version] diff --git a/app/seeders/admin_user_seeder.rb b/app/seeders/admin_user_seeder.rb index 60014a18fc..75a292f0a5 100644 --- a/app/seeders/admin_user_seeder.rb +++ b/app/seeders/admin_user_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/activity_seeder.rb b/app/seeders/basic_data/activity_seeder.rb index be8d6f93e9..7a019e2f90 100644 --- a/app/seeders/basic_data/activity_seeder.rb +++ b/app/seeders/basic_data/activity_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/builtin_roles_seeder.rb b/app/seeders/basic_data/builtin_roles_seeder.rb index 9f60c5ee58..efbb2b046e 100644 --- a/app/seeders/basic_data/builtin_roles_seeder.rb +++ b/app/seeders/basic_data/builtin_roles_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/color_scheme_seeder.rb b/app/seeders/basic_data/color_scheme_seeder.rb index 9c9b438661..6855a5ed5a 100644 --- a/app/seeders/basic_data/color_scheme_seeder.rb +++ b/app/seeders/basic_data/color_scheme_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/color_seeder.rb b/app/seeders/basic_data/color_seeder.rb index d9264c6a3c..e92817938d 100644 --- a/app/seeders/basic_data/color_seeder.rb +++ b/app/seeders/basic_data/color_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/priority_seeder.rb b/app/seeders/basic_data/priority_seeder.rb index ac2a6066ef..33ff329ba4 100644 --- a/app/seeders/basic_data/priority_seeder.rb +++ b/app/seeders/basic_data/priority_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/role_seeder.rb b/app/seeders/basic_data/role_seeder.rb index 362fc8cd09..1f6fdef7eb 100644 --- a/app/seeders/basic_data/role_seeder.rb +++ b/app/seeders/basic_data/role_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/setting_seeder.rb b/app/seeders/basic_data/setting_seeder.rb index aef76cc401..793acd40da 100644 --- a/app/seeders/basic_data/setting_seeder.rb +++ b/app/seeders/basic_data/setting_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/status_seeder.rb b/app/seeders/basic_data/status_seeder.rb index 7de71aa319..a93c600da5 100644 --- a/app/seeders/basic_data/status_seeder.rb +++ b/app/seeders/basic_data/status_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data/type_seeder.rb b/app/seeders/basic_data/type_seeder.rb index 83ed8b59e0..25a1ed51c2 100644 --- a/app/seeders/basic_data/type_seeder.rb +++ b/app/seeders/basic_data/type_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -50,19 +51,19 @@ module BasicData # @return [Array] List of attributes for each type. def data colors = Color.all - colors = colors.map { |c| { c.name => c.id } }.reduce({}, :merge) + colors = colors.map { |c| { c.name => c.id } }.reduce({}, :merge) type_table.map do |_name, values| color_id = colors[values[2]] || values[2] { - name: I18n.t(values[5]), - position: values[0], - is_default: values[1], - color_id: color_id, - is_in_roadmap: values[3], - is_milestone: values[4], - description: type_description(values[5]) + name: I18n.t(values[5]), + position: values[0], + is_default: values[1], + color_id: color_id, + is_in_roadmap: values[3], + is_milestone: values[4], + description: type_description(values[5]) } end end @@ -80,7 +81,7 @@ module BasicData demo_data_for('type_configuration').each do |entry| if entry[:type] && I18n.t(entry[:type]) === I18n.t(type_name) - return entry[:description] ? entry[:description] : '' + return entry[:description] || '' else return '' end diff --git a/app/seeders/basic_data/workflow_seeder.rb b/app/seeders/basic_data/workflow_seeder.rb index ca05b1be91..da57360530 100644 --- a/app/seeders/basic_data/workflow_seeder.rb +++ b/app/seeders/basic_data/workflow_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/basic_data_seeder.rb b/app/seeders/basic_data_seeder.rb index ad2e01c050..bf26db2417 100644 --- a/app/seeders/basic_data_seeder.rb +++ b/app/seeders/basic_data_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/composite_seeder.rb b/app/seeders/composite_seeder.rb index a4c29563db..a8252911c3 100644 --- a/app/seeders/composite_seeder.rb +++ b/app/seeders/composite_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/app/seeders/demo_data/custom_field_seeder.rb b/app/seeders/demo_data/custom_field_seeder.rb index 25597976b5..5ae4995619 100644 --- a/app/seeders/demo_data/custom_field_seeder.rb +++ b/app/seeders/demo_data/custom_field_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -39,7 +40,7 @@ module DemoData # on the seeded project will be lost. print_status ' ↳ Creating custom fields...' do # create some custom fields and add them to the project - Array(project_data_for(key,'custom_fields')).each do |name| + Array(project_data_for(key, 'custom_fields')).each do |name| cf = WorkPackageCustomField.create!( name: name, regexp: '', diff --git a/app/seeders/demo_data/group_seeder.rb b/app/seeders/demo_data/group_seeder.rb index 0da3448f7a..a0e5a0a7d1 100644 --- a/app/seeders/demo_data/group_seeder.rb +++ b/app/seeders/demo_data/group_seeder.rb @@ -30,6 +30,7 @@ module DemoData class GroupSeeder < Seeder attr_accessor :user + include ::DemoData::References def initialize diff --git a/app/seeders/demo_data/query_builder.rb b/app/seeders/demo_data/query_builder.rb index 53c8eb1099..a936bb428f 100644 --- a/app/seeders/demo_data/query_builder.rb +++ b/app/seeders/demo_data/query_builder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -27,8 +28,7 @@ # See docs/COPYRIGHT.rdoc for more details. module DemoData class QueryBuilder < ::Seeder - attr_reader :config - attr_reader :project + attr_reader :config, :project def initialize(config, project) @config = config diff --git a/app/seeders/demo_data/references.rb b/app/seeders/demo_data/references.rb index 337dfcec5c..65f55987f6 100644 --- a/app/seeders/demo_data/references.rb +++ b/app/seeders/demo_data/references.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -41,9 +42,7 @@ module DemoData def with_references(str, project) res = link_work_packages str, project res = link_queries res, project - res = link_sprints res, project - - res + link_sprints res, project end ## diff --git a/app/seeders/demo_data/version_builder.rb b/app/seeders/demo_data/version_builder.rb index f3ec3d43ba..1f3c313c27 100644 --- a/app/seeders/demo_data/version_builder.rb +++ b/app/seeders/demo_data/version_builder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -29,8 +30,7 @@ module DemoData class VersionBuilder include ::DemoData::References - attr_reader :config - attr_reader :project + attr_reader :config, :project def initialize(config, project) @config = config @@ -55,8 +55,8 @@ module DemoData def version version = Version.create!( - name: config[:name], - status: config[:status], + name: config[:name], + status: config[:status], sharing: config[:sharing], project: project ) diff --git a/app/seeders/demo_data/wiki_seeder.rb b/app/seeders/demo_data/wiki_seeder.rb index 992ea2dce4..26df8ef4ef 100644 --- a/app/seeders/demo_data/wiki_seeder.rb +++ b/app/seeders/demo_data/wiki_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/app/seeders/demo_data/work_package_seeder.rb b/app/seeders/demo_data/work_package_seeder.rb index 2127318d27..d089e0bdee 100644 --- a/app/seeders/demo_data/work_package_seeder.rb +++ b/app/seeders/demo_data/work_package_seeder.rb @@ -102,15 +102,15 @@ module DemoData def base_work_package_attributes(attributes) { - project: project, - author: user, - assigned_to: find_principal(attributes[:assignee]), - subject: attributes[:subject], - description: attributes[:description], - status: find_status(attributes), - type: find_type(attributes), - priority: find_priority(attributes) || IssuePriority.default, - parent: WorkPackage.find_by(subject: attributes[:parent]) + project: project, + author: user, + assigned_to: find_principal(attributes[:assignee]), + subject: attributes[:subject], + description: attributes[:description], + status: find_status(attributes), + type: find_type(attributes), + priority: find_priority(attributes) || IssuePriority.default, + parent: WorkPackage.find_by(subject: attributes[:parent]) } end diff --git a/app/seeders/development_data/custom_fields_seeder.rb b/app/seeders/development_data/custom_fields_seeder.rb index b8a6fc27ba..75481aa407 100644 --- a/app/seeders/development_data/custom_fields_seeder.rb +++ b/app/seeders/development_data/custom_fields_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -100,7 +101,7 @@ module DevelopmentData print_status '.' cfs - rescue => e + rescue StandardError => e binding.pry end diff --git a/app/seeders/development_data/projects_seeder.rb b/app/seeders/development_data/projects_seeder.rb index dd98b3e739..2be9cdfd20 100644 --- a/app/seeders/development_data/projects_seeder.rb +++ b/app/seeders/development_data/projects_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -82,8 +83,8 @@ module DevelopmentData if version_data.is_a? Array version_data.each do |attributes| p.versions << Version.create!( - name: attributes[:name], - status: attributes[:status], + name: attributes[:name], + status: attributes[:status], sharing: attributes[:sharing] ) end @@ -98,10 +99,10 @@ module DevelopmentData def project_data(identifier) { - name: identifier.humanize, - identifier: identifier, + name: identifier.humanize, + identifier: identifier, enabled_module_names: project_modules, - types: Type.all + types: Type.all } end diff --git a/app/seeders/development_data/users_seeder.rb b/app/seeders/development_data/users_seeder.rb index 4b72911903..37eec58a61 100644 --- a/app/seeders/development_data/users_seeder.rb +++ b/app/seeders/development_data/users_seeder.rb @@ -27,6 +27,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/app/seeders/development_data_seeder.rb b/app/seeders/development_data_seeder.rb index 4a954d57c3..5eb6864b7c 100644 --- a/app/seeders/development_data_seeder.rb +++ b/app/seeders/development_data_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,8 +32,8 @@ class DevelopmentDataSeeder < CompositeSeeder [ DevelopmentData::UsersSeeder, DevelopmentData::CustomFieldsSeeder, - DevelopmentData::ProjectsSeeder, - #DevelopmentData::WorkPackageSeeder + DevelopmentData::ProjectsSeeder + # DevelopmentData::WorkPackageSeeder ] end diff --git a/app/seeders/random_data/forum_seeder.rb b/app/seeders/random_data/forum_seeder.rb index 0c18667c36..74055f7dd1 100644 --- a/app/seeders/random_data/forum_seeder.rb +++ b/app/seeders/random_data/forum_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/app/seeders/random_data/news_seeder.rb b/app/seeders/random_data/news_seeder.rb index 9708dad0a3..93bd9a1bfa 100644 --- a/app/seeders/random_data/news_seeder.rb +++ b/app/seeders/random_data/news_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/app/seeders/random_data/wiki_seeder.rb b/app/seeders/random_data/wiki_seeder.rb index 7a94849b06..6cf1621e53 100644 --- a/app/seeders/random_data/wiki_seeder.rb +++ b/app/seeders/random_data/wiki_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -36,7 +37,7 @@ module RandomData rand(5).times do print_status '.' wiki_page = WikiPage.create( - wiki: project.wiki, + wiki: project.wiki, title: Faker::Lorem.words(5).join(' ') ) @@ -44,9 +45,9 @@ module RandomData rand(5).times do print_status '.' wiki_content = WikiContent.create( - page: wiki_page, - author: user, - text: Faker::Lorem.paragraph(5, true, 3) + page: wiki_page, + author: user, + text: Faker::Lorem.paragraph(5, true, 3) ) ## create some journal entries diff --git a/app/seeders/random_data/work_package_seeder.rb b/app/seeders/random_data/work_package_seeder.rb index 12c0da53fc..c214c37b79 100644 --- a/app/seeders/random_data/work_package_seeder.rb +++ b/app/seeders/random_data/work_package_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -50,13 +51,13 @@ module RandomData rand(50).times do print_status '.' work_package = WorkPackage.create!( - project: project, - author: user, - subject: Faker::Lorem.words(8).join(' '), - status: statuses.sample, - type: types.sample, - start_date: s = Date.today - (25 - rand(50)).days, - due_date: s + (1 + rand(120)).days + project: project, + author: user, + subject: Faker::Lorem.words(8).join(' '), + status: statuses.sample, + type: types.sample, + start_date: s = Date.today - rand(-24..25).days, + due_date: s + rand(1..120).days ) work_package.priority = IssuePriority.all.sample work_package.description = Faker::Lorem.paragraph(5, true, 3) @@ -79,14 +80,14 @@ module RandomData 2.times do |changeset_count| print_status '.' changeset = Changeset.create( - repository: repository, - user: user, - revision: work_package.id * 10 + changeset_count, - scmid: work_package.id * 10 + changeset_count, - work_packages: [work_package], - committer: Faker::Name.name, - committed_on: Date.today, - comments: Faker::Lorem.words(8).join(' ') + repository: repository, + user: user, + revision: work_package.id * 10 + changeset_count, + scmid: work_package.id * 10 + changeset_count, + work_packages: [work_package], + committer: Faker::Name.name, + committed_on: Date.today, + comments: Faker::Lorem.words(8).join(' ') ) 5.times do @@ -104,7 +105,7 @@ module RandomData changeset.save! rand(5).times do - print_status'.' + print_status '.' changeset.reload changeset.committer = Faker::Name.name if rand(99).even? @@ -119,12 +120,12 @@ module RandomData def add_time_entries(work_package) 5.times do |time_entry_count| time_entry = TimeEntry.create( - project: project, - user: user, - work_package: work_package, - spent_on: Date.today + time_entry_count, - activity: time_entry_activities.sample, - hours: time_entry_count + project: project, + user: user, + work_package: work_package, + spent_on: Date.today + time_entry_count, + activity: time_entry_activities.sample, + hours: time_entry_count ) work_package.time_entries << time_entry end @@ -135,8 +136,8 @@ module RandomData file = OpenProject::Files.create_uploaded_file(name: Faker::Lorem.words(8).join(' ')) attachment = Attachment.new( container: work_package, - author: user, - file: file + author: user, + file: file ) attachment.save! @@ -148,7 +149,7 @@ module RandomData project.work_package_custom_fields.each do |custom_field| work_package.type.custom_fields << custom_field if !work_package.type.custom_fields.include?(custom_field) work_package.custom_values << CustomValue.new(custom_field: custom_field, - value: Faker::Lorem.words(8).join(' ')) + value: Faker::Lorem.words(8).join(' ')) end work_package.type.save! diff --git a/app/seeders/random_data_seeder.rb b/app/seeders/random_data_seeder.rb index c8f4da4506..bb45c65412 100644 --- a/app/seeders/random_data_seeder.rb +++ b/app/seeders/random_data_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -46,9 +47,11 @@ class RandomDataSeeder puts " # %02d %-23s #" % [WorkPackage.where(project_id: project.id).count, 'issues created.'] puts " # %02d %-23s #" % [Message.joins(:board).where(boards: { project_id: project.id }).count, 'messages created.'] puts " # %02d %-23s #" % [News.where(project_id: project.id).count, 'news created.'] - puts " # %02d %-23s #" % [WikiContent.joins(page: [:wiki]).where('wikis.project_id = ?', project.id).count, 'wiki contents created.'] + puts " # %02d %-23s #" % [WikiContent.joins(page: [:wiki]).where('wikis.project_id = ?', project.id).count, + 'wiki contents created.'] puts " # %02d %-23s #" % [TimeEntry.where(project_id: project.id).count, 'time entries created.'] - puts " # %02d %-23s #" % [Changeset.joins(:repository).where(repositories: { project_id: project.id }).count, 'changesets created.'] + puts " # %02d %-23s #" % [Changeset.joins(:repository).where(repositories: { project_id: project.id }).count, + 'changesets created.'] puts " ################################\n\n" end end diff --git a/app/seeders/root_seeder.rb b/app/seeders/root_seeder.rb index 87591ef854..2203241dcf 100644 --- a/app/seeders/root_seeder.rb +++ b/app/seeders/root_seeder.rb @@ -127,7 +127,7 @@ class RootSeeder < Seeder # Load FactoryBot factories begin ::FactoryBot.find_definitions - rescue => e + rescue StandardError => e raise e unless e.message.downcase.include? "factory already registered" end diff --git a/app/seeders/standard_seeder/basic_data/priority_seeder.rb b/app/seeders/standard_seeder/basic_data/priority_seeder.rb index 9b1692c5b8..c0c473dad9 100644 --- a/app/seeders/standard_seeder/basic_data/priority_seeder.rb +++ b/app/seeders/standard_seeder/basic_data/priority_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/seeders/standard_seeder/basic_data/status_seeder.rb b/app/seeders/standard_seeder/basic_data/status_seeder.rb index 504ef76176..184b3b47b8 100644 --- a/app/seeders/standard_seeder/basic_data/status_seeder.rb +++ b/app/seeders/standard_seeder/basic_data/status_seeder.rb @@ -55,20 +55,34 @@ module StandardSeeder colors = color_names.collect { |name| colors_by_name[name].id } [ - { name: I18n.t(:default_status_new), color_id: colors[0], is_closed: false, is_default: true, position: 1 }, - { name: I18n.t(:default_status_in_specification), color_id: colors[1], is_closed: false, is_default: false, position: 2 }, - { name: I18n.t(:default_status_specified), color_id: colors[2], is_closed: false, is_default: false, position: 3 }, - { name: I18n.t(:default_status_confirmed), color_id: colors[3], is_closed: false, is_default: false, position: 4 }, - { name: I18n.t(:default_status_to_be_scheduled), color_id: colors[4], is_closed: false, is_default: false, position: 5 }, - { name: I18n.t(:default_status_scheduled), color_id: colors[5], is_closed: false, is_default: false, position: 6 }, - { name: I18n.t(:default_status_in_progress), color_id: colors[6], is_closed: false, is_default: false, position: 7 }, - { name: I18n.t(:default_status_developed), color_id: colors[8], is_closed: false, is_default: false, position: 9 }, - { name: I18n.t(:default_status_in_testing), color_id: colors[9], is_closed: false, is_default: false, position: 10 }, - { name: I18n.t(:default_status_tested), color_id: colors[10], is_closed: false, is_default: false, position: 11 }, - { name: I18n.t(:default_status_test_failed), color_id: colors[11], is_closed: false, is_default: false, position: 12 }, - { name: I18n.t(:default_status_closed), color_id: colors[12], is_closed: true, is_default: false, position: 13 }, - { name: I18n.t(:default_status_on_hold), color_id: colors[13], is_closed: false, is_default: false, position: 14 }, - { name: I18n.t(:default_status_rejected), color_id: colors[14], is_closed: true, is_default: false, position: 15 } + { name: I18n.t(:default_status_new), color_id: colors[0], is_closed: false, is_default: true, + position: 1 }, + { name: I18n.t(:default_status_in_specification), color_id: colors[1], is_closed: false, is_default: false, + position: 2 }, + { name: I18n.t(:default_status_specified), color_id: colors[2], is_closed: false, is_default: false, + position: 3 }, + { name: I18n.t(:default_status_confirmed), color_id: colors[3], is_closed: false, is_default: false, + position: 4 }, + { name: I18n.t(:default_status_to_be_scheduled), color_id: colors[4], is_closed: false, is_default: false, + position: 5 }, + { name: I18n.t(:default_status_scheduled), color_id: colors[5], is_closed: false, is_default: false, + position: 6 }, + { name: I18n.t(:default_status_in_progress), color_id: colors[6], is_closed: false, is_default: false, + position: 7 }, + { name: I18n.t(:default_status_developed), color_id: colors[8], is_closed: false, is_default: false, + position: 9 }, + { name: I18n.t(:default_status_in_testing), color_id: colors[9], is_closed: false, is_default: false, + position: 10 }, + { name: I18n.t(:default_status_tested), color_id: colors[10], is_closed: false, is_default: false, + position: 11 }, + { name: I18n.t(:default_status_test_failed), color_id: colors[11], is_closed: false, is_default: false, + position: 12 }, + { name: I18n.t(:default_status_closed), color_id: colors[12], is_closed: true, is_default: false, + position: 13 }, + { name: I18n.t(:default_status_on_hold), color_id: colors[13], is_closed: false, is_default: false, + position: 14 }, + { name: I18n.t(:default_status_rejected), color_id: colors[14], is_closed: true, is_default: false, + position: 15 } ] end end diff --git a/app/seeders/standard_seeder/basic_data/type_seeder.rb b/app/seeders/standard_seeder/basic_data/type_seeder.rb index 4880a79f51..84866718b7 100644 --- a/app/seeders/standard_seeder/basic_data/type_seeder.rb +++ b/app/seeders/standard_seeder/basic_data/type_seeder.rb @@ -36,13 +36,13 @@ module StandardSeeder def type_table { # position is_default color_id is_in_roadmap is_milestone - task: [1, true, I18n.t(:default_color_blue), true, false, :default_type_task], - milestone: [2, true, I18n.t(:default_color_green_light), false, true, :default_type_milestone], - phase: [3, true, 'orange-5', false, false, :default_type_phase], - feature: [4, false, 'indigo-5', true, false, :default_type_feature], - epic: [5, false, 'violet-5', true, false, :default_type_epic], - user_story: [6, false, I18n.t(:default_color_blue_light), true, false, :default_type_user_story], - bug: [7, false, 'red-7', true, false, :default_type_bug] + task: [1, true, I18n.t(:default_color_blue), true, false, :default_type_task], + milestone: [2, true, I18n.t(:default_color_green_light), false, true, :default_type_milestone], + phase: [3, true, 'orange-5', false, false, :default_type_phase], + feature: [4, false, 'indigo-5', true, false, :default_type_feature], + epic: [5, false, 'violet-5', true, false, :default_type_epic], + user_story: [6, false, I18n.t(:default_color_blue_light), true, false, :default_type_user_story], + bug: [7, false, 'red-7', true, false, :default_type_bug] } end end diff --git a/app/seeders/standard_seeder/basic_data/workflow_seeder.rb b/app/seeders/standard_seeder/basic_data/workflow_seeder.rb index 2b4e2bb245..f96153642d 100644 --- a/app/seeders/standard_seeder/basic_data/workflow_seeder.rb +++ b/app/seeders/standard_seeder/basic_data/workflow_seeder.rb @@ -50,13 +50,17 @@ module StandardSeeder rejected = Status.find_by(name: I18n.t(:default_status_rejected)) { - types[I18n.t(:default_type_task)] => [new, in_progress, on_hold, rejected, closed], - types[I18n.t(:default_type_milestone)] => [new, to_be_scheduled, scheduled, in_progress, on_hold, rejected, closed], - types[I18n.t(:default_type_phase)] => [new, to_be_scheduled, scheduled, in_progress, on_hold, rejected, closed], - types[I18n.t(:default_type_feature)] => [new, in_specification, specified, in_progress, developed, in_testing, tested, test_failed, on_hold, rejected, closed], - types[I18n.t(:default_type_epic)] => [new, in_specification, specified, in_progress, developed, in_testing, tested, test_failed, on_hold, rejected, closed], - types[I18n.t(:default_type_user_story)] => [new, in_specification, specified, in_progress, developed, in_testing, tested, test_failed, on_hold, rejected, closed], - types[I18n.t(:default_type_bug)] => [new, confirmed, in_progress, developed, in_testing, tested, test_failed, on_hold, rejected, closed] + types[I18n.t(:default_type_task)] => [new, in_progress, on_hold, rejected, closed], + types[I18n.t(:default_type_milestone)] => [new, to_be_scheduled, scheduled, in_progress, on_hold, rejected, closed], + types[I18n.t(:default_type_phase)] => [new, to_be_scheduled, scheduled, in_progress, on_hold, rejected, closed], + types[I18n.t(:default_type_feature)] => [new, in_specification, specified, in_progress, developed, in_testing, + tested, test_failed, on_hold, rejected, closed], + types[I18n.t(:default_type_epic)] => [new, in_specification, specified, in_progress, developed, in_testing, + tested, test_failed, on_hold, rejected, closed], + types[I18n.t(:default_type_user_story)] => [new, in_specification, specified, in_progress, developed, in_testing, + tested, test_failed, on_hold, rejected, closed], + types[I18n.t(:default_type_bug)] => [new, confirmed, in_progress, developed, in_testing, tested, test_failed, + on_hold, rejected, closed] } end diff --git a/app/services/add_work_package_note_service.rb b/app/services/add_work_package_note_service.rb index e3cada9c6b..3b3b39dee9 100644 --- a/app/services/add_work_package_note_service.rb +++ b/app/services/add_work_package_note_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/api/v3/parse_query_params_service.rb b/app/services/api/v3/parse_query_params_service.rb index b99a0a80d1..766253e503 100644 --- a/app/services/api/v3/parse_query_params_service.rb +++ b/app/services/api/v3/parse_query_params_service.rb @@ -53,9 +53,9 @@ module API } ServiceResult.new success: true, result: parsed - rescue ::JSON::ParserError => error + rescue ::JSON::ParserError => e result = ServiceResult.new success: false - result.errors.add(:base, error.message) + result.errors.add(:base, e.message) result end diff --git a/app/services/attachments/replace_attachments.rb b/app/services/attachments/replace_attachments.rb index 0f2e8f9dad..49b61dd683 100644 --- a/app/services/attachments/replace_attachments.rb +++ b/app/services/attachments/replace_attachments.rb @@ -38,8 +38,8 @@ module Attachments def set_attributes(attributes) call = super - if call.success? - call.result.attachments = call.result.attachments_replacements if call.result.attachments_replacements + if call.success? && call.result.attachments_replacements + call.result.attachments = call.result.attachments_replacements end call diff --git a/app/services/authorization.rb b/app/services/authorization.rb index dbbd10d789..9a61f71c7c 100644 --- a/app/services/authorization.rb +++ b/app/services/authorization.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/abstract_query.rb b/app/services/authorization/abstract_query.rb index 0f2c166dba..0894f482b8 100644 --- a/app/services/authorization/abstract_query.rb +++ b/app/services/authorization/abstract_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/abstract_user_query.rb b/app/services/authorization/abstract_user_query.rb index a261915bf5..ceea7b2c64 100644 --- a/app/services/authorization/abstract_user_query.rb +++ b/app/services/authorization/abstract_user_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/project_query.rb b/app/services/authorization/project_query.rb index 93e02c53f1..046443e67a 100644 --- a/app/services/authorization/project_query.rb +++ b/app/services/authorization/project_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -203,8 +204,8 @@ class Authorization::ProjectQuery < Authorization::AbstractQuery transformations.register :all, :assigned_roles_join, - after: [:permission_roles_join, - :members_member_roles_join] do |statement, user, action| + after: %i[permission_roles_join + members_member_roles_join] do |statement, user, action| if user.admin? statement else diff --git a/app/services/authorization/query_transformation.rb b/app/services/authorization/query_transformation.rb index 7e31985c95..79ebf349c6 100644 --- a/app/services/authorization/query_transformation.rb +++ b/app/services/authorization/query_transformation.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/query_transformation_visitor.rb b/app/services/authorization/query_transformation_visitor.rb index 85c9d0ec6b..f1c1173eed 100644 --- a/app/services/authorization/query_transformation_visitor.rb +++ b/app/services/authorization/query_transformation_visitor.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -# rubocop:disable MethodName +# rubocop:disable Naming/MethodName class Authorization::QueryTransformationVisitor < Arel::Visitors::Visitor attr_accessor :transformations, diff --git a/app/services/authorization/query_transformations.rb b/app/services/authorization/query_transformations.rb index 1d17460f34..a77bc1aeca 100644 --- a/app/services/authorization/query_transformations.rb +++ b/app/services/authorization/query_transformations.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/query_transformations_order.rb b/app/services/authorization/query_transformations_order.rb index 8a3669cdfe..73684d201b 100644 --- a/app/services/authorization/query_transformations_order.rb +++ b/app/services/authorization/query_transformations_order.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -45,9 +46,9 @@ class Authorization::QueryTransformationsOrder attr_accessor :array def transformation_partial_orders - map { |transformation| + map do |transformation| transformation.after + [transformation.name] + transformation.before - } + end end def merge_transformation_partial_orders(partial_orders) diff --git a/app/services/authorization/user_allowed_query.rb b/app/services/authorization/user_allowed_query.rb index 9d00ca198f..ddec95496b 100644 --- a/app/services/authorization/user_allowed_query.rb +++ b/app/services/authorization/user_allowed_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/user_global_roles_query.rb b/app/services/authorization/user_global_roles_query.rb index f9bc5fee4a..39024bf774 100644 --- a/app/services/authorization/user_global_roles_query.rb +++ b/app/services/authorization/user_global_roles_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization/user_roles_query.rb b/app/services/authorization/user_roles_query.rb index 189eaa4e1d..bbe45c5cb3 100644 --- a/app/services/authorization/user_roles_query.rb +++ b/app/services/authorization/user_roles_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/authorization_service.rb b/app/services/authorization_service.rb index eb8990f9f5..29fe66584d 100644 --- a/app/services/authorization_service.rb +++ b/app/services/authorization_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/base_project_service.rb b/app/services/base_project_service.rb index 4c3f7b992f..30baad7412 100644 --- a/app/services/base_project_service.rb +++ b/app/services/base_project_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/base_services/update.rb b/app/services/base_services/update.rb index cd9b7312c7..8045846f86 100644 --- a/app/services/base_services/update.rb +++ b/app/services/base_services/update.rb @@ -30,7 +30,6 @@ module BaseServices class Update < Write - def initialize(user:, model:, contract_class: nil, contract_options: {}) self.model = model super(user: user, contract_class: contract_class, contract_options: contract_options) diff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rb index dfa6b4a98c..7674d71b72 100644 --- a/app/services/base_type_service.rb +++ b/app/services/base_type_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,8 +32,7 @@ class BaseTypeService include Shared::BlockService include Contracted - attr_accessor :contract_class - attr_accessor :type, :user + attr_accessor :contract_class, :type, :user def initialize(type, user) self.type = type @@ -74,7 +74,7 @@ class BaseTypeService ServiceResult.new(success: success, errors: errors, result: type) - rescue => e + rescue StandardError => e ServiceResult.new(success: false).tap do |result| result.errors.add(:base, e.message) end diff --git a/app/services/concerns/with_reversible_state.rb b/app/services/concerns/with_reversible_state.rb index f25f98ec34..b6b074ceb9 100644 --- a/app/services/concerns/with_reversible_state.rb +++ b/app/services/concerns/with_reversible_state.rb @@ -33,6 +33,7 @@ module WithReversibleState included do attr_reader :state + around_call :assign_state ## diff --git a/app/services/copy/concerns/copy_attachments.rb b/app/services/copy/concerns/copy_attachments.rb index d289db547b..6a35882baf 100644 --- a/app/services/copy/concerns/copy_attachments.rb +++ b/app/services/copy/concerns/copy_attachments.rb @@ -1,7 +1,6 @@ module Copy module Concerns module CopyAttachments - ## # Tries to copy the given attachment between containers def copy_attachments(from_container, to_container_id) @@ -22,4 +21,4 @@ module Copy end end end -end \ No newline at end of file +end diff --git a/app/services/create_type_service.rb b/app/services/create_type_service.rb index c55d011c75..1c52b20a11 100644 --- a/app/services/create_type_service.rb +++ b/app/services/create_type_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/groups/add_users_service.rb b/app/services/groups/add_users_service.rb index 4f8c212ed0..a17cf6da70 100644 --- a/app/services/groups/add_users_service.rb +++ b/app/services/groups/add_users_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/members/edit_membership_service.rb b/app/services/members/edit_membership_service.rb index 79abd6fb4a..9df8a7363b 100644 --- a/app/services/members/edit_membership_service.rb +++ b/app/services/members/edit_membership_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -39,7 +40,6 @@ module Members def call(attributes: {}) User.execute_as current_user do - process_attributes! attributes unless validate_attributes! attributes diff --git a/app/services/params_to_query_service.rb b/app/services/params_to_query_service.rb index 680bc245f7..a0fb85ed1b 100644 --- a/app/services/params_to_query_service.rb +++ b/app/services/params_to_query_service.rb @@ -39,9 +39,7 @@ class ParamsToQueryService query = new_query query = apply_filters(query, params) - query = apply_order(query, params) - - query + apply_order(query, params) end private diff --git a/app/services/parse_schema_filter_params_service.rb b/app/services/parse_schema_filter_params_service.rb index 5b2dd09544..3813b09939 100644 --- a/app/services/parse_schema_filter_params_service.rb +++ b/app/services/parse_schema_filter_params_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rb index ef83604edd..c1a23c96c9 100644 --- a/app/services/projects/copy/work_packages_dependent_service.rb +++ b/app/services/projects/copy/work_packages_dependent_service.rb @@ -121,7 +121,6 @@ module Projects::Copy new_relation.to_id = new_wp_id new_relation.save end - end def copy_work_package_attribute_overrides(source_work_package, parent_id, user_cf_ids) diff --git a/app/services/projects/copy_service.rb b/app/services/projects/copy_service.rb index c1b315b14b..7badad458b 100644 --- a/app/services/projects/copy_service.rb +++ b/app/services/projects/copy_service.rb @@ -109,14 +109,16 @@ module Projects end def cleanup_target_project_params(_source, _target, target_project_params) - if (parent_id = target_project_params[:parent_id]) && (parent = Project.find_by(id: parent_id)) - target_project_params.delete(:parent_id) unless user.allowed_to?(:add_subprojects, parent) + if (parent_id = target_project_params[:parent_id]) && (parent = Project.find_by(id: parent_id)) && !user.allowed_to?( + :add_subprojects, parent + ) + target_project_params.delete(:parent_id) end end - def cleanup_target_project_attributes(source, target, target_project_params) - if target.parent - target.parent = nil unless user.allowed_to?(:add_subprojects, target.parent) + def cleanup_target_project_attributes(_source, target, _target_project_params) + if target.parent && !user.allowed_to?(:add_subprojects, target.parent) + target.parent = nil end end diff --git a/app/services/queries/base_service.rb b/app/services/queries/base_service.rb index f8aedf284a..d1732ede97 100644 --- a/app/services/queries/base_service.rb +++ b/app/services/queries/base_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/queries/copy_service.rb b/app/services/queries/copy_service.rb index a95c5363ae..8a51f2a14c 100644 --- a/app/services/queries/copy_service.rb +++ b/app/services/queries/copy_service.rb @@ -39,7 +39,7 @@ module Queries ] end - def initialize_copy(source, params) + def initialize_copy(source, _params) new_query = ::Query.new source.attributes.dup.except(*skipped_attributes) new_query.sort_criteria = source.sort_criteria if source.sort_criteria new_query.project = state.project || source.project diff --git a/app/services/queries/create_service.rb b/app/services/queries/create_service.rb index 68b0247638..b89ba49a21 100644 --- a/app/services/queries/create_service.rb +++ b/app/services/queries/create_service.rb @@ -39,7 +39,6 @@ class Queries::CreateService < Queries::BaseService super end - private def remove_invalid_order(query) diff --git a/app/services/reports/assignee_report.rb b/app/services/reports/assignee_report.rb index 8d49c51d6a..ace978c54d 100644 --- a/app/services/reports/assignee_report.rb +++ b/app/services/reports/assignee_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/author_report.rb b/app/services/reports/author_report.rb index 65aa6e9f28..0bfe68d355 100644 --- a/app/services/reports/author_report.rb +++ b/app/services/reports/author_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/category_report.rb b/app/services/reports/category_report.rb index 10e1ff8dd3..68b9cb44b3 100644 --- a/app/services/reports/category_report.rb +++ b/app/services/reports/category_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/priority_report.rb b/app/services/reports/priority_report.rb index d9e301085d..4f4cf9909c 100644 --- a/app/services/reports/priority_report.rb +++ b/app/services/reports/priority_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/report.rb b/app/services/reports/report.rb index 27b4cee7b7..c01168000f 100644 --- a/app/services/reports/report.rb +++ b/app/services/reports/report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/reports_service.rb b/app/services/reports/reports_service.rb index d52127775d..19ec9e4efd 100644 --- a/app/services/reports/reports_service.rb +++ b/app/services/reports/reports_service.rb @@ -53,6 +53,7 @@ class Reports::ReportsService def initialize(project) raise 'You must provide a project to report upon' unless project&.is_a?(Project) + @project = project end diff --git a/app/services/reports/responsible_report.rb b/app/services/reports/responsible_report.rb index 180ecedb97..541ea94c7f 100644 --- a/app/services/reports/responsible_report.rb +++ b/app/services/reports/responsible_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/subproject_report.rb b/app/services/reports/subproject_report.rb index ebdc4af56b..7f24066355 100644 --- a/app/services/reports/subproject_report.rb +++ b/app/services/reports/subproject_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/type_report.rb b/app/services/reports/type_report.rb index 210bc00bac..623fdc05f6 100644 --- a/app/services/reports/type_report.rb +++ b/app/services/reports/type_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/reports/version_report.rb b/app/services/reports/version_report.rb index 697cfdcd05..5db17d4883 100644 --- a/app/services/reports/version_report.rb +++ b/app/services/reports/version_report.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/scm/base_repository_service.rb b/app/services/scm/base_repository_service.rb index b361161842..6e9156fffd 100644 --- a/app/services/scm/base_repository_service.rb +++ b/app/services/scm/base_repository_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/scm/checkout_instructions_service.rb b/app/services/scm/checkout_instructions_service.rb index 61f27720af..99c75f42b0 100644 --- a/app/services/scm/checkout_instructions_service.rb +++ b/app/services/scm/checkout_instructions_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -97,7 +98,6 @@ class SCM::CheckoutInstructionsService repository.supports_checkout_info? && !checkout_enabled? end - ## # Determines whether permissions for the given repository # are available. @@ -134,7 +134,7 @@ class SCM::CheckoutInstructionsService # because otherwise OpenProject does not control the repository permissions. # Use +manages_permissions?+ to check whether this is the case. def may_checkout? - [:readwrite, :read].include?(permission) + %i[readwrite read].include?(permission) end ## diff --git a/app/services/scm/create_managed_repository_service.rb b/app/services/scm/create_managed_repository_service.rb index 6f13454583..469e522f96 100644 --- a/app/services/scm/create_managed_repository_service.rb +++ b/app/services/scm/create_managed_repository_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/scm/delete_managed_repository_service.rb b/app/services/scm/delete_managed_repository_service.rb index 217690b901..4503f96b3b 100644 --- a/app/services/scm/delete_managed_repository_service.rb +++ b/app/services/scm/delete_managed_repository_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/scm/repository_factory_service.rb b/app/services/scm/repository_factory_service.rb index 5cd5e42eb9..4b6fecf59e 100644 --- a/app/services/scm/repository_factory_service.rb +++ b/app/services/scm/repository_factory_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/service_result.rb b/app/services/service_result.rb index d457971c2b..f604cce82c 100644 --- a/app/services/service_result.rb +++ b/app/services/service_result.rb @@ -119,7 +119,6 @@ class ServiceResult results.reject { |call| call.errors.empty? } end - def self_and_dependent [self] + dependent_results end @@ -191,7 +190,6 @@ class ServiceResult end end - def get_message_type if message_type.present? message_type.to_sym @@ -207,7 +205,7 @@ class ServiceResult end def merge_errors!(other) - self.errors.merge! other.errors + errors.merge! other.errors end def merge_dependent!(other) diff --git a/app/services/sessions/base_service.rb b/app/services/sessions/base_service.rb index 5f7d89968f..7f43bd87af 100644 --- a/app/services/sessions/base_service.rb +++ b/app/services/sessions/base_service.rb @@ -31,7 +31,6 @@ module Sessions class BaseService class << self - protected ## diff --git a/app/services/set_localization_service.rb b/app/services/set_localization_service.rb index c226f40810..9249a53426 100644 --- a/app/services/set_localization_service.rb +++ b/app/services/set_localization_service.rb @@ -1,5 +1,6 @@ class SetLocalizationService attr_reader :user, :http_accept_header + include Redmine::I18n def initialize(user, http_accept_header = nil) @@ -57,7 +58,7 @@ class SetLocalizationService end tmp - rescue + rescue StandardError nil end diff --git a/app/services/update_projects_types_service.rb b/app/services/update_projects_types_service.rb index 75a3eca8fe..19722dc7ad 100644 --- a/app/services/update_projects_types_service.rb +++ b/app/services/update_projects_types_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/update_type_service.rb b/app/services/update_type_service.rb index 862e45ba91..c36fd04a89 100644 --- a/app/services/update_type_service.rb +++ b/app/services/update_type_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/update_user_email_settings_service.rb b/app/services/update_user_email_settings_service.rb index 0accba9f3b..0f37c23033 100644 --- a/app/services/update_user_email_settings_service.rb +++ b/app/services/update_user_email_settings_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -57,10 +58,10 @@ UpdateUserEmailSettingsService = Struct.new(:user) do end def set_notified_project_ids(notified_project_ids) - if user.mail_notification == 'selected' - user.notified_project_ids = notified_project_ids - else - user.notified_project_ids = [] - end + user.notified_project_ids = if user.mail_notification == 'selected' + notified_project_ids + else + [] + end end end diff --git a/app/services/user_search_service.rb b/app/services/user_search_service.rb index 28c087ff8d..88f4c2e926 100644 --- a/app/services/user_search_service.rb +++ b/app/services/user_search_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -83,7 +84,8 @@ class UserSearchService unless params[:name].blank? name = "%#{params[:name].strip.downcase}%" - c << ['LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?', name, name, name, name] + c << ['LOWER(login) LIKE ? OR LOWER(firstname) LIKE ? OR LOWER(lastname) LIKE ? OR LOWER(mail) LIKE ?', name, name, name, + name] end scope.where(c.conditions) diff --git a/app/services/users/change_password_service.rb b/app/services/users/change_password_service.rb index bddc061eb1..a0e33e9797 100644 --- a/app/services/users/change_password_service.rb +++ b/app/services/users/change_password_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,8 +30,7 @@ module Users class ChangePasswordService - attr_accessor :current_user - attr_accessor :session + attr_accessor :current_user, :session def initialize(current_user:, session:) @current_user = current_user diff --git a/app/services/users/create_service.rb b/app/services/users/create_service.rb index ba26e80c66..b061798f3d 100644 --- a/app/services/users/create_service.rb +++ b/app/services/users/create_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,7 +33,6 @@ require 'concerns/user_invitation' module Users class CreateService < ::BaseServices::Create - private def persist(call) @@ -54,8 +54,6 @@ module Users end def invite_user!(new_user) - - invited = ::UserInvitation.invite_user! new_user new_user.errors.add :base, I18n.t(:error_can_not_invite_user) unless invited.is_a? User diff --git a/app/services/users/delete_service.rb b/app/services/users/delete_service.rb index 3bf0df3cb4..f82744216e 100644 --- a/app/services/users/delete_service.rb +++ b/app/services/users/delete_service.rb @@ -32,7 +32,6 @@ # Implements the deletion of a user. module Users class DeleteService < ::BaseServices::Delete - ## # Deletes the given user if allowed. # diff --git a/app/services/users/login_service.rb b/app/services/users/login_service.rb index 1256fe26c9..210683866a 100644 --- a/app/services/users/login_service.rb +++ b/app/services/users/login_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/users/logout_service.rb b/app/services/users/logout_service.rb index 09b36154e0..73ae8a8d61 100644 --- a/app/services/users/logout_service.rb +++ b/app/services/users/logout_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/users/register_user_service.rb b/app/services/users/register_user_service.rb index e3478f1009..e6c4b18b30 100644 --- a/app/services/users/register_user_service.rb +++ b/app/services/users/register_user_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/users/set_attributes_service.rb b/app/services/users/set_attributes_service.rb index 335ba5707b..50d89e2af1 100644 --- a/app/services/users/set_attributes_service.rb +++ b/app/services/users/set_attributes_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb index 89ed5763ed..9aff6544af 100644 --- a/app/services/users/update_service.rb +++ b/app/services/users/update_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/services/work_packages/move_service.rb b/app/services/work_packages/move_service.rb index 527391905b..373f5f3914 100644 --- a/app/services/work_packages/move_service.rb +++ b/app/services/work_packages/move_service.rb @@ -30,7 +30,6 @@ class WorkPackages::MoveService .descendants .order_by_ancestors('asc') .each do |wp| - copied = copy_with_updated_parent_id(wp, attributes, ancestors) result.add_dependent!(copied) diff --git a/app/uploaders/direct_fog_uploader.rb b/app/uploaders/direct_fog_uploader.rb index a40748d279..c070de5c25 100644 --- a/app/uploaders/direct_fog_uploader.rb +++ b/app/uploaders/direct_fog_uploader.rb @@ -18,7 +18,7 @@ class DirectFogUploader < FogFileUploader def for_uploader(fog_file_uploader) raise ArgumentError, "FogFileUploader expected" unless fog_file_uploader.is_a? FogFileUploader - uploader = self.new + uploader = new uploader.instance_variable_set "@file", fog_file_uploader.file uploader.instance_variable_set "@key", fog_file_uploader.path diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 78f41c64c1..55f940f516 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -49,7 +49,7 @@ module FileUploader file.to_file end - def download_url(options = {}) + def download_url(_options = {}) file.is_path? ? file.path : file.url end @@ -63,17 +63,17 @@ module FileUploader File.readable?(local_file) end - # store! nil's the cache_id after it finishes so we need to remember it for deletion - def remember_cache_id(_new_file) + # store! nil's the cache_id after it finishes so we need to remember it for deletion + def remember_cache_id(_new_file) @cache_id_was = cache_id end def delete_tmp_dir(_new_file) # make sure we don't delete other things accidentally by checking the name pattern - if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/ + if @cache_id_was.present? && @cache_id_was =~ /\A\d{8}-\d{4}-\d+-\d{4}\z/ FileUtils.rm_rf(File.join(cache_dir, @cache_id_was)) end - rescue => e + rescue StandardError => e Rails.logger.error "Failed cleanup of upload file #{@cache_id_was}: #{e}" end @@ -81,13 +81,13 @@ module FileUploader def cache!(new_file = sanitized_file) super @old_tmp_file = new_file - rescue => e + rescue StandardError => e Rails.logger.error "Failed cache! of temporary upload file: #{e}" end def delete_old_tmp_file(_dummy) @old_tmp_file.try :delete - rescue => e + rescue StandardError => e Rails.logger.error "Failed cleanup of temporary upload file: #{e}" end diff --git a/app/uploaders/local_file_uploader.rb b/app/uploaders/local_file_uploader.rb index 9fa2898082..e19a7080d5 100644 --- a/app/uploaders/local_file_uploader.rb +++ b/app/uploaders/local_file_uploader.rb @@ -39,7 +39,6 @@ class LocalFileUploader < CarrierWave::Uploader::Base after :store, :delete_tmp_dir after :store, :delete_old_tmp_file - def copy_to(attachment) attachment.file = local_file end diff --git a/app/validators/url_validator.rb b/app/validators/url_validator.rb index 2124a2a47f..73a8238c41 100644 --- a/app/validators/url_validator.rb +++ b/app/validators/url_validator.rb @@ -14,9 +14,10 @@ class UrlValidator < ActiveModel::EachValidator def parse(value) url = URI.parse(value) - rescue => e + rescue StandardError => e nil end + def allowed_protocols options.fetch(:allowed_protocols, %w(http https)) end diff --git a/app/views/common/feed.atom.builder b/app/views/common/feed.atom.builder index 4d8315e249..537b586d40 100644 --- a/app/views/common/feed.atom.builder +++ b/app/views/common/feed.atom.builder @@ -57,10 +57,12 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do xml.id url xml.updated item_event.event_datetime.xmlschema author = item_event.event_author if item_event.respond_to?(:event_author) - xml.author do - xml.name(author) - xml.email(author.mail) if author.is_a?(User) && !author.mail.blank? && !author.pref.hide_mail - end if author + if author + xml.author do + xml.name(author) + xml.email(author.mail) if author.is_a?(User) && !author.mail.blank? && !author.pref.hide_mail + end + end xml.content "type" => "html" do xml.text! format_text(item_event, :event_description, only_path: false) end diff --git a/app/views/journals/index.atom.builder b/app/views/journals/index.atom.builder index 0cff1136be..2b5c38404d 100644 --- a/app/views/journals/index.atom.builder +++ b/app/views/journals/index.atom.builder @@ -29,17 +29,18 @@ xml.instruct! xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do xml.title title - xml.link "rel" => "self", "href" => url_for(:format => 'atom', :key => User.current.rss_key, :only_path => false) - xml.link "rel" => "alternate", "href" => home_url(:only_path => false) + xml.link "rel" => "self", "href" => url_for(format: 'atom', key: User.current.rss_key, only_path: false) + xml.link "rel" => "alternate", "href" => home_url(only_path: false) xml.id url_for(controller: '/homescreen', action: :index, only_path: false) xml.updated((journals.first ? journals.first.created_at : Time.now).xmlschema) - xml.author { xml.name "#{Setting.app_title}" } + xml.author { xml.name Setting.app_title.to_s } journals.each do |change| work_package = change.journable xml.entry do xml.title "#{work_package.project.name} - #{work_package.type.name} ##{work_package.id}: #{work_package.subject}" xml.link "rel" => "alternate", "href" => work_package_url(work_package) - xml.id url_for(:controller => '/work_packages' , :action => 'show', :id => work_package, :journal_id => change, :only_path => false) + xml.id url_for(controller: '/work_packages', action: 'show', id: work_package, journal_id: change, + only_path: false) xml.updated change.created_at.xmlschema xml.author do xml.name change.user.name @@ -48,11 +49,11 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do xml.content "type" => "html" do xml.text! '' - xml.text! format_text(change, :notes, :only_path => false) unless change.notes.blank? + xml.text! format_text(change, :notes, only_path: false) unless change.notes.blank? end end end diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb index af11a52713..b2e6e31577 100644 --- a/app/workers/copy_project_job.rb +++ b/app/workers/copy_project_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/cron/clear_old_sessions_job.rb b/app/workers/cron/clear_old_sessions_job.rb index af4ce956cf..610ed00379 100644 --- a/app/workers/cron/clear_old_sessions_job.rb +++ b/app/workers/cron/clear_old_sessions_job.rb @@ -39,4 +39,4 @@ module Cron super 'db:sessions:expire', 7 end end -end \ No newline at end of file +end diff --git a/app/workers/cron/clear_tmp_cache_job.rb b/app/workers/cron/clear_tmp_cache_job.rb index a162b28159..9fdf59553d 100644 --- a/app/workers/cron/clear_tmp_cache_job.rb +++ b/app/workers/cron/clear_tmp_cache_job.rb @@ -39,4 +39,4 @@ module Cron super 'tmp:cache:clear' end end -end \ No newline at end of file +end diff --git a/app/workers/cron/clear_uploaded_files_job.rb b/app/workers/cron/clear_uploaded_files_job.rb index 76e0279819..61712ea1dc 100644 --- a/app/workers/cron/clear_uploaded_files_job.rb +++ b/app/workers/cron/clear_uploaded_files_job.rb @@ -39,4 +39,4 @@ module Cron super 'attachments:clear' end end -end \ No newline at end of file +end diff --git a/app/workers/cron/cron_job.rb b/app/workers/cron/cron_job.rb index db45080048..263aa4fcf6 100644 --- a/app/workers/cron/cron_job.rb +++ b/app/workers/cron/cron_job.rb @@ -75,4 +75,4 @@ module Cron end end end -end \ No newline at end of file +end diff --git a/app/workers/delete_user_job.rb b/app/workers/delete_user_job.rb index d95e1a2a25..a4a7744b90 100644 --- a/app/workers/delete_user_job.rb +++ b/app/workers/delete_user_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/deliver_invitation_job.rb b/app/workers/deliver_invitation_job.rb index b642b882f1..b02c5bd72f 100644 --- a/app/workers/deliver_invitation_job.rb +++ b/app/workers/deliver_invitation_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/deliver_notification_job.rb b/app/workers/deliver_notification_job.rb index 79a6200735..0a75e0ce4d 100644 --- a/app/workers/deliver_notification_job.rb +++ b/app/workers/deliver_notification_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/deliver_watcher_notification_job.rb b/app/workers/deliver_watcher_notification_job.rb index 8b15c4b86e..2b081ca575 100644 --- a/app/workers/deliver_watcher_notification_job.rb +++ b/app/workers/deliver_watcher_notification_job.rb @@ -35,7 +35,7 @@ class DeliverWatcherNotificationJob < DeliverNotificationJob super(recipient_id, watcher_changer_id) end - def render_mail(recipient:, sender:) # rubocop:disable UnusedMethodArgument + def render_mail(recipient:, sender:) # rubocop:disable Lint/UnusedMethodArgument raise NotImplementedError, 'Subclass has to implement #render_mail' end diff --git a/app/workers/deliver_work_package_notification_job.rb b/app/workers/deliver_work_package_notification_job.rb index 4b8236f715..20a1a59d12 100644 --- a/app/workers/deliver_work_package_notification_job.rb +++ b/app/workers/deliver_work_package_notification_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/mailer_job.rb b/app/workers/mailer_job.rb index e081c8b2ee..062f44b318 100644 --- a/app/workers/mailer_job.rb +++ b/app/workers/mailer_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/notify_journal_completed_job.rb b/app/workers/notify_journal_completed_job.rb index 95e13ad6a4..74c370ee09 100644 --- a/app/workers/notify_journal_completed_job.rb +++ b/app/workers/notify_journal_completed_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/rake_job.rb b/app/workers/rake_job.rb index 43ccae54f5..d51f83a632 100644 --- a/app/workers/rake_job.rb +++ b/app/workers/rake_job.rb @@ -31,8 +31,7 @@ require 'rake' # Invoke a rake task while safely loading the tasks only once # to ensure they are neither loaded nor executed twice. module RakeJob - attr_reader :task_name - attr_reader :args + attr_reader :task_name, :args def perform(task_name, *args) @task_name = task_name diff --git a/app/workers/scm/create_local_repository_job.rb b/app/workers/scm/create_local_repository_job.rb index 970e26fb15..ae6b26e7f3 100644 --- a/app/workers/scm/create_local_repository_job.rb +++ b/app/workers/scm/create_local_repository_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +36,6 @@ # creation and deletion of repositories BOTH on the database and filesystem. # Until then, a synchronous process is more failsafe. class SCM::CreateLocalRepositoryJob < ApplicationJob - def self.ensure_not_existing!(repository) # Cowardly refusing to override existing local repository if File.directory?(repository.root_url) @@ -102,6 +102,6 @@ class SCM::CreateLocalRepositoryJob < ApplicationJob end def default_mode - 0700 + 0o700 end end diff --git a/app/workers/scm/create_remote_repository_job.rb b/app/workers/scm/create_remote_repository_job.rb index 5b7c7debc6..c256fc85d6 100644 --- a/app/workers/scm/create_remote_repository_job.rb +++ b/app/workers/scm/create_remote_repository_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/app/workers/scm/delete_remote_repository_job.rb b/app/workers/scm/delete_remote_repository_job.rb index f6cb10d09d..b24e6f31f8 100644 --- a/app/workers/scm/delete_remote_repository_job.rb +++ b/app/workers/scm/delete_remote_repository_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +36,6 @@ # creation and deletion of repositories BOTH on the database and filesystem. # Until then, a synchronous process is more failsafe. class SCM::DeleteRemoteRepositoryJob < SCM::RemoteRepositoryJob - def perform(repository) super send_request(repository_request.merge(action: :delete)) diff --git a/app/workers/scm/relocate_repository_job.rb b/app/workers/scm/relocate_repository_job.rb index f5d239abac..f0b0a09fa8 100644 --- a/app/workers/scm/relocate_repository_job.rb +++ b/app/workers/scm/relocate_repository_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -48,8 +49,9 @@ class SCM::RelocateRepositoryJob < SCM::RemoteRepositoryJob # POST to the remote managed repository a request to relocate the repository def relocate_remote response = send_request(repository_request.merge( - action: :relocate, - old_identifier: File.basename(repository.root_url))) + action: :relocate, + old_identifier: File.basename(repository.root_url) + )) repository.root_url = response['path'] repository.url = response['url'] diff --git a/app/workers/scm/remote_repository_job.rb b/app/workers/scm/remote_repository_job.rb index c8a35f05e2..9865cc0c21 100644 --- a/app/workers/scm/remote_repository_job.rb +++ b/app/workers/scm/remote_repository_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -62,11 +63,10 @@ class SCM::RemoteRepositoryJob < ApplicationJob unless response.is_a? ::Net::HTTPSuccess raise OpenProject::SCM::Exceptions::SCMError.new( - I18n.t('repositories.errors.remote_call_failed', - code: response.code, - message: info['message'] - ) - ) + I18n.t('repositories.errors.remote_call_failed', + code: response.code, + message: info['message']) + ) end info @@ -76,8 +76,8 @@ class SCM::RemoteRepositoryJob < ApplicationJob JSON.parse(body) rescue JSON::JSONError => e raise OpenProject::SCM::Exceptions::SCMError.new( - I18n.t('repositories.errors.remote_invalid_response') - ) + I18n.t('repositories.errors.remote_invalid_response') + ) end def repository_request @@ -91,7 +91,7 @@ class SCM::RemoteRepositoryJob < ApplicationJob project: { id: project.id, name: project.name, - identifier: project.identifier, + identifier: project.identifier } } end diff --git a/app/workers/scm/storage_updater_job.rb b/app/workers/scm/storage_updater_job.rb index 45eb0ab80b..9fd4341dc4 100644 --- a/app/workers/scm/storage_updater_job.rb +++ b/app/workers/scm/storage_updater_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,7 +41,7 @@ class SCM::StorageUpdaterJob < ApplicationJob repository.update!( required_storage_bytes: bytes, - storage_updated_at: Time.now, + storage_updated_at: Time.now ) end diff --git a/bin/bundle b/bin/bundle index 4f5e057772..b7323241d9 100755 --- a/bin/bundle +++ b/bin/bundle @@ -24,6 +24,7 @@ m = Module.new do def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| @@ -31,6 +32,7 @@ m = Module.new do bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 || ">= 0.a" update_index = i end @@ -41,7 +43,7 @@ m = Module.new do gemfile = ENV["BUNDLE_GEMFILE"] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../../Gemfile", __FILE__) + File.expand_path('../Gemfile', __dir__) end def lockfile @@ -55,8 +57,10 @@ m = Module.new do def lockfile_version return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) end @@ -82,10 +86,12 @@ m = Module.new do gem "bundler", bundler_version end return if gem_error.nil? + require_error = activation_error_handling do require "bundler/version" end return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" exit 42 end diff --git a/bin/rails b/bin/rails index 5badb2fde0..7a8ff81e6e 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,6 @@ #!/usr/bin/env ruby begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/bin/rake b/bin/rake index d87d5f5781..0ba8c48cba 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,6 @@ #!/usr/bin/env ruby begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/bin/rspec b/bin/rspec index 2f121560cd..3b2d262437 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,6 +1,6 @@ #!/usr/bin/env ruby begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end @@ -15,9 +15,9 @@ end require "pathname" ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) + Pathname.new(__FILE__).realpath) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ diff --git a/bin/setup b/bin/setup index acdb2c1389..9608de1b1b 100755 --- a/bin/setup +++ b/bin/setup @@ -2,7 +2,7 @@ require 'pathname' # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) Dir.chdir APP_ROOT do # This script is a starting point to setup your application. diff --git a/config.ru b/config.ru index c9ee84dfba..cf04e1b402 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,7 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('config/environment', __dir__) ## # Use the worker killer when Unicorn is being used diff --git a/config/application.rb b/config/application.rb index 8709e2e541..bae4ef8fa7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,8 +37,8 @@ require 'core_extensions' # Silence deprecations early on for testing on CI and production ActiveSupport::Deprecation.silenced = - (Rails.env.production? && !ENV['OPENPROJECT_SHOW_DEPRECATIONS']) || - (Rails.env.test? && ENV['CI']) + (Rails.env.production? && !ENV['OPENPROJECT_SHOW_DEPRECATIONS']) || + (Rails.env.test? && ENV['CI']) if defined?(Bundler) # lib directory has to be added to the load path so that diff --git a/config/boot.rb b/config/boot.rb index 07f6fbbbd7..a7e6eede16 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) # Load any local boot extras that is kept out of source control # (e.g., silencing of deprecations) @@ -49,6 +50,6 @@ if env == 'production' && ENV['OPENPROJECT_PROD_DEPRECATIONS'] != 'true' end if env == 'development' - $stderr.puts "Starting with bootsnap." + warn "Starting with bootsnap." require 'bootsnap/setup' # Speed up boot time by caching expensive operations. end diff --git a/config/constants/ar_to_api_conversions.rb b/config/constants/ar_to_api_conversions.rb index 38dcda3464..63c89257ff 100644 --- a/config/constants/ar_to_api_conversions.rb +++ b/config/constants/ar_to_api_conversions.rb @@ -28,7 +28,6 @@ module Constants class ARToAPIConversions - # Conversions that are bidirectional: # * from the API to AR # * from AR to the API @@ -52,7 +51,7 @@ module Constants # This can be used to still support renamed filters/sort_by, like for created/updatedOn. WELL_KNOWN_API_TO_AR_CONVERSIONS = { created_on: 'created_at', - updated_on: 'updated_at', + updated_on: 'updated_at' }.freeze class << self diff --git a/config/constants/project_activity.rb b/config/constants/project_activity.rb index d374037501..3116acff02 100644 --- a/config/constants/project_activity.rb +++ b/config/constants/project_activity.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,7 +31,7 @@ module Constants module ProjectActivity class << self - def register(on:, chain: [], attribute:) + def register(on:, attribute:, chain: []) @registered ||= [] @registered << { on: on, diff --git a/config/environments/demo.rb b/config/environments/demo.rb index ba694da28f..2c14c66a4a 100644 --- a/config/environments/demo.rb +++ b/config/environments/demo.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/environments/development.rb b/config/environments/development.rb index c3b338af15..4cd6549136 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/environments/production.rb b/config/environments/production.rb index 34b24a1c62..6ccc63d1ac 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -127,7 +128,6 @@ OpenProject::Application.configure do config.logger = ActiveSupport::TaggedLogging.new(logger) end - config.active_record.dump_schema_after_migration = false if OpenProject::Configuration.enable_internal_assets_server? @@ -136,7 +136,7 @@ OpenProject::Application.configure do 'Access-Control-Allow-Origin' => '*', 'Access-Control-Allow-Methods' => 'GET, OPTIONS, HEAD', 'Cache-Control' => 'public, s-maxage=31536000, max-age=15552000', - 'Expires' => "#{1.year.from_now.to_formatted_s(:rfc822)}" + 'Expires' => 1.year.from_now.to_formatted_s(:rfc822).to_s } end end diff --git a/config/environments/test.rb b/config/environments/test.rb index 00465982f4..f7910db82e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/environments/test_pgsql.rb b/config/environments/test_pgsql.rb index a22ac21ffd..adce42fa5b 100644 --- a/config/environments/test_pgsql.rb +++ b/config/environments/test_pgsql.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/00-core_plugins.rb b/config/initializers/00-core_plugins.rb index 505912d404..bda785f0cb 100644 --- a/config/initializers/00-core_plugins.rb +++ b/config/initializers/00-core_plugins.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/10-load_patches.rb b/config/initializers/10-load_patches.rb index c510ddc1e7..e5f49a1bcd 100644 --- a/config/initializers/10-load_patches.rb +++ b/config/initializers/10-load_patches.rb @@ -31,6 +31,6 @@ # Do not place any patches within this file. Add a file to lib/open_project/patches # Whatever ruby file is placed in lib/open_project/patches is required -Dir.glob(File.expand_path("../../../lib/open_project/patches/*.rb", __FILE__)).each do |path| +Dir.glob(File.expand_path('../../lib/open_project/patches/*.rb', __dir__)).each do |path| require path end diff --git a/config/initializers/authentication_stages.rb b/config/initializers/authentication_stages.rb index 7847625826..88af7bc7c7 100644 --- a/config/initializers/authentication_stages.rb +++ b/config/initializers/authentication_stages.rb @@ -1,14 +1,13 @@ OpenProject::Application.configure do |application| - # Ensure stage is entered when reloading in dev mode application.config.to_prepare do OpenProject::Authentication::Stage .register( :consent, run_after_activation: true, - active: ->() { Setting.consent_required? } - ) { + active: -> { Setting.consent_required? } + ) do account_consent_path - } + end end end diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 083dcacd3b..4f00e54b4f 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/bcrypt.rb b/config/initializers/bcrypt.rb index 0ad8296247..daac28dea9 100644 --- a/config/initializers/bcrypt.rb +++ b/config/initializers/bcrypt.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,9 +33,9 @@ if OpenProject::Configuration.override_bcrypt_cost_factor? current = BCrypt::Engine.cost if cost_factor < 8 - Rails.logger.warn { + Rails.logger.warn do "Ignoring BCrypt cost factor #{cost_factor}. Using default (#{current})." - } + end else BCrypt::Engine.cost = cost_factor end diff --git a/config/initializers/bullet.rb b/config/initializers/bullet.rb index 27473c569d..6262707b0d 100644 --- a/config/initializers/bullet.rb +++ b/config/initializers/bullet.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/delayed_job_config.rb b/config/initializers/delayed_job_config.rb index 2cedf4bacb..0d7481b532 100644 --- a/config/initializers/delayed_job_config.rb +++ b/config/initializers/delayed_job_config.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index a1ce5c022b..7c8bd6f353 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -183,7 +183,7 @@ Doorkeeper.configure do # Rails.logger.info(params.inspect) # end # - after_successful_authorization do |controller| + after_successful_authorization do |_controller| # Schedule a cleanup job to clean out over-TTL tokens and grants ::OAuth::CleanupJob.perform_later end diff --git a/config/initializers/ee_token.rb b/config/initializers/ee_token.rb index 3c3860b10a..12c2f8a8ce 100644 --- a/config/initializers/ee_token.rb +++ b/config/initializers/ee_token.rb @@ -2,6 +2,6 @@ begin data = File.read(Rails.root.join(".openproject-token.pub")) key = OpenSSL::PKey::RSA.new(data) OpenProject::Token.key = key -rescue +rescue StandardError warn "WARNING: Missing .openproject-token.pub key" end diff --git a/config/initializers/enforce_isolation_level.rb b/config/initializers/enforce_isolation_level.rb index 6e05fda4f0..ac939dc851 100644 --- a/config/initializers/enforce_isolation_level.rb +++ b/config/initializers/enforce_isolation_level.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -50,8 +51,7 @@ module ConnectionIsolationLevel end end -ActiveRecord::ConnectionAdapters::ConnectionPool.send(:prepend, - ConnectionIsolationLevel::ConnectionPoolPatch) +ActiveRecord::ConnectionAdapters::ConnectionPool.prepend ConnectionIsolationLevel::ConnectionPoolPatch # in case the existing connection was created before our patch # N.B.: this assumes that our process only has this single thread, which is at least true today... diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 01558f77d5..49ae5abd3c 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/friendly_id.rb b/config/initializers/friendly_id.rb index 4860128dca..b3733cabec 100644 --- a/config/initializers/friendly_id.rb +++ b/config/initializers/friendly_id.rb @@ -17,7 +17,7 @@ FriendlyId.defaults do |config| config.use :reserved config.reserved_words = %w(new edit index session login logout users admin - stylesheets assets javascripts images) + stylesheets assets javascripts images) # ## Friendly Finders # diff --git a/config/initializers/health_checks.rb b/config/initializers/health_checks.rb index c947dd2c37..8905f2d737 100644 --- a/config/initializers/health_checks.rb +++ b/config/initializers/health_checks.rb @@ -48,6 +48,7 @@ class PumaCheck < OkComputer::Check def stats return nil unless applicable? + server = Puma::Server.current return nil if server.nil? diff --git a/config/initializers/homescreen.rb b/config/initializers/homescreen.rb index d7b563530e..9d6ed05f69 100644 --- a/config/initializers/homescreen.rb +++ b/config/initializers/homescreen.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -98,9 +99,9 @@ OpenProject::Static::Homescreen.manage :links do |links| if impressum_link = link_hash[:impressum] links.push({ - label: impressum_link[:label], - url: impressum_link[:href], - icon: 'icon-context icon-info1' - }) + label: impressum_link[:label], + url: impressum_link[:href], + icon: 'icon-context icon-info1' + }) end end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 60c96e5732..a74ae9e7f5 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/livingstyleguide_patches.rb b/config/initializers/livingstyleguide_patches.rb index ed7f78fb35..b2ac538259 100644 --- a/config/initializers/livingstyleguide_patches.rb +++ b/config/initializers/livingstyleguide_patches.rb @@ -45,4 +45,3 @@ if defined?(LivingStyleGuide) LivingStyleGuide::Document.prepend DocumentTemplatePatch end - diff --git a/config/initializers/locale_fallbacks.rb b/config/initializers/locale_fallbacks.rb index 8ea6767d6b..e337551452 100644 --- a/config/initializers/locale_fallbacks.rb +++ b/config/initializers/locale_fallbacks.rb @@ -29,7 +29,7 @@ #++ # Adds fallback to default locale for untranslated strings -I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) +I18n::Backend::Simple.include I18n::Backend::Fallbacks # As we enabled +config.i18n.fallbacks+, Rails will fall back # to the default locale. diff --git a/config/initializers/log_slow_sql_queries.rb b/config/initializers/log_slow_sql_queries.rb index bf5cc118d7..4438fec78b 100644 --- a/config/initializers/log_slow_sql_queries.rb +++ b/config/initializers/log_slow_sql_queries.rb @@ -17,10 +17,10 @@ OpenProject::Application.configure do duration: duration, time: start.iso8601, cached: !!data[:cache], - sql: data[:sql], + sql: data[:sql] } - sql_log_string = data[:sql].strip.gsub(/(^([\s]+)?$\n)/, "") + sql_log_string = data[:sql].strip.gsub(/(^(\s+)?$\n)/, "") OpenProject.logger.warn "Encountered slow SQL (#{payload[:duration]} ms): #{sql_log_string}", payload: payload, # Hash of the query for reference/fingerprinting diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb index 832329d35f..ad84bb7d28 100644 --- a/config/initializers/menus.rb +++ b/config/initializers/menus.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -370,7 +371,7 @@ Redmine::MenuManager.map :project_menu do |menu| icon: 'icon2 icon-view-timeline', html: { id: 'main-menu-work-packages', - :'wp-query-menu' => 'wp-query-menu' + 'wp-query-menu': 'wp-query-menu' } menu.push :work_packages_query_select, diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 343dd7e6ac..b232fb3f79 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/module_handler.rb b/config/initializers/module_handler.rb index 203ceb4623..f99601ab69 100644 --- a/config/initializers/module_handler.rb +++ b/config/initializers/module_handler.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 547e6dcc50..25e974c3ba 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -28,6 +28,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do unless Rails.env.production? - provider :developer, fields: [:first_name, :last_name, :email] + provider :developer, fields: %i[first_name last_name email] end end diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb index 0367213f80..2f22397de3 100644 --- a/config/initializers/permissions.rb +++ b/config/initializers/permissions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -110,20 +111,20 @@ OpenProject::AccessControl.map do |map| journals: %i[index diff], work_packages: %i[show index], work_packages_api: [:get], - :'work_packages/reports' => %i[report report_details] + 'work_packages/reports': %i[report report_details] wpt.permission :add_work_packages, {} wpt.permission :edit_work_packages, { - :'work_packages/bulk' => %i[edit update] + 'work_packages/bulk': %i[edit update] }, require: :member, dependencies: :view_work_packages wpt.permission :move_work_packages, - { :'work_packages/moves' => %i[new create] }, + { 'work_packages/moves': %i[new create] }, require: :loggedin, dependencies: :view_work_packages @@ -155,21 +156,21 @@ OpenProject::AccessControl.map do |map| wpt.permission :export_work_packages, { - work_packages: %i[index all], + work_packages: %i[index all] }, dependencies: :view_work_packages wpt.permission :delete_work_packages, { work_packages: :destroy, - :'work_packages/bulk' => :destroy + 'work_packages/bulk': :destroy }, require: :member, dependencies: :view_work_packages wpt.permission :manage_work_package_relations, { - work_package_relations: %i[create destroy], + work_package_relations: %i[create destroy] }, dependencies: :view_work_packages @@ -211,12 +212,12 @@ OpenProject::AccessControl.map do |map| news.permission :manage_news, { news: %i[new create edit update destroy preview], - :'news/comments' => [:destroy] + 'news/comments': [:destroy] }, require: :member news.permission :comment_news, - :'news/comments' => :create + 'news/comments': :create end map.project_module :wiki do |wiki| @@ -314,7 +315,7 @@ OpenProject::AccessControl.map do |map| map.project_module :calendar do |cal| cal.permission :view_calendar, - :'work_packages/calendars' => [:index] + 'work_packages/calendars': [:index] end map.project_module :activity diff --git a/config/initializers/rack-cors.rb b/config/initializers/rack-cors.rb index 892b326926..babec0d18b 100644 --- a/config/initializers/rack-cors.rb +++ b/config/initializers/rack-cors.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,7 @@ #++ Rails.application.config.middleware.insert_after Rails::Rack::Logger, Rack::Cors do allow do - origins { |source, env| ::API::V3::CORS.allowed?(source) } + origins { |source, _env| ::API::V3::CORS.allowed?(source) } resource '/api/v3*', headers: :any, methods: :any, diff --git a/config/initializers/rails_footnotes.rb b/config/initializers/rails_footnotes.rb index 6a9707764f..0173111c71 100644 --- a/config/initializers/rails_footnotes.rb +++ b/config/initializers/rails_footnotes.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/register_mail_interceptors.rb b/config/initializers/register_mail_interceptors.rb index bca827397a..de9bab245a 100644 --- a/config/initializers/register_mail_interceptors.rb +++ b/config/initializers/register_mail_interceptors.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/search.rb b/config/initializers/search.rb index adb1c53496..e871d3fcfa 100644 --- a/config/initializers/search.rb +++ b/config/initializers/search.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index d26e5025a0..d81b06e3c9 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -78,10 +79,10 @@ session_store = config['session_store'].to_sym relative_url_root = config['rails_relative_url_root'].presence session_options = { - key: config['session_cookie_name'], + key: config['session_cookie_name'], httponly: true, secure: Setting.https?, - path: relative_url_root + path: relative_url_root } if session_store == :cache_store diff --git a/config/initializers/time_with_zone_as_json.rb b/config/initializers/time_with_zone_as_json.rb index 6c7cb3484c..e60baf55ab 100644 --- a/config/initializers/time_with_zone_as_json.rb +++ b/config/initializers/time_with_zone_as_json.rb @@ -28,6 +28,6 @@ class ActiveSupport::TimeWithZone def as_json(_options = {}) - %(#{time.strftime('%m/%d/%Y/ %H:%M %p')}) + time.strftime('%m/%d/%Y/ %H:%M %p').to_s end end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index a755740978..2f4d8de05b 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/config/initializers/zeitwerk.rb b/config/initializers/zeitwerk.rb index aecb81c88f..966c562d63 100644 --- a/config/initializers/zeitwerk.rb +++ b/config/initializers/zeitwerk.rb @@ -2,7 +2,7 @@ require Rails.root.join('config/constants/open_project/inflector') OpenProject::Inflector.rule do |_, abspath| if abspath.match?(/open_project\/version(\.rb)?\z/) || - abspath.match?(/lib\/open_project\/\w+\/version(\.rb)?\z/) + abspath.match?(/lib\/open_project\/\w+\/version(\.rb)?\z/) "VERSION" end end @@ -40,7 +40,7 @@ end # we simply return the general OpenProject namespace for such files. OpenProject::Inflector.rule do |_basename, abspath| if abspath =~ /openproject-\w+\/lib\/openproject-\w+.rb\z/ || - abspath =~ /modules\/\w+\/lib\/openproject-\w+.rb\z/ + abspath =~ /modules\/\w+\/lib\/openproject-\w+.rb\z/ 'OpenProject' end end diff --git a/config/routes.rb b/config/routes.rb index 03adb1e8d9..d2a963f6b7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,7 +46,6 @@ OpenProject::Application.routes.draw do "#{rails_relative_url_root}/work_packages/#{URI::RFC2396_Parser.new.escape(params[:rest])}" } - # Respond with 410 gone for APIV2 calls match '/api/v2(/*unmatched_route)', to: proc { [410, {}, ['']] }, via: :all match '/assets/compiler.js.map', to: proc { [404, {}, ['']] }, via: :all @@ -299,29 +298,29 @@ OpenProject::Application.routes.draw do get '(/revisions/:rev)/diff(/*repo_path)', action: :diff, format: 'html', - constraints: { rev: /[\w0-9\.\-_]+/, repo_path: /.*/ } + constraints: { rev: /[\w0-9.\-_]+/, repo_path: /.*/ } get '(/revisions/:rev)/:format/*repo_path', action: :entry, format: /raw/, - rev: /[\w0-9\.\-_]+/ + rev: /[\w0-9.\-_]+/ %w{diff annotate changes entry browse}.each do |action| get "(/revisions/:rev)/#{action}(/*repo_path)", format: 'html', action: action, - constraints: { rev: /[\w0-9\.\-_]+/, repo_path: /.*/ }, + constraints: { rev: /[\w0-9.\-_]+/, repo_path: /.*/ }, as: "#{action}_revision" end - get '/revision(/:rev)', rev: /[\w0-9\.\-_]+/, + get '/revision(/:rev)', rev: /[\w0-9.\-_]+/, action: :revision, as: 'show_revision' get '(/revisions/:rev)(/*repo_path)', action: :show, format: 'html', - constraints: { rev: /[\w0-9\.\-_]+/, repo_path: /.*/ }, + constraints: { rev: /[\w0-9.\-_]+/, repo_path: /.*/ }, as: 'show_revisions_path' end end @@ -395,7 +394,7 @@ OpenProject::Application.routes.draw do resource :settings, only: %i(update show) do SettingsHelper.system_settings_tabs.each do |tab| - get tab[:name], controller: "settings/#{tab[:name]}", action: 'show', as: "#{tab[:name]}" + get tab[:name], controller: "settings/#{tab[:name]}", action: 'show', as: (tab[:name]).to_s patch tab[:name], controller: "settings/#{tab[:name]}", action: 'update', as: "update_#{tab[:name]}" end @@ -522,7 +521,8 @@ OpenProject::Application.routes.draw do # alternate routes for the current user scope 'my' do match '/deletion_info' => 'users#deletion_info', via: :get, as: 'delete_my_account_info' - match '/oauth/revoke_application/:application_id' => 'oauth/grants#revoke_application', via: :post, as: 'revoke_my_oauth_application' + match '/oauth/revoke_application/:application_id' => 'oauth/grants#revoke_application', via: :post, + as: 'revoke_my_oauth_application' end scope controller: 'my' do diff --git a/db/migrate/20180105130053_rebuild_dag.rb b/db/migrate/20180105130053_rebuild_dag.rb index 568f7c890b..1c9f388c47 100644 --- a/db/migrate/20180105130053_rebuild_dag.rb +++ b/db/migrate/20180105130053_rebuild_dag.rb @@ -92,7 +92,7 @@ class RebuildDag < ActiveRecord::Migration[5.0] AND relations.includes = 0 AND relations.requires = 0 AND (hierarchy + relates + duplicates + follows + blocks + includes + requires > 0) - SQL + SQL add_index :relations, %i(from_id to_id hierarchy), @@ -104,7 +104,7 @@ class RebuildDag < ActiveRecord::Migration[5.0] AND relations.blocks = 0 AND relations.includes = 0 AND relations.requires = 0 - SQL + SQL add_index :relations, %i(to_id follows from_id), @@ -116,7 +116,7 @@ class RebuildDag < ActiveRecord::Migration[5.0] AND blocks = 0 AND includes = 0 AND requires = 0 - SQL + SQL end def add_non_hierarchy_index diff --git a/db/migrate/20180117065255_remove_timelines_and_reportings.rb b/db/migrate/20180117065255_remove_timelines_and_reportings.rb index 5a5da63750..f59480c215 100644 --- a/db/migrate/20180117065255_remove_timelines_and_reportings.rb +++ b/db/migrate/20180117065255_remove_timelines_and_reportings.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/db/migrate/20180706150714_convert_to_markdown.rb b/db/migrate/20180706150714_convert_to_markdown.rb index 199efa41cc..fed6ebdaf5 100644 --- a/db/migrate/20180706150714_convert_to_markdown.rb +++ b/db/migrate/20180706150714_convert_to_markdown.rb @@ -45,7 +45,7 @@ class ConvertToMarkdown < ActiveRecord::Migration[5.1] For more information, please visit this page: https://www.openproject.org/textile-to-markdown-migration - WARNING + WARNING return end diff --git a/db/migrate/20181112125034_create_doorkeeper_tables.rb b/db/migrate/20181112125034_create_doorkeeper_tables.rb index e0dd97683f..9db1e9fba9 100644 --- a/db/migrate/20181112125034_create_doorkeeper_tables.rb +++ b/db/migrate/20181112125034_create_doorkeeper_tables.rb @@ -50,12 +50,12 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[5.1] # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator # # t.text :token, null: false - t.string :token, null: false + t.string :token, null: false t.string :refresh_token t.integer :expires_in t.datetime :revoked_at - t.datetime :created_at, null: false + t.datetime :created_at, null: false t.string :scopes # If there is a previous_refresh_token column, diff --git a/db/migrate/20181121174153_create_ordered_work_packages.rb b/db/migrate/20181121174153_create_ordered_work_packages.rb index cdaecadee1..bb0f7c0795 100644 --- a/db/migrate/20181121174153_create_ordered_work_packages.rb +++ b/db/migrate/20181121174153_create_ordered_work_packages.rb @@ -2,7 +2,7 @@ class CreateOrderedWorkPackages < ActiveRecord::Migration[5.1] def change create_table :ordered_work_packages do |t| t.integer :position, index: true, null: false - + t.references :query, type: :integer, foreign_key: { index: true, on_delete: :cascade } t.references :work_package, type: :integer, foreign_key: { index: true, on_delete: :cascade } end diff --git a/db/migrate/20190220080647_migrate_my_page_layout.rb b/db/migrate/20190220080647_migrate_my_page_layout.rb index 9062dd1bdc..1ddb5ff554 100644 --- a/db/migrate/20190220080647_migrate_my_page_layout.rb +++ b/db/migrate/20190220080647_migrate_my_page_layout.rb @@ -1,7 +1,6 @@ class MigrateMyPageLayout < ActiveRecord::Migration[5.2] def up UserPreference.transaction do - # Remove all my page grids ::Grids::MyPage.destroy_all diff --git a/db/migrate/20190312083304_rename_boards_to_forums.rb b/db/migrate/20190312083304_rename_boards_to_forums.rb index dbd12fc1b7..f05ee20266 100644 --- a/db/migrate/20190312083304_rename_boards_to_forums.rb +++ b/db/migrate/20190312083304_rename_boards_to_forums.rb @@ -1,12 +1,11 @@ require_relative './tables/forums' class RenameBoardsToForums < ActiveRecord::Migration[5.2] - def up # Create the new table, then copy from the oldt table to ensure indexes are correct ::Tables::Forums.create(self) - execute "INSERT INTO forums SELECT * FROM boards"; + execute "INSERT INTO forums SELECT * FROM boards" rename_column :messages, :board_id, :forum_id rename_column :message_journals, :board_id, :forum_id @@ -32,5 +31,3 @@ class RenameBoardsToForums < ActiveRecord::Migration[5.2] Watcher.where(watchable_type: 'Forum').update_all(watchable_type: 'Board') end end - - diff --git a/db/migrate/20190710132957_rename_my_page_widgets.rb b/db/migrate/20190710132957_rename_my_page_widgets.rb index 8c449ec6b2..6b9ab51b2e 100644 --- a/db/migrate/20190710132957_rename_my_page_widgets.rb +++ b/db/migrate/20190710132957_rename_my_page_widgets.rb @@ -3,15 +3,13 @@ class RenameMyPageWidgets < ActiveRecord::Migration[5.2] reset_column_information Grids::MyPage.eager_load(:widgets, user: :preference).each do |page| - begin - I18n.with_locale(page.user&.language.presence || 'en') do - page.widgets.each(&method(:update_widget)) - end - rescue I18n::InvalidLocale => e - Rails.logger.warn "Failed to use user locale from #{page.user.inspect}: #{e} #{e.message}. Correcting" + I18n.with_locale(page.user&.language.presence || 'en') do page.widgets.each(&method(:update_widget)) - page.user&.update_column(:language, 'en') end + rescue I18n::InvalidLocale => e + Rails.logger.warn "Failed to use user locale from #{page.user.inspect}: #{e} #{e.message}. Correcting" + page.widgets.each(&method(:update_widget)) + page.user&.update_column(:language, 'en') end end diff --git a/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb b/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb index 23132b186d..51a9e65f64 100644 --- a/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb +++ b/db/migrate/20190722082648_add_derived_estimated_hours_to_work_packages.rb @@ -2,7 +2,7 @@ class AddDerivedEstimatedHoursToWorkPackages < ActiveRecord::Migration[5.2] class WorkPackageWithRelations < ActiveRecord::Base self.table_name = "work_packages" - scope :with_children, ->(*args) do + scope :with_children, ->(*_args) do rel = "relations" wp = "work_packages" diff --git a/db/migrate/20200625133727_fix_inherited_group_member_roles.rb b/db/migrate/20200625133727_fix_inherited_group_member_roles.rb index 9c9bb00e06..fc53b4615b 100644 --- a/db/migrate/20200625133727_fix_inherited_group_member_roles.rb +++ b/db/migrate/20200625133727_fix_inherited_group_member_roles.rb @@ -10,7 +10,6 @@ class FixInheritedGroupMemberRoles < ActiveRecord::Migration[6.0] .includes(member: %i[principal member_roles]) .where("#{Principal.table_name}.type" => 'Group') .find_each do |member_role| - # Recreate member_roles for all group members member_role.send :add_role_to_group_users end diff --git a/db/migrate/20200925084550_members_allow_null_on_project.rb b/db/migrate/20200925084550_members_allow_null_on_project.rb index 62bfa571cb..f220a77321 100644 --- a/db/migrate/20200925084550_members_allow_null_on_project.rb +++ b/db/migrate/20200925084550_members_allow_null_on_project.rb @@ -31,7 +31,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0] execute <<~SQL UPDATE members - SET + SET#{' '} updated_at = created_on SQL end @@ -66,7 +66,7 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0] execute <<~SQL INSERT INTO member_roles(member_id, role_id) - VALUES #{values.join(', ') } + VALUES #{values.join(', ')} SQL end @@ -123,4 +123,4 @@ class MembersAllowNullOnProject < ActiveRecord::Migration[6.0] ) SQL end -end \ No newline at end of file +end diff --git a/db/migrate/migration_utils/migration_squasher.rb b/db/migrate/migration_utils/migration_squasher.rb index 08d2b51aff..a10d53e435 100644 --- a/db/migrate/migration_utils/migration_squasher.rb +++ b/db/migrate/migration_utils/migration_squasher.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/db/migrate/migration_utils/permission_adder.rb b/db/migrate/migration_utils/permission_adder.rb index 9b6178860d..c597884573 100644 --- a/db/migrate/migration_utils/permission_adder.rb +++ b/db/migrate/migration_utils/permission_adder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,7 +37,6 @@ module Migration .where(role_permissions: { permission: having.to_s }) .references(:role_permissions) .find_each do |role| - role.add_permission! add end end diff --git a/db/migrate/migration_utils/setting_renamer.rb b/db/migrate/migration_utils/setting_renamer.rb index c21fc3a12f..98174cc5a5 100644 --- a/db/migrate/migration_utils/setting_renamer.rb +++ b/db/migrate/migration_utils/setting_renamer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/db/migrate/migration_utils/utils.rb b/db/migrate/migration_utils/utils.rb index 2205734a7b..a8f28fe9c5 100644 --- a/db/migrate/migration_utils/utils.rb +++ b/db/migrate/migration_utils/utils.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,11 +32,9 @@ module Migration module Utils UpdateResult = Struct.new(:row, :updated) - def say_with_time_silently(message) + def say_with_time_silently(message, &block) say_with_time message do - suppress_messages do - yield - end + suppress_messages(&block) end end diff --git a/db/migrate/tables/attachments.rb b/db/migrate/tables/attachments.rb index 46330ddf6a..1724c5bc12 100644 --- a/db/migrate/tables/attachments.rb +++ b/db/migrate/tables/attachments.rb @@ -31,7 +31,6 @@ require_relative 'base' class Tables::Attachments < Tables::Base - # rubocop:disable Metrics/AbcSize def self.table(migration) create_table migration do |t| t.integer :container_id, default: 0, null: false @@ -52,5 +51,4 @@ class Tables::Attachments < Tables::Base t.index :created_on, name: 'index_attachments_on_created_on' end end - # rubocop:enable Metrics/AbcSize end diff --git a/db/migrate/tables/auth_sources.rb b/db/migrate/tables/auth_sources.rb index f3a730cd3a..13103f6392 100644 --- a/db/migrate/tables/auth_sources.rb +++ b/db/migrate/tables/auth_sources.rb @@ -31,7 +31,6 @@ require_relative 'base' class Tables::AuthSources < Tables::Base - # rubocop:disable Metrics/AbcSize def self.table(migration) create_table migration do |t| t.string :type, limit: 30, default: '', null: false @@ -52,5 +51,4 @@ class Tables::AuthSources < Tables::Base t.index %i[id type], name: 'index_auth_sources_on_id_and_type' end end - # rubocop:enable Metrics/AbcSize end diff --git a/db/seeds.rb b/db/seeds.rb index d44a4a5a4f..46e5061dc7 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres b/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres index 97a6a484d7..6b11e9edb2 100755 --- a/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres +++ b/docker/prod/mysql-to-postgres/bin/migrate-mysql-to-postgres @@ -29,16 +29,16 @@ if mysql_url.scheme == 'mysql2' mysql_url.scheme = 'mysql' end -filtered_mysql_url = mysql_url.dup.tap{|url| url.password = "REDACTED"} -filtered_db_url = db_url.dup.tap{|url| url.password = "REDACTED"} +filtered_mysql_url = mysql_url.dup.tap { |url| url.password = "REDACTED" } +filtered_db_url = db_url.dup.tap { |url| url.password = "REDACTED" } puts "Migrating database from MySQL to PostgreSQL." puts puts "Import" puts " MySQL database" -puts " #{filtered_mysql_url.to_s}" +puts " #{filtered_mysql_url}" puts " into Postgres database " -puts " #{filtered_db_url.to_s}" +puts " #{filtered_db_url}" puts " ?" puts "WARNING: This resets the given Postgres database." puts @@ -50,10 +50,14 @@ if answer.downcase == "n" exit 0 end -db_user, db_password, db_host, db_port, db_name = db_url.user, db_url.password, db_url.host, db_url.port, db_url.path.sub("/", "") +db_user = db_url.user +db_password = db_url.password +db_host = db_url.host +db_port = db_url.port +db_name = db_url.path.sub("/", "") db_port ||= 5432 -if [db_host, db_name, db_port].any?{|value| [nil, ""].include?(value)} +if [db_host, db_name, db_port].any? { |value| [nil, ""].include?(value) } puts "ERROR: Could not parse database URL (#{filtered_db_url})" exit 1 @@ -102,7 +106,7 @@ unless ENV['SKIP_OPENPROJECT_DB_RESET'] == 'true' puts "Creating database..." create_cmd = "PGPASSWORD=#{db_password} psql -U #{db_user} -h #{db_host} -p #{db_port} -d postgres -c 'CREATE DATABASE #{db_name}'" - create_output, _ = run create_cmd, silent: true + create_output, = run create_cmd, silent: true if create_output == "CREATE DATABASE" # created database successfully @@ -112,7 +116,6 @@ unless ENV['SKIP_OPENPROJECT_DB_RESET'] == 'true' end end - puts "Importing database ..." mysql_url.query = nil @@ -215,5 +218,4 @@ if needs_fulltext_migration end end - puts "Migration from MySQL to Postgres completed successfully!" diff --git a/extra/mail_handler/rdm-mailhandler.rb b/extra/mail_handler/rdm-mailhandler.rb index f84a353a38..0d809c2106 100644 --- a/extra/mail_handler/rdm-mailhandler.rb +++ b/extra/mail_handler/rdm-mailhandler.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -#!/usr/bin/env ruby +# !/usr/bin/env ruby # == Synopsis # @@ -93,7 +94,7 @@ module Net request.initialize_http_header(headers) http = new(url.host, url.port) http.use_ssl = (url.scheme == 'https') - http.start {|h| h.request(request) } + http.start { |h| h.request(request) } end end end @@ -107,19 +108,19 @@ class RedmineMailHandler self.issue_attributes = {} opts = GetoptLong.new( - [ '--help', '-h', GetoptLong::NO_ARGUMENT ], - [ '--version', '-V', GetoptLong::NO_ARGUMENT ], - [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], - [ '--url', '-u', GetoptLong::REQUIRED_ARGUMENT ], - [ '--key', '-k', GetoptLong::REQUIRED_ARGUMENT], - [ '--project', '-p', GetoptLong::REQUIRED_ARGUMENT ], - [ '--status', '-s', GetoptLong::REQUIRED_ARGUMENT ], - [ '--type', '-t', GetoptLong::REQUIRED_ARGUMENT], - [ '--category', GetoptLong::REQUIRED_ARGUMENT], - [ '--priority', GetoptLong::REQUIRED_ARGUMENT], - [ '--allow-override', '-o', GetoptLong::REQUIRED_ARGUMENT], - [ '--unknown-user', GetoptLong::REQUIRED_ARGUMENT], - [ '--no-permission-check', GetoptLong::NO_ARGUMENT] + ['--help', '-h', GetoptLong::NO_ARGUMENT], + ['--version', '-V', GetoptLong::NO_ARGUMENT], + ['--verbose', '-v', GetoptLong::NO_ARGUMENT], + ['--url', '-u', GetoptLong::REQUIRED_ARGUMENT], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT], + ['--project', '-p', GetoptLong::REQUIRED_ARGUMENT], + ['--status', '-s', GetoptLong::REQUIRED_ARGUMENT], + ['--type', '-t', GetoptLong::REQUIRED_ARGUMENT], + ['--category', GetoptLong::REQUIRED_ARGUMENT], + ['--priority', GetoptLong::REQUIRED_ARGUMENT], + ['--allow-override', '-o', GetoptLong::REQUIRED_ARGUMENT], + ['--unknown-user', GetoptLong::REQUIRED_ARGUMENT], + ['--no-permission-check', GetoptLong::NO_ARGUMENT] ) opts.each do |opt, arg| @@ -135,7 +136,7 @@ class RedmineMailHandler when '--version' puts VERSION; exit when '--project', '--status', '--type', '--category', '--priority' - self.issue_attributes[opt.gsub(%r{^\-\-}, '')] = arg.dup + issue_attributes[opt.gsub(%r{^--}, '')] = arg.dup when '--allow-override' self.allow_override = arg.dup when '--unknown-user' @@ -154,9 +155,9 @@ class RedmineMailHandler headers = { 'User-Agent' => "Redmine mail handler/#{VERSION}" } data = { 'key' => key, 'email' => email, - 'allow_override' => allow_override, - 'unknown_user' => unknown_user, - 'no_permission_check' => no_permission_check} + 'allow_override' => allow_override, + 'unknown_user' => unknown_user, + 'no_permission_check' => no_permission_check } issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value } debug "Posting to #{uri}..." @@ -164,25 +165,25 @@ class RedmineMailHandler debug "Response received: #{response.code}" case response.code.to_i - when 403 - warn "Request was denied by your Redmine server. " + - "Make sure that 'WS for incoming emails' is enabled in application settings and that you provided the correct API key." - return 77 - when 422 - warn "Request was denied by your Redmine server. " + - "Possible reasons: email is sent from an invalid email address or is missing some information." - return 77 - when 400..499 - warn "Request was denied by your Redmine server (#{response.code})." - return 77 - when 500..599 - warn "Failed to contact your Redmine server (#{response.code})." - return 75 - when 201 - debug "Proccessed successfully" - return 0 - else - return 1 + when 403 + warn "Request was denied by your Redmine server. " + + "Make sure that 'WS for incoming emails' is enabled in application settings and that you provided the correct API key." + 77 + when 422 + warn "Request was denied by your Redmine server. " + + "Possible reasons: email is sent from an invalid email address or is missing some information." + 77 + when 400..499 + warn "Request was denied by your Redmine server (#{response.code})." + 77 + when 500..599 + warn "Failed to contact your Redmine server (#{response.code})." + 75 + when 201 + debug "Proccessed successfully" + 0 + else + 1 end end diff --git a/extra/svn/reposman.rb b/extra/svn/reposman.rb index 51d5b5fb54..66f5d2efc1 100755 --- a/extra/svn/reposman.rb +++ b/extra/svn/reposman.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,26 +29,26 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -warn <<-EOS -[DEPRECATION] The functionality provided by reposman.rb has been integrated into OpenProject. -Please remove any existing cronjobs that still use this script. - -You can create repositories explicitly on the filesystem using managed repositories. -Enable managed repositories for each SCM vendor individually using the templates -defined in configuration.yml. - -If you want to convert existing repositories previously created (by reposman.rb or manually) -into managed repositories, use the following command: - - $ bundle exec rake scm:migrate:managed[URL prefix (, URL prefix, ...)] -Where URL prefix denotes a common prefix of repositories whose status should be upgraded to :managed. -Example: - -If you have executed reposman.rb with the following parameters: - - $ reposman.rb [...] --svn-dir "/opt/svn" --url "file:///opt/svn" - -Then you can pass a URL prefix of 'file:///opt/svn' and the rake task will migrate all repositories -matching this prefix to :managed. -You may pass more than one URL prefix to the task. +warn <<~EOS + [DEPRECATION] The functionality provided by reposman.rb has been integrated into OpenProject. + Please remove any existing cronjobs that still use this script. + #{' '} + You can create repositories explicitly on the filesystem using managed repositories. + Enable managed repositories for each SCM vendor individually using the templates + defined in configuration.yml. + #{' '} + If you want to convert existing repositories previously created (by reposman.rb or manually) + into managed repositories, use the following command: + #{' '} + $ bundle exec rake scm:migrate:managed[URL prefix (, URL prefix, ...)] + Where URL prefix denotes a common prefix of repositories whose status should be upgraded to :managed. + Example: + #{' '} + If you have executed reposman.rb with the following parameters: + #{' '} + $ reposman.rb [...] --svn-dir "/opt/svn" --url "file:///opt/svn" + #{' '} + Then you can pass a URL prefix of 'file:///opt/svn' and the rake task will migrate all repositories + matching this prefix to :managed. + You may pass more than one URL prefix to the task. EOS diff --git a/lib/api/caching/cached_representer.rb b/lib/api/caching/cached_representer.rb index 37e5743889..d0fd73a183 100644 --- a/lib/api/caching/cached_representer.rb +++ b/lib/api/caching/cached_representer.rb @@ -85,6 +85,7 @@ module API protected attr_accessor :caching_state + class_attribute :_cached_representer_config private diff --git a/lib/api/caching/helpers.rb b/lib/api/caching/helpers.rb index ac76fd10ba..0c080c2f65 100644 --- a/lib/api/caching/helpers.rb +++ b/lib/api/caching/helpers.rb @@ -14,10 +14,10 @@ module API # Save serialization since we're only dealing with strings here args[:raw] = true - json = Rails.cache.fetch(key, args) { + json = Rails.cache.fetch(key, args) do result = yield result.to_json - } + end ::API::Caching::StoredRepresenter.new json end diff --git a/lib/api/caching/stored_representer.rb b/lib/api/caching/stored_representer.rb index 99e2462294..2dc08872e0 100644 --- a/lib/api/caching/stored_representer.rb +++ b/lib/api/caching/stored_representer.rb @@ -5,7 +5,7 @@ module API @json = json end - def to_json + def to_json(*_args) @json end end diff --git a/lib/api/decorators/aggregation_group.rb b/lib/api/decorators/aggregation_group.rb index 43e2d4028e..d44e9adb8e 100644 --- a/lib/api/decorators/aggregation_group.rb +++ b/lib/api/decorators/aggregation_group.rb @@ -31,7 +31,7 @@ module API module Decorators class AggregationGroup < Single - def initialize(group_key, count, query:, sums: nil, current_user:) + def initialize(group_key, count, query:, current_user:, sums: nil) @count = count @sums = sums @query = query diff --git a/lib/api/decorators/allowed_values_by_link_representer.rb b/lib/api/decorators/allowed_values_by_link_representer.rb index 9b378dcc7b..429b3076ff 100644 --- a/lib/api/decorators/allowed_values_by_link_representer.rb +++ b/lib/api/decorators/allowed_values_by_link_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/decorators/digest.rb b/lib/api/decorators/digest.rb index e243f5af75..2ff5aa7a9d 100644 --- a/lib/api/decorators/digest.rb +++ b/lib/api/decorators/digest.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -38,12 +39,12 @@ module API property :algorithm, exec_context: :decorator, - getter: -> (*) { @algorithm }, + getter: ->(*) { @algorithm }, writable: false, render_nil: true property :hash, exec_context: :decorator, - getter: -> (*) { represented }, + getter: ->(*) { represented }, render_nil: true end end diff --git a/lib/api/decorators/form.rb b/lib/api/decorators/form.rb index c224d73033..654bc80b11 100644 --- a/lib/api/decorators/form.rb +++ b/lib/api/decorators/form.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/decorators/formattable.rb b/lib/api/decorators/formattable.rb index de08322a03..321499bed6 100644 --- a/lib/api/decorators/formattable.rb +++ b/lib/api/decorators/formattable.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/decorators/offset_paginated_collection.rb b/lib/api/decorators/offset_paginated_collection.rb index 62a7f5f400..e93c9e12f2 100644 --- a/lib/api/decorators/offset_paginated_collection.rb +++ b/lib/api/decorators/offset_paginated_collection.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,7 +37,7 @@ module API relation.base_class.per_page end - def initialize(models, self_link:, query: {}, page: nil, per_page: nil, current_user:) + def initialize(models, self_link:, current_user:, query: {}, page: nil, per_page: nil) @self_link_base = self_link @query = query @page = page.to_i > 0 ? page.to_i : 1 diff --git a/lib/api/decorators/property_schema_representer.rb b/lib/api/decorators/property_schema_representer.rb index 069d21b30a..dcc51927ef 100644 --- a/lib/api/decorators/property_schema_representer.rb +++ b/lib/api/decorators/property_schema_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/decorators/schema_representer.rb b/lib/api/decorators/schema_representer.rb index 883da48cfc..3b18759de7 100644 --- a/lib/api/decorators/schema_representer.rb +++ b/lib/api/decorators/schema_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -87,10 +88,9 @@ module API end def schema_with_allowed_link(property, - type: make_type(property), + href_callback:, type: make_type(property), name_source: property, as: camelize(property), - href_callback:, required: true, has_default: false, writable: default_writable_property(property), @@ -116,14 +116,12 @@ module API end def schema_with_allowed_collection(property, - type: make_type(property), + value_representer:, link_factory:, type: make_type(property), name_source: property, as: camelize(property), values_callback: -> do represented.assignable_values(property, current_user) end, - value_representer:, - link_factory:, required: true, has_default: false, writable: default_writable_property(property), @@ -243,7 +241,7 @@ module API end def self.representable_definitions - representable_config = self.representable_attrs + representable_config = representable_attrs # For reasons beyond me, Representable::Config contains the definitions # * nested in [:definitions] in some envs, e.g. development diff --git a/lib/api/decorators/single.rb b/lib/api/decorators/single.rb index 050df4c8d2..3b195d4c03 100644 --- a/lib/api/decorators/single.rb +++ b/lib/api/decorators/single.rb @@ -42,6 +42,7 @@ module API include ::API::V3::Utilities::PathHelper attr_reader :current_user, :embed_links + class_attribute :as_strategy self.as_strategy = ::API::Utilities::CamelCasingStrategy.new diff --git a/lib/api/decorators/unpaginated_collection.rb b/lib/api/decorators/unpaginated_collection.rb index 5c509f37e2..85446d2b36 100644 --- a/lib/api/decorators/unpaginated_collection.rb +++ b/lib/api/decorators/unpaginated_collection.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/bad_request.rb b/lib/api/errors/bad_request.rb index 2a06455f42..bc35752189 100644 --- a/lib/api/errors/bad_request.rb +++ b/lib/api/errors/bad_request.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/conflict.rb b/lib/api/errors/conflict.rb index 8ff11ea19c..a17454b239 100644 --- a/lib/api/errors/conflict.rb +++ b/lib/api/errors/conflict.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/error_base.rb b/lib/api/errors/error_base.rb index 861101f842..4c37d43905 100644 --- a/lib/api/errors/error_base.rb +++ b/lib/api/errors/error_base.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -31,6 +32,7 @@ module API module Errors class ErrorBase < Grape::Exceptions::Base attr_reader :message, :details, :errors, :property + delegate :code, to: :class class << self diff --git a/lib/api/errors/internal_error.rb b/lib/api/errors/internal_error.rb index a5629656d9..4a46d34854 100644 --- a/lib/api/errors/internal_error.rb +++ b/lib/api/errors/internal_error.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/invalid_query.rb b/lib/api/errors/invalid_query.rb index 28705f473c..3f33827527 100644 --- a/lib/api/errors/invalid_query.rb +++ b/lib/api/errors/invalid_query.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/invalid_render_context.rb b/lib/api/errors/invalid_render_context.rb index 1a9ab910a4..1041eadc54 100644 --- a/lib/api/errors/invalid_render_context.rb +++ b/lib/api/errors/invalid_render_context.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/invalid_request_body.rb b/lib/api/errors/invalid_request_body.rb index a5812a57f0..303f340be0 100644 --- a/lib/api/errors/invalid_request_body.rb +++ b/lib/api/errors/invalid_request_body.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/invalid_resource_link.rb b/lib/api/errors/invalid_resource_link.rb index e671f8fa0e..dcc5bc3cdc 100644 --- a/lib/api/errors/invalid_resource_link.rb +++ b/lib/api/errors/invalid_resource_link.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/invalid_user_status_transition.rb b/lib/api/errors/invalid_user_status_transition.rb index 7276da841c..4ee86ee090 100644 --- a/lib/api/errors/invalid_user_status_transition.rb +++ b/lib/api/errors/invalid_user_status_transition.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/multiple_errors.rb b/lib/api/errors/multiple_errors.rb index 05da2efc97..0643689a5b 100644 --- a/lib/api/errors/multiple_errors.rb +++ b/lib/api/errors/multiple_errors.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/not_found.rb b/lib/api/errors/not_found.rb index a084412c41..8e9b2bbaa8 100644 --- a/lib/api/errors/not_found.rb +++ b/lib/api/errors/not_found.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/parse_error.rb b/lib/api/errors/parse_error.rb index 868a079a0b..58a8647142 100644 --- a/lib/api/errors/parse_error.rb +++ b/lib/api/errors/parse_error.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,7 @@ module API identifier InvalidRequestBody.identifier code 400 - def initialize(message = nil, details: nil) + def initialize(_message = nil, details: nil) super I18n.t('api_v3.errors.invalid_json') if details @@ -44,7 +45,7 @@ module API private def clean_parse_error(message) - message.gsub(/\s?\[parse.c\:\d+\]/, '') + message.gsub(/\s?\[parse.c:\d+\]/, '') end end end diff --git a/lib/api/errors/property_format_error.rb b/lib/api/errors/property_format_error.rb index 2a07b27fcc..65dbd199d4 100644 --- a/lib/api/errors/property_format_error.rb +++ b/lib/api/errors/property_format_error.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/unauthenticated.rb b/lib/api/errors/unauthenticated.rb index bef763445d..358dc6a73d 100644 --- a/lib/api/errors/unauthenticated.rb +++ b/lib/api/errors/unauthenticated.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/unauthorized.rb b/lib/api/errors/unauthorized.rb index a2aa8df4ca..1fa5372dc6 100644 --- a/lib/api/errors/unauthorized.rb +++ b/lib/api/errors/unauthorized.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/unsupported_media_type.rb b/lib/api/errors/unsupported_media_type.rb index b129fdc1fc..2e09af5bd5 100644 --- a/lib/api/errors/unsupported_media_type.rb +++ b/lib/api/errors/unsupported_media_type.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/unwritable_property.rb b/lib/api/errors/unwritable_property.rb index 972afdbc6b..8a62d0a9c5 100644 --- a/lib/api/errors/unwritable_property.rb +++ b/lib/api/errors/unwritable_property.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/errors/validation.rb b/lib/api/errors/validation.rb index aa6f4033cf..8987c9bb23 100644 --- a/lib/api/errors/validation.rb +++ b/lib/api/errors/validation.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/utilities/camel_casing_strategy.rb b/lib/api/utilities/camel_casing_strategy.rb index 501c34f5ca..61af38b684 100644 --- a/lib/api/utilities/camel_casing_strategy.rb +++ b/lib/api/utilities/camel_casing_strategy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -43,6 +44,7 @@ module API def to_camel_case(string) return string if string.first == '_' + string.camelize(:lower) end end diff --git a/lib/api/utilities/decorator_factory.rb b/lib/api/utilities/decorator_factory.rb index b62d3a1b3b..2f8d08bb8f 100644 --- a/lib/api/utilities/decorator_factory.rb +++ b/lib/api/utilities/decorator_factory.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/utilities/property_name_converter.rb b/lib/api/utilities/property_name_converter.rb index 3e57381e42..e303f2e64b 100644 --- a/lib/api/utilities/property_name_converter.rb +++ b/lib/api/utilities/property_name_converter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/utilities/property_name_converter_query_context.rb b/lib/api/utilities/property_name_converter_query_context.rb index b4d14bae7f..53991e0b9e 100644 --- a/lib/api/utilities/property_name_converter_query_context.rb +++ b/lib/api/utilities/property_name_converter_query_context.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -41,8 +42,7 @@ module API super(WorkPackage.new) end - def subproject_id - end + def subproject_id; end end end end diff --git a/lib/api/utilities/query_filters_name_converter.rb b/lib/api/utilities/query_filters_name_converter.rb index 680f0a4a0f..702432ac55 100644 --- a/lib/api/utilities/query_filters_name_converter.rb +++ b/lib/api/utilities/query_filters_name_converter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/utilities/resource_link_parser.rb b/lib/api/utilities/resource_link_parser.rb index 66e858f0e6..bc6ac2c336 100644 --- a/lib/api/utilities/resource_link_parser.rb +++ b/lib/api/utilities/resource_link_parser.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/utilities/text_renderer.rb b/lib/api/utilities/text_renderer.rb index 65d42060cb..cdde3546ed 100644 --- a/lib/api/utilities/text_renderer.rb +++ b/lib/api/utilities/text_renderer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/utilities/url_helper.rb b/lib/api/utilities/url_helper.rb index f975a167f3..6d963ac240 100644 --- a/lib/api/utilities/url_helper.rb +++ b/lib/api/utilities/url_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,8 @@ module API include ActionView::Helpers::UrlHelper include OpenProject::StaticRouting::UrlHelpers - def controller; end # The URL helpers need a controller, even if it's nil + # The URL helpers need a controller, even if it's nil + def controller; end end end end diff --git a/lib/api/utilities/wp_property_name_converter.rb b/lib/api/utilities/wp_property_name_converter.rb index 7acd27b90c..3bf47c530c 100644 --- a/lib/api/utilities/wp_property_name_converter.rb +++ b/lib/api/utilities/wp_property_name_converter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/activities/activity_collection_representer.rb b/lib/api/v3/activities/activity_collection_representer.rb index 72616987a4..9db95db476 100644 --- a/lib/api/v3/activities/activity_collection_representer.rb +++ b/lib/api/v3/activities/activity_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/activities/activity_representer.rb b/lib/api/v3/activities/activity_representer.rb index 5ac64c56f3..aca21c395c 100644 --- a/lib/api/v3/activities/activity_representer.rb +++ b/lib/api/v3/activities/activity_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -44,7 +45,7 @@ module API link :workPackage do { href: api_v3_paths.work_package(represented.journable.id), - title: "#{represented.journable.subject}" + title: represented.journable.subject.to_s } end diff --git a/lib/api/v3/attachments/attachment_collection_representer.rb b/lib/api/v3/attachments/attachment_collection_representer.rb index 9846752b07..7b21060e1e 100644 --- a/lib/api/v3/attachments/attachment_collection_representer.rb +++ b/lib/api/v3/attachments/attachment_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/attachments/attachment_upload_representer.rb b/lib/api/v3/attachments/attachment_upload_representer.rb index cfc1436dfb..3cbe0742d7 100644 --- a/lib/api/v3/attachments/attachment_upload_representer.rb +++ b/lib/api/v3/attachments/attachment_upload_representer.rb @@ -67,10 +67,7 @@ module API end end - attr_reader :form_url - attr_reader :form_fields - - attr_reader :attachment + attr_reader :form_url, :form_fields, :attachment def initialize(attachment, current_user:) super diff --git a/lib/api/v3/attachments/attachments_by_container_api.rb b/lib/api/v3/attachments/attachments_by_container_api.rb index f4b33ae4ce..745096e05f 100644 --- a/lib/api/v3/attachments/attachments_by_container_api.rb +++ b/lib/api/v3/attachments/attachments_by_container_api.rb @@ -132,12 +132,12 @@ module API def with_handled_create_errors yield - rescue ActiveRecord::RecordInvalid => error - raise ::API::Errors::ErrorBase.create_and_merge_errors(error.record.errors) - rescue StandardError => error - log_attachment_saving_error(error) + rescue ActiveRecord::RecordInvalid => e + raise ::API::Errors::ErrorBase.create_and_merge_errors(e.record.errors) + rescue StandardError => e + log_attachment_saving_error(e) message = - if error&.class&.to_s == 'Errno::EACCES' + if e&.class&.to_s == 'Errno::EACCES' I18n.t('api_v3.errors.unable_to_create_attachment_permissions') else I18n.t('api_v3.errors.unable_to_create_attachment') diff --git a/lib/api/v3/categories/categories_api.rb b/lib/api/v3/categories/categories_api.rb index e07cd268ca..e24c69e9b3 100644 --- a/lib/api/v3/categories/categories_api.rb +++ b/lib/api/v3/categories/categories_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/categories/categories_by_project_api.rb b/lib/api/v3/categories/categories_by_project_api.rb index dcec831276..ac5bd2660b 100644 --- a/lib/api/v3/categories/categories_by_project_api.rb +++ b/lib/api/v3/categories/categories_by_project_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/categories/category_collection_representer.rb b/lib/api/v3/categories/category_collection_representer.rb index f236d10aa0..184edda880 100644 --- a/lib/api/v3/categories/category_collection_representer.rb +++ b/lib/api/v3/categories/category_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/categories/category_representer.rb b/lib/api/v3/categories/category_representer.rb index d9c49fcf93..b4e2641a8b 100644 --- a/lib/api/v3/categories/category_representer.rb +++ b/lib/api/v3/categories/category_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/configuration/configuration_representer.rb b/lib/api/v3/configuration/configuration_representer.rb index a495ac324c..653c44d9f9 100644 --- a/lib/api/v3/configuration/configuration_representer.rb +++ b/lib/api/v3/configuration/configuration_representer.rb @@ -135,10 +135,8 @@ module API end end - def reformated(setting) - format = setting.gsub(/%\w/) do |directive| - yield directive - end + def reformated(setting, &block) + format = setting.gsub(/%\w/, &block) format.blank? ? nil : format end diff --git a/lib/api/v3/custom_actions/custom_actions_api.rb b/lib/api/v3/custom_actions/custom_actions_api.rb index 25abdd6127..b1f5af3c63 100644 --- a/lib/api/v3/custom_actions/custom_actions_api.rb +++ b/lib/api/v3/custom_actions/custom_actions_api.rb @@ -78,7 +78,6 @@ module API .new(user: current_user, action: custom_action) .call(work_package: work_package) do |call| - call.on_success do work_package.reload diff --git a/lib/api/v3/custom_options/custom_option_representer.rb b/lib/api/v3/custom_options/custom_option_representer.rb index 8ca7fa20df..bde0950d06 100644 --- a/lib/api/v3/custom_options/custom_option_representer.rb +++ b/lib/api/v3/custom_options/custom_option_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/formatter/txt_charset.rb b/lib/api/v3/formatter/txt_charset.rb index f5ae784fea..57c3c77114 100644 --- a/lib/api/v3/formatter/txt_charset.rb +++ b/lib/api/v3/formatter/txt_charset.rb @@ -40,7 +40,7 @@ module API::V3::Formatter # * Encoding.default_external if no charset provided def self.encoding(object, env) Encoding.find(charset(env)) - rescue + rescue StandardError object.encoding end private_class_method :encoding diff --git a/lib/api/v3/principals/principal_representer.rb b/lib/api/v3/principals/principal_representer.rb index 65e1d8cb6e..00d80798f0 100644 --- a/lib/api/v3/principals/principal_representer.rb +++ b/lib/api/v3/principals/principal_representer.rb @@ -43,7 +43,6 @@ module API link :memberships, cache_if: -> { current_user_allowed_to_see_members? } do - filters = [ { principal: { diff --git a/lib/api/v3/principals/principal_representer_factory.rb b/lib/api/v3/principals/principal_representer_factory.rb index 683d224740..01f6b20cae 100644 --- a/lib/api/v3/principals/principal_representer_factory.rb +++ b/lib/api/v3/principals/principal_representer_factory.rb @@ -32,7 +32,6 @@ module API module V3 module Principals class PrincipalRepresenterFactory - ## # Create the appropriate subclass representer # for each principal entity diff --git a/lib/api/v3/priorities/priorities_api.rb b/lib/api/v3/priorities/priorities_api.rb index d794201f2d..fe31336010 100644 --- a/lib/api/v3/priorities/priorities_api.rb +++ b/lib/api/v3/priorities/priorities_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/priorities/priority_collection_representer.rb b/lib/api/v3/priorities/priority_collection_representer.rb index 2f66bb0fa4..6c6b72e17d 100644 --- a/lib/api/v3/priorities/priority_collection_representer.rb +++ b/lib/api/v3/priorities/priority_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/priorities/priority_representer.rb b/lib/api/v3/priorities/priority_representer.rb index 7d2b1110d3..e61984c919 100644 --- a/lib/api/v3/priorities/priority_representer.rb +++ b/lib/api/v3/priorities/priority_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -42,7 +43,7 @@ module API property :name property :position property :color, - getter: -> (*) { color.hexcode if color }, + getter: ->(*) { color.hexcode if color }, render_nil: true property :is_default property :active, as: :isActive diff --git a/lib/api/v3/projects/project_collection_representer.rb b/lib/api/v3/projects/project_collection_representer.rb index 1234a40503..0d6d9d46b5 100644 --- a/lib/api/v3/projects/project_collection_representer.rb +++ b/lib/api/v3/projects/project_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/projects/project_representer.rb b/lib/api/v3/projects/project_representer.rb index 44841f8128..a3332394e2 100644 --- a/lib/api/v3/projects/project_representer.rb +++ b/lib/api/v3/projects/project_representer.rb @@ -107,7 +107,7 @@ module API current_user_allowed_to(:view_members, context: represented) } do { - href: api_v3_paths.path_for(:memberships, filters: [{ project: { operator: "=", values: [represented.id.to_s] }}]), + href: api_v3_paths.path_for(:memberships, filters: [{ project: { operator: "=", values: [represented.id.to_s] } }]) } end @@ -222,7 +222,7 @@ module API self.to_eager_load = [:status, :parent, :enabled_modules, - custom_values: :custom_field] + { custom_values: :custom_field }] self.checked_permissions = [:add_work_packages] end diff --git a/lib/api/v3/queries/create_form_representer.rb b/lib/api/v3/queries/create_form_representer.rb index c4bc03404e..e5f4f74b0d 100644 --- a/lib/api/v3/queries/create_form_representer.rb +++ b/lib/api/v3/queries/create_form_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/queries/filters/query_filter_decorator.rb b/lib/api/v3/queries/filters/query_filter_decorator.rb index 1a2b08ed9b..423f2855cc 100644 --- a/lib/api/v3/queries/filters/query_filter_decorator.rb +++ b/lib/api/v3/queries/filters/query_filter_decorator.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/queries/filters/query_filter_instance_representer.rb b/lib/api/v3/queries/filters/query_filter_instance_representer.rb index 4baa7e3d4e..63785bfbb8 100644 --- a/lib/api/v3/queries/filters/query_filter_instance_representer.rb +++ b/lib/api/v3/queries/filters/query_filter_instance_representer.rb @@ -84,7 +84,7 @@ module API path_name = value_object.class.name.demodulize.underscore api_v3_paths.send(path_name, value_object.id) - rescue => e + rescue StandardError => e Rails.logger.error "Failed to get href for value_object #{value_object}: #{e}" nil end diff --git a/lib/api/v3/queries/order/query_order_api.rb b/lib/api/v3/queries/order/query_order_api.rb index ccefe541e5..d90903be8e 100644 --- a/lib/api/v3/queries/order/query_order_api.rb +++ b/lib/api/v3/queries/order/query_order_api.rb @@ -32,9 +32,7 @@ module API module Order class QueryOrderAPI < ::API::OpenProjectAPI resource :order do - helpers do - ## # Remove the order for the given work package def remove_order(wp_id) diff --git a/lib/api/v3/queries/queries_api.rb b/lib/api/v3/queries/queries_api.rb index 719885322e..139b05fe00 100644 --- a/lib/api/v3/queries/queries_api.rb +++ b/lib/api/v3/queries/queries_api.rb @@ -166,6 +166,7 @@ module API query_menu_item = @query.query_menu_item return representer if @query.query_menu_item.nil? + query_menu_item.destroy @query.reload diff --git a/lib/api/v3/queries/query_params_representer.rb b/lib/api/v3/queries/query_params_representer.rb index a72460bc62..d4ba93e040 100644 --- a/lib/api/v3/queries/query_params_representer.rb +++ b/lib/api/v3/queries/query_params_representer.rb @@ -45,7 +45,7 @@ module API # To json hash outputs the hash to be parsed to the frontend http # which contains a reference to the columns array as columns[]. # This will match the Rails +to_query+ output - def to_json + def to_json(*_args) to_h(column_key: 'columns[]'.to_sym).to_json end diff --git a/lib/api/v3/queries/query_representer.rb b/lib/api/v3/queries/query_representer.rb index 0f9b0235c0..034ade42e7 100644 --- a/lib/api/v3/queries/query_representer.rb +++ b/lib/api/v3/queries/query_representer.rb @@ -324,7 +324,7 @@ module API self.to_eager_load = [:query_menu_item, :user, - project: :work_package_custom_fields] + { project: :work_package_custom_fields }] def _type 'Query' diff --git a/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb index e6355a609b..5028b397d7 100644 --- a/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class AllPrincipalsFilterDependencyRepresenter < PrincipalFilterDependencyRepresenter - def json_cache_key if filter.project super + [filter.project.id] diff --git a/lib/api/v3/queries/schemas/boolean_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/boolean_filter_dependency_representer.rb index 526279bbe3..0679d9eda2 100644 --- a/lib/api/v3/queries/schemas/boolean_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/boolean_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class BooleanFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback; end private diff --git a/lib/api/v3/queries/schemas/by_work_package_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/by_work_package_filter_dependency_representer.rb index c64a41142b..a930e9cf42 100644 --- a/lib/api/v3/queries/schemas/by_work_package_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/by_work_package_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class ByWorkPackageFilterDependencyRepresenter < FilterDependencyRepresenter - def json_cache_key super + (filter.project.present? ? [filter.project.id] : []) end diff --git a/lib/api/v3/queries/schemas/custom_option_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/custom_option_filter_dependency_representer.rb index f01a53c52c..dbc8ec9f6f 100644 --- a/lib/api/v3/queries/schemas/custom_option_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/custom_option_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class CustomOptionFilterDependencyRepresenter < FilterDependencyRepresenter - schema_with_allowed_collection :values, type: ->(*) { type }, writable: true, diff --git a/lib/api/v3/queries/schemas/date_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/date_filter_dependency_representer.rb index 25c435dbc2..078a99061b 100644 --- a/lib/api/v3/queries/schemas/date_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/date_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class DateFilterDependencyRepresenter < IntegerFilterDependencyRepresenter - private def type diff --git a/lib/api/v3/queries/schemas/date_time_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/date_time_filter_dependency_representer.rb index 33e1235364..66f1e94b0b 100644 --- a/lib/api/v3/queries/schemas/date_time_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/date_time_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class DateTimeFilterDependencyRepresenter < IntegerFilterDependencyRepresenter - def type if operator == ::Queries::Operators::OnDateTime '[1]DateTime' diff --git a/lib/api/v3/queries/schemas/filter_dependency_decorator.rb b/lib/api/v3/queries/schemas/filter_dependency_decorator.rb index aa901a7745..3c56822a86 100644 --- a/lib/api/v3/queries/schemas/filter_dependency_decorator.rb +++ b/lib/api/v3/queries/schemas/filter_dependency_decorator.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb b/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb index 0583a76f01..5d017fd208 100644 --- a/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb +++ b/lib/api/v3/queries/schemas/filter_dependency_representer_factory.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/queries/schemas/float_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/float_filter_dependency_representer.rb index a05a6c3fbe..5f74fa6b96 100644 --- a/lib/api/v3/queries/schemas/float_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/float_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class FloatFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback; end private diff --git a/lib/api/v3/queries/schemas/group_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/group_filter_dependency_representer.rb index 58588cef60..13db4acc81 100644 --- a/lib/api/v3/queries/schemas/group_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/group_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class GroupFilterDependencyRepresenter < PrincipalFilterDependencyRepresenter - def json_cache_key super + (filter.project.present? ? [filter.project.id] : []) end diff --git a/lib/api/v3/queries/schemas/integer_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/integer_filter_dependency_representer.rb index 5c8fb3844a..03c113b63d 100644 --- a/lib/api/v3/queries/schemas/integer_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/integer_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class IntegerFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback; end private diff --git a/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rb index b265cf22c2..36883c533a 100644 --- a/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/only_subproject_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class OnlySubprojectFilterDependencyRepresenter < FilterDependencyRepresenter - def json_cache_key if filter.project super + [filter.project.id] diff --git a/lib/api/v3/queries/schemas/principal_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/principal_filter_dependency_representer.rb index 90f18b461b..df06ef6220 100644 --- a/lib/api/v3/queries/schemas/principal_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/principal_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class PrincipalFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback query = CGI.escape(::JSON.dump(filter_query)) diff --git a/lib/api/v3/queries/schemas/priority_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/priority_filter_dependency_representer.rb index b1709614ee..c04e9abe46 100644 --- a/lib/api/v3/queries/schemas/priority_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/priority_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class PriorityFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback api_v3_paths.priorities end diff --git a/lib/api/v3/queries/schemas/project_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/project_filter_dependency_representer.rb index c46018a8ff..9a1af4a682 100644 --- a/lib/api/v3/queries/schemas/project_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/project_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class ProjectFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback params = [active: { operator: '=', values: ['t'] }] escaped = CGI.escape(::JSON.dump(params)) diff --git a/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb b/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb index ee7457f7d0..2039671bb7 100644 --- a/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb +++ b/lib/api/v3/queries/schemas/query_filter_instance_schema_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/queries/schemas/role_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/role_filter_dependency_representer.rb index 49f460449e..ae22c11584 100644 --- a/lib/api/v3/queries/schemas/role_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/role_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class RoleFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback api_v3_paths.roles end diff --git a/lib/api/v3/queries/schemas/status_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/status_filter_dependency_representer.rb index 68600c6fec..f949d0a26b 100644 --- a/lib/api/v3/queries/schemas/status_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/status_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class StatusFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback api_v3_paths.statuses end diff --git a/lib/api/v3/queries/schemas/subproject_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/subproject_filter_dependency_representer.rb index d535f47358..a3234f40d5 100644 --- a/lib/api/v3/queries/schemas/subproject_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/subproject_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class SubprojectFilterDependencyRepresenter < FilterDependencyRepresenter - def json_cache_key if filter.project super + [filter.project.id] diff --git a/lib/api/v3/queries/schemas/text_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/text_filter_dependency_representer.rb index 19534f16fc..de45fa7703 100644 --- a/lib/api/v3/queries/schemas/text_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/text_filter_dependency_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module API module Schemas class TextFilterDependencyRepresenter < FilterDependencyRepresenter - def href_callback; end private diff --git a/lib/api/v3/queries/schemas/type_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/type_filter_dependency_representer.rb index ba305949de..99dd3ed64c 100644 --- a/lib/api/v3/queries/schemas/type_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/type_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class TypeFilterDependencyRepresenter < FilterDependencyRepresenter - def json_cache_key super + (filter.project.present? ? [filter.project.id] : []) end diff --git a/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb index 38b9113066..ad482e215b 100644 --- a/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb +++ b/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb @@ -34,7 +34,6 @@ module API module Schemas class UserFilterDependencyRepresenter < PrincipalFilterDependencyRepresenter - def json_cache_key super + (filter.project.present? ? [filter.project.id] : []) end diff --git a/lib/api/v3/queries/sort_bys/sort_by_decorator.rb b/lib/api/v3/queries/sort_bys/sort_by_decorator.rb index aeaf4622c1..a54099b7e7 100644 --- a/lib/api/v3/queries/sort_bys/sort_by_decorator.rb +++ b/lib/api/v3/queries/sort_bys/sort_by_decorator.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/queries/update_form_representer.rb b/lib/api/v3/queries/update_form_representer.rb index 0880808b80..b394097d98 100644 --- a/lib/api/v3/queries/update_form_representer.rb +++ b/lib/api/v3/queries/update_form_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/relations/relation_collection_representer.rb b/lib/api/v3/relations/relation_collection_representer.rb index 49d8a90ade..5979c7375a 100644 --- a/lib/api/v3/relations/relation_collection_representer.rb +++ b/lib/api/v3/relations/relation_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/relations/relation_representer.rb b/lib/api/v3/relations/relation_representer.rb index 4c748c4b17..5d57c9fb8b 100644 --- a/lib/api/v3/relations/relation_representer.rb +++ b/lib/api/v3/relations/relation_representer.rb @@ -113,7 +113,7 @@ module API end self.to_eager_load = [:to, - from: { project: :enabled_modules }] + { from: { project: :enabled_modules } }] end end end diff --git a/lib/api/v3/render/render_api.rb b/lib/api/v3/render/render_api.rb index 2f88aabf26..931c2a59dc 100644 --- a/lib/api/v3/render/render_api.rb +++ b/lib/api/v3/render/render_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/repositories/revision_representer.rb b/lib/api/v3/repositories/revision_representer.rb index 6e8c34acbd..daf1fb5a2b 100644 --- a/lib/api/v3/repositories/revision_representer.rb +++ b/lib/api/v3/repositories/revision_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/repositories/revisions_collection_representer.rb b/lib/api/v3/repositories/revisions_collection_representer.rb index 8480075a7c..8b3023f2a7 100644 --- a/lib/api/v3/repositories/revisions_collection_representer.rb +++ b/lib/api/v3/repositories/revisions_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/roles/role_collection_representer.rb b/lib/api/v3/roles/role_collection_representer.rb index 2d0ae7ceb9..96b61a064c 100644 --- a/lib/api/v3/roles/role_collection_representer.rb +++ b/lib/api/v3/roles/role_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/roles/role_representer.rb b/lib/api/v3/roles/role_representer.rb index 5cb5c9d4a4..632d29bbde 100644 --- a/lib/api/v3/roles/role_representer.rb +++ b/lib/api/v3/roles/role_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/roles/roles_api.rb b/lib/api/v3/roles/roles_api.rb index 45574c3313..93c8b6023d 100644 --- a/lib/api/v3/roles/roles_api.rb +++ b/lib/api/v3/roles/roles_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/schemas/schema_collection_representer.rb b/lib/api/v3/schemas/schema_collection_representer.rb index 5b154605d1..8ff8413203 100644 --- a/lib/api/v3/schemas/schema_collection_representer.rb +++ b/lib/api/v3/schemas/schema_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/statuses/status_collection_representer.rb b/lib/api/v3/statuses/status_collection_representer.rb index ce273d1264..9e176e3a97 100644 --- a/lib/api/v3/statuses/status_collection_representer.rb +++ b/lib/api/v3/statuses/status_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/statuses/status_representer.rb b/lib/api/v3/statuses/status_representer.rb index 17a737fce9..c55ca06c2c 100644 --- a/lib/api/v3/statuses/status_representer.rb +++ b/lib/api/v3/statuses/status_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/statuses/statuses_api.rb b/lib/api/v3/statuses/statuses_api.rb index ef4723fe5a..8c5b5a751a 100644 --- a/lib/api/v3/statuses/statuses_api.rb +++ b/lib/api/v3/statuses/statuses_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/string_objects/string_objects_api.rb b/lib/api/v3/string_objects/string_objects_api.rb index e731a08ad0..9e15aeae0f 100644 --- a/lib/api/v3/string_objects/string_objects_api.rb +++ b/lib/api/v3/string_objects/string_objects_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/types/type_collection_representer.rb b/lib/api/v3/types/type_collection_representer.rb index e3536f56a3..b2d88008c9 100644 --- a/lib/api/v3/types/type_collection_representer.rb +++ b/lib/api/v3/types/type_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/types/type_representer.rb b/lib/api/v3/types/type_representer.rb index e0bb077d94..bd9f94a09a 100644 --- a/lib/api/v3/types/type_representer.rb +++ b/lib/api/v3/types/type_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/types/types_api.rb b/lib/api/v3/types/types_api.rb index 19357f5189..fb67fcf321 100644 --- a/lib/api/v3/types/types_api.rb +++ b/lib/api/v3/types/types_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,7 +37,7 @@ module API class TypesAPI < ::API::OpenProjectAPI resources :types do after_validation do - authorize_any([:view_work_packages, :manage_types], global: true) + authorize_any(%i[view_work_packages manage_types], global: true) end get do diff --git a/lib/api/v3/types/types_by_project_api.rb b/lib/api/v3/types/types_by_project_api.rb index a260613c3e..573ae6c7bd 100644 --- a/lib/api/v3/types/types_by_project_api.rb +++ b/lib/api/v3/types/types_by_project_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,13 +36,13 @@ module API class TypesByProjectAPI < ::API::OpenProjectAPI resources :types do after_validation do - authorize_any [:view_work_packages, :manage_types], projects: @project + authorize_any %i[view_work_packages manage_types], projects: @project end get do types = @project.types TypeCollectionRepresenter.new(types, - self_link:api_v3_paths.types_by_project(@project.id), + self_link: api_v3_paths.types_by_project(@project.id), current_user: current_user) end end diff --git a/lib/api/v3/users/user_collection_representer.rb b/lib/api/v3/users/user_collection_representer.rb index 0118abacc4..7a8468e52e 100644 --- a/lib/api/v3/users/user_collection_representer.rb +++ b/lib/api/v3/users/user_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/users/users_api.rb b/lib/api/v3/users/users_api.rb index cffe0aec27..268c8c8ec8 100644 --- a/lib/api/v3/users/users_api.rb +++ b/lib/api/v3/users/users_api.rb @@ -76,7 +76,7 @@ module API params do requires :id, desc: 'User\'s id' end - route_param :id do + route_param :id do after_validation do @user = if params[:id] == 'me' diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb index 4373238d57..d92b9547d1 100644 --- a/lib/api/v3/utilities/custom_field_injector.rb +++ b/lib/api/v3/utilities/custom_field_injector.rb @@ -349,9 +349,9 @@ module API def allowed_users_static_filters [ { status: { operator: '!', - values: [Principal.statuses[:locked].to_s] } }, + values: [Principal.statuses[:locked].to_s] } }, { type: { operator: '=', - values: %w[User Group PlaceholderUser] } } + values: %w[User Group PlaceholderUser] } } ] end diff --git a/lib/api/v3/utilities/custom_field_sum_injector.rb b/lib/api/v3/utilities/custom_field_sum_injector.rb index e910849f87..8e08d5af1b 100644 --- a/lib/api/v3/utilities/custom_field_sum_injector.rb +++ b/lib/api/v3/utilities/custom_field_sum_injector.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/utilities/date_time_formatter.rb b/lib/api/v3/utilities/date_time_formatter.rb index 4264db3c58..937ffac466 100644 --- a/lib/api/v3/utilities/date_time_formatter.rb +++ b/lib/api/v3/utilities/date_time_formatter.rb @@ -34,6 +34,7 @@ module API class DateTimeFormatter def self.format_date(date, allow_nil: false) return nil if date.nil? && allow_nil + date.to_date.iso8601 end @@ -72,6 +73,7 @@ module API def self.format_datetime(datetime, allow_nil: false) return nil if datetime.nil? && allow_nil + datetime.to_datetime.utc.iso8601 end diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb index 16a819bc79..3b4e773533 100644 --- a/lib/api/v3/utilities/path_helper.rb +++ b/lib/api/v3/utilities/path_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/utilities/resource_link_generator.rb b/lib/api/v3/utilities/resource_link_generator.rb index 38e668cc8d..fae572dc5c 100644 --- a/lib/api/v3/utilities/resource_link_generator.rb +++ b/lib/api/v3/utilities/resource_link_generator.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/versions/projects_by_version_api.rb b/lib/api/v3/versions/projects_by_version_api.rb index b015467018..41188783a4 100644 --- a/lib/api/v3/versions/projects_by_version_api.rb +++ b/lib/api/v3/versions/projects_by_version_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/versions/version_collection_representer.rb b/lib/api/v3/versions/version_collection_representer.rb index 0fc9018c80..1efd494331 100644 --- a/lib/api/v3/versions/version_collection_representer.rb +++ b/lib/api/v3/versions/version_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/watchers/watcher_representer.rb b/lib/api/v3/watchers/watcher_representer.rb index 178f0a49c7..de5a152a14 100644 --- a/lib/api/v3/watchers/watcher_representer.rb +++ b/lib/api/v3/watchers/watcher_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/wiki_pages/wiki_page_representer.rb b/lib/api/v3/wiki_pages/wiki_page_representer.rb index 89ab304938..a405599a00 100644 --- a/lib/api/v3/wiki_pages/wiki_page_representer.rb +++ b/lib/api/v3/wiki_pages/wiki_page_representer.rb @@ -45,6 +45,7 @@ module API associated_resource :project, link: ->(*) do next unless represented.project.present? + { href: api_v3_paths.project(represented.project.id), title: represented.project.name diff --git a/lib/api/v3/work_packages/create_form_representer.rb b/lib/api/v3/work_packages/create_form_representer.rb index c357f8ba35..04594f5b2b 100644 --- a/lib/api/v3/work_packages/create_form_representer.rb +++ b/lib/api/v3/work_packages/create_form_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/work_packages/create_project_form_representer.rb b/lib/api/v3/work_packages/create_project_form_representer.rb index 4f4fd7755b..8d23e8426a 100644 --- a/lib/api/v3/work_packages/create_project_form_representer.rb +++ b/lib/api/v3/work_packages/create_project_form_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/work_packages/link_to_object_extractor.rb b/lib/api/v3/work_packages/link_to_object_extractor.rb index 0fc43e4a5a..3e427e4354 100644 --- a/lib/api/v3/work_packages/link_to_object_extractor.rb +++ b/lib/api/v3/work_packages/link_to_object_extractor.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/work_packages/schema/base_work_package_schema.rb b/lib/api/v3/work_packages/schema/base_work_package_schema.rb index 54a187245d..a38520a0e0 100644 --- a/lib/api/v3/work_packages/schema/base_work_package_schema.rb +++ b/lib/api/v3/work_packages/schema/base_work_package_schema.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/work_packages/schema/specific_work_package_schema.rb b/lib/api/v3/work_packages/schema/specific_work_package_schema.rb index 0f99089708..02abddf20d 100644 --- a/lib/api/v3/work_packages/schema/specific_work_package_schema.rb +++ b/lib/api/v3/work_packages/schema/specific_work_package_schema.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,6 +34,7 @@ module API module Schema class SpecificWorkPackageSchema < BaseWorkPackageSchema attr_reader :work_package + include AssignableCustomFieldValues include AssignableValuesContract diff --git a/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb index bb22b47eb3..80a9513c95 100644 --- a/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb +++ b/lib/api/v3/work_packages/schema/work_package_schema_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/api/v3/work_packages/update_form_representer.rb b/lib/api/v3/work_packages/update_form_representer.rb index 8f9e84f696..4eba2a282d 100644 --- a/lib/api/v3/work_packages/update_form_representer.rb +++ b/lib/api/v3/work_packages/update_form_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -53,11 +54,13 @@ module API end link :commit do - { - href: api_v3_paths.work_package(represented.id), - method: :patch - } if current_user.allowed_to?(:edit_work_packages, represented.project) && - @errors.empty? + if current_user.allowed_to?(:edit_work_packages, represented.project) && + @errors.empty? + { + href: api_v3_paths.work_package(represented.id), + method: :patch + } + end end end end diff --git a/lib/api/v3/work_packages/watchers_api.rb b/lib/api/v3/work_packages/watchers_api.rb index 43e2645653..7357a93c55 100644 --- a/lib/api/v3/work_packages/watchers_api.rb +++ b/lib/api/v3/work_packages/watchers_api.rb @@ -89,8 +89,8 @@ module API user = User.find user_id Services::CreateWatcher.new(@work_package, user).run( - success: -> (result) { status(200) unless result[:created] }, - failure: -> (watcher) { + success: ->(result) { status(200) unless result[:created] }, + failure: ->(watcher) { raise ::API::Errors::ErrorBase.create_and_merge_errors(watcher.errors) } ) diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rb index 4b74e05627..2062a1eaa0 100644 --- a/lib/api/v3/work_packages/work_package_collection_representer.rb +++ b/lib/api/v3/work_packages/work_package_collection_representer.rb @@ -36,14 +36,11 @@ module API def initialize(models, self_link:, - query: {}, + groups:, total_sums:, current_user:, query: {}, project: nil, - groups:, - total_sums:, page: nil, per_page: nil, - embed_schemas: false, - current_user:) + embed_schemas: false) @project = project @groups = groups @total_sums = total_sums diff --git a/lib/constraints/enterprise.rb b/lib/constraints/enterprise.rb index ffd4760d11..af60b57305 100644 --- a/lib/constraints/enterprise.rb +++ b/lib/constraints/enterprise.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,9 +28,8 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - class Enterprise - def self.matches?(request) + def self.matches?(_request) OpenProject::Configuration.ee_manager_visible? end end diff --git a/lib/core_extensions.rb b/lib/core_extensions.rb index 889ecb7cc3..32fa6e89bd 100644 --- a/lib/core_extensions.rb +++ b/lib/core_extensions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/custom_field_form_builder.rb b/lib/custom_field_form_builder.rb index 4d78c83662..3fac604e8c 100644 --- a/lib/custom_field_form_builder.rb +++ b/lib/custom_field_form_builder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -124,7 +125,6 @@ class CustomFieldFormBuilder < TabularFormBuilder output = ''.html_safe output += custom_value.custom_field.name - # Render a help text icon if options[:help_text] output += content_tag('attribute-help-text', '', data: options[:help_text]) diff --git a/lib/generators/open_project/plugin/plugin_generator.rb b/lib/generators/open_project/plugin/plugin_generator.rb index db3ac69313..f21cc096cc 100644 --- a/lib/generators/open_project/plugin/plugin_generator.rb +++ b/lib/generators/open_project/plugin/plugin_generator.rb @@ -29,7 +29,7 @@ require 'rails/generators' class Generators::OpenProject::Plugin::PluginGenerator < Rails::Generators::Base - source_root File.expand_path('../templates', __FILE__) + source_root File.expand_path('templates', __dir__) argument :plugin_name, type: :string, default: 'openproject-new-plugin' argument :root_folder, type: :string, default: 'vendor/gems' diff --git a/lib/open_project/access_keys.rb b/lib/open_project/access_keys.rb index 3f45b2aba7..9f73100958 100644 --- a/lib/open_project/access_keys.rb +++ b/lib/open_project/access_keys.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,16 +30,17 @@ module OpenProject module AccessKeys - ACCESSKEYS = { preview: '1', - new_work_package: '2', - edit: '3', - quick_search: '4', - project_search: '5', - help: '6', - more_menu: '7', - details: '8', - new_project: '9' - }.freeze unless const_defined?(:ACCESSKEYS) + unless const_defined?(:ACCESSKEYS) + ACCESSKEYS = { preview: '1', + new_work_package: '2', + edit: '3', + quick_search: '4', + project_search: '5', + help: '6', + more_menu: '7', + details: '8', + new_project: '9' }.freeze + end def self.key_for(action) ACCESSKEYS[action] diff --git a/lib/open_project/acts_as_url/adapter/op_active_record.rb b/lib/open_project/acts_as_url/adapter/op_active_record.rb index 2be2e94fe1..5b7d911c7f 100644 --- a/lib/open_project/acts_as_url/adapter/op_active_record.rb +++ b/lib/open_project/acts_as_url/adapter/op_active_record.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/assets.rb b/lib/open_project/assets.rb index cce8eed15a..32a7771ee0 100644 --- a/lib/open_project/assets.rb +++ b/lib/open_project/assets.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -75,7 +76,7 @@ module OpenProject # Create map of asset chunk name to current hash manifest = {} OpenProject::Assets.current_assets.each do |filename| - md = filename.match /\A([^\.]+)\.(\w+)\.(\w+)\z/ + md = filename.match /\A([^.]+)\.(\w+)\.(\w+)\z/ # Non-hashed asset next if md.nil? diff --git a/lib/open_project/authentication.rb b/lib/open_project/authentication.rb index 8173e15cca..f1a5ba31c8 100644 --- a/lib/open_project/authentication.rb +++ b/lib/open_project/authentication.rb @@ -158,7 +158,7 @@ module OpenProject identifier, path = nil, run_after_activation: false, - active: ->() { true }, + active: -> { true }, before: nil, after: nil, &block @@ -191,11 +191,11 @@ module OpenProject def find_all(identifiers) identifiers - .map { |ident| self.stages.find { |st| st.identifier == ident } } + .map { |ident| stages.find { |st| st.identifier == ident } } .compact end - def complete_path(identifier, session:, back_url:nil) + def complete_path(identifier, session:, back_url: nil) stage_success_path stage: identifier, secret: Hash(session[:stage_secrets])[identifier] end diff --git a/lib/open_project/authentication/manager.rb b/lib/open_project/authentication/manager.rb index d402cf1943..472bbe2b82 100644 --- a/lib/open_project/authentication/manager.rb +++ b/lib/open_project/authentication/manager.rb @@ -61,7 +61,7 @@ module OpenProject def update!(opts, &block) self.store = opts[:store] if opts.include? :store self.realm = opts[:realm] if opts.include? :realm - self.strategies = block.call self.strategies if block_given? + self.strategies = block.call strategies if block_given? end end diff --git a/lib/open_project/authentication/strategies/warden/basic_auth_failure.rb b/lib/open_project/authentication/strategies/warden/basic_auth_failure.rb index e7f578fabb..16637ed702 100644 --- a/lib/open_project/authentication/strategies/warden/basic_auth_failure.rb +++ b/lib/open_project/authentication/strategies/warden/basic_auth_failure.rb @@ -6,7 +6,6 @@ module OpenProject # This strategy is inserted after optional basic auth strategies to # indicate that invalid basic auth credentials were provided. class BasicAuthFailure < ::Warden::Strategies::BasicAuth - def valid? OpenProject::Configuration.apiv3_enable_basic_auth? && super end diff --git a/lib/open_project/authentication/strategies/warden/doorkeeper_oauth.rb b/lib/open_project/authentication/strategies/warden/doorkeeper_oauth.rb index 761101787b..f81d90520c 100644 --- a/lib/open_project/authentication/strategies/warden/doorkeeper_oauth.rb +++ b/lib/open_project/authentication/strategies/warden/doorkeeper_oauth.rb @@ -10,7 +10,7 @@ module OpenProject class DoorkeeperOAuth < ::Warden::Strategies::Base def valid? @token = ::Doorkeeper::OAuth::Token.authenticate(decorated_request, *Doorkeeper.configuration.access_token_methods) - @token&.accessible? && @token.acceptable?(scope) + @token&.accessible? && @token&.acceptable?(scope) end def authenticate! diff --git a/lib/open_project/configuration.rb b/lib/open_project/configuration.rb index 57acc890e2..30027e5840 100644 --- a/lib/open_project/configuration.rb +++ b/lib/open_project/configuration.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -38,34 +39,34 @@ module OpenProject # Configuration default values @defaults = { - 'edition' => 'standard', - 'attachments_storage' => 'file', + 'edition' => 'standard', + 'attachments_storage' => 'file', 'attachments_storage_path' => nil, 'attachments_grace_period' => 180, - 'autologin_cookie_name' => 'autologin', - 'autologin_cookie_path' => '/', + 'autologin_cookie_name' => 'autologin', + 'autologin_cookie_path' => '/', 'autologin_cookie_secure' => false, - 'database_cipher_key' => nil, + 'database_cipher_key' => nil, # only applicable in conjunction with fog (effectively S3) attachments # which will be uploaded directly to the cloud storage rather than via OpenProject's # server process. - 'direct_uploads' => true, + 'direct_uploads' => true, 'fog_download_url_expires_in' => 21600, # 6h by default as 6 hours is max in S3 when using IAM roles 'show_community_links' => true, 'log_level' => 'info', - 'scm_git_command' => nil, - 'scm_subversion_command' => nil, + 'scm_git_command' => nil, + 'scm_subversion_command' => nil, 'scm_local_checkout_path' => 'repositories', # relative to OpenProject directory - 'disable_browser_cache' => true, + 'disable_browser_cache' => true, # default cache_store is :file_store in production and :memory_store in development - 'rails_cache_store' => nil, + 'rails_cache_store' => nil, 'cache_expires_in_seconds' => nil, 'cache_namespace' => nil, # use dalli defaults for memcache - 'cache_memcache_server' => nil, + 'cache_memcache_server' => nil, # where to store session data - 'session_store' => :cache_store, - 'session_cookie_name' => '_open_project_session', + 'session_store' => :cache_store, + 'session_cookie_name' => '_open_project_session', # Destroy all sessions for current_user on logout 'drop_old_sessions_on_logout' => true, # Destroy all sessions for current_user on login @@ -78,7 +79,7 @@ module OpenProject 'enable_internal_assets_server' => false, # Additional / overridden help links - 'force_help_link' => nil, + 'force_help_link' => nil, 'force_formatting_help_link' => nil, # Impressum link to be set, nil by default (= hidden) @@ -214,7 +215,7 @@ module OpenProject # exists def override_config!(config, source = default_override_source) config.keys.select { |key| source.include? key.upcase } - .each { |key| config[key] = extract_value key, source[key.upcase] } + .each { |key| config[key] = extract_value key, source[key.upcase] } config.deep_merge! merge_config(config, source) end @@ -505,8 +506,8 @@ module OpenProject def cache_parameters(config) mapping = { - 'cache_expires_in_seconds' => [:expires_in, :to_i], - 'cache_namespace' => [:namespace, :to_s] + 'cache_expires_in_seconds' => %i[expires_in to_i], + 'cache_namespace' => %i[namespace to_s] } parameters = {} mapping.each_pair do |from, to| diff --git a/lib/open_project/configuration/helpers.rb b/lib/open_project/configuration/helpers.rb index f83d0b92aa..cff03a10d8 100644 --- a/lib/open_project/configuration/helpers.rb +++ b/lib/open_project/configuration/helpers.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,7 +34,6 @@ module OpenProject # To be included into OpenProject::Configuration in order to provide # helper methods for easier access to certain configuration options. module Helpers - ## # Carrierwave storage type. Possible values are, among others, :file and :fog. # The latter requires further configuration. @@ -109,9 +109,9 @@ module OpenProject end def hidden_menu_items - menus = self['hidden_menu_items'].map { |label, nodes| + menus = self['hidden_menu_items'].map do |label, nodes| [label, array(nodes)] - } + end Hash[menus] end diff --git a/lib/open_project/content_type_detector.rb b/lib/open_project/content_type_detector.rb index bd6ccaaf5f..b4f164bff0 100644 --- a/lib/open_project/content_type_detector.rb +++ b/lib/open_project/content_type_detector.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -98,7 +99,7 @@ module OpenProject calculated_type_matches.first else type_from_file_command || SENSIBLE_DEFAULT - end.to_s + end.to_s end private diff --git a/lib/open_project/custom_styles/color_themes.rb b/lib/open_project/custom_styles/color_themes.rb index e9ff3b0506..d90094acb2 100644 --- a/lib/open_project/custom_styles/color_themes.rb +++ b/lib/open_project/custom_styles/color_themes.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/custom_styles/design.rb b/lib/open_project/custom_styles/design.rb index f1f9c832b1..ff0152ce87 100644 --- a/lib/open_project/custom_styles/design.rb +++ b/lib/open_project/custom_styles/design.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/database.rb b/lib/open_project/database.rb index 3327d014f0..80ba82363c 100644 --- a/lib/open_project/database.rb +++ b/lib/open_project/database.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -39,6 +40,7 @@ module OpenProject DB_VALUE_TRUE = 't'.freeze class InsufficientVersionError < StandardError; end + class UnsupportedDatabaseError < StandardError; end # This method returns a hash which maps the identifier of the supported @@ -139,7 +141,7 @@ module OpenProject # OpenProject::Database.postgresql?(my_connection) supported_adapters.keys.each do |adapter| (class << self; self; end).class_eval do - define_method(:"#{adapter.to_s}?") do |connection = self.connection| + define_method(:"#{adapter}?") do |connection = self.connection| send(:name, connection) == adapter end end @@ -157,7 +159,7 @@ module OpenProject def self.version(raw = false) @version ||= ActiveRecord::Base.connection.select_value('SELECT version()') - raw ? @version : @version.match(/\APostgreSQL ([\d\.]+)/i)[1] + raw ? @version : @version.match(/\APostgreSQL ([\d.]+)/i)[1] end def self.numeric_version diff --git a/lib/open_project/deprecation.rb b/lib/open_project/deprecation.rb index 52a84208a3..6e3c7228f5 100644 --- a/lib/open_project/deprecation.rb +++ b/lib/open_project/deprecation.rb @@ -32,10 +32,8 @@ module OpenProject::Deprecation @@deprecator ||= ActiveSupport::Deprecation .new('in a future major upgrade', 'OpenProject') .tap do |instance| - # Reuse the silenced state of the default deprecator instance.silenced = ActiveSupport::Deprecation.silenced - end end @@ -62,7 +60,14 @@ module OpenProject::Deprecation end def replaced(old_method, new_method, called_from) - ActiveSupport::Deprecation.warn "#{old_method} is deprecated and will be removed in a future OpenProject version. Please use #{new_method} instead.", called_from + message = <<~MSG + #{old_method} is deprecated and will be removed in a future OpenProject version. + + Please use #{new_method} instead. + + MSG + + ActiveSupport::Deprecation.warn message, called_from end end end diff --git a/lib/open_project/file_command_content_type_detector.rb b/lib/open_project/file_command_content_type_detector.rb index fd789f9b5c..ce6acad4df 100644 --- a/lib/open_project/file_command_content_type_detector.rb +++ b/lib/open_project/file_command_content_type_detector.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -83,7 +84,7 @@ module OpenProject type = SENSIBLE_DEFAULT end type.split(/[:;\s]+/)[0] - rescue => e + rescue StandardError => e Rails.logger.info { "Failed to get mime type from #{@filename}: #{e} #{e.message}" } SENSIBLE_DEFAULT end diff --git a/lib/open_project/footer.rb b/lib/open_project/footer.rb index 7d479a89b4..b7f84e545a 100644 --- a/lib/open_project/footer.rb +++ b/lib/open_project/footer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/form_tag_helper.rb b/lib/open_project/form_tag_helper.rb index aa52c95938..6ff10988d5 100644 --- a/lib/open_project/form_tag_helper.rb +++ b/lib/open_project/form_tag_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/full_text_search.rb b/lib/open_project/full_text_search.rb index 0c4d1ef5ad..aa1ec6812e 100644 --- a/lib/open_project/full_text_search.rb +++ b/lib/open_project/full_text_search.rb @@ -48,7 +48,7 @@ module OpenProject end def self.tokenize(text, concatenation = :and, normalization = :text) - terms = normalize(clean_terms(text), normalization).split(/[\s]+/).reject(&:blank?) + terms = normalize(clean_terms(text), normalization).split(/\s+/).reject(&:blank?) case concatenation when :and diff --git a/lib/open_project/journal/attachment_helper.rb b/lib/open_project/journal/attachment_helper.rb index 672306821a..9e50e0f271 100644 --- a/lib/open_project/journal/attachment_helper.rb +++ b/lib/open_project/journal/attachment_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/journal_formatter/attachment.rb b/lib/open_project/journal_formatter/attachment.rb index 0817107e70..efa19cfb75 100644 --- a/lib/open_project/journal_formatter/attachment.rb +++ b/lib/open_project/journal_formatter/attachment.rb @@ -62,8 +62,8 @@ class OpenProject::JournalFormatter::Attachment < ::JournalFormatter::Base def format_html_attachment_detail(key, value) if !value.blank? && a = Attachment.find_by(id: key.to_i) link_to_attachment(a, only_path: false) - else - value if value.present? + elsif value.present? + value end end end diff --git a/lib/open_project/journal_formatter/diff.rb b/lib/open_project/journal_formatter/diff.rb index d6dbd4b0ae..5d9d8ee07c 100644 --- a/lib/open_project/journal_formatter/diff.rb +++ b/lib/open_project/journal_formatter/diff.rb @@ -43,9 +43,11 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base def label(key, no_html = false) label = super key - no_html ? - label : + if no_html + label + else content_tag('strong', label) + end end def render_ternary_detail_text(key, value, old_value, options) @@ -69,7 +71,6 @@ class OpenProject::JournalFormatter::Diff < JournalFormatter::Base end def link(key, options) - url_attr = default_attributes(options).merge(controller: '/journals', action: 'diff', id: @journal.id, diff --git a/lib/open_project/locale_helper.rb b/lib/open_project/locale_helper.rb index b69d674681..df91ecc3a1 100644 --- a/lib/open_project/locale_helper.rb +++ b/lib/open_project/locale_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/logging/log_delegator.rb b/lib/open_project/logging/log_delegator.rb index 2ed444825a..8d4e83416f 100644 --- a/lib/open_project/logging/log_delegator.rb +++ b/lib/open_project/logging/log_delegator.rb @@ -2,7 +2,6 @@ module OpenProject module Logging class LogDelegator class << self - ## # Consume a message and let it be handled # by all handlers @@ -69,7 +68,7 @@ module OpenProject ## # Create a payload for lograge from a controller request line - def controller_payload_hash(controller) + def controller_payload_hash(_controller) { user: User.current.try(:id) } diff --git a/lib/open_project/nested_set/rebuild_patch.rb b/lib/open_project/nested_set/rebuild_patch.rb index 1cdb986ba0..04123edbef 100644 --- a/lib/open_project/nested_set/rebuild_patch.rb +++ b/lib/open_project/nested_set/rebuild_patch.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -55,9 +56,9 @@ module OpenProject::NestedSet::RebuildPatch scope = lambda { |_node| } if acts_as_nested_set_options[:scope] scope = lambda { |node| - scope_column_names.inject('') {|str, column_name| + scope_column_names.inject('') do |str, column_name| str << "AND #{connection.quote_column_name(column_name)} = #{connection.quote(node.send(column_name.to_sym))} " - } + end } end @@ -76,15 +77,15 @@ module OpenProject::NestedSet::RebuildPatch quoted_right_column_name, acts_as_nested_set_options[:order]].compact.join(', ')) - children.each do |n| set_left_and_rights.call(n) end + children.each { |n| set_left_and_rights.call(n) } # set right node[right_column_name] = indices[scope.call(node)] += 1 - changes = node.changes.inject({}) { |hash, (attribute, _values)| + changes = node.changes.inject({}) do |hash, (attribute, _values)| hash[attribute] = node.send(attribute.to_s) hash - } + end where(id: node.id).update_all(changes) unless changes.empty? } diff --git a/lib/open_project/object_linking.rb b/lib/open_project/object_linking.rb index 894e23d350..3e3958b4a5 100644 --- a/lib/open_project/object_linking.rb +++ b/lib/open_project/object_linking.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/omni_auth/authorization.rb b/lib/open_project/omni_auth/authorization.rb index 37ea391af1..749db9c274 100644 --- a/lib/open_project/omni_auth/authorization.rb +++ b/lib/open_project/omni_auth/authorization.rb @@ -35,7 +35,7 @@ module OpenProject # Checks whether the given user is authorized to login by calling # all registered callbacks. If all callbacks approve the user is authorized and may log in. def self.authorized?(auth_hash) - rejection = callbacks.find_map { |callback| + rejection = callbacks.find_map do |callback| d = callback.authorize auth_hash if d.is_a? Decision @@ -43,7 +43,7 @@ module OpenProject else fail ArgumentError, 'Expecting Callback#authorize to return a Decision.' end - } + end rejection || Approval.new end @@ -105,7 +105,7 @@ module OpenProject # @yieldparam user [User] User who has been logged in. # @yieldparam auth_hash [AuthHash] auth_hash OmniAuth authentication information # including user info and credentials. - # @yieldparam context The context from which the callback is called, e.g. a Controller. + # @yieldparam context The context from which the callback is called, e.g. a Controller. def self.after_login(&block) add_after_login_callback AfterLoginBlockCallback.new(&block) end diff --git a/lib/open_project/page_hierarchy_helper.rb b/lib/open_project/page_hierarchy_helper.rb index 3413200908..c61e627903 100644 --- a/lib/open_project/page_hierarchy_helper.rb +++ b/lib/open_project/page_hierarchy_helper.rb @@ -30,7 +30,6 @@ module OpenProject module PageHierarchyHelper - def render_page_hierarchy(pages, node = nil, options = {}) return '' unless pages[node] diff --git a/lib/open_project/passwords.rb b/lib/open_project/passwords.rb index 8cce7af219..4a3037ee1f 100644 --- a/lib/open_project/passwords.rb +++ b/lib/open_project/passwords.rb @@ -41,8 +41,8 @@ module OpenProject module Evaluator RULES = { 'uppercase' => /.*[A-Z].*/u, 'lowercase' => /.*[a-z].*/u, - 'special' => /.*[^\da-zA-Z].*/u, - 'numeric' => /.*\d.*/u } + 'special' => /.*[^\da-zA-Z].*/u, + 'numeric' => /.*\d.*/u } # Check whether password conforms to password complexity settings. # Checks complexity rules and password length. def self.conforming?(password) @@ -58,7 +58,7 @@ module OpenProject end unless password_long_enough(password) errors << I18n.t(:too_short, - scope: [:activerecord, :errors, :messages], + scope: %i[activerecord errors messages], count: OpenProject::Passwords::Evaluator.min_length) end errors @@ -114,8 +114,6 @@ module OpenProject count: OpenProject::Passwords::Evaluator.min_length) end - private - # Returns the number of active rules password adheres to. def self.size_active_rules_adhered_by(password) active_rules.count do |name| @@ -127,13 +125,13 @@ module OpenProject def self.active_rules_list active_rules.map do |rule| I18n.t(rule.to_sym, - scope: [:activerecord, :errors, :models, :user, :attributes, :password]) + scope: %i[activerecord errors models user attributes password]) end end def self.rules_description_locale(rules) I18n.t(:weak, - scope: [:activerecord, :errors, :models, :user, :attributes, :password], + scope: %i[activerecord errors models user attributes password], rules: rules, min_count: min_adhered_rules, all_count: active_rules.size) diff --git a/lib/open_project/patches/action_view_accessible_errors.rb b/lib/open_project/patches/action_view_accessible_errors.rb index cedb320fae..f6582f92ab 100644 --- a/lib/open_project/patches/action_view_accessible_errors.rb +++ b/lib/open_project/patches/action_view_accessible_errors.rb @@ -131,4 +131,4 @@ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| end end -ActionView::Base.send :include, ActionView::Helpers::AccessibleErrors +ActionView::Base.include ActionView::Helpers::AccessibleErrors diff --git a/lib/open_project/patches/acts_as_list.rb b/lib/open_project/patches/acts_as_list.rb index 61e626ece7..8fa724dfde 100644 --- a/lib/open_project/patches/acts_as_list.rb +++ b/lib/open_project/patches/acts_as_list.rb @@ -58,4 +58,4 @@ module OpenProject end end -ActiveRecord::Acts::List::InstanceMethods.send(:include, OpenProject::Patches::ActsAsList) +ActiveRecord::Acts::List::InstanceMethods.include OpenProject::Patches::ActsAsList diff --git a/lib/open_project/patches/array.rb b/lib/open_project/patches/array.rb index 660810c624..31872f0c79 100644 --- a/lib/open_project/patches/array.rb +++ b/lib/open_project/patches/array.rb @@ -1 +1 @@ -Array.send(:include, Redmine::Diff::Diffable) +Array.include Redmine::Diff::Diffable diff --git a/lib/open_project/patches/carrierwave_sanitized_file.rb b/lib/open_project/patches/carrierwave_sanitized_file.rb index f838ce63b6..783fa4ed79 100644 --- a/lib/open_project/patches/carrierwave_sanitized_file.rb +++ b/lib/open_project/patches/carrierwave_sanitized_file.rb @@ -17,8 +17,8 @@ module OpenProject::Patches::FogFile def authenticated_url(options = {}) if ['AWS', 'Google', 'Rackspace', 'OpenStack'].include?(@uploader.fog_credentials[:provider]) # avoid a get by using local references - local_directory = connection.directories.new(:key => @uploader.fog_directory) - local_file = local_directory.files.new(:key => path) + local_directory = connection.directories.new(key: @uploader.fog_directory) + local_file = local_directory.files.new(key: path) expire_at = options[:expire_at] || ::Fog::Time.now + @uploader.fog_authenticated_url_expiration case @uploader.fog_credentials[:provider] when 'AWS', 'Google' @@ -41,4 +41,4 @@ module OpenProject::Patches::FogFile end end -CarrierWave::Storage::Fog::File.send(:include, OpenProject::Patches::FogFile) +CarrierWave::Storage::Fog::File.include OpenProject::Patches::FogFile diff --git a/lib/open_project/patches/declarative_option.rb b/lib/open_project/patches/declarative_option.rb index 5251ddbcdc..5335a60883 100644 --- a/lib/open_project/patches/declarative_option.rb +++ b/lib/open_project/patches/declarative_option.rb @@ -35,6 +35,7 @@ module OpenProject::Patches::DeclarativeOption # Override Declarative::Option to avoid ruby 2.7.1 warnings about using the last argument as keyword parameter. def lambda_for_proc(value, options) return ->(context, **args) { context.instance_exec(**args, &value) } if options[:instance_exec] + value end end @@ -44,5 +45,6 @@ unless Declarative::Option.included_modules.include?(OpenProject::Patches::Decla if Gem.loaded_specs['declarative-option'].version > Gem::Version.create('0.1.0') raise "Check whether the patch to Declarative::Option is still necessary" end - Declarative::Option.send(:include, OpenProject::Patches::DeclarativeOption) + + Declarative::Option.include OpenProject::Patches::DeclarativeOption end diff --git a/lib/open_project/patches/delivery_job.rb b/lib/open_project/patches/delivery_job.rb index 5195cb152f..0a2cf9c736 100644 --- a/lib/open_project/patches/delivery_job.rb +++ b/lib/open_project/patches/delivery_job.rb @@ -32,10 +32,9 @@ module OpenProject module Patches module DeliveryJob - #include ::JobStatus::ApplicationJobWithStatus + # include ::JobStatus::ApplicationJobWithStatus end end end -ActionMailer::MailDeliveryJob.send(:include, ::JobStatus::ApplicationJobWithStatus) - +ActionMailer::MailDeliveryJob.include ::JobStatus::ApplicationJobWithStatus diff --git a/lib/open_project/patches/fog_file.rb b/lib/open_project/patches/fog_file.rb index d9461a3acf..9b32c56a39 100644 --- a/lib/open_project/patches/fog_file.rb +++ b/lib/open_project/patches/fog_file.rb @@ -16,4 +16,4 @@ module OpenProject::Patches::CarrierwaveSanitizedFile end end -CarrierWave::SanitizedFile.send(:include, OpenProject::Patches::CarrierwaveSanitizedFile) +CarrierWave::SanitizedFile.include OpenProject::Patches::CarrierwaveSanitizedFile diff --git a/lib/open_project/patches/representable.rb b/lib/open_project/patches/representable.rb index d466542706..f63d473a01 100644 --- a/lib/open_project/patches/representable.rb +++ b/lib/open_project/patches/representable.rb @@ -51,5 +51,5 @@ module OpenProject::Patches::Representable end unless Representable::Decorator.included_modules.include?(OpenProject::Patches::Representable) - Representable::Decorator.send(:include, OpenProject::Patches::Representable) + Representable::Decorator.include OpenProject::Patches::Representable end diff --git a/lib/open_project/patches/string.rb b/lib/open_project/patches/string.rb index 90987ff051..22069d14f3 100644 --- a/lib/open_project/patches/string.rb +++ b/lib/open_project/patches/string.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -38,13 +39,13 @@ module OpenProject s = $1 else # 230: 2.5 - s.gsub!(%r{^(\d+):(\d+)$}) do $1.to_i + $2.to_i / 60.0 end + s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 } # 2h30, 2h, 30m => 2.5, 2, 0.5 - s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| ($1 || $4) ? ($2.to_i + $5.to_i / 60.0) : m[0] } + s.gsub!(%r{^((\d+)\s*(h|hours?))?\s*((\d+)\s*(m|min)?)?$}) { |m| $1 || $4 ? ($2.to_i + $5.to_i / 60.0) : m[0] } end # 2,5 => 2.5 s.gsub!(',', '.') - begin; Kernel.Float(s); rescue; nil; end + begin; Kernel.Float(s); rescue StandardError; nil; end end # TODO: Check if this can be deleted @@ -55,5 +56,5 @@ module OpenProject end end -String.send(:include, OpenProject::Patches::String) -String.send(:include, Redmine::Diff::Diffable) +String.include OpenProject::Patches::String +String.include Redmine::Diff::Diffable diff --git a/lib/open_project/plugins/acts_as_op_engine.rb b/lib/open_project/plugins/acts_as_op_engine.rb index abe4d7a7c6..9fc16a8092 100644 --- a/lib/open_project/plugins/acts_as_op_engine.rb +++ b/lib/open_project/plugins/acts_as_op_engine.rb @@ -121,10 +121,10 @@ module OpenProject::Plugins self.class.config.to_prepare do klass_name = args.last patch = begin - "#{plugin_module}::Patches::#{args[0..-2].join('::')}::#{klass_name}Patch".constantize - rescue NameError - "#{plugin_module}::Patches::#{klass_name}Patch".constantize - end + "#{plugin_module}::Patches::#{args[0..-2].join('::')}::#{klass_name}Patch".constantize + rescue NameError + "#{plugin_module}::Patches::#{klass_name}Patch".constantize + end qualified_class_name = args.map(&:to_s).join('::') klass = qualified_class_name.to_s.constantize klass.send(:include, patch) unless klass.included_modules.include?(patch) @@ -242,8 +242,7 @@ module OpenProject::Plugins end def add_api_attribute(on:, - writable_for: [:create, :update], - ar_name:, + ar_name:, writable_for: %i[create update], writeable: true, &block) config.to_prepare do diff --git a/lib/open_project/plugins/frontend_linking.rb b/lib/open_project/plugins/frontend_linking.rb index 8e1c549a69..bf97b6f0f7 100644 --- a/lib/open_project/plugins/frontend_linking.rb +++ b/lib/open_project/plugins/frontend_linking.rb @@ -28,7 +28,6 @@ module ::OpenProject::Plugins module FrontendLinking - ## # Register plugins with an Angular frontend to the CLI build. # For that, search all gems with the group :opf_plugins diff --git a/lib/open_project/plugins/frontend_linking/erb_context.rb b/lib/open_project/plugins/frontend_linking/erb_context.rb index 1883ba82d0..d60c163f8e 100644 --- a/lib/open_project/plugins/frontend_linking/erb_context.rb +++ b/lib/open_project/plugins/frontend_linking/erb_context.rb @@ -2,7 +2,6 @@ module OpenProject module Plugins module FrontendLinking class ErbContext - def initialize(plugins) @plugins = plugins.keys.map { |name, _| [name, importable_name(name)] } end diff --git a/lib/open_project/plugins/frontend_linking/generator.rb b/lib/open_project/plugins/frontend_linking/generator.rb index 817d52bcf7..b72db5718f 100644 --- a/lib/open_project/plugins/frontend_linking/generator.rb +++ b/lib/open_project/plugins/frontend_linking/generator.rb @@ -32,7 +32,6 @@ require 'fileutils' module ::OpenProject::Plugins module FrontendLinking class Generator - attr_reader :openproject_plugins def initialize @@ -90,10 +89,8 @@ module ::OpenProject::Plugins # Regenerate the frontend plugin module orchestrating the linked frontends def generate_plugin_module(plugins) file_register = Rails.root.join('frontend', 'src', 'app', 'modules', 'plugins', 'linked-plugins.module.ts') - template_file = File.read(File.expand_path('../linked-plugins.module.ts.erb', __FILE__)) - template = ::ERB.new template_file, - nil, - '-' + template_file = File.read(File.expand_path('linked-plugins.module.ts.erb', __dir__)) + template = ::ERB.new template_file, trim_mode: '-' puts "Regenerating frontend plugin registry #{file_register}." context = ::OpenProject::Plugins::FrontendLinking::ErbContext.new plugins diff --git a/lib/open_project/plugins/patch_registry.rb b/lib/open_project/plugins/patch_registry.rb index 2aadcd1de4..39bb69b840 100644 --- a/lib/open_project/plugins/patch_registry.rb +++ b/lib/open_project/plugins/patch_registry.rb @@ -37,8 +37,6 @@ module OpenProject::Plugins end end - protected - def self.patches @patches ||= Hash.new do |h, k| h[k] = [] diff --git a/lib/open_project/repository_authentication.rb b/lib/open_project/repository_authentication.rb index 4c80d7fc43..9e66aa5121 100644 --- a/lib/open_project/repository_authentication.rb +++ b/lib/open_project/repository_authentication.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/scm/adapters.rb b/lib/open_project/scm/adapters.rb index 53a2d82762..18abf273f3 100644 --- a/lib/open_project/scm/adapters.rb +++ b/lib/open_project/scm/adapters.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -60,6 +61,7 @@ module OpenProject class Info attr_accessor :root_url, :lastrev + def initialize(attributes = {}) self.root_url = attributes[:root_url] self.lastrev = attributes[:lastrev] @@ -68,8 +70,9 @@ module OpenProject class Entry attr_accessor :name, :path, :kind, :size, :lastrev + def initialize(attributes = {}) - [:name, :path, :kind, :size].each do |attr| + %i[name path kind size].each do |attr| send("#{attr}=", attributes[attr]) end @@ -88,13 +91,13 @@ module OpenProject class Revisions < Array def latest - sort { |x, y| + max do |x, y| if x.time.nil? or y.time.nil? 0 else x.time <=> y.time end - }.last + end end end @@ -103,7 +106,7 @@ module OpenProject attr_writer :identifier def initialize(attributes = {}) - [:identifier, :scmid, :author, :time, :paths, :revision, :branch].each do |attr| + %i[identifier scmid author time paths revision branch].each do |attr| send("#{attr}=", attributes[attr]) end diff --git a/lib/open_project/scm/adapters/base.rb b/lib/open_project/scm/adapters/base.rb index e3631d5a23..dfdcd28798 100644 --- a/lib/open_project/scm/adapters/base.rb +++ b/lib/open_project/scm/adapters/base.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -144,12 +145,12 @@ module OpenProject def with_leading_slash(path) path ||= '' - (path[0, 1] != '/') ? "/#{path}" : path + path[0, 1] != '/' ? "/#{path}" : path end def with_trailling_slash(path) path ||= '' - (path[-1, 1] == '/') ? path : "#{path}/" + path[-1, 1] == '/' ? path : "#{path}/" end def without_leading_slash(path) @@ -159,7 +160,7 @@ module OpenProject def without_trailling_slash(path) path ||= '' - (path[-1, 1] == '/') ? path[0..-2] : path + path[-1, 1] == '/' ? path[0..-2] : path end end diff --git a/lib/open_project/scm/adapters/checkout_instructions.rb b/lib/open_project/scm/adapters/checkout_instructions.rb index 8377971a10..0deb5f0d1d 100644 --- a/lib/open_project/scm/adapters/checkout_instructions.rb +++ b/lib/open_project/scm/adapters/checkout_instructions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/scm/adapters/git.rb b/lib/open_project/scm/adapters/git.rb index 085e963c9f..3ebb6731a1 100644 --- a/lib/open_project/scm/adapters/git.rb +++ b/lib/open_project/scm/adapters/git.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -197,7 +198,7 @@ module OpenProject def checkout? parsed = URI.parse checkout_uri %w(file http https git).include? parsed.scheme - rescue => e + rescue StandardError => e false end @@ -213,6 +214,7 @@ module OpenProject def branches return @branches if @branches + @branches = [] cmd_args = %w|branch --no-color| popen3(cmd_args) do |io| @@ -225,6 +227,7 @@ module OpenProject def tags return @tags if @tags + cmd_args = %w|tag| @tags = capture_git(cmd_args).lines.sort!.map(&:strip) end @@ -232,6 +235,7 @@ module OpenProject def default_branch bras = branches return nil if bras.nil? + bras.include?('master') ? 'master' : bras.first end @@ -260,8 +264,8 @@ module OpenProject Entry.new( name: scm_encode('UTF-8', @path_encoding, name), path: path, - kind: (type == 'tree') ? 'dir' : 'file', - size: (type == 'tree') ? nil : size, + kind: type == 'tree' ? 'dir' : 'file', + size: type == 'tree' ? nil : size, lastrev: @flag_report_last_commit ? lastrev(path, identifier) : Revision.new ) end @@ -274,6 +278,7 @@ module OpenProject def lastrev(path, rev) return nil if path.nil? + args = %w|log --no-color --encoding=UTF-8 --date=iso --pretty=fuller --no-merges -n 1| args << rev if rev args << '--' << path unless path.empty? @@ -282,7 +287,7 @@ module OpenProject build_lastrev(lines) rescue NoMethodError logger.error("The revision '#{path}' has a wrong format") - return nil + nil end end @@ -312,7 +317,7 @@ module OpenProject if line =~ /^commit ([0-9a-f]{40})$/ key = 'commit' value = $1 - if parsing_descr == 1 || parsing_descr == 2 + if [1, 2].include?(parsing_descr) parsing_descr = 0 revision = Revision.new( identifier: changeset[:commit], @@ -342,7 +347,7 @@ module OpenProject elsif (parsing_descr == 0) && line.chomp.to_s == '' parsing_descr = 1 changeset[:description] = '' - elsif (parsing_descr == 1 || parsing_descr == 2) && + elsif [1, 2, 1, 2, 1, 2].include?(parsing_descr) && (line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\t(.+)$/) parsing_descr = 2 @@ -350,7 +355,7 @@ module OpenProject filepath = $2 p = scm_encode('UTF-8', @path_encoding, filepath) files << { action: fileaction, path: p } - elsif (parsing_descr == 1 || parsing_descr == 2) && + elsif [1, 2, 1, 2, 1, 2, 1, 2, 1, 2].include?(parsing_descr) && (line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\d+\s+(\S+)\t(.+)$/) parsing_descr = 2 @@ -389,10 +394,10 @@ module OpenProject args = %w|log --no-color --encoding=UTF-8 --raw --date=iso --pretty=fuller| args << '--reverse' if options[:reverse] args << '--all' if options[:all] - args << '-n' << "#{options[:limit].to_i}" if options[:limit] + args << '-n' << options[:limit].to_i.to_s if options[:limit] from_to = '' from_to << "#{identifier_from}.." if identifier_from - from_to << "#{identifier_to}" if identifier_to + from_to << identifier_to.to_s if identifier_to args << from_to if from_to.present? args << "--since=#{options[:since].strftime('%Y-%m-%d %H:%M:%S')}" if options[:since] args << '--' << scm_encode(@path_encoding, 'UTF-8', path) if path && !path.empty? @@ -438,7 +443,9 @@ module OpenProject $1, Revision.new( identifier: identifier, - author: authors_by_commit[identifier])) + author: authors_by_commit[identifier] + ) + ) identifier = '' end end diff --git a/lib/open_project/scm/adapters/local_client.rb b/lib/open_project/scm/adapters/local_client.rb index b27a566294..c2e93f7190 100644 --- a/lib/open_project/scm/adapters/local_client.rb +++ b/lib/open_project/scm/adapters/local_client.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -181,7 +182,7 @@ module OpenProject Open3.popen3(client_command, *args, opts, &block) rescue Exceptions::SCMError => e raise e - rescue => e + rescue StandardError => e error_msg = "SCM command for `#{client_command}` failed: #{strip_credential(e.message)}" logger.error(error_msg) raise Exceptions::CommandFailed.new(client_command, error_msg) @@ -198,16 +199,17 @@ module OpenProject # with a placeholder def strip_credential(cmd) q = Redmine::Platform.mswin? ? '"' : "'" - cmd.to_s.gsub(/(\-\-(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx') + cmd.to_s.gsub(/(--(password|username))\s+(#{q}[^#{q}]+#{q}|[^#{q}]\S+)/, '\\1 xxxx') end def scm_encode(to, from, str) return nil if str.nil? return str if to == from + begin str.to_s.encode(to, from) - rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError => err - logger.error("failed to convert from #{from} to #{to}. #{err}") + rescue Encoding::InvalidByteSequenceError, Encoding::UndefinedConversionError => e + logger.error("failed to convert from #{from} to #{to}. #{e}") nil end end @@ -256,13 +258,11 @@ module OpenProject # being ~25% slower than shelling out to du def count_storage_fallback ::Find.find(local_repository_path).inject(0) do |sum, f| - begin - sum + File.stat(f).size - rescue SystemCallError - # File.stat raises for permission and access errors, - # we won't be able to get this file's size. - sum - end + sum + File.stat(f).size + rescue SystemCallError + # File.stat raises for permission and access errors, + # we won't be able to get this file's size. + sum end end end diff --git a/lib/open_project/scm/adapters/subversion.rb b/lib/open_project/scm/adapters/subversion.rb index 83ee8202d5..e79c24e61a 100644 --- a/lib/open_project/scm/adapters/subversion.rb +++ b/lib/open_project/scm/adapters/subversion.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -228,6 +229,7 @@ module OpenProject popen3(cmd) do |io, _| io.each_line do |line| next unless line =~ %r{^\s*(\d+)\s*(\S+)\s(.*)$} + blame.add_line($3.rstrip, Revision.new(identifier: $1.to_i, author: $2.strip)) end end @@ -354,7 +356,6 @@ module OpenProject end end - ## # Builds the full git arguments from the parameters # and calls the given block with in, out, err, thread diff --git a/lib/open_project/scm/exceptions.rb b/lib/open_project/scm/exceptions.rb index 2b46b1e517..595654e2b7 100644 --- a/lib/open_project/scm/exceptions.rb +++ b/lib/open_project/scm/exceptions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -43,9 +44,7 @@ module OpenProject # Exception marking an error in the execution of a local command. class CommandFailed < SCMError - attr_reader :program - attr_reader :message - attr_reader :stderr + attr_reader :program, :message, :stderr # Create a +CommandFailed+ exception for the executed program (e.g., 'svn'), # and a meaningful error message @@ -83,6 +82,7 @@ module OpenProject super('unauthorized') end end + # raised when encountering an empty (bare) repository class SCMEmpty < SCMUnavailable def initialize diff --git a/lib/open_project/scm/manageable_repository.rb b/lib/open_project/scm/manageable_repository.rb index 277aea7da0..40da0585b8 100644 --- a/lib/open_project/scm/manageable_repository.rb +++ b/lib/open_project/scm/manageable_repository.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/sql_sanitization.rb b/lib/open_project/sql_sanitization.rb index 671888ab37..9e9217ca2a 100644 --- a/lib/open_project/sql_sanitization.rb +++ b/lib/open_project/sql_sanitization.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,6 @@ #++ module OpenProject - ## # Provides helpers from ActiveRecord::Sanitization # outside model context diff --git a/lib/open_project/static/homescreen.rb b/lib/open_project/static/homescreen.rb index 00840b040e..cbdb09b18a 100644 --- a/lib/open_project/static/homescreen.rb +++ b/lib/open_project/static/homescreen.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/static/links.rb b/lib/open_project/static/links.rb index c9eb9e0d27..f563a23024 100644 --- a/lib/open_project/static/links.rb +++ b/lib/open_project/static/links.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -182,7 +183,7 @@ module OpenProject label: 'oauth.flows.client_credentials' }, ldap_encryption_documentation: { - href: 'https://www.rubydoc.info/gems/net-ldap/Net/LDAP#constructor_details', + href: 'https://www.rubydoc.info/gems/net-ldap/Net/LDAP#constructor_details' }, origin_mdn_documentation: { href: 'https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin' @@ -191,19 +192,19 @@ module OpenProject href: 'https://docs.openproject.org/system-admin-guide/information/#security-badge' }, chargebee: { - href: 'https://js.chargebee.com/v2/chargebee.js', + href: 'https://js.chargebee.com/v2/chargebee.js' }, webinar_videos: { - href: 'https://www.youtube.com/watch?v=ebc3lcSmncA&t=8s', + href: 'https://www.youtube.com/watch?v=ebc3lcSmncA&t=8s' }, get_started_videos: { - href: 'https://www.youtube.com/playlist?list=PLGzJ4gG7hPb8WWOWmeXqlfMfhdXReu-RJ', + href: 'https://www.youtube.com/playlist?list=PLGzJ4gG7hPb8WWOWmeXqlfMfhdXReu-RJ' }, openproject_docs: { - href: 'https://docs.openproject.org', + href: 'https://docs.openproject.org' }, contact_us: { - href: 'https://www.openproject.org/contact-us', + href: 'https://www.openproject.org/contact-us' } } end diff --git a/lib/open_project/storage.rb b/lib/open_project/storage.rb index f097ca6d8c..359d57d1ea 100644 --- a/lib/open_project/storage.rb +++ b/lib/open_project/storage.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/syntax_highlighting.rb b/lib/open_project/syntax_highlighting.rb index bc03d12543..82ae4e19bc 100644 --- a/lib/open_project/syntax_highlighting.rb +++ b/lib/open_project/syntax_highlighting.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/text_formatting.rb b/lib/open_project/text_formatting.rb index ed5e4f9a4d..8fdb53e95f 100644 --- a/lib/open_project/text_formatting.rb +++ b/lib/open_project/text_formatting.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/text_formatting/filters/macro_filter.rb b/lib/open_project/text_formatting/filters/macro_filter.rb index 6be695f876..a291162387 100644 --- a/lib/open_project/text_formatting/filters/macro_filter.rb +++ b/lib/open_project/text_formatting/filters/macro_filter.rb @@ -52,7 +52,7 @@ module OpenProject::TextFormatting begin macro_class.apply(macro, result: result, context: context) - rescue => e + rescue StandardError => e Rails.logger.error("Failed to insert macro #{macro_class}: #{e} - #{e.message}") macro.replace macro_error_placeholder(macro_class, e.message) ensure @@ -69,7 +69,8 @@ module OpenProject::TextFormatting def macro_error_placeholder(macro_class, message) ApplicationController.helpers.content_tag :macro, - "#{I18n.t(:macro_execution_error, macro_name: macro_class.identifier)} (#{message})", + "#{I18n.t(:macro_execution_error, + macro_name: macro_class.identifier)} (#{message})", class: 'macro-unavailable', data: { macro_name: macro_class.identifier } end diff --git a/lib/open_project/text_formatting/filters/sanitization_filter.rb b/lib/open_project/text_formatting/filters/sanitization_filter.rb index cac9873f1c..edd30c8fff 100644 --- a/lib/open_project/text_formatting/filters/sanitization_filter.rb +++ b/lib/open_project/text_formatting/filters/sanitization_filter.rb @@ -31,7 +31,6 @@ module OpenProject::TextFormatting module Filters class SanitizationFilter < HTML::Pipeline::SanitizationFilter - def whitelist base = super @@ -86,7 +85,7 @@ module OpenProject::TextFormatting # Support both the old css ('todo-list__label') as well as the new one # ('op-uc-list_task-list'). table.css('label.todo-list__label, .op-uc-list_task-list label').each do |label| - #table.css('.op-uc-list_task-list label').each do |label| + # table.css('.op-uc-list_task-list label').each do |label| checkbox = label.css('input[type=checkbox]').first li_node = label.ancestors.detect { |node| node.name == 'li' } diff --git a/lib/open_project/text_formatting/filters/table_of_contents_filter.rb b/lib/open_project/text_formatting/filters/table_of_contents_filter.rb index 43b0d8045f..281ada127d 100644 --- a/lib/open_project/text_formatting/filters/table_of_contents_filter.rb +++ b/lib/open_project/text_formatting/filters/table_of_contents_filter.rb @@ -129,7 +129,6 @@ module OpenProject::TextFormatting render_nested end end - rescue StandardError => e Rails.logger.error { "Failed to render table of contents: #{e} #{e.message}" } end diff --git a/lib/open_project/text_formatting/formats/base_formatter.rb b/lib/open_project/text_formatting/formats/base_formatter.rb index 9432c76d8f..d989ab408a 100644 --- a/lib/open_project/text_formatting/formats/base_formatter.rb +++ b/lib/open_project/text_formatting/formats/base_formatter.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb b/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb index 7dadcbdd65..8dae353e12 100644 --- a/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb +++ b/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb @@ -108,12 +108,12 @@ module OpenProject::TextFormatting::Formats out = (child.out || '').force_encoding('UTF-8').truncate(100) err = (child.err || '').force_encoding('UTF-8') - raise <<-ERRORSTR - Pandoc failed with code [#{code}] [Stopped=#{status.stopped?}] - #{signal_msg} - - #{out} - #{err} + raise <<~ERRORSTR + Pandoc failed with code [#{code}] [Stopped=#{status.stopped?}] + #{signal_msg} + #{' '} + #{out} + #{err} ERRORSTR end diff --git a/lib/open_project/text_formatting/formats/markdown/textile_converter.rb b/lib/open_project/text_formatting/formats/markdown/textile_converter.rb index 5faccba0c3..50103868f2 100644 --- a/lib/open_project/text_formatting/formats/markdown/textile_converter.rb +++ b/lib/open_project/text_formatting/formats/markdown/textile_converter.rb @@ -169,7 +169,7 @@ module OpenProject::TextFormatting::Formats markdowns_in_groups = [] begin - markdown = convert_textile_to_markdown(joined_textile, raise_on_timeout: true) + markdown = convert_textile_to_markdown(joined_textile, raise_on_timeout: true) markdowns_in_groups = split_markdown(markdown).each_slice(attributes.length).to_a rescue StandardError => e # Don't do anything. Let the subsequent code try to handle it again @@ -221,7 +221,6 @@ module OpenProject::TextFormatting::Formats def execute_pandoc_with_stdin!(textile, raise_on_timeout) pandoc.execute! textile rescue Timeout::Error => e - if raise_on_timeout logger.error <<~TIMEOUT_WARN Execution of pandoc timed out: #{e}. @@ -272,7 +271,7 @@ module OpenProject::TextFormatting::Formats ::AttributeHelpText => [:help_text], ::Comment => [:comments], ::WikiContent => [:text], - ::WorkPackage => [:description], + ::WorkPackage => [:description], ::Message => [:content], ::News => [:description], OldForum => [:description], @@ -366,12 +365,12 @@ module OpenProject::TextFormatting::Formats markdown.gsub!(/(.+)<\/span>/, '\1') markdown.gsub!(/#{BLOCKQUOTE_START}\n(.+?)\n\n#{BLOCKQUOTE_END}/m) do - $1.gsub(/([\n])([^\n]*)/, '\1> \2') + $1.gsub(/(\n)([^\n]*)/, '\1> \2') end # Create markdown links from !image!:link syntax # ![alt](image]) - markdown.gsub! /(?\!\[[^\]]*\]\([^\)]+\)):(?https?:\S+)/, + markdown.gsub! /(?!\[[^\]]*\]\([^)]+\)):(?https?:\S+)/, '[\k](\k)' # remove the escaping from links within parenthesis having a trailing slash @@ -391,7 +390,7 @@ module OpenProject::TextFormatting::Formats ( \{\{ # opening tag ([\w\\_]+) # macro name - (\(([^\}]*)\))? # optional arguments + (\(([^}]*)\))? # optional arguments \}\} # closing tag ) /x @@ -429,7 +428,7 @@ module OpenProject::TextFormatting::Formats # OpenProject support @ inside inline code marked with @ (such as "@git@github.com@"), but not pandoc. # So we inject a placeholder that will be replaced later on with a real backtick. def placeholder_for_inline_code_at(textile) - textile.gsub!(/@([\S]+@[\S]+)@/, TAG_CODE + '\\1' + TAG_CODE) + textile.gsub!(/@(\S+@\S+)@/, TAG_CODE + '\\1' + TAG_CODE) end # Drop table colspan/rowspan notation ("|\2." or "|/2.") because pandoc does not support it @@ -464,7 +463,7 @@ module OpenProject::TextFormatting::Formats # Remove empty paragraph blocks which trip up pandoc def remove_empty_paragraphs(textile) - textile.gsub!(/\np(=|>)?\.[\s\.]*\n/, '') + textile.gsub!(/\np(=|>)?\.[\s.]*\n/, '') end # Replace numbered headings as they are not supported in commonmark/gfm @@ -495,7 +494,7 @@ module OpenProject::TextFormatting::Formats def hard_breaks_within_multiline_tables(textile) content_regexp = %r{ (?<=\|) # Assert beginning table pipe lookbehind - ([^\|]{5,}) # Non-empty content + ([^|]{5,}) # Non-empty content (?=\|) # Assert ending table pipe lookahead }mx @@ -508,12 +507,11 @@ module OpenProject::TextFormatting::Formats # Wrap all blockquote blocks into boundaries as `>` is not valid blockquote syntax and would thus be # escaped def wrap_blockquotes(textile) - textile.gsub!(/(([\n]>[^\n]*)+)/m) do - "\n#{BLOCKQUOTE_START}\n" + $1.gsub(/([\n])> *([^\n]*)/, '\1\2') + "\n\n#{BLOCKQUOTE_END}\n" + textile.gsub!(/((\n>[^\n]*)+)/m) do + "\n#{BLOCKQUOTE_START}\n" + $1.gsub(/(\n)> *([^\n]*)/, '\1\2') + "\n\n#{BLOCKQUOTE_END}\n" end end - class OldForum < ::ActiveRecord::Base self.table_name = 'boards' end diff --git a/lib/open_project/text_formatting/matchers/attribute_macros.rb b/lib/open_project/text_formatting/matchers/attribute_macros.rb index aacd68eae1..9ba1b8bba9 100644 --- a/lib/open_project/text_formatting/matchers/attribute_macros.rb +++ b/lib/open_project/text_formatting/matchers/attribute_macros.rb @@ -52,7 +52,7 @@ module OpenProject::TextFormatting content.include?('Label:') || content.include?('Value:') end - def self.process_match(m, matched_string, context) + def self.process_match(m, _matched_string, _context) # Leading string before match macro_attributes = { model: m[1], diff --git a/lib/open_project/text_formatting/matchers/link_handlers/base.rb b/lib/open_project/text_formatting/matchers/link_handlers/base.rb index e59a9a8259..3702034481 100644 --- a/lib/open_project/text_formatting/matchers/link_handlers/base.rb +++ b/lib/open_project/text_formatting/matchers/link_handlers/base.rb @@ -96,10 +96,10 @@ module OpenProject::TextFormatting::Matchers # Passes on all remaining params. def named_route(name, **args) route = if context[:only_path] - :"#{name}_path" - else - :"#{name}_url" - end + :"#{name}_path" + else + :"#{name}_url" + end public_send(route, **args) end diff --git a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb index e5bcf622d9..3232f41568 100644 --- a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb +++ b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb @@ -93,7 +93,8 @@ module OpenProject::TextFormatting::Matchers if project&.repository && (changeset = Changeset.where(['repository_id = ? AND scmid LIKE ?', project.repository.id, "#{oid}%"]).first) link_to h("#{matcher.project_prefix}#{matcher.identifier}"), - { only_path: context[:only_path], controller: '/repositories', action: 'revision', project_id: project, rev: changeset.identifier }, + { only_path: context[:only_path], controller: '/repositories', action: 'revision', project_id: project, + rev: changeset.identifier }, class: 'changeset', title: truncate_single_line(changeset.comments, length: 100) end diff --git a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb index eacd637bba..f0ea1c6532 100644 --- a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb +++ b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb @@ -31,7 +31,6 @@ module OpenProject::TextFormatting::Matchers module LinkHandlers class HashSeparator < Base - def self.allowed_prefixes %w(version message project user group document meeting) end diff --git a/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb b/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb index 69c7d540d1..757cb12713 100644 --- a/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb +++ b/lib/open_project/text_formatting/matchers/link_handlers/revisions.rb @@ -51,7 +51,8 @@ module OpenProject::TextFormatting::Matchers if changeset link_to(h("#{matcher.project_prefix}r#{matcher.identifier}"), - { only_path: context[:only_path], controller: '/repositories', action: 'revision', project_id: project, rev: changeset.revision }, + { only_path: context[:only_path], controller: '/repositories', action: 'revision', project_id: project, + rev: changeset.revision }, class: 'changeset', title: truncate_single_line(changeset.comments, length: 100)) end diff --git a/lib/open_project/text_formatting/matchers/regex_matcher.rb b/lib/open_project/text_formatting/matchers/regex_matcher.rb index 15c5a0cb8c..08b884affe 100644 --- a/lib/open_project/text_formatting/matchers/regex_matcher.rb +++ b/lib/open_project/text_formatting/matchers/regex_matcher.rb @@ -39,7 +39,6 @@ module OpenProject::TextFormatting if process_node!(content, context) node.replace(content) end - rescue RuntimeError # If an error is occurred, instead of failing hard, simply do not replace. end diff --git a/lib/open_project/text_formatting/matchers/resource_links_matcher.rb b/lib/open_project/text_formatting/matchers/resource_links_matcher.rb index 417e447282..fb30431025 100644 --- a/lib/open_project/text_formatting/matchers/resource_links_matcher.rb +++ b/lib/open_project/text_formatting/matchers/resource_links_matcher.rb @@ -78,7 +78,7 @@ module OpenProject::TextFormatting def self.regexp %r{ - ([[[:space:]]\(,\-\[\>]|^) # Leading string + ([[[:space:]](,\-\[>]|^) # Leading string (!)? # Escaped marker (([a-z0-9\-_]+):)? # Project identifier (#{allowed_prefixes.join("|")})? # prefix @@ -224,7 +224,7 @@ module OpenProject::TextFormatting break end end - rescue => e + rescue StandardError => e Rails.logger.error "Failed link resource handling for #{matched_string}: #{e}" Rails.logger.debug { "Backtrace:\n\t#{e.backtrace.join("\n\t")}" } # Keep the original string unmatched diff --git a/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb b/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb index 5acd0378b5..a4d7ff3ef8 100644 --- a/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb +++ b/lib/open_project/text_formatting/matchers/wiki_links_matcher.rb @@ -51,7 +51,7 @@ module OpenProject::TextFormatting include OpenProject::StaticRouting::UrlHelpers def self.regexp - /(!)?(\[\[([^\]\n\|]+)(\|([^\]\n\|]+))?\]\])/ + /(!)?(\[\[([^\]\n|]+)(\|([^\]\n|]+))?\]\])/ end def self.process_match(m, matched_string, context) @@ -96,7 +96,7 @@ module OpenProject::TextFormatting @context = context # Check if linking project exists - if page =~ /\A([^\:]+)\:(.*)\z/ + if page =~ /\A([^:]+):(.*)\z/ @project = Project.find_by(identifier: $1) || Project.find_by(name: $1) @page = $2 @title ||= $1 if @page.blank? diff --git a/lib/open_project/text_formatting/truncation.rb b/lib/open_project/text_formatting/truncation.rb index f926bfc3a9..0ad00d378a 100644 --- a/lib/open_project/text_formatting/truncation.rb +++ b/lib/open_project/text_formatting/truncation.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/open_project/ui/extensible_tabs.rb b/lib/open_project/ui/extensible_tabs.rb index 425cdbcd0e..5c907137c7 100644 --- a/lib/open_project/ui/extensible_tabs.rb +++ b/lib/open_project/ui/extensible_tabs.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -48,6 +49,7 @@ module OpenProject tabs[key] = [] if tabs[key].nil? raise ArgumentError.new "Invalid entry for tab #{key}" unless entry[:name] && entry[:partial] + tabs[key] << entry end diff --git a/lib/open_project/version.rb b/lib/open_project/version.rb index 9a69487de1..70647d6428 100644 --- a/lib/open_project/version.rb +++ b/lib/open_project/version.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -119,10 +120,10 @@ module OpenProject return instance_variable_get(variable) if instance_variable_defined?(variable) value = begin - yield - rescue StandardError - nil - end + yield + rescue StandardError + nil + end instance_variable_set(variable, value) end diff --git a/lib/pagination/controller.rb b/lib/pagination/controller.rb index dc494a7227..93760ae107 100644 --- a/lib/pagination/controller.rb +++ b/lib/pagination/controller.rb @@ -167,11 +167,12 @@ module Pagination::Controller def define_action!(block = default_block) controller.pagination[action] = self raise NameError, "method '#{action}' already defined in #{controller}" if controller.respond_to? action + controller.send(:define_method, action, block) end def default_block - Proc.new { + Proc.new do # TODO: less evilness paginator = self.class.pagination[__method__] size = params[:page_limit].to_i || 10 @@ -181,16 +182,16 @@ module Pagination::Controller page = page.to_i methods = {} - [:pagination, :search].each do |meth| + %i[pagination search].each do |meth| methods[meth] = if paginator.send(meth).respond_to?(:call) paginator.send(meth) else paginator.model.method(paginator.send(meth)) - end + end end if (options = paginator.search_options).respond_to?(:call) - options = instance_eval(&(options.to_proc)) + options = instance_eval(&options.to_proc) end search_call = (options.presence ? methods[:search].call(params[:q], options) : methods[:search].call(params[:q])) @@ -202,23 +203,22 @@ module Pagination::Controller @more = @paginated_items.total_pages > page @total = @paginated_items.total_entries - instance_eval(&(paginator.response.to_proc)) + instance_eval(&paginator.response.to_proc) end - } + end end def default_response_block - Proc.new { + Proc.new do respond_to do |format| format.json do render json: { results: { items: @paginated_items.map { |item| { id: item.id, name: item.name } }, - total: @total ? @total : @paginated_items.size, - more: @more ? @more : 0 } - } + total: @total || @paginated_items.size, + more: @more || 0 } } end end - } + end end end @@ -236,7 +236,7 @@ module Pagination::Controller def paginate_model(model) pagination_class.resolve_model(model) - pagination[model] = (pagination_class.new(self, model)) + pagination[model] = pagination_class.new(self, model) pagination[model].refresh_action! end @@ -287,7 +287,7 @@ module Pagination::Controller if inst.nil? raise ArgumentError, "Model #{model} is not being paginated. Call #paginate_model(s) first." else - return inst + inst end end end diff --git a/lib/pagination/model.rb b/lib/pagination/model.rb index 5604eed3b2..2f68a35596 100644 --- a/lib/pagination/model.rb +++ b/lib/pagination/model.rb @@ -36,9 +36,8 @@ module Pagination::Model end def self.extended(base) - unless base.respond_to? :like - base.scope :like, -> (q) { + base.scope :like, ->(q) { s = "%#{q.to_s.strip.downcase}%" base.where(['LOWER(name) LIKE :s', { s: s }]) .order(Arel.sql('name')) diff --git a/lib/plugins/acts_as_attachable/init.rb b/lib/plugins/acts_as_attachable/init.rb index 8330f494fb..79f08b1d98 100644 --- a/lib/plugins/acts_as_attachable/init.rb +++ b/lib/plugins/acts_as_attachable/init.rb @@ -27,5 +27,6 @@ #++ #-- encoding: UTF-8 + require File.dirname(__FILE__) + '/lib/acts_as_attachable' -ActiveRecord::Base.send(:include, Redmine::Acts::Attachable) +ActiveRecord::Base.include Redmine::Acts::Attachable diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb index c0afb65a42..a251638085 100644 --- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb +++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb @@ -52,6 +52,7 @@ module Redmine attr_accessor :attachments_replacements, :attachments_claimed + send :include, Redmine::Acts::Attachable::InstanceMethods OpenProject::Deprecation.deprecate_method self, :attach_files diff --git a/lib/plugins/acts_as_customizable/init.rb b/lib/plugins/acts_as_customizable/init.rb index 32b3722379..82465c4aca 100644 --- a/lib/plugins/acts_as_customizable/init.rb +++ b/lib/plugins/acts_as_customizable/init.rb @@ -27,6 +27,7 @@ #++ #-- encoding: UTF-8 + require File.dirname(__FILE__) + '/lib/acts_as_customizable' require File.dirname(__FILE__) + '/lib/human_attribute_name' -ActiveRecord::Base.send(:include, Redmine::Acts::Customizable) +ActiveRecord::Base.include Redmine::Acts::Customizable diff --git a/lib/plugins/acts_as_event/init.rb b/lib/plugins/acts_as_event/init.rb index ce4dd37668..474f006d3b 100644 --- a/lib/plugins/acts_as_event/init.rb +++ b/lib/plugins/acts_as_event/init.rb @@ -27,5 +27,6 @@ #++ #-- encoding: UTF-8 + require File.dirname(__FILE__) + '/lib/acts_as_event' -ActiveRecord::Base.send(:include, Redmine::Acts::Event) +ActiveRecord::Base.include Redmine::Acts::Event diff --git a/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb b/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb index f7d00b7e79..4ea15cafcd 100644 --- a/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb +++ b/lib/plugins/acts_as_journalized/lib/acts_as_journalized.rb @@ -53,7 +53,7 @@ require 'journal_formatter' module Acts end -Dir[File.expand_path('../acts/journalized/*.rb', __FILE__)].sort.each { |f| require f } +Dir[File.expand_path('acts/journalized/*.rb', __dir__)].sort.each { |f| require f } module Acts module Journalized diff --git a/lib/plugins/acts_as_journalized/lib/journal_deprecated.rb b/lib/plugins/acts_as_journalized/lib/journal_deprecated.rb index 16ed9738e9..f7c086135d 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_deprecated.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_deprecated.rb @@ -27,6 +27,7 @@ #++ #-- encoding: UTF-8 + # This file is part of the acts_as_journalized plugin for the redMine # project management software # diff --git a/lib/plugins/acts_as_journalized/lib/journal_detail.rb b/lib/plugins/acts_as_journalized/lib/journal_detail.rb index ed0fbe749b..877d10d111 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_detail.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_detail.rb @@ -27,6 +27,7 @@ #++ #-- encoding: UTF-8 + class JournalDetail attr_reader :prop_key, :value, :old_value diff --git a/lib/plugins/acts_as_journalized/lib/journal_formatter.rb b/lib/plugins/acts_as_journalized/lib/journal_formatter.rb index cbcb8eb2d6..e3bede4f40 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_formatter.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_formatter.rb @@ -27,6 +27,7 @@ #++ #-- encoding: UTF-8 + # This file is part of the acts_as_journalized plugin for the redMine # project management software # diff --git a/lib/plugins/acts_as_journalized/lib/journal_formatter/datetime.rb b/lib/plugins/acts_as_journalized/lib/journal_formatter/datetime.rb index 021c1e5bc0..fd787ac8f9 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_formatter/datetime.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_formatter/datetime.rb @@ -30,9 +30,11 @@ module JournalFormatter class Datetime < Attribute def format_values(values) values.map do |v| - v.nil? ? - nil : + if v.nil? + nil + else format_date(v.to_date) + end end end end diff --git a/lib/plugins/acts_as_journalized/lib/journal_formatter/fraction.rb b/lib/plugins/acts_as_journalized/lib/journal_formatter/fraction.rb index 660c4b6372..57081c4e2b 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_formatter/fraction.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_formatter/fraction.rb @@ -32,9 +32,11 @@ module JournalFormatter def format_values(values) values.map do |v| - v.nil? ? - nil : + if v.nil? + nil + else number_with_precision(v.to_f, precision: 2) + end end end end diff --git a/lib/plugins/acts_as_journalized/lib/journal_formatter/named_association.rb b/lib/plugins/acts_as_journalized/lib/journal_formatter/named_association.rb index 7210bc89c2..66f36263e5 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_formatter/named_association.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_formatter/named_association.rb @@ -49,7 +49,7 @@ module JournalFormatter end def format_values(values, key, options) - field = key.to_s.gsub(/\_id\z/, '').to_sym + field = key.to_s.gsub(/_id\z/, '').to_sym klass = class_from_field(field) values.map do |value| diff --git a/lib/plugins/acts_as_journalized/lib/journal_formatter/proc.rb b/lib/plugins/acts_as_journalized/lib/journal_formatter/proc.rb index 9713965dce..9139e7c199 100644 --- a/lib/plugins/acts_as_journalized/lib/journal_formatter/proc.rb +++ b/lib/plugins/acts_as_journalized/lib/journal_formatter/proc.rb @@ -43,7 +43,7 @@ module JournalFormatter end def format_values(values, key) - field = key.to_s.gsub(/\_id\z/, '') + field = key.to_s.gsub(/_id\z/, '') values.map do |value| self.class.proc.call value, @journal.journable, field diff --git a/lib/plugins/acts_as_searchable/init.rb b/lib/plugins/acts_as_searchable/init.rb index d8bb2247ee..4ad18ec278 100644 --- a/lib/plugins/acts_as_searchable/init.rb +++ b/lib/plugins/acts_as_searchable/init.rb @@ -27,5 +27,6 @@ #++ #-- encoding: UTF-8 + require File.dirname(__FILE__) + '/lib/acts_as_searchable' -ActiveRecord::Base.send(:include, Redmine::Acts::Searchable) +ActiveRecord::Base.include Redmine::Acts::Searchable diff --git a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb index fc73039d34..bd28604c17 100644 --- a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb +++ b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb @@ -59,7 +59,10 @@ module Redmine searchable_options[:order_column] ||= searchable_options[:date_column] # Permission needed to search this model - searchable_options[:permission] = "view_#{name.underscore.pluralize}".to_sym unless searchable_options.has_key?(:permission) + unless searchable_options.has_key?(:permission) + searchable_options[:permission] = + "view_#{name.underscore.pluralize}".to_sym + end # Should we search custom fields on this model ? searchable_options[:search_custom_fields] = !reflect_on_association(:custom_values).nil? diff --git a/lib/plugins/acts_as_watchable/init.rb b/lib/plugins/acts_as_watchable/init.rb index 41e78862aa..e0ecf611c4 100644 --- a/lib/plugins/acts_as_watchable/init.rb +++ b/lib/plugins/acts_as_watchable/init.rb @@ -27,8 +27,9 @@ #++ #-- encoding: UTF-8 + # Include hook code here require File.dirname(__FILE__) + '/lib/acts_as_watchable' require File.dirname(__FILE__) + '/lib/acts_as_watchable/routes.rb' -ActiveRecord::Base.send(:include, Redmine::Acts::Watchable) +ActiveRecord::Base.include Redmine::Acts::Watchable diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable/routes.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable/routes.rb index 1c1969659c..9a138d4fb4 100644 --- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable/routes.rb +++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable/routes.rb @@ -39,16 +39,14 @@ module OpenProject /\d+/.match(params[:object_id]) end - private - def self.watched?(object) - self.watchable_object? object + watchable_object? object end def self.watchable_object?(object) klass = object.to_s.classify.constantize klass.included_modules.include? Redmine::Acts::Watchable - rescue + rescue StandardError false end end diff --git a/lib/plugins/load_path_helper.rb b/lib/plugins/load_path_helper.rb index 824cc993af..8bd563594f 100644 --- a/lib/plugins/load_path_helper.rb +++ b/lib/plugins/load_path_helper.rb @@ -29,13 +29,11 @@ module Plugins module LoadPathHelper def self.spec_load_paths - plugin_load_paths.map { |path| + plugin_load_paths.map do |path| File.join(path, 'spec') - }.keep_if{ |path| File.directory?(path) } + end.keep_if { |path| File.directory?(path) } end - private - # fetch load paths for available plugins def self.plugin_load_paths Rails.application.config.plugins_to_test_paths.map(&:to_s) diff --git a/lib/plugins/verification/lib/action_controller/verification.rb b/lib/plugins/verification/lib/action_controller/verification.rb index 5a8aa4c1e5..c36261c2be 100644 --- a/lib/plugins/verification/lib/action_controller/verification.rb +++ b/lib/plugins/verification/lib/action_controller/verification.rb @@ -2,7 +2,9 @@ module ActionController #:nodoc: module Verification #:nodoc: extend ActiveSupport::Concern - include AbstractController::Callbacks, Flash, Rendering + include Rendering + include Flash + include AbstractController::Callbacks # This module provides a class-level method for specifying that certain # actions are guarded against being called without certain prerequisites @@ -104,7 +106,7 @@ module ActionController #:nodoc: def verify_presence_of_keys_in_hash_flash_or_params(options) # :nodoc: [*options[:params]].find { |v| v && params[v.to_sym].nil? } || [*options[:session]].find { |v| session[v].nil? } || - [*options[:flash]].find { |v| flash[v].nil? } + [*options[:flash]].find { |v| flash[v].nil? } end def verify_method(options) # :nodoc: @@ -116,17 +118,16 @@ module ActionController #:nodoc: end def apply_redirect_to(redirect_to_option) # :nodoc: - (redirect_to_option.is_a?(Symbol) && redirect_to_option != :back) ? __send__(redirect_to_option) : redirect_to_option + redirect_to_option.is_a?(Symbol) && redirect_to_option != :back ? __send__(redirect_to_option) : redirect_to_option end def apply_remaining_actions(options) # :nodoc: - case - when options[:render]; render(options[:render]) - when options[:redirect_to]; redirect_to(apply_redirect_to(options[:redirect_to])) + if options[:render]; render(options[:render]) + elsif options[:redirect_to]; redirect_to(apply_redirect_to(options[:redirect_to])) else head(:bad_request) end end end end -ActionController::Base.send :include, ActionController::Verification +ActionController::Base.include ActionController::Verification diff --git a/lib/redmine/about.rb b/lib/redmine/about.rb index d4cd45b4a5..daf7e899b1 100644 --- a/lib/redmine/about.rb +++ b/lib/redmine/about.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/redmine/codeset_util.rb b/lib/redmine/codeset_util.rb index 07ac804ac8..dc73aa0f8a 100644 --- a/lib/redmine/codeset_util.rb +++ b/lib/redmine/codeset_util.rb @@ -30,6 +30,7 @@ module Redmine module CodesetUtil def self.replace_invalid_utf8(str) return str if str.nil? + str.force_encoding('UTF-8') if str.valid_encoding? str @@ -44,6 +45,7 @@ module Redmine def self.to_utf8(str, encoding) return str if str.nil? + str.force_encoding('ASCII-8BIT') if str.empty? str.force_encoding('UTF-8') diff --git a/lib/redmine/diff.rb b/lib/redmine/diff.rb index 51b5382736..ce8a276ef7 100644 --- a/lib/redmine/diff.rb +++ b/lib/redmine/diff.rb @@ -33,13 +33,7 @@ module Redmine class Diff include ActionView::Helpers::TagHelper - attr_accessor :nb_line_left - attr_accessor :line_left - attr_accessor :nb_line_right - attr_accessor :line_right - attr_accessor :type_diff_right - attr_accessor :type_diff_left - attr_accessor :offsets + attr_accessor :nb_line_left, :line_left, :nb_line_right, :line_right, :type_diff_right, :type_diff_left, :offsets def initialize self.nb_line_left = '' @@ -91,13 +85,13 @@ module Redmine ActiveSupport::SafeBuffer.new.tap do |output| if offsets.first != 0 - output << line[0..offsets.first-1] + output << line[0..offsets.first - 1] end output << content_tag(:span, line[offsets.first..offsets.last]) unless offsets.last == -1 - output << line[offsets.last+1..-1] + output << line[offsets.last + 1..-1] end end.to_s end diff --git a/lib/redmine/diff/array_string_diff.rb b/lib/redmine/diff/array_string_diff.rb index 1cba92d115..372653a9e0 100644 --- a/lib/redmine/diff/array_string_diff.rb +++ b/lib/redmine/diff/array_string_diff.rb @@ -64,15 +64,16 @@ class Redmine::Diff::ArrayStringDiff (astart..afinish).each do |aindex| aelem = a[aindex] next unless bmatches.has_key? aelem + k = nil - bmatches[aelem].reverse_each { |bindex| + bmatches[aelem].reverse_each do |bindex| if k && (thresh[k] > bindex) && (thresh[k - 1] < bindex) thresh[k] = bindex else k = thresh.replacenextlarger(bindex, k) end - links[k] = [(k == 0) ? nil : links[k - 1], aindex, bindex] if k - } + links[k] = [k == 0 ? nil : links[k - 1], aindex, bindex] if k + end end if !thresh.empty? @@ -128,7 +129,7 @@ class Redmine::Diff::ArrayStringDiff i += 1 while df[i] && df[i][0] == whot && df[i][1] == last + 1 s << df[i][2] - last = df[i][1] + last = df[i][1] i += 1 end curdiff.push [whot, p, s] diff --git a/lib/redmine/diff/diffable.rb b/lib/redmine/diff/diffable.rb index 30c6adeb49..3612aa9d26 100644 --- a/lib/redmine/diff/diffable.rb +++ b/lib/redmine/diff/diffable.rb @@ -56,7 +56,7 @@ module Redmine::Diff::Diffable def replacenextlarger(value, high = nil) high ||= length - if self.empty? || value > self[-1] + if empty? || value > self[-1] push value return high end @@ -66,6 +66,7 @@ module Redmine::Diff::Diffable index = (high + low) / 2 found = self[index] return nil if value == found + if value > found low = index + 1 else @@ -83,15 +84,15 @@ module Redmine::Diff::Diffable def patch(diff) newary = nil - if diff.difftype == String - newary = diff.difftype.new('') - else - newary = diff.difftype.new - end + newary = if diff.difftype == String + diff.difftype.new('') + else + diff.difftype.new + end ai = 0 bi = 0 diff.diffs.each do |d| - d.each { |mod| + d.each do |mod| case mod[0] when '-' while ai < mod[1] @@ -111,7 +112,7 @@ module Redmine::Diff::Diffable else raise 'Unknown diff action' end - } + end end while ai < length newary << self[ai] diff --git a/lib/redmine/diff_table.rb b/lib/redmine/diff_table.rb index d9ddac1fc4..5bd9ccab5c 100644 --- a/lib/redmine/diff_table.rb +++ b/lib/redmine/diff_table.rb @@ -45,24 +45,22 @@ module Redmine # Function for add a line of this Diff # Returns false when the diff ends def add_line(line) - unless @parsing - if line =~ /^(---|\+\+\+) (.*)$/ - @file_name = $2 - elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ - @line_num_l = $2.to_i - @line_num_r = $5.to_i - @parsing = true - end - else - if line =~ /^[^\+\-\s@\\]/ + if @parsing + if line =~ /^[^+\-\s@\\]/ @parsing = false return false - elsif line =~ /^@@ (\+|\-)(\d+)(,\d+)? (\+|\-)(\d+)(,\d+)? @@/ + elsif line =~ /^@@ (\+|-)(\d+)(,\d+)? (\+|-)(\d+)(,\d+)? @@/ @line_num_l = $2.to_i @line_num_r = $5.to_i else parse_line(line, @type) end + elsif line =~ /^(---|\+\+\+) (.*)$/ + @file_name = $2 + elsif line =~ /^@@ (\+|-)(\d+)(,\d+)? (\+|-)(\d+)(,\d+)? @@/ + @line_num_l = $2.to_i + @line_num_r = $5.to_i + @parsing = true end true end @@ -143,7 +141,7 @@ module Redmine if @added > 0 && @added == @removed @added.times do |i| line = self[-(1 + i)] - removed = (@type == 'sbs') ? line : self[-(1 + @added + i)] + removed = @type == 'sbs' ? line : self[-(1 + @added + i)] offsets = offsets(removed.line_left, line.line_right) removed.offsets = line.offsets = offsets end diff --git a/lib/redmine/helpers/diff.rb b/lib/redmine/helpers/diff.rb index b1e2238fea..19a403bbf6 100644 --- a/lib/redmine/helpers/diff.rb +++ b/lib/redmine/helpers/diff.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -57,26 +58,28 @@ module Redmine diff.each do |change| pos = change[1] if change[0] == '+' - add_at = pos + dels unless add_at + add_at ||= pos + dels add_to = pos + dels words_add += 1 else - del_at = pos unless del_at + del_at ||= pos deleted << ' ' + h(change[2]) words_del += 1 end end if add_at - words[add_at] = ('').html_safe + words[add_at] - words[add_to] = words[add_to] + ('').html_safe + words[add_at] = + ('').html_safe + words[add_at] + words[add_to] = + words[add_to] + ('').html_safe end if del_at words.insert del_at - del_off + dels + words_add, ('').html_safe + deleted + - ('').html_safe + ('').html_safe dels += 1 del_off += words_del words_del = 0 diff --git a/lib/redmine/hook.rb b/lib/redmine/hook.rb index 6284b35deb..b69f1bf8e7 100644 --- a/lib/redmine/hook.rb +++ b/lib/redmine/hook.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -38,6 +39,7 @@ module Redmine # Automatically called when a class inherits from Redmine::Hook::Listener. def add_listener(klass) raise 'Hooks must include Singleton module.' unless klass.included_modules.include?(Singleton) + @@listener_classes << klass clear_listeners_instances end diff --git a/lib/redmine/i18n.rb b/lib/redmine/i18n.rb index 7f39900546..3b69e81783 100644 --- a/lib/redmine/i18n.rb +++ b/lib/redmine/i18n.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -66,11 +67,12 @@ module Redmine end def ll(lang, str, value = nil) - ::I18n.t(str.to_s, value: value, locale: lang.to_s.gsub(%r{(.+)\-(.+)$}) { "#{$1}-#{$2.upcase}" }) + ::I18n.t(str.to_s, value: value, locale: lang.to_s.gsub(%r{(.+)-(.+)$}) { "#{$1}-#{$2.upcase}" }) end def format_date(date) return nil unless date + Setting.date_format.blank? ? ::I18n.l(date.to_date) : date.strftime(Setting.date_format) end @@ -120,16 +122,26 @@ module Redmine # otherwise just use the date in the time zone attached to the time def format_time_as_date(time, format) return nil unless time + zone = User.current.time_zone - local_date = (zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)).to_date + local_date = (if zone + time.in_time_zone(zone) + else + (time.utc? ? time.localtime : time) + end).to_date local_date.strftime(format) end def format_time(time, include_date = true) return nil unless time + time = time.to_time if time.is_a?(String) zone = User.current.time_zone - local = zone ? time.in_time_zone(zone) : (time.utc? ? time.to_time.localtime : time) + local = if zone + time.in_time_zone(zone) + else + (time.utc? ? time.to_time.localtime : time) + end (include_date ? "#{format_date(local)} " : '') + (Setting.time_format.blank? ? ::I18n.l(local, format: :time) : local.strftime(Setting.time_format)) end @@ -153,7 +165,7 @@ module Redmine ## # Returns the given language if it is valid or nil otherwise. def find_language(lang) - return nil unless (lang.present? && lang =~ /[a-z-]+/i) + return nil unless lang.present? && lang =~ /[a-z-]+/i # Direct match direct_match = valid_languages.detect { |l| l =~ /^#{lang}$/i } @@ -175,11 +187,13 @@ module Redmine # Collects all translations for ActiveRecord attributes def all_attribute_translations(locale = current_locale) @cached_attribute_translations ||= {} - @cached_attribute_translations[locale] ||= ( + @cached_attribute_translations[locale] ||= begin general_attributes = ::I18n.t('attributes', locale: locale) - ::I18n.t('activerecord.attributes', locale: locale).inject(general_attributes) { |attr_t, model_t| + ::I18n.t('activerecord.attributes', + locale: locale).inject(general_attributes) do |attr_t, model_t| attr_t.merge(model_t.last || {}) - }) + end + end @cached_attribute_translations[locale] end end diff --git a/lib/redmine/imap.rb b/lib/redmine/imap.rb index 41f8385e55..4fc70331fa 100644 --- a/lib/redmine/imap.rb +++ b/lib/redmine/imap.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -72,7 +73,7 @@ module Redmine raise "Message was not successfully handled." unless MailHandler.receive(msg, options) message_received(message_id, imap, imap_options) - rescue => e + rescue StandardError => e Rails.logger.error { "Message #{message_id} resulted in error #{e} #{e.message}" } message_error(message_id, imap, imap_options) end @@ -84,7 +85,7 @@ module Redmine imap.copy(message_id, imap_options[:move_on_success]) end - imap.store(message_id, '+FLAGS', [:Seen, :Deleted]) + imap.store(message_id, '+FLAGS', %i[Seen Deleted]) end def message_error(message_id, imap, imap_options) diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index 85f0274a6e..21ae1de813 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/redmine/menu_manager/mapper.rb b/lib/redmine/menu_manager/mapper.rb index 2475e0e2bf..9f3baa95d2 100644 --- a/lib/redmine/menu_manager/mapper.rb +++ b/lib/redmine/menu_manager/mapper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -56,18 +57,18 @@ class Redmine::MenuManager::Mapper if options[:parent] subtree = find(options[:parent]) - if subtree - target_root = subtree - else - target_root = @menu_items.root - end + target_root = if subtree + subtree + else + @menu_items.root + end else target_root = @menu_items.root end # menu item position - if first = options.delete(:first) + if options.delete(:first) target_root.prepend(Redmine::MenuManager::MenuItem.new(name, url, options)) elsif before = options.delete(:before) @@ -128,13 +129,7 @@ class Redmine::MenuManager::MapDeferrer @menu_builder_queue = menu_builder_queue end - def defer(method, *args) - ActiveSupport::Deprecation.warn "Calling #{method} and accessing the the menu object from outside of the block attached to the map method is deprecated and will be removed in ChiliProject 3.0. Please access the menu object from within the attached block instead. Please also note the differences between the APIs.", caller.drop(1) - menu_builder = proc { |menu_mapper| menu_mapper.send(method, *args) } - @menu_builder_queue.push(menu_builder) - end - - [:push, :delete, :exists?, :find, :position_of].each do |method| + %i[push delete exists? find position_of].each do |method| define_method method do |*args| defer(method, *args) end diff --git a/lib/redmine/menu_manager/menu_controller.rb b/lib/redmine/menu_manager/menu_controller.rb index 45081f93bb..d8fad61875 100644 --- a/lib/redmine/menu_manager/menu_controller.rb +++ b/lib/redmine/menu_manager/menu_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -68,7 +69,7 @@ module Redmine::MenuManager::MenuController def menu_items self.class.menu_items end - + # Returns the menu item name according to the current action def current_menu_item return @current_menu_item if @current_menu_item_determined diff --git a/lib/redmine/menu_manager/menu_error.rb b/lib/redmine/menu_manager/menu_error.rb index 99508f06d0..7a3ca48509 100644 --- a/lib/redmine/menu_manager/menu_error.rb +++ b/lib/redmine/menu_manager/menu_error.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb index 154142b81c..c141f89d73 100644 --- a/lib/redmine/menu_manager/menu_helper.rb +++ b/lib/redmine/menu_manager/menu_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -213,7 +214,10 @@ module Redmine::MenuManager::MenuHelper end def render_unattached_menu_item(menu_item, project) - raise Redmine::MenuManager::MenuError, ':child_menus must be an array of MenuItems' unless menu_item.is_a? Redmine::MenuManager::MenuItem + unless menu_item.is_a? Redmine::MenuManager::MenuItem + raise Redmine::MenuManager::MenuError, + ':child_menus must be an array of MenuItems' + end if User.current.allowed_to?(menu_item.url(project), project) link_to(menu_item.caption, diff --git a/lib/redmine/menu_manager/menu_item.rb b/lib/redmine/menu_manager/menu_item.rb index 8265d77bc1..b132d0bf3f 100644 --- a/lib/redmine/menu_manager/menu_item.rb +++ b/lib/redmine/menu_manager/menu_item.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -44,7 +45,12 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call) raise ArgumentError, "Invalid option :html for menu item '#{name}'" if options[:html] && !options[:html].is_a?(Hash) raise ArgumentError, 'Cannot set the :parent to be the same as this item' if options[:parent] == name.to_sym - raise ArgumentError, "Invalid option :children for menu item '#{name}'" if options[:children] && !options[:children].respond_to?(:call) + + if options[:children] && !options[:children].respond_to?(:call) + raise ArgumentError, + "Invalid option :children for menu item '#{name}'" + end + @name = name @url = url @condition = options[:if] @@ -73,12 +79,10 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode c = @caption.call(project).to_s c = @name.to_s.humanize if c.blank? c + elsif @caption.nil? + l_or_humanize(name, prefix: 'label_') else - if @caption.nil? - l_or_humanize(name, prefix: 'label_') - else - @caption.is_a?(Symbol) ? I18n.t(@caption) : @caption - end + @caption.is_a?(Symbol) ? I18n.t(@caption) : @caption end end @@ -145,11 +149,12 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode def add_condition(new_condition) raise ArgumentError, 'Condition needs to be callable' unless new_condition.respond_to?(:call) + old_condition = @condition - if old_condition.respond_to?(:call) - @condition = -> (project) { old_condition.call(project) && new_condition.call(project) } - else - @condition = -> (project) { new_condition.call(project) } - end + @condition = if old_condition.respond_to?(:call) + ->(project) { old_condition.call(project) && new_condition.call(project) } + else + ->(project) { new_condition.call(project) } + end end end diff --git a/lib/redmine/menu_manager/top_menu/help_menu.rb b/lib/redmine/menu_manager/top_menu/help_menu.rb index 1be9d98ff3..401e093f2d 100644 --- a/lib/redmine/menu_manager/top_menu/help_menu.rb +++ b/lib/redmine/menu_manager/top_menu/help_menu.rb @@ -88,15 +88,16 @@ module Redmine::MenuManager::TopMenu::HelpMenu title: I18n.t('top_menu.help_and_support') end if EnterpriseToken.show_banners? - result << static_link_item(:upsale, href_suffix: "/?utm_source=unknown&utm_medium=op-instance&utm_campaign=ee-upsale-help-menu") + result << static_link_item(:upsale, + href_suffix: "/?utm_source=unknown&utm_medium=op-instance&utm_campaign=ee-upsale-help-menu") end result << static_link_item(:user_guides) - result << content_tag(:li) { + result << content_tag(:li) do link_to I18n.t('label_videos'), OpenProject::Configuration.youtube_channel, title: I18n.t('label_videos'), target: '_blank' - } + end result << static_link_item(:shortcuts) result << static_link_item(:forums) result << static_link_item(:professional_support) diff --git a/lib/redmine/menu_manager/top_menu/projects_menu.rb b/lib/redmine/menu_manager/top_menu/projects_menu.rb index 6537393dbf..810e183467 100644 --- a/lib/redmine/menu_manager/top_menu/projects_menu.rb +++ b/lib/redmine/menu_manager/top_menu/projects_menu.rb @@ -76,7 +76,7 @@ module Redmine::MenuManager::TopMenu::ProjectsMenu icon: "icon-add icon4", html: { accesskey: OpenProject::AccessKeys.key_for(:new_project), - aria: {label: t(:label_project_new)}, + aria: { label: t(:label_project_new) }, title: t(:label_project_new) }, if: Proc.new { User.current.allowed_to?(:add_project, nil, global: true) } diff --git a/lib/redmine/menu_manager/top_menu_helper.rb b/lib/redmine/menu_manager/top_menu_helper.rb index de620241ac..7de1305967 100644 --- a/lib/redmine/menu_manager/top_menu_helper.rb +++ b/lib/redmine/menu_manager/top_menu_helper.rb @@ -121,9 +121,9 @@ module Redmine::MenuManager::TopMenuHelper end def render_main_top_menu_nodes(items = main_top_menu_items) - items.map { |item| + items.map do |item| render_menu_node(item) - }.join(' ') + end.join(' ') end # Menu items for the main top menu diff --git a/lib/redmine/menu_manager/tree_node.rb b/lib/redmine/menu_manager/tree_node.rb index 0724a3c0b8..d8309ff129 100644 --- a/lib/redmine/menu_manager/tree_node.rb +++ b/lib/redmine/menu_manager/tree_node.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -43,7 +44,7 @@ class Redmine::MenuManager::TreeNode < Tree::TreeNode def prepend(child) raise(ArgumentError, 'Child already added') if @children_hash.has_key?(child.name) - @children_hash[child.name] = child + @children_hash[child.name] = child @children = [child] + @children child.parent = self child @@ -55,7 +56,7 @@ class Redmine::MenuManager::TreeNode < Tree::TreeNode def add_at(child, position) raise(ArgumentError, 'Child already added') if @children_hash.has_key?(child.name) - @children_hash[child.name] = child + @children_hash[child.name] = child @children = @children.insert(position, child) child.parent = self child @@ -64,7 +65,7 @@ class Redmine::MenuManager::TreeNode < Tree::TreeNode def add_last(child) raise(ArgumentError, 'Child already added') if @children_hash.has_key?(child.name) - @children_hash[child.name] = child + @children_hash[child.name] = child @children << child @last_items_count += 1 child.parent = self diff --git a/lib/redmine/menu_manager/wiki_menu_helper.rb b/lib/redmine/menu_manager/wiki_menu_helper.rb index b237906630..6eb1ff409c 100644 --- a/lib/redmine/menu_manager/wiki_menu_helper.rb +++ b/lib/redmine/menu_manager/wiki_menu_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,6 +31,7 @@ module Redmine::MenuManager::WikiMenuHelper def build_wiki_menus(project) return unless project.enabled_module_names.include? 'wiki' + project_wiki = project.wiki MenuItems::WikiMenuItem.main_items(project_wiki).each do |main_item| @@ -50,7 +52,7 @@ module Redmine::MenuManager::WikiMenuHelper caption: main_item.title, after: :repository, icon: 'icon2 icon-wiki', - html: { class: 'wiki-menu--main-item' } + html: { class: 'wiki-menu--main-item' } if project.wiki.pages.any? push_wiki_menu_partial(main_item, menu) @@ -65,7 +67,7 @@ module Redmine::MenuManager::WikiMenuHelper { controller: '/wiki', action: 'show', id: child.slug }, param: :project_id, caption: child.title, - html: { class: 'wiki-menu--sub-item' }, + html: { class: 'wiki-menu--sub-item' }, parent: main_item.menu_identifier rescue ArgumentError => e Rails.logger.error "Failed to add wiki item #{child.slug} to wiki menu: #{e}. Deleting it." diff --git a/lib/redmine/mime_type.rb b/lib/redmine/mime_type.rb index d3d1a4f3e9..cd99445db8 100644 --- a/lib/redmine/mime_type.rb +++ b/lib/redmine/mime_type.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -80,18 +81,19 @@ module Redmine 'video/x-ms-wmv' => 'wmv', 'video/quicktime' => 'qt,mov', 'video/vnd.vivo' => 'viv,vivo', - 'video/x-msvideo' => 'avi', + 'video/x-msvideo' => 'avi' }.freeze - EXTENSIONS = MIME_TYPES.inject({}) { |map, (type, exts)| - exts.split(',').each do |ext| map[ext.strip] = type end + EXTENSIONS = MIME_TYPES.inject({}) do |map, (type, exts)| + exts.split(',').each { |ext| map[ext.strip] = type } map - } + end # returns mime type for name or nil if unknown def self.of(name) return nil unless name - m = name.to_s.match(/(\A|\.)([^\.]+)\z/) + + m = name.to_s.match(/(\A|\.)([^.]+)\z/) EXTENSIONS[m[2].downcase] if m end @@ -115,7 +117,7 @@ module Redmine end def self.narrow_type(name, content_type) - (content_type.split('/').first == main_mimetype_of(name)) ? of(name) : content_type + content_type.split('/').first == main_mimetype_of(name) ? of(name) : content_type end end end diff --git a/lib/redmine/notifiable.rb b/lib/redmine/notifiable.rb index 9db28afa38..cb2a70c564 100644 --- a/lib/redmine/notifiable.rb +++ b/lib/redmine/notifiable.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,7 @@ #++ module Redmine - class Notifiable < Struct.new(:name, :parent) + Notifiable = Struct.new(:name, :parent) do def to_s name end diff --git a/lib/redmine/platform.rb b/lib/redmine/platform.rb index 0c6ff17a5a..bb8512e684 100644 --- a/lib/redmine/platform.rb +++ b/lib/redmine/platform.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/redmine/plugin.rb b/lib/redmine/plugin.rb index b5cd5884f8..7099266556 100644 --- a/lib/redmine/plugin.rb +++ b/lib/redmine/plugin.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,21 +33,25 @@ require Rails.root.join('config/constants/open_project/activity') module Redmine #:nodoc: class PluginError < StandardError attr_reader :plugin_id + def initialize(plug_id = nil) super @plugin_id = plug_id end end + class PluginNotFound < PluginError def to_s "Missing the plugin #{@plugin_id}" end end + class PluginCircularDependency < PluginError def to_s "Circular plugin dependency in #{@plugin_id}" end end + class PluginRequirementError < PluginError; end # Base class for Redmine plugins. @@ -180,8 +185,8 @@ module Redmine #:nodoc: @id = id.to_sym end - def <=>(plugin) - id.to_s <=> plugin.id.to_s + def <=>(other) + id.to_s <=> other.id.to_s end # Sets a requirement on the OpenProject version. @@ -206,6 +211,7 @@ module Redmine #:nodoc: unless required_version.satisfied_by? op_version raise PluginRequirementError.new("#{id} plugin requires OpenProject version #{required_version} but current version is #{op_version}.") end + true end @@ -266,9 +272,9 @@ module Redmine #:nodoc: # # +hide_if+ parameter can be a lambda accepting a project, the item will only be hidden if # the condition evaluates to true. - def hide_menu_item(menu_name, item, hide_if: -> (*) { true }) + def hide_menu_item(menu_name, item, hide_if: ->(*) { true }) Redmine::MenuManager.map(menu_name) do |menu| - menu.add_condition(item, -> (project) { !hide_if.call(project) }) + menu.add_condition(item, ->(project) { !hide_if.call(project) }) end end @@ -307,7 +313,11 @@ module Redmine #:nodoc: def permission(name, actions, options = {}) if @project_scope mod, mod_options = @project_scope - OpenProject::AccessControl.map { |map| map.project_module(mod, mod_options) { |map| map.permission(name, actions, options) } } + OpenProject::AccessControl.map do |map| + map.project_module(mod, mod_options) do |map| + map.permission(name, actions, options) + end + end else OpenProject::AccessControl.map { |map| map.permission(name, actions, options) } end @@ -388,20 +398,18 @@ module Redmine #:nodoc: target_dir = File.join(destination, dir.gsub(source, '')) begin FileUtils.mkdir_p(target_dir) - rescue => e + rescue StandardError => e raise "Could not create directory #{target_dir}: \n" + e end end source_files.each do |file| - begin - target = File.join(destination, file.gsub(source, '')) - unless File.exist?(target) && FileUtils.identical?(file, target) - FileUtils.cp(file, target) - end - rescue => e - raise "Could not copy #{file} to #{target}: \n" + e + target = File.join(destination, file.gsub(source, '')) + unless File.exist?(target) && FileUtils.identical?(file, target) + FileUtils.cp(file, target) end + rescue StandardError => e + raise "Could not copy #{file} to #{target}: \n" + e end end diff --git a/lib/redmine/pop3.rb b/lib/redmine/pop3.rb index f39dcf790a..6d4d561cf4 100644 --- a/lib/redmine/pop3.rb +++ b/lib/redmine/pop3.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -51,13 +52,11 @@ module Redmine if MailHandler.receive(message, options) msg.delete logger.debug "--> Message #{message_id} processed and deleted from the server" if logger && logger.debug? - else - if delete_unprocessed - msg.delete - logger.debug "--> Message #{message_id} NOT processed and deleted from the server" if logger && logger.debug? - else - logger.debug "--> Message #{message_id} NOT processed and left on the server" if logger && logger.debug? - end + elsif delete_unprocessed + msg.delete + logger.debug "--> Message #{message_id} NOT processed and deleted from the server" if logger && logger.debug? + elsif logger&.debug? + logger.debug "--> Message #{message_id} NOT processed and left on the server" end end end diff --git a/lib/redmine/search.rb b/lib/redmine/search.rb index 5daf617531..fcaedd1ba0 100644 --- a/lib/redmine/search.rb +++ b/lib/redmine/search.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/redmine/views/other_formats_builder.rb b/lib/redmine/views/other_formats_builder.rb index ba4d53651f..f3b8aec747 100644 --- a/lib/redmine/views/other_formats_builder.rb +++ b/lib/redmine/views/other_formats_builder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,6 +37,7 @@ module Redmine def link_to(name, options = {}) return if Setting.table_exists? && !Setting.feeds_enabled? && name == 'Atom' + url = { format: name.to_s.downcase }.merge(options.delete(:url) || {}) caption = options.delete(:caption) || name html_options = { class: "icon icon-#{name.to_s.downcase}", rel: 'nofollow' }.merge(options) diff --git a/lib/tabular_form_builder.rb b/lib/tabular_form_builder.rb index e4f9d40aa3..84b0917a88 100644 --- a/lib/tabular_form_builder.rb +++ b/lib/tabular_form_builder.rb @@ -261,7 +261,7 @@ class TabularFormBuilder < ActionView::Helpers::FormBuilder end end - def label_for_field_for(options, label_options, field) + def label_for_field_for(options, label_options, _field) label_options[:for] = options[:for] end diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index d0e3577685..286e5b0a02 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -46,11 +47,10 @@ namespace :assets do end desc 'Prepare locales and angular assets' - task prepare_op: [:export_locales, :angular] + task prepare_op: %i[export_locales angular] desc 'Compile assets with webpack' task :angular do - # We skip angular compilation if backend was requested # but frontend was not explicitly set if ENV['RECOMPILE_RAILS_ASSETS'] == 'true' && ENV['RECOMPILE_ANGULAR_ASSETS'] != 'true' diff --git a/lib/tasks/attachment_migrations.rake b/lib/tasks/attachment_migrations.rake index 3d0b8fa94c..b35eb5145f 100644 --- a/lib/tasks/attachment_migrations.rake +++ b/lib/tasks/attachment_migrations.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/attachments.rake b/lib/tasks/attachments.rake index d2b8d982af..b00bae0379 100644 --- a/lib/tasks/attachments.rake +++ b/lib/tasks/attachments.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake index 7717cfae63..2044772d19 100644 --- a/lib/tasks/backup.rake +++ b/lib/tasks/backup.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/ciphering.rake b/lib/tasks/ciphering.rake index c17962196c..822a686624 100644 --- a/lib/tasks/ciphering.rake +++ b/lib/tasks/ciphering.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/code.rake b/lib/tasks/code.rake index 01d000fe7f..61762683c7 100644 --- a/lib/tasks/code.rake +++ b/lib/tasks/code.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,10 +33,10 @@ namespace :code do task :fix_line_endings do Dir.chdir(File.join(File.dirname(__FILE__), '../..')) do files = Dir['**/**{.rb,.html.erb,.rhtml,.rjs,.plain.erb,.rxml,.yml,.rake,.eml}'] - files.reject! { |f| + files.reject! do |f| f.include?('lib/plugins') || f.include?('lib/diff') - } + end # handle files in chunks of 50 to avoid too long command lines while (slice = files.slice!(0, 50)).present? @@ -59,13 +60,11 @@ namespace :code do file_content = File.read(file_name) if file_content =~ magic_regex file_content.gsub!(magic_regex, "\\1#{magic_comment}") + elsif file_content.start_with?('#!') + file_content.sub!(/(\n|\r\n)/, "\\1#{magic_comment}\\1") + # We have a shebang. Encoding comment is to put on the second line else - if file_content.start_with?('#!') - # We have a shebang. Encoding comment is to put on the second line - file_content.sub!(/(\n|\r\n)/, "\\1#{magic_comment}\\1") - else - file_content = magic_comment + "\n" + file_content - end + file_content = magic_comment + "\n" + file_content end File.open(file_name, 'w') do |file| diff --git a/lib/tasks/copyright.rake b/lib/tasks/copyright.rake index 2af6672b29..eb13359542 100644 --- a/lib/tasks/copyright.rake +++ b/lib/tasks/copyright.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -52,8 +53,10 @@ namespace :copyright do def copyright_file(options = {}) path = 'docs/COPYRIGHT_short.rdoc' if options[:path] - path = File.join(options[:path], 'docs/COPYRIGHT_short.rdoc') if File.exists?(File.join(options[:path], 'docs/COPYRIGHT_short.rdoc')) - path = File.join(options[:path], 'docs/COPYRIGHT_short.md') if File.exists?(File.join(options[:path], 'docs/COPYRIGHT_short.md')) + path = File.join(options[:path], 'docs/COPYRIGHT_short.rdoc') if File.exists?(File.join(options[:path], + 'docs/COPYRIGHT_short.rdoc')) + path = File.join(options[:path], 'docs/COPYRIGHT_short.md') if File.exists?(File.join(options[:path], + 'docs/COPYRIGHT_short.md')) end path end @@ -65,9 +68,9 @@ namespace :copyright do end def short_copyright_line(sign, options = {}) - short_copyright = File.readlines(copyright_file(options)).collect { |line| + short_copyright = File.readlines(copyright_file(options)).collect do |line| "#{sign} #{line}".rstrip - }.join("\n") + end.join("\n") "#{sign}-- copyright\n#{short_copyright}\n#{sign}++" end @@ -113,6 +116,7 @@ namespace :copyright do excluded = exluded_paths.concat(additional_excludes) raise 'Path not found' unless Dir.exists?(path) + file_list.each do |file_name| # Skip 3rd party code next if excluded.any? { |e| file_name.include?(e) } @@ -133,9 +137,9 @@ namespace :copyright do desc 'Update special files, which do not have an ending' task :update_special_files, :arg1 do |_task, args| # ruby-like files - file_list = %w{Gemfile Rakefile config.ru .travis.yml .gitignore}.map { |f| + file_list = %w{Gemfile Rakefile config.ru .travis.yml .gitignore}.map do |f| File.absolute_path f - } + end rewrite_copyright('rb', [], :rb, args[:arg1], file_list: file_list) end diff --git a/lib/tasks/copyright_authors.rake b/lib/tasks/copyright_authors.rake index 887754962a..4592f6a9e4 100644 --- a/lib/tasks/copyright_authors.rake +++ b/lib/tasks/copyright_authors.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -67,7 +68,7 @@ namespace :copyright do def format_contribution_periods(contribution_periods) contribution_periods.each_with_object({}) do |c, h| - date = (c.begin == c.end) ? c.begin.to_s : "#{c.begin} - #{c.end}" + date = c.begin == c.end ? c.begin.to_s : "#{c.begin} - #{c.end}" h[date] = [] unless h.has_key? date h[date] << c.author end diff --git a/lib/tasks/delayed_job.rake b/lib/tasks/delayed_job.rake index c13d5a6275..43c405fd36 100644 --- a/lib/tasks/delayed_job.rake +++ b/lib/tasks/delayed_job.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -42,4 +43,3 @@ Rake::Task['jobs:environment_options'] load 'lib/tasks/cron.rake' Rake::Task["jobs:work"].enhance [:"openproject:cron:schedule"] Rake::Task["jobs:workoff"].enhance [:"openproject:cron:schedule"] - diff --git a/lib/tasks/delete_documents.rake b/lib/tasks/delete_documents.rake index 792b6d3cd1..8dc97d8499 100644 --- a/lib/tasks/delete_documents.rake +++ b/lib/tasks/delete_documents.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -50,7 +51,7 @@ namespace :migrations do TemporaryDocument.destroy_all Attachment.where(container_type: ['Document']).destroy_all end - rescue + rescue StandardError raise 'Cannot delete documents! There may be migrations missing...?' end diff --git a/lib/tasks/deprecated.rake b/lib/tasks/deprecated.rake index c000eaca19..c830e61808 100644 --- a/lib/tasks/deprecated.rake +++ b/lib/tasks/deprecated.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,13 +30,13 @@ def deprecated_task(name, new_name) task name => new_name do - $stderr.puts "\nNote: The rake task #{name} has been deprecated, please use the replacement version #{new_name}" + warn "\nNote: The rake task #{name} has been deprecated, please use the replacement version #{new_name}" end end def removed_task(name, message) task name do - $stderr.puts "\nError: The rake task #{name} has been removed. #{message}" + warn "\nError: The rake task #{name} has been removed. #{message}" raise end end diff --git a/lib/tasks/email.rake b/lib/tasks/email.rake index 21bb37b4a5..5ed4905908 100644 --- a/lib/tasks/email.rake +++ b/lib/tasks/email.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,113 +30,113 @@ namespace :redmine do namespace :email do - desc <<-END_DESC -Read an email from standard input. - -General options: - unknown_user=ACTION how to handle emails from an unknown user - ACTION can be one of the following values: - ignore: email is ignored (default) - accept: accept as anonymous user - create: create a user account - no_permission_check=1 disable permission checking when receiving - the email - -Issue attributes control options: - project=PROJECT identifier of the target project - status=STATUS name of the target status - type=TYPE name of the target type - category=CATEGORY name of the target category - priority=PRIORITY name of the target priority - allow_override=ATTRS allow email content to override attributes - specified by previous options - ATTRS is a comma separated list of attributes - -If you want to set default values for custom fields, set the value similar to -the attributes above, using the name of the custom field as a key. -Custom ields set this way can only contain characters valid for environment -variables, i.e. no punctuation and no whitespace. -Additionally, you need to set the list of the attributes set this way in the -default_attributes list like this: - - default_attributes="CustomField1 CustomField2" - -Examples: - # No project specified. Emails MUST contain the 'Project' keyword: - rake redmine:email:read RAILS_ENV="production" < raw_email - - # Fixed project and default type specified, but emails can override - # both type and priority attributes: - rake redmine:email:read RAILS_ENV="production" \\ - project=foo \\ - type=bug \\ - allow_override=type,priority < raw_email -END_DESC + desc <<~END_DESC + Read an email from standard input. + #{' '} + General options: + unknown_user=ACTION how to handle emails from an unknown user + ACTION can be one of the following values: + ignore: email is ignored (default) + accept: accept as anonymous user + create: create a user account + no_permission_check=1 disable permission checking when receiving + the email + #{' '} + Issue attributes control options: + project=PROJECT identifier of the target project + status=STATUS name of the target status + type=TYPE name of the target type + category=CATEGORY name of the target category + priority=PRIORITY name of the target priority + allow_override=ATTRS allow email content to override attributes + specified by previous options + ATTRS is a comma separated list of attributes + #{' '} + If you want to set default values for custom fields, set the value similar to + the attributes above, using the name of the custom field as a key. + Custom ields set this way can only contain characters valid for environment + variables, i.e. no punctuation and no whitespace. + Additionally, you need to set the list of the attributes set this way in the + default_attributes list like this: + #{' '} + default_attributes="CustomField1 CustomField2" + #{' '} + Examples: + # No project specified. Emails MUST contain the 'Project' keyword: + rake redmine:email:read RAILS_ENV="production" < raw_email + #{' '} + # Fixed project and default type specified, but emails can override + # both type and priority attributes: + rake redmine:email:read RAILS_ENV="production" \\ + project=foo \\ + type=bug \\ + allow_override=type,priority < raw_email + END_DESC task read: :environment do MailHandler.receive(STDIN.read, options_from_env) end - desc <<-END_DESC -Read emails from an IMAP server. - -General options: - unknown_user=ACTION how to handle emails from an unknown user - ACTION can be one of the following values: - ignore: email is ignored (default) - accept: accept as anonymous user - create: create a user account - no_permission_check=1 disable permission checking when receiving - the email - -Available IMAP options: - host=HOST IMAP server host (default: 127.0.0.1) - port=PORT IMAP server port (default: 143) - ssl=SSL Use SSL? (default: false) - username=USERNAME IMAP account - password=PASSWORD IMAP password - folder=FOLDER IMAP folder to read (default: INBOX) - -Issue attributes control options: - project=PROJECT identifier of the target project - status=STATUS name of the target status - type=TYPE name of the target type - category=CATEGORY name of the target category - priority=PRIORITY name of the target priority - allow_override=ATTRS allow email content to override attributes - specified by previous options - ATTRS is a comma separated list of attributes - -If you want to set default values for custom fields, set the value similar to -the attributes above, using the name of the custom field as a key. -Custom ields set this way can only contain characters valid for environment -variables, i.e. no punctuation and no whitespace. -Additionally, you need to set the list of the attributes set this way in the -default_attributes list like this: - - default_attributes="CustomField1 CustomField2" - -Processed emails control options: - move_on_success=MAILBOX move emails that were successfully received - to MAILBOX instead of deleting them - move_on_failure=MAILBOX move emails that were ignored to MAILBOX - -Examples: - # No project specified. Emails MUST contain the 'Project' keyword: - - rake redmine:email:receive_iamp RAILS_ENV="production" \\ - host=imap.foo.bar username=redmine@example.net password=xxx - - - # Fixed project and default type specified, but emails can override - # both type and priority attributes: - - rake redmine:email:receive_imap RAILS_ENV="production" \\ - host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\ - project=foo \\ - type=bug \\ - allow_override=type,priority -END_DESC + desc <<~END_DESC + Read emails from an IMAP server. + #{' '} + General options: + unknown_user=ACTION how to handle emails from an unknown user + ACTION can be one of the following values: + ignore: email is ignored (default) + accept: accept as anonymous user + create: create a user account + no_permission_check=1 disable permission checking when receiving + the email + #{' '} + Available IMAP options: + host=HOST IMAP server host (default: 127.0.0.1) + port=PORT IMAP server port (default: 143) + ssl=SSL Use SSL? (default: false) + username=USERNAME IMAP account + password=PASSWORD IMAP password + folder=FOLDER IMAP folder to read (default: INBOX) + #{' '} + Issue attributes control options: + project=PROJECT identifier of the target project + status=STATUS name of the target status + type=TYPE name of the target type + category=CATEGORY name of the target category + priority=PRIORITY name of the target priority + allow_override=ATTRS allow email content to override attributes + specified by previous options + ATTRS is a comma separated list of attributes + #{' '} + If you want to set default values for custom fields, set the value similar to + the attributes above, using the name of the custom field as a key. + Custom ields set this way can only contain characters valid for environment + variables, i.e. no punctuation and no whitespace. + Additionally, you need to set the list of the attributes set this way in the + default_attributes list like this: + #{' '} + default_attributes="CustomField1 CustomField2" + #{' '} + Processed emails control options: + move_on_success=MAILBOX move emails that were successfully received + to MAILBOX instead of deleting them + move_on_failure=MAILBOX move emails that were ignored to MAILBOX + #{' '} + Examples: + # No project specified. Emails MUST contain the 'Project' keyword: + #{' '} + rake redmine:email:receive_iamp RAILS_ENV="production" \\ + host=imap.foo.bar username=redmine@example.net password=xxx + #{' '} + #{' '} + # Fixed project and default type specified, but emails can override + # both type and priority attributes: + #{' '} + rake redmine:email:receive_imap RAILS_ENV="production" \\ + host=imap.foo.bar username=redmine@example.net password=xxx ssl=1 \\ + project=foo \\ + type=bug \\ + allow_override=type,priority + END_DESC task receive_imap: :environment do imap_options = { host: ENV['host'], @@ -151,29 +152,29 @@ END_DESC Redmine::IMAP.check(imap_options, options_from_env) end - desc <<-END_DESC -Read emails from an POP3 server. - -Available POP3 options: - host=HOST POP3 server host (default: 127.0.0.1) - port=PORT POP3 server port (default: 110) - username=USERNAME POP3 account - password=PASSWORD POP3 password - apop=1 use APOP authentication (default: false) - delete_unprocessed=1 delete messages that could not be processed - successfully from the server (default - behaviour is to leave them on the server) - -See redmine:email:receive_imap for more options and examples. -END_DESC + desc <<~END_DESC + Read emails from an POP3 server. + #{' '} + Available POP3 options: + host=HOST POP3 server host (default: 127.0.0.1) + port=PORT POP3 server port (default: 110) + username=USERNAME POP3 account + password=PASSWORD POP3 password + apop=1 use APOP authentication (default: false) + delete_unprocessed=1 delete messages that could not be processed + successfully from the server (default + behaviour is to leave them on the server) + #{' '} + See redmine:email:receive_imap for more options and examples. + END_DESC task receive_pop3: :environment do - pop_options = { host: ENV['host'], - port: ENV['port'], - apop: ENV['apop'], - username: ENV['username'], - password: ENV['password'], - delete_unprocessed: ENV['delete_unprocessed'] } + pop_options = { host: ENV['host'], + port: ENV['port'], + apop: ENV['apop'], + username: ENV['username'], + password: ENV['password'], + delete_unprocessed: ENV['delete_unprocessed'] } Redmine::POP3.check(pop_options, options_from_env) end @@ -182,7 +183,8 @@ END_DESC task :test, [:login] => :environment do |_task, args| login = args[:login] if login.blank? - abort I18n.t(:notice_email_error, default: 'Please include the user login to test with. Example: redmine:email:test[example-login]') + abort I18n.t(:notice_email_error, + default: 'Please include the user login to test with. Example: redmine:email:test[example-login]') end user = User.find_by_login(login) @@ -195,7 +197,7 @@ END_DESC begin UserMailer.test_mail(user).deliver_now puts I18n.t(:notice_email_sent, value: user.mail) - rescue => e + rescue StandardError => e abort I18n.t(:notice_email_error, e.message) end end @@ -206,7 +208,7 @@ END_DESC { issue: {} }.tap do |options| default_fields = (ENV['default_fields'] || '').split default_fields |= %w[project status type category priority assigned_to version] - default_fields.each do |field| options[:issue][field.to_sym] = ENV[field] if ENV[field] end + default_fields.each { |field| options[:issue][field.to_sym] = ENV[field] if ENV[field] } options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] diff --git a/lib/tasks/environment.rake b/lib/tasks/environment.rake index ec217f3655..d6156c9b74 100644 --- a/lib/tasks/environment.rake +++ b/lib/tasks/environment.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,7 +31,7 @@ namespace 'environment' do desc 'Force application to eager load if configured (does not happen by default for rake tasks)' task :full do - $stderr.puts "Forcefully loading the application. Use :environment to avoid eager loading." + warn "Forcefully loading the application. Use :environment to avoid eager loading." ## # Require the environment, bypassing the default :environment flag diff --git a/lib/tasks/extract_fixtures.rake b/lib/tasks/extract_fixtures.rake index 4f3939998b..d914b58e84 100644 --- a/lib/tasks/extract_fixtures.rake +++ b/lib/tasks/extract_fixtures.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/fetch_changesets.rake b/lib/tasks/fetch_changesets.rake index b4c92c9697..b2c551be4b 100644 --- a/lib/tasks/fetch_changesets.rake +++ b/lib/tasks/fetch_changesets.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/git.rake b/lib/tasks/git.rake index bc70b969db..7c8c4c6997 100644 --- a/lib/tasks/git.rake +++ b/lib/tasks/git.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,11 +34,11 @@ namespace :git do # FIXME: change this to master once we are there main_branch = 'dev' excluded_branches = [ - main_branch, - 'release/4.0', - 'release/4.1', - 'release/4.2' - ].join('|') + main_branch, + 'release/4.0', + 'release/4.1', + 'release/4.2' + ].join('|') # symbolic-ref gives us sth. like "refs/heads/foo" and we just need 'foo' current_branch = `git symbolic-ref HEAD`.chomp.split('/').last @@ -64,16 +65,16 @@ namespace :git do remote_branches = `git branch -r --merged` .split("\n") .map(&:strip) - .reject{ |b| + .reject do |b| !b.starts_with?('origin') || - excluded_branches.include?(b.split('/').drop(1).join('/')) - } + excluded_branches.include?(b.split('/').drop(1).join('/')) + end local_branches = `git branch --merged` .gsub(/^\* /, '') .split("\n") .map(&:strip) - .reject{ |b| excluded_branches.include?(b) } + .reject { |b| excluded_branches.include?(b) } if remote_branches.empty? && local_branches.empty? puts "No existing branches have been merged into #{current_branch}." diff --git a/lib/tasks/jdbc.rake b/lib/tasks/jdbc.rake index 1559b4558a..843a1a210a 100644 --- a/lib/tasks/jdbc.rake +++ b/lib/tasks/jdbc.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/ldap.rake b/lib/tasks/ldap.rake index 3ffe8e2c57..8e3a0ad980 100644 --- a/lib/tasks/ldap.rake +++ b/lib/tasks/ldap.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,6 @@ #++ namespace :ldap do - def parse_args # Rake croaks when using commas in default args without properly escaping args = {} @@ -54,7 +54,6 @@ namespace :ldap do User.transaction do ldap_con.search(base: ldap.base_dn, filter: filter) do |entry| - user = User.find_or_initialize_by(login: entry[ldap.attr_login]) user.attributes = { firstname: entry[ldap.attr_firstname], @@ -102,7 +101,6 @@ namespace :ldap do entries = ldap_con.search(base: base_dn, filter: object_filter & login_filter, attributes: attributes) - if entries.count == 0 warn "Did not find entry for #{username}" next @@ -123,7 +121,7 @@ namespace :ldap do if user.save puts "#{prefix} user #{user.login} from ldap synchronization" else - puts "Failed to save #{user.login}: #{user.errors.full_messages.join(", ")}." + puts "Failed to save #{user.login}: #{user.errors.full_messages.join(', ')}." end end end @@ -139,7 +137,6 @@ namespace :ldap do raise "Expected #{args[:url]} to be a valid ldap(s) URI." end - source = LdapAuthSource.find_or_initialize_by(name: args[:name]) unless source.new_record? diff --git a/lib/tasks/load_default_data.rake b/lib/tasks/load_default_data.rake index dd0486b344..5e68036f11 100644 --- a/lib/tasks/load_default_data.rake +++ b/lib/tasks/load_default_data.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -45,6 +46,7 @@ namespace :redmine do lang = STDIN.gets.chomp! break if lang.empty? break if set_language_if_valid(lang) + puts 'Unknown language!' end STDOUT.flush @@ -54,11 +56,11 @@ namespace :redmine do begin Redmine::DefaultData::Loader.load(current_language) puts 'Default configuration data loaded.' - rescue Redmine::DefaultData::DataAlreadyLoaded => error - puts error - rescue => error - puts 'Error: ' + error.message - puts error.backtrace.join("\n") + rescue Redmine::DefaultData::DataAlreadyLoaded => e + puts e + rescue StandardError => e + puts 'Error: ' + e.message + puts e.backtrace.join("\n") puts 'Default configuration data was not loaded.' end end diff --git a/lib/tasks/metrics.rake b/lib/tasks/metrics.rake index 72d823a211..28755f84a0 100644 --- a/lib/tasks/metrics.rake +++ b/lib/tasks/metrics.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/packager.rake b/lib/tasks/packager.rake index 2efe079281..313f53851f 100644 --- a/lib/tasks/packager.rake +++ b/lib/tasks/packager.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,6 @@ require 'open3' namespace :packager do - def shell_setup(cmd, raise_on_error: true) out_and_err, status = Open3.capture2e(ENV['APP_NAME'], *cmd) @@ -47,7 +47,6 @@ namespace :packager do # avoids to load the environment multiple times. # Removes older assets task postinstall: [:environment, 'assets:clean', 'setup:scm'] do - # We need to precompile assets when either # 1. packager requested it # 2. user requested frontend compilation with RECOMPILE_ANGULAR_ASSETS diff --git a/lib/tasks/parallel_testing.rake b/lib/tasks/parallel_testing.rake index b35b9c7c21..96b2b36f16 100644 --- a/lib/tasks/parallel_testing.rake +++ b/lib/tasks/parallel_testing.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/permissions.rake b/lib/tasks/permissions.rake index 69bd399213..967c3c3be6 100644 --- a/lib/tasks/permissions.rake +++ b/lib/tasks/permissions.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake index 92dcac2f5e..5386196662 100644 --- a/lib/tasks/plugins.rake +++ b/lib/tasks/plugins.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/random_data.rake b/lib/tasks/random_data.rake index 3b760c2a94..f858b7f322 100644 --- a/lib/tasks/random_data.rake +++ b/lib/tasks/random_data.rake @@ -29,7 +29,6 @@ namespace :random_data do desc 'seeds the data base wth random data' task seed: :environment do - puts '*** Seeding basic data' BasicDataSeeder.seed! diff --git a/lib/tasks/release.rake b/lib/tasks/release.rake index 2bbc562c39..4602e8eb60 100644 --- a/lib/tasks/release.rake +++ b/lib/tasks/release.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/reminder.rake b/lib/tasks/reminder.rake index cb817cb679..7db01f9754 100644 --- a/lib/tasks/reminder.rake +++ b/lib/tasks/reminder.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,22 +28,23 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -desc <<-END_DESC -Send reminders about issues due in the next days. - -Available options: - * days => number of days to remind about (defaults to 7) - * type => id of type (defaults to all type) - * project => id or identifier of project (defaults to all projects) - * users => comma separated list of user ids who should be reminded - -Example: - rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" +desc <<~END_DESC + Send reminders about issues due in the next days. + #{' '} + Available options: + * days => number of days to remind about (defaults to 7) + * type => id of type (defaults to all type) + * project => id or identifier of project (defaults to all projects) + * users => comma separated list of user ids who should be reminded + #{' '} + Example: + rake redmine:send_reminders days=7 users="1,23, 56" RAILS_ENV="production" END_DESC namespace :redmine do task send_reminders: :environment do - reminder = OpenProject::Reminders::DueIssuesReminder.new(days: ENV['days'], project_id: ENV['project'], type_id: ENV['type'], user_ids: ENV['users'].to_s.split(',').map(&:to_i)) + reminder = OpenProject::Reminders::DueIssuesReminder.new(days: ENV['days'], project_id: ENV['project'], + type_id: ENV['type'], user_ids: ENV['users'].to_s.split(',').map(&:to_i)) reminder.remind_users end end diff --git a/lib/tasks/reregister_password_migrations.rake b/lib/tasks/reregister_password_migrations.rake index c16b933099..423c6421a1 100644 --- a/lib/tasks/reregister_password_migrations.rake +++ b/lib/tasks/reregister_password_migrations.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/sample_data.rake b/lib/tasks/sample_data.rake index 55c84e76d1..6f95f9bd3d 100644 --- a/lib/tasks/sample_data.rake +++ b/lib/tasks/sample_data.rake @@ -36,8 +36,7 @@ namespace :sample_data do identifier: "#{Faker::Code.isbn}-#{i}", description: Faker::Lorem.paragraph(5), types: Type.all, - is_public: true - ) + is_public: true) puts "created: #{project.name}" end diff --git a/lib/tasks/scm.rake b/lib/tasks/scm.rake index c9b84c7f4d..86d5021aef 100644 --- a/lib/tasks/scm.rake +++ b/lib/tasks/scm.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -67,7 +68,7 @@ namespace :scm do end unless Dir.exists?(managed) - $stderr.puts "WARNING: Managed repository path set to '#{managed}'," \ + warn "WARNING: Managed repository path set to '#{managed}'," \ " but does not exist for SCM vendor #{vendor}!" next end @@ -75,27 +76,27 @@ namespace :scm do missing = scan_repositories(managed) unless missing.empty? - puts <<-WARNING - --- SCM vendor #{vendor} -- - -Found #{missing.length} repositories in #{managed} -without an associated project. - -#{missing.map { |identifier| "> #{identifier}" }.join("\n")} - -When using managed repositories of the vendor #{vendor}, OpenProject will not create -repositories whose associated project identifier is contained in the list above. - -To resolve these cases, you can either: - -1. Remove the affected repositories if they are only remnants of earlier projects - -2. Move them out of the OpenProject managed directory '#{managed}' - -3. Create an associated project and linking that repository - as existing through the Frontend. - + puts <<~WARNING + #{' '} + -- SCM vendor #{vendor} -- + #{' '} + Found #{missing.length} repositories in #{managed} + without an associated project. + #{' '} + #{missing.map { |identifier| "> #{identifier}" }.join("\n")} + #{' '} + When using managed repositories of the vendor #{vendor}, OpenProject will not create + repositories whose associated project identifier is contained in the list above. + #{' '} + To resolve these cases, you can either: + #{' '} + 1. Remove the affected repositories if they are only remnants of earlier projects + #{' '} + 2. Move them out of the OpenProject managed directory '#{managed}' + #{' '} + 3. Create an associated project and linking that repository + as existing through the Frontend. + #{' '} WARNING end end @@ -103,7 +104,6 @@ To resolve these cases, you can either: desc 'Setup a repository checkout base URL for the given vendor: rake scm:set_checkout_url[git=, subversion=]' task set_checkout_url: :environment do |_t, args| - checkout_data = Setting.repository_checkout_data args.extras.each do |tuple| vendor, base_url = tuple.split('=') @@ -120,8 +120,7 @@ To resolve these cases, you can either: namespace :migrate do desc 'Migrate existing repositories to managed for a given URL prefix' - task managed: :environment do |task, args| - + task managed: :environment do |_task, args| urls = args.extras abort "Requires at least one URL prefix to identify existing repositories" if urls.length < 1 diff --git a/lib/tasks/secret_token.rake b/lib/tasks/secret_token.rake index a39ecc54b9..aae8d97c5e 100644 --- a/lib/tasks/secret_token.rake +++ b/lib/tasks/secret_token.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,9 +34,9 @@ file 'config/secret_token.yml' do path = Rails.root.join('config/secret_token.yml').to_s secret = SecureRandom.hex(64) File.open(path, 'w') do |f| - f.write <<"EOF" -secret_token: '#{secret}' -EOF + f.write <<~"EOF" + secret_token: '#{secret}' + EOF end end diff --git a/lib/tasks/shared/attachment_migration.rb b/lib/tasks/shared/attachment_migration.rb index cbbceaeaba..af3069a11f 100644 --- a/lib/tasks/shared/attachment_migration.rb +++ b/lib/tasks/shared/attachment_migration.rb @@ -129,11 +129,7 @@ module Tasks def attachments_page!(wiki, name:) page = wiki.pages.where(title: name).first - if page - page - else - Migrations::Attachments::CurrentWikiPage.create wiki_id: wiki.id, title: name - end + page || create(wiki_id: wiki.id, title: name) end def try_delete_attachments_from_projects_and_versions @@ -142,13 +138,13 @@ module Tasks Attachment.where(container_type: ['Version', 'Project']).destroy_all end - rescue + rescue StandardError raise 'Cannot delete attachments from projects and versions! There may be migrations missing...?' end def user_agrees_to_delete_versions_and_projects_documents questions = ['CAUTION: This rake task will delete ALL attachments attached to versions or projects!', - "DISCLAIMER: This is the final warning: You're going to lose information!"] + "DISCLAIMER: This is the final warning: You're going to lose information!"] ask_for_confirmation(questions) end diff --git a/lib/tasks/shared/user_feedback.rb b/lib/tasks/shared/user_feedback.rb index 8fb02163bf..e60335f737 100644 --- a/lib/tasks/shared/user_feedback.rb +++ b/lib/tasks/shared/user_feedback.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index 6dcbf6ec0c..1cbc9895de 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -37,24 +38,22 @@ end task('spec:legacy').clear namespace :spec do - begin - require 'rspec/core/rake_task' + require 'rspec/core/rake_task' - desc 'Run the code examples in spec_legacy' - task legacy: %w(legacy:unit legacy:functional legacy:integration) - namespace :legacy do - %w(unit functional integration).each do |type| - desc "Run the code examples in spec_legacy/#{type}" - RSpec::Core::RakeTask.new(type => 'spec:prepare') do |t| - t.pattern = "spec_legacy/#{type}/**/*_spec.rb" - t.rspec_opts = '-I spec_legacy' - end + desc 'Run the code examples in spec_legacy' + task legacy: %w(legacy:unit legacy:functional legacy:integration) + namespace :legacy do + %w(unit functional integration).each do |type| + desc "Run the code examples in spec_legacy/#{type}" + RSpec::Core::RakeTask.new(type => 'spec:prepare') do |t| + t.pattern = "spec_legacy/#{type}/**/*_spec.rb" + t.rspec_opts = '-I spec_legacy' end end - rescue LoadError - # when you bundle without development and test (e.g. to create a deployment - # artefact) still all tasks get loaded. To avoid an error we rescue here. end +rescue LoadError + # when you bundle without development and test (e.g. to create a deployment + # artefact) still all tasks get loaded. To avoid an error we rescue here. end %w(spec).each do |type| diff --git a/lib/tasks/time_entry_activities.rake b/lib/tasks/time_entry_activities.rake index 243cd8bfdd..658729c3ef 100644 --- a/lib/tasks/time_entry_activities.rake +++ b/lib/tasks/time_entry_activities.rake @@ -66,24 +66,24 @@ namespace 'openproject' do SQL entries = begin - connection = ActiveRecord::Base - .establish_connection(ENV['BACKUP_DATABASE_URL']) - .connection - - if connection.select_all(check_statement).any? - connection.select_all(select_statement) - end - rescue PG::ConnectionBad, ActiveRecord::NoDatabaseError, LoadError => e - puts <<~MSG - - The 'BACKUP_DATABASE_URL' environment variable is incorrect. The script cannot connect to the backup database: - #{e.message} - - MSG - next - ensure - connection&.close - end + connection = ActiveRecord::Base + .establish_connection(ENV['BACKUP_DATABASE_URL']) + .connection + + if connection.select_all(check_statement).any? + connection.select_all(select_statement) + end + rescue PG::ConnectionBad, ActiveRecord::NoDatabaseError, LoadError => e + puts <<~MSG + + The 'BACKUP_DATABASE_URL' environment variable is incorrect. The script cannot connect to the backup database: + #{e.message} + + MSG + next + ensure + connection&.close + end if entries.nil? || entries.empty? puts <<~MSG diff --git a/lib/tasks/version.rake b/lib/tasks/version.rake index e7f2a5f441..d560fb7d39 100644 --- a/lib/tasks/version.rake +++ b/lib/tasks/version.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/watchers.rake b/lib/tasks/watchers.rake index 3589a2498c..673fde1efb 100644 --- a/lib/tasks/watchers.rake +++ b/lib/tasks/watchers.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/lib/tasks/yardoc.rake b/lib/tasks/yardoc.rake index 77d976635d..44055eb924 100644 --- a/lib/tasks/yardoc.rake +++ b/lib/tasks/yardoc.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -44,7 +45,6 @@ begin t.options += ['--output-dir', './doc/app', '--files', static_files] end - rescue LoadError # yard not installed (gem install yard) # http://yardoc.org diff --git a/modules/auth_plugins/lib/omni_auth/flexible_builder.rb b/modules/auth_plugins/lib/omni_auth/flexible_builder.rb index 4a8fa12baf..4a04366b82 100644 --- a/modules/auth_plugins/lib/omni_auth/flexible_builder.rb +++ b/modules/auth_plugins/lib/omni_auth/flexible_builder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/lib/omni_auth/flexible_strategy.rb b/modules/auth_plugins/lib/omni_auth/flexible_strategy.rb index b6e9187ab4..306c5f6b73 100644 --- a/modules/auth_plugins/lib/omni_auth/flexible_strategy.rb +++ b/modules/auth_plugins/lib/omni_auth/flexible_strategy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/lib/open_project/auth_plugins.rb b/modules/auth_plugins/lib/open_project/auth_plugins.rb index 6205744a6a..15a088944f 100644 --- a/modules/auth_plugins/lib/open_project/auth_plugins.rb +++ b/modules/auth_plugins/lib/open_project/auth_plugins.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/lib/open_project/auth_plugins/engine.rb b/modules/auth_plugins/lib/open_project/auth_plugins/engine.rb index 26ccce9d75..6547b40268 100644 --- a/modules/auth_plugins/lib/open_project/auth_plugins/engine.rb +++ b/modules/auth_plugins/lib/open_project/auth_plugins/engine.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb b/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb index 6b1af6e0e6..601abd8245 100644 --- a/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb +++ b/modules/auth_plugins/lib/open_project/auth_plugins/hooks.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb b/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb index f6b2515f57..b7f0f48952 100644 --- a/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb +++ b/modules/auth_plugins/lib/open_project/plugins/auth_plugin.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/lib/openproject-auth_plugins.rb b/modules/auth_plugins/lib/openproject-auth_plugins.rb index ed5f8690bd..d325271980 100644 --- a/modules/auth_plugins/lib/openproject-auth_plugins.rb +++ b/modules/auth_plugins/lib/openproject-auth_plugins.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/auth_plugins/spec/requests/auth_plugins.rb b/modules/auth_plugins/spec/requests/auth_plugins.rb index c3b95ee003..3b7f46f3a0 100644 --- a/modules/auth_plugins/spec/requests/auth_plugins.rb +++ b/modules/auth_plugins/spec/requests/auth_plugins.rb @@ -30,7 +30,6 @@ require 'spec_helper' require 'open_project/auth_plugins' describe OpenProject::Plugins::AuthPlugin do - class MockEngine extend OpenProject::Plugins::AuthPlugin end @@ -86,12 +85,12 @@ describe OpenProject::Plugins::AuthPlugin do end it 'should register all strategies' do - expect(strategies.keys.to_a).to eq [:strategy_a, :strategy_b] + expect(strategies.keys.to_a).to eq %i[strategy_a strategy_b] end it 'should register register each strategy (i.e. middleware) only once' do expect(middlewares.size).to eq 2 - expect(middlewares).to eq [:strategy_a, :strategy_b] + expect(middlewares).to eq %i[strategy_a strategy_b] end it 'should associate the correct providers with their respective strategies' do diff --git a/modules/auth_plugins/spec/requests/flexible_strategy_spec.rb b/modules/auth_plugins/spec/requests/flexible_strategy_spec.rb index d3dc166dab..5adfb5c49b 100644 --- a/modules/auth_plugins/spec/requests/flexible_strategy_spec.rb +++ b/modules/auth_plugins/spec/requests/flexible_strategy_spec.rb @@ -80,7 +80,7 @@ describe OmniAuth::FlexibleStrategy do it 'should match the registered providers' do [provider_a, provider_b].each do |pro| - code, _ = middleware.call env_for("http://www.example.com/auth/#{pro[:name]}/callback") + code, = middleware.call env_for("http://www.example.com/auth/#{pro[:name]}/callback") expect(code).to eq 'hit' end diff --git a/modules/auth_plugins/spec/views/base.html.erb_spec.rb b/modules/auth_plugins/spec/views/base.html.erb_spec.rb index 2a037d753c..2746557f46 100644 --- a/modules/auth_plugins/spec/views/base.html.erb_spec.rb +++ b/modules/auth_plugins/spec/views/base.html.erb_spec.rb @@ -56,4 +56,3 @@ describe 'layouts/base', type: :view do end end end - diff --git a/modules/auth_plugins/spec/views/hooks/login/_providers.html.erb_spec.rb b/modules/auth_plugins/spec/views/hooks/login/_providers.html.erb_spec.rb index bd9e87e713..ad6cd0af19 100644 --- a/modules/auth_plugins/spec/views/hooks/login/_providers.html.erb_spec.rb +++ b/modules/auth_plugins/spec/views/hooks/login/_providers.html.erb_spec.rb @@ -37,7 +37,6 @@ describe 'rendering the login buttons for all providers' do ] end - before do allow(OpenProject::Plugins::AuthPlugin).to receive(:providers).and_return(providers) diff --git a/modules/auth_saml/lib/open_project/auth_saml/engine.rb b/modules/auth_saml/lib/open_project/auth_saml/engine.rb index c7a2d4b1ba..bc865e8476 100644 --- a/modules/auth_saml/lib/open_project/auth_saml/engine.rb +++ b/modules/auth_saml/lib/open_project/auth_saml/engine.rb @@ -16,7 +16,7 @@ module OpenProject ## # Loads the settings once to avoid accessing the file in each request def self.load_global_settings! - Hash(settings_from_config || settings_from_yaml).with_indifferent_access + Hash(settings_from_config || settings_from_yaml).with_indifferent_access end def self.settings_from_db @@ -50,7 +50,7 @@ module OpenProject register 'openproject-auth_saml', author_url: 'https://github.com/finnlabs/openproject-auth_saml', bundled: true, - settings: { default: { "providers" => nil }} + settings: { default: { "providers" => nil } } assets %w( auth_saml/** diff --git a/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb b/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb index 3f940646c6..b0c18c92cf 100644 --- a/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb +++ b/modules/auth_saml/spec/lib/open_project/auth_saml_spec.rb @@ -19,7 +19,6 @@ describe OpenProject::AuthSaml do OpenProject::AuthSaml.configuration end - context( "with configuration", with_config: { diff --git a/modules/avatars/lib/api/v3/users/user_avatar_api.rb b/modules/avatars/lib/api/v3/users/user_avatar_api.rb index 9a0c3bbcb3..c7e1c67c10 100644 --- a/modules/avatars/lib/api/v3/users/user_avatar_api.rb +++ b/modules/avatars/lib/api/v3/users/user_avatar_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/avatars/lib/open_project/avatars/engine.rb b/modules/avatars/lib/open_project/avatars/engine.rb index 1c0dc40b7c..09208f461c 100644 --- a/modules/avatars/lib/open_project/avatars/engine.rb +++ b/modules/avatars/lib/open_project/avatars/engine.rb @@ -33,7 +33,6 @@ module OpenProject::Avatars menu_item: :user_avatars }, bundled: true do - add_menu_item :my_menu, :avatar, { controller: '/avatars/my_avatar', action: 'show' }, caption: ->(*) { I18n.t('avatars.label_avatar') }, diff --git a/modules/avatars/lib/open_project/avatars/patches/avatar_helper_patch.rb b/modules/avatars/lib/open_project/avatars/patches/avatar_helper_patch.rb index 6278b49b28..dc9f7f28b9 100644 --- a/modules/avatars/lib/open_project/avatars/patches/avatar_helper_patch.rb +++ b/modules/avatars/lib/open_project/avatars/patches/avatar_helper_patch.rb @@ -29,6 +29,7 @@ AvatarHelper.class_eval do # Override gems's method in order to avoid deprecated URI.escape GravatarImageTag.define_singleton_method(:url_params) do |gravatar_params| return nil if gravatar_params.keys.size == 0 + array = gravatar_params.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" } "?#{array.join('&')}" end diff --git a/modules/avatars/lib/open_project/avatars/patches/user_patch.rb b/modules/avatars/lib/open_project/avatars/patches/user_patch.rb index 33661ca01c..f675d5874c 100644 --- a/modules/avatars/lib/open_project/avatars/patches/user_patch.rb +++ b/modules/avatars/lib/open_project/avatars/patches/user_patch.rb @@ -48,10 +48,10 @@ module OpenProject::Avatars return @local_avatar_attachment if @local_avatar_attachment_calculated @local_avatar_attachment_calculated ||= begin - @local_avatar_attachment = attachments.find_by_description('avatar') + @local_avatar_attachment = attachments.find_by_description('avatar') - true - end + true + end @local_avatar_attachment end diff --git a/modules/avatars/openproject-avatars.gemspec b/modules/avatars/openproject-avatars.gemspec index 885ee6c68f..052598f174 100644 --- a/modules/avatars/openproject-avatars.gemspec +++ b/modules/avatars/openproject-avatars.gemspec @@ -14,6 +14,6 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*"] + %w(README.md) s.test_files = Dir["spec/**/*"] - s.add_dependency 'gravatar_image_tag', '~> 1.2.0' s.add_dependency 'fastimage', '~> 2.2.0' + s.add_dependency 'gravatar_image_tag', '~> 1.2.0' end diff --git a/modules/avatars/spec/factories/avatar_attachment_factory.rb b/modules/avatars/spec/factories/avatar_attachment_factory.rb index 8a56cccfa5..0606a53bdf 100644 --- a/modules/avatars/spec/factories/avatar_attachment_factory.rb +++ b/modules/avatars/spec/factories/avatar_attachment_factory.rb @@ -6,7 +6,7 @@ FactoryBot.define do filename { "avatar.jpg" } content_type { "image/jpeg" } file do - File.open(File.expand_path('../../fixtures/valid.jpg', __FILE__)) + File.open(File.expand_path('../fixtures/valid.jpg', __dir__)) end end end diff --git a/modules/avatars/spec/helpers/avatar_helper_spec.rb b/modules/avatars/spec/helpers/avatar_helper_spec.rb index a250d299a1..f3907ced0c 100644 --- a/modules/avatars/spec/helpers/avatar_helper_spec.rb +++ b/modules/avatars/spec/helpers/avatar_helper_spec.rb @@ -42,7 +42,7 @@ describe AvatarHelper, type: :helper, with_settings: { protocol: 'http' } do content_tag 'user-avatar', '', tag_options end - def gravatar_expected_user_avatar_tag(digest, options = {}) + def gravatar_expected_user_avatar_tag(_digest, _options = {}) tag_options = { 'data-user-id': user.id, 'data-user-name': user.name, 'data-class-list': 'avatar avatar--gravatar-image avatar--fallback' } diff --git a/modules/avatars/spec/shared_examples.rb b/modules/avatars/spec/shared_examples.rb index 8c81f64f9b..1513066c0f 100644 --- a/modules/avatars/spec/shared_examples.rb +++ b/modules/avatars/spec/shared_examples.rb @@ -89,9 +89,8 @@ shared_examples_for "an action requiring admin" do end end end -# shared_context "there are users with and without avatars" do - let(:base_path) { File.expand_path '../fixtures/', __FILE__ } + let(:base_path) { File.expand_path 'fixtures', __dir__ } let(:user_without_avatar) { FactoryBot.create :user } let(:user_with_avatar) do u = FactoryBot.create :user @@ -118,7 +117,6 @@ shared_context "there are users with and without avatars" do testfile end end -# shared_examples_for "an action with an invalid user" do it do do_action @@ -133,7 +131,6 @@ shared_examples_for "an action with stubbed User.find" do allow(User).to receive(:find) { |id, _args| id.to_s == "0" ? nil : user } end end -# shared_examples_for "an action that deletes the user's avatar" do it do expect_any_instance_of(Attachment).to receive(:destroy).and_call_original diff --git a/modules/backlogs/app/controllers/backlogs_settings_controller.rb b/modules/backlogs/app/controllers/backlogs_settings_controller.rb index 7d2a189edf..3fc9854c9b 100644 --- a/modules/backlogs/app/controllers/backlogs_settings_controller.rb +++ b/modules/backlogs/app/controllers/backlogs_settings_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/backlogs/app/controllers/rb_export_card_configurations_controller.rb b/modules/backlogs/app/controllers/rb_export_card_configurations_controller.rb index a5aa975b2e..2d258add70 100644 --- a/modules/backlogs/app/controllers/rb_export_card_configurations_controller.rb +++ b/modules/backlogs/app/controllers/rb_export_card_configurations_controller.rb @@ -42,12 +42,12 @@ class RbExportCardConfigurationsController < RbApplicationController filename = "#{@project}-#{@sprint}-#{Time.now.strftime('%B-%d-%Y')}.pdf" respond_to do |format| - format.pdf { + format.pdf do send_data(cards_document.render, disposition: 'attachment', type: 'application/pdf', filename: filename) - } + end end end diff --git a/modules/backlogs/app/controllers/rb_impediments_controller.rb b/modules/backlogs/app/controllers/rb_impediments_controller.rb index 74873822ba..c04414207d 100644 --- a/modules/backlogs/app/controllers/rb_impediments_controller.rb +++ b/modules/backlogs/app/controllers/rb_impediments_controller.rb @@ -71,7 +71,10 @@ class RbImpedimentsController < RbApplicationController # We block block_ids only when user is not allowed to create or update the # instance passed. - unless instance && ((instance.new_record? && User.current.allowed_to?(:add_work_packages, @project)) || User.current.allowed_to?(:edit_work_packages, @project)) + unless instance && ((instance.new_record? && User.current.allowed_to?(:add_work_packages, + @project)) || User.current.allowed_to?( + :edit_work_packages, @project + )) hash.delete(:block_ids) end diff --git a/modules/backlogs/app/controllers/rb_sprints_controller.rb b/modules/backlogs/app/controllers/rb_sprints_controller.rb index bcf633512e..3204e5e9cb 100644 --- a/modules/backlogs/app/controllers/rb_sprints_controller.rb +++ b/modules/backlogs/app/controllers/rb_sprints_controller.rb @@ -33,8 +33,8 @@ class RbSprintsController < RbApplicationController def update result = @sprint.update(params.permit(:name, - :start_date, - :effective_date)) + :start_date, + :effective_date)) status = (result ? 200 : 400) respond_to do |format| diff --git a/modules/backlogs/app/controllers/rb_stories_controller.rb b/modules/backlogs/app/controllers/rb_stories_controller.rb index 8290b406b5..a76649946a 100644 --- a/modules/backlogs/app/controllers/rb_stories_controller.rb +++ b/modules/backlogs/app/controllers/rb_stories_controller.rb @@ -32,9 +32,9 @@ class RbStoriesController < RbApplicationController # This is a constant here because we will recruit it elsewhere to whitelist # attributes. This is necessary for now as we still directly use `attributes=` # in non-controller code. - PERMITTED_PARAMS = [:id, :status_id, :version_id, - :story_points, :type_id, :subject, :author_id, - :sprint_id] + PERMITTED_PARAMS = %i[id status_id version_id + story_points type_id subject author_id + sprint_id] def create call = Stories::CreateService diff --git a/modules/backlogs/app/controllers/work_package_boxes_controller.rb b/modules/backlogs/app/controllers/work_package_boxes_controller.rb index b1859b2ce2..0e929361df 100644 --- a/modules/backlogs/app/controllers/work_package_boxes_controller.rb +++ b/modules/backlogs/app/controllers/work_package_boxes_controller.rb @@ -35,7 +35,9 @@ class WorkPackageBoxesController < WorkPackagesController load_journals @changesets = @work_package.changesets.visible.all @changesets.reverse! if User.current.wants_comments_in_reverse_order? - @relations = @work_package.relations.select { |r| r.other_work_package(@work_package) && r.other_work_package(@work_package).visible? } + @relations = @work_package.relations.select do |r| + r.other_work_package(@work_package) && r.other_work_package(@work_package).visible? + end @allowed_statuses = WorkPackages::UpdateContract.new(work_package, User.current).assignable_statuses @edit_allowed = User.current.allowed_to?(:edit_work_packages, @project) @priorities = IssuePriority.all diff --git a/modules/backlogs/app/helpers/burndown_charts_helper.rb b/modules/backlogs/app/helpers/burndown_charts_helper.rb index d469856ffe..641e943260 100644 --- a/modules/backlogs/app/helpers/burndown_charts_helper.rb +++ b/modules/backlogs/app/helpers/burndown_charts_helper.rb @@ -36,7 +36,7 @@ module BurndownChartsHelper mvalue = mvalue + 1 if mvalue == 1 || ((max % 25) == 0) - labels << "[#{(mvalue) * 25}, '#{I18n.t('backlogs.points')}']" + labels << "[#{mvalue * 25}, '#{I18n.t('backlogs.points')}']" result = labels.join(', ') @@ -48,12 +48,12 @@ module BurndownChartsHelper # Thus it is enough space between the entries. entries_displayed = (burndown.days.length / 14.0).ceil result = burndown.days.enum_for(:each_with_index).map do |d, i| - if ((i % entries_displayed) == 0) + if (i % entries_displayed) == 0 "[#{i + 1}, '#{escape_javascript(::I18n.t('date.abbr_day_names')[d.wday % 7])} #{d.strftime('%d/%m')}']" end end.join(',').html_safe + - ", [#{burndown.days.length + 1}, - '#{I18n.t('backlogs.date')}']".html_safe + ", [#{burndown.days.length + 1}, + '#{I18n.t('backlogs.date')}']".html_safe end def dataseries(burndown) diff --git a/modules/backlogs/app/helpers/rb_common_helper.rb b/modules/backlogs/app/helpers/rb_common_helper.rb index 1b95f768d4..f55769cd1e 100644 --- a/modules/backlogs/app/helpers/rb_common_helper.rb +++ b/modules/backlogs/app/helpers/rb_common_helper.rb @@ -164,6 +164,7 @@ module RbCommonHelper def date_string_with_milliseconds(d, add = 0) return '' if d.blank? + d.strftime('%B %d, %Y %H:%M:%S') + '.' + (d.to_f % 1 + add).to_s.split('.')[1] end @@ -228,7 +229,7 @@ module RbCommonHelper end def all_workflows - @all_workflows ||= Workflow.includes([:new_status, :old_status]) + @all_workflows ||= Workflow.includes(%i[new_status old_status]) .where(role_id: User.current.roles_for_project(@project).map(&:id), type_id: story_types.map(&:id)) end diff --git a/modules/backlogs/app/helpers/rb_master_backlogs_helper.rb b/modules/backlogs/app/helpers/rb_master_backlogs_helper.rb index 02014f5298..241f751ff8 100644 --- a/modules/backlogs/app/helpers/rb_master_backlogs_helper.rb +++ b/modules/backlogs/app/helpers/rb_master_backlogs_helper.rb @@ -35,9 +35,9 @@ module RbMasterBacklogsHelper [ content_tag(:div, '', class: "menu-trigger icon-context icon-pulldown icon-small"), content_tag(:ul, class: 'items') do - backlog_menu_items_for(backlog).map { |item| + backlog_menu_items_for(backlog).map do |item| content_tag(:li, item, class: 'item') - }.join.html_safe + end.join.html_safe end ].join.html_safe end @@ -51,7 +51,7 @@ module RbMasterBacklogsHelper end menu = [] - [:new_story, :stories_tasks, :task_board, :burndown, :cards, :wiki, :configs, :properties].each do |key| + %i[new_story stories_tasks task_board burndown cards wiki configs properties].each do |key| menu << items[key] if items.keys.include?(key) end @@ -108,7 +108,7 @@ module RbMasterBacklogsHelper def export_modal_link(backlog, options = {}) path = backlogs_project_sprint_export_card_configurations_path(@project.id, backlog.sprint.id) html_id = "modal_work_package_#{SecureRandom.hex(10)}" - link_to(I18n.t(:label_backlogs_export_card_export), path, options.merge(id: html_id, :'data-modal' => '')) + link_to(I18n.t(:label_backlogs_export_card_export), path, options.merge(id: html_id, 'data-modal': '')) end def sprint_backlog_menu_items_for(backlog) @@ -121,7 +121,6 @@ module RbMasterBacklogsHelper sprint_id: backlog.sprint }, class: 'show_task_board') - if backlog.sprint.has_burndown? items[:burndown] = content_tag(:a, I18n.t('backlogs.show_burndown_chart'), diff --git a/modules/backlogs/app/helpers/taskboards_helper.rb b/modules/backlogs/app/helpers/taskboards_helper.rb index 4fc96baf2f..5d0025dd55 100644 --- a/modules/backlogs/app/helpers/taskboards_helper.rb +++ b/modules/backlogs/app/helpers/taskboards_helper.rb @@ -31,6 +31,6 @@ module TaskboardsHelper @impediments_by_position_for_status ||= sprint.impediments(project).group_by(&:status_id) (@impediments_by_position_for_status[status.id] || []) - .sort_by { |i| i.position.present? ? i.position : 0 } + .sort_by { |i| i.position.present? ? i.position : 0 } end end diff --git a/modules/backlogs/app/helpers/version_settings_helper.rb b/modules/backlogs/app/helpers/version_settings_helper.rb index 17a37c16c6..bebd629826 100644 --- a/modules/backlogs/app/helpers/version_settings_helper.rb +++ b/modules/backlogs/app/helpers/version_settings_helper.rb @@ -34,7 +34,8 @@ module VersionSettingsHelper [ styled_label_tag(name_for_setting_attributes('display'), t(:label_column_in_backlog)), content_tag(:div, - styled_select_tag(name_for_setting_attributes('display'), options_for_select(position_display_options, setting.display), container_class: '-xslim' ), + styled_select_tag(name_for_setting_attributes('display'), + options_for_select(position_display_options, setting.display), container_class: '-xslim'), class: 'form--field-container'), version_hidden_id_field(setting), hidden_field_tag('project_id', project.id) diff --git a/modules/backlogs/app/models/backlog.rb b/modules/backlogs/app/models/backlog.rb index 0180bd9f41..771e3ea721 100644 --- a/modules/backlogs/app/models/backlog.rb +++ b/modules/backlogs/app/models/backlog.rb @@ -27,8 +27,7 @@ #++ class Backlog - attr_accessor :sprint - attr_accessor :stories + attr_accessor :sprint, :stories def self.owner_backlogs(project, options = {}) options.reverse_merge!(limit: nil) diff --git a/modules/backlogs/app/models/burndown.rb b/modules/backlogs/app/models/burndown.rb index 9437e51f1e..9a3d748d3f 100644 --- a/modules/backlogs/app/models/burndown.rb +++ b/modules/backlogs/app/models/burndown.rb @@ -27,7 +27,7 @@ #++ class Burndown - def initialize(sprint, project, burn_direction = nil) + def initialize(sprint, project, _burn_direction = nil) @sprint_id = sprint.id make_date_series sprint @@ -43,12 +43,7 @@ class Burndown determine_max end - attr_reader :days - attr_reader :sprint_id - attr_reader :max - - attr_reader :story_points - attr_reader :story_points_ideal + attr_reader :days, :sprint_id, :max, :story_points, :story_points_ideal def series(_select = :active) @available_series diff --git a/modules/backlogs/app/models/impediment.rb b/modules/backlogs/app/models/impediment.rb index 175c1ca079..756cfe812a 100644 --- a/modules/backlogs/app/models/impediment.rb +++ b/modules/backlogs/app/models/impediment.rb @@ -59,7 +59,10 @@ class Impediment < Task errors.add :blocks_ids, :must_block_at_least_one_work_package else other_version_ids = WorkPackage.where(id: blocks_ids).pluck(:version_id).uniq - errors.add :blocks_ids, :can_only_contain_work_packages_of_current_sprint if other_version_ids.size != 1 || other_version_ids[0] != version_id + if other_version_ids.size != 1 || other_version_ids[0] != version_id + errors.add :blocks_ids, + :can_only_contain_work_packages_of_current_sprint + end end end end diff --git a/modules/backlogs/app/models/sprint.rb b/modules/backlogs/app/models/sprint.rb index 2f1095c648..906d102965 100644 --- a/modules/backlogs/app/models/sprint.rb +++ b/modules/backlogs/app/models/sprint.rb @@ -53,17 +53,17 @@ class Sprint < Version scope :displayed_left, lambda { |project| joins(sanitize_sql_array([ - "LEFT OUTER JOIN (SELECT * from #{VersionSetting.table_name}" + - ' WHERE project_id = ? ) version_settings' + - ' ON version_settings.version_id = versions.id', - project.id]) - ) + "LEFT OUTER JOIN (SELECT * from #{VersionSetting.table_name}" + + ' WHERE project_id = ? ) version_settings' + + ' ON version_settings.version_id = versions.id', + project.id + ])) .where([ - '(version_settings.project_id = ? AND version_settings.display = ?)' + - ' OR (version_settings.project_id is NULL)', - project.id, - VersionSetting::DISPLAY_LEFT - ]) + '(version_settings.project_id = ? AND version_settings.display = ?)' + + ' OR (version_settings.project_id is NULL)', + project.id, + VersionSetting::DISPLAY_LEFT + ]) .joins(" LEFT OUTER JOIN (SELECT * FROM #{VersionSetting.table_name}) AS vs ON vs.version_id = #{Version.table_name}.id AND vs.project_id = #{Version.table_name}.project_id @@ -143,17 +143,17 @@ class Sprint < Version end def burndown(project, burn_direction = nil) - return nil unless self.has_burndown? + return nil unless has_burndown? @cached_burndown ||= Burndown.new(self, project, burn_direction) end def self.generate_burndown(only_current = true) - if only_current - conditions = ['? BETWEEN start_date AND effective_date', Date.today] - else - conditions = '1 = 1' - end + conditions = if only_current + ['? BETWEEN start_date AND effective_date', Date.today] + else + '1 = 1' + end Version.where(conditions).each(&:burndown) end diff --git a/modules/backlogs/app/models/story.rb b/modules/backlogs/app/models/story.rb index 0d577b085c..b2a81ca73f 100644 --- a/modules/backlogs/app/models/story.rb +++ b/modules/backlogs/app/models/story.rb @@ -40,9 +40,11 @@ class Story < WorkPackage end candidates.each do |story| - last_rank = stories_by_version[story.version_id].size > 0 ? - stories_by_version[story.version_id].last.rank : - 0 + last_rank = if stories_by_version[story.version_id].size > 0 + stories_by_version[story.version_id].last.rank + else + 0 + end story.rank = last_rank + 1 stories_by_version[story.version_id] << story @@ -59,7 +61,7 @@ class Story < WorkPackage Story.where(Story.condition(project_id, sprint_id)) .joins(:status) .order(Arel.sql(Story::ORDER)) - .offset(rank -1) + .offset(rank - 1) .first end @@ -76,11 +78,13 @@ class Story < WorkPackage def tasks_and_subtasks return [] unless Task.type + descendants.where(type_id: Task.type) end def direct_tasks_and_subtasks return [] unless Task.type + children.where(type_id: Task.type).map { |t| [t] + t.descendants }.flatten end @@ -100,7 +104,7 @@ class Story < WorkPackage p = Integer(p) if p >= 0 update_attribute(:story_points, p) - return + nil end end @@ -130,7 +134,9 @@ class Story < WorkPackage def rank if position.blank? - extras = ["and ((#{WorkPackage.table_name}.position is NULL and #{WorkPackage.table_name}.id <= ?) or not #{WorkPackage.table_name}.position is NULL)", id] + extras = [ + "and ((#{WorkPackage.table_name}.position is NULL and #{WorkPackage.table_name}.id <= ?) or not #{WorkPackage.table_name}.position is NULL)", id + ] else extras = ["and not #{WorkPackage.table_name}.position is NULL and #{WorkPackage.table_name}.position <= ?", position] end @@ -141,8 +147,6 @@ class Story < WorkPackage @rank end - private - def self.condition(project_id, sprint_ids, extras = []) c = ['project_id = ? AND type_id in (?) AND version_id in (?)', project_id, Story.types, sprint_ids] diff --git a/modules/backlogs/app/seeders/basic_data/backlogs/setting_seeder.rb b/modules/backlogs/app/seeders/basic_data/backlogs/setting_seeder.rb index b77772be2a..eefe7f2b83 100644 --- a/modules/backlogs/app/seeders/basic_data/backlogs/setting_seeder.rb +++ b/modules/backlogs/app/seeders/basic_data/backlogs/setting_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -68,7 +69,7 @@ module BasicData end def backlogs_type_names - [:default_type_feature, :default_type_epic, :default_type_user_story, :default_type_bug] + %i[default_type_feature default_type_epic default_type_user_story default_type_bug] .map { |code| I18n.t(code) } end diff --git a/modules/backlogs/app/seeders/basic_data/backlogs/type_seeder.rb b/modules/backlogs/app/seeders/basic_data/backlogs/type_seeder.rb index 23009f1258..648988d0bd 100644 --- a/modules/backlogs/app/seeders/basic_data/backlogs/type_seeder.rb +++ b/modules/backlogs/app/seeders/basic_data/backlogs/type_seeder.rb @@ -12,7 +12,7 @@ module BasicData # hidden, default, visible def backlogs_visibility_table { - story_points: [0, 0, 0, 1, 2, 2, 1], + story_points: [0, 0, 0, 1, 2, 2, 1], remaining_time: [1, 0, 0, 1, 1, 1, 1] } end diff --git a/modules/backlogs/config/routes.rb b/modules/backlogs/config/routes.rb index 9dae832139..a4e0e7140a 100644 --- a/modules/backlogs/config/routes.rb +++ b/modules/backlogs/config/routes.rb @@ -31,24 +31,24 @@ OpenProject::Application.routes.draw do scope 'projects/:project_id', as: 'project' do resources :backlogs, controller: :rb_master_backlogs, only: :index - resources :sprints, controller: :rb_sprints, only: [:show, :update] do + resources :sprints, controller: :rb_sprints, only: %i[show update] do resource :query, controller: :rb_queries, only: :show resource :taskboard, controller: :rb_taskboards, only: :show - resource :wiki, controller: :rb_wikis, only: [:show, :edit] + resource :wiki, controller: :rb_wikis, only: %i[show edit] resource :burndown_chart, controller: :rb_burndown_charts, only: :show - resources :impediments, controller: :rb_impediments, only: [:create, :update] + resources :impediments, controller: :rb_impediments, only: %i[create update] - resources :tasks, controller: :rb_tasks, only: [:create, :update] + resources :tasks, controller: :rb_tasks, only: %i[create update] - resources :export_card_configurations, controller: :rb_export_card_configurations, only: [:index, :show] do - resources :stories, controller: :rb_stories, only: [:index] + resources :export_card_configurations, controller: :rb_export_card_configurations, only: %i[index show] do + resources :stories, controller: :rb_stories, only: [:index] end - resources :stories, controller: :rb_stories, only: [:create, :update] + resources :stories, controller: :rb_stories, only: %i[create update] end resource :query, controller: :rb_queries, only: :show diff --git a/modules/backlogs/db/migrate/20180323151208_to_v710_aggregated_backlogs_migrations.rb b/modules/backlogs/db/migrate/20180323151208_to_v710_aggregated_backlogs_migrations.rb index f2cd8f742f..4e5a70e0d5 100644 --- a/modules/backlogs/db/migrate/20180323151208_to_v710_aggregated_backlogs_migrations.rb +++ b/modules/backlogs/db/migrate/20180323151208_to_v710_aggregated_backlogs_migrations.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require Rails.root.join("db","migrate","migration_utils","migration_squasher").to_s +require Rails.root.join("db", "migrate", "migration_utils", "migration_squasher").to_s # This migration aggregates the migrations detailed in MIGRATION_FILES class ToV710AggregatedBacklogsMigrations < ActiveRecord::Migration[5.1] - MIGRATION_FILES = <<-MIGRATIONS 20111014073606_aggregated_backlogs_migrations.rb 20130625094113_add_backlogs_column_to_work_package.rb @@ -62,10 +61,10 @@ class ToV710AggregatedBacklogsMigrations < ActiveRecord::Migration[5.1] add_column :work_package_journals, :remaining_hours, :float add_index :work_package_journals, - [:fixed_version_id, - :status_id, - :project_id, - :type_id], + %i[fixed_version_id + status_id + project_id + type_id], name: 'work_package_journal_on_burndown_attributes' end end diff --git a/modules/backlogs/lib/api/v3/queries/schemas/backlogs_type_dependency_representer.rb b/modules/backlogs/lib/api/v3/queries/schemas/backlogs_type_dependency_representer.rb index ca87b3e0c7..3717632bbd 100644 --- a/modules/backlogs/lib/api/v3/queries/schemas/backlogs_type_dependency_representer.rb +++ b/modules/backlogs/lib/api/v3/queries/schemas/backlogs_type_dependency_representer.rb @@ -32,7 +32,6 @@ module API module Schemas class BacklogsTypeDependencyRepresenter < FilterDependencyRepresenter - schema_with_allowed_collection :values, type: ->(*) { type }, writable: true, diff --git a/modules/backlogs/lib/open_project/backlogs/burndown/series.rb b/modules/backlogs/lib/open_project/backlogs/burndown/series.rb index 3d936bf4af..25f38bf64d 100644 --- a/modules/backlogs/lib/open_project/backlogs/burndown/series.rb +++ b/modules/backlogs/lib/open_project/backlogs/burndown/series.rb @@ -33,12 +33,12 @@ module OpenProject::Backlogs::Burndown @name = args.pop.to_sym @display = true - raise "Unsupported unit '#{@unit}'" unless [:points, :hours].include? @unit + raise "Unsupported unit '#{@unit}'" unless %i[points hours].include? @unit + super(*args) end - attr_reader :unit - attr_reader :name + attr_reader :unit, :name attr_accessor :display end end diff --git a/modules/backlogs/lib/open_project/backlogs/burndown/series_raw_data.rb b/modules/backlogs/lib/open_project/backlogs/burndown/series_raw_data.rb index d733ce4333..3b3daef442 100644 --- a/modules/backlogs/lib/open_project/backlogs/burndown/series_raw_data.rb +++ b/modules/backlogs/lib/open_project/backlogs/burndown/series_raw_data.rb @@ -35,9 +35,7 @@ module OpenProject::Backlogs::Burndown super(*args) end - attr_reader :collect - attr_reader :sprint - attr_reader :project + attr_reader :collect, :sprint, :project def collect_names @names ||= @collect.to_a.map(&:last).flatten @@ -85,6 +83,7 @@ module OpenProject::Backlogs::Burndown def data_for_dates(dates) return [] if dates.empty? + query_string = <<-SQL SELECT date_journals.date, @@ -114,7 +113,7 @@ module OpenProject::Backlogs::Burndown def authoritative_journal_for_date(dates) raise 'dates must not be empty!' if dates.empty? - query = <<-SQL + <<-SQL SELECT d.date, j.journable_id, @@ -154,16 +153,14 @@ module OpenProject::Backlogs::Burndown GROUP BY d.date, j.journable_id ORDER BY j.journable_id, d.date, version SQL - - query end def dates_of_interest_join_table(dates) raise 'dates must not be empty!' if dates.empty? - @date_join ||= dates.map { |date| + @date_join ||= dates.map do |date| "SELECT CAST('#{date}' AS DATE) AS date" - }.join(' UNION ') + end.join(' UNION ') end def and_status_query diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rb index 26c6bfa9c6..b7833a768f 100644 --- a/modules/backlogs/lib/open_project/backlogs/engine.rb +++ b/modules/backlogs/lib/open_project/backlogs/engine.rb @@ -35,10 +35,9 @@ module OpenProject::Backlogs engine_name :openproject_backlogs def self.settings - { default: { 'story_types' => nil, - 'task_type' => nil, - 'card_spec' => nil - }, + { default: { 'story_types' => nil, + 'task_type' => nil, + 'card_spec' => nil }, partial: 'shared/settings', menu_item: :backlogs_settings } end @@ -71,27 +70,27 @@ module OpenProject::Backlogs # SYNTAX: permission :name_of_permission, { :controller_name => [:action1, :action2] } # Master backlog permissions - permission :view_master_backlog, rb_master_backlogs: :index, - rb_sprints: [:index, :show], - rb_wikis: :show, - rb_stories: [:index, :show], - rb_queries: :show, - rb_burndown_charts: :show, - rb_export_card_configurations: [:index, :show] - - permission :view_taskboards, rb_taskboards: :show, - rb_sprints: :show, - rb_stories: :show, - rb_tasks: [:index, :show], - rb_impediments: [:index, :show], - rb_wikis: :show, - rb_burndown_charts: :show, - rb_export_card_configurations: [:index, :show] + permission :view_master_backlog, rb_master_backlogs: :index, + rb_sprints: %i[index show], + rb_wikis: :show, + rb_stories: %i[index show], + rb_queries: :show, + rb_burndown_charts: :show, + rb_export_card_configurations: %i[index show] + + permission :view_taskboards, rb_taskboards: :show, + rb_sprints: :show, + rb_stories: :show, + rb_tasks: %i[index show], + rb_impediments: %i[index show], + rb_wikis: :show, + rb_burndown_charts: :show, + rb_export_card_configurations: %i[index show] # Sprint permissions # :show_sprints and :list_sprints are implicit in :view_master_backlog permission - permission :update_sprints, rb_sprints: [:edit, :update], - rb_wikis: [:edit, :update] + permission :update_sprints, rb_sprints: %i[edit update], + rb_wikis: %i[edit update] end menu :project_menu, diff --git a/modules/backlogs/lib/open_project/backlogs/hooks.rb b/modules/backlogs/lib/open_project/backlogs/hooks.rb index 2215c1cf47..21ee86ed17 100644 --- a/modules/backlogs/lib/open_project/backlogs/hooks.rb +++ b/modules/backlogs/lib/open_project/backlogs/hooks.rb @@ -40,7 +40,8 @@ module OpenProject::Backlogs::Hooks if User.current.allowed_to?(:edit_wiki_pages, project) snippet += '' - snippet += link_to I18n.t(:button_edit_wiki), { controller: '/rb_wikis', action: 'edit', project_id: project.id, sprint_id: version.id }, class: 'icon icon-edit' + snippet += link_to I18n.t(:button_edit_wiki), + { controller: '/rb_wikis', action: 'edit', project_id: project.id, sprint_id: version.id }, class: 'icon icon-edit' snippet += '' # This wouldn't be necesary if the schedules plugin didn't disable the @@ -63,7 +64,9 @@ module OpenProject::Backlogs::Hooks user: context[:user], color: context[:user].backlogs_preference(:task_color), versions_default_fold_state: - context[:user].backlogs_preference(:versions_default_fold_state) }) + context[:user].backlogs_preference(:versions_default_fold_state) + } + ) end def controller_work_package_new_after_save(context = {}) @@ -84,7 +87,7 @@ module OpenProject::Backlogs::Hooks if params[:copy_tasks] params[:copy_tasks] += ':' if params[:copy_tasks] !~ /:/ - action, id = *(params[:copy_tasks].split(/:/)) + action, id = *params[:copy_tasks].split(/:/) story = (id.nil? ? nil : Story.find(Integer(id))) @@ -94,17 +97,16 @@ module OpenProject::Backlogs::Hooks when 'open' tasks = tasks.select { |t| !t.closed? } when 'all', 'none' - # else raise "Unexpected value #{params[:copy_tasks]}" end - tasks.each {|t| + tasks.each do |t| nt = Task.new nt.copy_from(t) nt.parent_id = work_package.id nt.save - } + end end end end diff --git a/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb b/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb index f5ba699f31..c604cb934f 100644 --- a/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb +++ b/modules/backlogs/lib/open_project/backlogs/hooks/user_settings_hook.rb @@ -27,7 +27,6 @@ #++ class OpenProject::Backlogs::Hooks::UserSettingsHook < Redmine::Hook::ViewListener - # Updates the backlogs settings before saving the user # # Context: diff --git a/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb index b715718aad..a1bc2a1fdf 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/permitted_params_patch.rb @@ -49,4 +49,4 @@ module OpenProject::Backlogs::Patches::PermittedParamsPatch end end end -PermittedParams.send(:include, OpenProject::Backlogs::Patches::PermittedParamsPatch) +PermittedParams.include OpenProject::Backlogs::Patches::PermittedParamsPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/project_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/project_patch.rb index 33c07c4e02..aac9bd7ecc 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/project_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/project_patch.rb @@ -41,7 +41,7 @@ module OpenProject::Backlogs::Patches::ProjectPatch def rebuild_positions return unless backlogs_enabled? - shared_versions.each do |v| v.rebuild_positions(self) end + shared_versions.each { |v| v.rebuild_positions(self) } nil end @@ -51,4 +51,4 @@ module OpenProject::Backlogs::Patches::ProjectPatch end end -Project.send(:include, OpenProject::Backlogs::Patches::ProjectPatch) +Project.include OpenProject::Backlogs::Patches::ProjectPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/project_seeder_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/project_seeder_patch.rb index 1edc0f23a4..3852ad1b26 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/project_seeder_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/project_seeder_patch.rb @@ -51,11 +51,11 @@ module OpenProject::Backlogs::Patches::ProjectSeederPatch # This relies on the names from the core's `config/locales/en.seeders.yml`. def version_settings_display_map { - 'Sprint 1' => VersionSetting::DISPLAY_LEFT, - 'Sprint 2' => VersionSetting::DISPLAY_LEFT, - 'Bug Backlog' => VersionSetting::DISPLAY_RIGHT, + 'Sprint 1' => VersionSetting::DISPLAY_LEFT, + 'Sprint 2' => VersionSetting::DISPLAY_LEFT, + 'Bug Backlog' => VersionSetting::DISPLAY_RIGHT, 'Product Backlog' => VersionSetting::DISPLAY_RIGHT, - 'Wish List' => VersionSetting::DISPLAY_RIGHT + 'Wish List' => VersionSetting::DISPLAY_RIGHT } end end diff --git a/modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb index f9fa021904..9acebacba6 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/project_settings_helper_patch.rb @@ -47,4 +47,4 @@ module OpenProject::Backlogs::Patches::ProjectSettingsHelperPatch end end -ProjectSettingsHelper.send(:include, OpenProject::Backlogs::Patches::ProjectSettingsHelperPatch) +ProjectSettingsHelper.include OpenProject::Backlogs::Patches::ProjectSettingsHelperPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb index d94d4bdf19..07269737c6 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/projects_controller_patch.rb @@ -37,9 +37,9 @@ module OpenProject::Backlogs::Patches::ProjectsControllerPatch module InstanceMethods def project_done_statuses - selected_statuses = (params[:statuses] || []).map { |work_package_status| + selected_statuses = (params[:statuses] || []).map do |work_package_status| Status.find(work_package_status[:status_id].to_i) - }.compact + end.compact @project.done_statuses = selected_statuses @project.save! @@ -70,4 +70,4 @@ module OpenProject::Backlogs::Patches::ProjectsControllerPatch end end -ProjectsController.send(:include, OpenProject::Backlogs::Patches::ProjectsControllerPatch) +ProjectsController.include OpenProject::Backlogs::Patches::ProjectsControllerPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/set_attributes_service_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/set_attributes_service_patch.rb index 2f1210e6ea..18cf95f22e 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/set_attributes_service_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/set_attributes_service_patch.rb @@ -47,10 +47,12 @@ module OpenProject::Backlogs::Patches::SetAttributesServicePatch def closest_story_or_impediment(parent_id) return work_package if work_package.is_story? || work_package.is_impediment? + closest = nil ancestor_chain(parent_id).each do |i| # break if we found an element in our chain that is not relevant in backlogs break unless i.in_backlogs_type? + if i.is_story? || i.is_impediment? closest = i break diff --git a/modules/backlogs/lib/open_project/backlogs/patches/status_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/status_patch.rb index 98f4118e5d..bfed03fb0d 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/status_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/status_patch.rb @@ -42,4 +42,4 @@ module OpenProject::Backlogs::Patches::StatusPatch end end -Status.send(:include, OpenProject::Backlogs::Patches::StatusPatch) +Status.include OpenProject::Backlogs::Patches::StatusPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/user_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/user_patch.rb index 47120181d4..d308887907 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/user_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/user_patch.rb @@ -60,7 +60,7 @@ module OpenProject::Backlogs::Patches::UserPatch def write_backlogs_preference(attr, new_value) pref[:"backlogs_#{attr}"] = new_value - pref.save! unless self.new_record? + pref.save! unless new_record? new_value end @@ -78,4 +78,4 @@ module OpenProject::Backlogs::Patches::UserPatch end end -User.send(:include, OpenProject::Backlogs::Patches::UserPatch) +User.include OpenProject::Backlogs::Patches::UserPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb index 17deba0df2..1bda57eba3 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb @@ -80,4 +80,4 @@ module OpenProject::Backlogs::Patches::VersionPatch end end -Version.send(:include, OpenProject::Backlogs::Patches::VersionPatch) +Version.include OpenProject::Backlogs::Patches::VersionPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/versions_controller_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/versions_controller_patch.rb index b51fe82847..a90e21e76d 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/versions_controller_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/versions_controller_patch.rb @@ -35,11 +35,11 @@ module OpenProject::Backlogs::Patches::VersionsControllerPatch helper :version_settings # Find project explicitly on update and edit - skip_before_action :find_project_from_association, only: [:edit, :update] - skip_before_action :find_model_object, only: [:edit, :update] - prepend_before_action :find_project_and_version, only: [:edit, :update] + skip_before_action :find_project_from_association, only: %i[edit update] + skip_before_action :find_model_object, only: %i[edit update] + prepend_before_action :find_project_and_version, only: %i[edit update] - before_action :add_project_to_version_settings_attributes, only: [:update, :create] + before_action :add_project_to_version_settings_attributes, only: %i[update create] before_action :whitelist_update_params, only: :update @@ -80,4 +80,4 @@ module OpenProject::Backlogs::Patches::VersionsControllerPatch end end -VersionsController.send(:include, OpenProject::Backlogs::Patches::VersionsControllerPatch) +VersionsController.include OpenProject::Backlogs::Patches::VersionsControllerPatch diff --git a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb index 9c5467694a..15d2f120ed 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb @@ -41,10 +41,10 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch register_on_journal_formatter(:decimal, 'story_points') register_on_journal_formatter(:decimal, 'position') - validates_numericality_of :story_points, only_integer: true, - allow_nil: true, + validates_numericality_of :story_points, only_integer: true, + allow_nil: true, greater_than_or_equal_to: 0, - less_than: 10_000, + less_than: 10_000, if: lambda { backlogs_enabled? } validates_numericality_of :remaining_hours, only_integer: false, @@ -102,10 +102,9 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch end def types - case - when is_story? + if is_story? Story.types - when is_task? + elsif is_task? Task.types else [] @@ -113,26 +112,29 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch end def story - if self.is_story? + if is_story? return Story.find(id) - elsif self.is_task? + elsif is_task? # Make sure to get the closest ancestor that is a Story, i.e. the one with the highest lft # otherwise, the highest parent that is a Story is returned story_work_package = ancestors.find_by(type_id: Story.types).order(Arel.sql('lft DESC')) return Story.find(story_work_package.id) if story_work_package end + nil end def blocks # return work_packages that I block that aren't closed return [] if closed? + blocks_relations.includes(:to).merge(WorkPackage.with_status_open).map(&:to) end def blockers # return work_packages that block me return [] if closed? + blocked_by_relations.includes(:from).merge(WorkPackage.with_status_open).map(&:from) end @@ -155,4 +157,4 @@ module OpenProject::Backlogs::Patches::WorkPackagePatch end end -WorkPackage.send(:include, OpenProject::Backlogs::Patches::WorkPackagePatch) +WorkPackage.include OpenProject::Backlogs::Patches::WorkPackagePatch diff --git a/modules/backlogs/spec/api/work_package_resource_spec.rb b/modules/backlogs/spec/api/work_package_resource_spec.rb index 66e5563f76..400efa5bd6 100644 --- a/modules/backlogs/spec/api/work_package_resource_spec.rb +++ b/modules/backlogs/spec/api/work_package_resource_spec.rb @@ -35,12 +35,12 @@ describe 'API v3 Work package resource' do let(:current_user) { FactoryBot.create(:admin) } let(:project) { FactoryBot.create(:project) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, - project: project, - story_points: 8, - remaining_hours: 5) - } + project: project, + story_points: 8, + remaining_hours: 5) + end let(:wp_path) { "/api/v3/work_packages/#{work_package.id}" } before do @@ -66,9 +66,9 @@ describe 'API v3 Work package resource' do end context 'backlogs deactivated' do - let(:project) { + let(:project) do FactoryBot.create(:project, disable_modules: 'backlogs') - } + end include_context 'query work package' diff --git a/modules/backlogs/spec/api/work_packages/form_resource_spec.rb b/modules/backlogs/spec/api/work_packages/form_resource_spec.rb index e135f92e99..c9fc4d176d 100644 --- a/modules/backlogs/spec/api/work_packages/form_resource_spec.rb +++ b/modules/backlogs/spec/api/work_packages/form_resource_spec.rb @@ -57,9 +57,9 @@ describe 'API v3 Work package form resource', type: :request do it_behaves_like 'API V3 formattable', '_embedded/payload/description' do let(:format) { 'markdown' } let(:raw) { defined?(raw_value) ? raw_value : work_package.description.to_s } - let(:html) { + let(:html) do defined?(html_value) ? html_value : ('

' + work_package.description.to_s + '

') - } + end end end @@ -76,9 +76,9 @@ describe 'API v3 Work package form resource', type: :request do let(:error_path) { "_embedded/validationErrors/#{property}" } let(:error_id) { 'urn:openproject-org:api:v3:errors:PropertyConstraintViolation'.to_json } - let(:error_body) { + let(:error_body) do parse_json(subject.body)['_embedded']['validationErrors'][property] - } + end it { expect(subject.body).to have_json_path(error_path) } it { diff --git a/modules/backlogs/spec/contracts/work_packages/base_contract_spec.rb b/modules/backlogs/spec/contracts/work_packages/base_contract_spec.rb index c49dec4df1..b9e9ed2119 100644 --- a/modules/backlogs/spec/contracts/work_packages/base_contract_spec.rb +++ b/modules/backlogs/spec/contracts/work_packages/base_contract_spec.rb @@ -42,9 +42,9 @@ describe WorkPackages::BaseContract, type: :model do let(:project) do p = FactoryBot.build(:project, members: [FactoryBot.build(:member, - principal: user, - roles: [role])], - types: [type_feature, type_task, type_bug]) + principal: user, + roles: [role])], + types: [type_feature, type_task, type_bug]) allow(p) .to receive(:assignable_versions) @@ -58,9 +58,9 @@ describe WorkPackages::BaseContract, type: :model do let(:other_project) do p = FactoryBot.build(:project, members: [FactoryBot.build(:member, - principal: user, - roles: [role])], - types: [type_feature, type_task, type_bug]) + principal: user, + roles: [role])], + types: [type_feature, type_task, type_bug]) allow(p) .to receive(:assignable_versions) @@ -73,69 +73,69 @@ describe WorkPackages::BaseContract, type: :model do let(:story) do FactoryBot.build_stubbed(:stubbed_work_package, - subject: 'Story', - project: project, - type: type_feature, - version: version1, - status: status, - author: user, - priority: issue_priority) + subject: 'Story', + project: project, + type: type_feature, + version: version1, + status: status, + author: user, + priority: issue_priority) end let(:story2) do FactoryBot.build_stubbed(:stubbed_work_package, - subject: 'Story2', - project: project, - type: type_feature, - version: version1, - status: status, - author: user, - priority: issue_priority) + subject: 'Story2', + project: project, + type: type_feature, + version: version1, + status: status, + author: user, + priority: issue_priority) end - let(:task) { + let(:task) do FactoryBot.build_stubbed(:stubbed_work_package, - subject: 'Task', - type: type_task, - version: version1, - project: project, - status: status, - author: user, - priority: issue_priority) - } - - let(:task2) { + subject: 'Task', + type: type_task, + version: version1, + project: project, + status: status, + author: user, + priority: issue_priority) + end + + let(:task2) do FactoryBot.build_stubbed(:stubbed_work_package, - subject: 'Task2', - type: type_task, - version: version1, - project: project, - status: status, - author: user, - priority: issue_priority) - } - - let(:bug) { + subject: 'Task2', + type: type_task, + version: version1, + project: project, + status: status, + author: user, + priority: issue_priority) + end + + let(:bug) do FactoryBot.build_stubbed(:stubbed_work_package, - subject: 'Bug', - type: type_bug, - version: version1, - project: project, - status: status, - author: user, - priority: issue_priority) - } - - let(:bug2) { + subject: 'Bug', + type: type_bug, + version: version1, + project: project, + status: status, + author: user, + priority: issue_priority) + end + + let(:bug2) do FactoryBot.build_stubbed(:stubbed_work_package, - subject: 'Bug2', - type: type_bug, - version: version1, - project: project, - status: status, - author: user, - priority: issue_priority) - } + subject: 'Bug2', + type: type_bug, + version: version1, + project: project, + status: status, + author: user, + priority: issue_priority) + end subject(:valid) { instance.validate } @@ -143,10 +143,10 @@ describe WorkPackages::BaseContract, type: :model do project.save! allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [type_feature.id], - 'task_type' => type_task.id.to_s }) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [type_feature.id], + 'task_type' => type_task.id.to_s }) end shared_examples_for 'is valid' do diff --git a/modules/backlogs/spec/factories/story_factory.rb b/modules/backlogs/spec/factories/story_factory.rb index e1a7dfbb66..d98bb24cff 100644 --- a/modules/backlogs/spec/factories/story_factory.rb +++ b/modules/backlogs/spec/factories/story_factory.rb @@ -29,7 +29,7 @@ FactoryBot.define do factory :story do association :priority, factory: :priority - sequence(:subject) do |n| "story#{n}" end + sequence(:subject) { |n| "story#{n}" } description { 'story story story' } association :type, factory: :type_feature association :author, factory: :user diff --git a/modules/backlogs/spec/features/backlogs/create_story_spec.rb b/modules/backlogs/spec/features/backlogs/create_story_spec.rb index 695cb5de07..b60e45f7fc 100644 --- a/modules/backlogs/spec/features/backlogs/create_story_spec.rb +++ b/modules/backlogs/spec/features/backlogs/create_story_spec.rb @@ -70,7 +70,7 @@ describe 'Backlogs', js: true do priority: default_priority, position: 1, story_points: 3, - version: backlog_version ) + version: backlog_version) end let!(:existing_story2) do FactoryBot.create(:work_package, diff --git a/modules/backlogs/spec/features/backlogs_in_backlog_view_spec.rb b/modules/backlogs/spec/features/backlogs_in_backlog_view_spec.rb index 815388b14d..2a84289987 100644 --- a/modules/backlogs/spec/features/backlogs_in_backlog_view_spec.rb +++ b/modules/backlogs/spec/features/backlogs_in_backlog_view_spec.rb @@ -60,7 +60,6 @@ describe 'Backlogs in backlog view', manage_versions update_sprints assign_versions)) - end let!(:current_user) do FactoryBot.create(:user, diff --git a/modules/backlogs/spec/features/impediments_spec.rb b/modules/backlogs/spec/features/impediments_spec.rb index 1e6cf9bde9..0be6bfa624 100644 --- a/modules/backlogs/spec/features/impediments_spec.rb +++ b/modules/backlogs/spec/features/impediments_spec.rb @@ -61,7 +61,6 @@ describe 'Impediments on taskboard', edit_work_packages manage_subtasks assign_versions)) - end let!(:current_user) do FactoryBot.create(:user, @@ -139,7 +138,8 @@ describe 'Impediments on taskboard', expect(page) .to have_selector('div.impediment.error', text: 'Other sprint impediment') expect(page) - .to have_selector('#msgBox', text: "IDs of blocked work packages can only contain IDs of work packages in the current sprint.") + .to have_selector('#msgBox', + text: "IDs of blocked work packages can only contain IDs of work packages in the current sprint.") click_on 'OK' @@ -156,7 +156,8 @@ describe 'Impediments on taskboard', expect(page) .to have_selector('div.impediment.error', text: 'Invalid id impediment') expect(page) - .to have_selector('#msgBox', text: "IDs of blocked work packages can only contain IDs of work packages in the current sprint.") + .to have_selector('#msgBox', + text: "IDs of blocked work packages can only contain IDs of work packages in the current sprint.") click_on 'OK' # Attempt to create a new impediment without specifying the blocked story/task diff --git a/modules/backlogs/spec/features/onboarding/backlogs_onboarding_tour_spec.rb b/modules/backlogs/spec/features/onboarding/backlogs_onboarding_tour_spec.rb index 95d43ce5a1..f5b84a7105 100644 --- a/modules/backlogs/spec/features/onboarding/backlogs_onboarding_tour_spec.rb +++ b/modules/backlogs/spec/features/onboarding/backlogs_onboarding_tour_spec.rb @@ -51,11 +51,11 @@ describe 'backlogs onboarding tour', js: true do let(:impediment) do FactoryBot.build(:impediment, author: user, - version: sprint, - assigned_to: user, - project: project, - type: type_task, - status: status) + version: sprint, + assigned_to: user, + project: project, + type: type_task, + status: status) end let(:story_type) { FactoryBot.create(:type_feature) } @@ -74,7 +74,7 @@ describe 'backlogs onboarding tour', js: true do priority: priority, position: 1, story_points: 3, - version: sprint ) + version: sprint) end before do diff --git a/modules/backlogs/spec/features/resolved_status_spec.rb b/modules/backlogs/spec/features/resolved_status_spec.rb index a55cd92052..42dc16db10 100644 --- a/modules/backlogs/spec/features/resolved_status_spec.rb +++ b/modules/backlogs/spec/features/resolved_status_spec.rb @@ -38,7 +38,6 @@ describe 'Resolved status', let(:role) do FactoryBot.create(:role, permissions: %i(edit_project)) - end let!(:current_user) do FactoryBot.create(:user, diff --git a/modules/backlogs/spec/features/stories_in_backlog_spec.rb b/modules/backlogs/spec/features/stories_in_backlog_spec.rb index d8ef8d2c5c..2947ac52ed 100644 --- a/modules/backlogs/spec/features/stories_in_backlog_spec.rb +++ b/modules/backlogs/spec/features/stories_in_backlog_spec.rb @@ -58,7 +58,6 @@ describe 'Stories in backlog', edit_work_packages manage_subtasks assign_versions)) - end let!(:current_user) do FactoryBot.create(:user, @@ -131,7 +130,6 @@ describe 'Stories in backlog', status: default_status, version: sprint, story_points: 10) - end let!(:export_card_configurations) do ExportCardConfiguration.create!(name: 'Default', diff --git a/modules/backlogs/spec/features/tasks_on_taskboard_spec.rb b/modules/backlogs/spec/features/tasks_on_taskboard_spec.rb index 62dd0adc36..164766b883 100644 --- a/modules/backlogs/spec/features/tasks_on_taskboard_spec.rb +++ b/modules/backlogs/spec/features/tasks_on_taskboard_spec.rb @@ -58,7 +58,6 @@ describe 'Tasks on taskboard', edit_work_packages manage_subtasks assign_versions)) - end let!(:current_user) do FactoryBot.create(:user, @@ -136,7 +135,6 @@ describe 'Tasks on taskboard', status: default_status, version: sprint, story_points: 10) - end let!(:export_card_configurations) do ExportCardConfiguration.create!(name: 'Default', diff --git a/modules/backlogs/spec/features/work_packages/story_points_spec.rb b/modules/backlogs/spec/features/work_packages/story_points_spec.rb index 9b732be690..05822912fc 100644 --- a/modules/backlogs/spec/features/work_packages/story_points_spec.rb +++ b/modules/backlogs/spec/features/work_packages/story_points_spec.rb @@ -32,29 +32,31 @@ describe 'Work packages having story points', type: :feature, js: true do before do allow(User).to receive(:current).and_return current_user allow(Setting).to receive(:plugin_openproject_backlogs).and_return('points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [story_type.id.to_s], - 'task_type' => task_type.id.to_s) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [story_type.id.to_s], + 'task_type' => task_type.id.to_s) end let(:current_user) { FactoryBot.create(:admin) } - let(:project) { FactoryBot.create(:project, - enabled_module_names: %w(work_package_tracking backlogs)) } + let(:project) do + FactoryBot.create(:project, + enabled_module_names: %w(work_package_tracking backlogs)) + end let(:status) { FactoryBot.create :default_status } let(:story_type) { FactoryBot.create(:type_feature) } let(:task_type) { FactoryBot.create(:type_feature) } describe 'showing the story points on the work package show page' do let(:story_points) { 42 } - let(:story_with_sp) { + let(:story_with_sp) do FactoryBot.create(:story, - type: story_type, - author: current_user, - project: project, - status: status, - story_points: story_points) - } + type: story_type, + author: current_user, + project: project, + status: status, + story_points: story_points) + end it 'should be displayed' do wp_page = Pages::FullWorkPackage.new(story_with_sp) @@ -62,7 +64,7 @@ describe 'Work packages having story points', type: :feature, js: true do wp_page.visit! wp_page.expect_subject - wp_page.expect_attributes :storyPoints => story_points + wp_page.expect_attributes storyPoints: story_points wp_page.ensure_page_loaded end diff --git a/modules/backlogs/spec/models/backlog_spec.rb b/modules/backlogs/spec/models/backlog_spec.rb index 3c7d42e146..35efa9c8e1 100644 --- a/modules/backlogs/spec/models/backlog_spec.rb +++ b/modules/backlogs/spec/models/backlog_spec.rb @@ -33,8 +33,8 @@ describe Backlog, type: :model do before(:each) do @feature = FactoryBot.create(:type_feature) - allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [@feature.id.to_s], - 'task_type' => '0' }) + allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [@feature.id.to_s], + 'task_type' => '0' }) @status = FactoryBot.create(:status) end @@ -43,7 +43,8 @@ describe Backlog, type: :model do describe 'WITH one open version defined in the project' do before(:each) do @project = project - @work_packages = [FactoryBot.create(:work_package, subject: 'work_package1', project: @project, type: @feature, status: @status)] + @work_packages = [FactoryBot.create(:work_package, subject: 'work_package1', project: @project, type: @feature, + status: @status)] @version = FactoryBot.create(:version, project: project, work_packages: @work_packages) @version_settings = @version.version_settings.create(display: VersionSetting::DISPLAY_RIGHT, project: project) end diff --git a/modules/backlogs/spec/models/burndown_spec.rb b/modules/backlogs/spec/models/burndown_spec.rb index 59fd637097..3f8289e866 100644 --- a/modules/backlogs/spec/models/burndown_spec.rb +++ b/modules/backlogs/spec/models/burndown_spec.rb @@ -65,10 +65,10 @@ describe Burndown, type: :model do allow(User).to receive(:current).and_return(user) allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [type_feature.id.to_s], - 'task_type' => type_task.id.to_s }) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [type_feature.id.to_s], + 'task_type' => type_task.id.to_s }) project.save! @@ -85,7 +85,7 @@ describe Burndown, type: :model do describe 'WITH the today date fixed to April 4th, 2011 and having a 10 (working days) sprint' do before(:each) do allow(Time).to receive(:now).and_return(Time.utc(2011, 'apr', 4, 20, 15, 1)) - allow(Date).to receive(:today).and_return(Date.civil(2011, 04, 04)) + allow(Date).to receive(:today).and_return(Date.civil(2011, 0o4, 0o4)) end describe 'WITH having a version in the future' do @@ -110,13 +110,13 @@ describe Burndown, type: :model do describe 'WITH 1 story assigned to the sprint' do before(:each) do @story = FactoryBot.build(:story, subject: 'Story 1', - project: project, - version: version, - type: type_feature, - status: issue_open, - priority: issue_priority, - created_at: Date.today - 20.days, - updated_at: Date.today - 20.days) + project: project, + version: version, + type: type_feature, + status: issue_open, + priority: issue_priority, + created_at: Date.today - 20.days, + updated_at: Date.today - 20.days) end describe 'WITH the story having story_point defined on creation' do @@ -162,13 +162,13 @@ describe Burndown, type: :model do (0..9).each do |i| @stories[i] = FactoryBot.create(:story, subject: "Story #{i}", - project: project, - version: version, - type: type_feature, - status: issue_open, - priority: issue_priority, - created_at: Date.today - (20 - i).days, - updated_at: Date.today - (20 - i).days) + project: project, + version: version, + type: type_feature, + status: issue_open, + priority: issue_priority, + created_at: Date.today - (20 - i).days, + updated_at: Date.today - (20 - i).days) @stories[i].last_journal.update_attribute(:created_at, @stories[i].created_at) end end diff --git a/modules/backlogs/spec/models/impediment_spec.rb b/modules/backlogs/spec/models/impediment_spec.rb index 676443854e..814ce09853 100644 --- a/modules/backlogs/spec/models/impediment_spec.rb +++ b/modules/backlogs/spec/models/impediment_spec.rb @@ -35,50 +35,50 @@ describe Impediment, type: :model do let(:type_task) { @type_task ||= FactoryBot.create(:type_task) } let(:issue_priority) { @issue_priority ||= FactoryBot.create(:priority, is_default: true) } let(:status) { FactoryBot.create(:status) } - let(:task) { + let(:task) do FactoryBot.build(:task, type: type_task, - project: project, - author: user, - priority: issue_priority, - status: status) - } - let(:feature) { + project: project, + author: user, + priority: issue_priority, + status: status) + end + let(:feature) do FactoryBot.build(:work_package, type: type_feature, - project: project, - author: user, - priority: issue_priority, - status: status) - } + project: project, + author: user, + priority: issue_priority, + status: status) + end let(:version) { FactoryBot.create(:version, project: project) } let(:project) do unless @project @project = FactoryBot.build(:project, types: [type_feature, type_task]) @project.members = [FactoryBot.build(:member, principal: user, - project: @project, - roles: [role])] + project: @project, + roles: [role])] end @project end - let(:impediment) { + let(:impediment) do FactoryBot.build(:impediment, author: user, - version: version, - assigned_to: user, - priority: issue_priority, - project: project, - type: type_task, - status: status) - } + version: version, + assigned_to: user, + priority: issue_priority, + project: project, + type: type_task, + status: status) + end before(:each) do allow(Setting) .to receive(:plugin_openproject_backlogs) .and_return({ 'points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [type_feature.id.to_s], - 'task_type' => type_task.id.to_s }) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [type_feature.id.to_s], + 'task_type' => type_task.id.to_s }) login_as user end diff --git a/modules/backlogs/spec/models/issue_position_spec.rb b/modules/backlogs/spec/models/issue_position_spec.rb index 932edaadc6..2749ee48e3 100644 --- a/modules/backlogs/spec/models/issue_position_spec.rb +++ b/modules/backlogs/spec/models/issue_position_spec.rb @@ -32,17 +32,17 @@ describe WorkPackage, type: :model do describe 'Story positions' do def build_work_package(options) FactoryBot.build(:work_package, options.reverse_merge(version_id: sprint_1.id, - priority_id: priority.id, - project_id: project.id, - status_id: status.id, - type_id: story_type.id)) + priority_id: priority.id, + project_id: project.id, + status_id: status.id, + type_id: story_type.id)) end def create_work_package(options) build_work_package(options).tap(&:save!) end - let(:status) { FactoryBot.create(:status) } + let(:status) { FactoryBot.create(:status) } let(:priority) { FactoryBot.create(:priority_normal) } let(:project) { FactoryBot.create(:project) } @@ -64,15 +64,15 @@ describe WorkPackage, type: :model do let(:work_package_b) { create_work_package(subject: 'WorkPackage b', version_id: sprint_2.id) } let(:work_package_c) { create_work_package(subject: 'WorkPackage c', version_id: sprint_2.id) } - let(:feedback_1) { + let(:feedback_1) do create_work_package(subject: 'Feedback 1', version_id: sprint_1.id, type_id: other_type.id) - } + end - let(:task_1) { + let(:task_1) do create_work_package(subject: 'Task 1', version_id: sprint_1.id, type_id: task_type.id) - } + end before do # We had problems while writing these specs, that some elements kept @@ -88,7 +88,8 @@ describe WorkPackage, type: :model do # Enable and configure backlogs project.enabled_module_names = project.enabled_module_names + ['backlogs'] - allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [story_type.id, epic_type.id], 'task_type' => task_type.id }) + allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [story_type.id, epic_type.id], + 'task_type' => task_type.id }) # Otherwise the type id's from the previous test are still active WorkPackage.instance_variable_set(:@backlogs_types, nil) @@ -120,7 +121,8 @@ describe WorkPackage, type: :model do it 'does not reorder the existing work_packages' do new_work_package = create_work_package(subject: 'Newest WorkPackage', version_id: sprint_1.id) - expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5]) + expect([work_package_1, work_package_2, work_package_3, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5]) end end @@ -129,7 +131,8 @@ describe WorkPackage, type: :model do work_package_2.version = sprint_2 work_package_2.save! - expect(sprint_1.work_packages.order(Arel.sql('id'))).to eq([work_package_1, work_package_3, work_package_4, work_package_5]) + expect(sprint_1.work_packages.order(Arel.sql('id'))).to eq([work_package_1, work_package_3, work_package_4, + work_package_5]) expect(sprint_1.work_packages.order(Arel.sql('id')).each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) end end @@ -146,7 +149,8 @@ describe WorkPackage, type: :model do work_package_a.version = sprint_1 work_package_a.save! - expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5]) + expect([work_package_1, work_package_2, work_package_3, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5]) end end @@ -154,7 +158,8 @@ describe WorkPackage, type: :model do it 'reorders the existing work_packages' do work_package_3.destroy - expect([work_package_1, work_package_2, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) + expect([work_package_1, work_package_2, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) end end @@ -164,7 +169,8 @@ describe WorkPackage, type: :model do work_package_3.type = epic_type work_package_3.save! - expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5]) + expect([work_package_1, work_package_2, work_package_3, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5]) end end @@ -180,7 +186,8 @@ describe WorkPackage, type: :model do work_package_3.type = other_type work_package_3.save! - expect([work_package_1, work_package_2, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) + expect([work_package_1, work_package_2, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) end end @@ -196,7 +203,8 @@ describe WorkPackage, type: :model do work_package_3.type = task_type work_package_3.save! - expect([work_package_1, work_package_2, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) + expect([work_package_1, work_package_2, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) end end @@ -212,7 +220,8 @@ describe WorkPackage, type: :model do task_1.type = story_type task_1.save! - expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5, task_1].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5, 6]) + expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5, + task_1].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5, 6]) end end @@ -228,7 +237,8 @@ describe WorkPackage, type: :model do feedback_1.type = story_type feedback_1.save! - expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5, feedback_1].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5, 6]) + expect([work_package_1, work_package_2, work_package_3, work_package_4, work_package_5, + feedback_1].each(&:reload).map(&:position)).to eq([1, 2, 3, 4, 5, 6]) end end end @@ -242,18 +252,18 @@ describe WorkPackage, type: :model do let(:project_wo_backlogs) { FactoryBot.create(:project) } let(:sub_project_wo_backlogs) { FactoryBot.create(:project) } - let(:shared_sprint) { + let(:shared_sprint) do FactoryBot.create(:version, - project_id: project.id, - name: 'Shared Sprint', - sharing: 'descendants') - } + project_id: project.id, + name: 'Shared Sprint', + sharing: 'descendants') + end - let(:version_go_live) { + let(:version_go_live) do FactoryBot.create(:version, - project_id: project_wo_backlogs.id, - name: 'Go-Live') - } + project_id: project_wo_backlogs.id, + name: 'Go-Live') + end shared_let(:admin) { FactoryBot.create :admin } def move_to_project(work_package, project) @@ -277,11 +287,11 @@ describe WorkPackage, type: :model do describe '- Moving an work_package from a project without backlogs to a backlogs_enabled project' do describe 'if the version may not be kept' do - let(:work_package_i) { + let(:work_package_i) do create_work_package(subject: 'WorkPackage I', version_id: version_go_live.id, project_id: project_wo_backlogs.id) - } + end before do work_package_i end @@ -304,11 +314,11 @@ describe WorkPackage, type: :model do end describe 'if the version may be kept' do - let(:work_package_i) { + let(:work_package_i) do create_work_package(subject: 'WorkPackage I', version_id: shared_sprint.id, project_id: sub_project_wo_backlogs.id) - } + end before do work_package_i @@ -355,23 +365,24 @@ describe WorkPackage, type: :model do expect(result).to be_truthy - expect([work_package_1, work_package_2, work_package_4, work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) + expect([work_package_1, work_package_2, work_package_4, + work_package_5].each(&:reload).map(&:position)).to eq([1, 2, 3, 4]) end end describe 'if the version may be kept' do - let(:work_package_i) { + let(:work_package_i) do create_work_package(subject: 'WorkPackage I', version_id: shared_sprint.id) - } - let(:work_package_ii) { + end + let(:work_package_ii) do create_work_package(subject: 'WorkPackage II', version_id: shared_sprint.id) - } - let(:work_package_iii) { + end + let(:work_package_iii) do create_work_package(subject: 'WorkPackage III', version_id: shared_sprint.id) - } + end before do work_package_i.move_to_bottom diff --git a/modules/backlogs/spec/models/issue_spec.rb b/modules/backlogs/spec/models/issue_spec.rb index cdee9c3650..5dfcd5278c 100644 --- a/modules/backlogs/spec/models/issue_spec.rb +++ b/modules/backlogs/spec/models/issue_spec.rb @@ -121,8 +121,8 @@ describe WorkPackage, type: :model do @project.types = [FactoryBot.build(:type_feature)] @work_package = FactoryBot.build(:work_package, project: @project, - status: @status_open, - type: FactoryBot.build(:type_feature)) + status: @status_open, + type: FactoryBot.build(:type_feature)) end it 'should not be done when having the initial status "open"' do diff --git a/modules/backlogs/spec/models/sprint_spec.rb b/modules/backlogs/spec/models/sprint_spec.rb index 4ae3962215..b61267586f 100644 --- a/modules/backlogs/spec/models/sprint_spec.rb +++ b/modules/backlogs/spec/models/sprint_spec.rb @@ -37,7 +37,7 @@ describe Sprint, type: :model do describe 'WITH display set to left' do before(:each) do sprint.version_settings = [FactoryBot.build(:version_setting, project: project, - display: VersionSetting::DISPLAY_LEFT)] + display: VersionSetting::DISPLAY_LEFT)] sprint.project = project sprint.save! end @@ -50,10 +50,10 @@ describe Sprint, type: :model do describe 'WITH a version setting defined for another project' do before(:each) do another_project = FactoryBot.build(:project, name: 'another project', - identifier: 'another project') + identifier: 'another project') sprint.version_settings = [FactoryBot.build(:version_setting, project: another_project, - display: VersionSetting::DISPLAY_RIGHT)] + display: VersionSetting::DISPLAY_RIGHT)] sprint.project = project sprint.save end @@ -196,8 +196,10 @@ describe Sprint, type: :model do describe '#order_by_date' do before(:each) do @sprint1 = FactoryBot.create(:sprint, name: 'sprint1', project: project, start_date: Date.today + 2.days) - @sprint2 = FactoryBot.create(:sprint, name: 'sprint2', project: project, start_date: Date.today + 1.day, effective_date: Date.today + 3.days) - @sprint3 = FactoryBot.create(:sprint, name: 'sprint3', project: project, start_date: Date.today + 1.day, effective_date: Date.today + 2.days) + @sprint2 = FactoryBot.create(:sprint, name: 'sprint2', project: project, start_date: Date.today + 1.day, + effective_date: Date.today + 3.days) + @sprint3 = FactoryBot.create(:sprint, name: 'sprint3', project: project, start_date: Date.today + 1.day, + effective_date: Date.today + 2.days) end it 'sorts the dates correctly', :aggregate_failures do @@ -205,7 +207,6 @@ describe Sprint, type: :model do expect(Sprint.order_by_date[1]).to eql @sprint2 expect(Sprint.order_by_date[2]).to eql @sprint1 end - end describe '#apply_to' do diff --git a/modules/backlogs/spec/models/story_spec.rb b/modules/backlogs/spec/models/story_spec.rb index 564dd614c2..8be8cb1ad7 100644 --- a/modules/backlogs/spec/models/story_spec.rb +++ b/modules/backlogs/spec/models/story_spec.rb @@ -38,35 +38,35 @@ describe Story, type: :model do let(:sprint) { @sprint ||= FactoryBot.create(:sprint, project: project) } let(:issue_priority) { @issue_priority ||= FactoryBot.create(:priority) } let(:task_type) { FactoryBot.create(:type_task) } - let(:task) { + let(:task) do FactoryBot.create(:story, version: version, - project: project, - status: status1, - type: task_type, - priority: issue_priority) - } - let(:story1) { + project: project, + status: status1, + type: task_type, + priority: issue_priority) + end + let(:story1) do FactoryBot.create(:story, version: version, - project: project, - status: status1, - type: type_feature, - priority: issue_priority) - } + project: project, + status: status1, + type: type_feature, + priority: issue_priority) + end - let(:story2) { + let(:story2) do FactoryBot.create(:story, version: version, - project: project, - status: status1, - type: type_feature, - priority: issue_priority) - } + project: project, + status: status1, + type: type_feature, + priority: issue_priority) + end let(:project) do unless @project @project = FactoryBot.build(:project) @project.members = [FactoryBot.build(:member, principal: user, - project: @project, - roles: [role])] + project: @project, + roles: [role])] end @project end @@ -75,10 +75,10 @@ describe Story, type: :model do ActionController::Base.perform_caching = false allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [type_feature.id.to_s], - 'task_type' => task_type.id.to_s }) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [type_feature.id.to_s], + 'task_type' => task_type.id.to_s }) project.types << task_type end diff --git a/modules/backlogs/spec/models/task_spec.rb b/modules/backlogs/spec/models/task_spec.rb index 72a84b286d..3fbbe8f3d0 100644 --- a/modules/backlogs/spec/models/task_spec.rb +++ b/modules/backlogs/spec/models/task_spec.rb @@ -32,12 +32,12 @@ describe Task, type: :model do let(:task_type) { FactoryBot.create(:type) } let(:default_status) { FactoryBot.create(:default_status) } let(:project) { FactoryBot.create(:project) } - let(:task) { + let(:task) do FactoryBot.build(:task, project: project, status: default_status, type: task_type) - } + end before(:each) do allow(Setting) diff --git a/modules/backlogs/spec/models/version_spec.rb b/modules/backlogs/spec/models/version_spec.rb index 68e8191665..36fc0261b2 100644 --- a/modules/backlogs/spec/models/version_spec.rb +++ b/modules/backlogs/spec/models/version_spec.rb @@ -34,16 +34,16 @@ describe Version, type: :model do describe 'rebuild positions' do def build_work_package(options = {}) FactoryBot.build(:work_package, options.reverse_merge(version_id: version.id, - priority_id: priority.id, - project_id: project.id, - status_id: status.id)) + priority_id: priority.id, + project_id: project.id, + status_id: status.id)) end def create_work_package(options = {}) build_work_package(options).tap(&:save!) end - let(:status) { FactoryBot.create(:status) } + let(:status) { FactoryBot.create(:status) } let(:priority) { FactoryBot.create(:priority_normal) } let(:project) { FactoryBot.create(:project, name: 'Project 1', types: [epic_type, story_type, task_type, other_type]) } @@ -76,7 +76,8 @@ describe Version, type: :model do # Enable and configure backlogs project.enabled_module_names = project.enabled_module_names + ['backlogs'] - allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [epic_type.id, story_type.id], 'task_type' => task_type.id }) + allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [epic_type.id, story_type.id], + 'task_type' => task_type.id }) # Otherwise the type id's from the previous test are still active WorkPackage.instance_variable_set(:@backlogs_types, nil) @@ -92,8 +93,10 @@ describe Version, type: :model do project2.reload work_package1 = FactoryBot.create(:work_package, type_id: task_type.id, status_id: status.id, project_id: project.id) - work_package2 = FactoryBot.create(:work_package, parent_id: work_package1.id, type_id: task_type.id, status_id: status.id, project_id: project.id) - work_package3 = FactoryBot.create(:work_package, parent_id: work_package2.id, type_id: task_type.id, status_id: status.id, project_id: project.id) + work_package2 = FactoryBot.create(:work_package, parent_id: work_package1.id, type_id: task_type.id, status_id: status.id, + project_id: project.id) + work_package3 = FactoryBot.create(:work_package, parent_id: work_package2.id, type_id: task_type.id, status_id: status.id, + project_id: project.id) work_package1.reload work_package1.version_id = version.id diff --git a/modules/backlogs/spec/models/work_package_export_spec.rb b/modules/backlogs/spec/models/work_package_export_spec.rb index ec152d88f1..5732963dda 100644 --- a/modules/backlogs/spec/models/work_package_export_spec.rb +++ b/modules/backlogs/spec/models/work_package_export_spec.rb @@ -28,9 +28,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe WorkPackage::Exporter::PDF, type: :model do +describe WorkPackage::Exporter::PDF, type: :model do let(:project) { FactoryBot.create :project } - let(:query) { Query.new_default(name: '_', project: project)} + let(:query) { Query.new_default(name: '_', project: project) } subject { described_class.new query } before do diff --git a/modules/backlogs/spec/services/impediments/create_services_spec.rb b/modules/backlogs/spec/services/impediments/create_services_spec.rb index 6228c0fe0d..1e4b15dca0 100644 --- a/modules/backlogs/spec/services/impediments/create_services_spec.rb +++ b/modules/backlogs/spec/services/impediments/create_services_spec.rb @@ -135,7 +135,11 @@ describe Impediments::CreateService do it_should_behave_like 'impediment creation with no blocking relationship' it { expect(subject).to be_new_record } - it { expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, scope: [:activerecord, :errors, :models, :work_package, :attributes, :blocks_ids]) } + it { + expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, + scope: %i[activerecord errors models work_package attributes + blocks_ids]) + } end describe 'WITH the story being non existent' do @@ -152,7 +156,11 @@ describe Impediments::CreateService do it_should_behave_like 'impediment creation with no blocking relationship' it { expect(subject).to be_new_record } - it { expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, scope: [:activerecord, :errors, :models, :work_package, :attributes, :blocks_ids]) } + it { + expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, + scope: %i[activerecord errors models work_package attributes + blocks_ids]) + } end end @@ -170,6 +178,10 @@ describe Impediments::CreateService do it_should_behave_like 'impediment creation with no blocking relationship' it { expect(subject).to be_new_record } - it { expect(subject.errors[:blocks_ids]).to include I18n.t(:must_block_at_least_one_work_package, scope: [:activerecord, :errors, :models, :work_package, :attributes, :blocks_ids]) } + it { + expect(subject.errors[:blocks_ids]).to include I18n.t(:must_block_at_least_one_work_package, + scope: %i[activerecord errors models work_package attributes + blocks_ids]) + } end end diff --git a/modules/backlogs/spec/services/impediments/update_service_spec.rb b/modules/backlogs/spec/services/impediments/update_service_spec.rb index fc044c3bf7..2158bf3904 100644 --- a/modules/backlogs/spec/services/impediments/update_service_spec.rb +++ b/modules/backlogs/spec/services/impediments/update_service_spec.rb @@ -36,55 +36,55 @@ describe Impediments::UpdateService, type: :model do let(:type_feature) { FactoryBot.create(:type_feature) } let(:type_task) { FactoryBot.create(:type_task) } let(:priority) { impediment.priority } - let(:task) { + let(:task) do FactoryBot.build(:task, type: type_task, - project: project, - author: user, - priority: priority, - status: status1) - } - let(:feature) { + project: project, + author: user, + priority: priority, + status: status1) + end + let(:feature) do FactoryBot.build(:work_package, type: type_feature, - project: project, - author: user, - priority: priority, - status: status1) - } + project: project, + author: user, + priority: priority, + status: status1) + end let(:version) { FactoryBot.create(:version, project: project) } let(:project) do project = FactoryBot.create(:project, types: [type_feature, type_task]) FactoryBot.create(:member, principal: user, - project: project, - roles: [role]) + project: project, + roles: [role]) project end let(:status1) { FactoryBot.create(:status, name: 'status 1', is_default: true) } let(:status2) { FactoryBot.create(:status, name: 'status 2') } - let(:type_workflow) { + let(:type_workflow) do Workflow.create(type_id: type_task.id, old_status: status1, new_status: status2, role: role) - } + end let(:impediment) do FactoryBot.build(:impediment, author: user, - version: version, - assigned_to: user, - project: project, - type: type_task, - status: status1) + version: version, + assigned_to: user, + project: project, + type: type_task, + status: status1) end before(:each) do allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [type_feature.id.to_s], - 'task_type' => type_task.id.to_s }) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [type_feature.id.to_s], + 'task_type' => type_task.id.to_s }) login_as user @@ -135,15 +135,15 @@ describe Impediments::UpdateService, type: :model do describe 'WHEN changing the blocking relationship to another story' do let(:story) do FactoryBot.build(:work_package, - subject: 'another story', - type: type_feature, - project: project, - author: user, - priority: priority, - status: status1) + subject: 'another story', + type: type_feature, + project: project, + author: user, + priority: priority, + status: status1) end let(:blocks) { story.id.to_s } - let(:story_version) { version } + let(:story_version) { version } before(:each) do story.version = story_version @@ -162,7 +162,11 @@ describe Impediments::UpdateService, type: :model do it 'should not be saved successfully' do expect(subject).to be_changed end - it { expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, scope: [:activerecord, :errors, :models, :work_package, :attributes, :blocks_ids]) } + it { + expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, + scope: %i[activerecord errors models work_package attributes + blocks_ids]) + } end describe 'WITH the story being non existent' do @@ -172,7 +176,11 @@ describe Impediments::UpdateService, type: :model do it 'should not be saved successfully' do expect(subject).to be_changed end - it { expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, scope: [:activerecord, :errors, :models, :work_package, :attributes, :blocks_ids]) } + it { + expect(subject.errors[:blocks_ids]).to include I18n.t(:can_only_contain_work_packages_of_current_sprint, + scope: %i[activerecord errors models work_package attributes + blocks_ids]) + } end end @@ -184,6 +192,10 @@ describe Impediments::UpdateService, type: :model do expect(subject).to be_changed end - it { expect(subject.errors[:blocks_ids]).to include I18n.t(:must_block_at_least_one_work_package, scope: [:activerecord, :errors, :models, :work_package, :attributes, :blocks_ids]) } + it { + expect(subject.errors[:blocks_ids]).to include I18n.t(:must_block_at_least_one_work_package, + scope: %i[activerecord errors models work_package attributes + blocks_ids]) + } end end diff --git a/modules/backlogs/spec/services/work_packages/update_ancestors_service_spec.rb b/modules/backlogs/spec/services/work_packages/update_ancestors_service_spec.rb index 33bb523e50..61bc530f79 100644 --- a/modules/backlogs/spec/services/work_packages/update_ancestors_service_spec.rb +++ b/modules/backlogs/spec/services/work_packages/update_ancestors_service_spec.rb @@ -39,19 +39,19 @@ describe WorkPackages::UpdateAncestorsService do end let!(:parent) do FactoryBot.create :work_package, - parent: grandparent + parent: grandparent end let!(:sibling) do FactoryBot.create :work_package, - parent: parent, - remaining_hours: sibling_remaining_hours + parent: parent, + remaining_hours: sibling_remaining_hours end context 'for a new ancestors' do let!(:work_package) do FactoryBot.create :work_package, - remaining_hours: work_package_remaining_hours, - parent: parent + remaining_hours: work_package_remaining_hours, + parent: parent end subject do diff --git a/modules/backlogs/spec/services/work_packages/update_service_version_inheritance_spec.rb b/modules/backlogs/spec/services/work_packages/update_service_version_inheritance_spec.rb index 20d7f30e4e..288d85eed3 100644 --- a/modules/backlogs/spec/services/work_packages/update_service_version_inheritance_spec.rb +++ b/modules/backlogs/spec/services/work_packages/update_service_version_inheritance_spec.rb @@ -1,5 +1,3 @@ - - #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -90,7 +88,7 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do story end - let(:task) { + let(:task) do FactoryBot.build(:work_package, subject: 'Task', type: type_task, @@ -99,9 +97,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:task2) { + let(:task2) do FactoryBot.build(:work_package, subject: 'Task2', type: type_task, @@ -110,9 +108,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:task3) { + let(:task3) do FactoryBot.build(:work_package, subject: 'Task3', type: type_task, @@ -121,9 +119,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:task4) { + let(:task4) do FactoryBot.build(:work_package, subject: 'Task4', type: type_task, @@ -132,9 +130,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:task5) { + let(:task5) do FactoryBot.build(:work_package, subject: 'Task5', type: type_task, @@ -143,9 +141,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:task6) { + let(:task6) do FactoryBot.build(:work_package, subject: 'Task6', type: type_task, @@ -154,9 +152,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:bug) { + let(:bug) do FactoryBot.build(:work_package, subject: 'Bug', type: type_bug, @@ -165,9 +163,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:bug2) { + let(:bug2) do FactoryBot.build(:work_package, subject: 'Bug2', type: type_bug, @@ -176,9 +174,9 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end - let(:bug3) { + let(:bug3) do FactoryBot.build(:work_package, subject: 'Bug3', type: type_bug, @@ -187,16 +185,16 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do status: status, author: user, priority: issue_priority) - } + end before(:each) do project.save! allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'points_burn_direction' => 'down', - 'wiki_template' => '', - 'card_spec' => 'Sattleford VM-5040', - 'story_types' => [type_feature.id], - 'task_type' => type_task.id.to_s }) + 'wiki_template' => '', + 'card_spec' => 'Sattleford VM-5040', + 'story_types' => [type_feature.id], + 'task_type' => type_task.id.to_s }) end def standard_child_layout @@ -392,7 +390,7 @@ describe WorkPackages::UpdateService, "version inheritance", type: :model do end describe 'WITH a task (impediment) without a parent' do - let(:parent) { task} + let(:parent) { task } describe 'WITH a task as child' do let(:child) { task2 } diff --git a/modules/backlogs/spec/support/pages/backlogs.rb b/modules/backlogs/spec/support/pages/backlogs.rb index 88d43a2366..9f8116fa4e 100644 --- a/modules/backlogs/spec/support/pages/backlogs.rb +++ b/modules/backlogs/spec/support/pages/backlogs.rb @@ -50,7 +50,7 @@ module Pages end def alter_attributes_in_edit_story_mode(story, attributes) - edit_proc = ->() do + edit_proc = -> do attributes.each do |key, value| case key when :subject @@ -92,7 +92,7 @@ module Pages end def save_story_from_edit_mode(story) - save_proc = -> () do + save_proc = -> do find('input[name=subject]').native.send_key :return expect(page) @@ -186,14 +186,14 @@ module Pages def expect_story_in_sprint(story, sprint) within_backlog(sprint) do expect(page) - .to have_selector("#{story_selector(story)}") + .to have_selector(story_selector(story).to_s) end end def expect_story_not_in_sprint(story, sprint) within_backlog(sprint) do expect(page) - .not_to have_selector("#{story_selector(story)}") + .not_to have_selector(story_selector(story).to_s) end end @@ -226,7 +226,7 @@ module Pages def expect_status_options(story, statuses) within_story(story) do - expect(all('.status_id option').map { |n| n.text.strip } ) + expect(all('.status_id option').map { |n| n.text.strip }) .to match_array(statuses.map(&:name)) end end diff --git a/modules/backlogs/spec/views/rb_burndown_charts/show_spec.rb b/modules/backlogs/spec/views/rb_burndown_charts/show_spec.rb index 5bf01055b1..61be52ab39 100644 --- a/modules/backlogs/spec/views/rb_burndown_charts/show_spec.rb +++ b/modules/backlogs/spec/views/rb_burndown_charts/show_spec.rb @@ -31,17 +31,17 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe 'rb_burndown_charts/show', type: :view do let(:user1) { FactoryBot.create(:user) } let(:user2) { FactoryBot.create(:user) } - let(:role_allowed) { + let(:role_allowed) do FactoryBot.create(:role, - permissions: [:add_work_packages, :manage_subtasks]) - } + permissions: %i[add_work_packages manage_subtasks]) + end let(:role_forbidden) { FactoryBot.create(:role) } # We need to create these as some view helpers access the database - let(:statuses) { + let(:statuses) do [FactoryBot.create(:status), FactoryBot.create(:status), FactoryBot.create(:status)] - } + end let(:type_task) { FactoryBot.create(:type_task) } let(:type_feature) { FactoryBot.create(:type_feature) } @@ -53,32 +53,31 @@ describe 'rb_burndown_charts/show', type: :view do project end - let(:story_a) { + let(:story_a) do FactoryBot.create(:story, status: statuses[0], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } - let(:story_b) { + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end + let(:story_b) do FactoryBot.create(:story, status: statuses[1], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } - let(:story_c) { + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end + let(:story_c) do FactoryBot.create(:story, status: statuses[2], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end let(:stories) { [story_a, story_b, story_c] } - let(:sprint) { FactoryBot.create(:sprint, project: project, start_date: Date.today - 1.week, effective_date: Date.today + 1.week) } + let(:sprint) do + FactoryBot.create(:sprint, project: project, start_date: Date.today - 1.week, effective_date: Date.today + 1.week) + end let(:task) do task = FactoryBot.create(:task, project: project, status: statuses[0], version: sprint, type: type_task) # This is necessary as for some unknown reason passing the parent directly @@ -89,7 +88,8 @@ describe 'rb_burndown_charts/show', type: :view do end before :each do - allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [type_feature.id], 'task_type' => type_task.id }) + allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [type_feature.id], + 'task_type' => type_task.id }) view.extend BurndownChartsHelper # We directly force the creation of stories,statuses by calling the method @@ -117,7 +117,7 @@ describe 'rb_burndown_charts/show', type: :view do render expect(view).to render_template(partial: '_burndown', count: 0) - expect(rendered).to include(I18n.translate 'backlogs.no_burndown_data') + expect(rendered).to include(I18n.translate('backlogs.no_burndown_data')) end end end diff --git a/modules/backlogs/spec/views/rb_master_backlogs/index.html.erb_spec.rb b/modules/backlogs/spec/views/rb_master_backlogs/index.html.erb_spec.rb index 072d552ea7..e349d66928 100644 --- a/modules/backlogs/spec/views/rb_master_backlogs/index.html.erb_spec.rb +++ b/modules/backlogs/spec/views/rb_master_backlogs/index.html.erb_spec.rb @@ -30,15 +30,15 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe 'rb_master_backlogs/index', type: :view do let(:user) { FactoryBot.create(:user) } - let(:role_allowed) { + let(:role_allowed) do FactoryBot.create(:role, - permissions: [:view_master_backlog, :view_taskboards]) - } - let(:statuses) { + permissions: %i[view_master_backlog view_taskboards]) + end + let(:statuses) do [FactoryBot.create(:status, is_default: true), FactoryBot.create(:status), FactoryBot.create(:status)] - } + end let(:type_task) { FactoryBot.create(:type_task) } let(:type_feature) { FactoryBot.create(:type_feature) } let(:issue_priority) { FactoryBot.create(:priority) } @@ -47,35 +47,33 @@ describe 'rb_master_backlogs/index', type: :view do project.members = [FactoryBot.create(:member, principal: user, project: project, roles: [role_allowed])] project end - let(:story_a) { + let(:story_a) do FactoryBot.create(:story, status: statuses[0], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } - let(:story_b) { + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end + let(:story_b) do FactoryBot.create(:story, status: statuses[1], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } - let(:story_c) { + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end + let(:story_c) do FactoryBot.create(:story, status: statuses[2], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end let(:stories) { [story_a, story_b, story_c] } - let(:sprint) { FactoryBot.create(:sprint, project: project) } + let(:sprint) { FactoryBot.create(:sprint, project: project) } before :each do - allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [type_feature.id], 'task_type' => type_task.id }) + allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [type_feature.id], + 'task_type' => type_task.id }) view.extend RbCommonHelper view.extend RbMasterBacklogsHelper allow(view).to receive(:current_user).and_return(user) @@ -95,12 +93,14 @@ describe 'rb_master_backlogs/index', type: :view do default_export_card_config = FactoryBot.create(:export_card_configuration) assign(:export_card_config_meta, { default: default_export_card_config, - count: 1 }) + count: 1 + }) render assert_select '.menu ul.items a' do |a| - url = backlogs_project_sprint_export_card_configuration_path(project.identifier, sprint.id, default_export_card_config.id, format: :pdf) + url = backlogs_project_sprint_export_card_configuration_path(project.identifier, sprint.id, default_export_card_config.id, + format: :pdf) expect(a.last).to have_content 'Export' expect(a.last).to have_css("a[href='#{url}']") end diff --git a/modules/backlogs/spec/views/rb_taskboards/show_spec.rb b/modules/backlogs/spec/views/rb_taskboards/show_spec.rb index 89274c891c..39d3aa0dbf 100644 --- a/modules/backlogs/spec/views/rb_taskboards/show_spec.rb +++ b/modules/backlogs/spec/views/rb_taskboards/show_spec.rb @@ -31,17 +31,17 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe 'rb_taskboards/show', type: :view do let(:user1) { FactoryBot.create(:user) } let(:user2) { FactoryBot.create(:user) } - let(:role_allowed) { + let(:role_allowed) do FactoryBot.create(:role, - permissions: [:add_work_packages, :edit_work_packages, :manage_subtasks]) - } + permissions: %i[add_work_packages edit_work_packages manage_subtasks]) + end let(:role_forbidden) { FactoryBot.create(:role) } # We need to create these as some view helpers access the database - let(:statuses) { + let(:statuses) do [FactoryBot.create(:status), FactoryBot.create(:status), FactoryBot.create(:status)] - } + end let(:type_task) { FactoryBot.create(:type_task) } let(:type_feature) { FactoryBot.create(:type_feature) } @@ -53,32 +53,29 @@ describe 'rb_taskboards/show', type: :view do project end - let(:story_a) { + let(:story_a) do FactoryBot.create(:story, status: statuses[0], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } - let(:story_b) { + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end + let(:story_b) do FactoryBot.create(:story, status: statuses[1], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } - let(:story_c) { + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end + let(:story_c) do FactoryBot.create(:story, status: statuses[2], - project: project, - type: type_feature, - version: sprint, - priority: issue_priority - ) - } + project: project, + type: type_feature, + version: sprint, + priority: issue_priority) + end let(:stories) { [story_a, story_b, story_c] } - let(:sprint) { FactoryBot.create(:sprint, project: project) } + let(:sprint) { FactoryBot.create(:sprint, project: project) } let(:task) do task = FactoryBot.create(:task, project: project, status: statuses[0], version: sprint, type: type_task) # This is necessary as for some unknown reason passing the parent directly @@ -87,10 +84,14 @@ describe 'rb_taskboards/show', type: :view do task.parent_id = story_a.id task end - let(:impediment) { FactoryBot.create(:impediment, project: project, status: statuses[0], version: sprint, blocks_ids: task.id.to_s, type: type_task) } + let(:impediment) do + FactoryBot.create(:impediment, project: project, status: statuses[0], version: sprint, blocks_ids: task.id.to_s, + type: type_task) + end before :each do - allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [type_feature.id], 'task_type' => type_task.id }) + allow(Setting).to receive(:plugin_openproject_backlogs).and_return({ 'story_types' => [type_feature.id], + 'task_type' => type_task.id }) view.extend RbCommonHelper view.extend TaskboardsHelper diff --git a/modules/bim/app/cells/bim/ifc_models/table_cell.rb b/modules/bim/app/cells/bim/ifc_models/table_cell.rb index 35c4f7fc6f..e22ae29555 100644 --- a/modules/bim/app/cells/bim/ifc_models/table_cell.rb +++ b/modules/bim/app/cells/bim/ifc_models/table_cell.rb @@ -26,12 +26,12 @@ module Bim def headers [ - ['title', caption: IfcModel.human_attribute_name(:title)], - ['is_default', caption: IfcModel.human_attribute_name(:is_default)], - ['created_at', caption: IfcModel.human_attribute_name(:created_at)], - ['updated_at', caption: IfcModel.human_attribute_name(:updated_at)], - ['uploader', caption: IfcModel.human_attribute_name(:uploader)], - ['processing', caption: I18n.t('ifc_models.processing_state.label')] + ['title', { caption: IfcModel.human_attribute_name(:title) }], + ['is_default', { caption: IfcModel.human_attribute_name(:is_default) }], + ['created_at', { caption: IfcModel.human_attribute_name(:created_at) }], + ['updated_at', { caption: IfcModel.human_attribute_name(:updated_at) }], + ['uploader', { caption: IfcModel.human_attribute_name(:uploader) }], + ['processing', { caption: I18n.t('ifc_models.processing_state.label') }] ] end end diff --git a/modules/bim/app/controllers/bim/bcf/api/v2_1/current_user_api.rb b/modules/bim/app/controllers/bim/bcf/api/v2_1/current_user_api.rb index 0938abf5ee..bab04e13a4 100644 --- a/modules/bim/app/controllers/bim/bcf/api/v2_1/current_user_api.rb +++ b/modules/bim/app/controllers/bim/bcf/api/v2_1/current_user_api.rb @@ -32,7 +32,7 @@ module Bim::Bcf::API::V2_1 class CurrentUserAPI < ::API::OpenProjectAPI resources :'current-user' do get &::Bim::Bcf::API::V2_1::Endpoints::Show.new(model: User, - instance_generator: ->(*) { current_user }).mount + instance_generator: ->(*) { current_user }).mount end end end diff --git a/modules/bim/app/controllers/bim/bcf/api/v2_1/projects_api.rb b/modules/bim/app/controllers/bim/bcf/api/v2_1/projects_api.rb index 60bf269d1a..fafd29367a 100644 --- a/modules/bim/app/controllers/bim/bcf/api/v2_1/projects_api.rb +++ b/modules/bim/app/controllers/bim/bcf/api/v2_1/projects_api.rb @@ -40,7 +40,7 @@ module Bim::Bcf::API::V2_1 end get &::Bim::Bcf::API::V2_1::Endpoints::Index.new(model: Project, - scope: -> { visible_projects }) + scope: -> { visible_projects }) .mount route_param :id, regexp: /\A(\d+)\z/ do diff --git a/modules/bim/app/controllers/bim/bcf/issues_controller.rb b/modules/bim/app/controllers/bim/bcf/issues_controller.rb index f3c664f4fe..9ed76963e8 100644 --- a/modules/bim/app/controllers/bim/bcf/issues_controller.rb +++ b/modules/bim/app/controllers/bim/bcf/issues_controller.rb @@ -46,8 +46,7 @@ module Bim menu_item :ifc_models - def upload; - end + def upload; end def index redirect_to action: :upload @@ -98,10 +97,10 @@ module Bim def import_canceled? if %i[unknown_types_action - unknown_statuses_action - invalid_people_action - unknown_mails_action - non_members_action].map { |key| params.dig(:import_options, key) }.include? 'cancel' + unknown_statuses_action + invalid_people_action + unknown_mails_action + non_members_action].map { |key| params.dig(:import_options, key) }.include? 'cancel' flash[:notice] = I18n.t('bcf.bcf_xml.import_canceled') redirect_to_bcf_issues_list end @@ -225,7 +224,9 @@ module Bim def check_bcf_version unless @importer.bcf_version_valid? - flash[:error] = I18n.t('bcf.bcf_xml.import_failed_unsupported_bcf_version', minimal_version: OpenProject::Bim::BcfXml::Importer::MINIMUM_BCF_VERSION) + flash[:error] = + I18n.t('bcf.bcf_xml.import_failed_unsupported_bcf_version', + minimal_version: OpenProject::Bim::BcfXml::Importer::MINIMUM_BCF_VERSION) redirect_to action: :upload end end diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb index 9e8a21fc47..511d9f4cac 100644 --- a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb +++ b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb @@ -33,13 +33,14 @@ module Bim class IfcModelsController < BaseController helper_method :gon - before_action :find_project_by_project_id, only: %i[index new create show defaults edit update destroy direct_upload_finished] + before_action :find_project_by_project_id, + only: %i[index new create show defaults edit update destroy direct_upload_finished] before_action :find_ifc_model_object, only: %i[edit update destroy] before_action :find_all_ifc_models, only: %i[show defaults index] # Callback done by AWS so can't be authenticated. Don't have to be either, though. # It only actually does anything if there is a pending upload with the key passed by AWS. - before_action :authorize, except: [:direct_upload_finished, :set_direct_upload_file_name] + before_action :authorize, except: %i[direct_upload_finished set_direct_upload_file_name] before_action :require_login, only: [:set_direct_upload_file_name] skip_before_action :verify_authenticity_token, only: [:set_direct_upload_file_name] # AJAX request in page, so skip authenticity token diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_viewer_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_viewer_controller.rb index 0dcbcc5ad7..e5a8b6b1bb 100644 --- a/modules/bim/app/controllers/bim/ifc_models/ifc_viewer_controller.rb +++ b/modules/bim/app/controllers/bim/ifc_models/ifc_viewer_controller.rb @@ -41,7 +41,6 @@ module Bim menu_item :ifc_models - def show; end private diff --git a/modules/bim/app/helpers/bcf_application_helper.rb b/modules/bim/app/helpers/bcf_application_helper.rb index 32e1017014..92e1d86539 100644 --- a/modules/bim/app/helpers/bcf_application_helper.rb +++ b/modules/bim/app/helpers/bcf_application_helper.rb @@ -29,8 +29,6 @@ module BcfApplicationHelper def body_css_classes classes = super - classes = classes + " bcf-#{@project&.module_enabled?(:bim) ? 'activated' : 'deactivated'}" - - classes + classes + " bcf-#{@project&.module_enabled?(:bim) ? 'activated' : 'deactivated'}" end end diff --git a/modules/bim/app/helpers/ifc_models_helper.rb b/modules/bim/app/helpers/ifc_models_helper.rb index 64f5b7201f..f95c07f371 100644 --- a/modules/bim/app/helpers/ifc_models_helper.rb +++ b/modules/bim/app/helpers/ifc_models_helper.rb @@ -5,12 +5,12 @@ module IfcModelsHelper gon.ifc_models = { models: gon_ifc_model_models(all_converted_models), shown_models: gon_ifc_shown_models(all_converted_models, shown_models), - projects: [{id: @project.identifier, name: @project.name}], + projects: [{ id: @project.identifier, name: @project.name }], xkt_attachment_ids: gon_ifc_model_xkt_attachment_ids(all_converted_models), metadata_attachment_ids: gon_ifc_model_metadata_attachment_ids(all_converted_models), permissions: { manage_ifc_models: User.current.allowed_to?(:manage_ifc_models, @project), - manage_bcf: User.current.allowed_to?(:manage_bcf, @project), + manage_bcf: User.current.allowed_to?(:manage_bcf, @project) } } end diff --git a/modules/bim/app/models/bim/ifc_models/ifc_model.rb b/modules/bim/app/models/bim/ifc_models/ifc_model.rb index cdb30ced64..470b40c01c 100644 --- a/modules/bim/app/models/bim/ifc_models/ifc_model.rb +++ b/modules/bim/app/models/bim/ifc_models/ifc_model.rb @@ -24,7 +24,7 @@ module Bim end delete_attachment name - attach_files('first' => {'file' => file, 'description' => name}) + attach_files('first' => { 'file' => file, 'description' => name }) end end diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb index bafba7c457..9a7c8f1f7d 100644 --- a/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb +++ b/modules/bim/app/representers/bim/bcf/api/v2_1/viewpoints/base_representer.rb @@ -36,7 +36,7 @@ module Bim::Bcf::API::V2_1 @base_scope = base_scope end - def to_json + def to_json(*_args) row = scope.first raise ::ActiveRecord::RecordNotFound unless row diff --git a/modules/bim/app/seeders/bim/basic_data/priority_seeder.rb b/modules/bim/app/seeders/bim/basic_data/priority_seeder.rb index 0a084ccc0c..b98eea765b 100644 --- a/modules/bim/app/seeders/bim/basic_data/priority_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/priority_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -34,7 +35,7 @@ module Bim 'cyan-1', # low 'blue-3', # normal 'yellow-7', # high - 'grape-5', # critical + 'grape-5' # critical ] # When selecting for an array of values, implicit order is applied @@ -44,7 +45,7 @@ module Bim [ { name: I18n.t(:default_priority_low), color_id: colors[0], position: 1, is_default: true }, - { name: I18n.t(:default_priority_normal), color_id: colors[1], position: 2, is_default: false }, + { name: I18n.t(:default_priority_normal), color_id: colors[1], position: 2, is_default: false }, { name: I18n.t(:default_priority_high), color_id: colors[2], position: 3, is_default: false }, { name: I18n.t('seeders.bim.default_priority_critical'), color_id: colors[3], position: 4, is_default: false } ] diff --git a/modules/bim/app/seeders/bim/basic_data/role_seeder.rb b/modules/bim/app/seeders/bim/basic_data/role_seeder.rb index c5b3b5c480..5c39ba44a6 100644 --- a/modules/bim/app/seeders/bim/basic_data/role_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/role_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,6 @@ module Bim module BasicData class RoleSeeder < ::BasicData::RoleSeeder - def member super.tap do |role_data| role_data[:permissions] += %i[view_linked_issues manage_bcf delete_work_packages manage_ifc_models view_ifc_models] diff --git a/modules/bim/app/seeders/bim/basic_data/setting_seeder.rb b/modules/bim/app/seeders/bim/basic_data/setting_seeder.rb index 9a5f5211bf..c9c4f1de84 100644 --- a/modules/bim/app/seeders/bim/basic_data/setting_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/setting_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/bim/app/seeders/bim/basic_data/status_seeder.rb b/modules/bim/app/seeders/bim/basic_data/status_seeder.rb index 4bbbc6d4d9..216842ed3a 100644 --- a/modules/bim/app/seeders/bim/basic_data/status_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/status_seeder.rb @@ -44,10 +44,14 @@ module Bim colors = color_names.collect { |name| colors_by_name[name].id } [ - { name: I18n.t(:default_status_new), color_id: colors[0], is_closed: false, is_default: true, position: 1 }, - { name: I18n.t(:default_status_in_progress), color_id: colors[1], is_closed: false, is_default: false, position: 2 }, - { name: I18n.t('seeders.bim.default_status_resolved'), color_id: colors[2], is_closed: false, is_default: false, position: 3 }, - { name: I18n.t(:default_status_closed), color_id: colors[3], is_closed: true, is_default: false, position: 4 }, + { name: I18n.t(:default_status_new), color_id: colors[0], is_closed: false, is_default: true, + position: 1 }, + { name: I18n.t(:default_status_in_progress), color_id: colors[1], is_closed: false, is_default: false, + position: 2 }, + { name: I18n.t('seeders.bim.default_status_resolved'), color_id: colors[2], is_closed: false, + is_default: false, position: 3 }, + { name: I18n.t(:default_status_closed), color_id: colors[3], is_closed: true, is_default: false, + position: 4 } ] end end diff --git a/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb b/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb index abb3b84afc..d9ad0f4490 100644 --- a/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/theme_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,7 +31,9 @@ module Bim module BasicData class ThemeSeeder < Seeder def seed_data! - theme = OpenProject::CustomStyles::ColorThemes.themes.find { |t| t[:theme] == OpenProject::CustomStyles::ColorThemes::BIM_THEME_NAME } + theme = OpenProject::CustomStyles::ColorThemes.themes.find do |t| + t[:theme] == OpenProject::CustomStyles::ColorThemes::BIM_THEME_NAME + end ::Design::UpdateDesignService .new(theme) diff --git a/modules/bim/app/seeders/bim/basic_data/type_seeder.rb b/modules/bim/app/seeders/bim/basic_data/type_seeder.rb index 5a645dd060..5a0f9cc5b8 100644 --- a/modules/bim/app/seeders/bim/basic_data/type_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/type_seeder.rb @@ -30,12 +30,10 @@ module Bim module BasicData class TypeSeeder < ::BasicData::TypeSeeder - def type_names %i[task milestone phase clash issue remark request] end - def type_table color_names = [ 'blue-6', @@ -51,13 +49,13 @@ module Bim colors = color_names.collect { |name| colors_by_name[name].id } { # position is_default color_id is_in_roadmap is_milestone - task: [1, true, colors[0], true, false, :default_type_task], - milestone: [2, true, colors[2], false, true, :default_type_milestone], - phase: [3, true, I18n.t(:default_color_gray), false, false, :default_type_phase], - issue: [4, true, colors[1], true, false, 'seeders.bim.default_type_issue'], - remark: [5, true, I18n.t(:default_color_green_dark), true, false, 'seeders.bim.default_type_remark'], - request: [6, true, colors[3], true, false, 'seeders.bim.default_type_request'], - clash: [7, true, colors[4], true, false, 'seeders.bim.default_type_clash'] + task: [1, true, colors[0], true, false, :default_type_task], + milestone: [2, true, colors[2], false, true, :default_type_milestone], + phase: [3, true, I18n.t(:default_color_gray), false, false, :default_type_phase], + issue: [4, true, colors[1], true, false, 'seeders.bim.default_type_issue'], + remark: [5, true, I18n.t(:default_color_green_dark), true, false, 'seeders.bim.default_type_remark'], + request: [6, true, colors[3], true, false, 'seeders.bim.default_type_request'], + clash: [7, true, colors[4], true, false, 'seeders.bim.default_type_clash'] } end end diff --git a/modules/bim/app/seeders/bim/basic_data/workflow_seeder.rb b/modules/bim/app/seeders/bim/basic_data/workflow_seeder.rb index 9928eb5f33..29c7c96663 100644 --- a/modules/bim/app/seeders/bim/basic_data/workflow_seeder.rb +++ b/modules/bim/app/seeders/bim/basic_data/workflow_seeder.rb @@ -40,13 +40,13 @@ module Bim resolved = Status.find_by(name: I18n.t('seeders.bim.default_status_resolved')) { - types[I18n.t(:default_type_task)] => [new, in_progress, closed], - types[I18n.t(:default_type_milestone)] => [new, in_progress, closed], - types[I18n.t(:default_type_phase)] => [new, in_progress, closed], - types[I18n.t('seeders.bim.default_type_clash')] => [new, in_progress, resolved, closed], - types[I18n.t('seeders.bim.default_type_issue')] => [new, in_progress, resolved, closed], - types[I18n.t('seeders.bim.default_type_remark')] => [new, in_progress, resolved, closed], - types[I18n.t('seeders.bim.default_type_request')] => [new, in_progress, resolved, closed] + types[I18n.t(:default_type_task)] => [new, in_progress, closed], + types[I18n.t(:default_type_milestone)] => [new, in_progress, closed], + types[I18n.t(:default_type_phase)] => [new, in_progress, closed], + types[I18n.t('seeders.bim.default_type_clash')] => [new, in_progress, resolved, closed], + types[I18n.t('seeders.bim.default_type_issue')] => [new, in_progress, resolved, closed], + types[I18n.t('seeders.bim.default_type_remark')] => [new, in_progress, resolved, closed], + types[I18n.t('seeders.bim.default_type_request')] => [new, in_progress, resolved, closed] } end diff --git a/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb b/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb index 6dbf22b570..3314dbef12 100644 --- a/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb +++ b/modules/bim/app/seeders/bim/demo_data/bcf_xml_seeder.rb @@ -47,8 +47,8 @@ module Bim import_options = { invalid_people_action: 'anonymize', - unknown_mails_action: 'anonymize', - non_members_action: 'anonymize' + unknown_mails_action: 'anonymize', + non_members_action: 'anonymize' } bcf_xml_file = File.new(File.join(Rails.root, 'modules/bim/files', filename)) diff --git a/modules/bim/app/services/bim/bcf/issues/delete_service.rb b/modules/bim/app/services/bim/bcf/issues/delete_service.rb index 73457c9834..5755464895 100644 --- a/modules/bim/app/services/bim/bcf/issues/delete_service.rb +++ b/modules/bim/app/services/bim/bcf/issues/delete_service.rb @@ -56,4 +56,4 @@ module Bim::Bcf end end end -end \ No newline at end of file +end diff --git a/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb b/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb index f04126d9fa..55ba9aabf5 100644 --- a/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb +++ b/modules/bim/app/services/bim/bcf/issues/transform_attributes_service.rb @@ -127,7 +127,7 @@ module Bim::Bcf if import_options[:unknown_statuses_action] == 'use_default' ::Status.default elsif import_options[:unknown_statuses_action] == 'chose' && - import_options[:unknown_statuses_chose_ids].any? + import_options[:unknown_statuses_chose_ids].any? ::Status.find_by(id: import_options[:unknown_statuses_chose_ids].first) elsif status_name Status::InexistentStatus.new @@ -138,7 +138,7 @@ module Bim::Bcf if import_options[:unknown_priorities_action] == 'use_default' # NOP The 'use_default' case gets already covered by OP. elsif import_options[:unknown_priorities_action] == 'chose' && - import_options[:unknown_priorities_chose_ids].any? + import_options[:unknown_priorities_chose_ids].any? ::IssuePriority.find_by(id: import_options[:unknown_priorities_chose_ids].first) elsif priority_name Priority::InexistentPriority.new @@ -151,7 +151,7 @@ module Bim::Bcf if import_options[:unknown_types_action] == 'use_default' types.default&.first elsif import_options[:unknown_types_action] == 'chose' && - import_options[:unknown_types_chose_ids].any? + import_options[:unknown_types_chose_ids].any? types.find_by(id: import_options[:unknown_types_chose_ids].first) elsif type_name Type::InexistentType.new diff --git a/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb b/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb index 9a809377db..fd861246f6 100644 --- a/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb +++ b/modules/bim/app/services/bim/bcf/viewpoints/set_attributes_service.rb @@ -91,7 +91,7 @@ module Bim::Bcf end def snapshot_url_parts - snapshot_base_64.match(/\Adata:([-\w]+\/[-\w\+\.]+)?;base64,(.*)/m) || [] + snapshot_base_64.match(/\Adata:([-\w]+\/[-\w+.]+)?;base64,(.*)/m) || [] end end end diff --git a/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb b/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb index dab69dcb82..1cb8a7b10e 100644 --- a/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb +++ b/modules/bim/app/services/bim/ifc_models/set_attributes_service.rb @@ -75,7 +75,7 @@ module Bim model.attachments << ifc_attachment else - model.attach_files('first' => {'file' => ifc_attachment, 'description' => 'ifc'}) + model.attach_files('first' => { 'file' => ifc_attachment, 'description' => 'ifc' }) end end end diff --git a/modules/bim/config/routes.rb b/modules/bim/config/routes.rb index 970fd727de..f9b5644be2 100644 --- a/modules/bim/config/routes.rb +++ b/modules/bim/config/routes.rb @@ -38,7 +38,6 @@ OpenProject::Application.routes.draw do post :import, action: :perform_import, on: :collection end - # IFC viewer frontend get 'bcf(/*state)', to: 'bim/ifc_models/ifc_viewer#show', as: :frontend diff --git a/modules/bim/db/migrate/20191121140202_migrate_xml_viewpoint_to_json.rb b/modules/bim/db/migrate/20191121140202_migrate_xml_viewpoint_to_json.rb index f0438abb34..05cff533e1 100644 --- a/modules/bim/db/migrate/20191121140202_migrate_xml_viewpoint_to_json.rb +++ b/modules/bim/db/migrate/20191121140202_migrate_xml_viewpoint_to_json.rb @@ -14,7 +14,7 @@ class MigrateXmlViewpointToJson < ActiveRecord::Migration[6.0] resource.update_column(:json_viewpoint, mapper.result) Rails.logger.debug { "Converted viewpoint (##{resource.id}) #{resource.uuid} to JSON." } - rescue => e + rescue StandardError => e warn "Failed to convert viewpoint #{viewpoint.uuid}: #{e} #{e.message}" end diff --git a/modules/bim/db/migrate/20201105154216_seed_custom_style_with_bim_theme.rb b/modules/bim/db/migrate/20201105154216_seed_custom_style_with_bim_theme.rb index 209970bf0a..43a1ece4f9 100644 --- a/modules/bim/db/migrate/20201105154216_seed_custom_style_with_bim_theme.rb +++ b/modules/bim/db/migrate/20201105154216_seed_custom_style_with_bim_theme.rb @@ -31,7 +31,6 @@ # This migration cleans up messed up themes. Sometimes in the past # the BIM theme was not set where it should have been set. class SeedCustomStyleWithBimTheme < ActiveRecord::Migration[6.0] - def up # When # migrating BIM instances diff --git a/modules/bim/lib/open_project/bim/bcf_json/viewpoint_reader.rb b/modules/bim/lib/open_project/bim/bcf_json/viewpoint_reader.rb index d48f15bc6b..7a1025ee56 100644 --- a/modules/bim/lib/open_project/bim/bcf_json/viewpoint_reader.rb +++ b/modules/bim/lib/open_project/bim/bcf_json/viewpoint_reader.rb @@ -16,7 +16,7 @@ module OpenProject::Bim viewpoint_hash end - def to_json + def to_json(*_args) viewpoint_hash.to_json end diff --git a/modules/bim/lib/open_project/bim/bcf_xml/base_writer.rb b/modules/bim/lib/open_project/bim/bcf_xml/base_writer.rb index 3548cf02f1..5886370087 100644 --- a/modules/bim/lib/open_project/bim/bcf_xml/base_writer.rb +++ b/modules/bim/lib/open_project/bim/bcf_xml/base_writer.rb @@ -22,7 +22,7 @@ module OpenProject::Bim::BcfXml # Initial markup file as basic BCF compliant xml def build_markup_document Nokogiri::XML::Builder - .new(:encoding => 'UTF-8') do |xml| + .new(encoding: 'UTF-8') do |xml| xml.comment created_by_comment xml.send(root_node, "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", diff --git a/modules/bim/lib/open_project/bim/bcf_xml/importer.rb b/modules/bim/lib/open_project/bim/bcf_xml/importer.rb index 3a1b40c5af..05d1ebca38 100644 --- a/modules/bim/lib/open_project/bim/bcf_xml/importer.rb +++ b/modules/bim/lib/open_project/bim/bcf_xml/importer.rb @@ -83,10 +83,8 @@ module OpenProject::Bim::BcfXml end def treat_invalid_people(options) - if aggregations.invalid_people.any? - unless options[:invalid_people_action] == 'anonymize' - raise StandardError.new 'Invalid people found in import. Use valid email addresses.' - end + if aggregations.invalid_people.any? && !(options[:invalid_people_action] == 'anonymize') + raise StandardError.new 'Invalid people found in import. Use valid email addresses.' end end diff --git a/modules/bim/lib/open_project/bim/engine.rb b/modules/bim/lib/open_project/bim/engine.rb index 26f1818d60..f97178d116 100644 --- a/modules/bim/lib/open_project/bim/engine.rb +++ b/modules/bim/lib/open_project/bim/engine.rb @@ -187,7 +187,7 @@ module OpenProject::Bim initializer 'bim.bcf.register_hooks' do # don't use require_dependency to not reload hooks in development mode - require 'open_project/xls_export/hooks/work_package_hook.rb' + require 'open_project/xls_export/hooks/work_package_hook' end initializer 'bim.bcf.register_mimetypes' do diff --git a/modules/bim/lib/open_project/bim/patches/activities_shared_helpers_patch.rb b/modules/bim/lib/open_project/bim/patches/activities_shared_helpers_patch.rb index 2719a9aada..d522f2d80f 100644 --- a/modules/bim/lib/open_project/bim/patches/activities_shared_helpers_patch.rb +++ b/modules/bim/lib/open_project/bim/patches/activities_shared_helpers_patch.rb @@ -36,11 +36,11 @@ module OpenProject::Bim::Patches::ActivitiesSharedHelpersPatch ::Journal::AggregatedJournal .aggregated_journals(journable: @work_package, includes: %i[ - customizable_journals - attachable_journals - data - bcf_comment - ]) + customizable_journals + attachable_journals + data + bcf_comment + ]) end end end diff --git a/modules/bim/lib/open_project/bim/patches/aggregated_journal_patch.rb b/modules/bim/lib/open_project/bim/patches/aggregated_journal_patch.rb index b4f746b722..d0b52d3f92 100644 --- a/modules/bim/lib/open_project/bim/patches/aggregated_journal_patch.rb +++ b/modules/bim/lib/open_project/bim/patches/aggregated_journal_patch.rb @@ -59,7 +59,7 @@ module OpenProject::Bim::Patches::AggregatedJournalPatch module InstanceMethods def set_preloaded_bcf_comment(loaded_bcf_comment) - self.journal.bcf_comment = loaded_bcf_comment + journal.bcf_comment = loaded_bcf_comment journal.association(:bcf_comment).loaded! end end diff --git a/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb b/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb index ea311df10b..ec6a12730a 100644 --- a/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb +++ b/modules/bim/lib/open_project/bim/patches/color_themes_patch.rb @@ -32,7 +32,7 @@ module OpenProject::Bim 'content-link-color' => "#275BB5", 'main-menu-bg-color' => "#0E2045", 'main-menu-bg-selected-background' => "#3270DB", - 'main-menu-bg-hover-background' => "#163473", + 'main-menu-bg-hover-background' => "#163473" # TODO 'new-feature-teaser-image' => '#{image-url("bim/new_feature_teaser.jpg")}' }, logo: 'bim/logo_openproject_bim_big.png' diff --git a/modules/bim/lib/open_project/bim/patches/type_patch.rb b/modules/bim/lib/open_project/bim/patches/type_patch.rb index f9b2eb2bab..0a41b5ab45 100644 --- a/modules/bim/lib/open_project/bim/patches/type_patch.rb +++ b/modules/bim/lib/open_project/bim/patches/type_patch.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - ## # We do not want the bcf_thumbnail to show up in the work package full view as we already have the BCF Viewpoint gallery # there. To achieve that we need to change how the default form configuration is set up. The default simply shall not diff --git a/modules/bim/lib/tasks/openproject-bim.rake b/modules/bim/lib/tasks/openproject-bim.rake index acb651f98c..b4c1cb8d68 100644 --- a/modules/bim/lib/tasks/openproject-bim.rake +++ b/modules/bim/lib/tasks/openproject-bim.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -54,7 +55,9 @@ class Seedifier def run @projects.each do |project| puts "=== PROJECT: #{project.identifier} ===" - work_packages = project.work_packages.reject { |work_package| work_package.parent && work_package.parent.project.identifier == project.identifier }.sort_by(&:start_date) + work_packages = project.work_packages.reject do |work_package| + work_package.parent && work_package.parent.project.identifier == project.identifier + end.sort_by(&:start_date) if work_packages.empty? puts "No work packages for project with identifier #{project.identifier}... skipping." next @@ -102,11 +105,11 @@ class Seedifier # Create a hash that only hold those properties that we would like to copy and paste into a seeder YAML file. def seedify_work_package(work_package, project) # Don't seed a WP twice. And don't seed WPs of other projects. - return nil if (@written_work_packages_ids.include?(work_package.id) || work_package.project_id != project.id) + return nil if @written_work_packages_ids.include?(work_package.id) || work_package.project_id != project.id @written_work_packages_ids << work_package.id - predecessors = work_package.follows.sort_by(&:start_date).map { |predecessor| {to: predecessor.subject, type: 'follows'} } + predecessors = work_package.follows.sort_by(&:start_date).map { |predecessor| { to: predecessor.subject, type: 'follows' } } children = work_package.children.sort_by(&:start_date).map { |child| seedify_work_package(child, project) }.compact @@ -131,7 +134,10 @@ class Seedifier seedified[:assigned_to] = assigned_to if assigned_to.present? seedified[:duration] = duration if duration.present? - seedified[:parent] = work_package.parent.subject if work_package.parent.present? && (work_package.bcf_issue || work_package.project_id != project.id) + if work_package.parent.present? && (work_package.bcf_issue || work_package.project_id != project.id) + seedified[:parent] = + work_package.parent.subject + end seedified[:relations] = predecessors if predecessors.any? seedified @@ -145,5 +151,3 @@ namespace :bim do Seedifier.new(project_identifiers).run end end - - diff --git a/modules/bim/spec/bcf/bcf_xml/issue_reader_spec.rb b/modules/bim/spec/bcf/bcf_xml/issue_reader_spec.rb index 9cb5a42b85..bdf166ec5e 100644 --- a/modules/bim/spec/bcf/bcf_xml/issue_reader_spec.rb +++ b/modules/bim/spec/bcf/bcf_xml/issue_reader_spec.rb @@ -184,7 +184,8 @@ describe ::OpenProject::Bim::BcfXml::IssueReader do it '#viewpoint_by_uuid' do expect(subject.send(:viewpoint_by_uuid, nil)).to be_nil - expect(subject.send(:viewpoint_by_uuid, bcf_issue.comments.first.viewpoint.uuid)).to eql(bcf_issue.comments.first.viewpoint) + expect(subject.send(:viewpoint_by_uuid, + bcf_issue.comments.first.viewpoint.uuid)).to eql(bcf_issue.comments.first.viewpoint) end end end diff --git a/modules/bim/spec/bcf/bcf_xml/issue_writer_spec.rb b/modules/bim/spec/bcf/bcf_xml/issue_writer_spec.rb index c980566e5e..de0e0c659e 100644 --- a/modules/bim/spec/bcf/bcf_xml/issue_writer_spec.rb +++ b/modules/bim/spec/bcf/bcf_xml/issue_writer_spec.rb @@ -145,7 +145,7 @@ describe ::OpenProject::Bim::BcfXml::IssueWriter do shared_examples_for 'valid markup' do it 'produces valid markup' do - expect(valid_markup? subject).to be_truthy + expect(valid_markup?(subject)).to be_truthy end end diff --git a/modules/bim/spec/contracts/bcf/viewpoints/create_contract_spec.rb b/modules/bim/spec/contracts/bcf/viewpoints/create_contract_spec.rb index 8f856fb6d6..e171917956 100644 --- a/modules/bim/spec/contracts/bcf/viewpoints/create_contract_spec.rb +++ b/modules/bim/spec/contracts/bcf/viewpoints/create_contract_spec.rb @@ -31,8 +31,8 @@ require 'spec_helper' describe Bim::Bcf::Viewpoints::CreateContract do let(:viewpoint) do Bim::Bcf::Viewpoint.new(uuid: viewpoint_uuid, - issue: viewpoint_issue, - json_viewpoint: viewpoint_json_viewpoint) + issue: viewpoint_issue, + json_viewpoint: viewpoint_json_viewpoint) end let(:permissions) { [:manage_bcf] } diff --git a/modules/bim/spec/contracts/ifc_models/create_contract_spec.rb b/modules/bim/spec/contracts/ifc_models/create_contract_spec.rb index 12a34c3d4a..1033bc786f 100644 --- a/modules/bim/spec/contracts/ifc_models/create_contract_spec.rb +++ b/modules/bim/spec/contracts/ifc_models/create_contract_spec.rb @@ -35,8 +35,8 @@ describe Bim::IfcModels::CreateContract do it_behaves_like 'ifc model contract' do let(:ifc_model) do ::Bim::IfcModels::IfcModel.new(project: model_project, - title: model_title, - uploader: model_user) + title: model_title, + uploader: model_user) end let(:permissions) { %i(manage_ifc_models) } let(:other_user) { FactoryBot.build_stubbed(:user) } diff --git a/modules/bim/spec/controllers/issues_controller_spec.rb b/modules/bim/spec/controllers/issues_controller_spec.rb index 3ac597eb6d..08eb3e451a 100644 --- a/modules/bim/spec/controllers/issues_controller_spec.rb +++ b/modules/bim/spec/controllers/issues_controller_spec.rb @@ -134,8 +134,8 @@ describe ::Bim::Bcf::IssuesController, type: :controller do let(:filename) { 'MaximumInformation.bcf' } let(:file) do Rack::Test::UploadedFile.new( - File.join(Rails.root, "modules/bim/spec/fixtures/files/#{filename}"), - 'application/octet-stream' + File.join(Rails.root, "modules/bim/spec/fixtures/files/#{filename}"), + 'application/octet-stream' ) end @@ -153,7 +153,6 @@ describe ::Bim::Bcf::IssuesController, type: :controller do end end - describe '#perform_import' do let(:action) do post :perform_import, params: { project_id: project.identifier.to_s } diff --git a/modules/bim/spec/features/bim_navigation_spec.rb b/modules/bim/spec/features/bim_navigation_spec.rb index 1b347ef9b3..e444666caf 100644 --- a/modules/bim/spec/features/bim_navigation_spec.rb +++ b/modules/bim/spec/features/bim_navigation_spec.rb @@ -34,7 +34,9 @@ describe 'BIM navigation spec', js: true do let(:project) { FactoryBot.create :project, enabled_module_names: %i[bim work_package_tracking] } let!(:work_package) { FactoryBot.create(:work_package, project: project) } - let(:role) { FactoryBot.create(:role, permissions: %i[view_ifc_models manage_ifc_models view_work_packages delete_work_packages]) } + let(:role) do + FactoryBot.create(:role, permissions: %i[view_ifc_models manage_ifc_models view_work_packages delete_work_packages]) + end let(:user) do FactoryBot.create :user, diff --git a/modules/bim/spec/features/bim_revit_add_in_navigation_spec.rb b/modules/bim/spec/features/bim_revit_add_in_navigation_spec.rb index 4103f6fddc..6b33a0f624 100644 --- a/modules/bim/spec/features/bim_revit_add_in_navigation_spec.rb +++ b/modules/bim/spec/features/bim_revit_add_in_navigation_spec.rb @@ -35,7 +35,10 @@ describe 'BIM Revit Add-in navigation spec', driver: :chrome_revit_add_in do let(:project) { FactoryBot.create :project, enabled_module_names: %i[bim work_package_tracking] } let!(:work_package) { FactoryBot.create(:work_package, project: project) } - let(:role) { FactoryBot.create(:role, permissions: %i[view_ifc_models manage_ifc_models add_work_packages edit_work_packages view_work_packages]) } + let(:role) do + FactoryBot.create(:role, + permissions: %i[view_ifc_models manage_ifc_models add_work_packages edit_work_packages view_work_packages]) + end let(:wp_table) { ::Pages::WorkPackagesTable.new(project) } let(:full_create) { ::Pages::FullWorkPackageCreate.new } diff --git a/modules/bim/spec/features/model_management_spec.rb b/modules/bim/spec/features/model_management_spec.rb index 37b771b6cd..79049dce54 100644 --- a/modules/bim/spec/features/model_management_spec.rb +++ b/modules/bim/spec/features/model_management_spec.rb @@ -57,7 +57,6 @@ describe 'model management', uploader: user) end - context 'with all permissions' do before do login_as(user) diff --git a/modules/bim/spec/features/model_viewer_spec.rb b/modules/bim/spec/features/model_viewer_spec.rb index 4b2495f831..30efeadb8e 100644 --- a/modules/bim/spec/features/model_viewer_spec.rb +++ b/modules/bim/spec/features/model_viewer_spec.rb @@ -32,7 +32,7 @@ describe 'model viewer', with_config: { edition: 'bim' }, type: :feature, js: true do - let(:project) { FactoryBot.create :project, enabled_module_names: [:bim, :work_package_tracking] } + let(:project) { FactoryBot.create :project, enabled_module_names: %i[bim work_package_tracking] } # TODO: Add empty viewpoint and stub method to load viewpoints once defined let(:work_package) { FactoryBot.create(:work_package, project: project) } let(:role) { FactoryBot.create(:role, permissions: %i[view_ifc_models manage_ifc_models view_work_packages]) } diff --git a/modules/bim/spec/features/viewer/create_viewpoint_spec.rb b/modules/bim/spec/features/viewer/create_viewpoint_spec.rb index b75fef1c03..01d8beaa59 100644 --- a/modules/bim/spec/features/viewer/create_viewpoint_spec.rb +++ b/modules/bim/spec/features/viewer/create_viewpoint_spec.rb @@ -32,7 +32,7 @@ describe 'Create viewpoint from BCF details page', type: :feature, with_config: { edition: 'bim' }, js: true do - let(:project) { FactoryBot.create :project, enabled_module_names: [:bim, :work_package_tracking] } + let(:project) { FactoryBot.create :project, enabled_module_names: %i[bim work_package_tracking] } let(:user) { FactoryBot.create :admin } let!(:model) do diff --git a/modules/bim/spec/features/viewer/delete_viewpoint_spec.rb b/modules/bim/spec/features/viewer/delete_viewpoint_spec.rb index a8cdc6fe32..feef430545 100644 --- a/modules/bim/spec/features/viewer/delete_viewpoint_spec.rb +++ b/modules/bim/spec/features/viewer/delete_viewpoint_spec.rb @@ -32,7 +32,7 @@ describe 'Delete viewpoint in model viewer', with_config: { edition: 'bim' }, type: :feature, js: true do - let(:project) { FactoryBot.create :project, enabled_module_names: [:bim, :work_package_tracking] } + let(:project) { FactoryBot.create :project, enabled_module_names: %i[bim work_package_tracking] } let(:user) { FactoryBot.create :admin } let!(:work_package) { FactoryBot.create(:work_package, project: project) } diff --git a/modules/bim/spec/features/viewer/show_viewpoint_spec.rb b/modules/bim/spec/features/viewer/show_viewpoint_spec.rb index d09955fd79..b553b742e6 100644 --- a/modules/bim/spec/features/viewer/show_viewpoint_spec.rb +++ b/modules/bim/spec/features/viewer/show_viewpoint_spec.rb @@ -34,7 +34,7 @@ describe 'Show viewpoint in model viewer', js: true do let(:project) do FactoryBot.create(:project, - enabled_module_names: [:bim, :work_package_tracking], + enabled_module_names: %i[bim work_package_tracking], parent: parent_project) end let(:parent_project) { nil } @@ -99,7 +99,7 @@ describe 'Show viewpoint in model viewer', context 'when in work packages details view' do let(:wp_details) { ::Pages::SplitWorkPackage.new(work_package, project) } - + shared_examples "moves to the BCF page" do it 'moves to the bcf page' do wp_details.visit! diff --git a/modules/bim/spec/lib/open_project/bcf/bcf_json/viewpoint_reader_spec.rb b/modules/bim/spec/lib/open_project/bcf/bcf_json/viewpoint_reader_spec.rb index a4eda43f88..f35bdba2a6 100644 --- a/modules/bim/spec/lib/open_project/bcf/bcf_json/viewpoint_reader_spec.rb +++ b/modules/bim/spec/lib/open_project/bcf/bcf_json/viewpoint_reader_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require_relative './viewpoint_reader_shared_examples.rb' +require_relative './viewpoint_reader_shared_examples' describe OpenProject::Bim::BcfJson::ViewpointReader do let(:instance) { described_class.new xml_viewpoint.uuid, xml_viewpoint.viewpoint } diff --git a/modules/bim/spec/requests/api/bcf/v2_1/project_extensions_api_spec.rb b/modules/bim/spec/requests/api/bcf/v2_1/project_extensions_api_spec.rb index 71551fcc29..f6b23c38a3 100644 --- a/modules/bim/spec/requests/api/bcf/v2_1/project_extensions_api_spec.rb +++ b/modules/bim/spec/requests/api/bcf/v2_1/project_extensions_api_spec.rb @@ -75,7 +75,7 @@ describe 'BCF 2.1 project extensions resource', type: :request, content_type: :j let(:current_user) do FactoryBot.create(:user, member_in_project: project, - member_with_permissions: [:view_project, :edit_project, :manage_bcf, :view_members]) + member_with_permissions: %i[view_project edit_project manage_bcf view_members]) end let(:other_user) do diff --git a/modules/bim/spec/requests/api/bcf/v2_1/shared_responses.rb b/modules/bim/spec/requests/api/bcf/v2_1/shared_responses.rb index c0d130e6ff..68e799e159 100644 --- a/modules/bim/spec/requests/api/bcf/v2_1/shared_responses.rb +++ b/modules/bim/spec/requests/api/bcf/v2_1/shared_responses.rb @@ -57,7 +57,6 @@ shared_examples_for 'bcf api successful response' do expect_identical_without_time(subject, expected_body) end - expect(subject.headers['Content-Type']).to eql 'application/json; charset=utf-8' unless defined?(no_content) end end diff --git a/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb b/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb index 887d1d275d..1c11a7aa6d 100644 --- a/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb +++ b/modules/bim/spec/requests/api/bcf/v2_1/topics_api_spec.rb @@ -672,7 +672,7 @@ describe 'BCF 2.1 topics resource', type: :request, content_type: :json, with_ma { title: "A new BCF topic", reference_links: [ - api_v3_paths.work_package((WorkPackage.last&.id).to_i + 42) + api_v3_paths.work_package(WorkPackage.last&.id.to_i + 42) ] } end diff --git a/modules/bim/spec/services/ifc_models/view_conversion_service_spec.rb b/modules/bim/spec/services/ifc_models/view_conversion_service_spec.rb index 36513debfb..12c2c746ab 100644 --- a/modules/bim/spec/services/ifc_models/view_conversion_service_spec.rb +++ b/modules/bim/spec/services/ifc_models/view_conversion_service_spec.rb @@ -62,7 +62,7 @@ describe Bim::IfcModels::ViewConverterService do let(:working_directory) { Dir.mktmpdir } let(:ifc_model_file_name) { "büro.ifc" } let(:ifc_model_path) { File.join working_directory, ifc_model_file_name } - let(:ext_regex) { /\.[^\.]*\Z/ } + let(:ext_regex) { /\.[^.]*\Z/ } before do allow(described_class).to receive(:available?).and_return true diff --git a/modules/bim/spec/support/components/xeokit_model_tree.rb b/modules/bim/spec/support/components/xeokit_model_tree.rb index 9a861fca23..369d832849 100644 --- a/modules/bim/spec/support/components/xeokit_model_tree.rb +++ b/modules/bim/spec/support/components/xeokit_model_tree.rb @@ -76,7 +76,6 @@ module Components else expect(page.find('input', match: :first)).not_to be_checked end - end end end diff --git a/modules/boards/lib/open_project/boards/engine.rb b/modules/boards/lib/open_project/boards/engine.rb index 957c3efbde..755447fe87 100644 --- a/modules/boards/lib/open_project/boards/engine.rb +++ b/modules/boards/lib/open_project/boards/engine.rb @@ -27,7 +27,6 @@ module OpenProject::Boards bundled: true, settings: {}, name: 'OpenProject Boards' do - project_module :board_view, order: 80 do permission :show_board_views, 'boards/boards': %i[index], dependencies: :view_work_packages permission :manage_board_views, 'boards/boards': %i[index], dependencies: :manage_public_queries diff --git a/modules/boards/spec/factories/board_factory.rb b/modules/boards/spec/factories/board_factory.rb index 2d43031fbc..2436831a5c 100644 --- a/modules/boards/spec/factories/board_factory.rb +++ b/modules/boards/spec/factories/board_factory.rb @@ -31,7 +31,8 @@ FactoryBot.define do end_row: 2, start_column: 1, end_column: 1, - options: { 'queryId' => query.id, "filters"=>[{"manualSort"=>{"operator"=>"ow", "values"=>[]}}]}) + options: { 'queryId' => query.id, + "filters" => [{ "manualSort" => { "operator" => "ow", "values" => [] } }] }) end end @@ -47,7 +48,6 @@ FactoryBot.define do callback(:after_build) do |board, evaluator| # this is also done after :create evaluator.num_queries.times do |i| - query = Query.new_default(name: "List #{i + 1}", is_public: true, project: board.project).tap do |q| q.sort_criteria = [[:manual_sorting, 'asc']] q.add_filter(:manual_sort, 'ow', []) @@ -60,7 +60,8 @@ FactoryBot.define do end_row: 2, start_column: 1, end_column: 1, - options: { 'queryId' => query.id, "filters"=>[{"manualSort"=>{"operator"=>"ow", "values"=>[]}}]}) + options: { 'queryId' => query.id, + "filters" => [{ "manualSort" => { "operator" => "ow", "values" => [] } }] }) end end end diff --git a/modules/boards/spec/features/action_boards/assignee_board_spec.rb b/modules/boards/spec/features/action_boards/assignee_board_spec.rb index 80f8aa7db3..604a88a660 100644 --- a/modules/boards/spec/features/action_boards/assignee_board_spec.rb +++ b/modules/boards/spec/features/action_boards/assignee_board_spec.rb @@ -49,14 +49,13 @@ describe 'Assignee action board', let(:board_index) { Pages::BoardIndex.new(project) } let(:other_board_index) { Pages::BoardIndex.new(project_without_members) } - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages edit_work_packages view_work_packages manage_public_queries] - } + end let!(:priority) { FactoryBot.create :default_priority } - # Set up other assignees let!(:foobar_user) do @@ -76,10 +75,12 @@ describe 'Assignee action board', end end - let!(:work_package) { FactoryBot.create :work_package, - project: project, - assigned_to: bobself_user, - subject: 'Some Task' } + let!(:work_package) do + FactoryBot.create :work_package, + project: project, + assigned_to: bobself_user, + subject: 'Some Task' + end context 'in a project with members' do before do diff --git a/modules/boards/spec/features/action_boards/status_board_spec.rb b/modules/boards/spec/features/action_boards/status_board_spec.rb index dfe7539361..456cb97db3 100644 --- a/modules/boards/spec/features/action_boards/status_board_spec.rb +++ b/modules/boards/spec/features/action_boards/status_board_spec.rb @@ -42,10 +42,10 @@ describe 'Status action board', type: :feature, js: true do let(:board_index) { Pages::BoardIndex.new(project) } - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages edit_work_packages view_work_packages manage_public_queries] - } + end let!(:priority) { FactoryBot.create :default_priority } let!(:open_status) { FactoryBot.create :default_status, name: 'Open' } @@ -55,27 +55,27 @@ describe 'Status action board', type: :feature, js: true do let(:filters) { ::Components::WorkPackages::Filters.new } - let!(:workflow_type) { + let!(:workflow_type) do FactoryBot.create(:workflow, type: type, role: role, old_status_id: open_status.id, new_status_id: closed_status.id) - } - let!(:workflow_type_back) { + end + let!(:workflow_type_back) do FactoryBot.create(:workflow, type: type, role: role, old_status_id: other_status.id, new_status_id: open_status.id) - } - let!(:workflow_type_back_open) { + end + let!(:workflow_type_back_open) do FactoryBot.create(:workflow, type: type, role: role, old_status_id: closed_status.id, new_status_id: open_status.id) - } + end before do with_enterprise_token :board_view diff --git a/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb b/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb index be8a20838e..d93808b569 100644 --- a/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb +++ b/modules/boards/spec/features/action_boards/status_type_moving_board_spec.rb @@ -36,17 +36,18 @@ describe 'Status action board', type: :feature, js: true do member_in_project: project, member_through_role: role) end - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages edit_work_packages view_work_packages manage_public_queries] - } + end let(:role) { FactoryBot.create(:role, permissions: permissions) } - let(:type_bug) { FactoryBot.create(:type_bug) } let(:type_task) { FactoryBot.create(:type_task) } - let(:project) { FactoryBot.create(:project, types: [type_task, type_bug], enabled_module_names: %i[work_package_tracking board_view]) } + let(:project) do + FactoryBot.create(:project, types: [type_task, type_bug], enabled_module_names: %i[work_package_tracking board_view]) + end let(:board_index) { Pages::BoardIndex.new(project) } let!(:priority) { FactoryBot.create :default_priority } @@ -68,35 +69,35 @@ describe 'Status action board', type: :feature, js: true do status: closed_status end - let!(:workflow_task) { + let!(:workflow_task) do FactoryBot.create(:workflow, type: type_task, role: role, old_status_id: open_status.id, new_status_id: closed_status.id) - } - let!(:workflow_task_back) { + end + let!(:workflow_task_back) do FactoryBot.create(:workflow, type: type_task, role: role, old_status_id: closed_status.id, new_status_id: open_status.id) - } + end - let!(:workflow_bug) { + let!(:workflow_bug) do FactoryBot.create(:workflow, type: type_bug, role: role, old_status_id: open_status.id, new_status_id: closed_status.id) - } - let!(:workflow_bug_back) { + end + let!(:workflow_bug_back) do FactoryBot.create(:workflow, type: type_bug, role: role, old_status_id: closed_status.id, new_status_id: open_status.id) - } + end let(:filters) { ::Components::WorkPackages::Filters.new } diff --git a/modules/boards/spec/features/action_boards/subproject_board_spec.rb b/modules/boards/spec/features/action_boards/subproject_board_spec.rb index 4c304aecf6..12df4cf6c8 100644 --- a/modules/boards/spec/features/action_boards/subproject_board_spec.rb +++ b/modules/boards/spec/features/action_boards/subproject_board_spec.rb @@ -37,17 +37,23 @@ describe 'Subproject action board', type: :feature, js: true do member_through_role: role) end let(:type) { FactoryBot.create(:type_standard) } - let(:project) { FactoryBot.create(:project, name: 'Parent', types: [type], enabled_module_names: %i[work_package_tracking board_view]) } - let(:subproject1) { FactoryBot.create(:project, parent: project, name: 'Child 1', types: [type], enabled_module_names: %i[work_package_tracking]) } - let(:subproject2) { FactoryBot.create(:project, parent: project, name: 'Child 2', types: [type], enabled_module_names: %i[work_package_tracking]) } + let(:project) do + FactoryBot.create(:project, name: 'Parent', types: [type], enabled_module_names: %i[work_package_tracking board_view]) + end + let(:subproject1) do + FactoryBot.create(:project, parent: project, name: 'Child 1', types: [type], enabled_module_names: %i[work_package_tracking]) + end + let(:subproject2) do + FactoryBot.create(:project, parent: project, name: 'Child 2', types: [type], enabled_module_names: %i[work_package_tracking]) + end let(:role) { FactoryBot.create(:role, permissions: permissions) } let(:board_index) { Pages::BoardIndex.new(project) } - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages edit_work_packages view_work_packages manage_public_queries move_work_packages] - } + end let!(:priority) { FactoryBot.create :default_priority } let!(:open_status) { FactoryBot.create :default_status, name: 'Open' } @@ -62,10 +68,10 @@ describe 'Subproject action board', type: :feature, js: true do end context 'without the move_work_packages permission' do - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages - edit_work_packages view_work_packages manage_public_queries] - } + edit_work_packages view_work_packages manage_public_queries] + end let(:user) do FactoryBot.create(:user, diff --git a/modules/boards/spec/features/action_boards/subtasks_board_spec.rb b/modules/boards/spec/features/action_boards/subtasks_board_spec.rb index f840952e27..948563b86b 100644 --- a/modules/boards/spec/features/action_boards/subtasks_board_spec.rb +++ b/modules/boards/spec/features/action_boards/subtasks_board_spec.rb @@ -54,10 +54,10 @@ describe 'Subtasks action board', type: :feature, js: true do end context 'without the manage_subtasks permission' do - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages - edit_work_packages view_work_packages manage_public_queries] - } + edit_work_packages view_work_packages manage_public_queries] + end it 'does not allow to move work packages' do board_index.visit! @@ -78,10 +78,10 @@ describe 'Subtasks action board', type: :feature, js: true do context 'with all permissions' do let!(:other_wp) { FactoryBot.create :work_package, project: project, subject: 'Other WP', status: open_status } - let(:permissions) { + let(:permissions) do %i[show_board_views manage_board_views add_work_packages - edit_work_packages view_work_packages manage_public_queries manage_subtasks] - } + edit_work_packages view_work_packages manage_public_queries manage_subtasks] + end it 'allows management of subtasks work packages' do board_index.visit! diff --git a/modules/boards/spec/features/action_boards/version_board_spec.rb b/modules/boards/spec/features/action_boards/version_board_spec.rb index 5a3a2dd4eb..44b0487426 100644 --- a/modules/boards/spec/features/action_boards/version_board_spec.rb +++ b/modules/boards/spec/features/action_boards/version_board_spec.rb @@ -109,8 +109,8 @@ describe 'Version action board', type: :feature, js: true do queries = board.contained_queries expect(queries.count).to eq(2) - open = queries.detect { |q| q.name == 'Open version'} - second_open = queries.detect { |q| q.name == 'A second version'} + open = queries.detect { |q| q.name == 'Open version' } + second_open = queries.detect { |q| q.name == 'A second version' } expect(open.name).to eq 'Open version' expect(second_open.name).to eq 'A second version' @@ -311,7 +311,7 @@ describe 'Version action board', type: :feature, js: true do let(:no_version_edit_role) { FactoryBot.create(:role, permissions: no_version_edit_permissions) } let(:no_version_edit_permissions) do %i[show_board_views manage_board_views add_work_packages manage_versions - edit_work_packages view_work_packages manage_public_queries] + edit_work_packages view_work_packages manage_public_queries] end it 'can not move cards or add cards' do diff --git a/modules/boards/spec/features/board_highlighting_spec.rb b/modules/boards/spec/features/board_highlighting_spec.rb index bc5ee25b64..46e194463f 100644 --- a/modules/boards/spec/features/board_highlighting_spec.rb +++ b/modules/boards/spec/features/board_highlighting_spec.rb @@ -42,17 +42,17 @@ describe 'Work Package boards spec', type: :feature, js: true do let!(:wp) do FactoryBot.create(:work_package, - project: project, - type: type, - priority: priority, - status: open_status) + project: project, + type: type, + priority: priority, + status: open_status) end let!(:wp2) do FactoryBot.create(:work_package, - project: project, - type: type2, - priority: priority2, - status: open_status) + project: project, + type: type2, + priority: priority2, + status: open_status) end let!(:priority) { FactoryBot.create :priority, color: color } diff --git a/modules/boards/spec/features/board_update_spec.rb b/modules/boards/spec/features/board_update_spec.rb index a8a9aa480f..97ad2fd5c3 100644 --- a/modules/boards/spec/features/board_update_spec.rb +++ b/modules/boards/spec/features/board_update_spec.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - require 'spec_helper' require_relative './support/board_index_page' require_relative './support/board_page' diff --git a/modules/boards/spec/features/onboarding/boards_onboarding_tour_spec.rb b/modules/boards/spec/features/onboarding/boards_onboarding_tour_spec.rb index ec6465c3cc..a713d6d7dc 100644 --- a/modules/boards/spec/features/onboarding/boards_onboarding_tour_spec.rb +++ b/modules/boards/spec/features/onboarding/boards_onboarding_tour_spec.rb @@ -31,9 +31,11 @@ require_relative './../support/onboarding_steps' describe 'boards onboarding tour', js: true do let(:next_button) { find('.enjoyhint_next_btn') } - let(:user) { FactoryBot.create :admin, - member_in_project: demo_project, - member_through_role: role} + let(:user) do + FactoryBot.create :admin, + member_in_project: demo_project, + member_through_role: role + end let(:permissions) do %i[ show_board_views @@ -94,7 +96,7 @@ describe 'boards onboarding tour', js: true do it "I see the board onboarding tour in the scrum project" do # Set sessionStorage value so that the tour knows that it is in the scum tour - page.execute_script("window.sessionStorage.setItem('openProject-onboardingTour', 'startMainTourFromBacklogs');"); + page.execute_script("window.sessionStorage.setItem('openProject-onboardingTour', 'startMainTourFromBacklogs');") # Set the tour parameter so that we can start on the wp page visit "/projects/#{scrum_project.identifier}/work_packages?start_onboarding_tour=true" diff --git a/modules/budgets/app/controllers/budgets_controller.rb b/modules/budgets/app/controllers/budgets_controller.rb index 427ceed7e8..bb26ce9220 100644 --- a/modules/budgets/app/controllers/budgets_controller.rb +++ b/modules/budgets/app/controllers/budgets_controller.rb @@ -157,7 +157,11 @@ class BudgetsController < ApplicationController if cost_type && params[:units].present? volume = Rate.parse_number_string_to_number(params[:units]) - @costs = volume * cost_type.rate_at(params[:fixed_date]).rate rescue 0.0 + @costs = begin + volume * cost_type.rate_at(params[:fixed_date]).rate + rescue StandardError + 0.0 + end @unit = volume == 1.0 ? cost_type.unit : cost_type.unit_plural else @costs = 0.0 @@ -177,7 +181,11 @@ class BudgetsController < ApplicationController if user && params[:hours] hours = Rate.parse_number_string_to_number(params[:hours]) - @costs = hours * user.rate_at(params[:fixed_date], @project).rate rescue 0.0 + @costs = begin + hours * user.rate_at(params[:fixed_date], @project).rate + rescue StandardError + 0.0 + end else @costs = 0.0 end diff --git a/modules/budgets/app/helpers/budgets_helper.rb b/modules/budgets/app/helpers/budgets_helper.rb index 59c675067a..6acdd94bc0 100644 --- a/modules/budgets/app/helpers/budgets_helper.rb +++ b/modules/budgets/app/helpers/budgets_helper.rb @@ -54,7 +54,7 @@ module BudgetsHelper Budget.human_attribute_name(:updated_at), Budget.human_attribute_name(:description) ] - csv << headers.map { |c| begin; c.to_s.encode('UTF-8'); rescue; c.to_s; end } + csv << headers.map { |c| begin; c.to_s.encode('UTF-8'); rescue StandardError; c.to_s; end } # csv lines budgets.each do |budget| fields = [ @@ -70,7 +70,7 @@ module BudgetsHelper format_time(budget.updated_at), budget.description ] - csv << fields.map { |c| begin; c.to_s.encode('UTF-8'); rescue; c.to_s; end } + csv << fields.map { |c| begin; c.to_s.encode('UTF-8'); rescue StandardError; c.to_s; end } end end end diff --git a/modules/budgets/app/models/budget.rb b/modules/budgets/app/models/budget.rb index c6fbed22d8..7d8e84b37e 100644 --- a/modules/budgets/app/models/budget.rb +++ b/modules/budgets/app/models/budget.rb @@ -162,30 +162,30 @@ class Budget < ApplicationRecord def spent_material @spent_material ||= begin - if cost_entries.blank? - BigDecimal('0.0000') - else - cost_entries.visible_costs(User.current, project).sum("CASE + if cost_entries.blank? + BigDecimal('0.0000') + else + cost_entries.visible_costs(User.current, project).sum("CASE WHEN #{CostEntry.table_name}.overridden_costs IS NULL THEN #{CostEntry.table_name}.costs ELSE #{CostEntry.table_name}.overridden_costs END").to_d - end - end + end + end end def spent_labor @spent_labor ||= begin - if time_entries.blank? - BigDecimal('0.0000') - else - time_entries.visible_costs(User.current, project).sum("CASE + if time_entries.blank? + BigDecimal('0.0000') + else + time_entries.visible_costs(User.current, project).sum("CASE WHEN #{TimeEntry.table_name}.overridden_costs IS NULL THEN #{TimeEntry.table_name}.costs ELSE #{TimeEntry.table_name}.overridden_costs END").to_d - end - end + end + end end def new_material_budget_item_attributes=(material_budget_item_attributes) diff --git a/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb b/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb index 5e4d240839..11a8168230 100644 --- a/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb +++ b/modules/budgets/db/migrate/20200810152654_rename_cost_object_to_budget.rb @@ -3,7 +3,7 @@ class RenameCostObjectToBudget < ActiveRecord::Migration[6.0] if primary_key_index_name(:cost_objects) != 'cost_objects_pkey' warn "Found unexpected primary key name. Fixing primary key names..." - require "./db/migrate/20190502102512_ensure_postgres_index_names.rb" + require './db/migrate/20190502102512_ensure_postgres_index_names' EnsurePostgresIndexNames.new.up end diff --git a/modules/budgets/spec/features/budgets/add_budget_spec.rb b/modules/budgets/spec/features/budgets/add_budget_spec.rb index 25ad24702c..a8dd679aec 100644 --- a/modules/budgets/spec/features/budgets/add_budget_spec.rb +++ b/modules/budgets/spec/features/budgets/add_budget_spec.rb @@ -55,7 +55,6 @@ describe 'adding a new budget', type: :feature, js: true do FactoryBot.create :cost_type, name: 'Foobar', unit: 'bar', unit_plural: 'bars' end - it 'can switch between them' do visit projects_budgets_path(project) @@ -137,14 +136,12 @@ describe 'adding a new budget', type: :feature, js: true do budget_page.expect_planned_costs! type: :labor, row: 1, expected: '125.002,50 EUR' budget_page.expect_planned_costs! type: :labor, row: 2, expected: '12,50 EUR' - fields = page .all('input.budget-item-value') .select { |node| node.value.present? } .map(&:value) expect(fields).to contain_exactly '3,50', '1.000,50', '5.000,10', '0,50' - end end diff --git a/modules/budgets/spec/models/budget_spec.rb b/modules/budgets/spec/models/budget_spec.rb index 07f44105d9..4aed89166c 100644 --- a/modules/budgets/spec/models/budget_spec.rb +++ b/modules/budgets/spec/models/budget_spec.rb @@ -86,7 +86,7 @@ describe Budget, type: :model do context 'with no value' do it 'deletes the item' do - budget.existing_material_budget_item_attributes = { existing_material_budget_item.id.to_s => { } } + budget.existing_material_budget_item_attributes = { existing_material_budget_item.id.to_s => {} } expect(existing_material_budget_item) .to be_destroyed diff --git a/modules/costs/app/controllers/cost_types_controller.rb b/modules/costs/app/controllers/cost_types_controller.rb index bd4cd9a183..2a8a0a992a 100644 --- a/modules/costs/app/controllers/cost_types_controller.rb +++ b/modules/costs/app/controllers/cost_types_controller.rb @@ -29,7 +29,7 @@ class CostTypesController < ApplicationController # Allow only admins here before_action :require_admin - before_action :find_cost_type, only: [:edit, :update, :set_rate, :destroy, :restore] + before_action :find_cost_type, only: %i[edit update set_rate destroy restore] layout 'admin' helper :sort @@ -46,12 +46,16 @@ class CostTypesController < ApplicationController @cost_types = CostType.order(sort_clause) - unless params[:clear_filter] - @fixed_date = Date.parse(params[:fixed_date]) rescue Date.today - @include_deleted = params[:include_deleted] - else + if params[:clear_filter] @fixed_date = Date.today @include_deleted = nil + else + @fixed_date = begin + Date.parse(params[:fixed_date]) + rescue StandardError + Date.today + end + @include_deleted = params[:include_deleted] end render action: 'index', layout: !request.xhr? diff --git a/modules/costs/app/controllers/costlog_controller.rb b/modules/costs/app/controllers/costlog_controller.rb index e089d35b76..219702f9c8 100644 --- a/modules/costs/app/controllers/costlog_controller.rb +++ b/modules/costs/app/controllers/costlog_controller.rb @@ -82,6 +82,7 @@ class CostlogController < ApplicationController def destroy render_404 and return unless @cost_entry render_403 and return unless @cost_entry.editable_by?(User.current) + @cost_entry.destroy flash[:notice] = t(:notice_successful_delete) @@ -109,7 +110,7 @@ class CostlogController < ApplicationController @project = Project.find(params[:project_id]) else render_404 - return false + false end rescue ActiveRecord::RecordNotFound render_404 @@ -133,19 +134,25 @@ class CostlogController < ApplicationController def find_associated_objects user_id = cost_entry_params.delete(:user_id) - @user = @cost_entry.present? && @cost_entry.user_id == user_id ? - @cost_entry.user : + @user = if @cost_entry.present? && @cost_entry.user_id == user_id + @cost_entry.user + else User.find_by_id(user_id) + end work_package_id = cost_entry_params.delete(:work_package_id) - @work_package = @cost_entry.present? && @cost_entry.work_package_id == work_package_id ? - @cost_entry.work_package : - WorkPackage.find_by_id(work_package_id) + @work_package = if @cost_entry.present? && @cost_entry.work_package_id == work_package_id + @cost_entry.work_package + else + WorkPackage.find_by_id(work_package_id) + end cost_type_id = cost_entry_params.delete(:cost_type_id) - @cost_type = @cost_entry.present? && @cost_entry.cost_type_id == cost_type_id ? - @cost_entry.cost_type : + @cost_type = if @cost_entry.present? && @cost_entry.cost_type_id == cost_type_id + @cost_entry.cost_type + else CostType.find_by_id(cost_type_id) + end end def new_default_cost_entry @@ -173,8 +180,6 @@ class CostlogController < ApplicationController @cost_entry.attributes = attributes end - private - def cost_entry_params params.require(:cost_entry).permit(:work_package_id, :spent_on, :user_id, :cost_type_id, :units, :comments) diff --git a/modules/costs/app/controllers/hourly_rates_controller.rb b/modules/costs/app/controllers/hourly_rates_controller.rb index ee41879254..c83326cd50 100644 --- a/modules/costs/app/controllers/hourly_rates_controller.rb +++ b/modules/costs/app/controllers/hourly_rates_controller.rb @@ -33,13 +33,13 @@ class HourlyRatesController < ApplicationController helper :hourly_rates include HourlyRatesHelper - before_action :find_user, only: [:show, :edit, :update, :set_rate] + before_action :find_user, only: %i[show edit update set_rate] - before_action :find_optional_project, only: [:show, :edit, :update] + before_action :find_optional_project, only: %i[show edit update] before_action :find_project, only: [:set_rate] # #show, #edit have their own authorization - before_action :authorize, except: [:show, :edit, :update] + before_action :authorize, except: %i[show edit update] # TODO: this should be an index def show @@ -140,7 +140,8 @@ class HourlyRatesController < ApplicationController if rate.save if request.xhr? render :update do |page| - page.replace_html "rate_for_#{@user.id}", link_to(number_to_currency(rate.rate), action: 'edit', id: @user, project_id: @project) + page.replace_html "rate_for_#{@user.id}", + link_to(number_to_currency(rate.rate), action: 'edit', id: @user, project_id: @project) end else flash[:notice] = t(:notice_successful_update) diff --git a/modules/costs/app/helpers/hourly_rates_helper.rb b/modules/costs/app/helpers/hourly_rates_helper.rb index 997cc513db..0f75e61bc3 100644 --- a/modules/costs/app/helpers/hourly_rates_helper.rb +++ b/modules/costs/app/helpers/hourly_rates_helper.rb @@ -45,12 +45,11 @@ module HourlyRatesHelper self_and_ancestors.each do |ancestor| rate = all_rates[ancestor].select { |rate| rate.valid_from <= at_date } - .sort_by(&:valid_from) - .last + .max_by(&:valid_from) return rate if rate end - return nil + nil end end diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rb index b6eb30f578..776537b066 100644 --- a/modules/costs/app/models/cost_entry.rb +++ b/modules/costs/app/models/cost_entry.rb @@ -53,10 +53,8 @@ class CostEntry < ApplicationRecord include Entry::SplashedDates def after_initialize - if new_record? && cost_type.nil? - if default_cost_type = CostType.default - self.cost_type_id = default_cost_type.id - end + if new_record? && cost_type.nil? && default_cost_type = CostType.default + self.cost_type_id = default_cost_type.id end end diff --git a/modules/costs/app/models/cost_rate.rb b/modules/costs/app/models/cost_rate.rb index 3f1d86a5cd..ab19cc363f 100644 --- a/modules/costs/app/models/cost_rate.rb +++ b/modules/costs/app/models/cost_rate.rb @@ -47,6 +47,6 @@ class CostRate < Rate private def change_of_cost_type_only_on_first_creation - errors.add :cost_type_id, :invalid if cost_type_id_changed? && !self.new_record? + errors.add :cost_type_id, :invalid if cost_type_id_changed? && !new_record? end end diff --git a/modules/costs/app/models/cost_scopes.rb b/modules/costs/app/models/cost_scopes.rb index 43041a2437..e9a3a41820 100644 --- a/modules/costs/app/models/cost_scopes.rb +++ b/modules/costs/app/models/cost_scopes.rb @@ -54,7 +54,8 @@ module CostScopes .or( table[:project_id] .in(view_own_allowed.arel) - .and(table[:user_id].eq(user.id))) + .and(table[:user_id].eq(user.id)) + ) end def with_visible_rates_on(scope, user: User.current) diff --git a/modules/costs/app/models/cost_type.rb b/modules/costs/app/models/cost_type.rb index a9b5ff6df7..e1c85469e6 100644 --- a/modules/costs/app/models/cost_type.rb +++ b/modules/costs/app/models/cost_type.rb @@ -49,8 +49,8 @@ class CostType < ApplicationRecord default end - def <=>(cost_type) - name.downcase <=> cost_type.name.downcase + def <=>(other) + name.downcase <=> other.name.downcase end def current_rate diff --git a/modules/costs/app/models/default_hourly_rate.rb b/modules/costs/app/models/default_hourly_rate.rb index d42a8512f6..24e6dca6c4 100644 --- a/modules/costs/app/models/default_hourly_rate.rb +++ b/modules/costs/app/models/default_hourly_rate.rb @@ -57,7 +57,7 @@ class DefaultHourlyRate < Rate def change_of_user_only_on_first_creation # Only allow change of user on first creation - errors.add :user_id, :invalid if !self.new_record? and user_id_changed? + errors.add :user_id, :invalid if !new_record? and user_id_changed? begin valid_from.to_date rescue Exception @@ -81,6 +81,7 @@ class DefaultHourlyRate < Rate # We have not moved a rate, maybe just changed the rate value return unless rate_changed? + # Only the rate value was changed so just update the currently assigned entries return rate_created end @@ -122,19 +123,19 @@ class DefaultHourlyRate < Rate # This gets an array of all the ids of the DefaultHourlyRates default_rates = DefaultHourlyRate.pluck(:id) - if date1.nil? || date2.nil? - # we have only one date, query >= - conditions = [ - 'user_id = ? AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on >= ?', - @rate.user_id, default_rates, date1 || date2 - ] - else - # we have two dates, query between - conditions = [ - 'user_id = ? AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on BETWEEN ? AND ?', - @rate.user_id, default_rates, date1, date2 - 1 - ] - end + conditions = if date1.nil? || date2.nil? + # we have only one date, query >= + [ + 'user_id = ? AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on >= ?', + @rate.user_id, default_rates, date1 || date2 + ] + else + # we have two dates, query between + [ + 'user_id = ? AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on BETWEEN ? AND ?', + @rate.user_id, default_rates, date1, date2 - 1 + ] + end TimeEntry.includes(:rate).where(conditions) end @@ -149,5 +150,4 @@ class DefaultHourlyRate < Rate end end end - end diff --git a/modules/costs/app/models/entry.rb b/modules/costs/app/models/entry.rb index d16e337900..8930e37a90 100644 --- a/modules/costs/app/models/entry.rb +++ b/modules/costs/app/models/entry.rb @@ -27,7 +27,7 @@ #++ module Entry - [TimeEntry, CostEntry].each do |e| e.send :include, self end + [TimeEntry, CostEntry].each { |e| e.send :include, self } class Delegator < ApplicationRecord self.abstract_class = true @@ -65,9 +65,9 @@ module Entry def find_last(options) find_one :find_last, options end - def find_every(options) find_many :find_every, options end + def find_every(options) find_many :find_every, options end - def find_from_ids(_args, options) find_many :find_from_ids, options end + def find_from_ids(_args, options) find_many :find_from_ids, options end def find_one(*args) TimeEntry.send(*args) || CostEntry.send(*args) diff --git a/modules/costs/app/models/hourly_rate.rb b/modules/costs/app/models/hourly_rate.rb index 1c86260c5e..f6d803bc51 100644 --- a/modules/costs/app/models/hourly_rate.rb +++ b/modules/costs/app/models/hourly_rate.rb @@ -27,7 +27,7 @@ #++ class HourlyRate < Rate - validates_uniqueness_of :valid_from, scope: [:user_id, :project_id] + validates_uniqueness_of :valid_from, scope: %i[user_id project_id] validates_presence_of :user_id, :project_id, :valid_from validate :change_of_user_only_on_first_creation @@ -99,7 +99,7 @@ class HourlyRate < Rate def change_of_user_only_on_first_creation # Only allow change of project and user on first creation - return if self.new_record? + return if new_record? errors.add :project_id, :invalid if project_id_changed? errors.add :user_id, :invalid if user_id_changed? diff --git a/modules/costs/app/models/rate.rb b/modules/costs/app/models/rate.rb index 3140ce3d93..2b5555f102 100644 --- a/modules/costs/app/models/rate.rb +++ b/modules/costs/app/models/rate.rb @@ -66,10 +66,10 @@ class Rate < ApplicationRecord next_rate = self.next # get entries from the current project - entries = o.find_entries(valid_from, (next_rate&.valid_from)) + entries = o.find_entries(valid_from, next_rate&.valid_from) # and entries from subprojects that need updating (only applies to hourly_rates) - entries += o.orphaned_child_entries(valid_from, (next_rate&.valid_from)) + entries += o.orphaned_child_entries(valid_from, next_rate&.valid_from) o.update_entries(entries) end @@ -81,6 +81,7 @@ class Rate < ApplicationRecord # We have not moved a rate, maybe just changed the rate value return unless saved_change_to_rate? + # Only the rate value was changed so just update the currently assigned entries return rate_created end @@ -105,7 +106,7 @@ class Rate < ApplicationRecord # and entries from subprojects that need updating (only applies to hourly_rates) entries += o.child_entries(valid_from_was, valid_from) - o.update_entries(entries, (valid_from_was < valid_from) ? previous : self) + o.update_entries(entries, valid_from_was < valid_from ? previous : self) end end @@ -145,12 +146,10 @@ class Rate < ApplicationRecord if @rate.is_a?(HourlyRate) { date_column => date1..(date2 - 1), user_id: @rate.user_id, - project_id: @rate.project_id - } + project_id: @rate.project_id } else { date_column => date1..(date2 - 1), - cost_type_id: @rate.cost_type_id, - } + cost_type_id: @rate.cost_type_id } end end @@ -187,19 +186,19 @@ class Rate < ApplicationRecord # This gets an array of all the ids of the DefaultHourlyRates default_rates = DefaultHourlyRate.pluck(:id) - if date1.nil? || date2.nil? - # we have only one date, query >= - conditions = [ - 'user_id = ? AND project_id IN (?) AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on >= ?', - @rate.user_id, @rate.project.descendants.to_a, default_rates, date1 || date2 - ] - else - # we have two dates, query between - conditions = [ - 'user_id = ? AND project_id IN (?) AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on BETWEEN ? AND ?', - @rate.user_id, @rate.project.descendants.to_a, default_rates, date1, date2 - ] - end + conditions = if date1.nil? || date2.nil? + # we have only one date, query >= + [ + 'user_id = ? AND project_id IN (?) AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on >= ?', + @rate.user_id, @rate.project.descendants.to_a, default_rates, date1 || date2 + ] + else + # we have two dates, query between + [ + 'user_id = ? AND project_id IN (?) AND (rate_id IN (?) OR rate_id IS NULL) AND spent_on BETWEEN ? AND ?', + @rate.user_id, @rate.project.descendants.to_a, default_rates, date1, date2 + ] + end TimeEntry.includes(:rate).where(conditions) end @@ -212,19 +211,19 @@ class Rate < ApplicationRecord (date1, date2) = order_dates(date1, date2) - if date1.nil? || date2.nil? - # we have only one date, query >= - conditions = [ - 'user_id = ? AND project_id IN (?) AND rate_id = ? AND spent_on >= ?', - @rate.user_id, @rate.project.descendants.to_a, @rate.id, date1 || date2 - ] - else - # we have two dates, query between - conditions = [ - 'user_id = ? AND project_id IN (?) AND rate_id = ? AND spent_on BETWEEN ? AND ?', - @rate.user_id, @rate.project.descendants.to_a, @rate.id, date1, date2 - ] - end + conditions = if date1.nil? || date2.nil? + # we have only one date, query >= + [ + 'user_id = ? AND project_id IN (?) AND rate_id = ? AND spent_on >= ?', + @rate.user_id, @rate.project.descendants.to_a, @rate.id, date1 || date2 + ] + else + # we have two dates, query between + [ + 'user_id = ? AND project_id IN (?) AND rate_id = ? AND spent_on BETWEEN ? AND ?', + @rate.user_id, @rate.project.descendants.to_a, @rate.id, date1, date2 + ] + end TimeEntry.includes(:rate).where(conditions) end diff --git a/modules/costs/app/models/time_entries/scopes/of_user_and_day.rb b/modules/costs/app/models/time_entries/scopes/of_user_and_day.rb index 83a7b51d35..e02f9e3869 100644 --- a/modules/costs/app/models/time_entries/scopes/of_user_and_day.rb +++ b/modules/costs/app/models/time_entries/scopes/of_user_and_day.rb @@ -44,7 +44,6 @@ module TimeEntries::Scopes scope end - end end end diff --git a/modules/costs/app/models/time_entry.rb b/modules/costs/app/models/time_entry.rb index 771a81506f..6a984fa5bb 100644 --- a/modules/costs/app/models/time_entry.rb +++ b/modules/costs/app/models/time_entry.rb @@ -61,7 +61,7 @@ class TimeEntry < ApplicationRecord def self.update_all(updates, conditions = nil, options = {}) # instead of a update_all, perform an individual update during work_package#move # to trigger the update of the costs based on new rates - if conditions.respond_to?(:keys) && conditions.keys == [:work_package_id] && updates =~ /^project_id = ([\d]+)$/ + if conditions.respond_to?(:keys) && conditions.keys == [:work_package_id] && updates =~ /^project_id = (\d+)$/ project_id = $1 time_entries = TimeEntry.where(conditions) time_entries.each do |entry| diff --git a/modules/costs/app/models/work_package/abstract_costs.rb b/modules/costs/app/models/work_package/abstract_costs.rb index 125039ff24..7b4954c088 100644 --- a/modules/costs/app/models/work_package/abstract_costs.rb +++ b/modules/costs/app/models/work_package/abstract_costs.rb @@ -1,7 +1,6 @@ class WorkPackage class AbstractCosts - attr_reader :user - attr_reader :project + attr_reader :user, :project def initialize(user: User.current, project: nil) @user = user diff --git a/modules/costs/app/seeders/basic_data/costs/type_seeder.rb b/modules/costs/app/seeders/basic_data/costs/type_seeder.rb index 21a0205b17..fd3f6d1361 100644 --- a/modules/costs/app/seeders/basic_data/costs/type_seeder.rb +++ b/modules/costs/app/seeders/basic_data/costs/type_seeder.rb @@ -13,10 +13,10 @@ module BasicData # hidden, default, visible def costs_visibility_table { - overall_costs: [1, 1, 1, 1, 1, 1, 1], + overall_costs: [1, 1, 1, 1, 1, 1, 1], material_costs: [1, 1, 1, 1, 1, 1, 1], # unit costs - labor_costs: [1, 1, 1, 1, 1, 1, 1], - budget: [1, 1, 1, 1, 1, 1, 1] # budget + labor_costs: [1, 1, 1, 1, 1, 1, 1], + budget: [1, 1, 1, 1, 1, 1, 1] # budget } end end diff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rb index d1c0621b73..8051681cab 100644 --- a/modules/costs/config/routes.rb +++ b/modules/costs/config/routes.rb @@ -28,9 +28,9 @@ OpenProject::Application.routes.draw do scope 'projects/:project_id', as: 'projects' do - resources :cost_entries, controller: 'costlog', only: [:new, :create] + resources :cost_entries, controller: 'costlog', only: %i[new create] - resources :hourly_rates, only: [:show, :edit, :update] do + resources :hourly_rates, only: %i[show edit update] do post :set_rate, on: :member end end @@ -39,9 +39,9 @@ OpenProject::Application.routes.draw do resources :cost_entries, controller: 'costlog', only: %i[new] end - resources :cost_entries, controller: 'costlog', only: [:edit, :update, :destroy] + resources :cost_entries, controller: 'costlog', only: %i[edit update destroy] - resources :cost_types, only: [:index, :new, :edit, :update, :create, :destroy] do + resources :cost_types, only: %i[index new edit update create destroy] do member do # TODO: check if this can be replaced with update method put :set_rate @@ -50,5 +50,5 @@ OpenProject::Application.routes.draw do end # TODO: this is a duplicate from a route defined under project/:project_id, check whether we really want to do that - resources :hourly_rates, only: [:edit, :update] + resources :hourly_rates, only: %i[edit update] end diff --git a/modules/costs/db/migrate/20180323133404_to_v710_aggregated_costs_migrations.rb b/modules/costs/db/migrate/20180323133404_to_v710_aggregated_costs_migrations.rb index db5498fca7..e101ec4ec4 100644 --- a/modules/costs/db/migrate/20180323133404_to_v710_aggregated_costs_migrations.rb +++ b/modules/costs/db/migrate/20180323133404_to_v710_aggregated_costs_migrations.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require Rails.root.join("db","migrate","migration_utils","migration_squasher").to_s +require Rails.root.join("db", "migrate", "migration_utils", "migration_squasher").to_s # This migration aggregates the migrations detailed in MIGRATION_FILES class ToV710AggregatedCostsMigrations < ActiveRecord::Migration[5.1] - MIGRATION_FILES = <<-MIGRATIONS 20121022124254_aggregated_costs_migrations.rb 20130529145329_remove_signoff_from_cost_objects.rb @@ -49,12 +48,12 @@ class ToV710AggregatedCostsMigrations < ActiveRecord::Migration[5.1] t.integer 'project_id', null: false t.integer 'work_package_id', null: false t.integer 'cost_type_id', null: false - t.float 'units', null: false - t.date 'spent_on', null: false + t.float 'units', null: false + t.date 'spent_on', null: false t.datetime 'created_on', null: false t.datetime 'updated_on', null: false - t.string 'comments', null: false - t.boolean 'blocked', default: false, null: false + t.string 'comments', null: false + t.boolean 'blocked', default: false, null: false t.decimal 'overridden_costs', precision: 15, scale: 4 t.decimal 'costs', precision: 15, scale: 4 t.integer 'rate_id' @@ -66,44 +65,44 @@ class ToV710AggregatedCostsMigrations < ActiveRecord::Migration[5.1] create_table 'cost_objects', id: :integer do |t| t.integer 'project_id', null: false t.integer 'author_id', null: false - t.string 'subject', null: false - t.text 'description', null: false - t.string 'type', null: false - t.date 'fixed_date', null: false + t.string 'subject', null: false + t.text 'description', null: false + t.string 'type', null: false + t.date 'fixed_date', null: false t.datetime 'created_on' t.datetime 'updated_on' end - add_index :cost_objects, [:project_id, :updated_on] + add_index :cost_objects, %i[project_id updated_on] create_table 'cost_types', id: :integer do |t| t.string 'name', null: false t.string 'unit', null: false t.string 'unit_plural', null: false - t.boolean 'default', default: false, null: false + t.boolean 'default', default: false, null: false t.datetime 'deleted_at' end create_table 'labor_budget_items', id: :integer do |t| - t.integer 'cost_object_id', null: false - t.float 'hours', null: false + t.integer 'cost_object_id', null: false + t.float 'hours', null: false t.integer 'user_id' - t.string 'comments', default: '', null: false - t.decimal 'budget', precision: 15, scale: 4 + t.string 'comments', default: '', null: false + t.decimal 'budget', precision: 15, scale: 4 end create_table 'material_budget_items', id: :integer do |t| - t.integer 'cost_object_id', null: false - t.float 'units', null: false + t.integer 'cost_object_id', null: false + t.float 'units', null: false t.integer 'cost_type_id' - t.string 'comments', default: '', null: false - t.decimal 'budget', precision: 15, scale: 4 + t.string 'comments', default: '', null: false + t.decimal 'budget', precision: 15, scale: 4 end create_table 'rates', id: :integer do |t| - t.date 'valid_from', null: false - t.decimal 'rate', precision: 15, scale: 4, null: false - t.string 'type', null: false + t.date 'valid_from', null: false + t.decimal 'rate', precision: 15, scale: 4, null: false + t.string 'type', null: false t.integer 'project_id' t.integer 'user_id' t.integer 'cost_type_id' @@ -119,7 +118,7 @@ class ToV710AggregatedCostsMigrations < ActiveRecord::Migration[5.1] t.integer :journal_id, null: false t.integer :project_id, null: false t.integer :author_id, null: false - t.string :subject, null: false + t.string :subject, null: false t.text :description t.date :fixed_date, null: false t.datetime :created_on diff --git a/modules/costs/lib/api/v3/cost_entries/cost_entries_api.rb b/modules/costs/lib/api/v3/cost_entries/cost_entries_api.rb index cbd8a74b23..31554f8496 100644 --- a/modules/costs/lib/api/v3/cost_entries/cost_entries_api.rb +++ b/modules/costs/lib/api/v3/cost_entries/cost_entries_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/costs/lib/api/v3/cost_entries/cost_entries_by_work_package_api.rb b/modules/costs/lib/api/v3/cost_entries/cost_entries_by_work_package_api.rb index 6d1a9de4c2..4133abd5c9 100644 --- a/modules/costs/lib/api/v3/cost_entries/cost_entries_by_work_package_api.rb +++ b/modules/costs/lib/api/v3/cost_entries/cost_entries_by_work_package_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -34,7 +35,7 @@ module API module CostEntries class CostEntriesByWorkPackageAPI < ::API::OpenProjectAPI after_validation do - authorize_any([:view_cost_entries, :view_own_cost_entries], + authorize_any(%i[view_cost_entries view_own_cost_entries], projects: @work_package.project) @cost_helper = ::Costs::AttributesHelper.new(@work_package, current_user) end diff --git a/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb b/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb index cf5e9890a2..e34b618e27 100644 --- a/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb +++ b/modules/costs/lib/api/v3/cost_entries/cost_entry_collection_representer.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/costs/lib/api/v3/cost_types/cost_types_api.rb b/modules/costs/lib/api/v3/cost_types/cost_types_api.rb index df148ea0b4..e49c5a871e 100644 --- a/modules/costs/lib/api/v3/cost_types/cost_types_api.rb +++ b/modules/costs/lib/api/v3/cost_types/cost_types_api.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +36,7 @@ module API class CostTypesAPI < ::API::OpenProjectAPI resources :cost_types do after_validation do - authorize_any([:view_cost_entries, :view_own_cost_entries], + authorize_any(%i[view_cost_entries view_own_cost_entries], global: true, user: current_user) end diff --git a/modules/costs/spec/controllers/costlog_controller_spec.rb b/modules/costs/spec/controllers/costlog_controller_spec.rb index 508d7754f3..999e4dc379 100644 --- a/modules/costs/spec/controllers/costlog_controller_spec.rb +++ b/modules/costs/spec/controllers/costlog_controller_spec.rb @@ -31,29 +31,29 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe CostlogController, type: :controller do include Cost::PluginSpecHelper let (:project) { FactoryBot.create(:project_with_types) } - let (:work_package) { + let (:work_package) do FactoryBot.create(:work_package, project: project, - author: user, - type: project.types.first) - } + author: user, + type: project.types.first) + end let (:user) { FactoryBot.create(:user) } let (:user2) { FactoryBot.create(:user) } - let (:controller) { FactoryBot.build(:role, permissions: [:log_costs, :edit_cost_entries]) } + let (:controller) { FactoryBot.build(:role, permissions: %i[log_costs edit_cost_entries]) } let (:cost_type) { FactoryBot.build(:cost_type) } - let (:cost_entry) { + let (:cost_entry) do FactoryBot.build(:cost_entry, work_package: work_package, - project: project, - spent_on: Date.today, - overridden_costs: 400, - units: 100, - user: user, - comments: '') - } + project: project, + spent_on: Date.today, + overridden_costs: 400, + units: 100, + user: user, + comments: '') + end let(:work_package_status) { FactoryBot.create(:work_package_status, is_default: true) } def grant_current_user_permissions(user, permissions) member = FactoryBot.build(:member, project: project, - principal: user) + principal: user) member.roles << FactoryBot.build(:role, permissions: permissions) member.principal = user member.save! @@ -235,8 +235,8 @@ describe CostlogController, type: :controller do cost_entry.project = FactoryBot.create(:project_with_types) cost_entry.work_package = FactoryBot.create(:work_package, project: cost_entry.project, - type: cost_entry.project.types.first, - author: user) + type: cost_entry.project.types.first, + author: user) cost_entry.save! end @@ -258,7 +258,7 @@ describe CostlogController, type: :controller do end describe 'POST create' do - let (:params) { + let (:params) do { 'project_id' => project.id.to_s, 'cost_entry' => { 'user_id' => user.id.to_s, 'work_package_id' => (work_package.present? ? work_package.id.to_s : ''), @@ -267,7 +267,7 @@ describe CostlogController, type: :controller do 'comments' => 'lorem', 'spent_on' => date.to_s, 'overridden_costs' => overridden_costs.to_s } } - } + end let(:expected_project) { project } let(:expected_work_package) { work_package } let(:expected_user) { user } @@ -438,11 +438,11 @@ describe CostlogController, type: :controller do describe "WHEN the user is allowed to create cost_entries WHEN the id of an work_package not included in the provided project is provided" do let(:project2) { FactoryBot.create(:project_with_types) } - let(:work_package2) { + let(:work_package2) do FactoryBot.create(:work_package, project: project2, - type: project2.types.first, - author: user) - } + type: project2.types.first, + author: user) + end let(:expected_work_package) { work_package2 } before do @@ -488,7 +488,7 @@ describe CostlogController, type: :controller do end describe 'PUT update' do - let(:params) { + let(:params) do { 'id' => cost_entry.id.to_s, 'cost_entry' => { 'comments' => 'lorem', 'work_package_id' => cost_entry.work_package.id.to_s, @@ -496,7 +496,7 @@ describe CostlogController, type: :controller do 'spent_on' => cost_entry.spent_on.to_s, 'user_id' => cost_entry.user.id.to_s, 'cost_type_id' => cost_entry.cost_type.id.to_s } } - } + end before do cost_entry.save(validate: false) @@ -548,11 +548,11 @@ describe CostlogController, type: :controller do cost_type overridden_costs spent_on" do - let(:expected_work_package) { + let(:expected_work_package) do FactoryBot.create(:work_package, project: project, - type: project.types.first, - author: user) - } + type: project.types.first, + author: user) + end let(:expected_user) { FactoryBot.create(:user) } let(:expected_spent_on) { cost_entry.spent_on + 4.days } let(:expected_units) { cost_entry.units + 20 } @@ -615,10 +615,10 @@ describe CostlogController, type: :controller do WHEN updating the work_package WHEN the new work_package isn't an work_package of the current project" do let(:project2) { FactoryBot.create(:project_with_types) } - let(:work_package2) { + let(:work_package2) do FactoryBot.create(:work_package, project: project2, - type: project2.types.first) - } + type: project2.types.first) + end let(:expected_work_package) { work_package2 } before do diff --git a/modules/costs/spec/controllers/hourly_rates_controller_spec.rb b/modules/costs/spec/controllers/hourly_rates_controller_spec.rb index 3d7aacdc9e..6ded00b20c 100644 --- a/modules/costs/spec/controllers/hourly_rates_controller_spec.rb +++ b/modules/costs/spec/controllers/hourly_rates_controller_spec.rb @@ -36,12 +36,13 @@ describe HourlyRatesController do describe 'PUT update' do describe 'WHEN trying to update with an invalid rate value' do - let(:params) { + let(:params) do { id: user.id, - user: { 'existing_rate_attributes' => { "#{default_rate.id}" => { 'valid_from' => "#{default_rate.valid_from}", 'rate' => '2d5' } } } + user: { 'existing_rate_attributes' => { default_rate.id.to_s => { 'valid_from' => default_rate.valid_from.to_s, + 'rate' => '2d5' } } } } - } + end before do as_logged_in_user admin do post :update, params: params diff --git a/modules/costs/spec/controllers/work_packages_bulk_controller_spec.rb b/modules/costs/spec/controllers/work_packages_bulk_controller_spec.rb index ce92e64774..dd919d42bb 100644 --- a/modules/costs/spec/controllers/work_packages_bulk_controller_spec.rb +++ b/modules/costs/spec/controllers/work_packages_bulk_controller_spec.rb @@ -30,7 +30,7 @@ require 'spec_helper' describe WorkPackages::BulkController, type: :controller do let(:project) { FactoryBot.create(:project_with_types) } - let(:controller_role) { FactoryBot.build(:role, permissions: [:view_work_packages, :edit_work_packages]) } + let(:controller_role) { FactoryBot.build(:role, permissions: %i[view_work_packages edit_work_packages]) } let(:user) { FactoryBot.create :user, member_in_project: project, member_through_role: controller_role } let(:budget) { FactoryBot.create :budget, project: project } let(:work_package) { FactoryBot.create(:work_package, project: project) } diff --git a/modules/costs/spec/factories/cost_type_factory.rb b/modules/costs/spec/factories/cost_type_factory.rb index 54c063407e..8e729a3639 100644 --- a/modules/costs/spec/factories/cost_type_factory.rb +++ b/modules/costs/spec/factories/cost_type_factory.rb @@ -27,8 +27,8 @@ #++ FactoryBot.define do - factory :cost_type do - sequence(:name) do |n| "ct no. #{n}" end + factory :cost_type do + sequence(:name) { |n| "ct no. #{n}" } unit { 'singular_unit' } unit_plural { 'plural_unit' } diff --git a/modules/costs/spec/features/add_cost_entry_spec.rb b/modules/costs/spec/features/add_cost_entry_spec.rb index 009f4c62ac..0ff5654770 100644 --- a/modules/costs/spec/features/add_cost_entry_spec.rb +++ b/modules/costs/spec/features/add_cost_entry_spec.rb @@ -32,29 +32,33 @@ describe 'Work Package cost fields', type: :feature, js: true do let(:type_task) { FactoryBot.create(:type_task) } let!(:status) { FactoryBot.create(:status, is_default: true) } let!(:priority) { FactoryBot.create(:priority, is_default: true) } - let!(:project) { + let!(:project) do FactoryBot.create(:project, types: [type_task]) - } - let(:user) { FactoryBot.create :user, - member_in_project: project, - member_through_role: role } - let(:role) { FactoryBot.create :role, permissions: [:view_work_packages, - :delete_work_packages, - :log_costs, - :view_cost_rates, - :edit_cost_entries, - :view_cost_entries] } - let!(:cost_type1) { + end + let(:user) do + FactoryBot.create :user, + member_in_project: project, + member_through_role: role + end + let(:role) do + FactoryBot.create :role, permissions: %i[view_work_packages + delete_work_packages + log_costs + view_cost_rates + edit_cost_entries + view_cost_entries] + end + let!(:cost_type1) do type = FactoryBot.create :cost_type, name: 'A', unit: 'A single', unit_plural: 'A plural' FactoryBot.create :cost_rate, cost_type: type, rate: 1.00 type - } + end - let!(:cost_type2) { + let!(:cost_type2) do type = FactoryBot.create :cost_type, name: 'B', unit: 'B single', unit_plural: 'B plural' FactoryBot.create :cost_rate, cost_type: type, rate: 2.00 type - } + end let!(:work_package) { FactoryBot.create :work_package, project: project, status: status, type: type_task } let(:full_view) { ::Pages::FullWorkPackage.new(work_package, project) } diff --git a/modules/costs/spec/features/cost_types/create_cost_type_spec.rb b/modules/costs/spec/features/cost_types/create_cost_type_spec.rb index fdf89b9ac2..eec3dbbec8 100644 --- a/modules/costs/spec/features/cost_types/create_cost_type_spec.rb +++ b/modules/costs/spec/features/cost_types/create_cost_type_spec.rb @@ -30,11 +30,11 @@ require 'spec_helper' describe 'creating a cost type', type: :feature, js: true do let!(:user) { FactoryBot.create :admin } - let!(:cost_type) { + let!(:cost_type) do type = FactoryBot.create :cost_type, name: 'Translations' FactoryBot.create :cost_rate, cost_type: type, rate: 1.00 type - } + end before do login_as user diff --git a/modules/costs/spec/features/cost_types/delete_cost_type_spec.rb b/modules/costs/spec/features/cost_types/delete_cost_type_spec.rb index d09c8da3a3..1bc70f05d3 100644 --- a/modules/costs/spec/features/cost_types/delete_cost_type_spec.rb +++ b/modules/costs/spec/features/cost_types/delete_cost_type_spec.rb @@ -30,11 +30,11 @@ require 'spec_helper' describe 'deleting a cost type', type: :feature, js: true do let!(:user) { FactoryBot.create :admin } - let!(:cost_type) { + let!(:cost_type) do type = FactoryBot.create :cost_type, name: 'Translations' FactoryBot.create :cost_rate, cost_type: type, rate: 1.00 type - } + end before do login_as user diff --git a/modules/costs/spec/features/destroy_work_package_with_cost_entries_spec.rb b/modules/costs/spec/features/destroy_work_package_with_cost_entries_spec.rb index ad20115161..bbbe7e787c 100644 --- a/modules/costs/spec/features/destroy_work_package_with_cost_entries_spec.rb +++ b/modules/costs/spec/features/destroy_work_package_with_cost_entries_spec.rb @@ -37,10 +37,10 @@ describe 'Deleting time entries', type: :feature, js: true do end let(:role) do FactoryBot.create :role, - permissions: [:view_work_packages, - :delete_work_packages, - :edit_cost_entries, - :view_cost_entries] + permissions: %i[view_work_packages + delete_work_packages + edit_cost_entries + view_cost_entries] end let(:work_package) { FactoryBot.create :work_package } let(:destroy_modal) { Components::WorkPackages::DestroyModal.new } diff --git a/modules/costs/spec/features/members_hourly_rates_spec.rb b/modules/costs/spec/features/members_hourly_rates_spec.rb index 6a39a2b6b9..292cd94327 100644 --- a/modules/costs/spec/features/members_hourly_rates_spec.rb +++ b/modules/costs/spec/features/members_hourly_rates_spec.rb @@ -51,7 +51,7 @@ describe 'hourly rates on a member', type: :feature, js: true do expect(page).to have_selector("#member-#{member.id} .currency", text: amount) end - def add_rate(date: nil, rate:) + def add_rate(rate:, date: nil) expect(page).to have_selector(".add-row-button") sleep(0.1) all("tr[id^='user_new_rate_attributes_'] .delete-row-button").each(&:click) diff --git a/modules/costs/spec/features/view_own_rates_spec.rb b/modules/costs/spec/features/view_own_rates_spec.rb index 03ad0e7ab9..d3a342f937 100644 --- a/modules/costs/spec/features/view_own_rates_spec.rb +++ b/modules/costs/spec/features/view_own_rates_spec.rb @@ -30,50 +30,68 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe 'Only see your own rates', type: :feature, js: true do let(:project) { work_package.project } - let(:user) { FactoryBot.create :user, - member_in_project: project, - member_through_role: role } - let(:role) { FactoryBot.create :role, permissions: [:view_own_hourly_rate, - :view_work_packages, - :view_work_packages, - :view_own_time_entries, - :view_own_cost_entries, - :view_cost_rates, - :log_costs] } - let(:work_package) {FactoryBot.create :work_package } + let(:user) do + FactoryBot.create :user, + member_in_project: project, + member_through_role: role + end + let(:role) do + FactoryBot.create :role, permissions: %i[view_own_hourly_rate + view_work_packages + view_work_packages + view_own_time_entries + view_own_cost_entries + view_cost_rates + log_costs] + end + let(:work_package) { FactoryBot.create :work_package } let(:wp_page) { ::Pages::FullWorkPackage.new(work_package) } - let(:hourly_rate) { FactoryBot.create :default_hourly_rate, user: user, - rate: 10.00 } - let(:time_entry) { FactoryBot.create :time_entry, user: user, - work_package: work_package, - project: project, - hours: 1.00 } - let(:cost_type) { + let(:hourly_rate) do + FactoryBot.create :default_hourly_rate, user: user, + rate: 10.00 + end + let(:time_entry) do + FactoryBot.create :time_entry, user: user, + work_package: work_package, + project: project, + hours: 1.00 + end + let(:cost_type) do type = FactoryBot.create :cost_type, name: 'Translations' FactoryBot.create :cost_rate, cost_type: type, - rate: 7.00 + rate: 7.00 type - } - let(:cost_entry) { FactoryBot.create :cost_entry, work_package: work_package, - project: project, - units: 2.00, - cost_type: cost_type, - user: user } + end + let(:cost_entry) do + FactoryBot.create :cost_entry, work_package: work_package, + project: project, + units: 2.00, + cost_type: cost_type, + user: user + end let(:other_role) { FactoryBot.create :role, permissions: [] } - let(:other_user) { FactoryBot.create :user, - member_in_project: project, - member_through_role: other_role } - let(:other_hourly_rate) { FactoryBot.create :default_hourly_rate, user: other_user, - rate: 11.00 } - let(:other_time_entry) { FactoryBot.create :time_entry, user: other_user, - hours: 3.00, - project: project, - work_package: work_package } - let(:other_cost_entry) { FactoryBot.create :cost_entry, work_package: work_package, - project: project, - units: 5.00, - user: other_user, - cost_type: cost_type } + let(:other_user) do + FactoryBot.create :user, + member_in_project: project, + member_through_role: other_role + end + let(:other_hourly_rate) do + FactoryBot.create :default_hourly_rate, user: other_user, + rate: 11.00 + end + let(:other_time_entry) do + FactoryBot.create :time_entry, user: other_user, + hours: 3.00, + project: project, + work_package: work_package + end + let(:other_cost_entry) do + FactoryBot.create :cost_entry, work_package: work_package, + project: project, + units: 5.00, + user: other_user, + cost_type: cost_type + end before do login_as(user) diff --git a/modules/costs/spec/lib/api/v3/cost_entries/work_package_costs_by_type_representer_spec.rb b/modules/costs/spec/lib/api/v3/cost_entries/work_package_costs_by_type_representer_spec.rb index 522f8229c6..631b844a6f 100644 --- a/modules/costs/spec/lib/api/v3/cost_entries/work_package_costs_by_type_representer_spec.rb +++ b/modules/costs/spec/lib/api/v3/cost_entries/work_package_costs_by_type_representer_spec.rb @@ -35,25 +35,25 @@ describe ::API::V3::CostEntries::WorkPackageCostsByTypeRepresenter do let(:work_package) { FactoryBot.create(:work_package, project: project) } let(:cost_type_A) { FactoryBot.create(:cost_type) } let(:cost_type_B) { FactoryBot.create(:cost_type) } - let(:cost_entries_A) { + let(:cost_entries_A) do FactoryBot.create_list(:cost_entry, - 2, - units: 1, - work_package: work_package, - project: project, - cost_type: cost_type_A) - } - let(:cost_entries_B) { + 2, + units: 1, + work_package: work_package, + project: project, + cost_type: cost_type_A) + end + let(:cost_entries_B) do FactoryBot.create_list(:cost_entry, - 3, - units: 2, - work_package: work_package, - project: project, - cost_type: cost_type_B) - } - let(:current_user) { + 3, + units: 2, + work_package: work_package, + project: project, + cost_type: cost_type_B) + end + let(:current_user) do FactoryBot.build(:user, member_in_project: project, member_through_role: role) - } + end let(:role) { FactoryBot.build(:role, permissions: [:view_cost_entries]) } let(:representer) { described_class.new(work_package, current_user: current_user) } @@ -77,16 +77,16 @@ describe ::API::V3::CostEntries::WorkPackageCostsByTypeRepresenter do it 'indicates the cost types' do elements = JSON.parse(subject)['_embedded']['elements'] types = elements.map { |entry| entry['_links']['costType']['href'] } - expect(types).to include(api_v3_paths.cost_type cost_type_A.id) - expect(types).to include(api_v3_paths.cost_type cost_type_B.id) + expect(types).to include(api_v3_paths.cost_type(cost_type_A.id)) + expect(types).to include(api_v3_paths.cost_type(cost_type_B.id)) end it 'aggregates the units' do elements = JSON.parse(subject)['_embedded']['elements'] - units_by_type = elements.inject({}) { |hash, entry| + units_by_type = elements.inject({}) do |hash, entry| hash[entry['_links']['costType']['href']] = entry['spentUnits'] hash - } + end expect(units_by_type[api_v3_paths.cost_type cost_type_A.id]).to eql 2.0 expect(units_by_type[api_v3_paths.cost_type cost_type_B.id]).to eql 6.0 diff --git a/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb index 849902a6fa..4ff51f5464 100644 --- a/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb +++ b/modules/costs/spec/lib/api/v3/work_packages/work_package_representer_spec.rb @@ -33,10 +33,10 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do let(:project) { FactoryBot.create(:project) } let(:role) do - FactoryBot.create(:role, permissions: [:view_time_entries, - :view_cost_entries, - :view_cost_rates, - :view_work_packages]) + FactoryBot.create(:role, permissions: %i[view_time_entries + view_cost_entries + view_cost_rates + view_work_packages]) end let(:user) do FactoryBot.create(:user, @@ -139,8 +139,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do context 'only view_own_time_entries permission' do let(:own_time_entries_role) do - FactoryBot.create(:role, permissions: [:view_own_time_entries, - :view_work_packages]) + FactoryBot.create(:role, permissions: %i[view_own_time_entries + view_work_packages]) end let(:user2) do diff --git a/modules/costs/spec/models/cost_entry_spec.rb b/modules/costs/spec/models/cost_entry_spec.rb index a964eb620b..d8250ec5cc 100644 --- a/modules/costs/spec/models/cost_entry_spec.rb +++ b/modules/costs/spec/models/cost_entry_spec.rb @@ -33,38 +33,38 @@ describe CostEntry, type: :model do let(:project) { FactoryBot.create(:project_with_types) } let(:project2) { FactoryBot.create(:project_with_types) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, project: project, - type: project.types.first, - author: user) - } - let(:work_package2) { + type: project.types.first, + author: user) + end + let(:work_package2) do FactoryBot.create(:work_package, project: project2, - type: project2.types.first, - author: user) - } + type: project2.types.first, + author: user) + end let(:user) { FactoryBot.create(:user) } let(:user2) { FactoryBot.create(:user) } let(:klass) { CostEntry } let(:cost_entry) do member FactoryBot.build(:cost_entry, cost_type: cost_type, - project: project, - work_package: work_package, - spent_on: date, - units: units, - user: user, - comments: 'lorem') + project: project, + work_package: work_package, + spent_on: date, + units: units, + user: user, + comments: 'lorem') end let(:cost_entry2) do FactoryBot.build(:cost_entry, cost_type: cost_type, - project: project, - work_package: work_package, - spent_on: date, - units: units, - user: user, - comments: 'lorem') + project: project, + work_package: work_package, + spent_on: date, + units: units, + user: user, + comments: 'lorem') end let(:cost_type) do @@ -76,23 +76,23 @@ describe CostEntry, type: :model do cost_type.reload cost_type end - let(:first_rate) { + let(:first_rate) do FactoryBot.build(:cost_rate, valid_from: date - 6.days, - rate: 10.0) - } - let(:second_rate) { + rate: 10.0) + end + let(:second_rate) do FactoryBot.build(:cost_rate, valid_from: date - 4.days, - rate: 100.0) - } - let(:third_rate) { + rate: 100.0) + end + let(:third_rate) do FactoryBot.build(:cost_rate, valid_from: date - 2.days, - rate: 1000.0) - } - let(:member) { + rate: 1000.0) + end + let(:member) do FactoryBot.create(:member, project: project, - roles: [role], - principal: user) - } + roles: [role], + principal: user) + end let(:role) { FactoryBot.create(:role, permissions: []) } let(:units) { 5.0 } let(:date) { Date.today } @@ -151,11 +151,11 @@ describe CostEntry, type: :model do describe 'instance' do describe '#costs' do - let(:fourth_rate) { + let(:fourth_rate) do FactoryBot.build(:cost_rate, valid_from: date - 1.days, - rate: 10000.0, - cost_type: cost_type) - } + rate: 10000.0, + cost_type: cost_type) + end describe 'WHEN updating the number of units' do before do diff --git a/modules/costs/spec/models/cost_type_spec.rb b/modules/costs/spec/models/cost_type_spec.rb index 9734c5ddc5..0b1242d52a 100644 --- a/modules/costs/spec/models/cost_type_spec.rb +++ b/modules/costs/spec/models/cost_type_spec.rb @@ -30,11 +30,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb') describe CostType, type: :model do let(:klass) { CostType } - let(:cost_type) { + let(:cost_type) do klass.new name: 'ct1', unit: 'singular', unit_plural: 'plural' - } + end before do # as the spec_helper loads fixtures and they are probably needed by other tests # we delete them here so they do not interfere. diff --git a/modules/costs/spec/models/default_hourly_rate_spec.rb b/modules/costs/spec/models/default_hourly_rate_spec.rb index 30ad1acf79..36960914ba 100644 --- a/modules/costs/spec/models/default_hourly_rate_spec.rb +++ b/modules/costs/spec/models/default_hourly_rate_spec.rb @@ -31,10 +31,10 @@ require File.dirname(__FILE__) + '/../spec_helper' describe DefaultHourlyRate, type: :model do let(:project) { FactoryBot.create(:project) } let(:user) { FactoryBot.create(:user) } - let(:rate) { + let(:rate) do FactoryBot.build(:default_hourly_rate, project: project, - user: user) - } + user: user) + end describe '#user' do describe 'WHEN an existing user is provided' do diff --git a/modules/costs/spec/models/hourly_rate_spec.rb b/modules/costs/spec/models/hourly_rate_spec.rb index 2e6567f825..9a8a68faf0 100644 --- a/modules/costs/spec/models/hourly_rate_spec.rb +++ b/modules/costs/spec/models/hourly_rate_spec.rb @@ -31,10 +31,10 @@ require File.dirname(__FILE__) + '/../spec_helper' describe HourlyRate, type: :model do let(:project) { FactoryBot.create(:project) } let(:user) { FactoryBot.create(:user) } - let(:rate) { + let(:rate) do FactoryBot.build(:hourly_rate, project: project, - user: user) - } + user: user) + end describe '#user' do describe 'WHEN an existing user is provided' do diff --git a/modules/costs/spec/models/permitted_params_spec.rb b/modules/costs/spec/models/permitted_params_spec.rb index cd66697635..f079a26321 100644 --- a/modules/costs/spec/models/permitted_params_spec.rb +++ b/modules/costs/spec/models/permitted_params_spec.rb @@ -26,7 +26,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../spec_helper', __dir__) describe PermittedParams, type: :model do let(:user) { FactoryBot.build(:user) } @@ -122,7 +122,8 @@ describe PermittedParams, type: :model do context 'new_rate_attributes' do let(:hash) do - { 'new_rate_attributes' => { '0' => { 'valid_from' => '2013-05-08', 'rate' => '5002' }, '1' => { 'valid_from' => '2013-05-10', 'rate' => '5004' } } } + { 'new_rate_attributes' => { '0' => { 'valid_from' => '2013-05-08', 'rate' => '5002' }, + '1' => { 'valid_from' => '2013-05-10', 'rate' => '5004' } } } end it_behaves_like 'allows params' diff --git a/modules/costs/spec/models/project/activity_spec.rb b/modules/costs/spec/models/project/activity_spec.rb index ece98cca1b..33f5af723d 100644 --- a/modules/costs/spec/models/project/activity_spec.rb +++ b/modules/costs/spec/models/project/activity_spec.rb @@ -37,17 +37,17 @@ describe Projects::Activity, type: :model do let(:budget) do FactoryBot.create(:budget, - project: project) + project: project) end let(:budget2) do FactoryBot.create(:budget, - project: project) + project: project) end let(:work_package) do FactoryBot.create(:work_package, - project: project) + project: project) end def latest_activity diff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rb index 1183fcb77e..21e6330da4 100644 --- a/modules/costs/spec/models/time_entry_spec.rb +++ b/modules/costs/spec/models/time_entry_spec.rb @@ -35,13 +35,13 @@ describe TimeEntry, type: :model do let(:project2) { FactoryBot.create(:project_with_types, public: false) } let(:work_package) do FactoryBot.create(:work_package, project: project, - type: project.types.first, - author: user) + type: project.types.first, + author: user) end let(:work_package2) do FactoryBot.create(:work_package, project: project2, - type: project2.types.first, - author: user2) + type: project2.types.first, + author: user2) end let(:user) { FactoryBot.create(:user) } let(:user2) { FactoryBot.create(:user) } diff --git a/modules/costs/spec/models/user_deletion_spec.rb b/modules/costs/spec/models/user_deletion_spec.rb index 724a9dec71..a4732c420a 100644 --- a/modules/costs/spec/models/user_deletion_spec.rb +++ b/modules/costs/spec/models/user_deletion_spec.rb @@ -153,19 +153,19 @@ describe User, '#destroy', type: :model do describe 'WHEN the user has a cost entry' do let(:work_package) { FactoryBot.create(:work_package) } - let(:entry) { + let(:entry) do FactoryBot.create(:cost_entry, user: user, project: work_package.project, units: 100.0, spent_on: Date.today, work_package: work_package, comments: '') - } + end before do FactoryBot.create(:member, project: work_package.project, - user: user, - roles: [FactoryBot.build(:role)]) + user: user, + roles: [FactoryBot.build(:role)]) entry user.destroy @@ -177,10 +177,10 @@ describe User, '#destroy', type: :model do end describe 'WHEN the user is assigned an hourly rate' do - let(:hourly_rate) { + let(:hourly_rate) do FactoryBot.build(:hourly_rate, user: user, - project: project) - } + project: project) + end before do hourly_rate.save! @@ -192,10 +192,10 @@ describe User, '#destroy', type: :model do end describe 'WHEN the user is assigned a default hourly rate' do - let(:default_hourly_rate) { + let(:default_hourly_rate) do FactoryBot.build(:default_hourly_rate, user: user, - project: project) - } + project: project) + end before do default_hourly_rate.save! diff --git a/modules/costs/spec/models/user_spec.rb b/modules/costs/spec/models/user_spec.rb index 0ceeec3274..5f091e9caf 100644 --- a/modules/costs/spec/models/user_spec.rb +++ b/modules/costs/spec/models/user_spec.rb @@ -34,10 +34,10 @@ describe User, type: :model do let(:user) { FactoryBot.build(:user) } let(:project) { FactoryBot.build(:valid_project) } let(:project2) { FactoryBot.build(:valid_project) } - let(:project_hourly_rate) { + let(:project_hourly_rate) do FactoryBot.build(:hourly_rate, user: user, - project: project) - } + project: project) + end let(:default_hourly_rate) { FactoryBot.build(:default_hourly_rate, user: user) } describe '#allowed_to' do @@ -114,10 +114,10 @@ describe User, type: :model do describe "WHEN providing a project WHEN providing attributes for an existing rate in the project" do - let(:new_attributes) { + let(:new_attributes) do { project_hourly_rate.id.to_s => { valid_from: (Date.today + 1.day).to_s, rate: (project_hourly_rate.rate + 5).to_s } } - } + end before do project_hourly_rate.save! @@ -127,11 +127,15 @@ describe User, type: :model do end it 'should update the rate' do - expect(user.rates.detect { |r| r.id == project_hourly_rate.id }.rate).to eq(new_attributes[project_hourly_rate.id.to_s][:rate].to_i) + expect(user.rates.detect do |r| + r.id == project_hourly_rate.id + end.rate).to eq(new_attributes[project_hourly_rate.id.to_s][:rate].to_i) end it 'should update valid_from' do - expect(user.rates.detect { |r| r.id == project_hourly_rate.id }.valid_from).to eq(new_attributes[project_hourly_rate.id.to_s][:valid_from].to_date) + expect(user.rates.detect do |r| + r.id == project_hourly_rate.id + end.valid_from).to eq(new_attributes[project_hourly_rate.id.to_s][:valid_from].to_date) end it 'should not create a rate' do @@ -141,10 +145,10 @@ describe User, type: :model do describe "WHEN providing a project WHEN providing attributes for an existing rate in another project" do - let(:new_attributes) { + let(:new_attributes) do { project_hourly_rate.id.to_s => { valid_from: (Date.today + 1.day).to_s, rate: (project_hourly_rate.rate + 5).to_s } } - } + end before do project_hourly_rate.save! diff --git a/modules/costs/spec/models/work_package/ask_before_destruction_spec.rb b/modules/costs/spec/models/work_package/ask_before_destruction_spec.rb index f7abcf261a..803962c74f 100644 --- a/modules/costs/spec/models/work_package/ask_before_destruction_spec.rb +++ b/modules/costs/spec/models/work_package/ask_before_destruction_spec.rb @@ -29,14 +29,14 @@ require 'spec_helper' describe WorkPackage, type: :model do - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, project: project, - status: status) - } - let(:work_package2) { + status: status) + end + let(:work_package2) do FactoryBot.create(:work_package, project: project2, - status: status) - } + status: status) + end let(:user) { FactoryBot.create(:user) } let(:type) { FactoryBot.create(:type_standard) } @@ -44,28 +44,28 @@ describe WorkPackage, type: :model do let(:project2) { FactoryBot.create(:project, types: [type]) } let(:role) { FactoryBot.create(:role) } let(:role2) { FactoryBot.create(:role) } - let(:member) { + let(:member) do FactoryBot.create(:member, principal: user, - roles: [role]) - } - let(:member2) { + roles: [role]) + end + let(:member2) do FactoryBot.create(:member, principal: user, - roles: [role2], - project: work_package2.project) - } + roles: [role2], + project: work_package2.project) + end let(:status) { FactoryBot.create(:status) } let(:priority) { FactoryBot.create(:priority) } let(:cost_type) { FactoryBot.create(:cost_type) } - let(:cost_entry) { + let(:cost_entry) do FactoryBot.create(:cost_entry, work_package: work_package, project: work_package.project, cost_type: cost_type) - } - let(:cost_entry2) { + end + let(:cost_entry2) do FactoryBot.create(:cost_entry, work_package: work_package2, project: work_package2.project, cost_type: cost_type) - } + end describe '#cleanup_action_required_before_destructing?' do describe 'w/ the work package having a cost entry' do @@ -197,7 +197,10 @@ describe WorkPackage, type: :model do describe 'w/ "reassign" as action w/ reassigning to a valid work_package' do - let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', reassign_to_id: work_package2.id) } + let(:action) do + WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', + reassign_to_id: work_package2.id) + end before do work_package2.save! @@ -227,7 +230,10 @@ describe WorkPackage, type: :model do describe 'w/ "reassign" as action w/ reassigning to a work_package the user is not allowed to see' do - let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', reassign_to_id: work_package2.id) } + let(:action) do + WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', + reassign_to_id: work_package2.id) + end before do work_package2.save! @@ -247,7 +253,9 @@ describe WorkPackage, type: :model do describe 'w/ "reassign" as action w/ reassigning to a non existing work package' do - let(:action) { WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', reassign_to_id: 0) } + let(:action) do + WorkPackage.cleanup_associated_before_destructing_if_required(work_package, user, action: 'reassign', reassign_to_id: 0) + end it 'should return true' do expect(action).to be_falsey diff --git a/modules/costs/spec/models/work_package_spec.rb b/modules/costs/spec/models/work_package_spec.rb index ba5a4e80ee..bfb9d7ea2d 100644 --- a/modules/costs/spec/models/work_package_spec.rb +++ b/modules/costs/spec/models/work_package_spec.rb @@ -38,12 +38,15 @@ describe WorkPackage, type: :model do end let(:project2) { FactoryBot.create(:project_with_types, types: project.types) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, project: project, - type: project.types.first, - author: user) - } - let!(:cost_entry) { FactoryBot.create(:cost_entry, work_package: work_package, project: project, units: 3, spent_on: Date.today, user: user, comments: 'test entry') } + type: project.types.first, + author: user) + end + let!(:cost_entry) do + FactoryBot.create(:cost_entry, work_package: work_package, project: project, units: 3, spent_on: Date.today, user: user, + comments: 'test entry') + end let!(:budget) { FactoryBot.create(:budget, project: project) } def move_to_project(work_package, project) diff --git a/modules/costs/spec/plugin_spec_helper.rb b/modules/costs/spec/plugin_spec_helper.rb index 271ec601da..1273baa705 100644 --- a/modules/costs/spec/plugin_spec_helper.rb +++ b/modules/costs/spec/plugin_spec_helper.rb @@ -32,8 +32,8 @@ module Cost role = ::FactoryBot.create(:role, permissions: permissions) ::FactoryBot.create(:member, project: project, - principal: user, - roles: [role]) + principal: user, + roles: [role]) user.reload end end diff --git a/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb b/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb index e534a9950c..d8cf4a14a1 100644 --- a/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb +++ b/modules/costs/spec/requests/api/cost_types/cost_type_resource_spec.rb @@ -33,9 +33,9 @@ describe 'API v3 Cost Type resource' do include Rack::Test::Methods include API::V3::Utilities::PathHelper - let(:current_user) { + let(:current_user) do FactoryBot.create(:user, member_in_project: project, member_through_role: role) - } + end let(:role) { FactoryBot.create(:role, permissions: [:view_cost_entries]) } let(:project) { FactoryBot.create(:project) } subject(:response) { last_response } diff --git a/modules/costs/spec/requests/api/time_entry_resource_spec.rb b/modules/costs/spec/requests/api/time_entry_resource_spec.rb index bc363a5bdc..ce4fb1b1e8 100644 --- a/modules/costs/spec/requests/api/time_entry_resource_spec.rb +++ b/modules/costs/spec/requests/api/time_entry_resource_spec.rb @@ -456,7 +456,7 @@ describe 'API v3 time_entry resource', type: :request do context 'if sending an activity the project disables' do let(:disable_activity) do - TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: project.id, active: false } ) + TimeEntryActivitiesProject.insert({ activity_id: activity.id, project_id: project.id, active: false }) end let(:additional_setup) { -> { disable_activity } } @@ -549,7 +549,7 @@ describe 'API v3 time_entry resource', type: :request do context 'if sending an activity the project disables' do let(:disable_activity) do - TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: project.id, active: false } ) + TimeEntryActivitiesProject.insert({ activity_id: activity.id, project_id: project.id, active: false }) end let(:additional_setup) { -> { disable_activity } } diff --git a/modules/documents/app/controllers/documents_controller.rb b/modules/documents/app/controllers/documents_controller.rb index 48e7c8b5ff..f805cc106e 100644 --- a/modules/documents/app/controllers/documents_controller.rb +++ b/modules/documents/app/controllers/documents_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -30,9 +31,9 @@ class DocumentsController < ApplicationController default_search_scope :documents model_object Document - before_action :find_project_by_project_id, only: [:index, :new, :create] - before_action :find_model_object, except: [:index, :new, :create] - before_action :find_project_from_association, except: [:index, :new, :create] + before_action :find_project_by_project_id, only: %i[index new create] + before_action :find_model_object, except: %i[index new create] + before_action :find_project_from_association, except: %i[index new create] before_action :authorize def index @@ -41,11 +42,11 @@ class DocumentsController < ApplicationController @grouped = case @group_by when 'date' - documents.group_by {|d| d.updated_at.to_date } + documents.group_by { |d| d.updated_at.to_date } when 'title' - documents.group_by {|d| d.title.first.upcase} + documents.group_by { |d| d.title.first.upcase } when 'author' - documents.with_attachments.group_by {|d| d.attachments.last.author} + documents.with_attachments.group_by { |d| d.attachments.last.author } else documents.includes(:category).group_by(&:category) end diff --git a/modules/documents/app/helpers/documents_helper.rb b/modules/documents/app/helpers/documents_helper.rb index 62de0522f0..0afc298bd3 100644 --- a/modules/documents/app/helpers/documents_helper.rb +++ b/modules/documents/app/helpers/documents_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/documents/app/mailers/documents_mailer.rb b/modules/documents/app/mailers/documents_mailer.rb index e39d0afca8..9f6b7a84d8 100644 --- a/modules/documents/app/mailers/documents_mailer.rb +++ b/modules/documents/app/mailers/documents_mailer.rb @@ -27,12 +27,11 @@ #++ class DocumentsMailer < UserMailer - def document_added(user, document) @document = document open_project_headers 'Project' => @document.project.identifier, - 'Type' => 'Document' + 'Type' => 'Document' with_locale_for(user) do subject = "[#{@document.project.name}] #{t(:label_document_new)}: #{@document.title}" @@ -48,5 +47,4 @@ class DocumentsMailer < UserMailer super end - end diff --git a/modules/documents/app/models/document.rb b/modules/documents/app/models/document.rb index 8fba2c6651..f265400dfa 100644 --- a/modules/documents/app/models/document.rb +++ b/modules/documents/app/models/document.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -63,7 +64,7 @@ class Document < ApplicationRecord after_initialize :set_default_category after_create :notify_document_created - def visible?(user=User.current) + def visible?(user = User.current) !user.nil? && user.allowed_to?(:view_documents, project) end diff --git a/modules/documents/app/models/document_category.rb b/modules/documents/app/models/document_category.rb index 8e581b2d61..914a48d431 100644 --- a/modules/documents/app/models/document_category.rb +++ b/modules/documents/app/models/document_category.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/documents/app/models/document_category_custom_field.rb b/modules/documents/app/models/document_category_custom_field.rb index 2c28f59f5c..a393d17a63 100644 --- a/modules/documents/app/models/document_category_custom_field.rb +++ b/modules/documents/app/models/document_category_custom_field.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/documents/app/models/journal/document_journal.rb b/modules/documents/app/models/journal/document_journal.rb index 4b5fb44db9..fd94190cf9 100644 --- a/modules/documents/app/models/journal/document_journal.rb +++ b/modules/documents/app/models/journal/document_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb b/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb index 820fa0c690..b6fad7e480 100644 --- a/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb +++ b/modules/documents/app/seeders/basic_data/documents/enumeration_seeder.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/documents/config/routes.rb b/modules/documents/config/routes.rb index 218d62c8ec..03bd30baa9 100644 --- a/modules/documents/config/routes.rb +++ b/modules/documents/config/routes.rb @@ -28,10 +28,10 @@ OpenProject::Application.routes.draw do resources :projects, only: [] do - resources :documents, only: [:create, :new, :index] + resources :documents, only: %i[create new index] end - resources :documents, except: [:create, :new, :index] do + resources :documents, except: %i[create new index] do member do post 'add_attachment' end diff --git a/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb b/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb index b05ffbbdd0..482ae19e01 100644 --- a/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb +++ b/modules/documents/db/migrate/20180323140208_to_v710_aggregated_documents_migrations.rb @@ -50,8 +50,8 @@ class ToV710AggregatedDocumentsMigrations < ActiveRecord::Migration[5.1] create_table :document_journals, id: :integer do |t| t.integer :journal_id, null: false - t.integer :project_id, default: 0, null: false - t.integer :category_id, default: 0, null: false + t.integer :project_id, default: 0, null: false + t.integer :category_id, default: 0, null: false t.string :title, limit: 60, default: "", null: false t.text :description t.datetime :created_on diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb index f504c918ce..747b36d69e 100644 --- a/modules/documents/lib/open_project/documents/engine.rb +++ b/modules/documents/lib/open_project/documents/engine.rb @@ -35,7 +35,6 @@ module OpenProject::Documents register 'openproject-documents', author_url: "http://www.openproject.com", bundled: true do - menu :project_menu, :documents, { controller: '/documents', action: 'index' }, @@ -45,10 +44,10 @@ module OpenProject::Documents icon: 'icon2 icon-notes' project_module :documents do |_map| - permission :view_documents, documents: [:index, :show, :download] + permission :view_documents, documents: %i[index show download] permission :manage_documents, { - documents: [:new, :create, :edit, :update, :destroy, :add_attachment] - }, require: :loggedin + documents: %i[new create edit update destroy add_attachment] + }, require: :loggedin end Redmine::Notifiable.all << Redmine::Notifiable.new('document_added') @@ -58,7 +57,7 @@ module OpenProject::Documents activity_provider :documents, class_name: 'Activities::DocumentActivityProvider', default: false - patches [:CustomFieldsHelper, :Project] + patches %i[CustomFieldsHelper Project] add_api_path :documents do "#{root}/documents" diff --git a/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb b/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb index 0a3a80f76a..309ecfb91c 100644 --- a/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb +++ b/modules/documents/lib/open_project/documents/patches/custom_fields_helper_patch.rb @@ -46,5 +46,5 @@ module OpenProject::Documents::Patches end unless CustomFieldsHelper.included_modules.include?(OpenProject::Documents::Patches::CustomFieldsHelperPatch) - CustomFieldsHelper.send(:include, OpenProject::Documents::Patches::CustomFieldsHelperPatch) + CustomFieldsHelper.include OpenProject::Documents::Patches::CustomFieldsHelperPatch end diff --git a/modules/documents/lib/open_project/documents/patches/project_patch.rb b/modules/documents/lib/open_project/documents/patches/project_patch.rb index dd1aa90f81..ae3d8df543 100644 --- a/modules/documents/lib/open_project/documents/patches/project_patch.rb +++ b/modules/documents/lib/open_project/documents/patches/project_patch.rb @@ -30,11 +30,10 @@ module OpenProject::Documents::Patches module ProjectPatch def self.included(base) base.class_eval do - has_many :documents, dependent: :destroy end end end end -Project.send(:include, OpenProject::Documents::Patches::ProjectPatch) +Project.include OpenProject::Documents::Patches::ProjectPatch diff --git a/modules/documents/spec/application_helper_spec.rb b/modules/documents/spec/application_helper_spec.rb index d4426ebfc2..2c68af905a 100644 --- a/modules/documents/spec/application_helper_spec.rb +++ b/modules/documents/spec/application_helper_spec.rb @@ -34,24 +34,23 @@ describe ApplicationHelper do include ActionDispatch::Routing include Rails.application.routes.url_helpers - - describe ".format_text" do + describe ".format_text" do let(:project) { FactoryBot.create :valid_project } let(:identifier) { project.identifier } - let(:role) { - FactoryBot.create(:role, permissions: [ - :view_work_packages, :edit_work_packages, :view_documents, :browse_repository, :view_changesets, :view_wiki_pages - ]) - } - let(:project_member) { + let(:role) do + FactoryBot.create(:role, permissions: %i[ + view_work_packages edit_work_packages view_documents browse_repository view_changesets view_wiki_pages + ]) + end + let(:project_member) do FactoryBot.create :user, member_in_project: project, - member_through_role: role - } - let(:document) { + member_through_role: role + end + let(:document) do FactoryBot.create :document, - title: 'Test document', - project: project - } + title: 'Test document', + project: project + end before do @project = project @@ -63,11 +62,11 @@ describe ApplicationHelper do end context "Simple Document links" do - let(:document_link) { + let(:document_link) do link_to('Test document', { controller: 'documents', action: 'show', id: document.id }, class: 'document op-uc-link') - } + end context "Plain link" do subject { format_text("document##{document.id}") } @@ -106,13 +105,17 @@ describe ApplicationHelper do context "By id and given project" do subject { format_text("#{identifier}:document##{document.id}", project: the_other_project) } - it { is_expected.to eq("

Test document

") } + it { + is_expected.to eq("

Test document

") + } end context "By name and given project" do subject { format_text("#{identifier}:document:\"#{document.title}\"", project: the_other_project) } - it { is_expected.to eq("

Test document

") } + it { + is_expected.to eq("

Test document

") + } end context "Invalid link" do diff --git a/modules/documents/spec/controllers/documents_controller_spec.rb b/modules/documents/spec/controllers/documents_controller_spec.rb index b95a7febe2..280bca4453 100644 --- a/modules/documents/spec/controllers/documents_controller_spec.rb +++ b/modules/documents/spec/controllers/documents_controller_spec.rb @@ -29,28 +29,27 @@ require File.dirname(__FILE__) + '/../spec_helper' describe DocumentsController do - render_views - let(:admin) { FactoryBot.create(:admin)} - let(:project) { FactoryBot.create(:project, name: "Test Project")} - let(:user) { FactoryBot.create(:user)} + let(:admin) { FactoryBot.create(:admin) } + let(:project) { FactoryBot.create(:project, name: "Test Project") } + let(:user) { FactoryBot.create(:user) } let(:role) { FactoryBot.create(:role, permissions: [:view_documents]) } - let(:default_category){ + let(:default_category) do FactoryBot.create(:document_category, project: project, name: "Default Category") - } + end - let(:document) { + let(:document) do FactoryBot.create(:document, title: "Sample Document", project: project, category: default_category) - } + end before do allow(User).to receive(:current).and_return admin end describe "index" do - let(:long_description) { + let(:long_description) do <<-LOREM.strip_heredoc Lorem ipsum dolor sit amet, consectetur adipiscing elit.\ Ut egestas, mi vehicula varius varius, ipsum massa fermentum orci,\ @@ -65,11 +64,11 @@ describe DocumentsController do Praesent a nunc lorem, ac porttitor eros. LOREM - } + end before do document.update(description: long_description) - get :index, params: { project_id: project.identifier } + get :index, params: { project_id: project.identifier } end it "should render the index-template successfully" do @@ -87,12 +86,11 @@ describe DocumentsController do expect(response.body).to have_selector('.wiki p', visible: :all, text: (document.description.split("\n").first + '...')) expect(response.body).to have_selector('.wiki p', visible: :all, text: /EndOfLineHere.../) end - end describe 'new' do before do - get :new, params: { project_id: project.id } + get :new, params: { project_id: project.id } end it 'show the new document form' do @@ -101,13 +99,11 @@ describe DocumentsController do end describe "create" do - - let(:document_attributes) { + let(:document_attributes) do FactoryBot.attributes_for(:document, title: "New Document", - project_id: project.id, - category_id: default_category.id) - } - + project_id: project.id, + category_id: default_category.id) + end before do ActionMailer::Base.deliveries.clear @@ -118,11 +114,9 @@ describe DocumentsController do expect do post :create, params: { project_id: project.identifier, document: FactoryBot.attributes_for(:document, title: "New Document", - project_id: project.id, - category_id: default_category.id - ) } - - end.to change{Document.count}.by 1 + project_id: project.id, + category_id: default_category.id) } + end.to change { Document.count }.by 1 end it "should create a new document with valid arguments" do @@ -132,11 +126,10 @@ describe DocumentsController do project_id: project.identifier, document: document_attributes } - end.to change{Document.count}.by 1 + end.to change { Document.count }.by 1 end describe "with attachments" do - before do notify_project = project FactoryBot.create(:member, project: notify_project, user: user, roles: [role]) @@ -144,10 +137,9 @@ describe DocumentsController do post :create, params: { project_id: notify_project.identifier, - document: FactoryBot.attributes_for(:document, title: "New Document", - project_id: notify_project.id, - category_id: default_category.id - ), + document: FactoryBot.attributes_for(:document, title: "New Document", + project_id: notify_project.id, + category_id: default_category.id), attachments: { '1' => { description: "sample file", file: file_attachment } } } end @@ -174,7 +166,7 @@ describe DocumentsController do describe 'show' do before do document - get :show, params: { id: document.id } + get :show, params: { id: document.id } end it "should delete the document and redirect back to documents-page of the project" do @@ -206,12 +198,12 @@ describe DocumentsController do end it "should delete the document and redirect back to documents-page of the project" do - expect{ + expect do delete :destroy, params: { id: document.id } - }.to change{Document.count}.by -1 + end.to change { Document.count }.by -1 expect(response).to redirect_to "/projects/#{project.identifier}/documents" - expect{Document.find(document.id)}.to raise_error ActiveRecord::RecordNotFound + expect { Document.find(document.id) }.to raise_error ActiveRecord::RecordNotFound end end diff --git a/modules/documents/spec/features/attachment_upload_spec.rb b/modules/documents/spec/features/attachment_upload_spec.rb index 59fd234953..34dc0e8f0e 100644 --- a/modules/documents/spec/features/attachment_upload_spec.rb +++ b/modules/documents/spec/features/attachment_upload_spec.rb @@ -83,7 +83,7 @@ describe 'Upload attachment to documents', js: true do # FIXME: yes indeed visit edit_document_path(document) - #editor.click_and_type_slowly 'abc' + # editor.click_and_type_slowly 'abc' SeleniumHubWaiter.wait editor.drag_attachment image_fixture.path, 'Image uploaded the second time' expect(page).to have_selector('attachment-list-item', text: 'image.png', count: 2) diff --git a/modules/documents/spec/lib/open_project/markdown_formatting_spec.rb b/modules/documents/spec/lib/open_project/markdown_formatting_spec.rb index a4a654df88..bb664ca798 100644 --- a/modules/documents/spec/lib/open_project/markdown_formatting_spec.rb +++ b/modules/documents/spec/lib/open_project/markdown_formatting_spec.rb @@ -32,7 +32,6 @@ describe OpenProject::TextFormatting, 'Document links', # Speeds up the spec by avoiding event mailers to be procssed with_settings: { notified_events: [] } do - include ActionView::Helpers::UrlHelper # soft-dependency include ActionView::Context include OpenProject::StaticRouting::UrlHelpers diff --git a/modules/documents/spec/lib/redmine/access_control_spec.rb b/modules/documents/spec/lib/redmine/access_control_spec.rb index 4e2cb0d647..743ef449e1 100644 --- a/modules/documents/spec/lib/redmine/access_control_spec.rb +++ b/modules/documents/spec/lib/redmine/access_control_spec.rb @@ -28,7 +28,6 @@ require File.dirname(__FILE__) + '/../../spec_helper' describe OpenProject::AccessControl do - describe 'manage documents permission' do it 'should be part of the documents project module' do permission = OpenProject::AccessControl.permission(:manage_documents) @@ -44,5 +43,4 @@ describe OpenProject::AccessControl do expect(permission.project_module).to eql(:documents) end end - end diff --git a/modules/documents/spec/mailers/documents_mailer_spec.rb b/modules/documents/spec/mailers/documents_mailer_spec.rb index b76ad94250..1d098477d6 100644 --- a/modules/documents/spec/mailers/documents_mailer_spec.rb +++ b/modules/documents/spec/mailers/documents_mailer_spec.rb @@ -28,14 +28,13 @@ require File.dirname(__FILE__) + '/../spec_helper' describe DocumentsMailer do - - let(:user) { + let(:user) do FactoryBot.create(:user, firstname: 'Test', lastname: "User", mail: 'test@test.com') - } + end let(:project) { FactoryBot.create(:project, name: "TestProject") } - let(:document) { - FactoryBot.create(:document, project: project, description: "Test Description", title: "Test Title" ) - } + let(:document) do + FactoryBot.create(:document, project: project, description: "Test Description", title: "Test Title") + end let(:mail) { DocumentsMailer.document_added(user, document) } describe "document added-mail" do @@ -52,10 +51,5 @@ describe DocumentsMailer do expect(mail.body.encoded).to match(document.description) expect(mail.body.encoded).to match(document.title) end - end - - - - end diff --git a/modules/documents/spec/models/document_category_spec.rb b/modules/documents/spec/models/document_category_spec.rb index 1a80e30162..f95226e9ae 100644 --- a/modules/documents/spec/models/document_category_spec.rb +++ b/modules/documents/spec/models/document_category_spec.rb @@ -27,24 +27,21 @@ #++ require File.dirname(__FILE__) + '/../spec_helper' - describe DocumentCategory do - - let(:project) {FactoryBot.create(:project)} + let(:project) { FactoryBot.create(:project) } it "should be an enumeration" do expect(DocumentCategory.ancestors).to include Enumeration end it "should order documents by the category they are created with" do - uncategorized = FactoryBot.create :document_category, name: "Uncategorized", project: project + uncategorized = FactoryBot.create :document_category, name: "Uncategorized", project: project user_documentation = FactoryBot.create :document_category, name: "User documentation" FactoryBot.create_list :document, 2, category: uncategorized, project: project expect(DocumentCategory.find_by_name(uncategorized.name).objects_count).to eql 2 expect(DocumentCategory.find_by_name(user_documentation.name).objects_count).to eql 0 - end it "should file the categorizations under the option name :enumeration_doc_categories" do @@ -54,12 +51,9 @@ describe DocumentCategory do it "should only allow one category to be the default-category" do old_default = FactoryBot.create :document_category, name: "old default", project: project, is_default: true - expect{ + expect do FactoryBot.create :document_category, name: "new default", project: project, is_default: true old_default.reload - }.to change{old_default.is_default?}.from(true).to(false) - - + end.to change { old_default.is_default? }.from(true).to(false) end - end diff --git a/modules/documents/spec/models/document_spec.rb b/modules/documents/spec/models/document_spec.rb index c6c772307d..b76ae23234 100644 --- a/modules/documents/spec/models/document_spec.rb +++ b/modules/documents/spec/models/document_spec.rb @@ -28,10 +28,10 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Document do - let(:documentation_category) { FactoryBot.create :document_category, name: 'User documentation'} - let(:project) { FactoryBot.create :project} - let(:user) { FactoryBot.create(:user)} - let(:admin) { FactoryBot.create(:admin)} + let(:documentation_category) { FactoryBot.create :document_category, name: 'User documentation' } + let(:project) { FactoryBot.create :project } + let(:user) { FactoryBot.create(:user) } + let(:admin) { FactoryBot.create(:admin) } let(:mail) do mock = Object.new @@ -40,27 +40,27 @@ describe Document do end context "validation" do - it { is_expected.to validate_presence_of :project} - it { is_expected.to validate_presence_of :title} - it { is_expected.to validate_presence_of :category} + it { is_expected.to validate_presence_of :project } + it { is_expected.to validate_presence_of :title } + it { is_expected.to validate_presence_of :category } end describe "create with a valid document" do - let(:valid_document) {Document.new(title: "Test", project: project, category: documentation_category)} + let(:valid_document) { Document.new(title: "Test", project: project, category: documentation_category) } it "should add a document" do - expect{ + expect do valid_document.save - }.to change{Document.count}.by 1 + end.to change { Document.count }.by 1 end it "should send out email-notifications" do allow(valid_document).to receive(:recipients).and_return([user]) Setting.notified_events = Setting.notified_events << 'document_added' - expect{ + expect do valid_document.save - }.to change{ActionMailer::Base.deliveries.size}.by 1 + end.to change { ActionMailer::Base.deliveries.size }.by 1 end it "should send notifications to the recipients of the project" do @@ -76,24 +76,24 @@ describe Document do default_category = FactoryBot.create :document_category, name: 'Technical documentation', is_default: true document = Document.new(project: project, title: "New Document") expect(document.category).to eql default_category - expect{ + expect do document.save - }.to change { Document.count }.by 1 + end.to change { Document.count }.by 1 end it "with attachments should change the updated_at-date on the document to the attachment's date" do valid_document.save - expect { + expect do Attachments::CreateService .new(valid_document, author: admin) .call(uploaded_file: FactoryBot.attributes_for(:attachment)[:file], description: '') expect(valid_document.attachments.size).to eql 1 - }.to(change { + end.to(change do valid_document.reload valid_document.updated_at - }) + end) end it "without attachments, the updated-on-date is taken from the document's date" do diff --git a/modules/documents/spec/requests/api/v3/attachments/attachments_by_documents_resource_spec.rb b/modules/documents/spec/requests/api/v3/attachments/attachments_by_documents_resource_spec.rb index 6b1457fe3f..4c12f43f30 100644 --- a/modules/documents/spec/requests/api/v3/attachments/attachments_by_documents_resource_spec.rb +++ b/modules/documents/spec/requests/api/v3/attachments/attachments_by_documents_resource_spec.rb @@ -136,4 +136,4 @@ describe 'API v3 Attachments by document resource', type: :request do it_behaves_like 'unauthorized access' end end -end \ No newline at end of file +end diff --git a/modules/documents/spec/routing/documents_routing_spec.rb b/modules/documents/spec/routing/documents_routing_spec.rb index 9355279464..f4914b29dd 100644 --- a/modules/documents/spec/routing/documents_routing_spec.rb +++ b/modules/documents/spec/routing/documents_routing_spec.rb @@ -30,46 +30,46 @@ require 'spec_helper' describe DocumentsController do describe "routing" do - it { + it { expect(get('/projects/567/documents')).to route_to(controller: 'documents', action: 'index', - project_id: '567' ) + project_id: '567') } - it { + it { expect(get('/projects/567/documents/new')).to route_to(controller: 'documents', action: 'new', - project_id: '567' ) + project_id: '567') } - it { + it { expect(get('/documents/22')).to route_to(controller: 'documents', action: 'show', - id: '22') + id: '22') } - it { + it { expect(get('/documents/22/edit')).to route_to(controller: 'documents', action: 'edit', - id: '22') + id: '22') } - it { + it { expect(post('/projects/567/documents')).to route_to(controller: 'documents', action: 'create', - project_id: '567') + project_id: '567') } - it { + it { expect(put('/documents/567')).to route_to(controller: 'documents', action: 'update', - id: '567') + id: '567') } - it { + it { expect(delete('/documents/567')).to route_to(controller: 'documents', action: 'destroy', - id: '567') + id: '567') } end end diff --git a/modules/github_integration/lib/open_project/github_integration/engine.rb b/modules/github_integration/lib/open_project/github_integration/engine.rb index 6ec0352bf0..84f4bab387 100644 --- a/modules/github_integration/lib/open_project/github_integration/engine.rb +++ b/modules/github_integration/lib/open_project/github_integration/engine.rb @@ -37,10 +37,9 @@ module OpenProject::GithubIntegration include OpenProject::Plugins::ActsAsOpEngine register 'openproject-github_integration', - :author_url => 'https://www.openproject.org/', + author_url: 'https://www.openproject.org/', bundled: true - initializer 'github.register_hook' do ::OpenProject::Webhooks.register_hook 'github' do |hook, environment, params, user| HookHandler.new.process(hook, environment, params, user) @@ -53,6 +52,5 @@ module OpenProject::GithubIntegration ::OpenProject::Notifications.subscribe('github.issue_comment', &NotificationHandlers.method(:issue_comment)) end - end end diff --git a/modules/github_integration/lib/open_project/github_integration/hook_handler.rb b/modules/github_integration/lib/open_project/github_integration/hook_handler.rb index 2629a86c81..d73151d1d6 100644 --- a/modules/github_integration/lib/open_project/github_integration/hook_handler.rb +++ b/modules/github_integration/lib/open_project/github_integration/hook_handler.rb @@ -34,7 +34,7 @@ module OpenProject::GithubIntegration # A github webhook happened. # We need to check validity of the data and send a Notification # which we process in our NotificationHandler. - def process(hook, request, params, user) + def process(_hook, request, params, user) event_type = request.env['HTTP_X_GITHUB_EVENT'] event_delivery = request.env['HTTP_X_GITHUB_DELIVERY'] @@ -52,7 +52,7 @@ module OpenProject::GithubIntegration OpenProject::Notifications.send(event_name(event_type), payload) - return 200 + 200 end private def event_name(github_event_name) diff --git a/modules/github_integration/lib/open_project/github_integration/notification_handlers.rb b/modules/github_integration/lib/open_project/github_integration/notification_handlers.rb index f871d975da..3dc3159b34 100644 --- a/modules/github_integration/lib/open_project/github_integration/notification_handlers.rb +++ b/modules/github_integration/lib/open_project/github_integration/notification_handlers.rb @@ -27,11 +27,9 @@ #++ module OpenProject::GithubIntegration - ## # Handles github-related notifications. module NotificationHandlers - ## # Handles a pull_request webhook notification. # The payload looks similar to this: @@ -53,8 +51,9 @@ module OpenProject::GithubIntegration # Don't add comments about assignments and labels either. ignored_actions = %w[synchronize assigned unassigned labeled unlabeled] return if ignored_actions.include? payload['action'] + comment_on_referenced_work_packages payload['pull_request']['body'], payload - rescue => e + rescue StandardError => e Rails.logger.error "Failed to handle pull_request event: #{e} #{e.message}" raise e end @@ -78,8 +77,9 @@ module OpenProject::GithubIntegration def self.issue_comment(payload) # if the comment is not associated with a PR, ignore it return unless payload['issue']['pull_request']['html_url'] + comment_on_referenced_work_packages payload['comment']['body'], payload - rescue => e + rescue StandardError => e Rails.logger.error "Failed to handle issue_comment event: #{e} #{e.message}" raise e end @@ -125,7 +125,7 @@ module OpenProject::GithubIntegration wp_regex = /OP#(\d+)|http(?:s?):\/\/#{host_name}\/(?:\S+?\/)*(?:work_packages|wp)\/([0-9]+)/ source.scan(wp_regex) - .map {|first, second| (first || second).to_i } + .map { |first, second| (first || second).to_i } .select { |el| el > 0 } .uniq end @@ -173,26 +173,26 @@ module OpenProject::GithubIntegration return nil unless key I18n.t("github_integration.pull_request_#{key}_comment", - :pr_number => payload['number'], - :pr_title => payload['pull_request']['title'], - :pr_url => payload['pull_request']['html_url'], - :repository => payload['pull_request']['base']['repo']['full_name'], - :repository_url => payload['pull_request']['base']['repo']['html_url'], - :github_user => payload['sender']['login'], - :github_user_url => payload['sender']['html_url']) + pr_number: payload['number'], + pr_title: payload['pull_request']['title'], + pr_url: payload['pull_request']['html_url'], + repository: payload['pull_request']['base']['repo']['full_name'], + repository_url: payload['pull_request']['base']['repo']['html_url'], + github_user: payload['sender']['login'], + github_user_url: payload['sender']['html_url']) end def self.notes_for_issue_comment_payload(payload) return nil unless payload['action'] == 'created' I18n.t("github_integration.pull_request_referenced_comment", - :pr_number => payload['issue']['number'], - :pr_title => payload['issue']['title'], - :pr_url => payload['comment']['html_url'], - :repository => payload['repository']['full_name'], - :repository_url => payload['repository']['html_url'], - :github_user => payload['comment']['user']['login'], - :github_user_url => payload['comment']['user']['html_url']) + pr_number: payload['issue']['number'], + pr_title: payload['issue']['title'], + pr_url: payload['comment']['html_url'], + repository: payload['repository']['full_name'], + repository_url: payload['repository']['html_url'], + github_user: payload['comment']['user']['login'], + github_user_url: payload['comment']['user']['html_url']) end end end diff --git a/modules/github_integration/openproject-github_integration.gemspec b/modules/github_integration/openproject-github_integration.gemspec index b613f4ba1a..0ed758a726 100644 --- a/modules/github_integration/openproject-github_integration.gemspec +++ b/modules/github_integration/openproject-github_integration.gemspec @@ -1,4 +1,5 @@ # encoding: UTF-8 + Gem::Specification.new do |s| s.name = "openproject-github_integration" s.version = '1.0.0' diff --git a/modules/github_integration/spec/lib/github_integration_spec.rb b/modules/github_integration/spec/lib/github_integration_spec.rb index e9487ef013..6fe61eb2ac 100644 --- a/modules/github_integration/spec/lib/github_integration_spec.rb +++ b/modules/github_integration/spec/lib/github_integration_spec.rb @@ -26,7 +26,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../spec_helper', __dir__) describe OpenProject::GithubIntegration do before do @@ -35,9 +35,11 @@ describe OpenProject::GithubIntegration do describe 'with sane set-up' do let(:user) { FactoryBot.create(:user) } - let(:role) { FactoryBot.create(:role, - permissions: [:view_work_packages, :add_work_package_notes]) } - let(:statuses) { (1..5).map{ |i| FactoryBot.create(:status)}} + let(:role) do + FactoryBot.create(:role, + permissions: %i[view_work_packages add_work_package_notes]) + end + let(:statuses) { (1..5).map { |_i| FactoryBot.create(:status) } } let(:priority) { FactoryBot.create :priority, is_default: true } let(:status) { statuses[0] } let(:project) do @@ -54,11 +56,11 @@ describe OpenProject::GithubIntegration do end let(:wp3) do FactoryBot.create :work_package, - project: project_without_permission + project: project_without_permission end let(:wp4) do FactoryBot.create :work_package, - project: project_without_permission + project: project_without_permission end let(:wps) { [wp1, wp2, wp3, wp4] } @@ -97,7 +99,7 @@ describe OpenProject::GithubIntegration do journal_count = wps.map { |wp| wp.journals.count } OpenProject::GithubIntegration::HookHandler.new.process('github', OpenStruct.new(env: environment), params, user) - [wp1,wp2,wp3,wp4].map { |x| x.reload } + [wp1, wp2, wp3, wp4].map { |x| x.reload } expect(wp1.journals.count).to equal(journal_count[0] + 1) expect(wp2.journals.count).to equal(journal_count[1] + 1) @@ -142,7 +144,7 @@ describe OpenProject::GithubIntegration do journal_count = wps.map { |wp| wp.journals.count } OpenProject::GithubIntegration::HookHandler.new.process('github', OpenStruct.new(env: environment), params, user) - [wp1,wp2,wp3,wp4].map { |x| x.reload } + [wp1, wp2, wp3, wp4].map { |x| x.reload } expect(wp1.journals.count).to eq(journal_count[0] + 1) expect(wp2.journals.count).to eq(journal_count[1] + 1) @@ -188,7 +190,7 @@ describe OpenProject::GithubIntegration do journal_count = wps.map { |wp| wp.journals.count } OpenProject::GithubIntegration::HookHandler.new.process('github', OpenStruct.new(env: environment), params, user) - [wp1,wp2,wp3,wp4].map { |x| x.reload } + [wp1, wp2, wp3, wp4].map { |x| x.reload } expect(wp1.journals.count).to equal(journal_count[0] + 1) expect(wp2.journals.count).to equal(journal_count[1] + 1) @@ -254,7 +256,7 @@ describe OpenProject::GithubIntegration do journal_count = wps.map { |wp| wp.journals.count } OpenProject::GithubIntegration::HookHandler.new.process('github', OpenStruct.new(env: environment), params, user) - [wp1,wp2,wp3,wp4].map { |x| x.reload } + [wp1, wp2, wp3, wp4].map { |x| x.reload } expect(wp1.journals.count).to equal(journal_count[0] + 1) expect(wp2.journals.count).to equal(journal_count[1] + 1) diff --git a/modules/github_integration/spec/lib/hook_handler_spec.rb b/modules/github_integration/spec/lib/hook_handler_spec.rb index f73d14591a..bc54b6892b 100644 --- a/modules/github_integration/spec/lib/hook_handler_spec.rb +++ b/modules/github_integration/spec/lib/hook_handler_spec.rb @@ -26,15 +26,17 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../spec_helper', __dir__) describe OpenProject::GithubIntegration::HookHandler do describe '#process' do let(:handler) { OpenProject::GithubIntegration::HookHandler.new } let(:hook) { 'fake hook' } let(:params) { ActionController::Parameters.new({ payload: { 'fake' => 'value' } }) } - let(:environment) { { 'HTTP_X_GITHUB_EVENT' => 'pull_request' , - 'HTTP_X_GITHUB_DELIVERY' => 'veryuniqueid' } } + let(:environment) do + { 'HTTP_X_GITHUB_EVENT' => 'pull_request', + 'HTTP_X_GITHUB_DELIVERY' => 'veryuniqueid' } + end let(:request) { OpenStruct.new(env: environment) } let(:user) do user = double(User) @@ -43,8 +45,10 @@ describe OpenProject::GithubIntegration::HookHandler do end context 'with an unsupported event' do - let(:environment) { { 'HTTP_X_GITHUB_EVENT' => 'X-unspupported' , - 'HTTP_X_GITHUB_DELIVERY' => 'veryuniqueid2' } } + let(:environment) do + { 'HTTP_X_GITHUB_EVENT' => 'X-unspupported', + 'HTTP_X_GITHUB_DELIVERY' => 'veryuniqueid2' } + end it 'should return 404' do result = handler.process(hook, request, params, user) @@ -68,11 +72,11 @@ describe OpenProject::GithubIntegration::HookHandler do it 'should send a notification with the correct contents' do expect(OpenProject::Notifications).to receive(:send).with("github.pull_request", { - 'fake' => 'value', - 'open_project_user_id' => 12, - 'github_event' => 'pull_request', - 'github_delivery' => 'veryuniqueid' - }) + 'fake' => 'value', + 'open_project_user_id' => 12, + 'github_event' => 'pull_request', + 'github_delivery' => 'veryuniqueid' + }) handler.process(hook, request, params, user) end diff --git a/modules/github_integration/spec/lib/notification_handlers_spec.rb b/modules/github_integration/spec/lib/notification_handlers_spec.rb index 1294ccbe70..a4cc4ac504 100644 --- a/modules/github_integration/spec/lib/notification_handlers_spec.rb +++ b/modules/github_integration/spec/lib/notification_handlers_spec.rb @@ -26,7 +26,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../spec_helper', __dir__) describe OpenProject::GithubIntegration do before do @@ -36,42 +36,48 @@ describe OpenProject::GithubIntegration do describe '.extract_work_package_ids' do it 'should return an empty array for an empty source' do result = OpenProject::GithubIntegration::NotificationHandlers.send( - :extract_work_package_ids, '') + :extract_work_package_ids, '' + ) expect(result).to eql([]) end it 'should find a plain work package url' do source = "Blabla\nOP#1234\n" result = OpenProject::GithubIntegration::NotificationHandlers.send( - :extract_work_package_ids, source) + :extract_work_package_ids, source + ) expect(result).to eql([1234]) end it 'should find a plain work package url' do source = 'Blabla\nhttps://example.net/work_packages/234\n' result = OpenProject::GithubIntegration::NotificationHandlers.send( - :extract_work_package_ids, source) + :extract_work_package_ids, source + ) expect(result).to eql([234]) end it 'should find a work package url in markdown link syntax' do source = 'Blabla\n[WP 234](https://example.net/work_packages/234)\n' result = OpenProject::GithubIntegration::NotificationHandlers.send( - :extract_work_package_ids, source) + :extract_work_package_ids, source + ) expect(result).to eql([234]) end it 'should find multiple work package urls' do source = "I reference https://example.net/work_packages/434\n and Blabla\n[WP 234](https://example.net/wp/234)\n" result = OpenProject::GithubIntegration::NotificationHandlers.send( - :extract_work_package_ids, source) + :extract_work_package_ids, source + ) expect(result).to eql([434, 234]) end it 'should find multiple occurences of a work package only once' do source = "I reference https://example.net/work_packages/434\n and Blabla\n[WP 234](https://example.net/work_packages/434)\n" result = OpenProject::GithubIntegration::NotificationHandlers.send( - :extract_work_package_ids, source) + :extract_work_package_ids, source + ) expect(result).to eql([434]) end end @@ -98,18 +104,21 @@ describe OpenProject::GithubIntegration do before do allow(WorkPackage).to receive(:includes).and_return(WorkPackage) - allow(WorkPackage).to receive(:find_by_id) {|id| wps[id]} + allow(WorkPackage).to receive(:find_by_id) { |id| wps[id] } end shared_examples_for 'GithubIntegration.find_visible_work_packages' do - subject { OpenProject::GithubIntegration::NotificationHandlers.send( - :find_visible_work_packages, ids, user) } + subject do + OpenProject::GithubIntegration::NotificationHandlers.send( + :find_visible_work_packages, ids, user + ) + end it { expect(subject).to eql(expected) } end describe 'should find an existing work package' do let(:wps) { [visible_wp] } - let(:ids) { [0] } + let(:ids) { [0] } let(:expected) { wps } it_behaves_like 'GithubIntegration.find_visible_work_packages' @@ -117,7 +126,7 @@ describe OpenProject::GithubIntegration do describe 'should not find a non-existing work package' do let(:wps) { [invisible_wp] } - let(:ids) { [0] } + let(:ids) { [0] } let(:expected) { [] } it_behaves_like 'GithubIntegration.find_visible_work_packages' @@ -125,7 +134,7 @@ describe OpenProject::GithubIntegration do describe 'should find multiple existing work packages' do let(:wps) { [visible_wp, visible_wp] } - let(:ids) { [0, 1] } + let(:ids) { [0, 1] } let(:expected) { wps } it_behaves_like 'GithubIntegration.find_visible_work_packages' @@ -133,7 +142,7 @@ describe OpenProject::GithubIntegration do describe 'should not find work package which the user shall not see' do let(:wps) { [visible_wp, invisible_wp, visible_wp, invisible_wp] } - let(:ids) { [0, 1, 2, 3] } + let(:ids) { [0, 1, 2, 3] } let(:expected) { [visible_wp, visible_wp] } it_behaves_like 'GithubIntegration.find_visible_work_packages' @@ -149,7 +158,8 @@ describe OpenProject::GithubIntegration do before do expect(OpenProject::GithubIntegration::NotificationHandlers).not_to receive( - :comment_on_referenced_work_packages) + :comment_on_referenced_work_packages + ) end it 'should do nothing' do @@ -160,11 +170,12 @@ describe OpenProject::GithubIntegration do describe '.pull_request' do context 'with a synchronize action' do - let(:payload) { {'action' => 'synchronize'} } + let(:payload) { { 'action' => 'synchronize' } } before do expect(OpenProject::GithubIntegration::NotificationHandlers).not_to receive( - :comment_on_referenced_work_packages) + :comment_on_referenced_work_packages + ) end it 'should do nothing' do diff --git a/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb b/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb index af970f39b7..bc35f0270b 100644 --- a/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb +++ b/modules/grids/app/representers/api/v3/grids/grid_collection_representer.rb @@ -32,8 +32,8 @@ module API module V3 module Grids class GridCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection - attr_reader :grid_scope - attr_reader :grid_writable + attr_reader :grid_scope, :grid_writable + element_decorator ::API::V3::Grids::GridRepresenter def initialize(models, self_link:, grid_scope:, **args) diff --git a/modules/grids/lib/grids/configuration/registration.rb b/modules/grids/lib/grids/configuration/registration.rb index 9ea2a9f002..790bdf4849 100644 --- a/modules/grids/lib/grids/configuration/registration.rb +++ b/modules/grids/lib/grids/configuration/registration.rb @@ -38,7 +38,7 @@ module Grids::Configuration private def macroed_getter_setter(name, type = :single) - private_name = :"_#{name.to_s}" + private_name = :"_#{name}" class_attribute private_name diff --git a/modules/grids/spec/support/pages/grid.rb b/modules/grids/spec/support/pages/grid.rb index b3ade0d72b..c1f65f4b90 100644 --- a/modules/grids/spec/support/pages/grid.rb +++ b/modules/grids/spec/support/pages/grid.rb @@ -78,14 +78,12 @@ module Pages private - def within_add_widget_modal(row_number, column_number, location) + def within_add_widget_modal(row_number, column_number, location, &block) area = area_of(row_number, column_number, location) area.hover area.find('.grid--widget-add', visible: :all).click - within '.op-modal--portal' do - yield - end + within '.op-modal--portal', &block end def expect_widget_adding_prohibited_generally(row_number = 1, column_number = 1) diff --git a/modules/ldap_groups/app/cells/ldap_groups/memberships/row_cell.rb b/modules/ldap_groups/app/cells/ldap_groups/memberships/row_cell.rb index f89d18c611..390740142c 100644 --- a/modules/ldap_groups/app/cells/ldap_groups/memberships/row_cell.rb +++ b/modules/ldap_groups/app/cells/ldap_groups/memberships/row_cell.rb @@ -17,4 +17,3 @@ module LdapGroups end end end - diff --git a/modules/ldap_groups/app/cells/ldap_groups/memberships/table_cell.rb b/modules/ldap_groups/app/cells/ldap_groups/memberships/table_cell.rb index a05d37c678..a14022ecef 100644 --- a/modules/ldap_groups/app/cells/ldap_groups/memberships/table_cell.rb +++ b/modules/ldap_groups/app/cells/ldap_groups/memberships/table_cell.rb @@ -17,8 +17,8 @@ module LdapGroups def headers [ - ['user', caption: ::LdapGroups::Membership.human_attribute_name('user')], - ['added', caption: ::LdapGroups::Membership.human_attribute_name('created_at')] + ['user', { caption: ::LdapGroups::Membership.human_attribute_name('user') }], + ['added', { caption: ::LdapGroups::Membership.human_attribute_name('created_at') }] ] end end diff --git a/modules/ldap_groups/app/cells/ldap_groups/synchronized_filters/table_cell.rb b/modules/ldap_groups/app/cells/ldap_groups/synchronized_filters/table_cell.rb index 7d797433f9..6b459d9cf9 100644 --- a/modules/ldap_groups/app/cells/ldap_groups/synchronized_filters/table_cell.rb +++ b/modules/ldap_groups/app/cells/ldap_groups/synchronized_filters/table_cell.rb @@ -1,4 +1,3 @@ - module LdapGroups module SynchronizedFilters class TableCell < ::TableCell @@ -26,11 +25,11 @@ module LdapGroups def headers [ - ['name', caption: ::LdapGroups::SynchronizedFilter.human_attribute_name('name')], - ['auth_source', caption: ::LdapGroups::SynchronizedFilter.human_attribute_name('auth_source')], - ['groups', caption: I18n.t('ldap_groups.synchronized_filters.plural')] + ['name', { caption: ::LdapGroups::SynchronizedFilter.human_attribute_name('name') }], + ['auth_source', { caption: ::LdapGroups::SynchronizedFilter.human_attribute_name('auth_source') }], + ['groups', { caption: I18n.t('ldap_groups.synchronized_filters.plural') }] ] end end end -end \ No newline at end of file +end diff --git a/modules/ldap_groups/app/cells/ldap_groups/synchronized_groups/table_cell.rb b/modules/ldap_groups/app/cells/ldap_groups/synchronized_groups/table_cell.rb index 0d58d7f0a5..c4133bd7a4 100644 --- a/modules/ldap_groups/app/cells/ldap_groups/synchronized_groups/table_cell.rb +++ b/modules/ldap_groups/app/cells/ldap_groups/synchronized_groups/table_cell.rb @@ -1,4 +1,3 @@ - module LdapGroups module SynchronizedGroups class TableCell < ::TableCell @@ -16,7 +15,7 @@ module LdapGroups true end - def sortable_column?(column) + def sortable_column?(_column) false end @@ -34,12 +33,12 @@ module LdapGroups def headers [ - ['dn', caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('dn')], - ['auth_source', caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('auth_source')], - ['group', caption: I18n.t(:label_group)], - ['users', caption: I18n.t(:label_user_plural)], + ['dn', { caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('dn') }], + ['auth_source', { caption: ::LdapGroups::SynchronizedGroup.human_attribute_name('auth_source') }], + ['group', { caption: I18n.t(:label_group) }], + ['users', { caption: I18n.t(:label_user_plural) }] ] end end end -end \ No newline at end of file +end diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb index 0ff761842a..d4d8ee1d1d 100644 --- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb +++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_filters_controller.rb @@ -68,7 +68,7 @@ module LdapGroups def check_ee unless EnterpriseToken.allows_to?(:ldap_groups) render template: 'ldap_groups/synchronized_groups/upsale' - return false + false end end diff --git a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb index 1a13a31eb8..620a9e1cca 100644 --- a/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb +++ b/modules/ldap_groups/app/controllers/ldap_groups/synchronized_groups_controller.rb @@ -59,7 +59,7 @@ module LdapGroups def check_ee unless EnterpriseToken.allows_to?(:ldap_groups) render template: 'ldap_groups/synchronized_groups/upsale' - return false + false end end diff --git a/modules/ldap_groups/app/models/ldap_groups.rb b/modules/ldap_groups/app/models/ldap_groups.rb index fba1f06aca..5a024ac739 100644 --- a/modules/ldap_groups/app/models/ldap_groups.rb +++ b/modules/ldap_groups/app/models/ldap_groups.rb @@ -2,4 +2,4 @@ module LdapGroups def self.table_name_prefix 'ldap_groups_' end -end \ No newline at end of file +end diff --git a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb index e6a23fda46..d0504e755f 100644 --- a/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb +++ b/modules/ldap_groups/app/models/ldap_groups/synchronized_group.rb @@ -32,7 +32,7 @@ module LdapGroups self.class.transaction do # create synchronized group memberships - memberships = new_users.map { |user| { group_id: self.id, user_id: user_id(user) } } + memberships = new_users.map { |user| { group_id: id, user_id: user_id(user) } } # Bulk insert the memberships to improve performance ::LdapGroups::Membership.insert_all memberships @@ -58,7 +58,8 @@ module LdapGroups users.delete users.where(user_id: users_to_remove).select(:id) group.users.delete group.users.where(id: users_to_remove).select(:id) else - raise ArgumentError, "Expected collection of Users or User IDs, got collection of #{users_to_remove.map(&:class).map(&:name).uniq.join(", ")}" + raise ArgumentError, + "Expected collection of Users or User IDs, got collection of #{users_to_remove.map(&:class).map(&:name).uniq.join(', ')}" end end end diff --git a/modules/ldap_groups/app/workers/ldap_groups/synchronization_job.rb b/modules/ldap_groups/app/workers/ldap_groups/synchronization_job.rb index c30ac60349..60de3a1283 100644 --- a/modules/ldap_groups/app/workers/ldap_groups/synchronization_job.rb +++ b/modules/ldap_groups/app/workers/ldap_groups/synchronization_job.rb @@ -58,4 +58,4 @@ module LdapGroups Rails.logger.error msg end end -end \ No newline at end of file +end diff --git a/modules/ldap_groups/config/routes.rb b/modules/ldap_groups/config/routes.rb index dff7c9976c..fd017d09e0 100644 --- a/modules/ldap_groups/config/routes.rb +++ b/modules/ldap_groups/config/routes.rb @@ -1,10 +1,8 @@ OpenProject::Application.routes.draw do namespace 'ldap_groups' do - resources :synchronized_filters, param: :ldap_filter_id, except: %i(index) do - member do # Extract groups from filter get 'synchronize' @@ -17,11 +15,10 @@ OpenProject::Application.routes.draw do resources :synchronized_groups, param: :ldap_group_id, only: %i(new index create show destroy) do - member do # Destroy warning get 'destroy_info' end end end -end \ No newline at end of file +end diff --git a/modules/ldap_groups/lib/open_project/ldap_groups.rb b/modules/ldap_groups/lib/open_project/ldap_groups.rb index a89d19e738..3e1e10b856 100644 --- a/modules/ldap_groups/lib/open_project/ldap_groups.rb +++ b/modules/ldap_groups/lib/open_project/ldap_groups.rb @@ -3,7 +3,6 @@ module OpenProject require "open_project/ldap_groups/engine" class << self - def settings Setting.plugin_openproject_ldap_groups end diff --git a/modules/ldap_groups/lib/open_project/ldap_groups/synchronization.rb b/modules/ldap_groups/lib/open_project/ldap_groups/synchronization.rb index 9d14954e87..74a8d9596f 100644 --- a/modules/ldap_groups/lib/open_project/ldap_groups/synchronization.rb +++ b/modules/ldap_groups/lib/open_project/ldap_groups/synchronization.rb @@ -72,7 +72,6 @@ module OpenProject::LdapGroups ## # Get the current members from the ldap group def get_members(ldap_con, group) - # Get user login attribute and base dn which are private base_dn = ldap.base_dn diff --git a/modules/ldap_groups/lib/open_project/ldap_groups/synchronize_filter.rb b/modules/ldap_groups/lib/open_project/ldap_groups/synchronize_filter.rb index 42b27a8bd9..db47797f03 100644 --- a/modules/ldap_groups/lib/open_project/ldap_groups/synchronize_filter.rb +++ b/modules/ldap_groups/lib/open_project/ldap_groups/synchronize_filter.rb @@ -52,7 +52,6 @@ module OpenProject::LdapGroups filter: filter.parsed_filter_string, attributes: ['dn', group_name] ).each do |entry| - yield entry.dn, LdapAuthSource.get_attr(entry, group_name) end end @@ -80,6 +79,5 @@ module OpenProject::LdapGroups sync.group = Group.find_or_create_by!(groupname: name) end end - end end diff --git a/modules/ldap_groups/lib/tasks/ldap_groups.rake b/modules/ldap_groups/lib/tasks/ldap_groups.rake index 44432455bf..7cc0207ac5 100644 --- a/modules/ldap_groups/lib/tasks/ldap_groups.rake +++ b/modules/ldap_groups/lib/tasks/ldap_groups.rake @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -42,36 +43,35 @@ namespace :ldap_groups do ldap_server = Ladle::Server.new(quiet: false, port: '12389', domain: 'dc=example,dc=com', ldif: ldif).start puts <<~EOS - - LDAP server ready at localhost:12389 - Users Base dn: ou=people,dc=example,dc=com - Admin account: uid=admin,ou=system - Admin password: secret - - -------------------------------------------------------- - - Attributes - Login: uid - First name: givenName - Last name: sn - Email: mail - memberOf: (Hard-coded, not virtual) - - -------------------------------------------------------- - - Users: - uid=aa729,ou=people,dc=example,dc=com (Password: smada) - uid=bb459,ou=people,dc=example,dc=com (Password: niwdlab) - uid=cc414,ou=people,dc=example,dc=com (Password: retneprac) - - -------------------------------------------------------- - - Groups: - cn=foo,ou=groups,dc=example,dc=com (Members: aa729) - cn=bar,ou=groups,dc=example,dc=com (Members: aa729, bb459, cc414) + #{' '} + LDAP server ready at localhost:12389 + Users Base dn: ou=people,dc=example,dc=com + Admin account: uid=admin,ou=system + Admin password: secret + #{' '} + -------------------------------------------------------- + #{' '} + Attributes + Login: uid + First name: givenName + Last name: sn + Email: mail + memberOf: (Hard-coded, not virtual) + #{' '} + -------------------------------------------------------- + #{' '} + Users: + uid=aa729,ou=people,dc=example,dc=com (Password: smada) + uid=bb459,ou=people,dc=example,dc=com (Password: niwdlab) + uid=cc414,ou=people,dc=example,dc=com (Password: retneprac) + #{' '} + -------------------------------------------------------- + #{' '} + Groups: + cn=foo,ou=groups,dc=example,dc=com (Members: aa729) + cn=bar,ou=groups,dc=example,dc=com (Members: aa729, bb459, cc414) EOS - puts "Send CTRL+D to stop the server" require 'irb'; binding.irb diff --git a/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb b/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb index a668127c70..495775856a 100644 --- a/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb +++ b/modules/ldap_groups/spec/factories/synchronized_filter_factory.rb @@ -6,4 +6,3 @@ FactoryBot.define do auth_source factory: :ldap_auth_source end end - diff --git a/modules/ldap_groups/spec/lib/synchronization_spec.rb b/modules/ldap_groups/spec/lib/synchronization_spec.rb index c1cc0c8d86..47f1aca982 100644 --- a/modules/ldap_groups/spec/lib/synchronization_spec.rb +++ b/modules/ldap_groups/spec/lib/synchronization_spec.rb @@ -3,12 +3,13 @@ require 'ladle' describe OpenProject::LdapGroups::Synchronization, with_ee: %i[ldap_groups] do let(:plugin_settings) do - {group_base: 'ou=groups,dc=example,dc=com', group_key: 'cn'} + { group_base: 'ou=groups,dc=example,dc=com', group_key: 'cn' } end before(:all) do ldif = Rails.root.join('spec/fixtures/ldap/users.ldif') - @ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com', ldif: ldif).start + @ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com', + ldif: ldif).start end after(:all) do @@ -42,8 +43,14 @@ describe OpenProject::LdapGroups::Synchronization, with_ee: %i[ldap_groups] do let(:group_foo) { FactoryBot.create :group, lastname: 'foo_internal' } let(:group_bar) { FactoryBot.create :group, lastname: 'bar' } - let(:synced_foo) { FactoryBot.create :ldap_synchronized_group, dn: 'cn=foo,ou=groups,dc=example,dc=com', group: group_foo, auth_source: auth_source } - let(:synced_bar) { FactoryBot.create :ldap_synchronized_group, dn: 'cn=bar,ou=groups,dc=example,dc=com', group: group_bar, auth_source: auth_source } + let(:synced_foo) do + FactoryBot.create :ldap_synchronized_group, dn: 'cn=foo,ou=groups,dc=example,dc=com', group: group_foo, + auth_source: auth_source + end + let(:synced_bar) do + FactoryBot.create :ldap_synchronized_group, dn: 'cn=bar,ou=groups,dc=example,dc=com', group: group_bar, + auth_source: auth_source + end subject do # Need the system user for admin permission @@ -113,7 +120,6 @@ describe OpenProject::LdapGroups::Synchronization, with_ee: %i[ldap_groups] do user_cc414 end - describe 'synchronizes all memberships' do before do subject @@ -259,8 +265,14 @@ describe OpenProject::LdapGroups::Synchronization, with_ee: %i[ldap_groups] do end context 'with invalid base' do - let(:synced_foo) { FactoryBot.create :ldap_synchronized_group, dn: 'cn=foo,ou=invalid,dc=example,dc=com', group: group_foo, auth_source: auth_source } - let(:synced_bar) { FactoryBot.create :ldap_synchronized_group, dn: 'cn=bar,ou=invalid,dc=example,dc=com', group: group_bar, auth_source: auth_source } + let(:synced_foo) do + FactoryBot.create :ldap_synchronized_group, dn: 'cn=foo,ou=invalid,dc=example,dc=com', group: group_foo, + auth_source: auth_source + end + let(:synced_bar) do + FactoryBot.create :ldap_synchronized_group, dn: 'cn=bar,ou=invalid,dc=example,dc=com', group: group_bar, + auth_source: auth_source + end context 'when one synced group exists' do before do diff --git a/modules/ldap_groups/spec/lib/synchronize_filter_spec.rb b/modules/ldap_groups/spec/lib/synchronize_filter_spec.rb index 02f5c527a5..1a8f58f8a0 100644 --- a/modules/ldap_groups/spec/lib/synchronize_filter_spec.rb +++ b/modules/ldap_groups/spec/lib/synchronize_filter_spec.rb @@ -4,7 +4,8 @@ require 'ladle' describe OpenProject::LdapGroups::SynchronizeFilter, with_ee: %i[ldap_groups] do before(:all) do ldif = Rails.root.join('spec/fixtures/ldap/users.ldif') - @ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com', ldif: ldif).start + @ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com', + ldif: ldif).start end after(:all) do @@ -30,8 +31,14 @@ describe OpenProject::LdapGroups::SynchronizeFilter, with_ee: %i[ldap_groups] do let(:group_foo) { FactoryBot.create :group, lastname: 'foo' } let(:group_bar) { FactoryBot.create :group, lastname: 'bar' } - let(:synced_foo) { FactoryBot.create :ldap_synchronized_group, dn: 'cn=foo,ou=groups,dc=example,dc=com', group: group_foo, auth_source: auth_source } - let(:synced_bar) { FactoryBot.create :ldap_synchronized_group, dn: 'cn=bar,ou=groups,dc=example,dc=com', group: group_bar, auth_source: auth_source } + let(:synced_foo) do + FactoryBot.create :ldap_synchronized_group, dn: 'cn=foo,ou=groups,dc=example,dc=com', group: group_foo, + auth_source: auth_source + end + let(:synced_bar) do + FactoryBot.create :ldap_synchronized_group, dn: 'cn=bar,ou=groups,dc=example,dc=com', group: group_bar, + auth_source: auth_source + end let(:filter_foo_bar) { FactoryBot.create :ldap_synchronized_filter, auth_source: auth_source } @@ -45,7 +52,8 @@ describe OpenProject::LdapGroups::SynchronizeFilter, with_ee: %i[ldap_groups] do # Expect two synchronized groups added expect(filter_foo_bar.groups.count).to eq 2 - expect(filter_foo_bar.groups.map(&:dn)).to match_array ['cn=foo,ou=groups,dc=example,dc=com', 'cn=bar,ou=groups,dc=example,dc=com'] + expect(filter_foo_bar.groups.map(&:dn)).to match_array ['cn=foo,ou=groups,dc=example,dc=com', + 'cn=bar,ou=groups,dc=example,dc=com'] # Expect two actual groups added op_foo_group = Group.find_by(lastname: 'foo') diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rb index 610b6aae24..c6ed7f1ab5 100644 --- a/modules/meeting/app/controllers/meetings_controller.rb +++ b/modules/meeting/app/controllers/meetings_controller.rb @@ -28,9 +28,9 @@ class MeetingsController < ApplicationController around_action :set_time_zone - before_action :find_project, only: [:index, :new, :create] - before_action :find_meeting, except: [:index, :new, :create] - before_action :convert_params, only: [:create, :update] + before_action :find_project, only: %i[index new create] + before_action :find_meeting, except: %i[index new create] + before_action :convert_params, only: %i[create update] before_action :authorize helper :watchers @@ -39,7 +39,7 @@ class MeetingsController < ApplicationController include WatchersHelper include PaginationHelper - menu_item :new_meeting, only: [:new, :create] + menu_item :new_meeting, only: %i[new create] def index scope = @project.meetings @@ -68,7 +68,8 @@ class MeetingsController < ApplicationController if params[:copied_from_meeting_id].present? && params[:copied_meeting_agenda_text].present? @meeting.agenda = MeetingAgenda.new( text: params[:copied_meeting_agenda_text], - comment: "Copied from Meeting ##{params[:copied_from_meeting_id]}") + comment: "Copied from Meeting ##{params[:copied_from_meeting_id]}" + ) @meeting.agenda.author = User.current end if @meeting.save @@ -160,10 +161,8 @@ class MeetingsController < ApplicationController @converted_params[:participants_attributes].each { |p| p.reverse_merge! attended: false, invited: false } end - private - def meeting_params params.require(:meeting).permit(:title, :location, :start_time, :duration, :start_date, :start_time_hour, - participants_attributes: [:email, :name, :invited, :attended, :user, :user_id, :meeting, :id]) + participants_attributes: %i[email name invited attended user user_id meeting id]) end end diff --git a/modules/meeting/app/helpers/meeting_contents_helper.rb b/modules/meeting/app/helpers/meeting_contents_helper.rb index fa46c2200a..933f9b9c8f 100644 --- a/modules/meeting/app/helpers/meeting_contents_helper.rb +++ b/modules/meeting/app/helpers/meeting_contents_helper.rb @@ -54,9 +54,11 @@ module MeetingContentsHelper end def meeting_agenda_toggle_status_link(content, content_type) - content.meeting.agenda.present? && content.meeting.agenda.locked? ? - open_meeting_agenda_link(content_type, content.meeting) : + if content.meeting.agenda.present? && content.meeting.agenda.locked? + open_meeting_agenda_link(content_type, content.meeting) + else close_meeting_agenda_link(content_type, content.meeting) + end end def close_meeting_agenda_link(content_type, meeting) diff --git a/modules/meeting/app/helpers/meetings_helper.rb b/modules/meeting/app/helpers/meetings_helper.rb index af6ea90334..c9434ac34b 100644 --- a/modules/meeting/app/helpers/meetings_helper.rb +++ b/modules/meeting/app/helpers/meetings_helper.rb @@ -43,7 +43,7 @@ module MeetingsHelper end # This renders a journal entry with a header and details - def render_journal_details(journal, header_label = :label_updated_time_by, model = nil, options = {}) + def render_journal_details(journal, header_label = :label_updated_time_by, _model = nil, options = {}) header = <<-HTML
#{avatar(journal.user)} @@ -57,11 +57,11 @@ module MeetingsHelper if journal.details.any? details = content_tag 'ul', class: 'details journal-attributes' do - journal.details.map { |detail| + journal.details.map do |detail| if d = journal.render_detail(detail, cache: options[:cache]) content_tag('li', d.html_safe) end - }.compact.join(' ').html_safe + end.compact.join(' ').html_safe end end diff --git a/modules/meeting/app/models/activities/meeting_activity_provider.rb b/modules/meeting/app/models/activities/meeting_activity_provider.rb index 55b1584e2b..bf1b03238a 100644 --- a/modules/meeting/app/models/activities/meeting_activity_provider.rb +++ b/modules/meeting/app/models/activities/meeting_activity_provider.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -109,7 +110,11 @@ class Activities::MeetingActivityProvider < Activities::BaseActivityProvider end end_time = start_time + event['meeting_duration'].to_f.hours - "#{I18n.t(:label_meeting)}: #{event['meeting_title']} (#{format_date start_time} #{format_time start_time, false}-#{format_time end_time, false})" + fstart_with = format_date start_time + fstart_without = format_time start_time, false + fend_without = format_time end_time, false + + "#{I18n.t(:label_meeting)}: #{event['meeting_title']} (#{fstart_with} #{fstart_without}-#{fend_without})" else "#{event['meeting_content_type'].constantize.model_name.human}: #{event['meeting_title']}" end diff --git a/modules/meeting/app/models/journal/meeting_content_journal.rb b/modules/meeting/app/models/journal/meeting_content_journal.rb index 54953c294e..f6a1ed00bc 100644 --- a/modules/meeting/app/models/journal/meeting_content_journal.rb +++ b/modules/meeting/app/models/journal/meeting_content_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/meeting/app/models/journal/meeting_journal.rb b/modules/meeting/app/models/journal/meeting_journal.rb index 002da7f9e7..49c3b4a89a 100644 --- a/modules/meeting/app/models/journal/meeting_journal.rb +++ b/modules/meeting/app/models/journal/meeting_journal.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/meeting/app/models/meeting.rb b/modules/meeting/app/models/meeting.rb index 15c19a4139..ad5f2c868e 100644 --- a/modules/meeting/app/models/meeting.rb +++ b/modules/meeting/app/models/meeting.rb @@ -38,9 +38,9 @@ class Meeting < ApplicationRecord has_many :contents, -> { readonly }, class_name: 'MeetingContent' has_many :participants, dependent: :destroy, class_name: 'MeetingParticipant' - default_scope { + default_scope do order("#{Meeting.table_name}.start_time DESC") - } + end scope :from_tomorrow, -> { where(['start_time >= ?', Date.tomorrow.beginning_of_day]) } scope :with_users_by_date, -> { order("#{Meeting.table_name}.title ASC") @@ -50,19 +50,19 @@ class Meeting < ApplicationRecord acts_as_watchable acts_as_searchable columns: ["#{table_name}.title", "#{MeetingContent.table_name}.text"], - include: [:contents, :project], + include: %i[contents project], references: :meeting_contents, date_column: "#{table_name}.created_at" acts_as_journalized acts_as_event title: Proc.new { |o| - "#{I18n.t(:label_meeting)}: #{o.title} \ + "#{I18n.t(:label_meeting)}: #{o.title} \ #{format_date o.start_time} \ #{format_time o.start_time, false}-#{format_time o.end_time, false})" - }, - url: Proc.new { |o| { controller: '/meetings', action: 'show', id: o } }, - author: Proc.new(&:user), - description: '' + }, + url: Proc.new { |o| { controller: '/meetings', action: 'show', id: o } }, + author: Proc.new(&:user), + description: '' register_on_journal_formatter(:plaintext, 'title') register_on_journal_formatter(:fraction, 'duration') @@ -126,7 +126,7 @@ class Meeting < ApplicationRecord def author=(user) super # Don't add the author as participant if we already have some through nested attributes - participants.build(user: user, invited: true) if self.new_record? && participants.empty? && user + participants.build(user: user, invited: true) if new_record? && participants.empty? && user end # Returns true if usr or current user is allowed to view the meeting @@ -227,8 +227,8 @@ class Meeting < ApplicationRecord if parse_start_time? errors.add :start_date, :not_an_iso_date if parsed_start_date.nil? errors.add :start_time_hour, :invalid_time_format if parsed_start_time_hour.nil? - else - errors.add :start_time, :invalid if start_time.nil? + elsif start_time.nil? + errors.add :start_time, :invalid end end diff --git a/modules/meeting/app/models/meeting_content.rb b/modules/meeting/app/models/meeting_content.rb index 804a77896f..03f48a054d 100644 --- a/modules/meeting/app/models/meeting_content.rb +++ b/modules/meeting/app/models/meeting_content.rb @@ -50,7 +50,7 @@ class MeetingContent < ApplicationRecord ) acts_as_journalized - acts_as_event type: Proc.new { |o| "#{o.class.to_s.underscore.dasherize}" }, + acts_as_event type: Proc.new { |o| o.class.to_s.underscore.dasherize.to_s }, title: Proc.new { |o| "#{o.class.model_name.human}: #{o.meeting.title}" }, url: Proc.new { |o| { controller: '/meetings', action: 'show', id: o.meeting } } diff --git a/modules/meeting/app/models/meeting_participant.rb b/modules/meeting/app/models/meeting_participant.rb index 57cc29b1d1..798866540d 100644 --- a/modules/meeting/app/models/meeting_participant.rb +++ b/modules/meeting/app/models/meeting_participant.rb @@ -45,8 +45,8 @@ class MeetingParticipant < ApplicationRecord user.present? ? user.mail : mail end - def <=>(participant) - to_s.downcase <=> participant.to_s.downcase + def <=>(other) + to_s.downcase <=> other.to_s.downcase end alias :to_s :name diff --git a/modules/meeting/app/services/meeting_notification_service.rb b/modules/meeting/app/services/meeting_notification_service.rb index 059a71cae7..9673bb806d 100644 --- a/modules/meeting/app/services/meeting_notification_service.rb +++ b/modules/meeting/app/services/meeting_notification_service.rb @@ -1,5 +1,4 @@ class MeetingNotificationService - attr_reader :meeting, :content_type def initialize(meeting, content_type) @@ -20,16 +19,14 @@ class MeetingNotificationService recipients_with_errors = [] meeting.participants.includes(:user).each do |recipient| - begin - next if recipient.mail == author_mail && do_not_notify_author + next if recipient.mail == author_mail && do_not_notify_author - MeetingMailer.send(action, content, content_type, recipient.user).deliver_now - rescue => e - Rails.logger.error { - "Failed to deliver #{action} notification to #{recipient.mail}: #{e.message}" - } - recipients_with_errors << recipient + MeetingMailer.send(action, content, content_type, recipient.user).deliver_now + rescue StandardError => e + Rails.logger.error do + "Failed to deliver #{action} notification to #{recipient.mail}: #{e.message}" end + recipients_with_errors << recipient end recipients_with_errors diff --git a/modules/meeting/config/routes.rb b/modules/meeting/config/routes.rb index 0eadbb6e10..93636c38d1 100644 --- a/modules/meeting/config/routes.rb +++ b/modules/meeting/config/routes.rb @@ -27,13 +27,11 @@ #++ OpenProject::Application.routes.draw do - scope 'projects/:project_id' do - resources :meetings, only: [:new, :create, :index] + resources :meetings, only: %i[new create index] end - resources :meetings, except: [:new, :create, :index] do - + resources :meetings, except: %i[new create index] do resource :agenda, controller: 'meeting_agendas', only: [:update] do member do get :history @@ -49,7 +47,7 @@ OpenProject::Application.routes.draw do controller: 'meeting_agendas' end - resource :contents, controller: 'meeting_contents', only: [:show, :update] do + resource :contents, controller: 'meeting_contents', only: %i[show update] do member do get :history get :diff diff --git a/modules/meeting/db/migrate/20180323135408_to_v710_aggregated_meeting_migrations.rb b/modules/meeting/db/migrate/20180323135408_to_v710_aggregated_meeting_migrations.rb index 077b9cff6c..157161dcb4 100644 --- a/modules/meeting/db/migrate/20180323135408_to_v710_aggregated_meeting_migrations.rb +++ b/modules/meeting/db/migrate/20180323135408_to_v710_aggregated_meeting_migrations.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require Rails.root.join("db","migrate","migration_utils","migration_squasher").to_s +require Rails.root.join("db", "migrate", "migration_utils", "migration_squasher").to_s # This migration aggregates the migrations detailed in MIGRATION_FILES class ToV710AggregatedMeetingMigrations < ActiveRecord::Migration[5.1] - MIGRATION_FILES = <<-MIGRATIONS 20111605171865_aggregated_meeting_migrations.rb 20130924114042_legacy_meeting_minutes_journal_data.rb @@ -51,7 +50,7 @@ class ToV710AggregatedMeetingMigrations < ActiveRecord::Migration[5.1] t.integer 'lock_version' t.datetime 'created_at', null: false t.datetime 'updated_at', null: false - t.boolean 'locked', default: false + t.boolean 'locked', default: false end create_table 'meeting_participants', id: :integer do |t| @@ -75,10 +74,9 @@ class ToV710AggregatedMeetingMigrations < ActiveRecord::Migration[5.1] t.datetime 'created_at', null: false t.datetime 'updated_at', null: false - t.index [:project_id, :updated_at] + t.index %i[project_id updated_at] end - create_table :meeting_journals, id: :integer do |t| t.integer :journal_id, null: false t.string :title diff --git a/modules/meeting/lib/api/v3/meeting_contents/meeting_content_representer.rb b/modules/meeting/lib/api/v3/meeting_contents/meeting_content_representer.rb index 4d6f164075..d6841657bd 100644 --- a/modules/meeting/lib/api/v3/meeting_contents/meeting_content_representer.rb +++ b/modules/meeting/lib/api/v3/meeting_contents/meeting_content_representer.rb @@ -43,6 +43,7 @@ module API associated_resource :project, link: ->(*) do next unless represented.project.present? + { href: api_v3_paths.project(represented.project.id), title: represented.project.name diff --git a/modules/meeting/lib/open_project/meeting/default_data.rb b/modules/meeting/lib/open_project/meeting/default_data.rb index cba1fa0862..66aacf3285 100644 --- a/modules/meeting/lib/open_project/meeting/default_data.rb +++ b/modules/meeting/lib/open_project/meeting/default_data.rb @@ -17,17 +17,17 @@ module OpenProject end def member_permissions - [ - :create_meetings, - :edit_meetings, - :delete_meetings, - :view_meetings, - :create_meeting_agendas, - :close_meeting_agendas, - :send_meeting_agendas_notification, - :send_meeting_agendas_icalendar, - :create_meeting_minutes, - :send_meeting_minutes_notification + %i[ + create_meetings + edit_meetings + delete_meetings + view_meetings + create_meeting_agendas + close_meeting_agendas + send_meeting_agendas_notification + send_meeting_agendas_icalendar + create_meeting_minutes + send_meeting_minutes_notification ] end diff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rb index 87a41a9748..d130f8dd7e 100644 --- a/modules/meeting/lib/open_project/meeting/engine.rb +++ b/modules/meeting/lib/open_project/meeting/engine.rb @@ -38,16 +38,17 @@ module OpenProject::Meeting author_url: 'https://www.openproject.com', bundled: true do project_module :meetings do - permission :view_meetings, meetings: [:index, :show], meeting_agendas: [:history, :show, :diff], meeting_minutes: [:history, :show, :diff] - permission :create_meetings, { meetings: [:new, :create, :copy] }, require: :member - permission :edit_meetings, { meetings: [:edit, :update] }, require: :member + permission :view_meetings, meetings: %i[index show], meeting_agendas: %i[history show diff], + meeting_minutes: %i[history show diff] + permission :create_meetings, { meetings: %i[new create copy] }, require: :member + permission :edit_meetings, { meetings: %i[edit update] }, require: :member permission :delete_meetings, { meetings: [:destroy] }, require: :member permission :meetings_send_invite, { meetings: [:icalendar] }, require: :member - permission :create_meeting_agendas, { meeting_agendas: [:update, :preview] }, require: :member - permission :close_meeting_agendas, { meeting_agendas: [:close, :open] }, require: :member + permission :create_meeting_agendas, { meeting_agendas: %i[update preview] }, require: :member + permission :close_meeting_agendas, { meeting_agendas: %i[close open] }, require: :member permission :send_meeting_agendas_notification, { meeting_agendas: [:notify] }, require: :member permission :send_meeting_agendas_icalendar, { meeting_agendas: [:icalendar] }, require: :member - permission :create_meeting_minutes, { meeting_minutes: [:update, :preview] }, require: :member + permission :create_meeting_minutes, { meeting_minutes: %i[update preview] }, require: :member permission :send_meeting_minutes_notification, { meeting_minutes: [:notify] }, require: :member end diff --git a/modules/meeting/lib/open_project/meeting/patches/project_patch.rb b/modules/meeting/lib/open_project/meeting/patches/project_patch.rb index a9e3decb00..ae6211a751 100644 --- a/modules/meeting/lib/open_project/meeting/patches/project_patch.rb +++ b/modules/meeting/lib/open_project/meeting/patches/project_patch.rb @@ -38,4 +38,4 @@ module OpenProject::Meeting end end -Project.send(:include, OpenProject::Meeting::Patches::ProjectPatch) +Project.include OpenProject::Meeting::Patches::ProjectPatch diff --git a/modules/meeting/lib/open_project/meeting/patches/setting_seeder_patch.rb b/modules/meeting/lib/open_project/meeting/patches/setting_seeder_patch.rb index 33c4e338db..5bcb63c152 100644 --- a/modules/meeting/lib/open_project/meeting/patches/setting_seeder_patch.rb +++ b/modules/meeting/lib/open_project/meeting/patches/setting_seeder_patch.rb @@ -43,4 +43,3 @@ module OpenProject::Meeting::Patches::SettingSeederPatch end end end - diff --git a/modules/meeting/openproject-meeting.gemspec b/modules/meeting/openproject-meeting.gemspec index a1cfd12525..9ff5b8d09a 100644 --- a/modules/meeting/openproject-meeting.gemspec +++ b/modules/meeting/openproject-meeting.gemspec @@ -1,4 +1,5 @@ # encoding: UTF-8 + # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = 'openproject-meeting' diff --git a/modules/meeting/spec/controllers/meetings_controller_spec.rb b/modules/meeting/spec/controllers/meetings_controller_spec.rb index 7a20c7f6ad..0d922234d7 100644 --- a/modules/meeting/spec/controllers/meetings_controller_spec.rb +++ b/modules/meeting/spec/controllers/meetings_controller_spec.rb @@ -47,7 +47,7 @@ describe MeetingsController, type: :controller do allow(@ms).to receive(:from_tomorrow).and_return(@ms) allow(project).to receive(:meetings).and_return(@ms) - [:with_users_by_date, :page, :per_page].each do |meth| + %i[with_users_by_date page per_page].each do |meth| expect(@ms).to receive(meth).and_return(@ms) end @grouped = double('grouped') @@ -55,7 +55,7 @@ describe MeetingsController, type: :controller do end describe 'html' do before(:each) do - get 'index', params: { project_id: project.id } + get 'index', params: { project_id: project.id } end it { expect(response).to be_successful } it { expect(assigns(:meetings_by_start_year_month_date)).to eql @grouped } @@ -97,7 +97,7 @@ describe MeetingsController, type: :controller do end describe 'html' do before(:each) do - get 'edit', params: { id: @m.id } + get 'edit', params: { id: @m.id } end it { expect(response).to be_successful } it { expect(assigns(:meeting)).to eql @m } diff --git a/modules/meeting/spec/features/meetings_locking_spec.rb b/modules/meeting/spec/features/meetings_locking_spec.rb index c2db89ddb2..97a96c6223 100644 --- a/modules/meeting/spec/features/meetings_locking_spec.rb +++ b/modules/meeting/spec/features/meetings_locking_spec.rb @@ -41,7 +41,6 @@ describe 'Meetings locking', type: :feature, js: true do end it 'shows an error when trying to update a meeting update while editing' do - # Edit agenda within '#tab-content-agenda' do find('.button--edit-agenda').click diff --git a/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rb b/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rb index b055a44aa5..72d3272feb 100644 --- a/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rb +++ b/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rb @@ -32,7 +32,6 @@ describe OpenProject::TextFormatting, 'Meeting links', # Speeds up the spec by avoiding event mailers to be procssed with_settings: { notified_events: [] } do - include ActionView::Helpers::UrlHelper # soft-dependency include ActionView::Context include OpenProject::StaticRouting::UrlHelpers diff --git a/modules/meeting/spec/mailers/meeting_mailer_spec.rb b/modules/meeting/spec/mailers/meeting_mailer_spec.rb index aa39b74022..006d1af438 100644 --- a/modules/meeting/spec/mailers/meeting_mailer_spec.rb +++ b/modules/meeting/spec/mailers/meeting_mailer_spec.rb @@ -82,7 +82,7 @@ describe MeetingMailer, type: :mailer do expect(mail.text_part.body).to include('GMT+09:00') expect(mail.html_part.body).to include('Tokyo') expect(mail.html_part.body).to include('GMT+09:00') - + expect(mail.to).to match_array([watcher1.mail]) end end @@ -91,9 +91,9 @@ describe MeetingMailer, type: :mailer do def check_meeting_mail_content(body) expect(body).to include(meeting.project.name) expect(body).to include(meeting.title) - expect(body).to include(i18n.format_date meeting.start_date) - expect(body).to include(i18n.format_time meeting.start_time, false) - expect(body).to include(i18n.format_time meeting.end_time, false) + expect(body).to include(i18n.format_date(meeting.start_date)) + expect(body).to include(i18n.format_time(meeting.start_time, false)) + expect(body).to include(i18n.format_time(meeting.end_time, false)) expect(body).to include(meeting.participants[0].name) expect(body).to include(meeting.participants[1].name) end diff --git a/modules/meeting/spec/models/project/activity_spec.rb b/modules/meeting/spec/models/project/activity_spec.rb index 4c515fe5f3..2304a52723 100644 --- a/modules/meeting/spec/models/project/activity_spec.rb +++ b/modules/meeting/spec/models/project/activity_spec.rb @@ -37,17 +37,17 @@ describe Projects::Activity, type: :model do let(:meeting) do FactoryBot.create(:meeting, - project: project) + project: project) end let(:meeting2) do FactoryBot.create(:meeting, - project: project) + project: project) end let(:work_package) do FactoryBot.create(:work_package, - project: project) + project: project) end def latest_activity diff --git a/modules/meeting/spec/models/user_deletion_spec.rb b/modules/meeting/spec/models/user_deletion_spec.rb index 16a55c8784..9cd260d496 100644 --- a/modules/meeting/spec/models/user_deletion_spec.rb +++ b/modules/meeting/spec/models/user_deletion_spec.rb @@ -148,7 +148,7 @@ describe User, '#destroy', type: :model do let(:associations) { [:author] } let(:associated_instance) do FactoryBot.build(:meeting_agenda, meeting: meeting, - text: 'lorem') + text: 'lorem') end let(:associated_class) { MeetingAgenda } @@ -159,7 +159,7 @@ describe User, '#destroy', type: :model do let(:associations) { [:author] } let(:associated_instance) do FactoryBot.build(:meeting_agenda, meeting: meeting, - text: 'lorem') + text: 'lorem') end let(:associated_class) { MeetingAgenda } diff --git a/modules/my_page/spec/features/my/my_page_spec.rb b/modules/my_page/spec/features/my/my_page_spec.rb index 817d1104cc..d7af475f3a 100644 --- a/modules/my_page/spec/features/my/my_page_spec.rb +++ b/modules/my_page/spec/features/my/my_page_spec.rb @@ -91,7 +91,7 @@ describe 'My page', type: :feature, js: true do end def find_area(name) - index = grid.widgets.sort_by(&:id).each_with_index.detect { |w, index| w.options["name"] == name }.last + index = grid.widgets.sort_by(&:id).each_with_index.detect { |w, _index| w.options["name"] == name }.last Components::Grids::GridArea.new(".grid--area.-widgeted:nth-of-type(#{index + 1})") end diff --git a/modules/openid_connect/app/cells/openid_connect/providers/table_cell.rb b/modules/openid_connect/app/cells/openid_connect/providers/table_cell.rb index aa8bc4f600..d26f8b9968 100644 --- a/modules/openid_connect/app/cells/openid_connect/providers/table_cell.rb +++ b/modules/openid_connect/app/cells/openid_connect/providers/table_cell.rb @@ -4,7 +4,7 @@ module OpenIDConnect columns :name def initial_sort - [:id, :asc] + %i[id asc] end def sortable? @@ -17,7 +17,7 @@ module OpenIDConnect def headers [ - ['name', caption: I18n.t('attributes.name')] + ['name', { caption: I18n.t('attributes.name') }] ] end end diff --git a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb index 9fadc28776..b0cecf0186 100644 --- a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb +++ b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb @@ -5,7 +5,7 @@ module OpenIDConnect before_action :require_admin before_action :check_ee - before_action :find_provider, only: [:edit, :update, :destroy] + before_action :find_provider, only: %i[edit update destroy] def index; end @@ -57,7 +57,7 @@ module OpenIDConnect def check_ee if EnterpriseToken.show_banners? render template: '/openid_connect/providers/upsale' - return false + false end end diff --git a/modules/openid_connect/app/models/openid_connect/provider.rb b/modules/openid_connect/app/models/openid_connect/provider.rb index cd133292dd..56ae712dce 100644 --- a/modules/openid_connect/app/models/openid_connect/provider.rb +++ b/modules/openid_connect/app/models/openid_connect/provider.rb @@ -14,6 +14,7 @@ module OpenIDConnect attr_reader :errors, :omniauth_provider attr_accessor :display_name + delegate :name, to: :omniauth_provider, allow_nil: true delegate :identifier, to: :omniauth_provider, allow_nil: true delegate :secret, to: :omniauth_provider, allow_nil: true @@ -40,6 +41,7 @@ module OpenIDConnect def id return nil unless persisted? + name end @@ -52,6 +54,7 @@ module OpenIDConnect def save return false unless valid? + config = Setting.plugin_openproject_openid_connect || Hash.new config["providers"] ||= Hash.new config["providers"][name] = omniauth_provider.to_h.stringify_keys diff --git a/modules/openid_connect/config/routes.rb b/modules/openid_connect/config/routes.rb index aba9d6fd24..f27795fcca 100644 --- a/modules/openid_connect/config/routes.rb +++ b/modules/openid_connect/config/routes.rb @@ -3,7 +3,7 @@ Rails.application.routes.draw do scope :admin do namespace :openid_connect do - resources :providers, only: [:index, :new, :create, :edit, :update, :destroy] + resources :providers, only: %i[index new create edit update destroy] end end end diff --git a/modules/openid_connect/openproject-openid_connect.gemspec b/modules/openid_connect/openproject-openid_connect.gemspec index ff00db3e35..3619e8b253 100644 --- a/modules/openid_connect/openproject-openid_connect.gemspec +++ b/modules/openid_connect/openproject-openid_connect.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.files = Dir['{app,config,db,lib}/**/*'] + %w(CHANGELOG.md README.md) - s.add_dependency 'openproject-auth_plugins' - s.add_dependency 'omniauth-openid_connect-providers', '~> 0.1' s.add_dependency 'lobby_boy', '~> 0.1.3' + s.add_dependency 'omniauth-openid_connect-providers', '~> 0.1' + s.add_dependency 'openproject-auth_plugins' end diff --git a/modules/openid_connect/spec/controllers/providers_controller_spec.rb b/modules/openid_connect/spec/controllers/providers_controller_spec.rb index 719c38c996..aa6ddcdd45 100644 --- a/modules/openid_connect/spec/controllers/providers_controller_spec.rb +++ b/modules/openid_connect/spec/controllers/providers_controller_spec.rb @@ -160,7 +160,6 @@ describe ::OpenIDConnect::ProvidersController, type: :controller do "providers" => { "azure" => { "identifier" => "IDENTIFIER", "secret" => "SECRET" } } } } do - it 'removes the provider' do delete :destroy, params: { id: "azure" } expect(response).to be_redirect diff --git a/modules/overviews/spec/controllers/overviews/overviews_controller_spec.rb b/modules/overviews/spec/controllers/overviews/overviews_controller_spec.rb index ca00beddf3..9a042760b2 100644 --- a/modules/overviews/spec/controllers/overviews/overviews_controller_spec.rb +++ b/modules/overviews/spec/controllers/overviews/overviews_controller_spec.rb @@ -29,7 +29,6 @@ require 'spec_helper' describe Overviews::OverviewsController, type: :controller do - let(:permissions) do %i(view_project) end diff --git a/modules/pdf_export/app/controllers/export_card_configurations_controller.rb b/modules/pdf_export/app/controllers/export_card_configurations_controller.rb index 5b1724c3bb..8791520b72 100644 --- a/modules/pdf_export/app/controllers/export_card_configurations_controller.rb +++ b/modules/pdf_export/app/controllers/export_card_configurations_controller.rb @@ -26,22 +26,18 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - class ExportCardConfigurationsController < ApplicationController layout 'admin' before_action :require_admin - before_action :load_config, only: [:show, :update, :edit, :destroy, :activate, :deactivate] + before_action :load_config, only: %i[show update edit destroy activate deactivate] before_action :load_configs, only: [:index] - def index - end + def index; end - def show - end + def show; end - def edit - end + def edit; end def new @config = ExportCardConfiguration.new diff --git a/modules/pdf_export/app/models/export_card_configuration.rb b/modules/pdf_export/app/models/export_card_configuration.rb index e1be84704a..009e9f7476 100644 --- a/modules/pdf_export/app/models/export_card_configuration.rb +++ b/modules/pdf_export/app/models/export_card_configuration.rb @@ -26,9 +26,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - class ExportCardConfiguration < ApplicationRecord - class RowsYamlValidator < ActiveModel::Validator REQUIRED_GROUP_KEYS = ["rows"] VALID_GROUP_KEYS = ["rows", "has_border", "height"] @@ -39,8 +37,8 @@ class ExportCardConfiguration < ApplicationRecord # VALID_MODEL_PROPERTIES = [""] REQUIRED_COLUMN_KEYS = [] VALID_COLUMN_KEYS = ["has_label", "min_font_size", "max_font_size", - "font_size", "font_style", "text_align", "minimum_lines", "render_if_empty", - "width", "indented", "custom_label", "has_count"] + "font_size", "font_style", "text_align", "minimum_lines", "render_if_empty", + "width", "indented", "custom_label", "has_count"] NUMERIC_COLUMN_VALUE = ["min_font_size", "max_font_size", "font_size", "minimum_lines"] def raise_yaml_error @@ -54,15 +52,18 @@ class ExportCardConfiguration < ApplicationRecord hash.assert_valid_keys valid_keys rescue ArgumentError => e # Small hack alert: Catch a raise error again but with localised text - raise ArgumentError, "#{I18n.t('validation_error_uknown_key')} '#{e.message.split(": ")[1]}'" + raise ArgumentError, "#{I18n.t('validation_error_uknown_key')} '#{e.message.split(': ')[1]}'" end pending_keys = required_keys - hash.keys - raise(ArgumentError, "#{I18n.t('validation_error_required_keys_not_present')} #{pending_keys.join(", ")}") unless pending_keys.empty? + unless pending_keys.empty? + raise(ArgumentError, + "#{I18n.t('validation_error_required_keys_not_present')} #{pending_keys.join(', ')}") + end end def check_valid_value_type(value, type) - raise(ArgumentError, "#{I18n.t('validation_error_yaml_is_badly_formed')}") unless value.is_a?type + raise(ArgumentError, I18n.t('validation_error_yaml_is_badly_formed').to_s) unless value.is_a? type end def validate(record) @@ -73,20 +74,20 @@ class ExportCardConfiguration < ApplicationRecord end rescue Psych::SyntaxError => e record.errors[:rows] << I18n.t('validation_error_yaml_is_badly_formed') - return false + return false end begin groups = YAML::load(record.rows) - groups.each do |gk, gv| + groups.each do |_gk, gv| assert_required_keys(gv, VALID_GROUP_KEYS, REQUIRED_GROUP_KEYS) raise_yaml_error if !gv["rows"].is_a?(Hash) - gv["rows"].each do |rk, rv| + gv["rows"].each do |_rk, rv| assert_required_keys(rv, VALID_ROW_KEYS, REQUIRED_ROW_KEYS) raise_yaml_error if !rv["columns"].is_a?(Hash) - rv["columns"].each do |ck, cv| + rv["columns"].each do |_ck, cv| assert_required_keys(cv, VALID_COLUMN_KEYS, REQUIRED_COLUMN_KEYS) - cv.map{|cname, cvalue | check_valid_value_type(cvalue, Numeric) if NUMERIC_COLUMN_VALUE.include?(cname)} + cv.map { |cname, cvalue| check_valid_value_type(cvalue, Numeric) if NUMERIC_COLUMN_VALUE.include?(cname) } end end end @@ -111,12 +112,12 @@ class ExportCardConfiguration < ApplicationRecord end def activate - self.update!({active: true}) + update!({ active: true }) end def deactivate - if !self.is_default? - self.update!({active: false}) + if !is_default? + update!({ active: false }) else false end @@ -133,22 +134,23 @@ class ExportCardConfiguration < ApplicationRecord def rows_hash config = YAML::load(rows) raise BadlyFormedExportCardConfigurationError.new(I18n.t('validation_error_yaml_is_badly_formed')) if !config.is_a?(Hash) + config end def is_default? - self.name.downcase == "default" + name.downcase == "default" end def can_delete? - !self.is_default? + !is_default? end def can_activate? - !self.active + !active end def can_deactivate? - self.active && !is_default? + active && !is_default? end end diff --git a/modules/pdf_export/config/routes.rb b/modules/pdf_export/config/routes.rb index a7e0052428..1749b0d6b8 100644 --- a/modules/pdf_export/config/routes.rb +++ b/modules/pdf_export/config/routes.rb @@ -26,14 +26,11 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - OpenProject::Application.routes.draw do - scope "", as: "pdf_export" do - resources :export_card_configurations, :controller => :export_card_configurations do + resources :export_card_configurations, controller: :export_card_configurations do post 'activate', on: :member post 'deactivate', on: :member end end - end diff --git a/modules/pdf_export/db/seeds/export_card_configurations.rb b/modules/pdf_export/db/seeds/export_card_configurations.rb index d95eb47ea4..400e7f4a75 100644 --- a/modules/pdf_export/db/seeds/export_card_configurations.rb +++ b/modules/pdf_export/db/seeds/export_card_configurations.rb @@ -26,11 +26,10 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - if ExportCardConfiguration.find_by_identifier("default").nil? - ExportCardConfiguration.create({name: "Default", - per_page: 2, - page_size: "A4", - orientation: "landscape", - rows: "rows:\n row1:\n has_border: false\n columns:\n id:\n has_label: false\n font_size: 20\n font_style: bold\n priority: 1\n minimum_lines: 2\n render_if_empty: false\n width: 30%\n due_date:\n has_label: false\n font_size: 15\n font_style: italic\n priority: 1\n minimum_lines: 2\n render_if_empty: false\n width: 70%\n row2:\n has_border: false\n columns:\n description:\n has_label: false\n font_size: 15\n font_style: normal\n priority: 4\n minimum_lines: 5\n render_if_empty: false\n width: 100%\n"}) + ExportCardConfiguration.create({ name: "Default", + per_page: 2, + page_size: "A4", + orientation: "landscape", + rows: "rows:\n row1:\n has_border: false\n columns:\n id:\n has_label: false\n font_size: 20\n font_style: bold\n priority: 1\n minimum_lines: 2\n render_if_empty: false\n width: 30%\n due_date:\n has_label: false\n font_size: 15\n font_style: italic\n priority: 1\n minimum_lines: 2\n render_if_empty: false\n width: 70%\n row2:\n has_border: false\n columns:\n description:\n has_label: false\n font_size: 15\n font_style: normal\n priority: 4\n minimum_lines: 5\n render_if_empty: false\n width: 100%\n" }) end diff --git a/modules/pdf_export/lib/open_project/pdf_export/engine.rb b/modules/pdf_export/lib/open_project/pdf_export/engine.rb index ad6033ef96..55ee9061f2 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/engine.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/engine.rb @@ -37,7 +37,6 @@ module OpenProject::PDFExport register 'openproject-pdf_export', author_url: 'https://www.openproject.com', bundled: true do - menu :admin_menu, :export_card_configurations, { controller: '/export_card_configurations', action: 'index' }, diff --git a/modules/pdf_export/lib/open_project/pdf_export/export_card/card_element.rb b/modules/pdf_export/lib/open_project/pdf_export/export_card/card_element.rb index 8dca689bc2..e829276f2b 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/export_card/card_element.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/export_card/card_element.rb @@ -50,9 +50,9 @@ module OpenProject::PDFExport::ExportCard current_y_offset = text_padding # Initialize groups - @groups_config.each_with_index do |(g_key, g_value), i| + @groups_config.each_with_index do |(_g_key, g_value), i| row_count = g_value["rows"].count - row_heights = all_heights[:row_heights].reject {|row| row[:group] != i}.map{|row| row[:height]} + row_heights = all_heights[:row_heights].reject { |row| row[:group] != i }.map { |row| row[:height] } group_height = all_heights[:group_heights][i] group_orientation = { y_offset: @orientation[:height] - current_y_offset, @@ -75,11 +75,11 @@ module OpenProject::PDFExport::ExportCard group_heights = Array.new row_heights = Array.new - groups.each_with_index do |(gk, gv), i| + groups.each_with_index do |(_gk, gv), i| enforced_group_height = gv["height"] || -1 used_group_height = 0 - gv["rows"].each do |rk, rv| + gv["rows"].each do |_rk, rv| # The + 1 on the height is needed as prawn does not seem to render # when the string to render has the same size as the row height. if rv["height"] @@ -101,6 +101,7 @@ module OpenProject::PDFExport::ExportCard available = @orientation[:height] - (@orientation[:group_padding] * 2) diff = available - heights[:group_heights].sum return false if diff >= 0 + diff *= -1 rows = heights[:row_heights] @@ -108,8 +109,8 @@ module OpenProject::PDFExport::ExportCard priorities = *(0..rows.count - 1) .zip(rows.map { |row| row[:priority] or 10 }) - .sort {|x,y| y[1] <=> x[1]} - .map {|x| x[0]} + .sort { |x, y| y[1] <=> x[1] } + .map { |x| x[0] } priorities.each do |p| to_reduce = rows[p] @@ -132,7 +133,7 @@ module OpenProject::PDFExport::ExportCard # Look through each of the row's columns for the column with the largest minimum height largest = 0 - row["columns"].each do |rk, rv| + row["columns"].each do |_rk, rv| min_lines = rv["minimum_lines"] || 1 font_size = rv["min_font_size"] || rv["font_size"] || 10 min_col_height = (@pdf.font.height_at(font_size) * min_lines).floor @@ -155,7 +156,6 @@ module OpenProject::PDFExport::ExportCard @pdf.stroke_bounds end - end end end diff --git a/modules/pdf_export/lib/open_project/pdf_export/export_card/column_element.rb b/modules/pdf_export/lib/open_project/pdf_export/export_card/column_element.rb index 4cc9bc2ca5..17e9e0b670 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/export_card/column_element.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/export_card/column_element.rb @@ -38,11 +38,11 @@ module OpenProject::PDFExport::ExportCard def draw # Get value from model - if @work_package.respond_to?(@property_name) - value = extract_property - else - value = extract_custom_field - end + value = if @work_package.respond_to?(@property_name) + extract_property + else + extract_custom_field + end draw_value(value) end @@ -65,7 +65,9 @@ module OpenProject::PDFExport::ExportCard value = "" available_languages.each do |locale| I18n.with_locale(locale) do - if (customs = @work_package.custom_field_values.select {|cf| cf.custom_field.name == @property_name} and customs.count > 0) + if customs = @work_package.custom_field_values.select do |cf| + cf.custom_field.name == @property_name + end and customs.count > 0 value = customs.first.value @custom_field = customs.first.custom_field end @@ -84,10 +86,10 @@ module OpenProject::PDFExport::ExportCard if @has_label custom_label = @config['custom_label'] label_text = if custom_label - "#{custom_label}" - else - localised_property_name - end + custom_label.to_s + else + localised_property_name + end if @config['has_count'] && value.is_a?(Array) label_text = "#{label_text} (#{value.count})" end @@ -102,13 +104,13 @@ module OpenProject::PDFExport::ExportCard def abbreviated_text(text, options) options = options.merge!({ document: @pdf }) text_box = Prawn::Text::Box.new(text, options) - left_over = text_box.render(:dry_run => true) + left_over = text_box.render(dry_run: true) # Be sure to do length arithmetics on chars, not bytes! left_over = left_over.mb_chars text = text.to_s.mb_chars - text = left_over.size > 0 ? text[0 ... -(left_over.size + 5)] + "[...]" : text + text = left_over.size > 0 ? text[0...-(left_over.size + 5)] + "[...]" : text text.to_s rescue Prawn::Errors::CannotFit '' @@ -147,10 +149,9 @@ module OpenProject::PDFExport::ExportCard @has_label = @config['has_label'] indented = @config['indented'] - # Flatten value to a display string display_value = value - display_value = display_value.map{|c| c.to_s }.join("\n") if display_value.is_a?(Array) + display_value = display_value.map { |c| c.to_s }.join("\n") if display_value.is_a?(Array) display_value = display_value.to_s if !display_value.is_a?(String) if @has_label && indented @@ -159,57 +160,58 @@ module OpenProject::PDFExport::ExportCard # Label Textbox offset = [@orientation[:x_offset], @orientation[:height] - (@orientation[:text_padding] / 2)] box = @pdf.text_box(label_text(value), - {:height => @orientation[:height], - :width => @orientation[:width] * width_ratio, - :at => offset, - :style => :bold, - :overflow => overflow, - :size => font_size, - :min_font_size => min_font_size, - :align => :left}) + { height: @orientation[:height], + width: @orientation[:width] * width_ratio, + at: offset, + style: :bold, + overflow: overflow, + size: font_size, + min_font_size: min_font_size, + align: :left }) # Get abbraviated text - options = {:height => @orientation[:height], - :width => @orientation[:width] * (1 - width_ratio), - :at => offset, - :style => font_style, - :overflow => overflow, - :size => font_size, - :min_font_size => min_font_size, - :align => text_align} + options = { height: @orientation[:height], + width: @orientation[:width] * (1 - width_ratio), + at: offset, + style: font_style, + overflow: overflow, + size: font_size, + min_font_size: min_font_size, + align: text_align } text = abbreviated_text(display_value, options) - offset = [@orientation[:x_offset] + (@orientation[:width] * width_ratio), @orientation[:height] - (@orientation[:text_padding] / 2)] + offset = [@orientation[:x_offset] + (@orientation[:width] * width_ratio), + @orientation[:height] - (@orientation[:text_padding] / 2)] # Content Textbox - box = @pdf.text_box(text, {:height => @orientation[:height], - :width => @orientation[:width] * (1 - width_ratio), - :at => offset, - :style => font_style, - :overflow => overflow, - :size => font_size, - :min_font_size => min_font_size, - :align => text_align}) + box = @pdf.text_box(text, { height: @orientation[:height], + width: @orientation[:width] * (1 - width_ratio), + at: offset, + style: font_style, + overflow: overflow, + size: font_size, + min_font_size: min_font_size, + align: text_align }) else - options = {:height => @orientation[:height], - :width => @orientation[:width], - :at => offset, - :style => font_style, - :overflow => overflow, - :min_font_size => min_font_size, - :align => text_align} + options = { height: @orientation[:height], + width: @orientation[:width], + at: offset, + style: font_style, + overflow: overflow, + min_font_size: min_font_size, + align: text_align } text = abbreviated_text(display_value, options) - texts = [{ text: label_text(value), styles: [:bold], :size => font_size }, { text: text, :size => font_size }] + texts = [{ text: label_text(value), styles: [:bold], size: font_size }, { text: text, size: font_size }] # Label and Content Textbox offset = [@orientation[:x_offset], @orientation[:height] - (@orientation[:text_padding] / 2)] - box = @pdf.formatted_text_box(texts, {:height => @orientation[:height], - :width => @orientation[:width], - :at => offset, - :style => font_style, - :overflow => overflow, - :min_font_size => min_font_size, - :align => text_align}) + box = @pdf.formatted_text_box(texts, { height: @orientation[:height], + width: @orientation[:width], + at: offset, + style: font_style, + overflow: overflow, + min_font_size: min_font_size, + align: text_align }) end end end diff --git a/modules/pdf_export/lib/open_project/pdf_export/export_card/document_generator.rb b/modules/pdf_export/lib/open_project/pdf_export/export_card/document_generator.rb index 26a2f4a6bb..187074b281 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/export_card/document_generator.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/export_card/document_generator.rb @@ -31,13 +31,7 @@ require 'prawn' module OpenProject::PDFExport::ExportCard require "open_project/pdf_export/export_card/model_display/work_package_display" class DocumentGenerator - - attr_reader :config - attr_reader :work_packages - attr_reader :pdf - attr_reader :current_position - attr_reader :paper_width - attr_reader :paper_height + attr_reader :config, :work_packages, :pdf, :current_position, :paper_width, :paper_height def initialize(config, work_packages) patch_models @@ -51,12 +45,13 @@ module OpenProject::PDFExport::ExportCard page_size = config.page_size or defaults[:page_size] @pdf = Prawn::Document.new( - :page_layout => page_layout, - :left_margin => 0, - :right_margin => 0, - :top_margin => 0, - :bottom_margin => 0, - :page_size => page_size) + page_layout: page_layout, + left_margin: 0, + right_margin: 0, + top_margin: 0, + bottom_margin: 0, + page_size: page_size + ) view = ::WorkPackage::PDFExport::View.new(I18n.locale) view.register_fonts! @pdf @@ -76,7 +71,7 @@ module OpenProject::PDFExport::ExportCard group_padding = 5 text_padding = 5 card_width = pdf.bounds.width - (card_padding * 2) - card_height = ((pdf.bounds.height - (card_padding * config.per_page )) / config.per_page) - (card_padding / config.per_page) + card_height = ((pdf.bounds.height - (card_padding * config.per_page)) / config.per_page) - (card_padding / config.per_page) card_y_offset = pdf.bounds.height - card_padding @work_packages.each_with_index do |wp, i| @@ -106,7 +101,7 @@ module OpenProject::PDFExport::ExportCard def patch_models # Note: Can't seem to patch the models when initializing for reasons which I don't understand - WorkPackage.send(:include, OpenProject::PDFExport::ExportCard::ModelDisplay::WorkPackageDisplay) + WorkPackage.include OpenProject::PDFExport::ExportCard::ModelDisplay::WorkPackageDisplay end end end diff --git a/modules/pdf_export/lib/open_project/pdf_export/export_card/group_element.rb b/modules/pdf_export/lib/open_project/pdf_export/export_card/group_element.rb index 281084647b..cbb3126e1a 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/export_card/group_element.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/export_card/group_element.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - module OpenProject::PDFExport::ExportCard class GroupElement include OpenProject::PDFExport::Exceptions @@ -42,7 +41,7 @@ module OpenProject::PDFExport::ExportCard current_y_offset = 0 row_heights = @orientation[:row_heights] - @rows_config.each_with_index do |(r_key, r_value), i| + @rows_config.each_with_index do |(_r_key, r_value), i| current_y_offset += (row_heights[i - 1]) if i > 0 row_orientation = { y_offset: @orientation[:height] - current_y_offset, @@ -70,11 +69,10 @@ module OpenProject::PDFExport::ExportCard row.draw end - if (@config["has_border"] or false) + if @config["has_border"] or false @pdf.stroke_bounds end end - end end end diff --git a/modules/pdf_export/lib/open_project/pdf_export/export_card/model_display/work_package_display.rb b/modules/pdf_export/lib/open_project/pdf_export/export_card/model_display/work_package_display.rb index c5a6298bb6..35803ee238 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/export_card/model_display/work_package_display.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/export_card/model_display/work_package_display.rb @@ -1,7 +1,7 @@ module OpenProject::PDFExport::ExportCard::ModelDisplay module WorkPackageDisplay def display_id - "#{kind.is_standard ? "" : "#{kind.name}"} ##{id}" + "#{kind.is_standard ? '' : kind.name.to_s} ##{id}" end end end diff --git a/modules/pdf_export/lib/open_project/pdf_export/export_card/row_element.rb b/modules/pdf_export/lib/open_project/pdf_export/export_card/row_element.rb index cd2f7279c5..528169f7a3 100644 --- a/modules/pdf_export/lib/open_project/pdf_export/export_card/row_element.rb +++ b/modules/pdf_export/lib/open_project/pdf_export/export_card/row_element.rb @@ -77,13 +77,12 @@ module OpenProject::PDFExport::ExportCard c.draw end end - end def self.prune_empty_groups(groups, wp) # Prune rows in groups - groups.each do |gk, gv| - self.prune_empty_rows(gv["rows"], wp) + groups.each do |_gk, gv| + prune_empty_rows(gv["rows"], wp) end # Prune empty groups @@ -105,13 +104,13 @@ module OpenProject::PDFExport::ExportCard end def self.is_empty_column(property_name, column, wp) - if wp.respond_to?(property_name) - value = wp.send(property_name) - elsif (field = locale_independent_custom_field(property_name, wp)) && !!field - value = field.value - else - value = "" - end + value = if wp.respond_to?(property_name) + wp.send(property_name) + elsif (field = locale_independent_custom_field(property_name, wp)) && !!field + field.value + else + "" + end value = "" if value.is_a?(Array) && value.empty? value = value.to_s if !value.is_a?(String) @@ -120,7 +119,7 @@ module OpenProject::PDFExport::ExportCard end def self.is_existing_column?(property_name, wp) - wp.respond_to?(property_name) || is_existing_custom_field?(property_name, wp) + wp.respond_to?(property_name) || is_existing_custom_field?(property_name, wp) end def self.is_existing_custom_field?(property_name, wp) @@ -130,7 +129,7 @@ module OpenProject::PDFExport::ExportCard def self.locale_independent_custom_field(property_name, wp) Setting.available_languages.each do |locale| I18n.with_locale(locale) do - if (fields = wp.custom_field_values.select {|cf| cf.custom_field.name == property_name} and fields.count > 0) + if fields = wp.custom_field_values.select { |cf| cf.custom_field.name == property_name } and fields.count > 0 return fields.first end end diff --git a/modules/pdf_export/openproject-pdf_export.gemspec b/modules/pdf_export/openproject-pdf_export.gemspec index 4b1a380fe8..c8d00fd364 100644 --- a/modules/pdf_export/openproject-pdf_export.gemspec +++ b/modules/pdf_export/openproject-pdf_export.gemspec @@ -12,6 +12,6 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib,doc}/**/*", "README.md"] - s.add_dependency "prawn", "~> 2.2" s.add_dependency "pdf-inspector", "~> 1.3.0" + s.add_dependency "prawn", "~> 2.2" end diff --git a/modules/pdf_export/spec/controllers/export_card_configurations_controller_spec.rb b/modules/pdf_export/spec/controllers/export_card_configurations_controller_spec.rb index 40f197d730..cbaa7f492a 100644 --- a/modules/pdf_export/spec/controllers/export_card_configurations_controller_spec.rb +++ b/modules/pdf_export/spec/controllers/export_card_configurations_controller_spec.rb @@ -26,11 +26,10 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - require 'spec_helper' require File.dirname(__FILE__) + '/../shared_examples' -describe ExportCardConfigurationsController, :type => :controller do +describe ExportCardConfigurationsController, type: :controller do before do allow(@controller).to receive(:require_admin) { true } @@ -47,38 +46,44 @@ describe ExportCardConfigurationsController, :type => :controller do describe 'Create' do context 'with all the values set' do it_behaves_like "should let you create a configuration" do - let(:params) { { :export_card_configuration => { name: "Config 1", - description: "This is a description", - rows: @valid_rows_yaml, - per_page: 5, - page_size: "A4", - orientation: "landscape" } } } + let(:params) do + { export_card_configuration: { name: "Config 1", + description: "This is a description", + rows: @valid_rows_yaml, + per_page: 5, + page_size: "A4", + orientation: "landscape" } } + end end end context 'with missing data' do it_behaves_like "should not let you create a configuration" do - let(:params) { { :export_card_configuration => { name: "Config 1" } } } + let(:params) { { export_card_configuration: { name: "Config 1" } } } end end context 'with invalid data' do it_behaves_like "should not let you create a configuration" do - let(:params) { { :export_card_configuration => { name: "Config 1", - rows: @invalid_rows_yaml, - per_page: 0, - page_size: "invalid", - orientation: "invalid" } } } + let(:params) do + { export_card_configuration: { name: "Config 1", + rows: @invalid_rows_yaml, + per_page: 0, + page_size: "invalid", + orientation: "invalid" } } + end end end context 'with invalid data format' do it_behaves_like "should not let you create a configuration" do - let(:params) { { :export_card_configuration => { name: "Config 1", - rows: @invalid_property_value_format, - per_page: 1, - page_size: "A4", - orientation: "landscape" } } } + let(:params) do + { export_card_configuration: { name: "Config 1", + rows: @invalid_property_value_format, + per_page: 1, + page_size: "A4", + orientation: "landscape" } } + end end end end @@ -89,7 +94,7 @@ describe ExportCardConfigurationsController, :type => :controller do @params[:export_card_configuration] = { per_page: 4 } put 'update', params: @params - expect(response).to redirect_to :action => 'index' + expect(response).to redirect_to action: 'index' expect(flash[:notice]).to eql(I18n.t(:notice_successful_update)) end @@ -103,7 +108,7 @@ describe ExportCardConfigurationsController, :type => :controller do it 'should not let you update a configuration with invalid page_size' do @params[:id] = @custom_config.id - @params[:export_card_configuration] = { page_size: "invalid"} + @params[:export_card_configuration] = { page_size: "invalid" } put 'update', params: @params expect(response).to render_template('edit') @@ -119,7 +124,7 @@ describe ExportCardConfigurationsController, :type => :controller do it 'should not let you update a configuration with invalid rows yaml' do @params[:id] = @custom_config.id - @params[:export_card_configuration] = { rows: "asdf ',#\""} + @params[:export_card_configuration] = { rows: "asdf ',#\"" } put 'update', params: @params expect(response).to render_template('edit') @@ -131,7 +136,7 @@ describe ExportCardConfigurationsController, :type => :controller do @params[:id] = @custom_config.id delete 'destroy', params: @params - expect(response).to redirect_to :action => 'index' + expect(response).to redirect_to action: 'index' expect(flash[:notice]).to eql(I18n.t(:notice_successful_delete)) end @@ -139,7 +144,7 @@ describe ExportCardConfigurationsController, :type => :controller do @params[:id] = @default_config.id delete 'destroy', params: @params - expect(response).to redirect_to :action => 'index' + expect(response).to redirect_to action: 'index' expect(flash[:notice]).to eql(I18n.t(:error_can_not_delete_export_card_configuration)) end end @@ -149,7 +154,7 @@ describe ExportCardConfigurationsController, :type => :controller do @params[:id] = @inactive_config.id post 'activate', params: @params - expect(response).to redirect_to :action => 'index' + expect(response).to redirect_to action: 'index' expect(flash[:notice]).to eql(I18n.t(:notice_export_card_configuration_activated)) end end @@ -159,7 +164,7 @@ describe ExportCardConfigurationsController, :type => :controller do @params[:id] = @active_config.id post 'deactivate', params: @params - expect(response).to redirect_to :action => 'index' + expect(response).to redirect_to action: 'index' expect(flash[:notice]).to eql(I18n.t(:notice_export_card_configuration_deactivated)) end @@ -167,7 +172,7 @@ describe ExportCardConfigurationsController, :type => :controller do @params[:id] = @default_config.id post 'deactivate', params: @params - expect(response).to redirect_to :action => 'index' + expect(response).to redirect_to action: 'index' expect(flash[:notice]).to eql(I18n.t(:error_can_not_deactivate_export_card_configuration)) end end diff --git a/modules/pdf_export/spec/export_card/document_generator_spec.rb b/modules/pdf_export/spec/export_card/document_generator_spec.rb index 3dec2e98eb..e2da46deae 100644 --- a/modules/pdf_export/spec/export_card/document_generator_spec.rb +++ b/modules/pdf_export/spec/export_card/document_generator_spec.rb @@ -29,24 +29,30 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe OpenProject::PDFExport::ExportCard::DocumentGenerator do - let(:config) { ExportCardConfiguration.new({ - name: "Default", - description: "This is a description", - per_page: 1, - page_size: "A4", - orientation: "landscape", - rows: "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n subject:\n has_label: false\n font_size: 15\n row2:\n height: 50\n priority: 1\n columns:\n non_existent:\n has_label: true\n font_size: 15\n render_if_empty: true" - })} + let(:config) do + ExportCardConfiguration.new({ + name: "Default", + description: "This is a description", + per_page: 1, + page_size: "A4", + orientation: "landscape", + rows: "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n subject:\n has_label: false\n font_size: 15\n row2:\n height: 50\n priority: 1\n columns:\n non_existent:\n has_label: true\n font_size: 15\n render_if_empty: true" + }) + end - let(:work_package1) { WorkPackage.new({ - subject: "Work package 1", - description: "This is a description" - })} + let(:work_package1) do + WorkPackage.new({ + subject: "Work package 1", + description: "This is a description" + }) + end - let(:work_package2) { WorkPackage.new({ - subject: "Work package 2", - description: "This is work package 2" - })} + let(:work_package2) do + WorkPackage.new({ + subject: "Work package 2", + description: "This is work package 2" + }) + end describe "Single work package rendering" do before(:each) do @@ -87,5 +93,4 @@ describe OpenProject::PDFExport::ExportCard::DocumentGenerator do expect(page_analysis.pages.size).to eq(2) end end - end diff --git a/modules/pdf_export/spec/factories/export_card_configuration_factory.rb b/modules/pdf_export/spec/factories/export_card_configuration_factory.rb index 905e8784dd..1e3776451c 100644 --- a/modules/pdf_export/spec/factories/export_card_configuration_factory.rb +++ b/modules/pdf_export/spec/factories/export_card_configuration_factory.rb @@ -26,28 +26,31 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - FactoryBot.define do factory :export_card_configuration do name { "Config 1" } description { "This is a description" } - rows { "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" } + rows do + "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" + end per_page { 5 } page_size { "A4" } orientation { "landscape" } end - factory :default_export_card_configuration, :class => ExportCardConfiguration do + factory :default_export_card_configuration, class: ExportCardConfiguration do name { "Default" } description { "This is a description" } active { true } - rows { "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" } + rows do + "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" + end per_page { 5 } page_size { "A4" } orientation { "landscape" } end - factory :invalid_export_card_configuration, :class => ExportCardConfiguration do + factory :invalid_export_card_configuration, class: ExportCardConfiguration do name { "Invalid" } description { "This is a description" } rows { "row1" } @@ -56,21 +59,25 @@ FactoryBot.define do orientation { "qwer" } end - factory :active_export_card_configuration, :class => ExportCardConfiguration do + factory :active_export_card_configuration, class: ExportCardConfiguration do name { "Config active" } description { "This is a description" } active { true } - rows { "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" } + rows do + "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" + end per_page { 5 } page_size { "A4" } orientation { "landscape" } end - factory :inactive_export_card_configuration, :class => ExportCardConfiguration do + factory :inactive_export_card_configuration, class: ExportCardConfiguration do name { "Config inactive" } description { "This is a description" } active { false } - rows { "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" } + rows do + "group1:\n has_border: false\n rows:\n row1:\n height: 50\n priority: 1\n columns:\n id:\n has_label: false" + end per_page { 5 } page_size { "A4" } orientation { "landscape" } diff --git a/modules/pdf_export/spec/shared_examples.rb b/modules/pdf_export/spec/shared_examples.rb index dee9d211c6..0816a44489 100644 --- a/modules/pdf_export/spec/shared_examples.rb +++ b/modules/pdf_export/spec/shared_examples.rb @@ -1,19 +1,17 @@ shared_examples_for "should let you create a configuration" do - before do post 'create', params: params end - it { expect(response).to redirect_to :action => 'index' } + it { expect(response).to redirect_to action: 'index' } it { expect(flash[:notice]).to eq(I18n.t(:notice_successful_create)) } end shared_examples_for "should not let you create a configuration" do - before do post 'create', params: params end it { expect(response).to render_template('new') } - it {expect(assigns(:config).errors.messages).to_not be_empty} + it { expect(assigns(:config).errors.messages).to_not be_empty } end diff --git a/modules/pdf_export/spec/views/edit.html.erb_spec.rb b/modules/pdf_export/spec/views/edit.html.erb_spec.rb index 314a2bfabd..86a7439574 100644 --- a/modules/pdf_export/spec/views/edit.html.erb_spec.rb +++ b/modules/pdf_export/spec/views/edit.html.erb_spec.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - require 'spec_helper' -describe 'export_card_configurations/edit', :type => :view do +describe 'export_card_configurations/edit', type: :view do let(:config) { FactoryBot.build(:export_card_configuration) } before do diff --git a/modules/pdf_export/spec/views/index.html.erb_spec.rb b/modules/pdf_export/spec/views/index.html.erb_spec.rb index 2a698fc084..4eabf78aab 100644 --- a/modules/pdf_export/spec/views/index.html.erb_spec.rb +++ b/modules/pdf_export/spec/views/index.html.erb_spec.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - require 'spec_helper' -describe 'export_card_configurations/index', :type => :view do +describe 'export_card_configurations/index', type: :view do let(:config1) { FactoryBot.build(:export_card_configuration, name: "Config 1") } let(:config2) { FactoryBot.build(:export_card_configuration, name: "Config 2") } @@ -45,5 +44,4 @@ describe 'export_card_configurations/index', :type => :view do expect(rendered).to have_selector("a", text: config1.name) expect(rendered).to have_selector("a", text: config2.name) end - end diff --git a/modules/pdf_export/spec/views/new.html.erb_spec.rb b/modules/pdf_export/spec/views/new.html.erb_spec.rb index 78c02cdcb3..1c0ce72296 100644 --- a/modules/pdf_export/spec/views/new.html.erb_spec.rb +++ b/modules/pdf_export/spec/views/new.html.erb_spec.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - require 'spec_helper' -describe 'export_card_configurations/new', :type => :view do +describe 'export_card_configurations/new', type: :view do let(:config) { FactoryBot.build(:export_card_configuration) } before do @@ -45,5 +44,4 @@ describe 'export_card_configurations/new', :type => :view do expect(rendered).to have_css("select#export_card_configuration_orientation") expect(rendered).to have_css("textarea#export_card_configuration_rows") end - end diff --git a/modules/recaptcha/config/routes.rb b/modules/recaptcha/config/routes.rb index eb86a6435f..d4f7ddeb07 100644 --- a/modules/recaptcha/config/routes.rb +++ b/modules/recaptcha/config/routes.rb @@ -1,5 +1,4 @@ OpenProject::Application::routes.draw do - namespace 'recaptcha' do get :settings, to: 'admin#show' post :settings, to: 'admin#update' diff --git a/modules/recaptcha/lib/open_project/recaptcha/engine.rb b/modules/recaptcha/lib/open_project/recaptcha/engine.rb index 72d5b134c0..639c10caf2 100644 --- a/modules/recaptcha/lib/open_project/recaptcha/engine.rb +++ b/modules/recaptcha/lib/open_project/recaptcha/engine.rb @@ -23,7 +23,7 @@ module OpenProject::Recaptcha end config.after_initialize do - SecureHeaders::Configuration.named_append(:recaptcha) do |request| + SecureHeaders::Configuration.named_append(:recaptcha) do |_request| { frame_src: %w(https://www.google.com/recaptcha/) } end diff --git a/modules/reporting/app/controllers/cost_reports_controller.rb b/modules/reporting/app/controllers/cost_reports_controller.rb index 539b601dc8..2884f4d0ea 100644 --- a/modules/reporting/app/controllers/cost_reports_controller.rb +++ b/modules/reporting/app/controllers/cost_reports_controller.rb @@ -49,7 +49,8 @@ class CostReportsController < ApplicationController helper_method :cost_type helper_method :unit_id - attr_accessor :report_engine + attr_accessor :report_engine, :cost_types, :unit_id, :cost_type + helper_method :current_user helper_method :allowed_to? @@ -58,12 +59,10 @@ class CostReportsController < ApplicationController helper { def engine; @report_engine; end } before_action :determine_engine - before_action :prepare_query, only: [:index, :create] - before_action :find_optional_report, only: [:index, :show, :update, :destroy, :rename] + before_action :prepare_query, only: %i[index create] + before_action :find_optional_report, only: %i[index show update destroy rename] before_action :possibly_only_narrow_values - attr_accessor :cost_types, :unit_id, :cost_type - before_action :set_cost_types # has to be set AFTER the Report::Controller filters run layout 'angular' @@ -78,11 +77,13 @@ class CostReportsController < ApplicationController def index table - respond_to do |format| - format.html { - session[report_engine.name.underscore.to_sym].try(:delete, :name) - } - end unless performed? + unless performed? + respond_to do |format| + format.html do + session[report_engine.name.underscore.to_sym].try(:delete, :name) + end + end + end end ## @@ -170,10 +171,10 @@ class CostReportsController < ApplicationController @query.public! if make_query_public? @query.save! store_query(@query) - unless request.xhr? - redirect_to action: 'show', id: @query.id - else + if request.xhr? render plain: @query.name + else + redirect_to action: 'show', id: @query.id end end @@ -249,7 +250,6 @@ class CostReportsController < ApplicationController ## # Clear the query if the project context changed def update_project_context!(filters) - # Only in project context return unless @project @@ -284,11 +284,11 @@ class CostReportsController < ApplicationController # Set a default query to cut down initial load time def default_group_parameters { columns: [:week], rows: [] }.tap do |h| - if @project - h[:rows] << :work_package_id - else - h[:rows] << :project_id - end + h[:rows] << if @project + :work_package_id + else + :project_id + end end end @@ -309,7 +309,7 @@ class CostReportsController < ApplicationController cost_type_filter = @query.filters.detect { |f| f.is_a?(CostQuery::Filter::CostTypeId) } cost_type_filter.values.first.to_i if cost_type_filter - end + end @unit_id = -1 unless @cost_types.include? @unit_id end @@ -359,11 +359,11 @@ class CostReportsController < ApplicationController # If report does not belong to a project, it is ok to look for the # permission in any project. Otherwise, the user should have the permission # in this project. - if report.project.present? - options = {} - else - options = { global: true } - end + options = if report.project.present? + {} + else + { global: true } + end case action when :create @@ -433,7 +433,8 @@ class CostReportsController < ApplicationController ## # Determines if the request contains filters to set - def set_filter? # FIXME: rename to set_query? + # FIXME: rename to set_query? + def set_filter? params[:set_filter].to_i == 1 end diff --git a/modules/reporting/app/controllers/work_package_costlog_controller.rb b/modules/reporting/app/controllers/work_package_costlog_controller.rb index 3edbd2ed35..27eabce58b 100644 --- a/modules/reporting/app/controllers/work_package_costlog_controller.rb +++ b/modules/reporting/app/controllers/work_package_costlog_controller.rb @@ -48,13 +48,13 @@ class WorkPackageCostlogController < ApplicationController filters[:values][:project_id] = [@project.id.to_s] respond_to do |format| - format.html { + format.html do session[CostQuery.name.underscore.to_sym] = { filters: filters, groups: { rows: [], columns: [] } } redirect_to_cost_reports - } - format.all { + end + format.all do redirect_to_cost_reports - } + end end end diff --git a/modules/reporting/app/helpers/reporting_helper.rb b/modules/reporting/app/helpers/reporting_helper.rb index 6c13139757..7544d68149 100644 --- a/modules/reporting/app/helpers/reporting_helper.rb +++ b/modules/reporting/app/helpers/reporting_helper.rb @@ -35,7 +35,8 @@ module ReportingHelper def with_project(project) project = Project.find(project) unless project.is_a? Project - project_was, @project = @project, project + project_was = @project + @project = project yield @project = project_was end @@ -52,6 +53,7 @@ module ReportingHelper if name.starts_with?('label') return I18n.t(field) end + name = name.camelcase if CostQuery::Filter.const_defined? name CostQuery::Filter.const_get(name).label @@ -239,6 +241,7 @@ module ReportingHelper def filter_class(filter_name) klass = CostQuery::Filter.const_get(filter_name.to_s.camelize) return klass if klass.is_a? Class + nil rescue NameError nil diff --git a/modules/reporting/app/models/cost_query.rb b/modules/reporting/app/models/cost_query.rb index 85a02154e5..4c4d8ace0d 100644 --- a/modules/reporting/app/models/cost_query.rb +++ b/modules/reporting/app/models/cost_query.rb @@ -92,11 +92,11 @@ class CostQuery < ApplicationRecord end def deserialize - unless @chain + if @chain + raise ArgumentError, 'Cannot deserialize a report which already has a chain' + else hash = serialized || serialize self.class.deserialize(hash, self) - else - raise ArgumentError, 'Cannot deserialize a report which already has a chain' end end @@ -121,7 +121,7 @@ class CostQuery < ApplicationRecord # This may be used to alter report properties without # creating a new report in a database. def migrate(report) - [:@chain, :@query, :@transformer, :@walker, :@table, :@depths, :@chain_initializer].each do |inst_var| + %i[@chain @query @transformer @walker @table @depths @chain_initializer].each do |inst_var| instance_variable_set inst_var, (report.instance_variable_get inst_var) end end @@ -140,7 +140,10 @@ class CostQuery < ApplicationRecord def add_chain(type, name, options) chain type.const_get(name.to_s.camelcase), options - @transformer, @table, @depths, @walker = nil, nil, nil, nil + @transformer = nil + @table = nil + @depths = nil + @walker = nil self end @@ -252,9 +255,9 @@ class CostQuery < ApplicationRecord CostQuery.where(['user_id = ?', user.id]).update_all ['user_id = ?', DeletedUser.first.id] max_query_id = 0 - while((current_queries = CostQuery.limit(1000) + while (current_queries = CostQuery.limit(1000) .where(["id > ?", max_query_id]) - .order("id ASC")).size > 0) do + .order("id ASC")).size > 0 current_queries.each do |query| serialized = query.serialized @@ -262,9 +265,9 @@ class CostQuery < ApplicationRecord serialized[:filters] = serialized[:filters].map do |name, options| options[:values].delete(user.id.to_s) if ["UserId", "AuthorId", "AssignedToId"].include?(name) - options[:values].nil? || options[:values].size > 0 ? - [name, options] : - nil + if options[:values].nil? || options[:values].size > 0 + [name, options] + end end.compact CostQuery.where(["id = ?", query.id]).update_all ["serialized = ?", YAML::dump(serialized)] diff --git a/modules/reporting/app/models/cost_query/cache.rb b/modules/reporting/app/models/cost_query/cache.rb index 4fdbe28b80..16ff9e4146 100644 --- a/modules/reporting/app/models/cost_query/cache.rb +++ b/modules/reporting/app/models/cost_query/cache.rb @@ -28,7 +28,6 @@ module CostQuery::Cache class << self - def check reset! if reset_required? end diff --git a/modules/reporting/app/models/cost_query/custom_field_mixin.rb b/modules/reporting/app/models/cost_query/custom_field_mixin.rb index 8dad0ae5f7..05df3de0bb 100644 --- a/modules/reporting/app/models/cost_query/custom_field_mixin.rb +++ b/modules/reporting/app/models/cost_query/custom_field_mixin.rb @@ -30,6 +30,7 @@ module CostQuery::CustomFieldMixin include Report::QueryUtils attr_reader :custom_field + SQL_TYPES = { 'string' => 'varchar', 'list' => 'varchar', diff --git a/modules/reporting/app/models/cost_query/filter/cost_type_id.rb b/modules/reporting/app/models/cost_query/filter/cost_type_id.rb index 345784ff69..218bd653bc 100644 --- a/modules/reporting/app/models/cost_query/filter/cost_type_id.rb +++ b/modules/reporting/app/models/cost_query/filter/cost_type_id.rb @@ -44,6 +44,7 @@ class CostQuery::Filter::CostTypeId < Report::Filter::Base # Displayability is decided on the instance def display? return super if @display.nil? + @display end diff --git a/modules/reporting/app/models/cost_query/filter/user_id.rb b/modules/reporting/app/models/cost_query/filter/user_id.rb index 2049e1529b..ddf70512a0 100644 --- a/modules/reporting/app/models/cost_query/filter/user_id.rb +++ b/modules/reporting/app/models/cost_query/filter/user_id.rb @@ -47,8 +47,6 @@ class CostQuery::Filter::UserId < Report::Filter::Base if User.current.logged? User.current.id - else - nil end end diff --git a/modules/reporting/app/models/cost_query/group_by/cost_type_id.rb b/modules/reporting/app/models/cost_query/group_by/cost_type_id.rb index 86da607521..48cad33e03 100644 --- a/modules/reporting/app/models/cost_query/group_by/cost_type_id.rb +++ b/modules/reporting/app/models/cost_query/group_by/cost_type_id.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::CostTypeId < Report::GroupBy::Base - def self.label CostType.model_name.human end diff --git a/modules/reporting/app/models/cost_query/group_by/project_id.rb b/modules/reporting/app/models/cost_query/group_by/project_id.rb index 2f0d278e44..70750bd6f9 100644 --- a/modules/reporting/app/models/cost_query/group_by/project_id.rb +++ b/modules/reporting/app/models/cost_query/group_by/project_id.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::ProjectId < Report::GroupBy::Base - def self.label Project.model_name.human end diff --git a/modules/reporting/app/models/cost_query/group_by/tmonth.rb b/modules/reporting/app/models/cost_query/group_by/tmonth.rb index 41fc1c823a..ac2fbf9fc4 100644 --- a/modules/reporting/app/models/cost_query/group_by/tmonth.rb +++ b/modules/reporting/app/models/cost_query/group_by/tmonth.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::Tmonth < Report::GroupBy::Base - def self.label I18n.t(:label_month_reporting) end diff --git a/modules/reporting/app/models/cost_query/group_by/tweek.rb b/modules/reporting/app/models/cost_query/group_by/tweek.rb index dd9fbf21eb..a8c436915b 100644 --- a/modules/reporting/app/models/cost_query/group_by/tweek.rb +++ b/modules/reporting/app/models/cost_query/group_by/tweek.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::Tweek < Report::GroupBy::Base - def self.label I18n.t(:label_week_reporting) end diff --git a/modules/reporting/app/models/cost_query/group_by/tyear.rb b/modules/reporting/app/models/cost_query/group_by/tyear.rb index 2310e927b0..b7c373790d 100644 --- a/modules/reporting/app/models/cost_query/group_by/tyear.rb +++ b/modules/reporting/app/models/cost_query/group_by/tyear.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::Tyear < Report::GroupBy::Base - def self.label I18n.t(:label_year_reporting) end diff --git a/modules/reporting/app/models/cost_query/group_by/user_id.rb b/modules/reporting/app/models/cost_query/group_by/user_id.rb index 9605473c3f..19dc2f6a6a 100644 --- a/modules/reporting/app/models/cost_query/group_by/user_id.rb +++ b/modules/reporting/app/models/cost_query/group_by/user_id.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::UserId < Report::GroupBy::Base - def self.label WorkPackage.human_attribute_name(:user) end diff --git a/modules/reporting/app/models/cost_query/group_by/work_package_id.rb b/modules/reporting/app/models/cost_query/group_by/work_package_id.rb index c4519cdd1c..7638c7b591 100644 --- a/modules/reporting/app/models/cost_query/group_by/work_package_id.rb +++ b/modules/reporting/app/models/cost_query/group_by/work_package_id.rb @@ -27,7 +27,6 @@ #++ class CostQuery::GroupBy::WorkPackageId < Report::GroupBy::Base - def self.label WorkPackage.model_name.human end diff --git a/modules/reporting/app/models/cost_query/operator.rb b/modules/reporting/app/models/cost_query/operator.rb index b9af049877..afca19f7ad 100644 --- a/modules/reporting/app/models/cost_query/operator.rb +++ b/modules/reporting/app/models/cost_query/operator.rb @@ -29,26 +29,28 @@ class CostQuery::Operator < Report::Operator # Operators from Redmine new "c", arity: 0, label: :label_closed do - def modify(query, field, *values) + def modify(query, field, *_values) raise "wrong field" if field.to_s.split('.').last != "status_id" + query.where "(#{Status.table_name}.is_closed = #{quoted_true})" query end end new "o", arity: 0, label: :label_open do - def modify(query, field, *values) + def modify(query, field, *_values) raise "wrong field" if field.to_s.split('.').last != "status_id" + query.where "(#{Status.table_name}.is_closed = #{quoted_false})" query end end - new "=_child_projects", validate: :integers, label: :label_is_project_with_subprojects do + new "=_child_projects", validate: :integers, label: :label_is_project_with_subprojects do def modify(query, field, *values) p_ids = [] values.each do |value| - p_ids += ([value] << Project.find(value).descendants.map{ |p| p.id }) + p_ids += ([value] << Project.find(value).descendants.map { |p| p.id }) end "=".to_operator.modify query, field, p_ids rescue ActiveRecord::RecordNotFound @@ -56,11 +58,11 @@ class CostQuery::Operator < Report::Operator end end - new "!_child_projects", validate: :integers, label: :label_is_not_project_with_subprojects do + new "!_child_projects", validate: :integers, label: :label_is_not_project_with_subprojects do def modify(query, field, *values) p_ids = [] values.each do |value| - p_ids += ([value] << Project.find(value).descendants.map{ |p| p.id }) + p_ids += ([value] << Project.find(value).descendants.map { |p| p.id }) end "!".to_operator.modify query, field, p_ids rescue ActiveRecord::RecordNotFound diff --git a/modules/reporting/app/models/cost_query/sql_statement.rb b/modules/reporting/app/models/cost_query/sql_statement.rb index 7c5f6084f9..1a33a2e82c 100644 --- a/modules/reporting/app/models/cost_query/sql_statement.rb +++ b/modules/reporting/app/models/cost_query/sql_statement.rb @@ -44,7 +44,7 @@ class CostQuery::SqlStatement < Report::SqlStatement # this is a hack to ensure that additional joins added by filters do not result # in additional columns being selected. def to_s - select(['entries.*']) if select == ['*'] && group_by.empty? && self.entry_union + select(['entries.*']) if select == ['*'] && group_by.empty? && entry_union super end @@ -86,11 +86,12 @@ class CostQuery::SqlStatement < Report::SqlStatement query.select COMMON_FIELDS query.desc = "Subquery for #{table}" query.select({ - count: 1, id: [model, :id], display_costs: 1, - real_costs: switch("#{table}.overridden_costs IS NULL" => [model, :costs], else: [model, :overridden_costs]), - week: iso_year_week(:spent_on, model), - singleton_value: 1 }) - #FIXME: build this subquery from a sql_statement + count: 1, id: [model, :id], display_costs: 1, + real_costs: switch("#{table}.overridden_costs IS NULL" => [model, :costs], else: [model, :overridden_costs]), + week: iso_year_week(:spent_on, model), + singleton_value: 1 + }) + # FIXME: build this subquery from a sql_statement query.from "(SELECT *, #{typed :text, model.model_name.to_s} AS type FROM #{table}) AS #{table}" send("unify_#{table}", query) end diff --git a/modules/reporting/app/models/entry.rb b/modules/reporting/app/models/entry.rb index 66fd5e8bae..816b9199c2 100644 --- a/modules/reporting/app/models/entry.rb +++ b/modules/reporting/app/models/entry.rb @@ -43,7 +43,8 @@ module Entry end def calculate(type, *args) - a, b = TimeEntry.calculate(type, *args), CostEntry.calculate(type, *args) + a = TimeEntry.calculate(type, *args) + b = CostEntry.calculate(type, *args) case type when :sum, :count then a + b when :avg then (a + b) / 2 @@ -54,13 +55,14 @@ module Entry end undef_method :create, :update, :delete, :destroy, :new, :update_counters, - :increment_counter, :decrement_counter + :increment_counter, :decrement_counter %w[update_all destroy_all delete_all].each do |meth| define_method(meth) { |*args| send_all(meth, *args) } end private + def all(*args) ActiveSupport::Deprecation.warn('Passing arguments is deprecated') if args.any? find_many :all # *args @@ -72,9 +74,12 @@ module Entry end def find_initial(options) find_one :find_initial, options end + def find_last(options) find_one :find_last, options end + def find_every(options) find_many :find_every, options end - def find_from_ids(args, options) find_many :find_from_ids, options end + + def find_from_ids(_args, options) find_many :find_from_ids, options end def find_one(*args) TimeEntry.send(*args) || CostEntry.send(*args) diff --git a/modules/reporting/config/routes.rb b/modules/reporting/config/routes.rb index e1437093cd..a7752ebdb9 100644 --- a/modules/reporting/config/routes.rb +++ b/modules/reporting/config/routes.rb @@ -30,7 +30,7 @@ OpenProject::Application.routes.draw do scope 'projects/:project_id' do resources :cost_reports, except: :create do collection do - match :index, via: [:get, :post] + match :index, via: %i[get post] end member do @@ -42,10 +42,10 @@ OpenProject::Application.routes.draw do resources :cost_reports, except: :create do collection do - match :index, via: [:get, :post] + match :index, via: %i[get post] post :save_as, action: :create get :drill_down - match :available_values, via: [:get, :post] + match :available_values, via: %i[get post] get :display_report_list end diff --git a/modules/reporting/db/migrate/20180323130704_to_v710_aggregated_reporting_migrations.rb b/modules/reporting/db/migrate/20180323130704_to_v710_aggregated_reporting_migrations.rb index f97e3a8433..fe692f756b 100644 --- a/modules/reporting/db/migrate/20180323130704_to_v710_aggregated_reporting_migrations.rb +++ b/modules/reporting/db/migrate/20180323130704_to_v710_aggregated_reporting_migrations.rb @@ -38,13 +38,13 @@ class ToV710AggregatedReportingMigrations < ActiveRecord::Migration[5.1] def up Migration::MigrationSquasher.squash(migrations) do create_table "cost_queries", id: :integer do |t| - t.integer "user_id", :null => false + t.integer "user_id", null: false t.integer "project_id" - t.string "name", :null => false - t.boolean "is_public", :default => false, :null => false - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false - t.string "serialized", :limit => 2000, :null => false + t.string "name", null: false + t.boolean "is_public", default: false, null: false + t.datetime "created_on", null: false + t.datetime "updated_on", null: false + t.string "serialized", limit: 2000, null: false end end end diff --git a/modules/reporting/lib/open_project/reporting/default_data.rb b/modules/reporting/lib/open_project/reporting/default_data.rb index be7cbe4f6f..eb88df8dfa 100644 --- a/modules/reporting/lib/open_project/reporting/default_data.rb +++ b/modules/reporting/lib/open_project/reporting/default_data.rb @@ -22,9 +22,9 @@ module OpenProject end def restricted_project_admin_permissions - [ - :save_cost_reports, - :save_private_cost_reports + %i[ + save_cost_reports + save_private_cost_reports ] end end diff --git a/modules/reporting/lib/open_project/reporting/engine.rb b/modules/reporting/lib/open_project/reporting/engine.rb index 82144b5a9f..df13df24d4 100644 --- a/modules/reporting/lib/open_project/reporting/engine.rb +++ b/modules/reporting/lib/open_project/reporting/engine.rb @@ -37,17 +37,16 @@ module OpenProject::Reporting register 'openproject-reporting', author_url: 'https://www.openproject.com', bundled: true do + view_actions = %i[index show drill_down available_values display_report_list] + edit_actions = %i[create update rename destroy] - view_actions = [:index, :show, :drill_down, :available_values, :display_report_list] - edit_actions = [:create, :update, :rename, :destroy] - - #register reporting_module including permissions + # register reporting_module including permissions project_module :costs do permission :save_cost_reports, { cost_reports: edit_actions } permission :save_private_cost_reports, { cost_reports: edit_actions } end - #register additional permissions for viewing time and cost entries through the CostReportsController + # register additional permissions for viewing time and cost entries through the CostReportsController view_actions.each do |action| OpenProject::AccessControl.permission(:view_time_entries).actions << "cost_reports/#{action}" OpenProject::AccessControl.permission(:view_own_time_entries).actions << "cost_reports/#{action}" @@ -55,7 +54,7 @@ module OpenProject::Reporting OpenProject::AccessControl.permission(:view_own_cost_entries).actions << "cost_reports/#{action}" end - #menu extensions + # menu extensions menu :top_menu, :cost_reports_global, { controller: '/cost_reports', action: 'index', project_id: nil }, @@ -67,7 +66,7 @@ module OpenProject::Reporting User.current.allowed_to?(:view_own_time_entries, nil, global: true) || User.current.allowed_to?(:view_cost_entries, nil, global: true) || User.current.allowed_to?(:view_own_cost_entries, nil, global: true) - ) + ) } menu :project_menu, diff --git a/modules/reporting/lib/open_project/reporting/patches/custom_fields_controller_patch.rb b/modules/reporting/lib/open_project/reporting/patches/custom_fields_controller_patch.rb index 616e704d6f..4b9319d4ca 100644 --- a/modules/reporting/lib/open_project/reporting/patches/custom_fields_controller_patch.rb +++ b/modules/reporting/lib/open_project/reporting/patches/custom_fields_controller_patch.rb @@ -42,7 +42,7 @@ module OpenProject::Reporting::Patches remove_custom_field_from_cost_report(reports, id) remove_custom_field_from_session(id) - rescue => e + rescue StandardError => e Rails.logger.error "Failed to remove custom_field #{id} from custom queries. " \ "#{e.class}: #{e.message}" ensure diff --git a/modules/reporting/lib/open_project/reporting/patches/open_project/configuration_patch.rb b/modules/reporting/lib/open_project/reporting/patches/open_project/configuration_patch.rb index 4e7d91a1d0..9a73f14097 100644 --- a/modules/reporting/lib/open_project/reporting/patches/open_project/configuration_patch.rb +++ b/modules/reporting/lib/open_project/reporting/patches/open_project/configuration_patch.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - require_dependency 'open_project/configuration' module OpenProject::Reporting::Patches diff --git a/modules/reporting/lib/open_project/reporting/patches/to_date_patch.rb b/modules/reporting/lib/open_project/reporting/patches/to_date_patch.rb index 2d29662d73..3cd8ec0efe 100644 --- a/modules/reporting/lib/open_project/reporting/patches/to_date_patch.rb +++ b/modules/reporting/lib/open_project/reporting/patches/to_date_patch.rb @@ -35,6 +35,7 @@ module OpenProject::Reporting::Patches::ToDatePatch def to_dateish return Date.today if blank? + Date.parse self end end @@ -50,6 +51,7 @@ module OpenProject::Reporting::Patches::ToDatePatch def force_utc return to_time.force_utc unless respond_to? :utc_offset return self if utc? + utc - utc_offset end end diff --git a/modules/reporting/lib/report/chainable.rb b/modules/reporting/lib/report/chainable.rb index 6518919d88..ebb628584f 100644 --- a/modules/reporting/lib/report/chainable.rb +++ b/modules/reporting/lib/report/chainable.rb @@ -58,6 +58,7 @@ module Report def self.base return self if base? + superclass.base end @@ -81,6 +82,7 @@ module Report def self.table_from(value) return value.table_name if value.respond_to? :table_name return value unless value.respond_to? :to_ary or value.respond_to? :to_hash + table_from value.to_a.first end @@ -124,6 +126,7 @@ module Report end attr_accessor :parent, :child, :type + accepts_property :type def each(&block) @@ -149,6 +152,7 @@ module Report def top return self if top? + parent.top end @@ -162,6 +166,7 @@ module Report def bottom return self if bottom? + child.bottom end @@ -170,10 +175,14 @@ module Report options.each do |key, value| unless self.class.extra_options.include? key raise ArgumentError, "may not set #{key}" unless engine.accepted_properties.include? key.to_s + send "#{key}=", value end end - self.child, child.parent = child, self if child + if child + self.child = child + child.parent = self + end move_down until correct_position? clear end @@ -249,6 +258,7 @@ module Report def sql_statement raise "should not get here (#{inspect})" if bottom? + child.cached(:sql_statement).tap do |q| chain_collect(:table_joins).each { |args| q.join(*args) } if responsible_for_sql? end @@ -301,6 +311,7 @@ module Report class << self def new(chain = nil, options = {}) return chain if chain and chain.map(&:class).include? self + super end end diff --git a/modules/reporting/lib/report/filter/base.rb b/modules/reporting/lib/report/filter/base.rb index c40cddc263..61cdeef4c2 100644 --- a/modules/reporting/lib/report/filter/base.rb +++ b/modules/reporting/lib/report/filter/base.rb @@ -105,7 +105,7 @@ class Report::Filter def self.inherited(klass) if base? - self.dont_display! + dont_display! klass.display! end super @@ -187,7 +187,7 @@ class Report::Filter arity = operator.arity query_values = [*transformed_values].compact # if there is just the nil it might be actually intendet to be there - query_values.unshift nil if Array(self.values).size == 1 && Array(self.values).first.nil? + query_values.unshift nil if Array(values).size == 1 && Array(values).first.nil? query_values = query_values[0, arity] if query_values and arity >= 0 and arity != query_values.size operator.modify(query, field, *query_values) unless field.empty? end diff --git a/modules/reporting/lib/report/group_by/base.rb b/modules/reporting/lib/report/group_by/base.rb index 821089c806..2f07b76d63 100644 --- a/modules/reporting/lib/report/group_by/base.rb +++ b/modules/reporting/lib/report/group_by/base.rb @@ -69,7 +69,7 @@ class Report::GroupBy def select_fields # + (parent ? parent.select_fields : []) - self.class.select_fields ? self.class.select_fields : group_fields + self.class.select_fields || group_fields end ## diff --git a/modules/reporting/lib/report/inherited_attribute.rb b/modules/reporting/lib/report/inherited_attribute.rb index 7d4da310a2..dc0d765ff7 100644 --- a/modules/reporting/lib/report/inherited_attribute.rb +++ b/modules/reporting/lib/report/inherited_attribute.rb @@ -43,17 +43,19 @@ module Report::InheritedAttribute define_singleton_method(name) do |*values| # FIXME: I'm ugly return get_inherited_attribute(name, default, list, uniq) if values.empty? + if list old = instance_variable_get("@#{name}") if merge old ||= [] return set_inherited_attribute(name, values.map(&map) + old) end raise ArgumentError, "wrong number of arguments (#{values.size} for 1)" if values.size > 1 + set_inherited_attribute name, map.call(values.first) end define_method(name) { |*values| self.class.send(name, *values) } end - end + end def define_singleton_method(name, &block) singleton_class.send :attr_writer, name @@ -63,6 +65,7 @@ module Report::InheritedAttribute def get_inherited_attribute(name, default = nil, list = false, uniq = false) return get_inherited_attribute(name, default, list, false).uniq if list and uniq + result = instance_variable_get("@#{name}") super_result = superclass.get_inherited_attribute(name, default, list) if inherit? name if result.nil? diff --git a/modules/reporting/lib/report/operator.rb b/modules/reporting/lib/report/operator.rb index cdffa955ec..c09fda8144 100644 --- a/modules/reporting/lib/report/operator.rb +++ b/modules/reporting/lib/report/operator.rb @@ -36,7 +36,7 @@ class Report::Operator def self.define_operators # :nodoc: # Defaults defaults do - def_delegators :'singleton_class', :forced?, :force!, :forced + def_delegators :singleton_class, :forced?, :force!, :forced def sql_operator name @@ -115,10 +115,9 @@ class Report::Operator new '=', label: :label_equals do def modify(query, field, *values) - case - when values.size == 1 && values.first.nil? + if values.size == 1 && values.first.nil? query.where "#{field} IS NULL" - when values.compact.empty? + elsif values.compact.empty? query.where '1=0' else query.where "#{field} IN #{collection(*values)}" @@ -187,6 +186,7 @@ class Report::Operator new 'd', label: :label_greater_or_equal, validate: :dates do def modify(query, field, value) return query if value.to_s.empty? + '>='.to_operator.modify query, field, quoted_date(value) end end @@ -201,6 +202,7 @@ class Report::Operator new '<>d', label: :label_between, validate: :dates do def modify(query, field, from, to) return query if from.to_s.empty? || to.to_s.empty? + query.where "#{field} BETWEEN '#{quoted_date from}' AND '#{quoted_date to}'" query end @@ -209,6 +211,7 @@ class Report::Operator new '=d', label: :label_date_on, validate: :dates do def modify(query, field, value) return query if value.to_s.empty? + '='.to_operator.modify query, field, quoted_date(value) end end @@ -276,6 +279,7 @@ class Report::Operator def self.load return if @done + @done = true define_operators end @@ -358,6 +362,7 @@ class Report::Operator all = self.class.all alt = alt_name.to_s raise ArgumentError, "Can't alias operator with an existing one's name ( #{alt} )." if all.has_key?(alt) + op = all[name].clone op.send(:rename_to, alt_name) op.singleton_class.send(:define_method, 'label') { alt_label } diff --git a/modules/reporting/lib/report/query_utils.rb b/modules/reporting/lib/report/query_utils.rb index 0d91f6588d..db5ee78da0 100644 --- a/modules/reporting/lib/report/query_utils.rb +++ b/modules/reporting/lib/report/query_utils.rb @@ -42,6 +42,7 @@ module Report::QueryUtils # @return [Object] Quoted version def quote_string(str) return str unless str.respond_to? :to_str + engine.reporting_connection.quote_string(str) end @@ -111,6 +112,7 @@ module Report::QueryUtils # @return [String] The table name. def table_name_for(object) return object.table_name if object.respond_to? :table_name + object.to_s.tableize end @@ -133,6 +135,7 @@ module Report::QueryUtils return arg if arg.is_a? String and arg =~ /\.| |\(.*\)/ return table_name_for(arg.first || default_table) + '.' << arg.last.to_s if arg.is_a? Array and arg.size == 2 return arg.to_s unless default_table + field_name_for [default_table, arg] end @@ -155,14 +158,14 @@ module Report::QueryUtils # @param [Hash] options Condition => Result. # @return [String] Case statement. def switch(options) - desc = "#{__method__} #{options.inspect[1..-2]}".gsub(/(Cost|Time)Entry\([^\)]*\)/, '\1Entry') + desc = "#{__method__} #{options.inspect[1..-2]}".gsub(/(Cost|Time)Entry\([^)]*\)/, '\1Entry') options = options.with_indifferent_access else_part = options.delete :else "-- #{desc}\n\t" \ - "CASE #{options.map { |k, v| + "CASE #{options.map do |k, v| "\n\t\tWHEN #{field_name_for k}\n\t\t" \ "THEN #{field_name_for v}" - }.join(', ')}\n\t\tELSE #{field_name_for else_part}\n\tEND" + end.join(', ')}\n\t\tELSE #{field_name_for else_part}\n\tEND" end ## diff --git a/modules/reporting/lib/report/result.rb b/modules/reporting/lib/report/result.rb index 4eb8104cfa..3c1efc755a 100644 --- a/modules/reporting/lib/report/result.rb +++ b/modules/reporting/lib/report/result.rb @@ -30,8 +30,7 @@ class Report::Result include Report::QueryUtils class Base - attr_accessor :parent, :type, :important_fields - attr_accessor :key + attr_accessor :parent, :type, :important_fields, :key attr_reader :value alias values value include Enumerable @@ -117,8 +116,7 @@ class Report::Result type == :direct end - def each_row - end + def each_row; end def final?(type) type? type and (direct? or size == 0 or first.type != type) @@ -137,6 +135,7 @@ class Report::Result def final_number(type) return 1 if final? type return 0 if direct? + @final_number ||= {} @final_number[type] ||= sum { |v| v.final_number type } end @@ -181,11 +180,13 @@ class Report::Result def each return enum_for(__method__) unless block_given? + yield self end def each_direct_result(_cached = false) return enum_for(__method__) unless block_given? + yield self end @@ -204,6 +205,7 @@ class Report::Result def sort!(force = false) return false if @sorted and not force + values.sort! { |a, b| compare a.key, b.key } values.each { |e| e.sort! force } @sorted = true @@ -252,6 +254,7 @@ class Report::Result def each_row return enum_for(:each_row) unless block_given? + if final_row? then yield self else each { |c| c.each_row(&Proc.new) } end @@ -266,10 +269,11 @@ class Report::Result values.each(&block) end - def each_direct_result(cached = true) + def each_direct_result(cached = true, &block) return enum_for(__method__) unless block_given? + if @direct_results - @direct_results.each { |r| yield(r) } + @direct_results.each(&block) else values.each do |value| value.each_direct_result(false) do |result| diff --git a/modules/reporting/lib/report/sql_statement.rb b/modules/reporting/lib/report/sql_statement.rb index eadb0a84e3..2b7732b6d8 100644 --- a/modules/reporting/lib/report/sql_statement.rb +++ b/modules/reporting/lib/report/sql_statement.rb @@ -29,8 +29,11 @@ class Report::SqlStatement class Union attr_accessor :first, :second, :as + def initialize(first, second, as = nil) - @first, @second, @as = first, second, as + @first = first + @second = second + @as = as end def to_s @@ -80,6 +83,7 @@ class Report::SqlStatement def sum(field, name = :sum, type = :sum) @sql = nil return sum({ name => field }, nil, type) unless field.respond_to? :to_hash + field.each { |k, v| field[k] = "#{type}(#{v})" } select field end @@ -201,6 +205,7 @@ class Report::SqlStatement # @return [Array] All fields/statements for select part def select(*fields) return(@select || default_select) if fields.empty? + (@select ||= []).tap do @sql = nil fields.reject { |f| never_select.include? f }.each do |f| diff --git a/modules/reporting/lib/report/table.rb b/modules/reporting/lib/report/table.rb index 0f09d36c3b..8bef5a85dd 100644 --- a/modules/reporting/lib/report/table.rb +++ b/modules/reporting/lib/report/table.rb @@ -30,6 +30,7 @@ class Report::Table attr_accessor :query + include Report::QueryUtils def initialize(query) @@ -76,15 +77,15 @@ class Report::Table def fields_for(type) @fields_for ||= begin - child = query.chain - fields = Hash.new { |h, k| h[k] = [] } - - until child.filter? - fields[child.type].push(*child.group_fields) - child = child.child - end - fields - end + child = query.chain + fields = Hash.new { |h, k| h[k] = [] } + + until child.filter? + fields[child.type].push(*child.group_fields) + child = child.child + end + fields + end @fields_for[type] end @@ -112,7 +113,7 @@ class Report::Table def get_index(type) @indexes ||= begin indexes = Hash.new { |h, k| h[k] = Set.new } - query.each_direct_result { |result| [:row, :column].each { |t| indexes[t] << fields_from(result, t) } } + query.each_direct_result { |result| %i[row column].each { |t| indexes[t] << fields_from(result, t) } } indexes.keys.each { |k| indexes[k] = indexes[k].sort { |x, y| compare x, y } } indexes end diff --git a/modules/reporting/lib/report/transformer.rb b/modules/reporting/lib/report/transformer.rb index 45b673b684..76b8689e75 100644 --- a/modules/reporting/lib/report/transformer.rb +++ b/modules/reporting/lib/report/transformer.rb @@ -27,6 +27,7 @@ #++ # encoding: UTF-8 + class Report::Transformer attr_reader :query @@ -47,9 +48,11 @@ class Report::Transformer def column_first @column_first ||= begin # reverse since we fake recursion ↓↓↓ - list, all_fields = restructured.reverse, @all_fields.dup + list = restructured.reverse + all_fields = @all_fields.dup result = list.inject(@ungrouped) do |aggregate, (current_fields, type)| - fields, all_fields = all_fields, all_fields - current_fields + fields = all_fields + all_fields = all_fields - current_fields aggregate.grouped_by fields, type, current_fields end result or query.result @@ -60,7 +63,9 @@ class Report::Transformer # Important side effect: it sets @ungrouped, @all_fields. # @return [Array, Symbol>>] Group by fields + types (:row or :column) def restructured - rows, columns, current = [], [], query.chain + rows = [] + columns = [] + current = query.chain @all_fields = [] until current.filter? @ungrouped = current.result if current.responsible_for_sql? diff --git a/modules/reporting/lib/report/validation.rb b/modules/reporting/lib/report/validation.rb index 2a9def7396..9f4b25764b 100644 --- a/modules/reporting/lib/report/validation.rb +++ b/modules/reporting/lib/report/validation.rb @@ -63,6 +63,7 @@ module Report::Validation def validate(*values) errors.clear return true if validations.empty? + validations.all? do |validation| values.empty? ? true : send(validation, *values) end diff --git a/modules/reporting/lib/report/validation/dates.rb b/modules/reporting/lib/report/validation/dates.rb index 8009528ae8..579818f547 100644 --- a/modules/reporting/lib/report/validation/dates.rb +++ b/modules/reporting/lib/report/validation/dates.rb @@ -31,14 +31,13 @@ module Report::Validation def validate_dates(*values) values = values.flatten return true if values.empty? + values.flatten.all? do |val| - begin - !!val.to_dateish - rescue ArgumentError - errors[:date] << val - validate_dates(values - [val]) - false - end + !!val.to_dateish + rescue ArgumentError + errors[:date] << val + validate_dates(values - [val]) + false end end end diff --git a/modules/reporting/lib/report/validation/integers.rb b/modules/reporting/lib/report/validation/integers.rb index 9d7dc927e7..35579fa268 100644 --- a/modules/reporting/lib/report/validation/integers.rb +++ b/modules/reporting/lib/report/validation/integers.rb @@ -31,6 +31,7 @@ module Report::Validation def validate_integers(*values) values = values.flatten return true if values.empty? + values.flatten.all? do |val| if val.to_i.to_s != val.to_s errors[:int] << val diff --git a/modules/reporting/lib/report/walker.rb b/modules/reporting/lib/report/walker.rb index 6d6e9adb7c..0616a6a995 100644 --- a/modules/reporting/lib/report/walker.rb +++ b/modules/reporting/lib/report/walker.rb @@ -28,6 +28,7 @@ class Report::Walker attr_accessor :query, :header_stack + def initialize(query) @query = query end @@ -68,6 +69,7 @@ class Report::Walker sublevel = 0 result.recursive_each_with_level(0, false) do |level, result| break if result.final_column? + if first_in_col = (last_level < level) list = [] last_level = level @@ -86,6 +88,7 @@ class Report::Walker def reverse_headers fail 'call header first' unless @header_stack + first = true @header_stack.reverse_each do |list| list.each do |result, first_in_col, last_in_col| @@ -97,6 +100,7 @@ class Report::Walker def headers_empty? fail 'call header first' unless @header_stack + @header_stack.empty? end @@ -109,8 +113,9 @@ class Report::Walker result.sort! end - def body(result = nil) - return [*body(result)].each { |a| yield a } if block_given? + def body(result = nil, &block) + return [*body(result)].each(&block) if block_given? + result ||= query.result.tap { |r| sort(r) } if result.row? if result.final_row? diff --git a/modules/reporting/lib/widget/controls/apply.rb b/modules/reporting/lib/widget/controls/apply.rb index d7e2233033..3f4dbbb8b8 100644 --- a/modules/reporting/lib/widget/controls/apply.rb +++ b/modules/reporting/lib/widget/controls/apply.rb @@ -32,6 +32,6 @@ class Widget::Controls::Apply < Widget::Controls '#', id: 'query-icon-apply-button', class: 'button -highlight', - :'data-target' => url_for(action: 'index', set_filter: '1')) + 'data-target': url_for(action: 'index', set_filter: '1')) end end diff --git a/modules/reporting/lib/widget/controls/delete.rb b/modules/reporting/lib/widget/controls/delete.rb index d7b776be91..1858a99f08 100644 --- a/modules/reporting/lib/widget/controls/delete.rb +++ b/modules/reporting/lib/widget/controls/delete.rb @@ -29,6 +29,7 @@ class Widget::Controls::Delete < Widget::Controls def render return '' if @subject.new_record? or !@options[:can_delete] + button = link_to(I18n.t(:button_delete), '#', id: 'query-icon-delete', diff --git a/modules/reporting/lib/widget/controls/save.rb b/modules/reporting/lib/widget/controls/save.rb index ade8a301ec..1174391da4 100644 --- a/modules/reporting/lib/widget/controls/save.rb +++ b/modules/reporting/lib/widget/controls/save.rb @@ -29,10 +29,11 @@ class Widget::Controls::Save < Widget::Controls def render return '' if @subject.new_record? or !@options[:can_save] + write link_to(I18n.t(:button_save), '#', id: 'query-breadcrumb-save', class: 'button icon-context icon-save', - :"data-target" => url_for(action: 'update', id: @subject.id, set_filter: '1')) + "data-target": url_for(action: 'update', id: @subject.id, set_filter: '1')) end end diff --git a/modules/reporting/lib/widget/controls/save_as.rb b/modules/reporting/lib/widget/controls/save_as.rb index 4bb2bfc8f1..8a63b025d7 100644 --- a/modules/reporting/lib/widget/controls/save_as.rb +++ b/modules/reporting/lib/widget/controls/save_as.rb @@ -50,31 +50,31 @@ class Widget::Controls::SaveAs < Widget::Controls class: 'form--label -transparent') do Query.human_attribute_name(:name).html_safe end + - content_tag(:span, - class: 'form--field-container') do content_tag(:span, - class: 'form--text-field-container') do - text_field_tag(:query_name, - @subject.name, - required: true) + class: 'form--field-container') do + content_tag(:span, + class: 'form--text-field-container') do + text_field_tag(:query_name, + @subject.name, + required: true) + end end - end end if @options[:can_save_as_public] box = content_tag :p, class: 'form--field -wide-label' do label_tag(:query_is_public, Query.human_attribute_name(:is_public), class: 'form--label -transparent') + - content_tag(:span, - class: 'form--field-container') do content_tag(:span, - class: 'form--check-box-container') do - check_box_tag(:query_is_public, - 1, - false, - class: 'form--check-box') + class: 'form--field-container') do + content_tag(:span, + class: 'form--check-box-container') do + check_box_tag(:query_is_public, + 1, + false, + class: 'form--check-box') + end end - end end name + box else @@ -90,7 +90,7 @@ class Widget::Controls::SaveAs < Widget::Controls '#', id: 'query-icon-save-button', class: 'button -highlight icon-context icon-save', - :"data-target" => url_for(**save_url_params)) + "data-target": url_for(**save_url_params)) cancel = link_to(I18n.t(:button_cancel), '#', diff --git a/modules/reporting/lib/widget/filters.rb b/modules/reporting/lib/widget/filters.rb index a506aa188c..55894bc726 100644 --- a/modules/reporting/lib/widget/filters.rb +++ b/modules/reporting/lib/widget/filters.rb @@ -35,8 +35,8 @@ class Widget::Filters < ::Widget::Base add_filter_label = label_tag 'add_filter_select', I18n.t(:label_filter_add), class: 'advanced-filters--add-filter-label' add_filter_label += label_tag 'add_filter_select', I18n.t('js.filter.description.text_open_filter') + ' ' + - I18n.t('js.filter.description.text_close_filter'), - class: 'hidden-for-sighted' + I18n.t('js.filter.description.text_close_filter'), + class: 'hidden-for-sighted' add_filter_value = content_tag :div, class: 'advanced-filters--add-filter-value' do select_tag 'add_filter_select', @@ -67,8 +67,8 @@ class Widget::Filters < ::Widget::Base engine::Filter.all.select(&:selectable?).map do |filter| opts = { id: "filter_#{filter.underscore_name}", class: "#{filter.underscore_name} advanced-filters--filter", - :"data-filter-name" => filter.underscore_name } - active_instance = active_filters.detect { |f| f.class == filter } + "data-filter-name": filter.underscore_name } + active_instance = active_filters.detect { |f| f.instance_of?(filter) } if active_instance opts[:"data-selected"] = true else @@ -97,12 +97,10 @@ class Widget::Filters < ::Widget::Base else render_widget MultiValues, f, to: html, lazy: true end + elsif f_cls.is_multiple_choice? + render_widget MultiChoice, f, to: html else - if f_cls.is_multiple_choice? - render_widget MultiChoice, f, to: html - else - render_widget MultiValues, f, to: html, lazy: true - end + render_widget MultiValues, f, to: html, lazy: true end render_widget RemoveButton, f, to: html end diff --git a/modules/reporting/lib/widget/filters/base.rb b/modules/reporting/lib/widget/filters/base.rb index d68ded18aa..2b36280ea0 100644 --- a/modules/reporting/lib/widget/filters/base.rb +++ b/modules/reporting/lib/widget/filters/base.rb @@ -30,7 +30,7 @@ class Widget::Filters::Base < Widget::Base attr_reader :filter, :filter_class def initialize(filter) - if filter.class == Class + if filter.instance_of?(Class) @filter_class = filter @filter = filter.new else diff --git a/modules/reporting/lib/widget/filters/date.rb b/modules/reporting/lib/widget/filters/date.rb index b38ca935d2..1eebc90ab9 100644 --- a/modules/reporting/lib/widget/filters/date.rb +++ b/modules/reporting/lib/widget/filters/date.rb @@ -46,7 +46,7 @@ class Widget::Filters::Date < Widget::Filters::Base size: 10, class: 'advanced-filters--text-field -augmented-datepicker', id: "#{id_prefix}arg_1_val", - :'data-type' => 'date' + 'data-type': 'date' label1 + text1 end @@ -55,11 +55,11 @@ class Widget::Filters::Date < Widget::Filters::Base class: 'hidden-for-sighted' arg2 = content_tag :span, id: "#{id_prefix}arg_2", class: 'advanced-filters--filter-value2' do - text2 = text_field_tag "#{name}", @filter.values.second.to_s, + text2 = text_field_tag name.to_s, @filter.values.second.to_s, size: 10, class: 'advanced-filters--text-field -augmented-datepicker', id: "#{id_prefix}arg_2_val", - :'data-type' => 'date' + 'data-type': 'date' label2 + text2 end diff --git a/modules/reporting/lib/widget/filters/heavy.rb b/modules/reporting/lib/widget/filters/heavy.rb index 049949ca06..b217de8b78 100644 --- a/modules/reporting/lib/widget/filters/heavy.rb +++ b/modules/reporting/lib/widget/filters/heavy.rb @@ -41,13 +41,13 @@ class Widget::Filters::Heavy < Widget::Filters::Base values = filter.values.first.is_a?(Array) ? filter.values.first : filter.values opts = Array(values).empty? ? [] : values.map { |i| filter_class.label_for_value(i.to_i) } div = content_tag :div, id: "#{filter_class.underscore_name}_arg_1", class: 'advanced-filters--filter-value hidden' do - select_options = { :"data-remote-url" => url_for(action: 'available_values'), - :"data-initially-selected" => JSON::dump(Array(filter.values).flatten), + select_options = { "data-remote-url": url_for(action: 'available_values'), + "data-initially-selected": JSON::dump(Array(filter.values).flatten), name: "values[#{filter_class.underscore_name}][]", - :"data-loading" => '', + "data-loading": '', id: "#{filter_class.underscore_name}_arg_1_val", class: 'advanced-filters--select filter-value', - :"data-filter-name" => filter_class.underscore_name } + "data-filter-name": filter_class.underscore_name } box = content_tag :select, select_options do render_widget Widget::Filters::Option, filter, to: '', content: opts end diff --git a/modules/reporting/lib/widget/filters/label.rb b/modules/reporting/lib/widget/filters/label.rb index 633b64c5f9..7f755105c9 100644 --- a/modules/reporting/lib/widget/filters/label.rb +++ b/modules/reporting/lib/widget/filters/label.rb @@ -32,7 +32,7 @@ require_dependency 'widget/filters/base' class Widget::Filters::Label < Widget::Filters::Base def render options = { - id: filter_class.underscore_name, + id: filter_class.underscore_name, class: 'advanced-filters--filter-name', title: h(filter_class.label) } diff --git a/modules/reporting/lib/widget/filters/multi_choice.rb b/modules/reporting/lib/widget/filters/multi_choice.rb index bb013fb64d..6e569620a5 100644 --- a/modules/reporting/lib/widget/filters/multi_choice.rb +++ b/modules/reporting/lib/widget/filters/multi_choice.rb @@ -44,7 +44,7 @@ class Widget::Filters::MultiChoice < Widget::Filters::Base radio_button = tag :input, opts content_tag :label, radio_button + translate(label), for: "#{filterName}_radio_option_#{i}", - :'data-filter-name' => filter_class.underscore_name, + 'data-filter-name': filter_class.underscore_name, class: "#{filterName}_radio_option filter_radio_option" end content_tag :div, choices.join.html_safe, diff --git a/modules/reporting/lib/widget/filters/multi_values.rb b/modules/reporting/lib/widget/filters/multi_values.rb index 56d04a34c1..6eee034131 100644 --- a/modules/reporting/lib/widget/filters/multi_values.rb +++ b/modules/reporting/lib/widget/filters/multi_values.rb @@ -32,14 +32,14 @@ require_dependency 'widget/filters/base' class Widget::Filters::MultiValues < Widget::Filters::Base def render write(content_tag(:div, id: "#{filter_class.underscore_name}_arg_1", class: 'advanced-filters--filter-value') do - select_options = { :"data-remote-url" => url_for(action: 'available_values'), - :"data-initially-selected" => JSON::dump(Array(filter.values).flatten), + select_options = { "data-remote-url": url_for(action: 'available_values'), + "data-initially-selected": JSON::dump(Array(filter.values).flatten), style: 'vertical-align: top;', # FIXME: Do CSS name: "values[#{filter_class.underscore_name}][]", - :"data-loading" => @options[:lazy] ? 'ajax' : '', + "data-loading": @options[:lazy] ? 'ajax' : '', id: "#{filter_class.underscore_name}_arg_1_val", class: 'form--select filter-value', - :"data-filter-name" => filter_class.underscore_name } + "data-filter-name": filter_class.underscore_name } box_content = ''.html_safe label = label_tag "#{filter_class.underscore_name}_arg_1_val", h(filter_class.label) + ' ' + I18n.t(:label_filter_value), @@ -51,14 +51,14 @@ class Widget::Filters::MultiValues < Widget::Filters::Base plus = content_tag :a, href: '#', class: 'form-label filter_multi-select -transparent', - :"data-filter-name" => filter_class.underscore_name, + "data-filter-name": filter_class.underscore_name, title: I18n.t(:description_multi_select) do - content_tag :span, - '', - class: 'icon-context icon-button icon-add icon4', - title: I18n.t(:label_enable_multi_select) do - content_tag :span, I18n.t(:label_enable_multi_select), class: 'hidden-for-sighted' - end + content_tag :span, + '', + class: 'icon-context icon-button icon-add icon4', + title: I18n.t(:label_enable_multi_select) do + content_tag :span, I18n.t(:label_enable_multi_select), class: 'hidden-for-sighted' + end end content_tag(:span, class: 'inline-label') do diff --git a/modules/reporting/lib/widget/filters/operators.rb b/modules/reporting/lib/widget/filters/operators.rb index 3805f89efd..ee491c5e27 100644 --- a/modules/reporting/lib/widget/filters/operators.rb +++ b/modules/reporting/lib/widget/filters/operators.rb @@ -36,13 +36,13 @@ class Widget::Filters::Operators < Widget::Filters::Base options = { class: 'advanced-filters--select filters-select filter_operator', id: "operators[#{filter_class.underscore_name}]", name: "operators[#{filter_class.underscore_name}]", - :"data-filter-name" => filter_class.underscore_name } + "data-filter-name": filter_class.underscore_name } options.merge! style: 'display: none' if hide_select_box select_box = content_tag :select, options do filter_class.available_operators.map do |o| - opts = { value: h(o.to_s), :"data-arity" => o.arity } - opts.reverse_merge! :"data-forced" => o.forced if o.forced? + opts = { value: h(o.to_s), "data-arity": o.arity } + opts.reverse_merge! "data-forced": o.forced if o.forced? opts[:selected] = 'selected' if filter.operator.to_s == o.to_s content_tag(:option, opts) { h(I18n.t(o.label)) } end.join.html_safe diff --git a/modules/reporting/lib/widget/filters/option.rb b/modules/reporting/lib/widget/filters/option.rb index f461c4c26b..338b284763 100644 --- a/modules/reporting/lib/widget/filters/option.rb +++ b/modules/reporting/lib/widget/filters/option.rb @@ -41,7 +41,7 @@ class Widget::Filters::Option < Widget::Filters::Base level = options[:level] # nesting_level is optional for values name = I18n.t(name) if name.is_a? Symbol name = name.empty? ? I18n.t(:label_none) : name - name_prefix = ((level && level > 0) ? (' ' * 2 * level + '> ') : '') + name_prefix = (level && level > 0 ? (' ' * 2 * level + '> ') : '') if options[:optgroup] tag :optgroup, label: I18n.t(:label_sector) else diff --git a/modules/reporting/lib/widget/filters/text_box.rb b/modules/reporting/lib/widget/filters/text_box.rb index c965a1f40f..45c4c1af93 100644 --- a/modules/reporting/lib/widget/filters/text_box.rb +++ b/modules/reporting/lib/widget/filters/text_box.rb @@ -41,7 +41,7 @@ class Widget::Filters::TextBox < Widget::Filters::Base size: '6', class: 'advanced-filters--text-field', id: "#{filter_class.underscore_name}_arg_1_val", - :'data-filter-name' => filter_class.underscore_name) + 'data-filter-name': filter_class.underscore_name) end) end end diff --git a/modules/reporting/lib/widget/group_bys.rb b/modules/reporting/lib/widget/group_bys.rb index 743ea5fac5..bf3299516b 100644 --- a/modules/reporting/lib/widget/group_bys.rb +++ b/modules/reporting/lib/widget/group_bys.rb @@ -30,7 +30,8 @@ class Widget::GroupBys < Widget::Base def render_options(group_by_ary) group_by_ary.sort_by(&:label).map do |group_by| next unless group_by.selectable? - content_tag :option, value: group_by.underscore_name, :'data-label' => "#{CGI::escapeHTML(h(group_by.label))}" do + + content_tag :option, value: group_by.underscore_name, 'data-label': CGI::escapeHTML(h(group_by.label)).to_s do h(group_by.label) end end.join.html_safe @@ -47,7 +48,7 @@ class Widget::GroupBys < Widget::Base container = content_tag :div, id: "group-by--#{type}", class: 'group-by--container grid-block', - :'data-initially-selected' => initially_selected.to_json.gsub('"', "'") do + 'data-initially-selected': initially_selected.to_json.gsub('"', "'") do out = content_tag :span, class: 'group-by--caption grid-content shrink' do content_tag :span do I18n.t(:"label_#{type}") @@ -59,7 +60,7 @@ class Widget::GroupBys < Widget::Base out += content_tag :span, class: 'group-by--control grid-content shrink' do label = label_tag "group-by--add-#{type}", - I18n.t(:"label_group_by_add") + ' ' + + I18n.t(:label_group_by_add) + ' ' + I18n.t('js.filter.description.text_open_filter'), class: 'hidden-for-sighted' diff --git a/modules/reporting/lib/widget/reporting_widget.rb b/modules/reporting/lib/widget/reporting_widget.rb index ed01dd2b55..ec6ad7b601 100644 --- a/modules/reporting/lib/widget/reporting_widget.rb +++ b/modules/reporting/lib/widget/reporting_widget.rb @@ -73,5 +73,5 @@ class Widget::ReportingWidget < ActionView::Base end end -ActionView::Base.send(:include, Widget::ReportingWidget::RenderWidgetInstanceMethods) -ActionController::Base.send(:include, Widget::ReportingWidget::RenderWidgetInstanceMethods) +ActionView::Base.include Widget::ReportingWidget::RenderWidgetInstanceMethods +ActionController::Base.include Widget::ReportingWidget::RenderWidgetInstanceMethods diff --git a/modules/reporting/lib/widget/settings/fieldset.rb b/modules/reporting/lib/widget/settings/fieldset.rb index fadb5b7adb..6f045f6e69 100644 --- a/modules/reporting/lib/widget/settings/fieldset.rb +++ b/modules/reporting/lib/widget/settings/fieldset.rb @@ -31,7 +31,7 @@ class Widget::Settings::Fieldset < Widget::Base def render_with_options(options, &block) @type = options.delete(:type) || 'filter' - @id = "#{@type}" + @id = @type.to_s @label = :"label_#{@type}" super(options, &block) end diff --git a/modules/reporting/lib/widget/settings_patch.rb b/modules/reporting/lib/widget/settings_patch.rb index 287d3d7b26..23609faa16 100644 --- a/modules/reporting/lib/widget/settings_patch.rb +++ b/modules/reporting/lib/widget/settings_patch.rb @@ -58,4 +58,4 @@ module Widget::SettingsPatch end end -Widget::Settings.send(:include, Widget::SettingsPatch) +Widget::Settings.include Widget::SettingsPatch diff --git a/modules/reporting/lib/widget/table.rb b/modules/reporting/lib/widget/table.rb index ef7ebe0f0f..6750235fbf 100644 --- a/modules/reporting/lib/widget/table.rb +++ b/modules/reporting/lib/widget/table.rb @@ -30,12 +30,11 @@ class Widget::Table < Widget::Base extend Report::InheritedAttribute include ReportingHelper - attr_accessor :debug - attr_accessor :fields - attr_accessor :mapping + attr_accessor :debug, :fields, :mapping def initialize(query) raise ArgumentError, 'Tables only work on CostQuery!' unless query.is_a? CostQuery + super end diff --git a/modules/reporting/lib/widget/table/entry_table.rb b/modules/reporting/lib/widget/table/entry_table.rb index 41a21c8aad..e1b6f1b837 100644 --- a/modules/reporting/lib/widget/table/entry_table.rb +++ b/modules/reporting/lib/widget/table/entry_table.rb @@ -27,7 +27,7 @@ #++ class ::Widget::Table::EntryTable < ::Widget::Table - FIELDS = [:spent_on, :user_id, :activity_id, :work_package_id, :comments, :project_id] + FIELDS = %i[spent_on user_id activity_id work_package_id comments project_id] detailed_table self @@ -87,6 +87,7 @@ class ::Widget::Table::EntryTable < ::Widget::Table hit = false @subject.each_direct_result do |result| next if hit + if entry_for(result).editable_by? User.current concat content_tag(:th, class: 'unsortable') { content_tag(:div, '', class: 'generic-table--empty-header') @@ -134,16 +135,16 @@ class ::Widget::Table::EntryTable < ::Widget::Table ''.html_safe FIELDS.each do |field| concat content_tag(:td, show_field(field, result.fields[field.to_s]).html_safe, - :'raw-data' => raw_field(field, result.fields[field.to_s]), + 'raw-data': raw_field(field, result.fields[field.to_s]), class: 'left') end concat content_tag :td, show_result(result, result.fields['cost_type_id'].to_i).html_safe, class: 'units right', - :'raw-data' => result.units + 'raw-data': result.units concat content_tag :td, - (show_result(result, 0)).html_safe, + show_result(result, 0).html_safe, class: 'currency right', - :'raw-data' => result.real_costs + 'raw-data': result.real_costs concat content_tag :td, icons(result) end) end @@ -162,8 +163,8 @@ class ::Widget::Table::EntryTable < ::Widget::Table title: I18n.t(:button_edit)) icons << link_to(icon_wrapper('icon-context icon-delete', I18n.t(:button_delete)), - (action_for(result, action: 'destroy') - .reverse_merge(authenticity_token: form_authenticity_token)), + action_for(result, action: 'destroy') + .reverse_merge(authenticity_token: form_authenticity_token), data: { confirm: I18n.t(:text_are_you_sure) }, method: :delete, class: 'no-decoration-on-hover', diff --git a/modules/reporting/lib/widget/table/report_table.rb b/modules/reporting/lib/widget/table/report_table.rb index 4f3c4226e7..6b695d167c 100644 --- a/modules/reporting/lib/widget/table/report_table.rb +++ b/modules/reporting/lib/widget/table/report_table.rb @@ -130,6 +130,7 @@ class Widget::Table::ReportTable < Widget::Table def render_tfoot return if walker.headers_empty? + write '' walker.reverse_headers do |list, first, first_in_col, last_in_col| if first_in_col diff --git a/modules/reporting/spec/controllers/custom_fields_controller_spec.rb b/modules/reporting/spec/controllers/custom_fields_controller_spec.rb index db504a3446..e37404fc29 100644 --- a/modules/reporting/spec/controllers/custom_fields_controller_spec.rb +++ b/modules/reporting/spec/controllers/custom_fields_controller_spec.rb @@ -121,14 +121,14 @@ describe CustomFieldsController do context 'session' do let(:engine_name) { CostQuery.name.underscore.to_sym } let(:key) { :"custom_field#{custom_field.id}" } - let(:query) { { filters: + let(:query) do + { filters: { operators: { user_id: "=", key => "=" }, values: { user_id: ["96"], key => "" } }, - groups: { rows: [key.to_s], columns: [key.to_s] } - } - } + groups: { rows: [key.to_s], columns: [key.to_s] } } + end before { session[engine_name] = query } describe 'does not contain custom field reference' do diff --git a/modules/reporting/spec/features/calculations_spec.rb b/modules/reporting/spec/features/calculations_spec.rb index dfe7b5e19a..06abba7640 100644 --- a/modules/reporting/spec/features/calculations_spec.rb +++ b/modules/reporting/spec/features/calculations_spec.rb @@ -9,41 +9,40 @@ describe 'Cost report calculations', type: :feature, js: true do let!(:hourly_rate2) { FactoryBot.create :default_hourly_rate, user: user, rate: 5.00, valid_from: 2.years.ago } let!(:hourly_rate3) { FactoryBot.create :default_hourly_rate, user: user, rate: 10.00, valid_from: 3.years.ago } - let!(:time_entry1) { + let!(:time_entry1) do FactoryBot.create :time_entry, - spent_on: 6.months.ago, - user: user, - work_package: work_package, - project: project, - hours: 10 - } - let!(:time_entry2) { + spent_on: 6.months.ago, + user: user, + work_package: work_package, + project: project, + hours: 10 + end + let!(:time_entry2) do FactoryBot.create :time_entry, - spent_on: 18.months.ago, - user: user, - work_package: work_package, - project: project, - hours: 10 - } - let!(:time_entry3) { + spent_on: 18.months.ago, + user: user, + work_package: work_package, + project: project, + hours: 10 + end + let!(:time_entry3) do FactoryBot.create :time_entry, - spent_on: 30.months.ago, - user: user, - work_package: work_package, - project: project, - hours: 10 - } + spent_on: 30.months.ago, + user: user, + work_package: work_package, + project: project, + hours: 10 + end before do login_as(user) visit '/cost_reports?set_filter=1' end - it 'shows the correct calculations' do expect(page).to have_text '10.00' # 1 EUR x 10 expect(page).to have_text '50.00' # 5 EUR x 10 expect(page).to have_text '100.00' # 10 EUR x 10 expect(page).to have_text '160.00' end -end \ No newline at end of file +end diff --git a/modules/reporting/spec/features/custom_fields_spec.rb b/modules/reporting/spec/features/custom_fields_spec.rb index d378a36e8f..1f1ceed431 100644 --- a/modules/reporting/spec/features/custom_fields_spec.rb +++ b/modules/reporting/spec/features/custom_fields_spec.rb @@ -57,7 +57,6 @@ describe 'Custom fields reporting', type: :feature, js: true do hours: 2.50 end - def custom_value_for(cf, str) cf.custom_options.find { |co| co.value == str }.try(:id) end @@ -130,7 +129,7 @@ describe 'Custom fields reporting', type: :feature, js: true do # Expect row of work package within('#result-table') do - expect(page).to have_selector('a.issue', text: "#{work_package.type.to_s} ##{work_package.id}") + expect(page).to have_selector('a.issue', text: "#{work_package.type} ##{work_package.id}") expect(page).to have_selector('th.inner', text: 'First option') expect(page).to have_no_selector('th.inner', text: 'Second option') @@ -159,7 +158,7 @@ describe 'Custom fields reporting', type: :feature, js: true do let!(:work_package2) do FactoryBot.create :work_package, project: project, - custom_values: { custom_field_2.id => custom_value_for(custom_field_2, 'A')} + custom_values: { custom_field_2.id => custom_value_for(custom_field_2, 'A') } end let!(:time_entry1) do @@ -191,7 +190,7 @@ describe 'Custom fields reporting', type: :feature, js: true do # Expect row of work package within('#result-table') do - expect(page).to have_selector('a.issue', text: "#{work_package.type.to_s} ##{work_package.id}") + expect(page).to have_selector('a.issue', text: "#{work_package.type} ##{work_package.id}") expect(page).to have_selector('th.inner', text: '1') expect(page).to have_no_selector('th.inner', text: 'invalid!') end @@ -224,7 +223,7 @@ describe 'Custom fields reporting', type: :feature, js: true do # Expect row of work package within('#result-table') do - expect(page).to have_selector('a.issue', text: "#{work_package.type.to_s} ##{work_package.id}") + expect(page).to have_selector('a.issue', text: "#{work_package.type} ##{work_package.id}") expect(page).to have_selector('th.inner', text: 'foo') expect(page).to have_no_selector('th.inner', text: 'None') diff --git a/modules/reporting/spec/features/filter_spec.rb b/modules/reporting/spec/features/filter_spec.rb index 045fdacc53..b17d510f4d 100644 --- a/modules/reporting/spec/features/filter_spec.rb +++ b/modules/reporting/spec/features/filter_spec.rb @@ -32,4 +32,4 @@ describe 'Cost report calculations', type: :feature, js: true do expect(page).to have_selector("#user_id_arg_1_val", text: 'me') end -end \ No newline at end of file +end diff --git a/modules/reporting/spec/features/group_by_spec.rb b/modules/reporting/spec/features/group_by_spec.rb index daf6733dd8..eaf7cb8b99 100644 --- a/modules/reporting/spec/features/group_by_spec.rb +++ b/modules/reporting/spec/features/group_by_spec.rb @@ -8,109 +8,108 @@ describe 'Cost report calculations', type: :feature, js: true do let(:work_package) { FactoryBot.create :work_package, project: project } let!(:hourly_rate1) { FactoryBot.create :default_hourly_rate, user: user, rate: 1.00, valid_from: 1.year.ago } - let(:report_page) { ::Pages::CostReportPage.new project} + let(:report_page) { ::Pages::CostReportPage.new project } - let!(:time_entry1) { + let!(:time_entry1) do FactoryBot.create :time_entry, - spent_on: 6.months.ago, - user: user, - work_package: work_package, - project: project, - hours: 10 - } + spent_on: 6.months.ago, + user: user, + work_package: work_package, + project: project, + hours: 10 + end before do login_as(user) visit cost_reports_path(project) end - it 'provides grouping' do - # Then I should see "Week (Spent)" in columns - # And I should see "Work package" in rows - report_page.expect_column_element('Week (Spent)') - report_page.expect_row_element('Work package') - - # When I click on "Clear" - report_page.clear - # Then I should not see "Week (Spent)" in columns - # And I should not see "Work package" in rows - report_page.expect_column_element('Week (Spent)', present: false) - report_page.expect_row_element('Work package', present: false) - - # And I group rows by "User" - report_page.add_to_rows 'User' - # And I group rows by "Cost type" - report_page.add_to_rows 'Cost type' - - # When I click on "Clear" - report_page.clear - - # Then I should not see "Week (Spent)" in columns - # And I should not see "Work package" in rows - report_page.expect_column_element('Week (Spent)', present: false) - report_page.expect_row_element('Work package', present: false) - # And I should not see "User" in rows - # And I should not see "Cost type" in rows - report_page.expect_row_element('User', present: false) - report_page.expect_row_element('Cost type', present: false) - - # When I click on "Clear" - report_page.clear - # And I group columns by "Work package" - report_page.add_to_columns 'Work package' - - # Then I should see "Work package" in columns - report_page.expect_column_element('Work package') - # When I group rows by "Project" - report_page.add_to_columns 'Project' - # Then I should see "Project" in rows - report_page.expect_column_element('Project') - - # When I click on "Clear" - report_page.clear - # And I group columns by "Work package" - report_page.add_to_columns 'Work package' - # And I group rows by "Project" - report_page.add_to_rows 'Project' - - # Then I should see "Work package" in columns - report_page.expect_column_element('Work package') - # And I should see "Project" in rows - report_page.expect_row_element('Project') - - # When I remove "Project" from rows - report_page.remove_row_element('Project') - - # And I remove "Work package" from columns - report_page.remove_column_element('Work package') - - # Then I should not see "Work package" in columns - report_page.expect_column_element('Work package', present: false) - # And I should not see "Project" in rows - report_page.expect_row_element('Project', present: false) - - # When I click on "Clear" - report_page.clear - - # And I group columns by "Project" - report_page.add_to_columns 'Project' - # And I group columns by "Work package" - report_page.add_to_columns 'Work package' - # And I group rows by "User" - report_page.add_to_rows 'User' - # And I group rows by "Cost type" - report_page.add_to_rows 'Cost type' - - # And I send the query - report_page.apply - - # Then I should see "Project" in columns - report_page.expect_column_element('Work package') - # And I should see "Work package" in columns - report_page.expect_column_element('Project') - # And I should see "User" in rows - report_page.expect_row_element('User') - # And I should see "Cost type" in rows - report_page.expect_row_element('Cost type') + # Then I should see "Week (Spent)" in columns + # And I should see "Work package" in rows + report_page.expect_column_element('Week (Spent)') + report_page.expect_row_element('Work package') + + # When I click on "Clear" + report_page.clear + # Then I should not see "Week (Spent)" in columns + # And I should not see "Work package" in rows + report_page.expect_column_element('Week (Spent)', present: false) + report_page.expect_row_element('Work package', present: false) + + # And I group rows by "User" + report_page.add_to_rows 'User' + # And I group rows by "Cost type" + report_page.add_to_rows 'Cost type' + + # When I click on "Clear" + report_page.clear + + # Then I should not see "Week (Spent)" in columns + # And I should not see "Work package" in rows + report_page.expect_column_element('Week (Spent)', present: false) + report_page.expect_row_element('Work package', present: false) + # And I should not see "User" in rows + # And I should not see "Cost type" in rows + report_page.expect_row_element('User', present: false) + report_page.expect_row_element('Cost type', present: false) + + # When I click on "Clear" + report_page.clear + # And I group columns by "Work package" + report_page.add_to_columns 'Work package' + + # Then I should see "Work package" in columns + report_page.expect_column_element('Work package') + # When I group rows by "Project" + report_page.add_to_columns 'Project' + # Then I should see "Project" in rows + report_page.expect_column_element('Project') + + # When I click on "Clear" + report_page.clear + # And I group columns by "Work package" + report_page.add_to_columns 'Work package' + # And I group rows by "Project" + report_page.add_to_rows 'Project' + + # Then I should see "Work package" in columns + report_page.expect_column_element('Work package') + # And I should see "Project" in rows + report_page.expect_row_element('Project') + + # When I remove "Project" from rows + report_page.remove_row_element('Project') + + # And I remove "Work package" from columns + report_page.remove_column_element('Work package') + + # Then I should not see "Work package" in columns + report_page.expect_column_element('Work package', present: false) + # And I should not see "Project" in rows + report_page.expect_row_element('Project', present: false) + + # When I click on "Clear" + report_page.clear + + # And I group columns by "Project" + report_page.add_to_columns 'Project' + # And I group columns by "Work package" + report_page.add_to_columns 'Work package' + # And I group rows by "User" + report_page.add_to_rows 'User' + # And I group rows by "Cost type" + report_page.add_to_rows 'Cost type' + + # And I send the query + report_page.apply + + # Then I should see "Project" in columns + report_page.expect_column_element('Work package') + # And I should see "Work package" in columns + report_page.expect_column_element('Project') + # And I should see "User" in rows + report_page.expect_row_element('User') + # And I should see "Cost type" in rows + report_page.expect_row_element('Cost type') end -end \ No newline at end of file +end diff --git a/modules/reporting/spec/features/me_value_spec.rb b/modules/reporting/spec/features/me_value_spec.rb index 77dfd973cb..29e4c89bcf 100644 --- a/modules/reporting/spec/features/me_value_spec.rb +++ b/modules/reporting/spec/features/me_value_spec.rb @@ -8,20 +8,20 @@ describe 'Cost report showing my own times', type: :feature, js: true do let(:work_package) { FactoryBot.create :work_package, project: project } let!(:hourly_rate1) { FactoryBot.create :default_hourly_rate, user: user, rate: 1.00, valid_from: 1.year.ago } - let!(:time_entry1) { + let!(:time_entry1) do FactoryBot.create :time_entry, - user: user, - work_package: work_package, - project: project, - hours: 10 - } - let!(:time_entry2) { + user: user, + work_package: work_package, + project: project, + hours: 10 + end + let!(:time_entry2) do FactoryBot.create :time_entry, user: user2, work_package: work_package, project: project, hours: 15 - } + end before do # Login as first user @@ -29,7 +29,6 @@ describe 'Cost report showing my own times', type: :feature, js: true do # Create and save cost report visit cost_reports_path(project) - end shared_examples 'me filter value' do |filter_name, filter_selector| @@ -43,7 +42,7 @@ describe 'Cost report showing my own times', type: :feature, js: true do expect(page).to have_selector('.report', text: '10.00') report = CostQuery.last - user_filter = report.serialized[:filters].detect { |name,_| name == filter_name } + user_filter = report.serialized[:filters].detect { |name, _| name == filter_name } expect(user_filter[1][:values]).to eq %w(me) # Login as the next user @@ -62,21 +61,20 @@ describe 'Cost report showing my own times', type: :feature, js: true do let(:work_package) { FactoryBot.create :work_package, project: project, assigned_to: user } let(:work_package2) { FactoryBot.create :work_package, project: project, assigned_to: user2 } - let!(:time_entry1) { + let!(:time_entry1) do FactoryBot.create :time_entry, user: user, work_package: work_package, project: project, hours: 10 - } - let!(:time_entry2) { + end + let!(:time_entry2) do FactoryBot.create :time_entry, user: user2, work_package: work_package2, project: project, hours: 15 - } - + end before do # Remove default user filter, add assignee filter diff --git a/modules/reporting/spec/features/my_time_spec.rb b/modules/reporting/spec/features/my_time_spec.rb index 9ca9f3baec..0c0bf414e9 100644 --- a/modules/reporting/spec/features/my_time_spec.rb +++ b/modules/reporting/spec/features/my_time_spec.rb @@ -8,20 +8,19 @@ describe 'Cost report showing my own times', type: :feature, js: true do let(:work_package) { FactoryBot.create :work_package, project: project } let!(:hourly_rate1) { FactoryBot.create :default_hourly_rate, user: user, rate: 1.00, valid_from: 1.year.ago } - let!(:time_entry1) { + let!(:time_entry1) do FactoryBot.create :time_entry, - user: user, - work_package: work_package, - project: project, - hours: 10 - } + user: user, + work_package: work_package, + project: project, + hours: 10 + end before do login_as(current_user) visit cost_reports_path(project) end - context 'as user with logged time' do let(:current_user) { user } it 'shows my time' do diff --git a/modules/reporting/spec/features/permissions_spec.rb b/modules/reporting/spec/features/permissions_spec.rb index 043c15c693..0d04e539b1 100644 --- a/modules/reporting/spec/features/permissions_spec.rb +++ b/modules/reporting/spec/features/permissions_spec.rb @@ -9,8 +9,8 @@ describe 'Cost report calculations', type: :feature, js: true do let!(:role) { FactoryBot.create :role, permissions: permissions } let!(:user) do FactoryBot.create :user, - member_in_project: project, - member_through_role: role + member_in_project: project, + member_through_role: role end let(:work_package) { FactoryBot.create :work_package, project: project } @@ -19,33 +19,33 @@ describe 'Cost report calculations', type: :feature, js: true do let(:report_page) { ::Pages::CostReportPage.new project } - let!(:time_entry_user) { + let!(:time_entry_user) do FactoryBot.create :time_entry, - user: admin, - work_package: work_package, - project: project, - hours: 10 - } - let!(:time_entry_admin) { + user: admin, + work_package: work_package, + project: project, + hours: 10 + end + let!(:time_entry_admin) do FactoryBot.create :time_entry, - user: user, - work_package: work_package, - project: project, - hours: 5 - } - let!(:cost_type) { + user: user, + work_package: work_package, + project: project, + hours: 5 + end + let!(:cost_type) do type = FactoryBot.create :cost_type, name: 'Translations' FactoryBot.create :cost_rate, cost_type: type, rate: 7.00 type - } - let!(:cost_entry_user) { + end + let!(:cost_entry_user) do FactoryBot.create :cost_entry, - work_package: work_package, - project: project, - units: 3.00, - cost_type: cost_type, - user: user - } + work_package: work_package, + project: project, + units: 3.00, + cost_type: cost_type, + user: user + end before do login_as current_user @@ -77,7 +77,7 @@ describe 'Cost report calculations', type: :feature, js: true do context 'as user with all permissions' do let(:current_user) { user } let!(:permissions) do - %i(view_own_hourly_rate view_hourly_rates view_cost_rates + %i(view_own_hourly_rate view_hourly_rates view_cost_rates view_own_time_entries view_own_cost_entries view_cost_entries view_time_entries) end @@ -102,7 +102,7 @@ describe 'Cost report calculations', type: :feature, js: true do context 'as user with own permissions' do let(:current_user) { user } let!(:permissions) do - %i(view_own_hourly_rate view_own_time_entries view_own_cost_entries) + %i(view_own_hourly_rate view_own_time_entries view_own_cost_entries) end it 'shows his own costs' do diff --git a/modules/reporting/spec/features/project_context_spec.rb b/modules/reporting/spec/features/project_context_spec.rb index 21d0a06a19..265d38d0cc 100644 --- a/modules/reporting/spec/features/project_context_spec.rb +++ b/modules/reporting/spec/features/project_context_spec.rb @@ -21,4 +21,4 @@ describe 'Cost report project context', type: :feature, js: true do visit cost_reports_path(project2) expect(page).to have_selector('#project_id_arg_1_val option', text: project2.name) end -end \ No newline at end of file +end diff --git a/modules/reporting/spec/features/saving_spec.rb b/modules/reporting/spec/features/saving_spec.rb index 5a8e2d1f71..4a3a86b9b5 100644 --- a/modules/reporting/spec/features/saving_spec.rb +++ b/modules/reporting/spec/features/saving_spec.rb @@ -50,8 +50,8 @@ describe 'Cost report saving', type: :feature, js: true do let(:role) { FactoryBot.create :role, permissions: %i(view_time_entries) } let!(:user) do FactoryBot.create :user, - member_in_project: project, - member_through_role: role + member_in_project: project, + member_through_role: role end it 'cannot save reports' do diff --git a/modules/reporting/spec/features/subproject_spec.rb b/modules/reporting/spec/features/subproject_spec.rb index ebc5fb5673..e27eef2999 100644 --- a/modules/reporting/spec/features/subproject_spec.rb +++ b/modules/reporting/spec/features/subproject_spec.rb @@ -7,8 +7,8 @@ describe 'Cost report in subproject', type: :feature, js: true do let!(:role) { FactoryBot.create :role, permissions: %i(view_cost_entries view_own_cost_entries) } let!(:user) do FactoryBot.create :user, - member_in_project: subproject, - member_through_role: role + member_in_project: subproject, + member_through_role: role end before do @@ -25,4 +25,4 @@ describe 'Cost report in subproject', type: :feature, js: true do expect(page).to have_content 'New cost report' end end -end \ No newline at end of file +end diff --git a/modules/reporting/spec/features/support/components/cost_reports_base_table.rb b/modules/reporting/spec/features/support/components/cost_reports_base_table.rb index ffe40e1ad0..0b4c419d50 100644 --- a/modules/reporting/spec/features/support/components/cost_reports_base_table.rb +++ b/modules/reporting/spec/features/support/components/cost_reports_base_table.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - module Components class CostReportsBaseTable include Capybara::DSL diff --git a/modules/reporting/spec/lib/open_project/configuration_spec.rb b/modules/reporting/spec/lib/open_project/configuration_spec.rb index e1b1ac2b16..e0579819f8 100644 --- a/modules/reporting/spec/lib/open_project/configuration_spec.rb +++ b/modules/reporting/spec/lib/open_project/configuration_spec.rb @@ -47,10 +47,8 @@ describe 'OpenProject::Configuration' do expect(OpenProject::Configuration.cost_reporting_cache_filter_classes).to be_truthy end - it 'is true by default via the hash' do expect(OpenProject::Configuration['cost_reporting_cache_filter_classes']).to be_truthy end - end end diff --git a/modules/reporting/spec/models/cost_query/cache_spec.rb b/modules/reporting/spec/models/cost_query/cache_spec.rb index 4a13123cd8..f3a04fbbeb 100644 --- a/modules/reporting/spec/models/cost_query/cache_spec.rb +++ b/modules/reporting/spec/models/cost_query/cache_spec.rb @@ -33,10 +33,10 @@ describe CostQuery::Cache do include OpenProject::Reporting::SpecHelper::ConfigurationHelper def all_caches - [ CostQuery::GroupBy::CustomFieldEntries, - CostQuery::GroupBy, - CostQuery::Filter::CustomFieldEntries, - CostQuery::Filter ] + [CostQuery::GroupBy::CustomFieldEntries, + CostQuery::GroupBy, + CostQuery::Filter::CustomFieldEntries, + CostQuery::Filter] end def expect_reset_on_caches @@ -76,7 +76,6 @@ describe CostQuery::Cache do end describe '.check' do - context 'with cache_classes configuration enabled' do before do mock_cache_classes_setting_with(true) diff --git a/modules/reporting/spec/models/cost_query/chaining_spec.rb b/modules/reporting/spec/models/cost_query/chaining_spec.rb index 8643fd0c86..f8f5036219 100644 --- a/modules/reporting/spec/models/cost_query/chaining_spec.rb +++ b/modules/reporting/spec/models/cost_query/chaining_spec.rb @@ -35,7 +35,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do describe '#chain' do before do - #FIXME: is there a better way to load all filter and groups? + # FIXME: is there a better way to load all filter and groups? CostQuery::Filter.all && CostQuery::GroupBy.all CostQuery.chain_initializer.clear end @@ -95,14 +95,14 @@ describe CostQuery, type: :model, reporting_query_helper: true do @query.filter :project_id @query.group_by :project_id expect(@query.filters.size).to eq(2) - expect(@query.filters.map {|f| f.class.underscore_name}).to include "project_id" + expect(@query.filters.map { |f| f.class.underscore_name }).to include "project_id" end it "should return all group_bys" do @query.filter :project_id @query.group_by :project_id expect(@query.group_bys.size).to eq(1) - expect(@query.group_bys.map {|g| g.class.underscore_name}).to include "project_id" + expect(@query.group_bys.map { |g| g.class.underscore_name }).to include "project_id" end it "should initialize the chain through a block" do @@ -111,10 +111,10 @@ describe CostQuery, type: :model, reporting_query_helper: true do CostQuery end end - TestFilter.send(:initialize_query_with) {|query| query.filter(:project_id, value: project.id)} + TestFilter.send(:initialize_query_with) { |query| query.filter(:project_id, value: project.id) } @query.build_new_chain - expect(@query.filters.map {|f| f.class.underscore_name}).to include "project_id" - expect(@query.filters.detect {|f| f.class.underscore_name == "project_id"}.values).to eq(Array(project.id)) + expect(@query.filters.map { |f| f.class.underscore_name }).to include "project_id" + expect(@query.filters.detect { |f| f.class.underscore_name == "project_id" }.values).to eq(Array(project.id)) end context "store and load" do @@ -129,9 +129,9 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it "should serialize the chain correctly" do - [:filters, :group_bys].each do |type| + %i[filters group_bys].each do |type| @query.send(type).each do |chainable| - expect(@query.serialize[type].collect{|c| c[0]}).to include chainable.class.name.demodulize + expect(@query.serialize[type].collect { |c| c[0] }).to include chainable.class.name.demodulize end end end @@ -144,7 +144,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do @query.group_bys.each_with_index do |group_by, index| # check for order @new_query.group_bys.each_with_index do |g, ix| - if g.class.name == group_by.class.name + if g.instance_of?(group_by.class) expect(ix).to eq(index) end end @@ -152,10 +152,10 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it "should keep the right filter values" do - @query.filters.each_with_index do |filter, index| + @query.filters.each_with_index do |filter, _index| # check for presence expect(@new_query.filters.any? do |f| - f.class.name == filter.class.name && (filter.respond_to?(:values) ? f.values == filter.values : true) + f.instance_of?(filter.class) && (filter.respond_to?(:values) ? f.values == filter.values : true) end).to be_truthy end end @@ -180,7 +180,8 @@ describe CostQuery, type: :model, reporting_query_helper: true do it "sets new top when prepending elements" do current = @chain 10.times do - old, current = current, Report::Chainable.new(current) + old = current + current = Report::Chainable.new(current) expect(old.top).to eq(current) expect(@chain.top).to eq(current) end @@ -215,7 +216,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it 'is able to map values' do - @a.inherited_attribute :bar, map: proc { |x| x*2 } + @a.inherited_attribute :bar, map: proc { |x| x * 2 } @a.bar 21 expect(@a.bar).to eq(42) end diff --git a/modules/reporting/spec/models/cost_query/cost_query_spec.rb b/modules/reporting/spec/models/cost_query/cost_query_spec.rb index f56f1cd13c..d90f54fc1f 100644 --- a/modules/reporting/spec/models/cost_query/cost_query_spec.rb +++ b/modules/reporting/spec/models/cost_query/cost_query_spec.rb @@ -36,7 +36,6 @@ describe User, "#destroy", type: :model do let(:user2) { FactoryBot.create(:user) } describe "WHEN the user has saved private cost queries" do - before do private_query.user.destroy end @@ -64,7 +63,7 @@ describe User, "#destroy", type: :model do user.destroy end - it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.any?{ |f| f.is_a?(filter) }).to be_falsey } + it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.any? { |f| f.is_a?(filter) }).to be_falsey } end describe "WHEN the filter has another user as it's value" do @@ -75,8 +74,12 @@ describe User, "#destroy", type: :model do user.destroy end - it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.any?{ |f| f.is_a?(filter) }).to be_truthy } - it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.detect{ |f| f.is_a?(filter) }.values).to eq([user2.id.to_s]) } + it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.any? { |f| f.is_a?(filter) }).to be_truthy } + it { + expect(CostQuery.find_by_id(public_query.id).deserialize.filters.detect do |f| + f.is_a?(filter) + end.values).to eq([user2.id.to_s]) + } end describe "WHEN the filter has the deleted user and another user as it's value" do @@ -87,8 +90,12 @@ describe User, "#destroy", type: :model do user.destroy end - it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.any?{ |f| f.is_a?(filter) }).to be_truthy } - it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.detect{ |f| f.is_a?(filter) }.values).to eq([user2.id.to_s]) } + it { expect(CostQuery.find_by_id(public_query.id).deserialize.filters.any? { |f| f.is_a?(filter) }).to be_truthy } + it { + expect(CostQuery.find_by_id(public_query.id).deserialize.filters.detect do |f| + f.is_a?(filter) + end.values).to eq([user2.id.to_s]) + } end end diff --git a/modules/reporting/spec/models/cost_query/filter_spec.rb b/modules/reporting/spec/models/cost_query/filter_spec.rb index 570ea791a7..5f5c9fea3d 100644 --- a/modules/reporting/spec/models/cost_query/filter_spec.rb +++ b/modules/reporting/spec/models/cost_query/filter_spec.rb @@ -35,8 +35,8 @@ describe CostQuery, type: :model, reporting_query_helper: true do let!(:project) { FactoryBot.create(:project_with_types) } let!(:user) { FactoryBot.create(:user, member_in_project: project) } - def create_work_package_with_entry(entry_type, work_package_params={}, entry_params = {}) - work_package_params = {project: project}.merge!(work_package_params) + def create_work_package_with_entry(entry_type, work_package_params = {}, entry_params = {}) + work_package_params = { project: project }.merge!(work_package_params) work_package = FactoryBot.create(:work_package, work_package_params) entry_params = { work_package: work_package, project: work_package_params[:project], @@ -46,7 +46,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end describe CostQuery::Filter do - def create_work_package_with_time_entry(work_package_params={}, entry_params = {}) + def create_work_package_with_time_entry(work_package_params = {}, entry_params = {}) create_work_package_with_entry(:time_entry, work_package_params, entry_params) end @@ -72,8 +72,8 @@ describe CostQuery, type: :model, reporting_query_helper: true do [CostQuery::Filter::ProjectId, 'project', "project_id", 2], [CostQuery::Filter::UserId, 'user', "user_id", 2], [CostQuery::Filter::CostTypeId, 'cost_type', "cost_type_id", 1], - [CostQuery::Filter::WorkPackageId, 'work_package', "work_package_id", 2], - [CostQuery::Filter::ActivityId, 'activity', "activity_id", 1], + [CostQuery::Filter::WorkPackageId, 'work_package', "work_package_id", 2], + [CostQuery::Filter::ActivityId, 'activity', "activity_id", 1] ].each do |filter, object_name, field, expected_count| describe filter do let!(:non_matching_entry) { FactoryBot.create(:cost_entry) } @@ -101,7 +101,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do activity: activity) end - it "should only return entries from the given #{filter.to_s}" do + it "should only return entries from the given #{filter}" do @query.filter field, value: object.id @query.result.each do |result| expect(result[field].to_s).to eq(object.id.to_s) @@ -206,15 +206,15 @@ describe CostQuery, type: :model, reporting_query_helper: true do old_user = User.current # create non-matching entry anonymous = FactoryBot.create(:anonymous) - create_work_package_with_time_entry({}, {user: anonymous}) + create_work_package_with_time_entry({}, { user: anonymous }) # create matching entry - create_work_package_with_time_entry() + create_work_package_with_time_entry @query.filter :user_id, value: user.id, operator: '=' expect(@query.result.count).to eq(1) end describe "work_package-based filters" do - def create_work_packages_and_time_entries(entry_count, work_package_params={}, entry_params={}) + def create_work_packages_and_time_entries(entry_count, work_package_params = {}, entry_params = {}) entry_count.times do create_work_package_with_entry(:cost_entry, work_package_params, entry_params) end @@ -222,7 +222,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do def create_matching_object_with_time_entries(factory, work_package_field, entry_count) object = FactoryBot.create(factory) - create_work_packages_and_time_entries(entry_count, {work_package_field => object}) + create_work_packages_and_time_entries(entry_count, { work_package_field => object }) object end @@ -303,7 +303,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end end - #filter for specific objects, which can't be null + # filter for specific objects, which can't be null [ CostQuery::Filter::UserId, CostQuery::Filter::CostTypeId, @@ -317,7 +317,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end end - #filter for specific objects, which might be null + # filter for specific objects, which might be null [ CostQuery::Filter::AssignedToId, CostQuery::Filter::CategoryId, @@ -328,7 +328,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end end - #filter for specific objects, which can only have the default operator + # filter for specific objects, which can only have the default operator [ CostQuery::Filter::WorkPackageId ].each do |filter| @@ -337,7 +337,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end end - #filter for time/date + # filter for time/date [ CostQuery::Filter::CreatedOn, CostQuery::Filter::UpdatedOn, @@ -380,7 +380,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do def update_work_package_custom_field(name, options) fld = WorkPackageCustomField.find_by(name: name) - options.each_pair {|k, v| fld.send(:"#{k}=", v) } + options.each_pair { |k, v| fld.send(:"#{k}=", v) } fld.save! clear_cache end @@ -426,14 +426,14 @@ describe CostQuery, type: :model, reporting_query_helper: true do it "includes custom fields classes in CustomFieldEntries.all" do custom_field - expect(CostQuery::Filter::CustomFieldEntries.all). - to include(filter_class_name_string(custom_field).constantize) + expect(CostQuery::Filter::CustomFieldEntries.all) + .to include(filter_class_name_string(custom_field).constantize) end it "includes custom fields classes in Filter.all" do custom_field - expect(CostQuery::Filter.all). - to include(filter_class_name_string(custom_field).constantize) + expect(CostQuery::Filter.all) + .to include(filter_class_name_string(custom_field).constantize) end def create_searchable_fields_and_values diff --git a/modules/reporting/spec/models/cost_query/group_by_spec.rb b/modules/reporting/spec/models/cost_query/group_by_spec.rb index 63e9678675..c8f0b2eb80 100644 --- a/modules/reporting/spec/models/cost_query/group_by_spec.rb +++ b/modules/reporting/spec/models/cost_query/group_by_spec.rb @@ -31,34 +31,42 @@ require File.join(File.dirname(__FILE__), '..', '..', 'support', 'custom_field_f describe CostQuery, type: :model, reporting_query_helper: true do let!(:type) { FactoryBot.create(:type) } - let!(:project1){ FactoryBot.create(:project_with_types, types: [type]) } - let!(:work_package1) { FactoryBot.create(:work_package, project: project1, type: type)} - let!(:time_entry1) { FactoryBot.create(:time_entry, work_package: work_package1, project: project1, spent_on: Date.new(2012, 1, 1)) } + let!(:project1) { FactoryBot.create(:project_with_types, types: [type]) } + let!(:work_package1) { FactoryBot.create(:work_package, project: project1, type: type) } + let!(:time_entry1) do + FactoryBot.create(:time_entry, work_package: work_package1, project: project1, spent_on: Date.new(2012, 1, 1)) + end let!(:time_entry2) do time_entry2 = time_entry1.dup time_entry2.save! time_entry2 end let!(:budget1) { FactoryBot.create(:budget, project: project1) } - let!(:cost_entry1) { FactoryBot.create(:cost_entry, work_package: work_package1, project: project1, spent_on: Date.new(2013, 2, 3)) } + let!(:cost_entry1) do + FactoryBot.create(:cost_entry, work_package: work_package1, project: project1, spent_on: Date.new(2013, 2, 3)) + end let!(:cost_entry2) do - cost_entry2 = cost_entry1.dup + cost_entry2 = cost_entry1.dup cost_entry2.save! cost_entry2 end let!(:project2) { FactoryBot.create(:project_with_types, types: [type]) } let!(:work_package2) { FactoryBot.create(:work_package, project: project2, type: type) } - let!(:time_entry3) { FactoryBot.create(:time_entry, work_package: work_package2, project: project2, spent_on: Date.new(2013, 2, 3)) } + let!(:time_entry3) do + FactoryBot.create(:time_entry, work_package: work_package2, project: project2, spent_on: Date.new(2013, 2, 3)) + end let!(:time_entry4) do time_entry4 = time_entry3.dup time_entry4.save! time_entry4 end let!(:budget2) { FactoryBot.create(:budget, project: project2) } - let!(:cost_entry3) { FactoryBot.create(:cost_entry, work_package: work_package2, project: project2, spent_on: Date.new(2012, 1, 1)) } + let!(:cost_entry3) do + FactoryBot.create(:cost_entry, work_package: work_package2, project: project2, spent_on: Date.new(2012, 1, 1)) + end let!(:cost_entry4) do - cost_entry4 = cost_entry3.dup + cost_entry4 = cost_entry3.dup cost_entry4.save! cost_entry4 end @@ -196,7 +204,6 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it "should aggregate a third group_by which owns at least 2 sub results" do - @query.group_by :tweek @query.group_by :project_id @query.group_by :user_id @@ -225,7 +232,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end describe CostQuery::GroupBy::CustomFieldEntries do - let!(:project){ FactoryBot.create(:project_with_types) } + let!(:project) { FactoryBot.create(:project_with_types) } let!(:custom_field) do FactoryBot.create(:work_package_custom_field) end @@ -280,13 +287,13 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it "includes custom fields classes in CustomFieldEntries.all" do - expect(CostQuery::GroupBy::CustomFieldEntries.all). - to include(group_by_class_name_string(custom_field).constantize) + expect(CostQuery::GroupBy::CustomFieldEntries.all) + .to include(group_by_class_name_string(custom_field).constantize) end it "includes custom fields classes in GroupBy.all" do - expect(CostQuery::GroupBy.all). - to include(group_by_class_name_string(custom_field).constantize) + expect(CostQuery::GroupBy.all) + .to include(group_by_class_name_string(custom_field).constantize) end it "is usable as filter" do diff --git a/modules/reporting/spec/models/cost_query/integration_spec.rb b/modules/reporting/spec/models/cost_query/integration_spec.rb index ccfc43ea1b..238f7aaf3d 100644 --- a/modules/reporting/spec/models/cost_query/integration_spec.rb +++ b/modules/reporting/spec/models/cost_query/integration_spec.rb @@ -31,7 +31,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe CostQuery, type: :model, reporting_query_helper: true do minimal_query - let!(:project1){ FactoryBot.create(:project_with_types) } + let!(:project1) { FactoryBot.create(:project_with_types) } let!(:work_package1) { FactoryBot.create(:work_package, project: project1) } let!(:time_entry1) { FactoryBot.create(:time_entry, work_package: work_package1, project: project1) } let!(:time_entry2) { FactoryBot.create(:time_entry, work_package: work_package1, project: project1) } @@ -52,10 +52,10 @@ describe CostQuery, type: :model, reporting_query_helper: true do sql_result = @query.result expect(sql_result.size).to eq(2) - #for each project the number of entries should be correct + # for each project the number of entries should be correct sql_count = [] sql_result.each do |sub_result| - #project should be the outmost group_by + # project should be the outmost group_by expect(sub_result.fields).to include(:project_id) sql_count.push sub_result.count end @@ -69,10 +69,10 @@ describe CostQuery, type: :model, reporting_query_helper: true do sql_result = @query.result expect(sql_result.size).to eq(2) - #for each user the number of entries should be correct + # for each user the number of entries should be correct sql_count = [] sql_result.each do |sub_result| - #project should be the outmost group_by + # project should be the outmost group_by expect(sub_result.fields).to include(:user_id) sql_count.push sub_result.count end diff --git a/modules/reporting/spec/models/cost_query/operator_spec.rb b/modules/reporting/spec/models/cost_query/operator_spec.rb index ba86155b41..d124671175 100644 --- a/modules/reporting/spec/models/cost_query/operator_spec.rb +++ b/modules/reporting/spec/models/cost_query/operator_spec.rb @@ -118,7 +118,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it "does w (this week)" do - #somehow this test doesn't work on sundays + # somehow this test doesn't work on sundays n = query('projects', 'created_at', 'w').size day_in_this_week = Time.now.at_beginning_of_week + 1.day FactoryBot.create(:project, created_at: day_in_this_week) @@ -184,7 +184,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do expect(query('projects', 'created_at', 'd" do - #assuming that all projects were created in the past + # assuming that all projects were created in the past expect(query('projects', 'created_at', '>d', Time.now).size).to eq(0) end describe 'arity' do - arities = {'t' => 0, 'w' => 0, '<>d' => 2, '>d' => 1} - arities.each do |o,a| + arities = { 't' => 0, 'w' => 0, '<>d' => 2, '>d' => 1 } + arities.each do |o, a| it("#{o} should take #{a} values") { expect(o.to_operator.arity).to eq(a) } end end diff --git a/modules/reporting/spec/models/cost_query/result_spec.rb b/modules/reporting/spec/models/cost_query/result_spec.rb index 9855daa458..49e3d91cd3 100644 --- a/modules/reporting/spec/models/cost_query/result_spec.rb +++ b/modules/reporting/spec/models/cost_query/result_spec.rb @@ -41,66 +41,66 @@ describe CostQuery, type: :model, reporting_query_helper: true do describe CostQuery::Result do def direct_results(quantity = 0) - (1..quantity).map {|i| CostQuery::Result.new real_costs:i.to_f, count:1 ,units:i.to_f} + (1..quantity).map { |i| CostQuery::Result.new real_costs: i.to_f, count: 1, units: i.to_f } end - def wrapped_result(source, quantity=1) - CostQuery::Result.new((1..quantity).map { |i| source}) + def wrapped_result(source, quantity = 1) + CostQuery::Result.new((1..quantity).map { |_i| source }) end it "should travel recursively depth-first" do - #build a tree of wrapped and direct results + # build a tree of wrapped and direct results w1 = wrapped_result((direct_results 5), 3) w2 = wrapped_result wrapped_result((direct_results 3), 2) w = wrapped_result [w1, w2] previous_depth = -1 w.recursive_each_with_level do |level, result| - #depth first, so we should get deeper into the hole, until we find a direct_result + # depth first, so we should get deeper into the hole, until we find a direct_result expect(previous_depth).to eq(level - 1) - previous_depth=level + previous_depth = level break if result.is_a? CostQuery::Result::DirectResult end end it "should travel recursively width-first" do - #build a tree of wrapped and direct results + # build a tree of wrapped and direct results w1 = wrapped_result((direct_results 5), 3) w2 = wrapped_result wrapped_result((direct_results 3), 2) w = wrapped_result [w1, w2] previous_depth = -1 - w.recursive_each_with_level 0, false do |level, result| - #width first, so we should get only deeper into the hole without ever coming up again + w.recursive_each_with_level 0, false do |level, _result| + # width first, so we should get only deeper into the hole without ever coming up again expect(previous_depth).to be <= level - previous_depth=level + previous_depth = level end end it "should travel to all results width-first" do - #build a tree of wrapped and direct results + # build a tree of wrapped and direct results w1 = wrapped_result((direct_results 5), 3) w2 = wrapped_result wrapped_result((direct_results 3), 2) w = wrapped_result [w1, w2] count = 0 - w.recursive_each_with_level 0, false do |level, result| - #width first + w.recursive_each_with_level 0, false do |_level, result| + # width first count = count + 1 if result.is_a? CostQuery::Result::DirectResult end expect(w.count).to eq(count) end it "should travel to all results width-first" do - #build a tree of wrapped and direct results + # build a tree of wrapped and direct results w1 = wrapped_result((direct_results 5), 3) w2 = wrapped_result wrapped_result((direct_results 3), 2) w = wrapped_result [w1, w2] count = 0 - w.recursive_each_with_level do |level, result| - #depth first - count = count + 1 if result.is_a? CostQuery::Result::DirectResult - end + w.recursive_each_with_level do |_level, result| + # depth first + count = count + 1 if result.is_a? CostQuery::Result::DirectResult + end expect(w.count).to eq(count) end @@ -109,11 +109,11 @@ describe CostQuery, type: :model, reporting_query_helper: true do end it "should compute units correctly" do - expect(@query.result.units).to eq(Entry.all.map { |e| e.units}.sum) + expect(@query.result.units).to eq(Entry.all.map { |e| e.units }.sum) end it "should compute real_costs correctly" do - expect(@query.result.real_costs).to eq(Entry.all.map { |e| e.overridden_costs || e.costs}.sum) + expect(@query.result.real_costs).to eq(Entry.all.map { |e| e.overridden_costs || e.costs }.sum) end it "should compute count for DirectResults" do @@ -122,8 +122,8 @@ describe CostQuery, type: :model, reporting_query_helper: true do it "should compute units for DirectResults" do id_sorted = @query.result.values.sort_by { |r| r[:id] } - te_result = id_sorted.select { |r| r[:type]==TimeEntry.to_s }.first - ce_result = id_sorted.select { |r| r[:type]==CostEntry.to_s }.first + te_result = id_sorted.select { |r| r[:type] == TimeEntry.to_s }.first + ce_result = id_sorted.select { |r| r[:type] == CostEntry.to_s }.first expect(te_result.units.to_s).to eq("1.0") expect(ce_result.units.to_s).to eq("1.0") end @@ -131,7 +131,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do it "should compute real_costs for DirectResults" do id_sorted = @query.result.values.sort_by { |r| r[:id] } [CostEntry].each do |type| - result = id_sorted.select { |r| r[:type]==type.to_s }.first + result = id_sorted.select { |r| r[:type] == type.to_s }.first first = type.all.first expect(result.real_costs).to eq(first.overridden_costs || first.costs) end @@ -151,6 +151,5 @@ describe CostQuery, type: :model, reporting_query_helper: true do @query.column :project_id expect(@query.result.first.first.type).to eq(:direct) end - end end diff --git a/modules/reporting/spec/models/cost_query/validation_spec.rb b/modules/reporting/spec/models/cost_query/validation_spec.rb index 68057fb7ca..dacf699de9 100644 --- a/modules/reporting/spec/models/cost_query/validation_spec.rb +++ b/modules/reporting/spec/models/cost_query/validation_spec.rb @@ -45,7 +45,7 @@ describe "CostQuery::Validation", type: :model do it "should allow for multiple validations" do obj = CostQuery::SomeBase.new - obj.register_validations([:integers, :dates]) + obj.register_validations(%i[integers dates]) expect(obj.validations.size).to eq(2) end @@ -59,14 +59,14 @@ describe "CostQuery::Validation", type: :model do it "should have no errors set when we try to validate something valid" do obj = CostQuery::SomeBase.new obj.register_validation(:integers) - expect(obj.validate(1,2,3,4)).to be_truthy + expect(obj.validate(1, 2, 3, 4)).to be_truthy expect(obj.errors[:int].size).to eq(0) end it "should validate integers correctly" do obj = CostQuery::SomeBase.new obj.register_validation(:integers) - expect(obj.validate(1,2,3,4)).to be_truthy + expect(obj.validate(1, 2, 3, 4)).to be_truthy expect(obj.errors[:int].size).to eq(0) expect(obj.validate("I ain't gonna work on Maggies Farm no more")).to be_falsey expect(obj.errors[:int].size).to eq(1) diff --git a/modules/reporting/spec/models/cost_query/walker_spec.rb b/modules/reporting/spec/models/cost_query/walker_spec.rb index 3e9ff8bec8..48e8a438b0 100644 --- a/modules/reporting/spec/models/cost_query/walker_spec.rb +++ b/modules/reporting/spec/models/cost_query/walker_spec.rb @@ -46,7 +46,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do @query.row :user_id result = @query.transformer.row_first.values.first - [:user_id, :project_id, :tweek].each do |field| + %i[user_id project_id tweek].each do |field| expect(result.fields).to include(field) result = result.values.first end @@ -59,7 +59,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do @query.row :user_id result = @query.transformer.column_first.values.first - [:tweek, :work_package_id].each do |field| + %i[tweek work_package_id].each do |field| expect(result.fields).to include(field) result = result.values.first end diff --git a/modules/reporting/spec/support/plugin_spec_helper.rb b/modules/reporting/spec/support/plugin_spec_helper.rb index 6b22ab1090..bfea854b1c 100644 --- a/modules/reporting/spec/support/plugin_spec_helper.rb +++ b/modules/reporting/spec/support/plugin_spec_helper.rb @@ -32,8 +32,8 @@ module OpenProject::Reporting role = FactoryBot.create(:role, permissions: permissions) FactoryBot.create(:member, project: project, - principal: user, - roles: [role]) + principal: user, + roles: [role]) end end end diff --git a/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/row_cell.rb b/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/row_cell.rb index a35d0deddb..98320a7a20 100644 --- a/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/row_cell.rb +++ b/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/row_cell.rb @@ -49,10 +49,10 @@ module ::TwoFactorAuthentication def make_default_link password_confirmation_form_for( - device, - url: { controller: table.target_controller, action: :make_default, device_id: device.id }, - method: :post, - html: { id: 'two_factor_make_default_form', class: 'form--inline' } + device, + url: { controller: table.target_controller, action: :make_default, device_id: device.id }, + method: :post, + html: { id: 'two_factor_make_default_form', class: 'form--inline' } ) do |f| f.submit I18n.t(:button_make_default), class: 'button--link two-factor--mark-default-button' @@ -86,7 +86,7 @@ module ::TwoFactorAuthentication device.default && table.enforced? end - def column_css_class(column) + def column_css_class(_column) if device.default 'mobile-otp--device-default' end diff --git a/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/table_cell.rb b/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/table_cell.rb index 327989a481..07a2a42410 100644 --- a/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/table_cell.rb +++ b/modules/two_factor_authentication/app/cells/two_factor_authentication/devices/table_cell.rb @@ -5,7 +5,7 @@ module ::TwoFactorAuthentication columns :device_type, :default, :confirmed def initial_sort - [:login, :asc] + %i[login asc] end def self_table? @@ -33,7 +33,7 @@ module ::TwoFactorAuthentication link_to({ controller: target_controller, action: :new }, class: 'budget-add-row wp-inline-create--add-link', title: I18n.t('two_factor_authentication.devices.add_new')) do - op_icon('icon icon-add') + op_icon('icon icon-add') end end end @@ -56,9 +56,9 @@ module ::TwoFactorAuthentication def headers [ - ['device_type', caption: I18n.t('two_factor_authentication.label_device_type')], - ['default', caption: I18n.t(:label_default)], - ['confirmed', caption: I18n.t(:label_confirmed)], + ['device_type', { caption: I18n.t('two_factor_authentication.label_device_type') }], + ['default', { caption: I18n.t(:label_default) }], + ['confirmed', { caption: I18n.t(:label_confirmed) }] ] end end diff --git a/modules/two_factor_authentication/app/controllers/concerns/two_factor_authentication/backup_codes.rb b/modules/two_factor_authentication/app/controllers/concerns/two_factor_authentication/backup_codes.rb index b8af6698ae..b13833e99d 100644 --- a/modules/two_factor_authentication/app/controllers/concerns/two_factor_authentication/backup_codes.rb +++ b/modules/two_factor_authentication/app/controllers/concerns/two_factor_authentication/backup_codes.rb @@ -23,4 +23,4 @@ module ::TwoFactorAuthentication end end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb index af5015b821..b7c1beed9b 100644 --- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb +++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb @@ -66,7 +66,6 @@ module ::TwoFactorAuthentication render_login_otp(service) end - ## # Create a token service for the current user # with an optional override to use a non-default channel @@ -81,8 +80,6 @@ module ::TwoFactorAuthentication use_device = if session[:two_factor_authentication_device_id] user.otp_devices.find(session[:two_factor_authentication_device_id]) - else - nil end otp_service(user, use_device: use_device) rescue ActiveRecord::RecordNotFound @@ -97,8 +94,6 @@ module ::TwoFactorAuthentication device = if params[:use_device].present? @authenticated_user.otp_devices.find(params[:use_device]) - else - nil end otp_service(@authenticated_user, use_channel: channel, use_device: device) @@ -134,9 +129,9 @@ module ::TwoFactorAuthentication @active_devices = @user.otp_devices.get_active if params["back_url"] - render :action => 'request_otp', :back_url => params["back_url"] + render action: 'request_otp', back_url: params["back_url"] else - render :action => 'request_otp' + render action: 'request_otp' end end @@ -160,7 +155,7 @@ module ::TwoFactorAuthentication unless request.post? head(:method_not_allowed) - return false + false end end @@ -190,7 +185,7 @@ module ::TwoFactorAuthentication def ensure_valid_configuration if manager.invalid_configuration? render_500 message: I18n.t('two_factor_authentication.error_is_enforced_not_active') - return false + false end end diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb index c41be624b7..0d5c64a3c2 100644 --- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb +++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/base_controller.rb @@ -1,13 +1,12 @@ module ::TwoFactorAuthentication class BaseController < ApplicationController - # Ensure 2FA authentication is enabled before_action :ensure_enabled_2fa # Locate the user we're editing prepend_before_action :find_user - before_action :find_device, only: [:confirm, :make_default, :destroy] + before_action :find_device, only: %i[confirm make_default destroy] layout 'no_menu' @@ -61,6 +60,7 @@ module ::TwoFactorAuthentication request_device_confirmation_token elsif request.post? return unless ensure_token_parameter + validate_device_token else head 405 @@ -73,10 +73,10 @@ module ::TwoFactorAuthentication # Request (if needed) the token for entering def request_device_confirmation_token request_token_for_device( - @device, - confirm_path: url_for(action: :confirm, device_id: @device.id), - title: I18n.t('two_factor_authentication.devices.confirm_device'), - message: I18n.t('two_factor_authentication.devices.text_confirm_to_complete_html', identifier: @device.identifier) + @device, + confirm_path: url_for(action: :confirm, device_id: @device.id), + title: I18n.t('two_factor_authentication.devices.confirm_device'), + message: I18n.t('two_factor_authentication.devices.text_confirm_to_complete_html', identifier: @device.identifier) ) end diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb index 1a2271bfb2..7d02561729 100644 --- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb +++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb @@ -30,7 +30,7 @@ module ::TwoFactorAuthentication Rails.logger.info "User ##{target_user.id} forced to register a new (unconfirmed) device #{@device_type}." redirect_to action: :confirm, device_id: @device.id else - Rails.logger.warn {"User ##{target_user.id} forced to register failed for #{@device_type}."} + Rails.logger.warn { "User ##{target_user.id} forced to register failed for #{@device_type}." } render 'two_factor_authentication/two_factor_devices/new' end end @@ -61,16 +61,17 @@ module ::TwoFactorAuthentication # Ensure the authentication stage from the core provided the authenticated user def require_authenticated_user raise ArgumentError, 'Missing param' unless session[:authenticated_user_force_2fa] + @authenticated_user = User.find(session[:authenticated_user_id]) - return true + true rescue ActiveRecord::RecordNotFound Rails.logger.error "Failed to find authenticated_user for 2FA authentication." redirect_to registration_failure_path - return false + false rescue ArgumentError Rails.logger.error "User tried to access forced registration without registration session param set." redirect_to registration_failure_path - return false + false end end end diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb index 9029c1ba8c..75cd358a86 100644 --- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb +++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb @@ -6,7 +6,7 @@ module ::TwoFactorAuthentication before_action :set_user_variables - before_action :find_device, except: [:new, :index, :register] + before_action :find_device, except: %i[new index register] # Remmeber token functionality include ::TwoFactorAuthentication::RememberToken @@ -14,7 +14,7 @@ module ::TwoFactorAuthentication # Password confirmation helpers and actions include PasswordConfirmation before_action :check_password_confirmation, - only: [:make_default, :destroy] + only: %i[make_default destroy] # Delete remember token on destroy before_action :clear_remember_token!, only: [:destroy] @@ -39,7 +39,7 @@ module ::TwoFactorAuthentication Rails.logger.info "User ##{current_user.id} registered a new (unconfirmed) device #{@device_type}." redirect_to action: :confirm, device_id: @device.id else - Rails.logger.warn {"User ##{current_user.id} failed to register a device #{@device_type}."} + Rails.logger.warn { "User ##{current_user.id} failed to register a device #{@device_type}." } render 'two_factor_authentication/two_factor_devices/new' end end @@ -51,6 +51,7 @@ module ::TwoFactorAuthentication request_device_confirmation_token else return unless ensure_token_parameter + validate_device_token end end @@ -61,10 +62,10 @@ module ::TwoFactorAuthentication # Request (if needed) the token for entering def request_device_confirmation_token request_token_for_device( - @device, - confirm_path: url_for(action: :confirm, device_id: @device.id), - title: I18n.t('two_factor_authentication.devices.confirm_device'), - message: I18n.t('two_factor_authentication.devices.text_confirm_to_complete_html', identifier: @device.identifier) + @device, + confirm_path: url_for(action: :confirm, device_id: @device.id), + title: I18n.t('two_factor_authentication.devices.confirm_device'), + message: I18n.t('two_factor_authentication.devices.text_confirm_to_complete_html', identifier: @device.identifier) ) end diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb index 32c7ae8246..a12ad1e465 100644 --- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb +++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/two_factor_settings_controller.rb @@ -1,6 +1,5 @@ module ::TwoFactorAuthentication class TwoFactorSettingsController < ApplicationController - before_action :require_admin before_action :check_enabled before_action :check_ee diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/users/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/users/two_factor_devices_controller.rb index 177d366ce0..c9838af266 100644 --- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/users/two_factor_devices_controller.rb +++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/users/two_factor_devices_controller.rb @@ -62,6 +62,7 @@ module ::TwoFactorAuthentication request_device_confirmation_token else return unless ensure_token_parameter + validate_device_token end end @@ -108,8 +109,8 @@ module ::TwoFactorAuthentication # Overrides the base controller to active the device # without prior confirmation. permitted_device_params.merge( - user: @user, - active: true + user: @user, + active: true ) end diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication.rb b/modules/two_factor_authentication/app/models/two_factor_authentication.rb index bff5348ef1..ece37388ac 100644 --- a/modules/two_factor_authentication/app/models/two_factor_authentication.rb +++ b/modules/two_factor_authentication/app/models/two_factor_authentication.rb @@ -2,4 +2,4 @@ module TwoFactorAuthentication def self.table_name_prefix 'two_factor_authentication_' end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/backup_code.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/backup_code.rb index 3a0f305276..ea8d46773e 100644 --- a/modules/two_factor_authentication/app/models/two_factor_authentication/backup_code.rb +++ b/modules/two_factor_authentication/app/models/two_factor_authentication/backup_code.rb @@ -3,7 +3,6 @@ require_dependency 'token/hashed_token' module TwoFactorAuthentication class BackupCode < ::Token::HashedToken class << self - def regenerate!(user) backup_codes = [] @@ -33,4 +32,4 @@ module TwoFactorAuthentication false end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb index 794c026381..2c2e56290f 100644 --- a/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb +++ b/modules/two_factor_authentication/app/models/two_factor_authentication/device.rb @@ -37,11 +37,7 @@ module TwoFactorAuthentication def identifier value = read_attribute(:identifier) - if value - value - else - default_identifier - end + value || default_identifier end def redacted_identifier @@ -69,7 +65,7 @@ module TwoFactorAuthentication Device.transaction do Device.where(user_id: user_id).update_all(default: false) - self.update_column(:default, true) + update_column(:default, true) return true end end @@ -91,7 +87,7 @@ module TwoFactorAuthentication def self.available_channels_in_strategy strategy_class = manager.get_strategy(device_type) - strategy_class.supported_channels & self.supported_channels + strategy_class.supported_channels & supported_channels end private diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/device/sms.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/device/sms.rb index c01a60a6a9..1794de03dc 100644 --- a/modules/two_factor_authentication/app/models/two_factor_authentication/device/sms.rb +++ b/modules/two_factor_authentication/app/models/two_factor_authentication/device/sms.rb @@ -65,4 +65,4 @@ module TwoFactorAuthentication super(number.try(:strip)) end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/device/totp.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/device/totp.rb index 047545492d..67259a948a 100644 --- a/modules/two_factor_authentication/app/models/two_factor_authentication/device/totp.rb +++ b/modules/two_factor_authentication/app/models/two_factor_authentication/device/totp.rb @@ -65,4 +65,4 @@ module TwoFactorAuthentication @totp ||= ::ROTP::TOTP.new otp_secret, issuer: (Setting.app_title.presence || 'OpenProject') end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb b/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb index b93f9aab86..07f54a74bc 100644 --- a/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb +++ b/modules/two_factor_authentication/app/models/two_factor_authentication/login_token.rb @@ -9,14 +9,11 @@ module TwoFactorAuthentication 15.minutes end - private - def self.generate_token_value chars = ("0".."9").to_a password = '' - 6.times { |i| password << chars[rand(chars.size-1)] } + 6.times { |_i| password << chars[rand(chars.size - 1)] } password end - end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb b/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb index 57c3fecb6e..516a02415b 100644 --- a/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb +++ b/modules/two_factor_authentication/app/services/two_factor_authentication/token_service.rb @@ -22,7 +22,7 @@ module TwoFactorAuthentication return true if manager.enforced? # Otherwise, only enabled if active and a device is present for the user - return manager.enabled? && device.present? + manager.enabled? && device.present? end ## @@ -30,7 +30,8 @@ module TwoFactorAuthentication # device during the login flow. def needs_registration? return false unless manager.enforced? - return device.nil? + + device.nil? end ## @@ -45,7 +46,7 @@ module TwoFactorAuthentication strategy.transmit ServiceResult.new(success: true, result: strategy.transmit_success_message) - rescue => e + rescue StandardError => e Rails.logger.error "[2FA plugin] Error during token request to user##{user.id}: #{e}" result = ServiceResult.new(success: false) @@ -65,7 +66,7 @@ module TwoFactorAuthentication result = strategy.verify input_token ServiceResult.new(success: result) - rescue => e + rescue StandardError => e Rails.logger.error "[2FA plugin] Error during token validation for user##{user.id}: #{e}" result = ServiceResult.new(success: false) @@ -100,4 +101,4 @@ module TwoFactorAuthentication ::OpenProject::TwoFactorAuthentication::TokenStrategyManager end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb b/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb index b2a7ab4462..568ec43936 100644 --- a/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb +++ b/modules/two_factor_authentication/app/services/two_factor_authentication/use_backup_code_service.rb @@ -14,8 +14,9 @@ module TwoFactorAuthentication token = user.otp_backup_codes.find_by_plaintext_value(code) raise I18n.t('two_factor_authentication.error_invalid_backup_code') if token.nil? + use_valid_token! token - rescue => e + rescue StandardError => e Rails.logger.error "[2FA plugin] Error during backup code validation for user##{user.id}: #{e}" result = ServiceResult.new(success: false) @@ -33,4 +34,4 @@ module TwoFactorAuthentication ServiceResult.new(success: true, result: token) end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/config/routes.rb b/modules/two_factor_authentication/config/routes.rb index b007933eda..244e474e04 100644 --- a/modules/two_factor_authentication/config/routes.rb +++ b/modules/two_factor_authentication/config/routes.rb @@ -1,5 +1,4 @@ OpenProject::Application::routes.draw do - namespace 'two_factor_authentication' do get :request, to: 'authentication#request_otp' post :confirm, to: 'authentication#confirm_otp' @@ -16,7 +15,7 @@ OpenProject::Application::routes.draw do controller: 'two_factor_authentication/forced_registration/two_factor_devices' do get :new, action: :new, as: 'new_forced_2fa_device' post :register, action: :register, as: 'register_forced_2fa_device' - match '/:device_id/confirm', action: :confirm, via: [:get, :post], as: 'confirm_forced_2fa_device' + match '/:device_id/confirm', action: :confirm, via: %i[get post], as: 'confirm_forced_2fa_device' end end @@ -26,8 +25,7 @@ OpenProject::Application::routes.draw do param: :device_id, controller: 'two_factor_authentication/users/two_factor_devices', as: 'user_2fa_devices', - only: [:new, :create, :destroy] do - + only: %i[new create destroy] do # Register new device ( 'create' ) post :register, on: :collection @@ -40,12 +38,11 @@ OpenProject::Application::routes.draw do end end - scope 'my' do resource :backup_codes, controller: 'two_factor_authentication/my/backup_codes', as: 'my_2fa_backup_codes', - only: [:show, :create] + only: %i[show create] resource :remember_cookie, controller: 'two_factor_authentication/my/remember_cookie', @@ -56,7 +53,7 @@ OpenProject::Application::routes.draw do controller: 'two_factor_authentication/my/two_factor_devices', param: :device_id, as: 'my_2fa_devices', - only: [:index, :new, :destroy] do + only: %i[index new destroy] do # Register new device ( 'create' ) post :register, on: :collection diff --git a/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb b/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb index 72836b1ccc..1f9e039257 100644 --- a/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb +++ b/modules/two_factor_authentication/db/migrate/20120214103300_aggregated_mobile_otp_migrations.rb @@ -20,7 +20,8 @@ class AggregatedMobileOtpMigrations < ActiveRecord::Migration[5.0] add_column :users, :unverified_phone, :string User.reset_column_information end - Migration::MigrationUtils::SettingRenamer.rename("plugin_redmine_two_factor_authentication_authentication","plugin_openproject_two_factor_authentication") + Migration::MigrationUtils::SettingRenamer.rename("plugin_redmine_two_factor_authentication_authentication", + "plugin_openproject_two_factor_authentication") end def down diff --git a/modules/two_factor_authentication/db/migrate/20130214130336_add_default_otp_channel_to_user.rb b/modules/two_factor_authentication/db/migrate/20130214130336_add_default_otp_channel_to_user.rb index 97a32278cf..238c1fc944 100644 --- a/modules/two_factor_authentication/db/migrate/20130214130336_add_default_otp_channel_to_user.rb +++ b/modules/two_factor_authentication/db/migrate/20130214130336_add_default_otp_channel_to_user.rb @@ -1,6 +1,6 @@ class AddDefaultOtpChannelToUser < ActiveRecord::Migration[5.0] def self.up - add_column :users, :default_otp_channel, :string, :default => 'text' + add_column :users, :default_otp_channel, :string, default: 'text' end def self.down diff --git a/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb b/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb index 9538ef717a..f14c2c8145 100644 --- a/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb +++ b/modules/two_factor_authentication/db/migrate/20171023190036_model_reorganization.rb @@ -2,7 +2,6 @@ class ModelReorganization < ActiveRecord::Migration[5.0] def self.up # Add devices table create_table "two_factor_authentication_devices" do |t| - t.string "type" # Whether this is the default strategy @@ -19,7 +18,7 @@ class ModelReorganization < ActiveRecord::Migration[5.0] t.string "phone_number", null: true # User-given identifier for this device - t.string "identifier", null: false + t.string "identifier", null: false # Default rails timestamps t.timestamps @@ -69,7 +68,6 @@ class ModelReorganization < ActiveRecord::Migration[5.0] .where(active: true) .includes(:user) .find_each do |device| - device.user.update_columns(unverified_phone: device.phone_number, default_otp_channel: device.channel) end end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb index d6823ba0f3..cdde68dd62 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/engine.rb @@ -54,7 +54,9 @@ module OpenProject::TwoFactorAuthentication OpenProject::Authentication::Stage.register(:two_factor_authentication, nil, run_after_activation: true, - active: -> { ::OpenProject::TwoFactorAuthentication::TokenStrategyManager.enabled? }) do + active: -> { + ::OpenProject::TwoFactorAuthentication::TokenStrategyManager.enabled? + }) do two_factor_authentication_request_path end end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb index 0aae93deb0..51e0dbb0cc 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/base.rb @@ -89,4 +89,4 @@ module OpenProject::TwoFactorAuthentication end end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/developer.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/developer.rb index 4c9892f36b..7d7e87b47d 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/developer.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/developer.rb @@ -1,7 +1,6 @@ module OpenProject::TwoFactorAuthentication module TokenStrategy class Developer < Base - def self.validate! if Rails.env.production? raise "You're trying to use the developer strategy in production. Don't!" @@ -13,7 +12,7 @@ module OpenProject::TwoFactorAuthentication end def self.supported_channels - [:sms, :voice] + %i[sms voice] end def self.mobile_token? @@ -35,4 +34,4 @@ module OpenProject::TwoFactorAuthentication end end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb index 2481371d75..8d615cbfd3 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/message_bird.rb @@ -7,6 +7,7 @@ module OpenProject::TwoFactorAuthentication if configuration_params.nil? raise ArgumentError, 'Missing configuration hash' end + validate_params configuration_params end @@ -35,7 +36,7 @@ module OpenProject::TwoFactorAuthentication validity: 720 raise "Failed to deliver SMS" if response.recipients['totalDeliveryFailedCount'] > 0 - rescue => e + rescue StandardError => e Rails.logger.error("[2FA] MessageBird SMS delivery failed for user #{user.login}. Error: #{e} #{e.message}") raise I18n.t('two_factor_authentication.message_bird.sms_delivery_failed') end @@ -56,7 +57,7 @@ module OpenProject::TwoFactorAuthentication language: params[:language] raise "Failed to initiate voice message" if response.recipients['totalDeliveryFailedCount'] > 0 - rescue => e + rescue StandardError => e Rails.logger.error("[2FA] MessageBird VOICE delivery failed for user #{user.login}. Error: #{e} #{e.message}") raise I18n.t('two_factor_authentication.message_bird.voice_delivery_failed') end @@ -138,7 +139,6 @@ module OpenProject::TwoFactorAuthentication :"en-us" end - ## # Checks whether the locale has a non-fallback def has_localized_text?(locale_key) @@ -172,7 +172,7 @@ module OpenProject::TwoFactorAuthentication # Output format: xxyyyyyyyyyy def build_recipients(params) phone = device.phone_number - phone.gsub!(/[\+\s]/, '') + phone.gsub!(/[+\s]/, '') params[:recipients] = phone end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb index deabc68b72..8de7133003 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/restdt.rb @@ -7,6 +7,7 @@ module OpenProject::TwoFactorAuthentication if configuration_params.nil? raise ArgumentError, 'Missing configuration hash' end + validate_params configuration_params end @@ -19,7 +20,7 @@ module OpenProject::TwoFactorAuthentication end def self.supported_channels - [:sms, :voice] + %i[sms voice] end private @@ -37,7 +38,6 @@ module OpenProject::TwoFactorAuthentication } end - def send_sms Rails.logger.info { "[2FA] REST DT delivery sending SMS request for #{user.login}" } submit(build_user_params(onlycall: '0')) @@ -69,7 +69,7 @@ module OpenProject::TwoFactorAuthentication # Stored format: +xx yyy yyy yyyy (optional whitespacing) def build_user_phone phone = device.phone_number - phone.gsub!(/[\+]/, '00') + phone.gsub!(/\+/, '00') phone.gsub!(/\s/, '') phone @@ -92,8 +92,10 @@ module OpenProject::TwoFactorAuthentication return end - Rails.logger.error { "[2FA] REST DT delivery failed for user #{user.login} " \ - "(Error #{response.body})" } + Rails.logger.error do + "[2FA] REST DT delivery failed for user #{user.login} " \ + "(Error #{response.body})" + end raise I18n.t('two_factor_authentication.restdt.delivery_failed_with_code', code: code) end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/sns.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/sns.rb index 52604fd8c6..96a01a360c 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/sns.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/sns.rb @@ -55,7 +55,7 @@ module OpenProject::TwoFactorAuthentication end def submit - aws_params = self.configuration_params.slice :region, :access_key_id, :secret_access_key + aws_params = configuration_params.slice :region, :access_key_id, :secret_access_key sns = ::Aws::SNS::Client.new aws_params sns.set_sms_attributes( @@ -65,7 +65,7 @@ module OpenProject::TwoFactorAuthentication 'DefaultSMSType' => 'Transactional', # Set sender ID name (may not be supported in all countries) - 'DefaultSenderID' => self.configuration_params.fetch(:sender_id, 'OpenProject') + 'DefaultSenderID' => configuration_params.fetch(:sender_id, 'OpenProject') } ) @@ -80,9 +80,11 @@ module OpenProject::TwoFactorAuthentication end raise result - rescue => e - Rails.logger.error { "[2FA] SNS delivery failed for user #{user.login} " \ - "(Error: #{e})" } + rescue StandardError => e + Rails.logger.error do + "[2FA] SNS delivery failed for user #{user.login} " \ + "(Error: #{e})" + end raise I18n.t('two_factor_authentication.sns.delivery_failed') end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/totp.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/totp.rb index b6792cde77..4221c8cd5a 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/totp.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy/totp.rb @@ -1,9 +1,8 @@ require 'rotp' module OpenProject::TwoFactorAuthentication -module TokenStrategy + module TokenStrategy class Totp < Base - def verify(input_token) result = device.verify_token input_token @@ -41,4 +40,4 @@ module TokenStrategy end end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb index bf3034a031..7217c3f9a9 100644 --- a/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb +++ b/modules/two_factor_authentication/lib/open_project/two_factor_authentication/token_strategy_manager.rb @@ -8,7 +8,7 @@ module OpenProject::TwoFactorAuthentication active_strategies.detect { |s| s.supported_channels.include? channel.to_sym } end - #validate_configuration + # validate_configuration def validate_configuration! validate_active_strategies! end @@ -134,7 +134,7 @@ module OpenProject::TwoFactorAuthentication totp: I18n.t("activerecord.models.two_factor_authentication/device/totp"), sns: I18n.t("activerecord.models.two_factor_authentication/device/sms"), restdt: I18n.t("activerecord.models.two_factor_authentication/device/restdt"), - message_bird: I18n.t("activerecord.models.two_factor_authentication/device/sms"), + message_bird: I18n.t("activerecord.models.two_factor_authentication/device/sms") } end diff --git a/modules/two_factor_authentication/openproject-two_factor_authentication.gemspec b/modules/two_factor_authentication/openproject-two_factor_authentication.gemspec index e57f165f96..a7c5ddf207 100644 --- a/modules/two_factor_authentication/openproject-two_factor_authentication.gemspec +++ b/modules/two_factor_authentication/openproject-two_factor_authentication.gemspec @@ -13,8 +13,8 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "CHANGELOG.md", "README.rdoc"] s.test_files = Dir["spec/**/*"] - s.add_dependency 'rotp', '~> 6.1' s.add_dependency 'messagebird-rest', '~> 1.4.2' + s.add_dependency 'rotp', '~> 6.1' s.add_dependency 'aws-sdk-sns', '~> 1.37.0' end diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_shared_examples.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_shared_examples.rb index 024a403c34..07a369b6b6 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_shared_examples.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_shared_examples.rb @@ -18,7 +18,8 @@ end shared_examples '2FA forced registry' do it "should not log in user" do - expect(User.current).not_to eq(user) end + expect(User.current).not_to eq(user) + end it "should set authenticated user" do expect(session[:authenticated_user_force_2fa]).to be_truthy @@ -106,7 +107,6 @@ shared_examples '2FA TOTP request success' do # Can post to login_otp with pending and token describe 'follow-up post of a login token' do - before do # Assume the user is pending session[:authenticated_user_id] = user.id @@ -153,7 +153,6 @@ shared_examples '2FA SMS request success' do post :confirm_otp, params: { otp: valid_token.value } end - context 'when not expired' do let(:expired) { false } it_behaves_like 'immediate success login' diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb index 406c39a167..dff1ed2d48 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/authentication_controller_spec.rb @@ -22,7 +22,8 @@ describe ::TwoFactorAuthentication::AuthenticationController, with_2fa_ee: true, it_behaves_like 'immediate success login' end - describe 'with no active strategy, but 2FA enforced as configuration', with_config: { '2fa' => { active_strategies: [], enforced: true } } do + describe 'with no active strategy, but 2FA enforced as configuration', + with_config: { '2fa' => { active_strategies: [], enforced: true } } do before do allow(OpenProject::TwoFactorAuthentication::TokenStrategyManager) .to receive(:add_default_strategy?) @@ -81,7 +82,7 @@ describe ::TwoFactorAuthentication::AuthenticationController, with_2fa_ee: true, end end - describe 'with two active strategy', with_config: { '2fa' => { active_strategies: [:developer, :totp] } } do + describe 'with two active strategy', with_config: { '2fa' => { active_strategies: %i[developer totp] } } do context 'with a totp device' do let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, channel: :totp } it_behaves_like '2FA TOTP request success' diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb index cca6a58d5b..2b7f83fc7c 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller_spec.rb @@ -134,7 +134,7 @@ describe ::TwoFactorAuthentication::ForcedRegistration::TwoFactorDevicesControll describe 'and registered totp device' do let(:active_strategies) { [:totp] } - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false } it 'renders the confirmation page' do get :confirm, params: { device_id: device.id } @@ -145,7 +145,7 @@ describe ::TwoFactorAuthentication::ForcedRegistration::TwoFactorDevicesControll end describe 'with registered device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: false, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: false, default: false } it 'renders the confirmation page' do get :confirm, params: { device_id: device.id } @@ -173,7 +173,7 @@ describe ::TwoFactorAuthentication::ForcedRegistration::TwoFactorDevicesControll describe 'and registered totp device' do let(:active_strategies) { [:totp] } - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false } it 'renders a 400 on missing token' do post :confirm, params: { device_id: device.id } diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb index 4c6d15e227..9713512e30 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/my/two_factor_devices_controller_spec.rb @@ -115,7 +115,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: describe 'and registered totp device' do let(:active_strategies) { [:totp] } - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false } it 'renders the confirmation page' do get :confirm, params: { device_id: device.id } @@ -126,7 +126,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: end describe 'with registered device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: false, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: false, default: false } it 'renders the confirmation page' do get :confirm, params: { device_id: device.id } @@ -154,7 +154,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: describe 'and registered totp device' do let(:active_strategies) { [:totp] } - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: false, default: false } it 'renders a 400 on missing token' do post :confirm, params: { device_id: device.id } @@ -187,7 +187,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: end context 'with another default device present' do - let!(:default_device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true} + let!(:default_device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } it 'activates the device when entered correctly' do allow_any_instance_of(::TwoFactorAuthentication::TokenService) @@ -220,7 +220,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: end context 'with existing non-default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: false } it 'deletes it' do delete :destroy, params: { device_id: device.id } @@ -230,7 +230,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: end context 'with existing default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } it 'deletes it' do delete :destroy, params: { device_id: device.id } @@ -240,7 +240,7 @@ describe ::TwoFactorAuthentication::My::TwoFactorDevicesController, with_2fa_ee: end context 'with existing default device AND enforced' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } let(:config) { { enforced: true } } it 'cannot be deleted' do diff --git a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb index 8c2b2482ba..cca615bf1f 100644 --- a/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb +++ b/modules/two_factor_authentication/spec/controllers/two_factor_authentication/users/two_factor_devices_controller_spec.rb @@ -123,7 +123,7 @@ describe ::TwoFactorAuthentication::Users::TwoFactorDevicesController, with_2fa_ end context 'with existing non-default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: false } it 'deletes it' do delete :destroy, params: { id: user.id, device_id: device.id } @@ -133,7 +133,7 @@ describe ::TwoFactorAuthentication::Users::TwoFactorDevicesController, with_2fa_ end context 'with existing default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } it 'deletes it' do delete :destroy, params: { id: user.id, device_id: device.id } @@ -143,7 +143,7 @@ describe ::TwoFactorAuthentication::Users::TwoFactorDevicesController, with_2fa_ end context 'with existing default device AND enforced' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } let(:config) { { enforced: true } } it 'cannot be deleted' do diff --git a/modules/two_factor_authentication/spec/features/account_activation_spec.rb b/modules/two_factor_authentication/spec/features/account_activation_spec.rb index 9c723ada07..1c0e328092 100644 --- a/modules/two_factor_authentication/spec/features/account_activation_spec.rb +++ b/modules/two_factor_authentication/spec/features/account_activation_spec.rb @@ -5,14 +5,14 @@ describe 'activating an invited account', with_2fa_ee: true, type: :feature, js: true, - with_config: {:'2fa' => {active_strategies: [:developer]}} do - let(:user) { + with_config: { '2fa': { active_strategies: [:developer] } } do + let(:user) do user = FactoryBot.build :user, first_login: true UserInvitation.invite_user! user user - } - let(:token) {Token::Invitation.find_by(user_id: user.id)} + end + let(:token) { Token::Invitation.find_by(user_id: user.id) } def activate! visit url_for(controller: :account, @@ -38,7 +38,7 @@ describe 'activating an invited account', end context 'when not enforced, but device present' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, default: true } it 'requests a OTP' do sms_token = nil @@ -72,7 +72,7 @@ describe 'activating an invited account', end end - context 'when enforced', with_config: {:'2fa' => {active_strategies: [:developer], enforced: true}} do + context 'when enforced', with_config: { '2fa': { active_strategies: [:developer], enforced: true } } do before do activate! end diff --git a/modules/two_factor_authentication/spec/features/admin_edit_two_factor_devices_spec.rb b/modules/two_factor_authentication/spec/features/admin_edit_two_factor_devices_spec.rb index d5f0d23918..75d8384938 100644 --- a/modules/two_factor_authentication/spec/features/admin_edit_two_factor_devices_spec.rb +++ b/modules/two_factor_authentication/spec/features/admin_edit_two_factor_devices_spec.rb @@ -1,19 +1,17 @@ require_relative '../spec_helper' describe 'Admin 2FA management', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer, :totp]}}, - js: true do + with_config: { '2fa': { active_strategies: %i[developer totp] } }, + js: true do let(:dialog) { ::Components::PasswordConfirmationDialog.new } - let(:user_password) {'admin!' * 4} + let(:user_password) { 'admin!' * 4 } let(:other_user) { FactoryBot.create :user, login: 'bob' } let(:admin) do FactoryBot.create(:admin, - password: user_password, - password_confirmation: user_password, - ) + password: user_password, + password_confirmation: user_password) end - before do login_as admin end @@ -33,7 +31,8 @@ describe 'Admin 2FA management', with_2fa_ee: true, type: :feature, visit edit_user_path(other_user, tab: :two_factor_authentication) # Visit empty index - expect(page).to have_selector('.generic-table--empty-row', text: I18n.t('two_factor_authentication.admin.no_devices_for_user')) + expect(page).to have_selector('.generic-table--empty-row', + text: I18n.t('two_factor_authentication.admin.no_devices_for_user')) expect(page).to have_selector('.on-off-status.-disabled') # Visit inline create @@ -83,4 +82,3 @@ describe 'Admin 2FA management', with_2fa_ee: true, type: :feature, end end end - diff --git a/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes.rb b/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes.rb index 9b7f7b936a..8c06059e8d 100644 --- a/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes.rb +++ b/modules/two_factor_authentication/spec/features/backup_codes/generate_backup_codes.rb @@ -2,15 +2,14 @@ require_relative '../../spec_helper' require_relative '../shared_2fa_examples' describe 'Generate 2FA backup codes', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer]}}, - js: true do - let(:user_password) {'bob!' * 4} + with_config: { '2fa': { active_strategies: [:developer] } }, + js: true do + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end let(:dialog) { ::Components::PasswordConfirmationDialog.new } @@ -45,4 +44,3 @@ describe 'Generate 2FA backup codes', with_2fa_ee: true, type: :feature, end end end - diff --git a/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb b/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb index cf8fb8f89f..baa6c8f832 100644 --- a/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb +++ b/modules/two_factor_authentication/spec/features/backup_codes/login_with_backup_code_spec.rb @@ -2,17 +2,16 @@ require_relative '../../spec_helper' require_relative '../shared_2fa_examples' describe 'Login with 2FA backup code', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer]}}, - js: true do - let(:user_password) {'bob!' * 4} + with_config: { '2fa': { active_strategies: [:developer] } }, + js: true do + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true } context 'user has no backup code' do it 'does not show the backup code link' do @@ -70,4 +69,3 @@ describe 'Login with 2FA backup code', with_2fa_ee: true, type: :feature, end end end - diff --git a/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb index 1b5c1d0c68..e83372d7b8 100644 --- a/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb +++ b/modules/two_factor_authentication/spec/features/login/login_enforced_2fa_spec.rb @@ -2,19 +2,18 @@ require_relative '../../spec_helper' require_relative '../shared_2fa_examples' describe 'Login with enforced 2FA', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer], enforced: true }}, - js: true do - let(:user_password) {'bob!' * 4} + with_config: { '2fa': { active_strategies: [:developer], enforced: true } }, + js: true do + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end context 'with a default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true } it 'requests a 2FA' do sms_token = nil @@ -45,4 +44,3 @@ describe 'Login with enforced 2FA', with_2fa_ee: true, type: :feature, it_behaves_like 'create enforced sms device' end end - diff --git a/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb index 12cd20d72e..7aea83bd27 100644 --- a/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb +++ b/modules/two_factor_authentication/spec/features/login/login_with_2fa_spec.rb @@ -2,19 +2,18 @@ require_relative '../../spec_helper' require_relative '../shared_2fa_examples' describe 'Login with 2FA device', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer]}}, - js: true do - let(:user_password) {'bob!' * 4} + with_config: { '2fa': { active_strategies: [:developer] } }, + js: true do + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end context 'with a default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true } it 'requests a 2FA' do sms_token = nil @@ -37,4 +36,3 @@ describe 'Login with 2FA device', with_2fa_ee: true, type: :feature, end end end - diff --git a/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb b/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb index 56d8ea1279..84c9d59748 100644 --- a/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb +++ b/modules/two_factor_authentication/spec/features/login/login_without_2fa_spec.rb @@ -2,26 +2,24 @@ require_relative '../../spec_helper' require_relative '../shared_2fa_examples' describe 'Login with no required OTP', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer]}}, - js: true do - let(:user_password) {'bob!' * 4} + with_config: { '2fa': { active_strategies: [:developer] } }, + js: true do + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end context 'non-default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: false } it_behaves_like 'login without 2FA' end context 'not enabled', - with_config: {:'2fa' => {active_strategies: []}} do - + with_config: { '2fa': { active_strategies: [] } } do it_behaves_like 'login without 2FA' end @@ -29,4 +27,3 @@ describe 'Login with no required OTP', with_2fa_ee: true, type: :feature, it_behaves_like 'login without 2FA' end end - diff --git a/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb b/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb index 20dceb9ff9..06a9163c80 100644 --- a/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb +++ b/modules/two_factor_authentication/spec/features/login/switch_available_devices_spec.rb @@ -2,20 +2,19 @@ require_relative '../../spec_helper' require_relative '../shared_2fa_examples' describe 'Login by switching 2FA device', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer, :totp]}}, - js: true do - let(:user_password) {'bob!' * 4} + with_config: { '2fa': { active_strategies: %i[developer totp] } }, + js: true do + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end context 'with two default device' do - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true} - let!(:device2) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: true, default: false} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true } + let!(:device2) { FactoryBot.create :two_factor_authentication_device_totp, user: user, active: true, default: false } it 'requests a 2FA and allows switching' do first_login_step @@ -37,4 +36,3 @@ describe 'Login by switching 2FA device', with_2fa_ee: true, type: :feature, end end end - diff --git a/modules/two_factor_authentication/spec/features/my_two_factor_devices_spec.rb b/modules/two_factor_authentication/spec/features/my_two_factor_devices_spec.rb index 7b6d7d94ec..3cdfa837b4 100644 --- a/modules/two_factor_authentication/spec/features/my_two_factor_devices_spec.rb +++ b/modules/two_factor_authentication/spec/features/my_two_factor_devices_spec.rb @@ -1,16 +1,15 @@ require_relative '../spec_helper' describe 'My Account 2FA configuration', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer, :totp]}}, - js: true do + with_config: { '2fa': { active_strategies: %i[developer totp] } }, + js: true do let(:dialog) { ::Components::PasswordConfirmationDialog.new } - let(:user_password) {'bob!' * 4} + let(:user_password) { 'bob!' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end before do @@ -18,7 +17,6 @@ describe 'My Account 2FA configuration', with_2fa_ee: true, type: :feature, end it 'allows 2FA device management' do - # Visit empty index visit my_2fa_devices_path expect(page).to have_selector('.generic-table--empty-row', text: I18n.t('two_factor_authentication.devices.not_existing')) @@ -55,7 +53,8 @@ describe 'My Account 2FA configuration', with_2fa_ee: true, type: :feature, expect(page).to have_selector('h2', text: I18n.t('two_factor_authentication.devices.confirm_device')) expect(page).to have_selector('input#otp') - expect(page).to have_selector('.flash.error', text: I18n.t('two_factor_authentication.devices.registration_failed_token_invalid')) + expect(page).to have_selector('.flash.error', + text: I18n.t('two_factor_authentication.devices.registration_failed_token_invalid')) # Fill in correct token fill_in 'otp', with: sms_token @@ -136,4 +135,3 @@ describe 'My Account 2FA configuration', with_2fa_ee: true, type: :feature, expect(user.otp_devices.count).to eq 0 end end - diff --git a/modules/two_factor_authentication/spec/features/password_change_spec.rb b/modules/two_factor_authentication/spec/features/password_change_spec.rb index 5df2c60223..f54bc92ccb 100644 --- a/modules/two_factor_authentication/spec/features/password_change_spec.rb +++ b/modules/two_factor_authentication/spec/features/password_change_spec.rb @@ -1,19 +1,17 @@ require_relative '../spec_helper' describe 'Password change with OTP', with_2fa_ee: true, type: :feature, - with_config: {:'2fa' => {active_strategies: [:developer]}}, - js: true do - let(:user_password) {'bob' * 4} - let(:new_user_password) {'obb' * 4} + with_config: { '2fa': { active_strategies: [:developer] } }, + js: true do + let(:user_password) { 'bob' * 4 } + let(:new_user_password) { 'obb' * 4 } let(:user) do FactoryBot.create(:user, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + login: 'bob', + password: user_password, + password_confirmation: user_password) end - let(:expected_path_after_login) {my_page_path} - + let(:expected_path_after_login) { my_page_path } def handle_password_change(requires_otp: true) visit signin_path @@ -49,8 +47,7 @@ describe 'Password change with OTP', with_2fa_ee: true, type: :feature, end context 'when password is expired', - with_settings: {password_days_valid: 7} do - + with_settings: { password_days_valid: 7 } do before do user end @@ -89,18 +86,17 @@ describe 'Password change with OTP', with_2fa_ee: true, type: :feature, end context 'when force password change is set' do - let(:user_password) {'bob' * 4} - let(:new_user_password) {'obb' * 4} + let(:user_password) { 'bob' * 4 } + let(:new_user_password) { 'obb' * 4 } let(:user) do FactoryBot.create(:user, - force_password_change: true, - first_login: true, - login: 'bob', - password: user_password, - password_confirmation: user_password, - ) + force_password_change: true, + first_login: true, + login: 'bob', + password: user_password, + password_confirmation: user_password) end - let(:expected_path_after_login) {home_path} + let(:expected_path_after_login) { home_path } before do user @@ -123,4 +119,3 @@ describe 'Password change with OTP', with_2fa_ee: true, type: :feature, end end end - diff --git a/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb b/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb index c12a638fd1..0c748486ea 100644 --- a/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb +++ b/modules/two_factor_authentication/spec/features/remember_cookie/login_with_remember_cookie_spec.rb @@ -13,7 +13,7 @@ describe 'Login with 2FA remember cookie', # Works because the user is not reloaded user.password end - let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, active: true, default: true } def login_with_cookie page.driver.browser.manage.delete_all_cookies @@ -42,8 +42,7 @@ describe 'Login with 2FA remember cookie', end context 'not enabled', - - with_config: {:'2fa' => {active_strategies: [:developer], allow_remember_for_days: 0 }} do + with_config: { '2fa': { active_strategies: [:developer], allow_remember_for_days: 0 } } do it 'does not show the save form' do first_login_step expect(page).to have_no_selector('input#remember_me') @@ -104,4 +103,3 @@ describe 'Login with 2FA remember cookie', end end end - diff --git a/modules/two_factor_authentication/spec/features/shared_2fa_examples.rb b/modules/two_factor_authentication/spec/features/shared_2fa_examples.rb index d30ba8e923..7c563ce118 100644 --- a/modules/two_factor_authentication/spec/features/shared_2fa_examples.rb +++ b/modules/two_factor_authentication/spec/features/shared_2fa_examples.rb @@ -35,7 +35,8 @@ end shared_examples 'create enforced sms device' do it do - expect(page).to have_selector('.flash.info', text: I18n.t('two_factor_authentication.forced_registration.required_to_add_device')) + expect(page).to have_selector('.flash.info', + text: I18n.t('two_factor_authentication.forced_registration.required_to_add_device')) SeleniumHubWaiter.wait # Create SMS device @@ -44,7 +45,6 @@ shared_examples 'create enforced sms device' do fill_in 'device_phone_number', with: 'invalid' click_on 'Continue' - # Expect error on invalid phone expect(page).to have_selector('#errorExplanation', text: 'Phone number must be of format +XX XXXXXXXXX') @@ -71,7 +71,8 @@ shared_examples 'create enforced sms device' do expect(page).to have_selector('h2', text: I18n.t('two_factor_authentication.devices.confirm_device')) expect(page).to have_selector('input#otp') - expect(page).to have_selector('.flash.error', text: I18n.t('two_factor_authentication.devices.registration_failed_token_invalid')) + expect(page).to have_selector('.flash.error', + text: I18n.t('two_factor_authentication.devices.registration_failed_token_invalid')) SeleniumHubWaiter.wait # Fill in wrong token diff --git a/modules/two_factor_authentication/spec/lib/token_strategy_manager_spec.rb b/modules/two_factor_authentication/spec/lib/token_strategy_manager_spec.rb index 49343272e2..8b2d17f55a 100644 --- a/modules/two_factor_authentication/spec/lib/token_strategy_manager_spec.rb +++ b/modules/two_factor_authentication/spec/lib/token_strategy_manager_spec.rb @@ -174,4 +174,4 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategyManager do end end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/spec/models/devices/default_device_spec.rb b/modules/two_factor_authentication/spec/models/devices/default_device_spec.rb index 85159fd0e2..43f390e3c9 100644 --- a/modules/two_factor_authentication/spec/models/devices/default_device_spec.rb +++ b/modules/two_factor_authentication/spec/models/devices/default_device_spec.rb @@ -31,4 +31,4 @@ describe 'Default device', with_2fa_ee: true, type: :model do expect(user.otp_devices.get_default).to eq(subject) end end -end \ No newline at end of file +end diff --git a/modules/two_factor_authentication/spec/models/devices/totp_spec.rb b/modules/two_factor_authentication/spec/models/devices/totp_spec.rb index 626292681e..d7575ea285 100644 --- a/modules/two_factor_authentication/spec/models/devices/totp_spec.rb +++ b/modules/two_factor_authentication/spec/models/devices/totp_spec.rb @@ -27,7 +27,7 @@ describe ::TwoFactorAuthentication::Device::Totp, with_2fa_ee: true, type: :mode describe 'token validation' do let(:totp) { subject.send :totp } - context 'drift', with_config: { :'2fa' => { otp_drift_window: 30 } } do + context 'drift', with_config: { '2fa': { otp_drift_window: 30 } } do it 'uses the drift window from configuration' do expect(subject.allowed_drift).to eq 30 end diff --git a/modules/two_factor_authentication/spec/models/login_token_spec.rb b/modules/two_factor_authentication/spec/models/login_token_spec.rb index 2b706f1a44..44ce4e4419 100644 --- a/modules/two_factor_authentication/spec/models/login_token_spec.rb +++ b/modules/two_factor_authentication/spec/models/login_token_spec.rb @@ -1,14 +1,13 @@ require_relative '../spec_helper' describe TwoFactorAuthentication::LoginToken, with_2fa_ee: true do - before(:each) do @user = FactoryBot.build_stubbed(:user, login: "john", password: "doe") allow(@user).to receive(:new_record?).and_return(false) allow(@user).to receive(:force_password_reset).and_return(false) allow(@user).to receive(:password_expired?).and_return(false) allow(@user).to receive(:phone_verified?).and_return(true) - @token = described_class.new( :user => @user ) + @token = described_class.new(user: @user) @token.save end @@ -25,10 +24,9 @@ describe TwoFactorAuthentication::LoginToken, with_2fa_ee: true do end it "should delete previous tokens for the user on creation" do - @new_token = described_class.new( :user => @user ) + @new_token = described_class.new(user: @user) @new_token.save - expect(described_class.find_by_id( @token.id )).to eq(nil) - expect(described_class.find( @new_token.id )).not_to eq(nil) + expect(described_class.find_by_id(@token.id)).to eq(nil) + expect(described_class.find(@new_token.id)).not_to eq(nil) end - end diff --git a/modules/two_factor_authentication/spec/models/user_spec.rb b/modules/two_factor_authentication/spec/models/user_spec.rb index 368d1b86a0..604cd31068 100644 --- a/modules/two_factor_authentication/spec/models/user_spec.rb +++ b/modules/two_factor_authentication/spec/models/user_spec.rb @@ -9,11 +9,11 @@ module OpenProject::TwoFactorAuthentication::Patches @password = @user.password @user.auth_source_id = auth_source_id @user.save! - allow_any_instance_of(User).to receive_messages(:allowed_to? => true, :active? => true) + allow_any_instance_of(User).to receive_messages(allowed_to?: true, active?: true) end def create_user_with_auth_source - auth_source = AuthSource.new :name => "test" + auth_source = AuthSource.new name: "test" create_user auth_source.id end @@ -25,7 +25,7 @@ module OpenProject::TwoFactorAuthentication::Patches login_with @username, @password + "INVALID" end - def login_with login, password + def login_with(login, password) User.try_to_login(login, password) end diff --git a/modules/two_factor_authentication/spec/routing/two_factor_authentication/my/two_factor_devices_spec.rb b/modules/two_factor_authentication/spec/routing/two_factor_authentication/my/two_factor_devices_spec.rb index a15aa49e61..6595a77908 100644 --- a/modules/two_factor_authentication/spec/routing/two_factor_authentication/my/two_factor_devices_spec.rb +++ b/modules/two_factor_authentication/spec/routing/two_factor_authentication/my/two_factor_devices_spec.rb @@ -61,7 +61,7 @@ describe 'users 2fa devices', type: :routing do it 'route to DELETE destroy' do expect(delete('/my/two_factor_devices/1')).to route_to(controller: 'two_factor_authentication/my/two_factor_devices', - action: 'destroy', - device_id: '1') + action: 'destroy', + device_id: '1') end end diff --git a/modules/two_factor_authentication/spec/routing/two_factor_authentication/users/two_factor_devices_spec.rb b/modules/two_factor_authentication/spec/routing/two_factor_authentication/users/two_factor_devices_spec.rb index d13c2f4130..ec0d21b377 100644 --- a/modules/two_factor_authentication/spec/routing/two_factor_authentication/users/two_factor_devices_spec.rb +++ b/modules/two_factor_authentication/spec/routing/two_factor_authentication/users/two_factor_devices_spec.rb @@ -31,8 +31,8 @@ require 'spec_helper' describe 'users 2fa devices', type: :routing do it 'route to GET new' do expect(get('/users/2/two_factor_devices/new')).to route_to(controller: 'two_factor_authentication/users/two_factor_devices', - action: 'new', - id: '2') + action: 'new', + id: '2') end it 'route to POST register' do @@ -43,21 +43,21 @@ describe 'users 2fa devices', type: :routing do it 'route to POST confirm' do expect(post('/users/2/two_factor_devices/1/make_default')).to route_to(controller: 'two_factor_authentication/users/two_factor_devices', - action: 'make_default', - id: '2', - device_id: '1') + action: 'make_default', + id: '2', + device_id: '1') end it 'route to POST delete_all' do expect(post('/users/2/two_factor_devices/delete_all')).to route_to(controller: 'two_factor_authentication/users/two_factor_devices', - action: 'delete_all', - id: '2') + action: 'delete_all', + id: '2') end it 'route to DELETE destroy' do expect(delete('/users/2/two_factor_devices/1')).to route_to(controller: 'two_factor_authentication/users/two_factor_devices', - action: 'destroy', - id: '2', - device_id: '1') + action: 'destroy', + id: '2', + device_id: '1') end end diff --git a/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb index 9785c8fc85..1747d728b9 100644 --- a/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb +++ b/modules/two_factor_authentication/spec/services/token_delivery/message_bird_spec.rb @@ -8,11 +8,11 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::MessageBird, wit let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, channel: channel } let(:service_url) { 'https://example.org/foobar' } - let(:params) { + let(:params) do { - apikey: 'whatever' + apikey: 'whatever' } - } + end before do allow(OpenProject::Configuration) diff --git a/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb index 1b1c1bc0d3..c7fe2e4c1c 100644 --- a/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb +++ b/modules/two_factor_authentication/spec/services/token_delivery/restdt_spec.rb @@ -6,15 +6,15 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Restdt, with_2fa let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, channel: channel } let(:service_url) { 'https://example.org/foobar' } - let(:params) { + let(:params) do { service_url: service_url, username: 'foobar', password: 'password!' } - } + end - let(:base_request) { + let(:base_request) do { user: 'foobar', pass: 'password!', @@ -23,7 +23,7 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Restdt, with_2fa txt: '1234', output: 'plain' } - } + end before do allow(OpenProject::Configuration) diff --git a/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb index 0c4619dc64..6862cfce4f 100644 --- a/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb +++ b/modules/two_factor_authentication/spec/services/token_delivery/sns_spec.rb @@ -7,13 +7,13 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Sns, with_2fa_ee let!(:device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, channel: channel } let(:channel) { :sms } - let(:params) { + let(:params) do { region: 'eu-west-1', access_key_id: 'foobar', secret_access_key: 'foobar key' } - } + end before do allow(OpenProject::Configuration) @@ -66,7 +66,8 @@ describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Sns, with_2fa_ee expect(api) .to receive(:publish) .with(phone_number: phone.gsub(' ', ''), - message: I18n.t('two_factor_authentication.text_otp_delivery_message_sms', app_title: Setting.app_title, token: 1234)) + message: I18n.t('two_factor_authentication.text_otp_delivery_message_sms', app_title: Setting.app_title, + token: 1234)) .and_return(api_result) end diff --git a/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb b/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb index 5ac4e7cacb..0a447ff718 100644 --- a/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb +++ b/modules/two_factor_authentication/spec/services/token_delivery/totp_spec.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') describe ::OpenProject::TwoFactorAuthentication::TokenStrategy::Totp, with_2fa_ee: true do describe 'sending messages' do let!(:user) { FactoryBot.create :user } - let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true} + let!(:device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } before do allow(OpenProject::Configuration) diff --git a/modules/two_factor_authentication/spec/services/token_service_spec.rb b/modules/two_factor_authentication/spec/services/token_service_spec.rb index a4af599203..9f90b5f898 100644 --- a/modules/two_factor_authentication/spec/services/token_service_spec.rb +++ b/modules/two_factor_authentication/spec/services/token_service_spec.rb @@ -93,7 +93,7 @@ describe ::TwoFactorAuthentication::TokenService, with_2fa_ee: true do end context 'when developer and totp strategies are set' do - let(:active_strategies) { [:developer, :totp] } + let(:active_strategies) { %i[developer totp] } let!(:totp_device) { FactoryBot.create :two_factor_authentication_device_totp, user: user, default: true } let!(:sms_device) { FactoryBot.create :two_factor_authentication_device_sms, user: user, default: false } diff --git a/modules/two_factor_authentication/spec/spec_helper.rb b/modules/two_factor_authentication/spec/spec_helper.rb index d170945a80..ccee9f71c2 100644 --- a/modules/two_factor_authentication/spec/spec_helper.rb +++ b/modules/two_factor_authentication/spec/spec_helper.rb @@ -14,4 +14,4 @@ RSpec.configure do |config| .with(:two_factor_authentication) .and_return true end -end \ No newline at end of file +end diff --git a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb b/modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb index 8314c9a3ca..b2d92b0b5d 100644 --- a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb +++ b/modules/webhooks/app/cells/webhooks/outgoing/deliveries/row_cell.rb @@ -19,4 +19,4 @@ module ::Webhooks end end end -end \ No newline at end of file +end diff --git a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb b/modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb index 66bab5a586..2aa5321148 100644 --- a/modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb +++ b/modules/webhooks/app/cells/webhooks/outgoing/deliveries/table_cell.rb @@ -14,11 +14,11 @@ module ::Webhooks def headers [ - ['id', caption: I18n.t('attributes.id')], - ['event_name', caption: ::Webhooks::Log.human_attribute_name('event_name')], - ['time', caption: I18n.t('webhooks.outgoing.deliveries.time')], - ['response_code', caption: ::Webhooks::Log.human_attribute_name('response_code')], - ['response_body', caption: ::Webhooks::Log.human_attribute_name('response_body')], + ['id', { caption: I18n.t('attributes.id') }], + ['event_name', { caption: ::Webhooks::Log.human_attribute_name('event_name') }], + ['time', { caption: I18n.t('webhooks.outgoing.deliveries.time') }], + ['response_code', { caption: ::Webhooks::Log.human_attribute_name('response_code') }], + ['response_body', { caption: ::Webhooks::Log.human_attribute_name('response_body') }] ] end end diff --git a/modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb b/modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb index 53628da9ee..fc99ada650 100644 --- a/modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb +++ b/modules/webhooks/app/cells/webhooks/outgoing/webhooks/table_cell.rb @@ -5,7 +5,7 @@ module ::Webhooks columns :name, :enabled, :selected_projects, :events, :description def initial_sort - [:id, :asc] + %i[id asc] end def target_controller @@ -20,7 +20,7 @@ module ::Webhooks link_to({ controller: target_controller, action: :new }, class: 'webhooks--add-row wp-inline-create--add-link', title: I18n.t('webhooks.outgoing.label_add_new')) do - op_icon('icon icon-add') + op_icon('icon icon-add') end end @@ -30,14 +30,14 @@ module ::Webhooks def headers [ - ['name', caption: I18n.t('attributes.name')], - ['enabled', caption: I18n.t(:label_active)], - ['selected_projects', caption: ::Webhooks::Webhook.human_attribute_name('projects')], - ['events', caption: I18n.t('webhooks.outgoing.label_event_resources')], - ['description', caption: I18n.t('attributes.description')] + ['name', { caption: I18n.t('attributes.name') }], + ['enabled', { caption: I18n.t(:label_active) }], + ['selected_projects', { caption: ::Webhooks::Webhook.human_attribute_name('projects') }], + ['events', { caption: I18n.t('webhooks.outgoing.label_event_resources') }], + ['description', { caption: I18n.t('attributes.description') }] ] end end end end -end \ No newline at end of file +end diff --git a/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb b/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb index 5dad2791d0..01beea6a3b 100644 --- a/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb +++ b/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/webhooks/app/controllers/webhooks/outgoing/admin_controller.rb b/modules/webhooks/app/controllers/webhooks/outgoing/admin_controller.rb index c692241574..ce903e0438 100644 --- a/modules/webhooks/app/controllers/webhooks/outgoing/admin_controller.rb +++ b/modules/webhooks/app/controllers/webhooks/outgoing/admin_controller.rb @@ -4,7 +4,7 @@ module Webhooks layout 'admin' before_action :require_admin - before_action :find_webhook, only: [:show, :edit, :update, :destroy] + before_action :find_webhook, only: %i[show edit update destroy] menu_item :plugin_webhooks @@ -13,6 +13,7 @@ module Webhooks end def show; end + def edit; end def new @@ -70,7 +71,6 @@ module Webhooks .require(:webhook) .permit(:name, :description, :url, :secret, :enabled, :project_ids, selected_project_ids: [], events: []) - end def show_local_breadcrumb diff --git a/modules/webhooks/app/models/webhooks.rb b/modules/webhooks/app/models/webhooks.rb index aac358193c..03e7ca3512 100644 --- a/modules/webhooks/app/models/webhooks.rb +++ b/modules/webhooks/app/models/webhooks.rb @@ -2,4 +2,4 @@ module Webhooks def self.table_name_prefix 'webhooks_' end -end \ No newline at end of file +end diff --git a/modules/webhooks/app/services/webhooks/outgoing/update_webhook_service.rb b/modules/webhooks/app/services/webhooks/outgoing/update_webhook_service.rb index 7350ea58d7..3dbdfc8d0d 100644 --- a/modules/webhooks/app/services/webhooks/outgoing/update_webhook_service.rb +++ b/modules/webhooks/app/services/webhooks/outgoing/update_webhook_service.rb @@ -1,8 +1,7 @@ module Webhooks module Outgoing class UpdateWebhookService - attr_reader :current_user - attr_reader :webhook + attr_reader :current_user, :webhook def initialize(webhook, current_user:) @current_user = current_user @@ -12,10 +11,10 @@ module Webhooks def call(attributes: {}) ::Webhooks::Webhook.transaction do set_attributes attributes - raise ActiveRecord::Rollback unless (webhook.errors.empty? && webhook.save) + raise ActiveRecord::Rollback unless webhook.errors.empty? && webhook.save end - ServiceResult.new success: webhook.errors.empty? , errors: webhook.errors, result: webhook + ServiceResult.new success: webhook.errors.empty?, errors: webhook.errors, result: webhook end private diff --git a/modules/webhooks/app/workers/webhook_job.rb b/modules/webhooks/app/workers/webhook_job.rb index 2c6c4bd181..e39b93849e 100644 --- a/modules/webhooks/app/workers/webhook_job.rb +++ b/modules/webhooks/app/workers/webhook_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/modules/webhooks/lib/open_project/webhooks/engine.rb b/modules/webhooks/lib/open_project/webhooks/engine.rb index bf08d9b83a..80c69395d6 100644 --- a/modules/webhooks/lib/open_project/webhooks/engine.rb +++ b/modules/webhooks/lib/open_project/webhooks/engine.rb @@ -37,13 +37,13 @@ module OpenProject::Webhooks register 'openproject-webhooks', bundled: true, author_url: 'https://github.com/opf/openproject-webhooks' do - menu :admin_menu, - :plugin_webhooks, - { controller: 'webhooks/outgoing/admin', action: :index }, - if: Proc.new { User.current.admin? }, - after: :plugins, - caption: ->(*) { I18n.t('webhooks.plural') }, - icon: 'icon2 icon-relations' + menu :admin_menu, + :plugin_webhooks, + { controller: 'webhooks/outgoing/admin', action: :index }, + if: Proc.new { User.current.admin? }, + after: :plugins, + caption: ->(*) { I18n.t('webhooks.plural') }, + icon: 'icon2 icon-relations' end config.before_configuration do |app| diff --git a/modules/webhooks/lib/open_project/webhooks/event_resources.rb b/modules/webhooks/lib/open_project/webhooks/event_resources.rb index a19e31e6c8..7aa065f358 100644 --- a/modules/webhooks/lib/open_project/webhooks/event_resources.rb +++ b/modules/webhooks/lib/open_project/webhooks/event_resources.rb @@ -24,12 +24,10 @@ module OpenProject::Webhooks def resource_modules @resource_modules ||= begin resources.map do |name| - begin - require_relative "./event_resources/#{name}" - "OpenProject::Webhooks::EventResources::#{name.to_s.camelize}".constantize - rescue LoadError, NameError => e - raise ArgumentError, "Failed to initialize resources module for #{name}: #{e}" - end + require_relative "./event_resources/#{name}" + "OpenProject::Webhooks::EventResources::#{name.to_s.camelize}".constantize + rescue LoadError, NameError => e + raise ArgumentError, "Failed to initialize resources module for #{name}: #{e}" end end end diff --git a/modules/webhooks/lib/open_project/webhooks/event_resources/base.rb b/modules/webhooks/lib/open_project/webhooks/event_resources/base.rb index 1e51d7bc10..bab430a0ff 100644 --- a/modules/webhooks/lib/open_project/webhooks/event_resources/base.rb +++ b/modules/webhooks/lib/open_project/webhooks/event_resources/base.rb @@ -18,7 +18,7 @@ module OpenProject::Webhooks::EventResources ## # Return a mapping of event key to its localized name def available_events_map - Hash[available_actions.map { |symbol| [ prefixed_event_name(symbol), localize_event_name(symbol) ] }] + Hash[available_actions.map { |symbol| [prefixed_event_name(symbol), localize_event_name(symbol)] }] end ## @@ -70,4 +70,4 @@ module OpenProject::Webhooks::EventResources end end end -end \ No newline at end of file +end diff --git a/modules/webhooks/lib/open_project/webhooks/hook.rb b/modules/webhooks/lib/open_project/webhooks/hook.rb index fddd1564a3..52c09e8888 100644 --- a/modules/webhooks/lib/open_project/webhooks/hook.rb +++ b/modules/webhooks/lib/open_project/webhooks/hook.rb @@ -43,6 +43,5 @@ module OpenProject::Webhooks def handle(request = Hash.new, params = Hash.new, user = nil) callback.call self, request, params, user end - end end diff --git a/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb b/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb index 27f3630d57..107a6666b3 100644 --- a/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb +++ b/modules/webhooks/spec/controllers/outgoing/admin_controller_spec.rb @@ -94,9 +94,9 @@ describe ::Webhooks::Outgoing::AdminController, type: :controller do expect(service) .to receive(:call) - .and_return(ServiceResult.new success: success) + .and_return(ServiceResult.new(success: success)) - post :create, params: { webhook: webhook_params} + post :create, params: { webhook: webhook_params } end context 'when success' do @@ -174,9 +174,9 @@ describe ::Webhooks::Outgoing::AdminController, type: :controller do expect(service) .to receive(:call) - .and_return(ServiceResult.new success: success) + .and_return(ServiceResult.new(success: success)) - put :update, params: { webhook_id: '1234', webhook: webhook_params} + put :update, params: { webhook_id: '1234', webhook: webhook_params } end context 'when success' do diff --git a/modules/webhooks/spec/controllers/webhooks_controller_spec.rb b/modules/webhooks/spec/controllers/webhooks_controller_spec.rb index b9ce4ab720..446334ec88 100644 --- a/modules/webhooks/spec/controllers/webhooks_controller_spec.rb +++ b/modules/webhooks/spec/controllers/webhooks_controller_spec.rb @@ -26,10 +26,9 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../spec_helper', __dir__) - -describe Webhooks::Incoming::HooksController, :type => :controller do +describe Webhooks::Incoming::HooksController, type: :controller do let(:hook) { double(OpenProject::Webhooks::Hook) } let(:user) { double(User).as_null_object } @@ -53,12 +52,11 @@ describe Webhooks::Incoming::HooksController, :type => :controller do end it 'should call the hook with a user' do - expect(hook).to receive(:handle) { |env, params, user| + expect(hook).to receive(:handle) { |_env, _params, user| expect(user).to equal(user) } post :handle_hook, params: { hook_name: 'testhook' } end - end end diff --git a/modules/webhooks/spec/lib/hook_spec.rb b/modules/webhooks/spec/lib/hook_spec.rb index 99c6f781d0..d74367baf5 100644 --- a/modules/webhooks/spec/lib/hook_spec.rb +++ b/modules/webhooks/spec/lib/hook_spec.rb @@ -26,11 +26,11 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) +require File.expand_path('../spec_helper', __dir__) describe OpenProject::Webhooks::Hook do describe '#relative_url' do - let(:hook) { OpenProject::Webhooks::Hook.new('myhook')} + let(:hook) { OpenProject::Webhooks::Hook.new('myhook') } it "should return the correct URL" do expect(hook.relative_url).to eql('webhooks/myhook') @@ -38,7 +38,7 @@ describe OpenProject::Webhooks::Hook do end describe '#handle' do - let(:probe) { lambda{} } + let(:probe) { lambda {} } let(:hook) { OpenProject::Webhooks::Hook.new('myhook', &probe) } before do diff --git a/modules/webhooks/spec/lib/webhooks_spec.rb b/modules/webhooks/spec/lib/webhooks_spec.rb index 712e476db6..7c7a8d0b02 100644 --- a/modules/webhooks/spec/lib/webhooks_spec.rb +++ b/modules/webhooks/spec/lib/webhooks_spec.rb @@ -26,8 +26,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../../spec_helper', __FILE__) - +require File.expand_path('../spec_helper', __dir__) describe OpenProject::Webhooks do describe '.register_hook' do @@ -53,11 +52,10 @@ describe OpenProject::Webhooks do end describe '.unregister_hook' do - let(:probe) { lambda{} } + let(:probe) { lambda {} } before do OpenProject::Webhooks.register_hook('testhook2', &probe) - end it 'should result in the hook no longer being found' do @@ -65,5 +63,4 @@ describe OpenProject::Webhooks do expect(OpenProject::Webhooks.find('testhook2')).to be_nil end end - end diff --git a/modules/webhooks/spec/routing/webhooks/outgoing/admin_controller_spec.rb b/modules/webhooks/spec/routing/webhooks/outgoing/admin_controller_spec.rb index 9a009ff745..d147d80b44 100644 --- a/modules/webhooks/spec/routing/webhooks/outgoing/admin_controller_spec.rb +++ b/modules/webhooks/spec/routing/webhooks/outgoing/admin_controller_spec.rb @@ -39,20 +39,20 @@ describe 'Outgoing webhooks administration', type: :routing do it 'route to show' do expect(get('/admin/webhooks/1')).to route_to(controller: 'webhooks/outgoing/admin', - action: 'show', - webhook_id: '1') + action: 'show', + webhook_id: '1') end it 'route to edit' do expect(get('/admin/webhooks/1/edit')).to route_to(controller: 'webhooks/outgoing/admin', - action: 'edit', - webhook_id: '1') + action: 'edit', + webhook_id: '1') end it 'route to PUT update' do expect(put('/admin/webhooks/1')).to route_to(controller: 'webhooks/outgoing/admin', - action: 'update', - webhook_id: '1') + action: 'update', + webhook_id: '1') end it 'route to DELETE destroy' do diff --git a/modules/webhooks/spec/workers/project_webhook_job.rb b/modules/webhooks/spec/workers/project_webhook_job.rb index f1e9d597df..4d0f1e107c 100644 --- a/modules/webhooks/spec/workers/project_webhook_job.rb +++ b/modules/webhooks/spec/workers/project_webhook_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -71,12 +72,10 @@ describe ProjectWebhookJob, type: :job, webmock: true do end subject do - begin - job - rescue - # ignoring it as it's expected to throw exceptions in certain scenarios - nil - end + job + rescue StandardError + # ignoring it as it's expected to throw exceptions in certain scenarios + nil end before do diff --git a/modules/webhooks/spec/workers/time_entry_webhook_job.rb b/modules/webhooks/spec/workers/time_entry_webhook_job.rb index e8c527ba51..a5be81336e 100644 --- a/modules/webhooks/spec/workers/time_entry_webhook_job.rb +++ b/modules/webhooks/spec/workers/time_entry_webhook_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -71,12 +72,10 @@ describe TimeEntryWebhookJob, type: :job, webmock: true do end subject do - begin - job - rescue - # ignoring it as it's expected to throw exceptions in certain scenarios - nil - end + job + rescue StandardError + # ignoring it as it's expected to throw exceptions in certain scenarios + nil end before do diff --git a/modules/webhooks/spec/workers/work_package_webhook_job.rb b/modules/webhooks/spec/workers/work_package_webhook_job.rb index 185dc021ee..12c9edd8e2 100644 --- a/modules/webhooks/spec/workers/work_package_webhook_job.rb +++ b/modules/webhooks/spec/workers/work_package_webhook_job.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -72,12 +73,10 @@ describe WorkPackageWebhookJob, type: :model, webmock: true do end subject do - begin - job.perform - rescue - # ignoring it as it's expected to throw exceptions in certain scenarios - nil - end + job.perform + rescue StandardError + # ignoring it as it's expected to throw exceptions in certain scenarios + nil end before do diff --git a/modules/xls_export/lib/open_project/xls_export/engine.rb b/modules/xls_export/lib/open_project/xls_export/engine.rb index 21b38df93f..53723534af 100644 --- a/modules/xls_export/lib/open_project/xls_export/engine.rb +++ b/modules/xls_export/lib/open_project/xls_export/engine.rb @@ -19,9 +19,9 @@ module OpenProject::XlsExport initializer 'xls_export.register_hooks' do # don't use require_dependency to not reload hooks in development mode - require 'open_project/xls_export/hooks/cost_report_hook.rb' + require 'open_project/xls_export/hooks/cost_report_hook' - require 'open_project/xls_export/hooks/work_package_hook.rb' + require 'open_project/xls_export/hooks/work_package_hook' end initializer 'xls_export.register_mimetypes' do diff --git a/modules/xls_export/lib/open_project/xls_export/formatters.rb b/modules/xls_export/lib/open_project/xls_export/formatters.rb index f86efcc4c0..80ed5c292f 100644 --- a/modules/xls_export/lib/open_project/xls_export/formatters.rb +++ b/modules/xls_export/lib/open_project/xls_export/formatters.rb @@ -1,7 +1,7 @@ module OpenProject::XlsExport module Formatters def self.all - self.constants.map do |const| + constants.map do |const| Kernel.const_get("OpenProject::XlsExport::Formatters::#{const}") end.select do |const| const.is_a?(Class) && const != DefaultFormatter @@ -15,7 +15,7 @@ module OpenProject::XlsExport ## # Returns a Hash mapping columns to formatters to be used. def self.for_columns(columns) - formatters = self.all + formatters = all entries = columns.map do |column| formatter = formatters.find { |formatter| formatter.apply? column } [column, (formatter || DefaultFormatter).new] @@ -27,7 +27,7 @@ module OpenProject::XlsExport ## # Takes a QueryColumn and returns true if this formatter should be used to handle it. def self.apply?(column) - column.xls_formatter == self.key + column.xls_formatter == key end def self.key @@ -49,20 +49,20 @@ module OpenProject::XlsExport ## # Takes a QueryColumn and returns format options for it. - def format_options(column) + def format_options(_column) {} end end class TimeFormatter < DefaultFormatter - def format_options(column) - { :number_format => '0.0 "h"' } + def format_options(_column) + { number_format: '0.0 "h"' } end end class CostFormatter < DefaultFormatter - def format_options(column) - { :number_format => number_format_string } + def format_options(_column) + { number_format: number_format_string } end def number_format_string diff --git a/modules/xls_export/lib/open_project/xls_export/patches/cost_reports_controller_patch.rb b/modules/xls_export/lib/open_project/xls_export/patches/cost_reports_controller_patch.rb index 6a76c68dde..e7e78d6329 100644 --- a/modules/xls_export/lib/open_project/xls_export/patches/cost_reports_controller_patch.rb +++ b/modules/xls_export/lib/open_project/xls_export/patches/cost_reports_controller_patch.rb @@ -42,4 +42,4 @@ module OpenProject::XlsExport::Patches end end -CostReportsController.send(:include, OpenProject::XlsExport::Patches::CostReportsControllerPatch) +CostReportsController.include OpenProject::XlsExport::Patches::CostReportsControllerPatch diff --git a/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb b/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb index 3ac9718099..308d585896 100644 --- a/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb +++ b/modules/xls_export/lib/open_project/xls_export/spreadsheet_builder.rb @@ -53,8 +53,8 @@ module OpenProject::XlsExport # Get the approximate width of a value as seen in the excel sheet def get_value_width(value) - if ['Time', 'Date'].include?(value.class.name) - return 18 unless value.to_s.length < 18 + if ['Time', 'Date'].include?(value.class.name) && !(value.to_s.length < 18) + return 18 end tot_w = [Float(0)] @@ -93,7 +93,7 @@ module OpenProject::XlsExport value_width = get_value_width(arr_or_str[0] * 2) @column_widths[0] = value_width if (@column_widths[0] || 0) < value_width end - title_format = Spreadsheet::Format.new(:weight => :bold, :size => 18) + title_format = Spreadsheet::Format.new(weight: :bold, size: 18) @sheet.row(0).set_format(0, title_format) end @@ -139,7 +139,7 @@ module OpenProject::XlsExport arr.each_with_index do |c, i| value = if %w(Time Date Fixnum Float Integer).include?(c.class.name) c - elsif c.class == BigDecimal + elsif c.instance_of?(BigDecimal) c.to_f else c.to_s.gsub("\r\n", "\n").gsub("\r", "\n") diff --git a/modules/xls_export/spec/lib/custom_field_xls_export_spec.rb b/modules/xls_export/spec/lib/custom_field_xls_export_spec.rb index 4b5164a448..eca96cbc37 100644 --- a/modules/xls_export/spec/lib/custom_field_xls_export_spec.rb +++ b/modules/xls_export/spec/lib/custom_field_xls_export_spec.rb @@ -7,12 +7,12 @@ describe "WorkPackageXlsExport Custom Fields" do let!(:custom_field) do FactoryBot.create( - :list_wp_custom_field, - name: "Ingredients", - multi_value: true, - types: [type], - projects: [project], - possible_values: ["ham", "onions", "pineapple", "mushrooms"] + :list_wp_custom_field, + name: "Ingredients", + multi_value: true, + types: [type], + projects: [project], + possible_values: ["ham", "onions", "pineapple", "mushrooms"] ) end diff --git a/modules/xls_export/spec/patches/cost_reports_controller_patch_spec.rb b/modules/xls_export/spec/patches/cost_reports_controller_patch_spec.rb index ead956322b..83f2ec2e15 100644 --- a/modules/xls_export/spec/patches/cost_reports_controller_patch_spec.rb +++ b/modules/xls_export/spec/patches/cost_reports_controller_patch_spec.rb @@ -5,18 +5,17 @@ describe 'CostReportsController', "rendering to xls" do it "should respond with the xls if requested in the index" do skip - render :action => :index + render action: :index expect(response).to be_redirect end it "should not respond with the xls if requested in a detail view" do skip - render :action => :show + render action: :show expect(response).to be_redirect end it "should generate xls from issues" do skip end - end diff --git a/packaging/scripts/send-test-email b/packaging/scripts/send-test-email index 6a71a92820..9a9d9471aa 100755 --- a/packaging/scripts/send-test-email +++ b/packaging/scripts/send-test-email @@ -10,25 +10,25 @@ smtp_domain = ENV.fetch('SMTP_DOMAIN') { "example.net" } from = "no-reply@#{smtp_domain}" delivery_method = ENV.fetch('EMAIL_DELIVERY_METHOD') { "sendmail" } -msgstr = < -To: #{admin_email} -Subject: Test message -Date: #{Time.now.httpdate} -Message-Id: <#{SecureRandom.hex}@#{smtp_domain}> - -This is a test message to verify your OpenProject settings. -If you see this, this means OpenProject email settings are working properly. +msgstr = <<~END_OF_MESSAGE + From: OpenProject <#{from}> + To: #{admin_email} + Subject: Test message + Date: #{Time.now.httpdate} + Message-Id: <#{SecureRandom.hex}@#{smtp_domain}> + #{' '} + This is a test message to verify your OpenProject settings. + If you see this, this means OpenProject email settings are working properly. END_OF_MESSAGE if delivery_method == "sendmail" puts "sending test email using sendmail..." tmpfile = Tempfile.new("mail-test") - File.open(tmpfile.path, "w+") {|f| f << msgstr} + File.open(tmpfile.path, "w+") { |f| f << msgstr } system("cat #{tmpfile.path} | sendmail -i -t") || exit(1) else smtp_authentication = ENV.fetch('SMTP_AUTHENTICATION', "none").to_sym - #set authentication to nil because :none is not supported by SMTP module + # set authentication to nil because :none is not supported by SMTP module smtp_authentication = nil if smtp_authentication == :none puts "sending test email using SMTP..." smtp = Net::SMTP.new( @@ -38,11 +38,10 @@ else smtp.enable_starttls_auto if ENV.fetch('SMTP_ENABLE_STARTTLS_AUTO', 'false') == 'true' smtp.start( ENV.fetch('SMTP_DOMAIN'), - ENV.fetch('SMTP_USERNAME',nil), - ENV.fetch('SMTP_PASSWORD',nil), + ENV.fetch('SMTP_USERNAME', nil), + ENV.fetch('SMTP_PASSWORD', nil), smtp_authentication ) smtp.send_message msgstr, from, admin_email smtp.finish end - diff --git a/script/travis_pr_errors b/script/travis_pr_errors index b0dd9a12ed..d531714ee9 100755 --- a/script/travis_pr_errors +++ b/script/travis_pr_errors @@ -15,7 +15,7 @@ begin response = RestClient.get "https://api.github.com/repos/opf/openproject/pulls?state=open&head=opf:#{branch_name}" json = JSON.parse(response) pr_number = json.first['number'] -rescue => e +rescue StandardError => e warn "Failed to get PR number from #{branch_name}: #{e} #{e.message}" end @@ -46,4 +46,3 @@ end specs = results.flatten.join(" ") puts "Errors\n\n#{specs}" - diff --git a/spec/contracts/authentication/omniauth_auth_hash_contract_spec.rb b/spec/contracts/authentication/omniauth_auth_hash_contract_spec.rb index fea77ed875..16efc285c5 100644 --- a/spec/contracts/authentication/omniauth_auth_hash_contract_spec.rb +++ b/spec/contracts/authentication/omniauth_auth_hash_contract_spec.rb @@ -38,8 +38,7 @@ describe Authentication::OmniauthAuthHashContract do info: { name: 'foo', email: 'foo@bar.com', first_name: 'foo', - last_name: 'bar' - } + last_name: 'bar' } ) end @@ -100,7 +99,7 @@ describe Authentication::OmniauthAuthHashContract do end describe '#validate_authorization_callback' do - let(:auth_double) { double('Authorization', approve?: authorized, message: message)} + let(:auth_double) { double('Authorization', approve?: authorized, message: message) } before do allow(OpenProject::OmniAuth::Authorization) diff --git a/spec/contracts/custom_actions/cu_contract_spec.rb b/spec/contracts/custom_actions/cu_contract_spec.rb index cf17240b41..30ae61b4e3 100644 --- a/spec/contracts/custom_actions/cu_contract_spec.rb +++ b/spec/contracts/custom_actions/cu_contract_spec.rb @@ -95,7 +95,7 @@ describe CustomActions::CuContract do allow(status_action) .to receive(:allowed_values) .and_return([{ value: nil, label: '-' }, - { value: 1, label: 'some status'}]) + { value: 1, label: 'some status' }]) action.actions = [status_action] @@ -128,7 +128,7 @@ describe CustomActions::CuContract do allow(status_condition) .to receive(:allowed_values) .and_return([{ value: nil, label: '-' }, - { value: 1, label: 'some status'}]) + { value: 1, label: 'some status' }]) action.conditions = [status_condition] diff --git a/spec/contracts/projects/delete_contract_spec.rb b/spec/contracts/projects/delete_contract_spec.rb index 91f3ce3135..6e86c5964a 100644 --- a/spec/contracts/projects/delete_contract_spec.rb +++ b/spec/contracts/projects/delete_contract_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/contracts/queries/update_contract_spec.rb b/spec/contracts/queries/update_contract_spec.rb index 2a0c817773..71f273836b 100644 --- a/spec/contracts/queries/update_contract_spec.rb +++ b/spec/contracts/queries/update_contract_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/contracts/users/create_contract_spec.rb b/spec/contracts/users/create_contract_spec.rb index baa8464b85..eb70f56387 100644 --- a/spec/contracts/users/create_contract_spec.rb +++ b/spec/contracts/users/create_contract_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/contracts/wiki_pages/shared_contract_examples.rb b/spec/contracts/wiki_pages/shared_contract_examples.rb index 53a24fa8e8..7aed59d7c6 100644 --- a/spec/contracts/wiki_pages/shared_contract_examples.rb +++ b/spec/contracts/wiki_pages/shared_contract_examples.rb @@ -39,8 +39,8 @@ shared_examples_for 'wiki page contract' do end let(:page_wiki) { FactoryBot.build_stubbed(:wiki) } let(:page_author) { current_user } - let(:page_title) { 'Wiki title'} - let(:page_slug) { 'wiki slug'} + let(:page_title) { 'Wiki title' } + let(:page_slug) { 'wiki slug' } let(:page_protected) { false } let(:page_parent) { nil } let(:page_text) { 'Wiki text' } diff --git a/spec/contracts/work_packages/create_contract_spec.rb b/spec/contracts/work_packages/create_contract_spec.rb index 26d680aaee..9a814c013e 100644 --- a/spec/contracts/work_packages/create_contract_spec.rb +++ b/spec/contracts/work_packages/create_contract_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/contracts/work_packages/create_note_contract_spec.rb b/spec/contracts/work_packages/create_note_contract_spec.rb index 13b52092af..13d164e1ca 100644 --- a/spec/contracts/work_packages/create_note_contract_spec.rb +++ b/spec/contracts/work_packages/create_note_contract_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/contracts/work_packages/shared_base_contract.rb b/spec/contracts/work_packages/shared_base_contract.rb index 07e61232cc..856af1ce39 100644 --- a/spec/contracts/work_packages/shared_base_contract.rb +++ b/spec/contracts/work_packages/shared_base_contract.rb @@ -35,11 +35,11 @@ shared_examples_for 'work package contract' do subject(:contract) { described_class.new(work_package, user) } - let(:validated_contract) { + let(:validated_contract) do contract = subject contract.validate contract - } + end before do allow(WorkPackagePolicy) diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb index c8cb2f698b..162aa1353e 100644 --- a/spec/controllers/account_controller_spec.rb +++ b/spec/controllers/account_controller_spec.rb @@ -29,10 +29,8 @@ require 'spec_helper' describe AccountController, type: :controller do - class UserHook < Redmine::Hook::ViewListener - attr_reader :registered_user - attr_reader :first_login_user + attr_reader :registered_user, :first_login_user def user_registered(context) @registered_user = context[:user] @@ -323,7 +321,6 @@ describe AccountController, type: :controller do context 'with direct login and redirecting callback', with_settings: { login_required?: true }, with_config: { omniauth_direct_login_provider: 'foo' } do - it 'will still call the callback' do # Set the previous session session[:foo] = 'bar' @@ -351,9 +348,9 @@ describe AccountController, type: :controller do context 'with a no-op callback' do it 'will redirect to default if the callback does nothing' do was_called = false - sso_provider[:single_sign_out_callback] = Proc.new { + sso_provider[:single_sign_out_callback] = Proc.new do was_called = true - } + end get :logout expect(was_called).to eq true @@ -448,8 +445,7 @@ describe AccountController, type: :controller do end describe '#login with omniauth_direct_login enabled', - with_config: { omniauth_direct_login_provider: 'some_provider' } do - + with_config: { omniauth_direct_login_provider: 'some_provider' } do describe 'GET' do it 'redirects to some_provider' do get :login @@ -474,7 +470,6 @@ describe AccountController, type: :controller do allow_any_instance_of(User).to receive(:change_password_allowed?).and_return(false) end - describe "Missing flash data for user initiated password change" do before do post 'change_password', @@ -810,7 +805,8 @@ describe AccountController, type: :controller do it 'preserves the back url' do expect(response).to redirect_to( - '/login?back_url=https%3A%2F%2Fexample.net%2Fsome_back_url') + '/login?back_url=https%3A%2F%2Fexample.net%2Fsome_back_url' + ) end it 'calls the user_registered callback' do diff --git a/spec/controllers/activities_controller_spec.rb b/spec/controllers/activities_controller_spec.rb index 048a0e6e11..924f3992fc 100644 --- a/spec/controllers/activities_controller_spec.rb +++ b/spec/controllers/activities_controller_spec.rb @@ -69,13 +69,13 @@ describe ActivitiesController, type: :controller do render_views it do - assert_select 'h3', - content: /#{3.day.ago.to_date.day}/, - sibling: { tag: 'dl', - child: { tag: 'dt', - attributes: { class: /work_package/ }, - child: { tag: 'a', - content: /#{ERB::Util.html_escape(work_package.subject)}/ } } } + assert_select 'h3', + content: /#{3.day.ago.to_date.day}/, + sibling: { tag: 'dl', + child: { tag: 'dt', + attributes: { class: /work_package/ }, + child: { tag: 'a', + content: /#{ERB::Util.html_escape(work_package.subject)}/ } } } end end @@ -139,9 +139,9 @@ describe ActivitiesController, type: :controller do before { get 'index', format: 'atom' } it do - assert_select 'entry', - child: { tag: 'link', - attributes: { href: Regexp.new("/work_packages/#{wp_1.id}#") } } + assert_select 'entry', + child: { tag: 'link', + attributes: { href: Regexp.new("/work_packages/#{wp_1.id}#") } } end end diff --git a/spec/controllers/categories_controller_spec.rb b/spec/controllers/categories_controller_spec.rb index 75f7e0a2d2..c0b5af2777 100644 --- a/spec/controllers/categories_controller_spec.rb +++ b/spec/controllers/categories_controller_spec.rb @@ -31,16 +31,16 @@ require 'spec_helper' describe CategoriesController, type: :controller do let(:user) { FactoryBot.create(:user) } let(:project) { FactoryBot.create(:project) } - let(:role) { + let(:role) do FactoryBot.create(:role, - permissions: [:manage_categories]) - } - let(:member) { + permissions: [:manage_categories]) + end + let(:member) do FactoryBot.create(:member, - project: project, - principal: user, - roles: [role]) - } + project: project, + principal: user, + roles: [role]) + end before do member @@ -92,17 +92,16 @@ describe CategoriesController, type: :controller do end describe '#edit' do - let(:category) { + let(:category) do FactoryBot.create(:category, - project: project) - } + project: project) + end subject { response } before do get :edit, params: { id: category_id } end - context 'valid category' do let(:category_id) { category.id } it { is_expected.to be_successful } @@ -119,10 +118,10 @@ describe CategoriesController, type: :controller do let(:name) { 'Testing' } context 'valid category' do - let(:category) { + let(:category) do FactoryBot.create(:category, - project: project) - } + project: project) + end before do post :update, @@ -161,17 +160,17 @@ describe CategoriesController, type: :controller do end describe '#destroy' do - let(:category) { + let(:category) do FactoryBot.create(:category, - project: project) - } - let(:work_package) { + project: project) + end + let(:work_package) do FactoryBot.create(:work_package, - project: project, - category: category) - } + project: project, + category: category) + end - before do category end + before { category } shared_examples_for :delete do subject { Category.find_by(id: category.id) } @@ -210,10 +209,10 @@ describe CategoriesController, type: :controller do end describe '#reassign' do - let(:target) { + let(:target) do FactoryBot.create(:category, - project: project) - } + project: project) + end before do work_package diff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rb index 3fd311a7d7..282fdddc24 100644 --- a/spec/controllers/concerns/auth_source_sso_spec.rb +++ b/spec/controllers/concerns/auth_source_sso_spec.rb @@ -110,9 +110,9 @@ describe MyController, type: :controller do end context 'when the user is invited' do - let!(:user) { + let!(:user) do FactoryBot.create :user, login: login, status: Principal.statuses[:invited], auth_source_id: auth_source.id - } + end it "should log in given user and activate it" do expect(response.body.squish).to have_content("Username h.wurst") diff --git a/spec/controllers/concerns/omniauth_login_spec.rb b/spec/controllers/concerns/omniauth_login_spec.rb index 69fa04dc9b..1aa0c8f03e 100644 --- a/spec/controllers/concerns/omniauth_login_spec.rb +++ b/spec/controllers/concerns/omniauth_login_spec.rb @@ -34,7 +34,7 @@ describe AccountController, type: :controller do User.current = nil end - context 'GET #omniauth_login', with_settings: { self_registration: Setting::SelfRegistration.automatic} do + context 'GET #omniauth_login', with_settings: { self_registration: Setting::SelfRegistration.automatic } do describe 'with on-the-fly registration' do context 'providing all required fields' do let(:omniauth_hash) do @@ -44,8 +44,7 @@ describe AccountController, type: :controller do info: { name: 'foo', email: 'foo@bar.com', first_name: 'foo', - last_name: 'bar' - } + last_name: 'bar' } ) end @@ -109,8 +108,7 @@ describe AccountController, type: :controller do uid: 'foo', info: { email: 'whattheheck@example.com', first_name: 'what', - last_name: 'theheck' - }, + last_name: 'theheck' }, extra: { raw_info: { real_uid: 'bar@example.org', first_name: 'foo', @@ -164,7 +162,7 @@ describe AccountController, type: :controller do provider: 'google', uid: '123545', info: { name: 'foo', email: 'foo@bar.com' } - # first_name and last_name not set + # first_name and last_name not set ) end @@ -184,7 +182,8 @@ describe AccountController, type: :controller do auth_source_registration = omniauth_hash.merge( omniauth: true, - timestamp: Time.new) + timestamp: Time.new + ) session[:auth_source_registration] = auth_source_registration post :register, params: { @@ -208,7 +207,8 @@ describe AccountController, type: :controller do before do session[:auth_source_registration] = omniauth_hash.merge( omniauth: true, - timestamp: Time.new - 42.days) + timestamp: Time.new - 42.days + ) end it 'does not register the user when providing all the missing fields' do @@ -252,8 +252,7 @@ describe AccountController, type: :controller do info: { name: 'foo', email: 'foo@bar.com', first_name: 'foo', - last_name: 'bar' - } + last_name: 'bar' } ) end @@ -281,14 +280,13 @@ describe AccountController, type: :controller do uid: '123545', info: { name: 'foo', last_name: 'bar', - email: 'foo@bar.com' - } + email: 'foo@bar.com' } ) end let(:user) do FactoryBot.build(:user, force_password_change: false, - identity_url: 'google:123545') + identity_url: 'google:123545') end before do @@ -502,8 +500,7 @@ describe AccountController, type: :controller do provider: 'google', # id is deliberately missing here to make the auth_hash invalid info: { name: 'foo', - email: 'foo@bar.com' - } + email: 'foo@bar.com' } ) end diff --git a/spec/controllers/concerns/user_invitation_spec.rb b/spec/controllers/concerns/user_invitation_spec.rb index 30bc07b389..25900a3751 100644 --- a/spec/controllers/concerns/user_invitation_spec.rb +++ b/spec/controllers/concerns/user_invitation_spec.rb @@ -52,7 +52,7 @@ describe UserInvitation do let!(:token) { FactoryBot.create :invitation_token, user: user } it 'notifies listeners of the re-invite' do - expect(OpenProject::Notifications).to receive(:send) do |event, new_token| + expect(OpenProject::Notifications).to receive(:send) do |event, _new_token| expect(event).to eq 'user_reinvited' end diff --git a/spec/controllers/copy_projects_controller_spec.rb b/spec/controllers/copy_projects_controller_spec.rb index f6103303a1..f60f662cd5 100644 --- a/spec/controllers/copy_projects_controller_spec.rb +++ b/spec/controllers/copy_projects_controller_spec.rb @@ -87,7 +87,10 @@ describe CopyProjectsController, type: :controller do end shared_examples_for 'successful copy' do - it { expect(flash[:notice]).to eq(I18n.t('copy_project.started', source_project_name: source_project.name, target_project_name: target_project_name)) } + it { + expect(flash[:notice]).to eq(I18n.t('copy_project.started', source_project_name: source_project.name, + target_project_name: target_project_name)) + } end def copy_project(project) @@ -136,7 +139,7 @@ describe CopyProjectsController, type: :controller do true end - let(:permission) { [:copy_projects, :add_project] } + let(:permission) { %i[copy_projects add_project] } let(:project) { FactoryBot.create(:project, public: false) } it_should_behave_like 'a controller action which needs project permissions' diff --git a/spec/controllers/enumerations_controller.rb b/spec/controllers/enumerations_controller.rb index e5c13495c8..11dee32023 100644 --- a/spec/controllers/enumerations_controller.rb +++ b/spec/controllers/enumerations_controller.rb @@ -29,7 +29,7 @@ require 'spec_helper' describe EnumerationsController, type: :controller do - before do allow(controller).to receive(:require_admin).and_return(true) end + before { allow(controller).to receive(:require_admin).and_return(true) } describe '#destroy' do describe '#priority' do @@ -51,10 +51,10 @@ describe EnumerationsController, type: :controller do describe 'in use' do let!(:enum_to_reassign) { FactoryBot.create(:priority_high) } - let!(:work_package) { + let!(:work_package) do FactoryBot.create(:work_package, - priority: enum_to_delete) - } + priority: enum_to_delete) + end describe 'no reassign' do before do diff --git a/spec/controllers/forums_controller_spec.rb b/spec/controllers/forums_controller_spec.rb index 2a26027239..a89cc3377d 100644 --- a/spec/controllers/forums_controller_spec.rb +++ b/spec/controllers/forums_controller_spec.rb @@ -38,7 +38,6 @@ describe ForumsController, type: :controller do end describe '#index' do - context 'public project' do let(:project) { FactoryBot.create(:public_project) } let!(:role) { FactoryBot.create(:non_member) } @@ -160,16 +159,16 @@ describe ForumsController, type: :controller do describe '#move' do let(:project) { FactoryBot.create(:project) } - let!(:forum_1) { + let!(:forum_1) do FactoryBot.create(:forum, - project: project, - position: 1) - } - let!(:forum_2) { + project: project, + position: 1) + end + let!(:forum_2) do FactoryBot.create(:forum, - project: project, - position: 2) - } + project: project, + position: 2) + end before do allow(@controller).to receive(:authorize).and_return(true) @@ -198,10 +197,10 @@ describe ForumsController, type: :controller do end describe '#update' do - let!(:forum) { + let!(:forum) do FactoryBot.create(:forum, name: 'Forum name', - description: 'Forum description') - } + description: 'Forum description') + end before do expect(@controller).to receive(:authorize) @@ -257,22 +256,22 @@ describe ForumsController, type: :controller do describe '#sticky' do let!(:message1) { FactoryBot.create(:message, forum: forum) } let!(:message2) { FactoryBot.create(:message, forum: forum) } - let!(:sticked_message1) { + let!(:sticked_message1) do FactoryBot.create(:message, forum_id: forum.id, - subject: 'How to', - content: 'How to install this cool app', - sticky: '1', - sticked_on: Time.now - 2.minute) - } + subject: 'How to', + content: 'How to install this cool app', + sticky: '1', + sticked_on: Time.now - 2.minute) + end - let!(:sticked_message2) { + let!(:sticked_message2) do FactoryBot.create(:message, forum_id: forum.id, - subject: 'FAQ', - content: 'Frequestly asked question', - sticky: '1', - sticked_on: + subject: 'FAQ', + content: 'Frequestly asked question', + sticky: '1', + sticked_on: Time.now - 1.minute) - } + end describe 'all sticky messages' do before do diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 5f46e39d73..457a00a4be 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -177,9 +177,9 @@ describe GroupsController, type: :controller do end it 'should forbid create' do - expect { + expect do post :create, params: { group: { lastname: 'New group' } } - }.not_to change { Group.count } + end.not_to change { Group.count } expect(response).not_to be_successful expect(response.status).to eq 403 diff --git a/spec/controllers/homescreen_controller_spec.rb b/spec/controllers/homescreen_controller_spec.rb index 89334e6fad..0e439067e9 100644 --- a/spec/controllers/homescreen_controller_spec.rb +++ b/spec/controllers/homescreen_controller_spec.rb @@ -38,9 +38,9 @@ describe HomescreenController, type: :controller do get :index end - let(:all_blocks) { + let(:all_blocks) do %w(administration community my_account projects users) - } + end let(:show_welcome) { false } diff --git a/spec/controllers/journals_controller_spec.rb b/spec/controllers/journals_controller_spec.rb index 90420c0ecc..f5ead1ff4f 100644 --- a/spec/controllers/journals_controller_spec.rb +++ b/spec/controllers/journals_controller_spec.rb @@ -32,22 +32,22 @@ describe JournalsController, type: :controller do let(:user) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) } let(:project) { FactoryBot.create(:project_with_types) } let(:role) { FactoryBot.create(:role, permissions: permissions) } - let(:member) { + let(:member) do FactoryBot.build(:member, project: project, - roles: [role], - principal: user) - } - let(:work_package) { + roles: [role], + principal: user) + end + let(:work_package) do FactoryBot.build(:work_package, type: project.types.first, - author: user, - project: project, - description: '') - } - let(:journal) { + author: user, + project: project, + description: '') + end + let(:journal) do FactoryBot.create(:work_package_journal, - journable: work_package, - user: user) - } + journable: work_package, + user: user) + end let(:permissions) { [:view_work_packages] } before do diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 8fe1144dfb..cb874b7fe4 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -33,11 +33,11 @@ describe MembersController, type: :controller do let(:user) { FactoryBot.create(:user) } let(:project) { FactoryBot.create(:project, identifier: 'pet_project') } let(:role) { FactoryBot.create(:role) } - let(:member) { + let(:member) do FactoryBot.create(:member, project: project, - user: user, - roles: [role]) - } + user: user, + roles: [role]) + end before do allow(User).to receive(:current).and_return(admin) @@ -67,9 +67,9 @@ describe MembersController, type: :controller do u.reload expect(u.memberships.size).to be >= 1 - expect(u.memberships.find { |m| + expect(u.memberships.find do |m| expect(m.roles).to include(role) - }).not_to be_nil + end).not_to be_nil end end end @@ -84,7 +84,8 @@ describe MembersController, type: :controller do :member, project: project_2, user: admin, - roles: [role_1]) + roles: [role_1] + ) end before do @@ -211,13 +212,13 @@ describe MembersController, type: :controller do end describe '#update' do - let(:action) { + let(:action) do post :update, params: { id: member.id, member: { role_ids: [role2.id], user_id: user.id } } - } + end let(:role2) { FactoryBot.create(:role) } before do diff --git a/spec/controllers/my_controller_spec.rb b/spec/controllers/my_controller_spec.rb index adb9dee8ad..13c8c110fc 100644 --- a/spec/controllers/my_controller_spec.rb +++ b/spec/controllers/my_controller_spec.rb @@ -169,7 +169,6 @@ describe MyController, type: :controller do expect(request.path).to eq(my_settings_path) expect(flash[:notice]).to eql I18n.t(:notice_account_updated) - end context 'when user is invalid' do diff --git a/spec/controllers/news/comments_controller_spec.rb b/spec/controllers/news/comments_controller_spec.rb index 5112afc832..6afd0b532d 100644 --- a/spec/controllers/news/comments_controller_spec.rb +++ b/spec/controllers/news/comments_controller_spec.rb @@ -51,10 +51,10 @@ describe News::CommentsController, type: :controller do end it "doesn't create a comment when it is invalid" do - expect { + expect do post :create, params: { news_id: news.id, comment: { comments: '' } } expect(response).to redirect_to news_path(news) - }.not_to change { Comment.count } + end.not_to change { Comment.count } end end @@ -62,9 +62,9 @@ describe News::CommentsController, type: :controller do it 'deletes the comment and redirects to the news page' do comment = FactoryBot.create :comment, commented: news - expect { + expect do delete :destroy, params: { id: comment.id } - }.to change { Comment.count }.by -1 + end.to change { Comment.count }.by -1 expect(response).to redirect_to news_path(news) expect { comment.reload }.to raise_error ActiveRecord::RecordNotFound diff --git a/spec/controllers/news_controller_spec.rb b/spec/controllers/news_controller_spec.rb index 673578744d..e635f465ac 100644 --- a/spec/controllers/news_controller_spec.rb +++ b/spec/controllers/news_controller_spec.rb @@ -125,7 +125,6 @@ describe NewsController, type: :controller do expect(news.author).to eq user expect(news.project).to eq project - perform_enqueued_jobs expect(ActionMailer::Base.deliveries.size).to eq(1) diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 9164618291..7ac4501901 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -113,7 +113,6 @@ describe ProjectsController, type: :controller do context 'with default modules', with_settings: { default_projects_modules: %w(work_package_tracking repository) } do - it 'should create should preserve modules on validation failure' do expect do post :create, @@ -192,7 +191,7 @@ describe ProjectsController, type: :controller do # We need at least one givable role to make the user member let!(:role) { FactoryBot.create :role, permissions: [:view_project] } before do - non_member.update_attribute :permissions, [:add_project, :view_work_packages] + non_member.update_attribute :permissions, %i[add_project view_work_packages] login_as non_member_user end @@ -565,8 +564,8 @@ describe ProjectsController, type: :controller do it 'sets flash[:error]' do expect(flash[:error]).to include( - "You cannot update the project's available custom fields. The project is invalid:" - ) + "You cannot update the project's available custom fields. The project is invalid:" + ) end end end @@ -594,7 +593,7 @@ describe ProjectsController, type: :controller do params: { id: project.id, project: { - name: 'Test changed name', + name: 'Test changed name' } } diff --git a/spec/controllers/repositories_controller_spec.rb b/spec/controllers/repositories_controller_spec.rb index 3ee7543240..3f6799e981 100644 --- a/spec/controllers/repositories_controller_spec.rb +++ b/spec/controllers/repositories_controller_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -37,7 +38,7 @@ describe RepositoriesController, type: :controller do end let(:user) do FactoryBot.create(:user, member_in_project: project, - member_through_role: role) + member_through_role: role) end let(:role) { FactoryBot.create(:role, permissions: []) } let (:url) { 'file:///tmp/something/does/not/exist.svn' } @@ -45,9 +46,9 @@ describe RepositoriesController, type: :controller do let(:repository) do allow(Setting).to receive(:enabled_scm).and_return(['subversion']) repo = FactoryBot.build_stubbed(:repository_subversion, - scm_type: 'local', - url: url, - project: project) + scm_type: 'local', + url: url, + project: project) allow(repo).to receive(:default_branch).and_return('master') allow(repo).to receive(:branches).and_return(['master']) allow(repo).to receive(:save).and_return(true) @@ -127,14 +128,13 @@ describe RepositoriesController, type: :controller do context 'with #show and checkout' do render_views - let(:checkout_hash) { + let(:checkout_hash) do { 'subversion' => { 'enabled' => '1', 'text' => 'foo', - 'base_url' => 'http://localhost' - } + 'base_url' => 'http://localhost' } } - } + end before do allow(Setting).to receive(:repository_checkout_data).and_return(checkout_hash) @@ -154,9 +154,9 @@ describe RepositoriesController, type: :controller do let(:root_url) { repo_dir } let(:url) { "file://#{root_url}" } - let(:repository) { + let(:repository) do FactoryBot.create(:repository_subversion, project: project, url: url, root_url: url) - } + end describe 'commits per author graph' do before do @@ -164,10 +164,10 @@ describe RepositoriesController, type: :controller do end context 'requested by an authorized user' do - let(:role) { - FactoryBot.create(:role, permissions: [:browse_repository, - :view_commit_author_statistics]) - } + let(:role) do + FactoryBot.create(:role, permissions: %i[browse_repository + view_commit_author_statistics]) + end it 'should be successful' do expect(response).to be_successful @@ -221,10 +221,10 @@ describe RepositoriesController, type: :controller do end describe 'requested by a user with view_commit_author_statistics permission' do - let(:role) { - FactoryBot.create(:role, permissions: [:browse_repository, - :view_commit_author_statistics]) - } + let(:role) do + FactoryBot.create(:role, permissions: %i[browse_repository + view_commit_author_statistics]) + end it 'show the commits per author graph' do expect(assigns(:show_commits_per_author)).to eq(true) @@ -290,14 +290,13 @@ describe RepositoriesController, type: :controller do render_views let(:role) { FactoryBot.create(:role, permissions: [:browse_repository]) } - let(:checkout_hash) { + let(:checkout_hash) do { 'subversion' => { 'enabled' => '1', 'text' => 'foo', - 'base_url' => 'http://localhost' - } + 'base_url' => 'http://localhost' } } - } + end before do allow(Setting).to receive(:repository_checkout_data).and_return(checkout_hash) diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index cac8d07335..53df0fca7c 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -206,7 +206,7 @@ describe SearchController, type: :controller do end before do - get :index, params: { q: 'note'} + get :index, params: { q: 'note' } end it_behaves_like 'successful search' diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb index 96a41a0e5a..cf2808c2d0 100644 --- a/spec/controllers/statuses_controller_spec.rb +++ b/spec/controllers/statuses_controller_spec.rb @@ -91,7 +91,7 @@ describe StatusesController, type: :controller do context 'default' do let!(:status_default) do FactoryBot.create(:status, - is_default: true) + is_default: true) end before do @@ -156,7 +156,7 @@ describe StatusesController, type: :controller do shared_examples_for :destroyed do subject { Status.find_by(name: name) } - it { is_expected.to be_nil} + it { is_expected.to be_nil } end context 'unused' do diff --git a/spec/controllers/sys_controller_spec.rb b/spec/controllers/sys_controller_spec.rb index 529cc19257..d46a5878a4 100644 --- a/spec/controllers/sys_controller_spec.rb +++ b/spec/controllers/sys_controller_spec.rb @@ -29,18 +29,18 @@ require 'spec_helper' describe SysController, type: :controller do - let(:commit_role) { + let(:commit_role) do FactoryBot.create(:role, permissions: %i[commit_access browse_repository]) - } + end let(:browse_role) { FactoryBot.create(:role, permissions: [:browse_repository]) } let(:guest_role) { FactoryBot.create(:role, permissions: []) } let(:valid_user_password) { 'Top Secret Password' } - let(:valid_user) { + let(:valid_user) do FactoryBot.create(:user, login: 'johndoe', password: valid_user_password, password_confirmation: valid_user_password) - } + end let(:api_key) { '12345678' } @@ -76,9 +76,9 @@ describe SysController, type: :controller do valid_user_password ) - post 'repo_auth', params: {key: api_key, - repository: 'without-access', - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: 'without-access', + method: 'GET' } end it 'should respond 403 not allowed' do @@ -102,17 +102,17 @@ describe SysController, type: :controller do end it 'should respond 200 okay dokay for GET' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET' } expect(response.code).to eq('200') end it 'should respond 403 not allowed for POST' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'POST'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'POST' } expect(response.code).to eq('403') end @@ -133,17 +133,17 @@ describe SysController, type: :controller do end it 'should respond 200 okay dokay for GET' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET' } expect(response.code).to eq('200') end it 'should respond 200 okay dokay for POST' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'POST'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'POST' } expect(response.code).to eq('200') end @@ -161,9 +161,9 @@ describe SysController, type: :controller do valid_user_password + 'made invalid' ) - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET' } end it 'should respond 401 auth required' do @@ -179,9 +179,9 @@ describe SysController, type: :controller do valid_user_password ) - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET' } end it 'should respond 403 not allowed' do @@ -205,9 +205,9 @@ describe SysController, type: :controller do valid_user_password ) - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET' } end it 'should respond 200 OK' do @@ -217,9 +217,9 @@ describe SysController, type: :controller do context 'for invalid credentials' do before(:each) do - post 'repo_auth', params: {key: api_key, - repository: 'any-repo', - method: 'GET'} + post 'repo_auth', params: { key: api_key, + repository: 'any-repo', + method: 'GET' } end it 'should respond 401 auth required' do @@ -235,9 +235,9 @@ describe SysController, type: :controller do valid_user.login, valid_user_password ) - post 'repo_auth', params: {key: 'not_the_api_key', - repository: 'any-repo', - method: 'GET'} + post 'repo_auth', params: { key: 'not_the_api_key', + repository: 'any-repo', + method: 'GET' } expect(response.code).to eq('403') expect(response.body) @@ -251,9 +251,9 @@ describe SysController, type: :controller do 'invalid' ) - post 'repo_auth', params: {key: 'not_the_api_key', - repository: 'any-repo', - method: 'GET'} + post 'repo_auth', params: { key: 'not_the_api_key', + repository: 'any-repo', + method: 'GET' } expect(response.code).to eq('403') expect(response.body) @@ -274,12 +274,12 @@ describe SysController, type: :controller do valid_user_password ) - post 'repo_auth', params: {key: api_key, - repository: 'without-access', - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: 'without-access', + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } end it 'should respond 403 not allowed' do @@ -303,23 +303,23 @@ describe SysController, type: :controller do end it 'should respond 200 okay dokay for read-only access' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } expect(response.code).to eq('200') end it 'should respond 403 not allowed for write (push)' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'POST', - git_smart_http: '1', - uri: "/git/#{project.identifier}/git-receive-pack", - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'POST', + git_smart_http: '1', + uri: "/git/#{project.identifier}/git-receive-pack", + location: '/git' } expect(response.code).to eq('403') end @@ -341,23 +341,23 @@ describe SysController, type: :controller do end it 'should respond 200 okay dokay for GET' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } expect(response.code).to eq('200') end it 'should respond 200 okay dokay for POST' do - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'POST', - git_smart_http: '1', - uri: "/git/#{project.identifier}/git-receive-pack", - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'POST', + git_smart_http: '1', + uri: "/git/#{project.identifier}/git-receive-pack", + location: '/git' } expect(response.code).to eq('200') end @@ -376,12 +376,12 @@ describe SysController, type: :controller do valid_user_password + 'made invalid' ) - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } end it 'should respond 401 auth required' do @@ -398,12 +398,12 @@ describe SysController, type: :controller do valid_user_password ) - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } end it 'should respond 403 not allowed' do @@ -425,12 +425,12 @@ describe SysController, type: :controller do valid_user.login, valid_user_password ) - post 'repo_auth', params: {key: api_key, - repository: project.identifier, - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: project.identifier, + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } end it 'should respond 200 OK' do @@ -440,12 +440,12 @@ describe SysController, type: :controller do context 'for invalid credentials' do before(:each) do - post 'repo_auth', params: {key: api_key, - repository: 'any-repo', - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: api_key, + repository: 'any-repo', + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } end it 'should respond 401 auth required' do @@ -462,12 +462,12 @@ describe SysController, type: :controller do valid_user_password ) - post 'repo_auth', params: {key: 'not_the_api_key', - repository: 'any-repo', - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: 'not_the_api_key', + repository: 'any-repo', + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } expect(response.code).to eq('403') expect(response.body) @@ -481,12 +481,12 @@ describe SysController, type: :controller do 'invalid' ) - post 'repo_auth', params: {key: 'not_the_api_key', - repository: 'any-repo', - method: 'GET', - git_smart_http: '1', - uri: '/git', - location: '/git'} + post 'repo_auth', params: { key: 'not_the_api_key', + repository: 'any-repo', + method: 'GET', + git_smart_http: '1', + uri: '/git', + location: '/git' } expect(response.code).to eq('403') expect(response.body) @@ -497,10 +497,10 @@ describe SysController, type: :controller do end describe '#cached_user_login' do - let(:cache_key) { + let(:cache_key) do OpenProject::RepositoryAuthentication::CACHE_PREFIX + Digest::SHA1.hexdigest("#{valid_user.login}#{valid_user_password}") - } + end let(:cache_expiry) { OpenProject::RepositoryAuthentication::CACHE_EXPIRES_AFTER } it 'should call user_login only once when called twice' do @@ -546,9 +546,9 @@ describe SysController, type: :controller do let(:last_updated) { nil } def request_storage - get 'update_required_storage', params: {key: apikey, - id: id, - force: force} + get 'update_required_storage', params: { key: apikey, + id: id, + force: force } end context 'missing project' do @@ -578,9 +578,9 @@ describe SysController, type: :controller do context 'stubbed repository' do let(:project) { FactoryBot.build_stubbed(:project) } let(:id) { project.id } - let(:repository) { + let(:repository) do FactoryBot.build_stubbed(:repository_subversion, url: url, root_url: url) - } + end before do allow(Project).to receive(:find).and_return(project) @@ -619,9 +619,9 @@ describe SysController, type: :controller do let(:project) { FactoryBot.create(:project) } let(:id) { project.id } - let(:repository) { + let(:repository) do FactoryBot.create(:repository_subversion, project: project, url: url, root_url: url) - } + end before do allow(Project).to receive(:find).and_return(project) diff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/types_controller_spec.rb index dfa1090b24..8843d50962 100644 --- a/spec/controllers/types_controller_spec.rb +++ b/spec/controllers/types_controller_spec.rb @@ -31,12 +31,12 @@ require 'spec_helper' describe TypesController, type: :controller do let(:project) do FactoryBot.create(:project, - work_package_custom_fields: [custom_field_2]) + work_package_custom_fields: [custom_field_2]) end let(:custom_field_1) do FactoryBot.create(:work_package_custom_field, - field_format: 'string', - is_for_all: true) + field_format: 'string', + is_for_all: true) end let(:custom_field_2) { FactoryBot.create(:work_package_custom_field) } let(:status_0) { FactoryBot.create(:status) } @@ -168,9 +168,9 @@ describe TypesController, type: :controller do let!(:existing_type) { FactoryBot.create(:type, name: 'Existing type') } let!(:workflow) do FactoryBot.create(:workflow, - old_status: status_0, - new_status: status_1, - type_id: existing_type.id) + old_status: status_0, + new_status: status_1, + type_id: existing_type.id) end let(:params) do @@ -200,8 +200,8 @@ describe TypesController, type: :controller do render_views let(:type) do FactoryBot.create(:type, name: 'My type', - is_milestone: true, - projects: [project]) + is_milestone: true, + projects: [project]) end before do @@ -219,8 +219,8 @@ describe TypesController, type: :controller do render_views let(:type) do FactoryBot.create(:type, name: 'My type', - is_milestone: true, - projects: [project]) + is_milestone: true, + projects: [project]) end before do @@ -230,15 +230,17 @@ describe TypesController, type: :controller do it { expect(response).to be_successful } it { expect(response).to render_template 'edit' } it { expect(response).to render_template 'types/form/_projects' } - it { expect(response.body).to have_selector "input[@name='type[project_ids][]'][@value='#{project.id}'][@checked='checked']" } + it { + expect(response.body).to have_selector "input[@name='type[project_ids][]'][@value='#{project.id}'][@checked='checked']" + } end describe 'POST update' do let(:project2) { FactoryBot.create(:project) } let(:type) do FactoryBot.create(:type, name: 'My type', - is_milestone: true, - projects: [project, project2]) + is_milestone: true, + projects: [project, project2]) end describe 'WITH type rename' do @@ -327,14 +329,14 @@ describe TypesController, type: :controller do describe 'detroy type in use should fail' do let(:project2) do FactoryBot.create(:project, - work_package_custom_fields: [custom_field_2], - types: [type2]) + work_package_custom_fields: [custom_field_2], + types: [type2]) end let!(:work_package) do FactoryBot.create(:work_package, - author: current_user, - type: type2, - project: project2) + author: current_user, + type: type2, + project: project2) end let(:params) { { 'id' => type2.id } } diff --git a/spec/controllers/users/memberships_controller_spec.rb b/spec/controllers/users/memberships_controller_spec.rb index 42b43929c2..c0acaa9cf6 100644 --- a/spec/controllers/users/memberships_controller_spec.rb +++ b/spec/controllers/users/memberships_controller_spec.rb @@ -54,9 +54,9 @@ describe Users::MembershipsController, type: :controller do expect(response).to redirect_to(controller: '/users', action: 'edit', id: user.id, tab: 'memberships') - is_member = user.reload.memberships.any? { |m| + is_member = user.reload.memberships.any? do |m| m.project_id == project.id && m.role_ids.include?(role.id) - } + end expect(is_member).to eql(true) end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 796f15ff8b..d5d235a18c 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -86,7 +86,7 @@ describe UsersController, type: :controller do describe 'GET deletion_info' do describe "WHEN the current user is the requested user WHEN the setting users_deletable_by_self is set to true" do - let(:params) { {'id' => user.id.to_s} } + let(:params) { { 'id' => user.id.to_s } } before do allow(Setting).to receive(:users_deletable_by_self?).and_return(true) @@ -107,7 +107,7 @@ describe UsersController, type: :controller do describe "WHEN the current user is the requested user WHEN the setting users_deletable_by_self is set to false" do - let(:params) { {'id' => user.id.to_s} } + let(:params) { { 'id' => user.id.to_s } } before do allow(Setting).to receive(:users_deletable_by_self?).and_return(false) @@ -121,7 +121,7 @@ describe UsersController, type: :controller do end describe 'WHEN the current user is the anonymous user' do - let(:params) { {'id' => anonymous.id.to_s} } + let(:params) { { 'id' => anonymous.id.to_s } } before do as_logged_in_user anonymous do @@ -139,7 +139,7 @@ describe UsersController, type: :controller do describe "WHEN the current user is admin WHEN the setting users_deletable_by_admins is set to true" do - let(:params) { {'id' => user.id.to_s} } + let(:params) { { 'id' => user.id.to_s } } before do allow(Setting).to receive(:users_deletable_by_admins?).and_return(true) @@ -160,7 +160,7 @@ describe UsersController, type: :controller do describe "WHEN the current user is admin WHEN the setting users_deletable_by_admins is set to false" do - let(:params) { {'id' => user.id.to_s} } + let(:params) { { 'id' => user.id.to_s } } before do allow(Setting).to receive(:users_deletable_by_admins?).and_return(false) @@ -182,7 +182,7 @@ describe UsersController, type: :controller do before do as_logged_in_user normal_user do - post :resend_invitation, params: {id: invited_user.id} + post :resend_invitation, params: { id: invited_user.id } end end @@ -197,7 +197,7 @@ describe UsersController, type: :controller do as_logged_in_user admin do perform_enqueued_jobs do - post :resend_invitation, params: {id: invited_user.id} + post :resend_invitation, params: { id: invited_user.id } end end end @@ -217,7 +217,7 @@ describe UsersController, type: :controller do end describe 'POST destroy' do - let(:base_params) { {'id' => user.id.to_s, back_url: my_account_path} } + let(:base_params) { { 'id' => user.id.to_s, back_url: my_account_path } } context 'WHEN the password confirmation is missing' do before do disable_flash_sweep @@ -236,7 +236,7 @@ describe UsersController, type: :controller do context 'WHEN password confirmation is present' do let(:base_params) do - {'id' => user.id.to_s, :'_password_confirmation' => user_password, back_url: my_account_path} + { 'id' => user.id.to_s, :_password_confirmation => user_password, back_url: my_account_path } end describe "WHEN the current user is the requested one @@ -258,7 +258,6 @@ describe UsersController, type: :controller do describe "WHEN the current user is the requested one WHEN the setting users_deletable_by_self is set to false" do - before do disable_flash_sweep allow(Setting).to receive(:users_deletable_by_self?).and_return(false) @@ -273,7 +272,6 @@ describe UsersController, type: :controller do describe "WHEN the current user is the anonymous user EVEN when the setting login_required is set to false" do - before do allow(@controller).to receive(:find_current_user).and_return(anonymous) allow(Setting).to receive(:login_required?).and_return(false) @@ -311,13 +309,12 @@ describe UsersController, type: :controller do describe "WHEN the current user is the admin WHEN the given password does match WHEN the setting users_deletable_by_admins is set to true" do - before do disable_flash_sweep allow(Setting).to receive(:users_deletable_by_admins?).and_return(true) as_logged_in_user admin do - post :destroy, params: base_params.merge(:'_password_confirmation' => 'adminADMIN!') + post :destroy, params: base_params.merge('_password_confirmation': 'adminADMIN!') end end @@ -354,8 +351,8 @@ describe UsersController, type: :controller do as_logged_in_user admin do get :change_status_info, params: { - id: registered_user.id, - change_action: change_action + id: registered_user.id, + change_action: change_action } end end @@ -395,13 +392,13 @@ describe UsersController, type: :controller do describe '#change_status', with_settings: { - available_languages: %i(en de), - bcc_recipients: 1 + available_languages: %i(en de), + bcc_recipients: 1 } do describe 'WHEN activating a registered user' do let!(:registered_user) do FactoryBot.create(:user, status: User.statuses[:registered], - language: 'de') + language: 'de') end let(:user_limit_reached) { false } @@ -412,9 +409,9 @@ describe UsersController, type: :controller do as_logged_in_user admin do post :change_status, params: { - id: registered_user.id, - user: {status: User.statuses[:active]}, - activate: '1' + id: registered_user.id, + user: { status: User.statuses[:active] }, + activate: '1' } end end @@ -467,7 +464,8 @@ describe UsersController, type: :controller do shared_examples_for 'index action with enabled session lifetime and inactivity exceeded' do it 'logs out the user and redirects with a warning that he has been locked out' do - expect(response.redirect_url).to eq(signin_url + '?back_url=' + CGI::escape(@controller.url_for(controller: 'users', action: 'index'))) + expect(response.redirect_url).to eq(signin_url + '?back_url=' + CGI::escape(@controller.url_for(controller: 'users', + action: 'index'))) expect(User.current).not_to eq(admin) expect(flash[:warning]).to eq(I18n.t(:notice_forced_logout, ttl_time: Setting.session_ttl)) end @@ -553,25 +551,25 @@ describe UsersController, type: :controller do context 'fields' do let(:user) do FactoryBot.create(:user, firstname: 'Firstname', - admin: true, - login: 'testlogin', - mail_notification: 'all', - force_password_change: false) + admin: true, + login: 'testlogin', + mail_notification: 'all', + force_password_change: false) end let(:params) do { - id: user.id, - user: { - admin: false, - firstname: 'Changed', - login: 'changedlogin', - mail_notification: 'only_assigned', - force_password_change: true - }, - pref: { - hide_mail: '1', - comments_sorting: 'desc' - } + id: user.id, + user: { + admin: false, + firstname: 'Changed', + login: 'changedlogin', + mail_notification: 'only_assigned', + force_password_change: true + }, + pref: { + hide_mail: '1', + comments_sorting: 'desc' + } } end @@ -606,7 +604,7 @@ describe UsersController, type: :controller do before do as_logged_in_user(admin) do - put :update, params: {id: user.id, user: {force_password_change: 'true'}} + put :update, params: { id: user.id, user: { force_password_change: 'true' } } end user.reload end @@ -624,9 +622,9 @@ describe UsersController, type: :controller do as_logged_in_user admin do put :update, params: { - id: user.id, - user: {auth_source_id: '', password: 'newpassPASS!', - password_confirmation: 'newpassPASS!'} + id: user.id, + user: { auth_source_id: '', password: 'newpassPASS!', + password_confirmation: 'newpassPASS!' } } end @@ -644,8 +642,8 @@ describe UsersController, type: :controller do as_logged_in_user(admin) do put :update, params: { - id: user.id, - user: {password: 'changedpass!', password_confirmation: 'changedpass!'} + id: user.id, + user: { password: 'changedpass!', password_confirmation: 'changedpass!' } } end @@ -658,13 +656,13 @@ describe UsersController, type: :controller do it 'should redirect to the login page' do post :create, params: { - user: { - login: 'psmith', - firstname: 'Paul', - lastname: 'Smith' - }, - password: 'psmithPSMITH09', - password_confirmation: 'psmithPSMITH09' + user: { + login: 'psmith', + firstname: 'Paul', + lastname: 'Smith' + }, + password: 'psmithPSMITH09', + password_confirmation: 'psmithPSMITH09' } expect(response).to redirect_to '/login?back_url=http%3A%2F%2Ftest.host%2Fusers' end @@ -674,7 +672,7 @@ describe UsersController, type: :controller do describe 'general' do before do as_logged_in_user user do - get :show, params: {id: user.id} + get :show, params: { id: user.id } end end @@ -732,7 +730,7 @@ describe UsersController, type: :controller do allow(User).to receive(:current).and_return(user.reload) allow_any_instance_of(User).to receive(:reported_work_package_count).and_return(42) - get :show, params: {id: user.id} + get :show, params: { id: user.id } end it 'should include the number of reported work packages' do diff --git a/spec/controllers/versions_controller_spec.rb b/spec/controllers/versions_controller_spec.rb index 08d5bec4da..36081c60be 100644 --- a/spec/controllers/versions_controller_spec.rb +++ b/spec/controllers/versions_controller_spec.rb @@ -174,7 +174,7 @@ describe VersionsController, type: :controller do it { expect(response).to be_successful } it { expect(response).to render_template('show') } - it {assert_select 'h2', content: version2.name } + it { assert_select 'h2', content: version2.name } subject { assigns(:version) } it { is_expected.to eq(version2) } diff --git a/spec/controllers/wiki_controller_spec.rb b/spec/controllers/wiki_controller_spec.rb index 35acd66bb8..300601029d 100644 --- a/spec/controllers/wiki_controller_spec.rb +++ b/spec/controllers/wiki_controller_spec.rb @@ -237,7 +237,7 @@ describe WikiController, type: :controller do end end end - end # describe 'actions' + end describe 'view related stuff' do render_views @@ -472,7 +472,9 @@ describe WikiController, type: :controller do # Expect to set back ref id expect(flash[:_related_wiki_page_id]).to eq @page_with_content.id - assert_select "#content a[href='#{new_child_project_wiki_path(project_id: @project, id: @page_with_content.slug)}']", 'Wiki page' + path = new_child_project_wiki_path(project_id: @project, id: @page_with_content.slug) + + assert_select "#content a[href='#{path}']", 'Wiki page' end end @@ -512,7 +514,8 @@ describe WikiController, type: :controller do expect(response).to be_successful - assert_select ".toolbar-items a[href='#{new_child_project_wiki_path(project_id: @project, id: 'wiki')}']", 'Wiki page' + assert_select ".toolbar-items a[href='#{new_child_project_wiki_path(project_id: @project, id: 'wiki')}']", +'Wiki page' end end diff --git a/spec/controllers/wiki_menu_items_controller_spec.rb b/spec/controllers/wiki_menu_items_controller_spec.rb index 02ae68b2b7..128ffc8ab1 100644 --- a/spec/controllers/wiki_menu_items_controller_spec.rb +++ b/spec/controllers/wiki_menu_items_controller_spec.rb @@ -36,7 +36,9 @@ describe WikiMenuItemsController, type: :controller do let(:wiki) { project.wiki } let(:wiki_page) { FactoryBot.create(:wiki_page, wiki: wiki) } # first wiki page without child pages - let!(:top_level_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, :with_menu_item_options, wiki: wiki, name: wiki_page.slug) } + let!(:top_level_wiki_menu_item) do + FactoryBot.create(:wiki_menu_item, :with_menu_item_options, wiki: wiki, name: wiki_page.slug) + end before :each do # log in user @@ -46,20 +48,24 @@ describe WikiMenuItemsController, type: :controller do describe '#edit' do # more wiki pages with menu items let(:another_wiki_page) { FactoryBot.create(:wiki_page, wiki: wiki) } # second wiki page with two child pages - let!(:another_wiki_page_top_level_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, wiki: wiki, name: another_wiki_page.slug) } + let!(:another_wiki_page_top_level_wiki_menu_item) do + FactoryBot.create(:wiki_menu_item, wiki: wiki, name: another_wiki_page.slug) + end # child pages of another_wiki_page let(:child_page) { FactoryBot.create(:wiki_page, parent: another_wiki_page, wiki: wiki) } let!(:child_page_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, wiki: wiki, name: child_page.slug) } let(:another_child_page) { FactoryBot.create(:wiki_page, parent: another_wiki_page, wiki: wiki) } - let!(:another_child_page_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, wiki: wiki, name: another_child_page.slug, parent: top_level_wiki_menu_item) } + let!(:another_child_page_wiki_menu_item) do + FactoryBot.create(:wiki_menu_item, wiki: wiki, name: another_child_page.slug, parent: top_level_wiki_menu_item) + end let(:grand_child_page) { FactoryBot.create(:wiki_page, parent: child_page, wiki: wiki) } let!(:grand_child_page_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, wiki: wiki, name: grand_child_page.slug) } context 'when no parent wiki menu item has been configured yet' do context 'and it is a child page' do - before do get :edit, params: { project_id: project.id, id: child_page.slug } end + before { get :edit, params: { project_id: project.id, id: child_page.slug } } subject { response } it 'preselects the wiki menu item of the parent page as parent wiki menu item option' do @@ -84,7 +90,7 @@ describe WikiMenuItemsController, type: :controller do end context 'when a parent wiki menu item has already been configured' do - before do get :edit, params: { project_id: project.id, id: another_child_page.slug } end + before { get :edit, params: { project_id: project.id, id: another_child_page.slug } } subject { response } it 'preselects the parent wiki menu item that is already assigned' do @@ -103,7 +109,7 @@ describe WikiMenuItemsController, type: :controller do describe '#select_main_menu_item' do include_context 'when there is one more wiki page with a child page' - before do get :select_main_menu_item, params: { project_id: project, id: wiki_page.id } end + before { get :select_main_menu_item, params: { project_id: project, id: wiki_page.id } } subject { assigns['possible_wiki_pages'] } context 'when selecting a new wiki page to replace the current main menu item' do diff --git a/spec/controllers/work_packages/bulk_controller_spec.rb b/spec/controllers/work_packages/bulk_controller_spec.rb index 6456cf4bd1..99fe99e7d4 100644 --- a/spec/controllers/work_packages/bulk_controller_spec.rb +++ b/spec/controllers/work_packages/bulk_controller_spec.rb @@ -180,7 +180,9 @@ describe WorkPackages::BulkController, type: :controller do end describe '#project' do - it { assert_select 'select', { attributes: { name: "work_package[custom_field_values][#{custom_field_2.id}]" } }, false } + it { + assert_select 'select', { attributes: { name: "work_package[custom_field_values][#{custom_field_2.id}]" } }, false + } end end end @@ -223,7 +225,9 @@ describe WorkPackages::BulkController, type: :controller do context 'when updating two work packages with differing whitelisted params' do let!(:work_package_ids) { [work_package_1.id, work_package_3.id] } - let!(:role_with_permission_to_add_watchers) { FactoryBot.create(:role, permissions: role.permissions + [:add_work_package_watchers]) } + let!(:role_with_permission_to_add_watchers) do + FactoryBot.create(:role, permissions: role.permissions + [:add_work_package_watchers]) + end let!(:other_user) { FactoryBot.create :user } let!(:other_member_1) do @@ -673,7 +677,8 @@ describe WorkPackages::BulkController, type: :controller do describe 'w/o the cleanup being successful' do before do - expect(WorkPackage).to receive(:cleanup_associated_before_destructing_if_required).with([stub_work_package], user, params['to_do']).and_return false + expect(WorkPackage).to receive(:cleanup_associated_before_destructing_if_required).with([stub_work_package], user, + params['to_do']).and_return false as_logged_in_user(user) do delete :destroy, params: params diff --git a/spec/controllers/work_packages/moves_controller_spec.rb b/spec/controllers/work_packages/moves_controller_spec.rb index 8cf4ee735c..f7fd424a40 100644 --- a/spec/controllers/work_packages/moves_controller_spec.rb +++ b/spec/controllers/work_packages/moves_controller_spec.rb @@ -33,11 +33,11 @@ describe WorkPackages::MovesController, type: :controller do let(:role) do FactoryBot.create :role, permissions: %i(move_work_packages - view_work_packages - add_work_packages - edit_work_packages - assign_versions - manage_subtasks) + view_work_packages + add_work_packages + edit_work_packages + assign_versions + manage_subtasks) end let(:type) { FactoryBot.create :type } let(:type_2) { FactoryBot.create :type } @@ -120,12 +120,12 @@ describe WorkPackages::MovesController, type: :controller do let!(:source_member) { FactoryBot.create(:member, user: current_user, project: project, roles: [role]) } let!(:target_member) { FactoryBot.create(:member, user: current_user, project: target_project, roles: [role]) } let(:target_project) { FactoryBot.create(:project, public: false) } - let(:work_package_2) { + let(:work_package_2) do FactoryBot.create(:work_package, project_id: project.id, type: type_2, priority: priority) - } + end describe 'an issue to another project' do context 'w/o following' do @@ -242,7 +242,7 @@ describe WorkPackages::MovesController, type: :controller do shared_examples_for 'single note for moved work package' do it { expect(moved_work_package.journals.count).to eq(2) } - it { expect(moved_work_package.journals.sort_by(&:id).last.notes).to eq(note) } + it { expect(moved_work_package.journals.max_by(&:id).notes).to eq(note) } end describe 'move with given note' do @@ -447,7 +447,7 @@ describe WorkPackages::MovesController, type: :controller do params: { ids: [work_package.id, child_wp.id], copy: '', - new_project_id: to_project.id, + new_project_id: to_project.id } it 'reports the one child work package' do @@ -468,13 +468,13 @@ describe WorkPackages::MovesController, type: :controller do .not_to receive(:new) .with(child_wp, current_user) - expect { + expect do post :create, params: { ids: [work_package.id, child_wp.id], - copy: '', + copy: '' } - }.to change(WorkPackage, :count).by(2) + end.to change(WorkPackage, :count).by(2) expect(flash[:notice]).to eq(I18n.t(:notice_successful_create)) end diff --git a/spec/controllers/work_packages/reports_controller_spec.rb b/spec/controllers/work_packages/reports_controller_spec.rb index 5ab89a32a2..8f981e218a 100644 --- a/spec/controllers/work_packages/reports_controller_spec.rb +++ b/spec/controllers/work_packages/reports_controller_spec.rb @@ -31,33 +31,33 @@ require 'spec_helper' describe WorkPackages::ReportsController, type: :controller do let(:user) { FactoryBot.create(:user) } let(:project) { FactoryBot.create(:project) } - let(:role) { + let(:role) do FactoryBot.create(:role, - permissions: [:view_work_packages]) - } - let(:member) { + permissions: [:view_work_packages]) + end + let(:member) do FactoryBot.create(:member, - project: project, - principal: user, - roles: [role]) - } - let(:work_package_1) { + project: project, + principal: user, + roles: [role]) + end + let(:work_package_1) do FactoryBot.create(:work_package, - id: 21, - subject: "Can't print recipes", - project: project) - } - let(:work_package_2) { + id: 21, + subject: "Can't print recipes", + project: project) + end + let(:work_package_2) do FactoryBot.create(:work_package, - id: 2101, - subject: 'Error 281 when updating a recipe', - project: project) - } - let(:work_package_3) { + id: 2101, + subject: 'Error 281 when updating a recipe', + project: project) + end + let(:work_package_3) do FactoryBot.create(:work_package, - id: 2102, - project: project) - } + id: 2102, + project: project) + end before do member diff --git a/spec/decorators/single_spec.rb b/spec/decorators/single_spec.rb index b1a357d7db..357b89d784 100644 --- a/spec/decorators/single_spec.rb +++ b/spec/decorators/single_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/factories/category_factory.rb b/spec/factories/category_factory.rb index 82bf8218f4..248a3d6aaf 100644 --- a/spec/factories/category_factory.rb +++ b/spec/factories/category_factory.rb @@ -28,7 +28,7 @@ FactoryBot.define do factory :category do - sequence(:name) do |n| "Issue category #{n}" end + sequence(:name) { |n| "Issue category #{n}" } project callback(:after_build) do |issue| diff --git a/spec/factories/changeset_factory.rb b/spec/factories/changeset_factory.rb index c8d5e19803..4a6d95f488 100644 --- a/spec/factories/changeset_factory.rb +++ b/spec/factories/changeset_factory.rb @@ -28,7 +28,7 @@ FactoryBot.define do factory :changeset do - sequence(:revision) { |n| "#{n}" } + sequence(:revision) { |n| n.to_s } committed_on { Time.now } commit_date { Date.today } end diff --git a/spec/factories/color_factory.rb b/spec/factories/color_factory.rb index ba032db2e4..2676dc7d8f 100644 --- a/spec/factories/color_factory.rb +++ b/spec/factories/color_factory.rb @@ -28,28 +28,28 @@ FactoryBot.define do factory(:color, class: Color) do - sequence(:name) do |n| "Color No. #{n}" end - hexcode do ('#%0.6x' % rand(0xFFFFFF)).upcase end + sequence(:name) { |n| "Color No. #{n}" } + hexcode { ('#%0.6x' % rand(0xFFFFFF)).upcase } end end -{ 'maroon' => '#800000', - 'red' => '#FF0000', - 'orange' => '#FFA500', - 'yellow' => '#FFFF00', - 'olive' => '#808000', - 'purple' => '#800080', +{ 'maroon' => '#800000', + 'red' => '#FF0000', + 'orange' => '#FFA500', + 'yellow' => '#FFFF00', + 'olive' => '#808000', + 'purple' => '#800080', 'fuchsia' => '#FF00FF', - 'white' => '#FFFFFF', - 'lime' => '#00FF00', - 'green' => '#008000', - 'navy' => '#000080', - 'blue' => '#0000FF', - 'aqua' => '#00FFFF', - 'teal' => '#008080', - 'black' => '#000000', - 'silver' => '#C0C0C0', - 'gray' => '#808080' }.each do |name, code| + 'white' => '#FFFFFF', + 'lime' => '#00FF00', + 'green' => '#008000', + 'navy' => '#000080', + 'blue' => '#0000FF', + 'aqua' => '#00FFFF', + 'teal' => '#008080', + 'black' => '#000000', + 'silver' => '#C0C0C0', + 'gray' => '#808080' }.each do |name, code| FactoryBot.define do factory(:"color_#{name}", parent: :color) do name { name } diff --git a/spec/factories/comment_factory.rb b/spec/factories/comment_factory.rb index 9720d73d6d..a5b120f5e1 100644 --- a/spec/factories/comment_factory.rb +++ b/spec/factories/comment_factory.rb @@ -29,7 +29,7 @@ FactoryBot.define do factory :comment do author factory: :user - sequence(:comments) do |n| "I am a comment No. #{n}" end + sequence(:comments) { |n| "I am a comment No. #{n}" } commented factory: :news end end diff --git a/spec/factories/enumerations_factory.rb b/spec/factories/enumerations_factory.rb index 2257b3f799..303f4fc9a3 100644 --- a/spec/factories/enumerations_factory.rb +++ b/spec/factories/enumerations_factory.rb @@ -39,7 +39,7 @@ FactoryBot.define do end factory :activity, class: TimeEntryActivity do - sequence(:name) do |i| "Activity #{i}" end + sequence(:name) { |i| "Activity #{i}" } active { true } is_default { false } @@ -52,7 +52,7 @@ FactoryBot.define do end factory :priority, class: IssuePriority do - sequence(:name) do |i| "Priority #{i}" end + sequence(:name) { |i| "Priority #{i}" } active { true } factory :priority_low do @@ -60,7 +60,7 @@ FactoryBot.define do # reuse existing priority with the given name # this prevents a validation error (name has to be unique) - initialize_with do IssuePriority.find_or_create_by(name: name) end + initialize_with { IssuePriority.find_or_create_by(name: name) } factory :priority_normal do name { 'Normal' } diff --git a/spec/factories/file_factory.rb b/spec/factories/file_factory.rb index 089069be00..abc6c9fb3b 100644 --- a/spec/factories/file_factory.rb +++ b/spec/factories/file_factory.rb @@ -51,10 +51,11 @@ FactoryBot.define do initialize_with do FileHelpers.mock_uploaded_file( - name: name, - content: content, + name: name, + content: content, content_type: content_type, - binary: binary) + binary: binary + ) end factory :uploaded_jpg do diff --git a/spec/factories/forum_factory.rb b/spec/factories/forum_factory.rb index 7d8612d32e..066a903ec9 100644 --- a/spec/factories/forum_factory.rb +++ b/spec/factories/forum_factory.rb @@ -29,7 +29,7 @@ FactoryBot.define do factory :forum do project - sequence(:name) do |n| "Forum No. #{n}" end + sequence(:name) { |n| "Forum No. #{n}" } sequence(:description) { |n| "I am the Forum No. #{n}" } end end diff --git a/spec/factories/menu_item_factory.rb b/spec/factories/menu_item_factory.rb index 1ae1567086..1541ad0631 100644 --- a/spec/factories/menu_item_factory.rb +++ b/spec/factories/menu_item_factory.rb @@ -28,13 +28,13 @@ FactoryBot.define do factory :menu_item do - sequence(:name) do |n| "Item No. #{n}" end - sequence(:title) do |n| "Menu item Title #{n}" end + sequence(:name) { |n| "Item No. #{n}" } + sequence(:title) { |n| "Menu item Title #{n}" } factory :wiki_menu_item, class: MenuItems::WikiMenuItem do wiki - sequence(:title) do |n| "Wiki Title #{n}" end + sequence(:title) { |n| "Wiki Title #{n}" } trait :with_menu_item_options do index_page { true } @@ -53,8 +53,8 @@ FactoryBot.define do factory :query_menu_item, class: MenuItems::QueryMenuItem do query - name do query.normalized_name end - title do query.name end + name { query.normalized_name } + title { query.name } navigatable_id { query.id } end diff --git a/spec/factories/message_factory.rb b/spec/factories/message_factory.rb index 214db7637c..512ab7d4e0 100644 --- a/spec/factories/message_factory.rb +++ b/spec/factories/message_factory.rb @@ -29,7 +29,7 @@ FactoryBot.define do factory :message do forum - sequence(:content) do |n| "Message content #{n}" end + sequence(:content) { |n| "Message content #{n}" } sequence(:subject) { |n| "Message subject #{n}" } end end diff --git a/spec/factories/news_factory.rb b/spec/factories/news_factory.rb index e40601dd74..e64ab0b201 100644 --- a/spec/factories/news_factory.rb +++ b/spec/factories/news_factory.rb @@ -28,9 +28,9 @@ FactoryBot.define do factory :news do - sequence(:title) do |n| "News title#{n}" end - sequence(:summary) do |n| "News summary#{n}" end - sequence(:description) do |n| "News description#{n}" end + sequence(:title) { |n| "News title#{n}" } + sequence(:summary) { |n| "News summary#{n}" } + sequence(:description) { |n| "News description#{n}" } author factory: :user project end diff --git a/spec/factories/principal_factory.rb b/spec/factories/principal_factory.rb index a9336bc2cd..b167d8cc09 100644 --- a/spec/factories/principal_factory.rb +++ b/spec/factories/principal_factory.rb @@ -47,7 +47,10 @@ FactoryBot.define do (projects = evaluator.member_in_projects || []) projects << evaluator.member_in_project if evaluator.member_in_project if !projects.empty? - role = evaluator.member_through_role || FactoryBot.build(:role, permissions: evaluator.member_with_permissions || [:view_work_packages, :edit_work_packages]) + role = evaluator.member_through_role || FactoryBot.build(:role, + permissions: evaluator.member_with_permissions || %i[ + view_work_packages edit_work_packages + ]) projects.each do |project| project.add_member! principal, role if project end diff --git a/spec/factories/project_factory.rb b/spec/factories/project_factory.rb index 08110b7816..b553b6722a 100644 --- a/spec/factories/project_factory.rb +++ b/spec/factories/project_factory.rb @@ -1,4 +1,5 @@ # encoding: utf-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/factories/project_status.rb b/spec/factories/project_status.rb index 3fc43cc039..d8b07d63fd 100644 --- a/spec/factories/project_status.rb +++ b/spec/factories/project_status.rb @@ -1,4 +1,5 @@ # encoding: utf-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/factories/role_factory.rb b/spec/factories/role_factory.rb index 57299550b4..862dc51380 100644 --- a/spec/factories/role_factory.rb +++ b/spec/factories/role_factory.rb @@ -31,7 +31,7 @@ require 'digest' FactoryBot.define do factory :role do permissions { [] } - sequence(:name) do |n| "role_#{n}" end + sequence(:name) { |n| "role_#{n}" } assignable { true } factory :non_member do diff --git a/spec/factories/status_factory.rb b/spec/factories/status_factory.rb index b3a3be00d7..e6c4fffccc 100644 --- a/spec/factories/status_factory.rb +++ b/spec/factories/status_factory.rb @@ -28,7 +28,7 @@ FactoryBot.define do factory :status do - sequence(:name) do |n| "status #{n}" end + sequence(:name) { |n| "status #{n}" } is_closed { false } is_readonly { false } diff --git a/spec/factories/type_factory.rb b/spec/factories/type_factory.rb index 203a5f89ee..901f92bb02 100644 --- a/spec/factories/type_factory.rb +++ b/spec/factories/type_factory.rb @@ -49,7 +49,8 @@ FactoryBot.define do query = FactoryBot.create(:query) query.add_filter(evaluator.relation_filter.to_s, '=', [::Queries::Filters::TemplatedValue::KEY]) query.save - t.attribute_groups = t.default_attribute_groups + [["Embedded table for #{evaluator.relation_filter.to_s}", ["query_#{query.id}".to_sym]]] + t.attribute_groups = t.default_attribute_groups + [["Embedded table for #{evaluator.relation_filter}", + ["query_#{query.id}".to_sym]]] end end end diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb index 222b2298d6..b849ac86b5 100644 --- a/spec/factories/user_factory.rb +++ b/spec/factories/user_factory.rb @@ -44,9 +44,9 @@ FactoryBot.define do factory :admin do firstname { 'OpenProject' } - sequence(:lastname) do |n| "Admin#{n}" end - sequence(:login) do |n| "admin#{n}" end - sequence(:mail) do |n| "admin#{n}@example.com" end + sequence(:lastname) { |n| "Admin#{n}" } + sequence(:login) { |n| "admin#{n}" } + sequence(:mail) { |n| "admin#{n}@example.com" } admin { true } first_login { false if User.table_exists? and User.columns.map(&:name).include? 'first_login' } end @@ -56,10 +56,10 @@ FactoryBot.define do factory :locked_user do firstname { 'Locked' } lastname { 'User' } - sequence(:login) do |n| "bob#{n}" end - sequence(:mail) do |n| "bob#{n}.bobbit@bob.com" end + sequence(:login) { |n| "bob#{n}" } + sequence(:mail) { |n| "bob#{n}.bobbit@bob.com" } password { 'adminADMIN!' } - password_confirmation { 'adminADMIN!'} + password_confirmation { 'adminADMIN!' } status { User.statuses[:locked] } end diff --git a/spec/factories/user_session_factory.rb b/spec/factories/user_session_factory.rb index 03eb8b9e2f..e70d951b20 100644 --- a/spec/factories/user_session_factory.rb +++ b/spec/factories/user_session_factory.rb @@ -28,7 +28,7 @@ FactoryBot.define do factory :user_session do - sequence(:session_id) do |n| "session_#{n}" end + sequence(:session_id) { |n| "session_#{n}" } association :user callback(:after_build) do |session| diff --git a/spec/factories/work_package_custom_field_factory.rb b/spec/factories/work_package_custom_field_factory.rb index 01298dd0ac..1fe67db96d 100644 --- a/spec/factories/work_package_custom_field_factory.rb +++ b/spec/factories/work_package_custom_field_factory.rb @@ -32,7 +32,7 @@ FactoryBot.define do default_locales { nil } end - sequence(:name) do |n| "Custom Field Nr. #{n}" end + sequence(:name) { |n| "Custom Field Nr. #{n}" } regexp { '' } is_required { false } min_length { false } diff --git a/spec/factories/work_packags_export_factory.rb b/spec/factories/work_packags_export_factory.rb index 04517a9849..3f60d90d9d 100644 --- a/spec/factories/work_packags_export_factory.rb +++ b/spec/factories/work_packags_export_factory.rb @@ -28,6 +28,5 @@ FactoryBot.define do factory :work_packages_export, class: WorkPackages::Export do - end end diff --git a/spec/features/accessibility/work_packages/work_package_query_spec.rb b/spec/features/accessibility/work_packages/work_package_query_spec.rb index 46ecf716b0..6c8fbfcfc3 100644 --- a/spec/features/accessibility/work_packages/work_package_query_spec.rb +++ b/spec/features/accessibility/work_packages/work_package_query_spec.rb @@ -52,7 +52,7 @@ describe 'Work package index accessibility', type: :feature, selenium: true do end describe 'Sort link', js: true do - before do visit_index_page end + before { visit_index_page } def click_sort_ascending_link expect(page).to have_selector(sort_ascending_selector) @@ -84,9 +84,8 @@ describe 'Work package index accessibility', type: :feature, selenium: true do it_behaves_like 'sort column' end - shared_examples_for 'sortable column' do - before do expect(page).to have_selector(column_header_selector) end + before { expect(page).to have_selector(column_header_selector) } describe 'Initial sort' do it_behaves_like 'unsorted column' @@ -155,10 +154,10 @@ describe 'Work package index accessibility', type: :feature, selenium: true do end describe 'hotkeys', js: true do - let!(:another_work_package) { + let!(:another_work_package) do FactoryBot.create(:work_package, - project: project) - } + project: project) + end before do visit_index_page end @@ -229,14 +228,14 @@ describe 'Work package index accessibility', type: :feature, selenium: true do it_behaves_like 'context menu' do let(:target_link) { '#work-package-context-menu a.detailsViewMenuItem' } let(:source_link) { '.work-package-table--container tr.issue td.id a' } - let(:keys) { [:shift, :alt, :f10] } + let(:keys) { %i[shift alt f10] } let(:sets_focus) { true } end it_behaves_like 'context menu' do let(:target_link) { '#work-package-context-menu a.openFullScreenView' } let(:source_link) { '.work-package-table--container tr.issue td.id a' } - let(:keys) { [:shift, :alt, :f10] } + let(:keys) { %i[shift alt f10] } let(:sets_focus) { false } end end diff --git a/spec/features/admin/enterprise/enterprise_trial_spec.rb b/spec/features/admin/enterprise/enterprise_trial_spec.rb index 400df7d9ac..7c0e02a518 100644 --- a/spec/features/admin/enterprise/enterprise_trial_spec.rb +++ b/spec/features/admin/enterprise/enterprise_trial_spec.rb @@ -31,7 +31,6 @@ require 'spec_helper' describe 'Enterprise trial management', type: :feature, driver: :chrome_billy do - let(:admin) { FactoryBot.create(:admin) } let(:trial_id) { '1b6486b4-5a30-4042-8714-99d7c8e6b637' } diff --git a/spec/features/auth/auth_stages_spec.rb b/spec/features/auth/auth_stages_spec.rb index 9a5f04ef10..b43b4ac599 100644 --- a/spec/features/auth/auth_stages_spec.rb +++ b/spec/features/auth/auth_stages_spec.rb @@ -77,7 +77,7 @@ describe 'Authentication Stages', type: :feature do end # this shouldn't influence the specs as it is active - OpenProject::Authentication::Stage.register :inactive, '/foo/bar', active: ->() { false } + OpenProject::Authentication::Stage.register :inactive, '/foo/bar', active: -> { false } end after do diff --git a/spec/features/auth/login_spec.rb b/spec/features/auth/login_spec.rb index 5b3a43a05e..2987b0ddc9 100644 --- a/spec/features/auth/login_spec.rb +++ b/spec/features/auth/login_spec.rb @@ -134,7 +134,6 @@ describe 'Login', type: :feature do with_settings: { autologin: 1 } do - def fake_browser_closed page.driver.browser.set_cookie(OpenProject::Configuration['session_cookie_name']) end diff --git a/spec/features/auth/omniauth_spec.rb b/spec/features/auth/omniauth_spec.rb index e0aef9d220..58719a3232 100644 --- a/spec/features/auth/omniauth_spec.rb +++ b/spec/features/auth/omniauth_spec.rb @@ -38,13 +38,12 @@ describe 'Omniauth authentication', type: :feature do let(:user) do FactoryBot.create(:user, - force_password_change: false, - identity_url: 'developer:omnibob@example.com', - login: 'omnibob', - mail: 'omnibob@example.com', - firstname: 'omni', - lastname: 'bob' - ) + force_password_change: false, + identity_url: 'developer:omnibob@example.com', + login: 'omnibob', + mail: 'omnibob@example.com', + firstname: 'omni', + lastname: 'bob') end before do @@ -96,7 +95,6 @@ describe 'Omniauth authentication', type: :feature do context 'with direct login', with_config: { omniauth_direct_login_provider: 'developer' } do - it 'should go directly to the developer sign in and then redirect to the back url' do visit my_account_path # requires login, redirects to developer login which is why we see the login form now @@ -115,7 +113,6 @@ describe 'Omniauth authentication', type: :feature do describe 'sign out a user with direct login and login required', with_config: { omniauth_direct_login_provider: 'developer' }, with_settings: { login_required?: true } do - it 'shows a notice that the user has been logged out' do visit signout_path @@ -143,7 +140,7 @@ describe 'Omniauth authentication', type: :feature do shared_examples 'omniauth user registration' do it 'should register new user' do visit '/' - click_link("Omniauth Developer", :match => :first) + click_link("Omniauth Developer", match: :first) SeleniumHubWaiter.wait # login form developer strategy @@ -166,12 +163,11 @@ describe 'Omniauth authentication', type: :feature do end context 'register on the fly', - with_settings: { + with_settings: { self_registration?: true, self_registration: '3', available_languages: [:en] - } do - + } do let(:user) do User.new(force_password_change: false, identity_url: 'developer:omnibob@example.com', @@ -185,7 +181,7 @@ describe 'Omniauth authentication', type: :feature do it 'should redirect to homesceen' do visit account_lost_password_path - click_link("Omniauth Developer", :match => :first) + click_link("Omniauth Developer", match: :first) SeleniumHubWaiter.wait # login form developer strategy @@ -206,7 +202,6 @@ describe 'Omniauth authentication', type: :feature do context 'with password login disabled', with_config: { disable_password_login: 'true' } do - it_behaves_like 'omniauth user registration' end end @@ -216,7 +211,6 @@ describe 'Omniauth authentication', type: :feature do self_registration?: true, self_registration: Setting::SelfRegistration.by_email.to_s } do - shared_examples 'registration with registration by email' do it 'shows a note explaining that the account has to be activated' do visit login_path @@ -243,7 +237,6 @@ describe 'Omniauth authentication', type: :feature do context 'with direct login enabled and login required', with_config: { omniauth_direct_login_provider: 'developer' } do - before do allow(Setting).to receive(:login_required?).and_return(true) end @@ -267,9 +260,9 @@ describe 'Omniauth authentication', type: :feature do OmniAuth.config.mock_auth[:developer] = :invalid_credentials # seems like this default behaviour is removed when running the full # test suite, so let's set it back when running this test - OmniAuth.config.on_failure = Proc.new { |env| + OmniAuth.config.on_failure = Proc.new do |env| OmniAuth::FailureEndpoint.new(env).redirect_to_failure - } + end visit login_path expect(page).to have_content(I18n.t(:error_external_authentication_failed)) @@ -285,7 +278,6 @@ describe 'Omniauth authentication', type: :feature do context 'with direct login and login required', with_config: { omniauth_direct_login_provider: 'developer' } do - before do allow(Setting).to receive(:login_required?).and_return(true) end diff --git a/spec/features/categories/delete_spec.rb b/spec/features/categories/delete_spec.rb index fe02c6a8ab..f6684549d3 100644 --- a/spec/features/categories/delete_spec.rb +++ b/spec/features/categories/delete_spec.rb @@ -36,7 +36,7 @@ describe 'Deletion', type: :feature do let(:delete_button) { 'a.icon-delete' } let(:confirm_deletion_button) { 'input[type="submit"]' } - before do allow(User).to receive(:current).and_return current_user end + before { allow(User).to receive(:current).and_return current_user } shared_context 'delete category' do before do @@ -61,11 +61,11 @@ describe 'Deletion', type: :feature do end describe 'with work package' do - let!(:work_package) { + let!(:work_package) do FactoryBot.create :work_package, - project: category.project, - category: category - } + project: category.project, + category: category + end include_context 'delete category' diff --git a/spec/features/custom_fields/create_long_text_spec.rb b/spec/features/custom_fields/create_long_text_spec.rb index eb795daafc..13feb5359e 100644 --- a/spec/features/custom_fields/create_long_text_spec.rb +++ b/spec/features/custom_fields/create_long_text_spec.rb @@ -52,7 +52,6 @@ describe 'custom fields', js: true do type.custom_fields << cf type.save! - wp_page.visit! wp_editor = TextEditorField.new(page, 'description', selector: ".inline-edit--container.customField#{cf.id}") wp_editor.expect_active! diff --git a/spec/features/custom_fields/multi_user_custom_field_spec.rb b/spec/features/custom_fields/multi_user_custom_field_spec.rb index 196071954d..3d13bba28a 100644 --- a/spec/features/custom_fields/multi_user_custom_field_spec.rb +++ b/spec/features/custom_fields/multi_user_custom_field_spec.rb @@ -19,7 +19,6 @@ describe "multi select custom values", js: true do ) end - let(:wp_page) { Pages::FullWorkPackage.new work_package } let(:cf_edit_field) do @@ -128,7 +127,6 @@ describe "multi select custom values", js: true do member_through_role: role end - context "with existing custom values" do let(:work_package) do wp = FactoryBot.build :work_package, project: project, type: type @@ -141,7 +139,6 @@ describe "multi select custom values", js: true do wp end - it "should be shown and allowed to be updated" do expect(page).to have_text custom_field.name expect(page).to have_text "Billy Nobbler" diff --git a/spec/features/custom_fields/multi_value_custom_field_spec.rb b/spec/features/custom_fields/multi_value_custom_field_spec.rb index c9fd2e9b0a..3289af5f55 100644 --- a/spec/features/custom_fields/multi_value_custom_field_spec.rb +++ b/spec/features/custom_fields/multi_value_custom_field_spec.rb @@ -35,7 +35,7 @@ describe "multi select custom values", clear_cache: true, js: true do let(:sort_by) { ::Components::WorkPackages::SortBy.new } let(:user) { FactoryBot.create :admin } - let(:cf_frontend) { "customField#{custom_field.id}"} + let(:cf_frontend) { "customField#{custom_field.id}" } context "with existing custom values" do let(:work_package_options) { %w[ham pineapple onions] } diff --git a/spec/features/global_roles/global_role_assignment_spec.rb b/spec/features/global_roles/global_role_assignment_spec.rb index fb90214f11..20e9ae620e 100644 --- a/spec/features/global_roles/global_role_assignment_spec.rb +++ b/spec/features/global_roles/global_role_assignment_spec.rb @@ -36,7 +36,7 @@ describe 'Global role: Global role assignment', type: :feature, js: true do describe 'Going to the global role assignment page' do before do - mock_global_permissions [['global1', project_module: :global], ['global2', project_module: :global]] + mock_global_permissions [['global1', { project_module: :global }], ['global2', { project_module: :global }]] end let!(:global_role1) { FactoryBot.create :global_role, name: 'global_role1', permissions: %i[global1] } let!(:global_role2) { FactoryBot.create :global_role, name: 'global_role2', permissions: %i[global2] } diff --git a/spec/features/global_roles/global_role_crud_spec.rb b/spec/features/global_roles/global_role_crud_spec.rb index ba11b20ec8..eecbbe8f8f 100644 --- a/spec/features/global_roles/global_role_crud_spec.rb +++ b/spec/features/global_roles/global_role_crud_spec.rb @@ -33,7 +33,7 @@ describe 'Global role: Global role CRUD', type: :feature, js: true do # Scenario: Global Role creation # Given there is the global permission "glob_test" of the module "global_group" before do - mock_global_permissions [['glob_test', project_module: 'global_group']] + mock_global_permissions [['glob_test', { project_module: 'global_group' }]] login_as(current_user) end diff --git a/spec/features/global_roles/no_module_spec.rb b/spec/features/global_roles/no_module_spec.rb index e62ca9eae7..3d839ca4ac 100644 --- a/spec/features/global_roles/no_module_spec.rb +++ b/spec/features/global_roles/no_module_spec.rb @@ -41,7 +41,7 @@ describe 'Global role: No module', type: :feature, js: true do scenario 'Global Rights Modules do not exist as Project -> Settings -> Modules' do # Scenario: # Given there is the global permission "glob_test" of the module "global" - mock_global_permissions [['global_perm1', project_module: :global]] + mock_global_permissions [['global_perm1', { project_module: :global }]] # And there is 1 project with the following: # | name | test | diff --git a/spec/features/homescreen/robots_spec.rb b/spec/features/homescreen/robots_spec.rb index 7ea11b2934..f71e9d594f 100644 --- a/spec/features/homescreen/robots_spec.rb +++ b/spec/features/homescreen/robots_spec.rb @@ -38,7 +38,7 @@ describe 'robots.txt', type: :feature do it 'disallows global paths and paths from public project' do expect(page).to have_content('Disallow: /work_packages/calendar') expect(page).to have_content('Disallow: /activity') - + expect(page).to have_content("Disallow: /projects/#{project.identifier}/repository") expect(page).to have_content("Disallow: /projects/#{project.identifier}/work_packages") expect(page).to have_content("Disallow: /projects/#{project.identifier}/activity") diff --git a/spec/features/localization_spec.rb b/spec/features/localization_spec.rb index dcb9324e96..98665fbd58 100644 --- a/spec/features/localization_spec.rb +++ b/spec/features/localization_spec.rb @@ -33,7 +33,6 @@ require 'spec_helper' describe 'Localization', type: :feature, with_settings: { login_required?: false, available_languages: %i[de en], default_language: 'en' } do - it 'set localization' do Capybara.current_session.driver.header('Accept-Language', 'de,de-de;q=0.8,en-us;q=0.5,en;q=0.3') diff --git a/spec/features/members/invitation_spec.rb b/spec/features/members/invitation_spec.rb index cfd1a23eb2..939a1e1e9c 100644 --- a/spec/features/members/invitation_spec.rb +++ b/spec/features/members/invitation_spec.rb @@ -67,16 +67,15 @@ feature 'invite user via email', type: :feature, js: true do # Should show the invited user on the default filter as well members_page.visit! expect(members_page).to have_user 'finkelstein @openproject.com' - end end context 'with a registered user' do let!(:user) do FactoryBot.create :user, mail: 'hugo@openproject.com', - login: 'hugo@openproject.com', - firstname: 'Hugo', - lastname: 'Hurried' + login: 'hugo@openproject.com', + firstname: 'Hugo', + lastname: 'Hurried' end scenario 'user lookup by email' do diff --git a/spec/features/members/membership_filter_spec.rb b/spec/features/members/membership_filter_spec.rb index 979804d0d6..5e218c80e3 100644 --- a/spec/features/members/membership_filter_spec.rb +++ b/spec/features/members/membership_filter_spec.rb @@ -39,7 +39,6 @@ feature 'group memberships through groups page', type: :feature, js: true do mail: 'foo@example.org', member_in_project: project, member_through_role: role - end let!(:hannibal) do @@ -49,7 +48,6 @@ feature 'group memberships through groups page', type: :feature, js: true do mail: 'foo@example.com', member_in_project: project, member_through_role: role - end let(:role) { FactoryBot.create(:role, permissions: %i(add_work_packages)) } let(:members_page) { Pages::Members.new project.identifier } diff --git a/spec/features/my/my_notifications_spec.rb b/spec/features/my/my_notifications_spec.rb index faf97b1073..6436110a29 100644 --- a/spec/features/my/my_notifications_spec.rb +++ b/spec/features/my/my_notifications_spec.rb @@ -34,8 +34,8 @@ describe 'My notifications spec', type: :feature, js: true do let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do @@ -62,7 +62,6 @@ describe 'My notifications spec', type: :feature, js: true do expect(user.mail_notification).to eq(User::USER_MAIL_OPTION_SELECTED.first) expect(user.notified_projects_ids).to eq [project.id] - select 'No events', from: 'Send email notifications' click_on 'Save' expect(page).to have_selector('.flash.notice') diff --git a/spec/features/oauth/authorization_code_flow_spec.rb b/spec/features/oauth/authorization_code_flow_spec.rb index 7bd3b0ee8c..f22a00ca71 100644 --- a/spec/features/oauth/authorization_code_flow_spec.rb +++ b/spec/features/oauth/authorization_code_flow_spec.rb @@ -130,7 +130,8 @@ describe 'OAuth authorization code flow', login_with user.login, 'adminADMIN!', visit_signin_path: false # But we got no further - expect(page).to have_selector('.notification-box.-error', text: 'Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.') + expect(page).to have_selector('.notification-box.-error', + text: 'Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method.') # And also have no grant for this application user.oauth_grants.reload diff --git a/spec/features/onboarding/onboarding_tour_spec.rb b/spec/features/onboarding/onboarding_tour_spec.rb index 8d5fb576ad..4f5fc00752 100644 --- a/spec/features/onboarding/onboarding_tour_spec.rb +++ b/spec/features/onboarding/onboarding_tour_spec.rb @@ -30,8 +30,14 @@ require 'spec_helper' describe 'onboarding tour for new users', js: true do let(:user) { FactoryBot.create :admin } - let(:project) { FactoryBot.create :project, name: 'Demo project', identifier: 'demo-project', public: true, enabled_module_names: %w[work_package_tracking wiki] } - let(:scrum_project) {FactoryBot.create :project, name: 'Scrum project', identifier: 'your-scrum-project', public: true, enabled_module_names: %w[work_package_tracking] } + let(:project) do + FactoryBot.create :project, name: 'Demo project', identifier: 'demo-project', public: true, + enabled_module_names: %w[work_package_tracking wiki] + end + let(:scrum_project) do + FactoryBot.create :project, name: 'Scrum project', identifier: 'your-scrum-project', public: true, + enabled_module_names: %w[work_package_tracking] + end let!(:wp_1) { FactoryBot.create(:work_package, project: project) } let(:next_button) { find('.enjoyhint_next_btn') } @@ -48,7 +54,7 @@ describe 'onboarding tour for new users', js: true do expect(page).to have_text 'Please select your language' # SeleniumHubWaiter.wait - select 'Deutsch', :from => 'user_language' + select 'Deutsch', from: 'user_language' click_button 'Save' expect(page).to have_text 'Projekt auswählen' @@ -60,7 +66,7 @@ describe 'onboarding tour for new users', js: true do visit home_path first_time_user: true # SeleniumHubWaiter.wait - select 'English', :from => 'user_language' + select 'English', from: 'user_language' click_button 'Save' end @@ -76,7 +82,7 @@ describe 'onboarding tour for new users', js: true do visit home_path first_time_user: true # SeleniumHubWaiter.wait - select 'English', :from => 'user_language' + select 'English', from: 'user_language' click_button 'Save' SeleniumHubWaiter.wait end @@ -121,5 +127,3 @@ describe 'onboarding tour for new users', js: true do end end end - - diff --git a/spec/features/page_objects/notification.rb b/spec/features/page_objects/notification.rb index 46543cd291..29d2aabe58 100644 --- a/spec/features/page_objects/notification.rb +++ b/spec/features/page_objects/notification.rb @@ -38,6 +38,7 @@ module PageObjects def expect_type(type, message) raise "Unimplemented type #{type}." unless types.include?(type) + expect(page).to have_selector(".notification-box.-#{type}", text: message, wait: 10) end @@ -52,7 +53,7 @@ module PageObjects private def types - [:success, :error] + %i[success error] end end end diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb index 06a4fee1ac..2f3f3ce4a6 100644 --- a/spec/features/projects/projects_index_spec.rb +++ b/spec/features/projects/projects_index_spec.rb @@ -265,8 +265,8 @@ describe 'Projects index page', # Results should be filtered and ordered ASC by name expect(page).to have_text(development_project.name) - expect(page).to have_no_text(project.name) # as it filtered away - expect(page).to have_text('Next') # as the result set is larger than 1 + expect(page).to have_no_text(project.name) # as it filtered away + expect(page).to have_text('Next') # as the result set is larger than 1 expect(page).to have_no_text(public_project.name) # as it is on the second page # Changing the page size to 5 and back to 1 should not change the filters (which we test later on the second page) @@ -302,7 +302,7 @@ describe 'Projects index page', expect(page).to have_text(public_project.name) expect(page).to have_no_text(development_project.name) # as it is on the second page expect(page).to have_no_text(project.name) # as it filtered away - expect(page).to have_text('Next') # as the result set is larger than 1 + expect(page).to have_text('Next') # as the result set is larger than 1 end end @@ -508,7 +508,6 @@ describe 'Projects index page', expect(page).to have_text(gray_project.name) expect(page).to have_text(no_status_project.name) end - end feature 'other filter types' do diff --git a/spec/features/projects/projects_spec.rb b/spec/features/projects/projects_spec.rb index 65e2e99170..b58c5047c2 100644 --- a/spec/features/projects/projects_spec.rb +++ b/spec/features/projects/projects_spec.rb @@ -58,7 +58,7 @@ describe 'Projects', type: :feature do end context 'work_packages module disabled', - with_settings: { default_projects_modules: %q(wiki) } do + with_settings: { default_projects_modules: 'wiki' } do it 'creates a project and redirects to settings' do click_on 'New project' @@ -97,8 +97,6 @@ describe 'Projects', type: :feature do expect(page).to have_content 'Identifier has already been taken' expect(current_path).to eq '/projects' end - - end describe 'project types' do @@ -185,14 +183,14 @@ describe 'Projects', type: :feature do let(:project) { FactoryBot.build(:project, name: 'Foo project', identifier: 'foo-project') } let!(:optional_custom_field) do FactoryBot.create(:custom_field, name: 'Optional Foo', - type: ProjectCustomField, - is_for_all: true) + type: ProjectCustomField, + is_for_all: true) end let!(:required_custom_field) do FactoryBot.create(:custom_field, name: 'Required Foo', - type: ProjectCustomField, - is_for_all: true, - is_required: true) + type: ProjectCustomField, + is_for_all: true, + is_required: true) end it 'seperates optional and required custom fields for new' do diff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rb index ab1b356944..84d8f691ec 100644 --- a/spec/features/projects/template_spec.rb +++ b/spec/features/projects/template_spec.rb @@ -57,15 +57,17 @@ describe 'Project templates', type: :feature, js: true do end describe 'instantiating templates' do - let!(:template) { + let!(:template) do FactoryBot.create(:template_project, name: 'My template', enabled_module_names: %w[wiki work_package_tracking]) - } + end let!(:template_status) { FactoryBot.create(:project_status, project: template, explanation: 'source') } let!(:other_project) { FactoryBot.create(:project, name: 'Some other project') } let!(:work_package) { FactoryBot.create :work_package, project: template } let!(:wiki_page) { FactoryBot.create(:wiki_page_with_content, wiki: template.wiki) } - let!(:role) { FactoryBot.create(:role, permissions: %i[view_project view_work_packages copy_projects add_subprojects add_project]) } + let!(:role) do + FactoryBot.create(:role, permissions: %i[view_project view_work_packages copy_projects add_subprojects add_project]) + end let!(:current_user) { FactoryBot.create(:user, member_in_projects: [template, other_project], member_through_role: role) } let(:status_field_selector) { 'ckeditor-augmented-textarea[textarea-selector="#project_status_explanation"]' } let(:status_description) { ::Components::WysiwygEditor.new status_field_selector } @@ -145,4 +147,3 @@ describe 'Project templates', type: :feature, js: true do end end end - diff --git a/spec/features/repositories/checkout_instructions_spec.rb b/spec/features/repositories/checkout_instructions_spec.rb index 9b444ba01e..67af175b8a 100644 --- a/spec/features/repositories/checkout_instructions_spec.rb +++ b/spec/features/repositories/checkout_instructions_spec.rb @@ -44,16 +44,16 @@ describe 'Create repository', type: :feature, js: true do context 'managed repositories' do include_context 'with tmpdir' - let(:config) { + let(:config) do { git: { manages: File.join(tmpdir, 'git') } } - } - let(:checkout_data) { + end + let(:checkout_data) do { 'git' => { 'enabled' => '1', 'base_url' => 'http://localhost/git/' } } - } + end - let!(:repository) { + let!(:repository) do repo = FactoryBot.build(:repository_git, scm_type: :managed) repo.project = project repo.configure(:managed, nil) @@ -61,7 +61,7 @@ describe 'Create repository', type: :feature, js: true do perform_enqueued_jobs repo - } + end it 'toggles checkout instructions' do visit project_repository_path(project) diff --git a/spec/features/repositories/repository_settings_spec.rb b/spec/features/repositories/repository_settings_spec.rb index 6befb377dd..a525f64695 100644 --- a/spec/features/repositories/repository_settings_spec.rb +++ b/spec/features/repositories/repository_settings_spec.rb @@ -103,12 +103,12 @@ describe 'Repository Settings', type: :feature, js: true do end end - shared_examples 'manages the repository with' do |name, type, repository_type, project_name| - let(:repository) { + shared_examples 'manages the repository with' do |name, type, _repository_type, _project_name| + let(:repository) do FactoryBot.create("repository_#{name}".to_sym, - scm_type: type, - project: project) - } + scm_type: type, + project: project) + end it_behaves_like 'manages the repository', type end @@ -118,14 +118,14 @@ describe 'Repository Settings', type: :feature, js: true do context 'managed repositories' do context 'local' do include_context 'with tmpdir' - let(:config) { + let(:config) do { subversion: { manages: File.join(tmpdir, 'svn') }, git: { manages: File.join(tmpdir, 'git') } } - } + end - let(:repository) { + let(:repository) do repo = Repository.build( project, managed_vendor, @@ -136,7 +136,7 @@ describe 'Repository Settings', type: :feature, js: true do repo.save! repo - } + end context 'Subversion' do let(:managed_vendor) { :subversion } @@ -151,13 +151,13 @@ describe 'Repository Settings', type: :feature, js: true do context 'remote', webmock: true do let(:url) { 'http://myreposerver.example.com/api/' } - let(:config) { + let(:config) do { git: { manages: url } } - } + end let(:managed_vendor) { :git } - let(:repository) { + let(:repository) do repo = Repository.build( project, managed_vendor, @@ -172,17 +172,17 @@ describe 'Repository Settings', type: :feature, js: true do repo.save! repo - } + end it_behaves_like 'manages the repository', 'managed' end end describe 'update repositories' do - let(:repository) { + let(:repository) do FactoryBot.create(:repository_subversion, - scm_type: :existing, - project: project) - } + scm_type: :existing, + project: project) + end it 'can set login and password' do fill_in('repository[login]', with: 'foobar') diff --git a/spec/features/security/expire_sessions_spec.rb b/spec/features/security/expire_sessions_spec.rb index 0b4c169c68..6055ab8c9b 100644 --- a/spec/features/security/expire_sessions_spec.rb +++ b/spec/features/security/expire_sessions_spec.rb @@ -32,7 +32,7 @@ describe 'Expire old user sessions', with_config: { session_store: :active_record_store }, type: :feature do shared_let(:admin) { FactoryBot.create :admin } - let(:admin_password) { 'adminADMIN!'} + let(:admin_password) { 'adminADMIN!' } before do login_with(admin.login, admin_password) diff --git a/spec/features/security/session_ttl_spec.rb b/spec/features/security/session_ttl_spec.rb index 9a7e36837d..ba59d2f6d3 100644 --- a/spec/features/security/session_ttl_spec.rb +++ b/spec/features/security/session_ttl_spec.rb @@ -32,7 +32,7 @@ describe 'Session TTL', with_settings: { session_ttl_enabled?: true, session_ttl: '10' }, type: :feature do shared_let(:admin) { FactoryBot.create :admin } - let(:admin_password) { 'adminADMIN!'} + let(:admin_password) { 'adminADMIN!' } let!(:work_package) { FactoryBot.create :work_package } diff --git a/spec/features/support/components/time_logging_modal.rb b/spec/features/support/components/time_logging_modal.rb index 417f21fd18..47dd7f4e89 100644 --- a/spec/features/support/components/time_logging_modal.rb +++ b/spec/features/support/components/time_logging_modal.rb @@ -114,8 +114,6 @@ module Components 'wp-new-inline-edit--field-spentOn' when 'work_package' 'wp-new-inline-edit--field-workPackage' - else - nil end end @@ -131,8 +129,6 @@ module Components comment_field when 'work_package' work_package_field - else - nil end end diff --git a/spec/features/types/form_configuration_query_spec.rb b/spec/features/types/form_configuration_query_spec.rb index 0aa49f0343..6f5b516a90 100644 --- a/spec/features/types/form_configuration_query_spec.rb +++ b/spec/features/types/form_configuration_query_spec.rb @@ -97,7 +97,6 @@ describe 'form query configuration', type: :feature, js: true do form.save_changes expect(page).to have_selector('.flash.notice', text: 'Successful update.', wait: 10) - # Visit wp_table wp_table.visit! wp_table.expect_work_package_listed work_package, related_task, related_bug diff --git a/spec/features/types/reset_form_configuration_spec.rb b/spec/features/types/reset_form_configuration_spec.rb index 8a1d246c08..22c40d4ebb 100644 --- a/spec/features/types/reset_form_configuration_spec.rb +++ b/spec/features/types/reset_form_configuration_spec.rb @@ -77,10 +77,10 @@ describe 'Reset form configuration', type: :feature, js: true do expect(type.custom_field_ids).to be_empty - new_group = type.attribute_groups.detect { |g| g.key == 'New Group'} + new_group = type.attribute_groups.detect { |g| g.key == 'New Group' } expect(new_group).not_to be_present - other_group = type.attribute_groups.detect { |g| g.key == :other} + other_group = type.attribute_groups.detect { |g| g.key == :other } expect(other_group).not_to be_present end end diff --git a/spec/features/users/brute_force_spec.rb b/spec/features/users/brute_force_spec.rb index 535868a1dd..f23b8e54d6 100644 --- a/spec/features/users/brute_force_spec.rb +++ b/spec/features/users/brute_force_spec.rb @@ -98,7 +98,6 @@ describe 'Loggin (with brute force protection)', type: :feature do it 'does not block if brute force is disabled', with_settings: { brute_force_block_minutes: 5, brute_force_block_after_failed_logins: 0 } do - login_with login, invalid_password expect(page) diff --git a/spec/features/users/create_spec.rb b/spec/features/users/create_spec.rb index 30d4bc585e..bb85d50207 100644 --- a/spec/features/users/create_spec.rb +++ b/spec/features/users/create_spec.rb @@ -107,7 +107,6 @@ describe 'create users', type: :feature, selenium: true do login: 'bob', auth_source: auth_source.name - perform_enqueued_jobs do new_user_page.submit! end diff --git a/spec/features/users/delete_spec.rb b/spec/features/users/delete_spec.rb index b2de04fe81..6d5cd57b73 100644 --- a/spec/features/users/delete_spec.rb +++ b/spec/features/users/delete_spec.rb @@ -36,11 +36,11 @@ describe 'user deletion: ', type: :feature, js: true do end context 'regular user' do - let(:user_password) {'bob!' * 4} + let(:user_password) { 'bob!' * 4 } let(:current_user) do FactoryBot.create(:user, - password: user_password, - password_confirmation: user_password) + password: user_password, + password_confirmation: user_password) end it 'can delete their own account', js: true do @@ -87,8 +87,8 @@ describe 'user deletion: ', type: :feature, js: true do let(:user_password) { 'admin! * 4' } let(:current_user) do FactoryBot.create(:admin, - password: user_password, - password_confirmation: user_password) + password: user_password, + password_confirmation: user_password) end it 'can delete other users if the setting permitts it', selenium: true do @@ -104,7 +104,7 @@ describe 'user deletion: ', type: :feature, js: true do click_on 'Delete' dialog.confirm_flow_with 'wrong', should_fail: true - + SeleniumHubWaiter.wait fill_in 'login_verification', with: user.login click_on 'Delete' @@ -131,7 +131,7 @@ describe 'user deletion: ', type: :feature, js: true do find(:css, "#settings_users_deletable_by_admins").set(true) find(:css, "#settings_users_deletable_by_self").set(true) - click_on 'Save' + click_on 'Save' expect(Setting.users_deletable_by_admins?).to eq true expect(Setting.users_deletable_by_self?).to eq true diff --git a/spec/features/users/password_change_spec.rb b/spec/features/users/password_change_spec.rb index 209fc2fdd8..8a8ffcc412 100644 --- a/spec/features/users/password_change_spec.rb +++ b/spec/features/users/password_change_spec.rb @@ -186,7 +186,6 @@ describe 'random password generation', password_min_length: 4 }, js: true do - it 'enforces those rules' do # Change to valid password according to spec user_page.change_password(old_password, 'password') diff --git a/spec/features/users/self_registration_spec.rb b/spec/features/users/self_registration_spec.rb index fd5b524725..22689df5a8 100644 --- a/spec/features/users/self_registration_spec.rb +++ b/spec/features/users/self_registration_spec.rb @@ -34,7 +34,6 @@ describe 'user self registration', type: :feature, js: true do context 'with "manual account activation"', with_settings: { self_registration: Setting::SelfRegistration.manual.to_s } do - it 'allows self registration on login page (Regression #28076)' do visit signin_path diff --git a/spec/features/versions/create_spec.rb b/spec/features/versions/create_spec.rb index 94da116250..8cbcbc1f2c 100644 --- a/spec/features/versions/create_spec.rb +++ b/spec/features/versions/create_spec.rb @@ -33,7 +33,7 @@ describe 'version create', type: :feature, js: false do FactoryBot.create(:user, member_in_project: project, member_with_permissions: %i[manage_versions view_work_packages]) - end + end let(:project) { FactoryBot.create(:project) } let(:new_version_name) { 'A new version name' } @@ -52,7 +52,6 @@ describe 'version create', type: :feature, js: false do expect(page).to have_content new_version_name end - it 'and redirect back to where you started' do visit project_roadmap_path(project) click_on 'New version' diff --git a/spec/features/watching/toggle_watching_spec.rb b/spec/features/watching/toggle_watching_spec.rb index 0cf2e25851..3d730ef2dc 100644 --- a/spec/features/watching/toggle_watching_spec.rb +++ b/spec/features/watching/toggle_watching_spec.rb @@ -30,7 +30,7 @@ require 'spec_helper' describe 'Toggle watching', type: :feature, js: true do let(:project) { FactoryBot.create(:project) } - let(:role) { FactoryBot.create(:role, permissions: [:view_messages, :view_wiki_pages]) } + let(:role) { FactoryBot.create(:role, permissions: %i[view_messages view_wiki_pages]) } let(:user) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) } let(:news) { FactoryBot.create(:news, project: project) } let(:forum) { FactoryBot.create(:forum, project: project) } diff --git a/spec/features/wiki/attachment_upload_spec.rb b/spec/features/wiki/attachment_upload_spec.rb index 0da661caaf..c521bc10af 100644 --- a/spec/features/wiki/attachment_upload_spec.rb +++ b/spec/features/wiki/attachment_upload_spec.rb @@ -127,7 +127,7 @@ describe 'Upload attachment to wiki page', js: true do expect(page).to have_selector('#errorExplanation', text: "Title can't be blank.") expect(page).to have_selector('.work-package--attachments--filename', text: 'image.png') - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| editable.send_keys 'hello there.' end diff --git a/spec/features/wiki/child_pages_spec.rb b/spec/features/wiki/child_pages_spec.rb index 40c66253e1..68a0d7003e 100644 --- a/spec/features/wiki/child_pages_spec.rb +++ b/spec/features/wiki/child_pages_spec.rb @@ -65,7 +65,7 @@ describe 'wiki child pages', type: :feature, js: true do # hierarchy displayed in the breadcrumb expect(page).to have_selector('#breadcrumb .breadcrumb', - text: "#{parent_page.title}") + text: parent_page.title.to_s) # hierarchy displayed in the sidebar expect(page).to have_selector('.pages-hierarchy', diff --git a/spec/features/work_package_show_spec.rb b/spec/features/work_package_show_spec.rb index 9b0a8374db..851cc59fb0 100644 --- a/spec/features/work_package_show_spec.rb +++ b/spec/features/work_package_show_spec.rb @@ -33,9 +33,9 @@ RSpec.feature 'Work package show page', selenium: true do let(:project) { FactoryBot.create(:project) } let(:work_package) do FactoryBot.build(:work_package, - project: project, - assigned_to: user, - responsible: user) + project: project, + assigned_to: user, + responsible: user) end before do diff --git a/spec/features/work_packages/attachments/attachment_upload_spec.rb b/spec/features/work_packages/attachments/attachment_upload_spec.rb index 4f1f9d88c3..86883d7778 100644 --- a/spec/features/work_packages/attachments/attachment_upload_spec.rb +++ b/spec/features/work_packages/attachments/attachment_upload_spec.rb @@ -102,7 +102,7 @@ describe 'Upload attachment to work package', js: true do sleep 2 expect(page).not_to have_selector('notification-upload-progress') - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| expect(editable).to have_selector('img[src*="/api/v3/attachments/"]', wait: 20) expect(editable).not_to have_selector('.ck-upload-placeholder-loader') end diff --git a/spec/features/work_packages/bulk/copy_work_package_spec.rb b/spec/features/work_packages/bulk/copy_work_package_spec.rb index c41784ac61..86ab0f0326 100644 --- a/spec/features/work_packages/bulk/copy_work_package_spec.rb +++ b/spec/features/work_packages/bulk/copy_work_package_spec.rb @@ -4,25 +4,26 @@ require 'features/page_objects/notification' describe 'Copy work packages through Rails view', js: true do let(:dev_role) do FactoryBot.create :role, - permissions: %i[view_work_packages] + permissions: %i[view_work_packages] end let(:mover_role) do FactoryBot.create :role, - permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks assign_versions add_work_packages] + permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks assign_versions + add_work_packages] end let(:dev) do FactoryBot.create :user, - firstname: 'Dev', - lastname: 'Guy', - member_in_project: project, - member_through_role: dev_role + firstname: 'Dev', + lastname: 'Guy', + member_in_project: project, + member_through_role: dev_role end let(:mover) do FactoryBot.create :admin, - firstname: 'Manager', - lastname: 'Guy', - member_in_project: project, - member_through_role: mover_role + firstname: 'Manager', + lastname: 'Guy', + member_in_project: project, + member_through_role: mover_role end let(:type) { FactoryBot.create :type, name: 'Bug' } @@ -31,28 +32,28 @@ describe 'Copy work packages through Rails view', js: true do let!(:project) { FactoryBot.create(:project, name: 'Source', types: [type, type2]) } let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type, type2]) } - let!(:work_package) { + let!(:work_package) do FactoryBot.create(:work_package, - author: dev, - project: project, - type: type) - } - let!(:work_package2) { + author: dev, + project: project, + type: type) + end + let!(:work_package2) do FactoryBot.create(:work_package, - author: dev, - project: project, - type: type) - } + author: dev, + project: project, + type: type) + end let(:status) { work_package.status } let!(:version) { FactoryBot.create :version, project: project2 } let!(:status2) { FactoryBot.create :default_status } let!(:workflow) do FactoryBot.create :workflow, - type_id: type2.id, - old_status: work_package.status, - new_status: status2, - role: mover_role + type_id: type2.id, + old_status: work_package.status, + new_status: status2, + role: mover_role end let(:wp_table) { ::Pages::WorkPackagesTable.new(project) } diff --git a/spec/features/work_packages/bulk/move_work_package_spec.rb b/spec/features/work_packages/bulk/move_work_package_spec.rb index f5689bc388..b42df0763f 100644 --- a/spec/features/work_packages/bulk/move_work_package_spec.rb +++ b/spec/features/work_packages/bulk/move_work_package_spec.rb @@ -4,25 +4,25 @@ require 'features/page_objects/notification' describe 'Moving a work package through Rails view', js: true do let(:dev_role) do FactoryBot.create :role, - permissions: %i[view_work_packages add_work_packages] + permissions: %i[view_work_packages add_work_packages] end let(:mover_role) do FactoryBot.create :role, - permissions: %i[view_work_packages move_work_packages manage_subtasks add_work_packages] + permissions: %i[view_work_packages move_work_packages manage_subtasks add_work_packages] end let(:dev) do FactoryBot.create :user, - firstname: 'Dev', - lastname: 'Guy', - member_in_project: project, - member_through_role: dev_role + firstname: 'Dev', + lastname: 'Guy', + member_in_project: project, + member_through_role: dev_role end let(:mover) do FactoryBot.create :admin, - firstname: 'Manager', - lastname: 'Guy', - member_in_project: project, - member_through_role: mover_role + firstname: 'Manager', + lastname: 'Guy', + member_in_project: project, + member_through_role: mover_role end let(:type) { FactoryBot.create :type, name: 'Bug' } @@ -31,28 +31,28 @@ describe 'Moving a work package through Rails view', js: true do let!(:project) { FactoryBot.create(:project, name: 'Source', types: [type, type2]) } let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type, type2]) } - let!(:work_package) { + let!(:work_package) do FactoryBot.create(:work_package, - author: dev, - project: project, - type: type) - } - let!(:child_wp) { + author: dev, + project: project, + type: type) + end + let!(:child_wp) do FactoryBot.create(:work_package, - author: dev, - parent: work_package, - project: project, - type: type) - } + author: dev, + parent: work_package, + project: project, + type: type) + end let(:status) { work_package.status } let!(:status2) { FactoryBot.create :default_status } let!(:workflow) do FactoryBot.create :workflow, - type_id: type2.id, - old_status: work_package.status, - new_status: status2, - role: mover_role + type_id: type2.id, + old_status: work_package.status, + new_status: status2, + role: mover_role end let(:wp_table) { ::Pages::WorkPackagesTable.new(project) } @@ -82,7 +82,6 @@ describe 'Moving a work package through Rails view', js: true do click_on 'Move and follow' end - it 'moves parent and child wp to a new project' do expect_angular_frontend_initialized expect(page).to have_selector('.inline-edit--container.subject', text: work_package.subject, wait: 10) diff --git a/spec/features/work_packages/bulk/update_work_package_spec.rb b/spec/features/work_packages/bulk/update_work_package_spec.rb index 99f7998f4f..084d7bae58 100644 --- a/spec/features/work_packages/bulk/update_work_package_spec.rb +++ b/spec/features/work_packages/bulk/update_work_package_spec.rb @@ -4,25 +4,25 @@ require 'features/page_objects/notification' describe 'Bulk update work packages through Rails view', js: true do let(:dev_role) do FactoryBot.create :role, - permissions: %i[view_work_packages] + permissions: %i[view_work_packages] end let(:mover_role) do FactoryBot.create :role, - permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks add_work_packages] + permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks add_work_packages] end let(:dev) do FactoryBot.create :user, - firstname: 'Dev', - lastname: 'Guy', - member_in_project: project, - member_through_role: dev_role + firstname: 'Dev', + lastname: 'Guy', + member_in_project: project, + member_through_role: dev_role end let(:mover) do FactoryBot.create :admin, - firstname: 'Manager', - lastname: 'Guy', - member_in_project: project, - member_through_role: mover_role + firstname: 'Manager', + lastname: 'Guy', + member_in_project: project, + member_through_role: mover_role end let(:type) { FactoryBot.create :type, name: 'Bug' } @@ -31,28 +31,28 @@ describe 'Bulk update work packages through Rails view', js: true do let!(:status) { FactoryBot.create :status } - let!(:work_package) { + let!(:work_package) do FactoryBot.create(:work_package, - author: dev, - status: status, - project: project, - type: type) - } - let!(:work_package2) { + author: dev, + status: status, + project: project, + type: type) + end + let!(:work_package2) do FactoryBot.create(:work_package, - author: dev, - status: status, - project: project, - type: type) - } + author: dev, + status: status, + project: project, + type: type) + end let!(:status2) { FactoryBot.create :default_status } let!(:workflow) do FactoryBot.create :workflow, - type_id: type.id, - old_status: work_package.status, - new_status: status2, - role: mover_role + type_id: type.id, + old_status: work_package.status, + new_status: status2, + role: mover_role end let(:wp_table) { ::Pages::WorkPackagesTable.new(project) } diff --git a/spec/features/work_packages/cancel_editing_spec.rb b/spec/features/work_packages/cancel_editing_spec.rb index af7457bda7..5926c145c3 100644 --- a/spec/features/work_packages/cancel_editing_spec.rb +++ b/spec/features/work_packages/cancel_editing_spec.rb @@ -35,14 +35,14 @@ describe 'Cancel editing work package', js: true do let(:work_package2) { FactoryBot.create(:work_package, project: project) } let(:wp_page) { ::Pages::AbstractWorkPackage.new(work_package) } let(:wp_table) { ::Pages::WorkPackagesTable.new } - let(:paths) { + let(:paths) do [ new_work_packages_path, new_split_work_packages_path, new_project_work_packages_path(project), new_split_project_work_packages_path(project) ] - } + end before do work_package diff --git a/spec/features/work_packages/cards/wp_card_status_spec.rb b/spec/features/work_packages/cards/wp_card_status_spec.rb index 315bcae1a7..489222250b 100644 --- a/spec/features/work_packages/cards/wp_card_status_spec.rb +++ b/spec/features/work_packages/cards/wp_card_status_spec.rb @@ -44,13 +44,13 @@ describe 'Update status from WP card', type: :feature, js: true do let(:type) { FactoryBot.create :type } let!(:project) { FactoryBot.create(:project, types: [type]) } - let!(:work_package) { + let!(:work_package) do FactoryBot.create(:work_package, project: project, type: type, status: status1, subject: 'Foobar') - } + end let!(:workflow) do FactoryBot.create :workflow, diff --git a/spec/features/work_packages/copy_spec.rb b/spec/features/work_packages/copy_spec.rb index ff5c058cbe..3aabefc15c 100644 --- a/spec/features/work_packages/copy_spec.rb +++ b/spec/features/work_packages/copy_spec.rb @@ -178,7 +178,6 @@ RSpec.feature 'Work package copy', js: true, selenium: true do work_package_page.expect_activity user, number: 1 work_package_page.expect_current_path - work_package_page.visit_tab!('relations') expect_angular_frontend_initialized expect(page).to have_selector('.relation-group--header', text: 'RELATED TO', wait: 20) diff --git a/spec/features/work_packages/details/custom_fields/custom_field_spec.rb b/spec/features/work_packages/details/custom_fields/custom_field_spec.rb index d64334f619..41153392f1 100644 --- a/spec/features/work_packages/details/custom_fields/custom_field_spec.rb +++ b/spec/features/work_packages/details/custom_fields/custom_field_spec.rb @@ -101,8 +101,8 @@ describe 'custom field inplace editor', js: true do message: I18n.t('js.notice_successful_update'), field: field2 - wp_page.expect_attributes :"customField#{custom_field1.id}" => 'bar', - :"customField#{custom_field2.id}" => 'Y' + wp_page.expect_attributes "customField#{custom_field1.id}": 'bar', + "customField#{custom_field2.id}": 'Y' field1.activate! expect(field1.input_element).to have_text 'bar' @@ -116,8 +116,8 @@ describe 'custom field inplace editor', js: true do message: I18n.t('js.notice_successful_update'), field: field2 - wp_page.expect_attributes :"customField#{custom_field1.id}" => 'bar', - :"customField#{custom_field2.id}" => 'X' + wp_page.expect_attributes "customField#{custom_field1.id}": 'bar', + "customField#{custom_field2.id}": 'X' end end diff --git a/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb b/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb index d0a4a05380..48c0d5a60f 100644 --- a/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb +++ b/spec/features/work_packages/details/inplace_editor/subject_editor_spec.rb @@ -11,7 +11,7 @@ describe 'subject inplace editor', js: true, selenium: true do let(:property_title) { 'Subject' } let(:work_package) { FactoryBot.create :work_package, project: project } let(:user) { FactoryBot.create :admin } - let(:work_packages_page) { Pages::SplitWorkPackage.new(work_package,project) } + let(:work_packages_page) { Pages::SplitWorkPackage.new(work_package, project) } let(:field) { work_packages_page.edit_field(property_name) } let(:notification) { ::PageObjects::Notifications.new(page) } diff --git a/spec/features/work_packages/details/relations/hierarchy_custom_fields_spec.rb b/spec/features/work_packages/details/relations/hierarchy_custom_fields_spec.rb index b3912b1a57..a5c734fb84 100644 --- a/spec/features/work_packages/details/relations/hierarchy_custom_fields_spec.rb +++ b/spec/features/work_packages/details/relations/hierarchy_custom_fields_spec.rb @@ -36,10 +36,11 @@ describe 'creating a child directly after the wp itself was created', js: true d let!(:status) { FactoryBot.create(:status, is_default: true) } let!(:priority) { FactoryBot.create(:priority, is_default: true) } let(:type) { FactoryBot.create(:type, custom_fields: [custom_field]) } - let(:custom_field) { FactoryBot.create :work_package_custom_field, - field_format: 'int', - is_for_all: true - } + let(:custom_field) do + FactoryBot.create :work_package_custom_field, + field_format: 'int', + is_for_all: true + end let(:relations_tab) { find('.tabrow li', text: 'RELATIONS') } before do diff --git a/spec/features/work_packages/details/relations/relations_spec.rb b/spec/features/work_packages/details/relations/relations_spec.rb index ae45cd1afc..0fcda9ccdd 100644 --- a/spec/features/work_packages/details/relations/relations_spec.rb +++ b/spec/features/work_packages/details/relations/relations_spec.rb @@ -69,15 +69,15 @@ describe 'Work package relations tab', js: true, selenium: true do let!(:relation_1) do FactoryBot.create :relation, - from: work_package, - to: to_1, - relation_type: Relation::TYPE_FOLLOWS + from: work_package, + to: to_1, + relation_type: Relation::TYPE_FOLLOWS end let!(:relation_2) do FactoryBot.create :relation, - from: work_package, - to: to_2, - relation_type: Relation::TYPE_RELATES + from: work_package, + to: to_2, + relation_type: Relation::TYPE_RELATES end let(:toggle_btn_selector) { '#wp-relation-group-by-toggle' } @@ -154,8 +154,8 @@ describe 'Work package relations tab', js: true, selenium: true do let(:user) do FactoryBot.create :user, - member_in_project: project, - member_through_role: user_role + member_in_project: project, + member_through_role: user_role end context 'as view-only user, with parent set' do @@ -257,7 +257,7 @@ describe 'Work package relations tab', js: true, selenium: true do relations.hover_action(relatable, :info) created_row = relations.find_row(relatable) - find'.wp-relation--description-read-value' + find '.wp-relation--description-read-value' end created_row.find('.wp-relation--description-read-value', diff --git a/spec/features/work_packages/display_fields/date_field_display_spec.rb b/spec/features/work_packages/display_fields/date_field_display_spec.rb index b5813c943c..fc1a6372e3 100644 --- a/spec/features/work_packages/display_fields/date_field_display_spec.rb +++ b/spec/features/work_packages/display_fields/date_field_display_spec.rb @@ -30,7 +30,7 @@ require 'spec_helper' describe 'Show the date of a Work Package', type: :feature, js: true do let(:project) { FactoryBot.create :project } - let(:admin) { FactoryBot.create :admin} + let(:admin) { FactoryBot.create :admin } let(:work_package) do FactoryBot.create :work_package, project: project, diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb index f08295e45f..509b297d22 100644 --- a/spec/features/work_packages/edit_work_package_spec.rb +++ b/spec/features/work_packages/edit_work_package_spec.rb @@ -4,8 +4,8 @@ require 'features/page_objects/notification' describe 'edit work package', js: true do let(:dev_role) do FactoryBot.create :role, - permissions: [:view_work_packages, - :add_work_packages] + permissions: %i[view_work_packages + add_work_packages] end let(:dev) do FactoryBot.create :user, @@ -16,8 +16,8 @@ describe 'edit work package', js: true do end let(:manager_role) do FactoryBot.create :role, - permissions: [:view_work_packages, - :edit_work_packages] + permissions: %i[view_work_packages + edit_work_packages] end let(:manager) do FactoryBot.create :admin, @@ -198,8 +198,8 @@ describe 'edit work package', js: true do :work_package_custom_field, field_format: 'string', default_value: nil, - is_required: true, - is_for_all: true + is_required: true, + is_for_all: true ) end let!(:type2) { FactoryBot.create(:type, custom_fields: [custom_field]) } diff --git a/spec/features/work_packages/export_spec.rb b/spec/features/work_packages/export_spec.rb index ee7fea38ef..d0a680cc57 100644 --- a/spec/features/work_packages/export_spec.rb +++ b/spec/features/work_packages/export_spec.rb @@ -77,7 +77,7 @@ describe 'work package export', type: :feature do begin perform_enqueued_jobs - rescue + rescue StandardError # nothing end diff --git a/spec/features/work_packages/highlighting_spec.rb b/spec/features/work_packages/highlighting_spec.rb index e10040c341..11a408386b 100644 --- a/spec/features/work_packages/highlighting_spec.rb +++ b/spec/features/work_packages/highlighting_spec.rb @@ -10,7 +10,9 @@ describe 'Work Package highlighting fields', let(:status1) { FactoryBot.create :status, color: FactoryBot.create(:color, hexcode: '#FF0000') } # rgba(255, 0, 0, 1) let(:status2) { FactoryBot.create :status, color: FactoryBot.create(:color, hexcode: '#F0F0F0') } # rgba(240, 240, 240, 1) - let(:priority1) { FactoryBot.create :issue_priority, color: FactoryBot.create(:color, hexcode: '#123456') } #rgba(18, 52, 86, 1) + let(:priority1) do + FactoryBot.create :issue_priority, color: FactoryBot.create(:color, hexcode: '#123456') + end let(:priority_no_color) { FactoryBot.create :issue_priority, color: nil } let!(:wp_1) do @@ -47,7 +49,6 @@ describe 'Work Package highlighting fields', end before do - # Ensure Rails and Capybara caches are cleared Rails.cache.clear Capybara.reset! diff --git a/spec/features/work_packages/navigation_spec.rb b/spec/features/work_packages/navigation_spec.rb index 8b90570307..340fd90836 100644 --- a/spec/features/work_packages/navigation_spec.rb +++ b/spec/features/work_packages/navigation_spec.rb @@ -97,7 +97,6 @@ RSpec.feature 'Work package navigation', js: true, selenium: true do project_work_packages.expect_work_package_listed(work_package) project_html_title.expect_first_segment 'All open' - # Visit query with project wp project_work_packages.visit_query query project_work_packages.expect_work_package_listed(work_package) @@ -154,7 +153,6 @@ RSpec.feature 'Work package navigation', js: true, selenium: true do page404.expect_and_dismiss_notification type: :error, message: I18n.t('api_v3.errors.code_404') end - # Regression #29994 scenario 'access the work package views directly from a non-angular view' do visit project_path(project) @@ -203,7 +201,7 @@ RSpec.feature 'Work package navigation', js: true, selenium: true do # Click on All open find('.collapsible-menu--item-link', text: 'All open').click - + if OpenProject::Configuration.bim? wp_display.expect_state 'Cards' else diff --git a/spec/features/work_packages/new/new_work_package_spec.rb b/spec/features/work_packages/new/new_work_package_spec.rb index 3f55f76646..7500ae6a0b 100644 --- a/spec/features/work_packages/new/new_work_package_spec.rb +++ b/spec/features/work_packages/new/new_work_package_spec.rb @@ -44,7 +44,7 @@ describe 'new work package', js: true do end end - def create_work_package(type, project) + def create_work_package(type, _project) loading_indicator_saveguard wp_page.click_create_wp_button(type) @@ -435,7 +435,7 @@ describe 'new work package', js: true do # The dates are taken over from the parent by default date_field = split_create_page.edit_field(:combinedDate) - date_field.expect_value("#{parent.start_date} - #{parent.due_date}" ) + date_field.expect_value("#{parent.start_date} - #{parent.due_date}") date_field.input_element.click sleep 1 diff --git a/spec/features/work_packages/pagination_spec.rb b/spec/features/work_packages/pagination_spec.rb index 747dee5bed..140b5b5701 100644 --- a/spec/features/work_packages/pagination_spec.rb +++ b/spec/features/work_packages/pagination_spec.rb @@ -73,7 +73,6 @@ RSpec.feature 'Work package pagination', js: true do expect(page).to have_content(work_package_2.subject) end end - end context 'with project scope' do diff --git a/spec/features/work_packages/project_context_switch_spec.rb b/spec/features/work_packages/project_context_switch_spec.rb index f06685f0a0..bb82276ff0 100644 --- a/spec/features/work_packages/project_context_switch_spec.rb +++ b/spec/features/work_packages/project_context_switch_spec.rb @@ -6,7 +6,7 @@ describe 'Project context switching spec', js: true do let(:project) { FactoryBot.create(:project) } let(:work_package) { FactoryBot.create(:work_package, project: project) } - let(:wp_table) { Pages::WorkPackagesTable.new } + let(:wp_table) { Pages::WorkPackagesTable.new } let(:wp_page) { Pages::FullWorkPackage.new(work_package, project) } before do diff --git a/spec/features/work_packages/shared_contexts.rb b/spec/features/work_packages/shared_contexts.rb index 89ef8bb2f2..96940f807a 100644 --- a/spec/features/work_packages/shared_contexts.rb +++ b/spec/features/work_packages/shared_contexts.rb @@ -30,8 +30,10 @@ # The status filter is loaded very late in the page setup. shared_context 'ensure wp details pane update done' do after do - raise "Expect to have a let called 'update_user' defining which user \ - is doing the update".squish unless update_user + unless update_user + raise "Expect to have a let called 'update_user' defining which user \ + is doing the update".squish + end # safeguard to ensure all backend queries # have been answered before starting a new spec diff --git a/spec/features/work_packages/sorting/table_sorting_spec.rb b/spec/features/work_packages/sorting/table_sorting_spec.rb index 99704b17a1..30f3bcc7ea 100644 --- a/spec/features/work_packages/sorting/table_sorting_spec.rb +++ b/spec/features/work_packages/sorting/table_sorting_spec.rb @@ -45,11 +45,11 @@ describe 'Select work package row', type: :feature, js: true do let(:version_1) do FactoryBot.create(:version, project: project, - name: 'aaa_version') + name: 'aaa_version') end let(:version_2) do FactoryBot.create(:version, project: project, - name: 'zzz_version') + name: 'zzz_version') end let(:columns) { ::Components::WorkPackages::Columns.new } let(:sort_by) { ::Components::WorkPackages::SortBy.new } @@ -107,32 +107,32 @@ describe 'Select work package row', type: :feature, js: true do let(:parent) do FactoryBot.create :work_package, - project: project + project: project end let(:child1) do FactoryBot.create :work_package, - project: project, - parent: parent + project: project, + parent: parent end let(:child2) do FactoryBot.create :work_package, - project: project, - parent: parent + project: project, + parent: parent end let(:grand_child1) do FactoryBot.create :work_package, - project: project, - parent: child1 + project: project, + parent: child1 end let(:grand_child2) do FactoryBot.create :work_package, - project: project, - parent: child2 + project: project, + parent: child2 end let(:grand_child3) do FactoryBot.create :work_package, - project: project, - parent: child1 + project: project, + parent: child1 end before do diff --git a/spec/features/work_packages/table/configuration_modal/column_spec.rb b/spec/features/work_packages/table/configuration_modal/column_spec.rb index 14cdea9494..a583250148 100644 --- a/spec/features/work_packages/table/configuration_modal/column_spec.rb +++ b/spec/features/work_packages/table/configuration_modal/column_spec.rb @@ -46,7 +46,6 @@ describe 'Work Package table configuration modal columns spec', js: true do context 'When seeing the table' do it_behaves_like 'add and remove columns' - context 'with three columns', driver: :firefox_de do let!(:query) do query = FactoryBot.build(:query, user: user, project: project) diff --git a/spec/features/work_packages/table/context_menu_spec.rb b/spec/features/work_packages/table/context_menu_spec.rb index fcb5cb1866..d362d72501 100644 --- a/spec/features/work_packages/table/context_menu_spec.rb +++ b/spec/features/work_packages/table/context_menu_spec.rb @@ -11,7 +11,7 @@ describe 'Work package table context menu', js: true do let(:time_logging_modal) { Components::TimeLoggingModal.new } let(:display_representation) { ::Components::WorkPackages::DisplayRepresentation.new } - def goto_context_menu list_view = true + def goto_context_menu(list_view = true) # Go to table wp_table.visit! wp_table.expect_work_package_listed(work_package) @@ -58,9 +58,9 @@ describe 'Work package table context menu', js: true do goto_context_menu list_view menu.choose('Copy') # Split view open in copy state - expect(page). - to have_selector('.wp-new-top-row', - text: "#{work_package.status.name.capitalize}\n#{work_package.type.name.upcase}") + expect(page) + .to have_selector('.wp-new-top-row', + text: "#{work_package.status.name.capitalize}\n#{work_package.type.name.upcase}") expect(page).to have_field('wp-new-inline-edit--field-subject', with: work_package.subject) # Open Delete @@ -74,7 +74,7 @@ describe 'Work package table context menu', js: true do menu.choose('Create new child') expect(page).to have_selector('.inline-edit--container.subject input') expect(page).to have_selector('.inline-edit--field.type') - expect(current_url).to match(/.*\/create_new\?.*(\&)*parent_id=#{work_package.id.to_s}/) + expect(current_url).to match(/.*\/create_new\?.*(&)*parent_id=#{work_package.id}/) find('#work-packages--edit-actions-cancel').click expect(page).to have_no_selector('.inline-edit--container.subject input') @@ -143,7 +143,7 @@ describe 'Work package table context menu', js: true do goto_context_menu true menu.choose('Create new child') expect(page).to have_selector('.inline-edit--container.subject input') - expect(current_url).to match(/.*\/create_new\?.*(\&)*parent_id=#{work_package.id.to_s}/) + expect(current_url).to match(/.*\/create_new\?.*(&)*parent_id=#{work_package.id}/) split_view = ::Pages::SplitWorkPackageCreate.new project: work_package.project subject = split_view.edit_field(:subject) diff --git a/spec/features/work_packages/table/delete_work_packages_spec.rb b/spec/features/work_packages/table/delete_work_packages_spec.rb index 1df250379f..2c2bba5877 100644 --- a/spec/features/work_packages/table/delete_work_packages_spec.rb +++ b/spec/features/work_packages/table/delete_work_packages_spec.rb @@ -101,7 +101,7 @@ describe 'Delete work package', js: true do describe 'when deleting it within a project context' do let(:project) { FactoryBot.create(:project) } - let(:work_package) { FactoryBot.create(:work_package, project:project) } + let(:work_package) { FactoryBot.create(:work_package, project: project) } let(:split_view) { Pages::SplitWorkPackage.new(work_package, project.identifier) } let(:wp_table) { Pages::WorkPackagesTable.new(project.identifier) } diff --git a/spec/features/work_packages/table/edit_work_packages_spec.rb b/spec/features/work_packages/table/edit_work_packages_spec.rb index 68ff00be89..8d2ce95763 100644 --- a/spec/features/work_packages/table/edit_work_packages_spec.rb +++ b/spec/features/work_packages/table/edit_work_packages_spec.rb @@ -3,37 +3,37 @@ require 'spec_helper' describe 'Inline editing work packages', js: true do let(:manager_role) do FactoryBot.create :role, - permissions: [:view_work_packages, - :edit_work_packages] + permissions: %i[view_work_packages + edit_work_packages] end let(:manager) do FactoryBot.create :user, - firstname: 'Manager', - lastname: 'Guy', - member_in_project: project, - member_through_role: manager_role + firstname: 'Manager', + lastname: 'Guy', + member_in_project: project, + member_through_role: manager_role end let(:type) { FactoryBot.create :type } let(:status1) { FactoryBot.create :status } let(:status2) { FactoryBot.create :status } let(:project) { FactoryBot.create(:project, types: [type]) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, - project: project, - type: type, - status: status1, - subject: 'Foobar') - } + project: project, + type: type, + status: status1, + subject: 'Foobar') + end let(:wp_table) { Pages::WorkPackagesTable.new(project) } let(:workflow) do FactoryBot.create :workflow, - type_id: type.id, - old_status: status1, - new_status: status2, - role: manager_role + type_id: type.id, + old_status: status1, + new_status: status2, + role: manager_role end let(:version) { FactoryBot.create :version, project: project } let(:category) { FactoryBot.create :category, project: project } @@ -116,34 +116,34 @@ describe 'Inline editing work packages', js: true do end context 'custom field' do - let(:custom_fields) { + let(:custom_fields) do fields = [ FactoryBot.create( :work_package_custom_field, - field_format: 'list', + field_format: 'list', possible_values: %w(foo bar xyz), - is_required: true, - is_for_all: false + is_required: true, + is_for_all: false ), FactoryBot.create( :work_package_custom_field, field_format: 'string', - is_required: true, - is_for_all: false + is_required: true, + is_for_all: false ) ] fields - } + end let(:type) { FactoryBot.create(:type_task, custom_fields: custom_fields) } let(:project) { FactoryBot.create(:project, types: [type]) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, - subject: 'Foobar', - status: status1, - type: type, - project: project) - } + subject: 'Foobar', + status: status1, + type: type, + project: project) + end before do work_package @@ -169,7 +169,7 @@ describe 'Inline editing work packages', js: true do cf_list_name = custom_fields.first.name cf_text_name = custom_fields.last.name wp_table.expect_notification( - type: :error, + type: :error, message: "#{cf_list_name} can't be blank.\n#{cf_text_name} can't be blank." ) diff --git a/spec/features/work_packages/table/hierarchy/hierarchy_parent_below_spec.rb b/spec/features/work_packages/table/hierarchy/hierarchy_parent_below_spec.rb index 76751a75ce..28edaaf8d6 100644 --- a/spec/features/work_packages/table/hierarchy/hierarchy_parent_below_spec.rb +++ b/spec/features/work_packages/table/hierarchy/hierarchy_parent_below_spec.rb @@ -65,7 +65,6 @@ describe 'Work Package table hierarchy parent below', js: true do wp_table.visit_query query wp_table.expect_work_package_listed(child, parent, grandparent) - # Double order result from regression # wp_table.expect_work_package_order(child.id, parent.id, grandparent.id, grandparent.id) wp_table.expect_work_package_order(grandparent.id, parent.id, child.id) @@ -157,12 +156,12 @@ describe 'Work Package table hierarchy parent below', js: true do wp_table.expect_work_package_listed(child, parent) expect(page).to have_selector('.wp-table--hierarchy-indicator-icon') - + split_page = wp_table.open_split_view(parent) split_page.visit_tab!("relations") relations.remove_child(child) loading_indicator_saveguard - + expect(page).to have_no_selector('.wp-table--hierarchy-indicator-icon') end end diff --git a/spec/features/work_packages/table/hierarchy/hierarchy_spec.rb b/spec/features/work_packages/table/hierarchy/hierarchy_spec.rb index 8133302436..d165a17409 100644 --- a/spec/features/work_packages/table/hierarchy/hierarchy_spec.rb +++ b/spec/features/work_packages/table/hierarchy/hierarchy_spec.rb @@ -176,8 +176,8 @@ describe 'Work Package table hierarchy', js: true do let(:user) do FactoryBot.create :user, - member_in_project: project, - member_through_role: role + member_in_project: project, + member_through_role: role end let(:permissions) { %i(view_work_packages add_work_packages save_queries) } let(:role) { FactoryBot.create :role, permissions: permissions } @@ -250,7 +250,7 @@ describe 'Work Package table hierarchy', js: true do hierarchy.toggle_row(root_assigned) # Sort descending - sort_by.update_criteria([ 'Assignee', descending: true]) + sort_by.update_criteria(['Assignee', { descending: true }]) loading_indicator_saveguard wp_table.expect_work_package_listed(root, root_assigned) diff --git a/spec/features/work_packages/table/hierarchy/parent_column_spec.rb b/spec/features/work_packages/table/hierarchy/parent_column_spec.rb index 40ccba32d4..e7fc38a712 100644 --- a/spec/features/work_packages/table/hierarchy/parent_column_spec.rb +++ b/spec/features/work_packages/table/hierarchy/parent_column_spec.rb @@ -10,7 +10,6 @@ describe 'Work Package table parent column', js: true do login_as(user) end - let!(:parent) { FactoryBot.create(:work_package, project: project) } let!(:child) { FactoryBot.create(:work_package, project: project, parent: parent) } diff --git a/spec/features/work_packages/table/inline_create/create_work_packages_spec.rb b/spec/features/work_packages/table/inline_create/create_work_packages_spec.rb index d5fbbd1c0f..0fbae4a66a 100644 --- a/spec/features/work_packages/table/inline_create/create_work_packages_spec.rb +++ b/spec/features/work_packages/table/inline_create/create_work_packages_spec.rb @@ -151,7 +151,7 @@ describe 'inline create work package', js: true do it_behaves_like 'inline create work package' do let(:callback) do - ->() { + -> { # Set project project_field = wp_table.edit_field(nil, :project) project_field.expect_active! @@ -179,7 +179,7 @@ describe 'inline create work package', js: true do it_behaves_like 'inline create work package' do let(:callback) do - ->() {} + -> {} end end diff --git a/spec/features/work_packages/table/inline_create/inline_create_refresh_spec.rb b/spec/features/work_packages/table/inline_create/inline_create_refresh_spec.rb index 58efcf83b1..df34e15233 100644 --- a/spec/features/work_packages/table/inline_create/inline_create_refresh_spec.rb +++ b/spec/features/work_packages/table/inline_create/inline_create_refresh_spec.rb @@ -22,7 +22,6 @@ describe 'Refreshing in inline-create row', flaky: true, js: true do wp_table.visit_query(query) end - it 'correctly updates the set of active columns' do expect(page).to have_selector('.wp--row', count: 0) diff --git a/spec/features/work_packages/table/queries/assignee_filter_spec.rb b/spec/features/work_packages/table/queries/assignee_filter_spec.rb index b0f3d674f1..0710fae5c5 100644 --- a/spec/features/work_packages/table/queries/assignee_filter_spec.rb +++ b/spec/features/work_packages/table/queries/assignee_filter_spec.rb @@ -32,7 +32,7 @@ describe 'Work package filtering by assignee', js: true do let(:project) { FactoryBot.create :project } let(:wp_table) { ::Pages::WorkPackagesTable.new(project) } let(:filters) { ::Components::WorkPackages::Filters.new } - let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages, :save_queries]) } + let(:role) { FactoryBot.create(:role, permissions: %i[view_work_packages save_queries]) } let(:other_user) do FactoryBot.create :user, firstname: 'Other', diff --git a/spec/features/work_packages/table/queries/filter_spec.rb b/spec/features/work_packages/table/queries/filter_spec.rb index d11e2820c8..0be2319be4 100644 --- a/spec/features/work_packages/table/queries/filter_spec.rb +++ b/spec/features/work_packages/table/queries/filter_spec.rb @@ -73,7 +73,9 @@ describe 'filter work packages', js: true do context 'by version in project' do let(:version) { FactoryBot.create :version, project: project } - let(:work_package_with_version) { FactoryBot.create :work_package, project: project, subject: 'With version', version: version } + let(:work_package_with_version) do + FactoryBot.create :work_package, project: project, subject: 'With version', version: version + end let(:work_package_without_version) { FactoryBot.create :work_package, subject: 'Without version', project: project } before do @@ -214,7 +216,6 @@ describe 'filter work packages', js: true do end it 'allows filtering, saving and retrieving the saved filter' do - # Wait for form to load filters.expect_loaded @@ -293,7 +294,6 @@ describe 'filter work packages', js: true do end it 'allows filtering, saving and retrieving the saved filter' do - # Wait for form to load filters.expect_loaded @@ -337,7 +337,6 @@ describe 'filter work packages', js: true do loading_indicator_saveguard wp_table.expect_work_package_listed work_package_and wp_table.ensure_work_package_not_listed! work_package_plus - end end @@ -512,26 +511,26 @@ describe 'filter work packages', js: true do end describe 'add parent WP filter' do - let(:wp_parent) { FactoryBot.create :work_package, project: project, subject: 'project' } - let(:wp_child1) { FactoryBot.create :work_package, project: project, subject: 'child 1', parent: wp_parent } - let(:wp_child2) { FactoryBot.create :work_package, project: project, subject: 'child 2', parent: wp_parent } - let(:wp_default) { FactoryBot.create :work_package, project: project, subject: 'default' } - - it do - wp_parent - wp_child1 - wp_child2 - wp_default - wp_table.visit! - loading_indicator_saveguard - filters.expect_loaded - filters.open - filters.add_filter_by 'Parent', 'is', [wp_parent.subject] - loading_indicator_saveguard - - # It should show the children of the selected parent - wp_table.expect_work_package_listed wp_child1, wp_child2 - wp_table.ensure_work_package_not_listed! wp_default + let(:wp_parent) { FactoryBot.create :work_package, project: project, subject: 'project' } + let(:wp_child1) { FactoryBot.create :work_package, project: project, subject: 'child 1', parent: wp_parent } + let(:wp_child2) { FactoryBot.create :work_package, project: project, subject: 'child 2', parent: wp_parent } + let(:wp_default) { FactoryBot.create :work_package, project: project, subject: 'default' } + + it do + wp_parent + wp_child1 + wp_child2 + wp_default + wp_table.visit! + loading_indicator_saveguard + filters.expect_loaded + filters.open + filters.add_filter_by 'Parent', 'is', [wp_parent.subject] + loading_indicator_saveguard + + # It should show the children of the selected parent + wp_table.expect_work_package_listed wp_child1, wp_child2 + wp_table.ensure_work_package_not_listed! wp_default + end end end -end diff --git a/spec/features/work_packages/table/queries/me_filter_spec.rb b/spec/features/work_packages/table/queries/me_filter_spec.rb index b89e68bfd5..c00d3a43ec 100644 --- a/spec/features/work_packages/table/queries/me_filter_spec.rb +++ b/spec/features/work_packages/table/queries/me_filter_spec.rb @@ -29,7 +29,7 @@ require 'spec_helper' describe 'filter me value', js: true do - let(:status) { FactoryBot.create :default_status} + let(:status) { FactoryBot.create :default_status } let!(:priority) { FactoryBot.create :default_priority } let(:project) { FactoryBot.create :project, public: true } let(:role) { FactoryBot.create :existing_role, permissions: [:view_work_packages] } @@ -51,9 +51,9 @@ describe 'filter me value', js: true do context 'as anonymous', with_settings: { login_required?: false } do let(:assignee_query) do query = FactoryBot.create(:query, - name: 'Assignee Query', - project: project, - user: user) + name: 'Assignee Query', + project: project, + user: user) query.add_filter('assigned_to_id', '=', ['me']) query.save!(validate: false) @@ -131,32 +131,32 @@ describe 'filter me value', js: true do let(:type_task) { FactoryBot.create(:type_task, custom_fields: [custom_field]) } let(:project) do FactoryBot.create(:project, - types: [type_task], - work_package_custom_fields: [custom_field]) + types: [type_task], + work_package_custom_fields: [custom_field]) end let(:cf_accessor) { "cf_#{custom_field.id}" } let(:cf_accessor_frontend) { "customField#{custom_field.id}" } let(:wp_admin) do FactoryBot.create :work_package, - type: type_task, - project: project, - custom_field_values: { custom_field.id => admin.id } + type: type_task, + project: project, + custom_field_values: { custom_field.id => admin.id } end let(:wp_user) do FactoryBot.create :work_package, - type: type_task, - project: project, - custom_field_values: { custom_field.id => user.id } + type: type_task, + project: project, + custom_field_values: { custom_field.id => user.id } end context 'as anonymous', with_settings: { login_required?: false } do let(:assignee_query) do query = FactoryBot.create(:query, - name: 'CF user Query', - project: project, - user: user) + name: 'CF user Query', + project: project, + user: user) query.add_filter(cf_accessor, '=', ['me']) query.save!(validate: false) diff --git a/spec/features/work_packages/table/queries/query_history_spec.rb b/spec/features/work_packages/table/queries/query_history_spec.rb index af4c2d62e5..cd35543e77 100644 --- a/spec/features/work_packages/table/queries/query_history_spec.rb +++ b/spec/features/work_packages/table/queries/query_history_spec.rb @@ -31,43 +31,43 @@ require 'spec_helper' describe 'Going back and forth through the browser history', type: :feature, js: true do let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let(:project) { FactoryBot.create(:project) } let(:type) { project.types.first } let(:role) do FactoryBot.create(:role, - permissions: [:view_work_packages, - :save_queries]) + permissions: %i[view_work_packages + save_queries]) end let(:work_package_1) do FactoryBot.create(:work_package, - project: project, - type: type) + project: project, + type: type) end let(:work_package_2) do FactoryBot.create(:work_package, - project: project, - type: type, - assigned_to: user) + project: project, + type: type, + assigned_to: user) end let(:version) do FactoryBot.create(:version, - project: project) + project: project) end let(:work_package_3) do FactoryBot.create(:work_package, - project: project, - type: type, - version: version) + project: project, + type: type, + version: version) end let(:assignee_query) do query = FactoryBot.create(:query, - name: 'Assignee Query', - project: project, - user: user) + name: 'Assignee Query', + project: project, + user: user) query.add_filter('assigned_to_id', '=', [user.id]) query.save! @@ -76,9 +76,9 @@ describe 'Going back and forth through the browser history', type: :feature, js: end let(:version_query) do query = FactoryBot.create(:query, - name: 'Version Query', - project: project, - user: user) + name: 'Version Query', + project: project, + user: user) query.add_filter('version_id', '=', [version.id]) query.save! diff --git a/spec/features/work_packages/table/queries/query_name_inline_edit_spec.rb b/spec/features/work_packages/table/queries/query_name_inline_edit_spec.rb index c8d2381889..c29c6d839d 100644 --- a/spec/features/work_packages/table/queries/query_name_inline_edit_spec.rb +++ b/spec/features/work_packages/table/queries/query_name_inline_edit_spec.rb @@ -38,8 +38,8 @@ describe 'Query name inline edit', js: true do let(:type) { project.types.first } let(:role) do FactoryBot.create(:role, - permissions: [:view_work_packages, - :save_queries]) + permissions: %i[view_work_packages + save_queries]) end let(:work_package) do diff --git a/spec/features/work_packages/table/queries/responsible_filter_spec.rb b/spec/features/work_packages/table/queries/responsible_filter_spec.rb index 3caec00530..46f71f69a3 100644 --- a/spec/features/work_packages/table/queries/responsible_filter_spec.rb +++ b/spec/features/work_packages/table/queries/responsible_filter_spec.rb @@ -32,7 +32,7 @@ describe 'Work package filtering by responsible', js: true do let(:project) { FactoryBot.create :project } let(:wp_table) { ::Pages::WorkPackagesTable.new(project) } let(:filters) { ::Components::WorkPackages::Filters.new } - let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages, :save_queries]) } + let(:role) { FactoryBot.create(:role, permissions: %i[view_work_packages save_queries]) } let(:other_user) do FactoryBot.create :user, firstname: 'Other', diff --git a/spec/features/work_packages/table/queries/summary_spec.rb b/spec/features/work_packages/table/queries/summary_spec.rb index 5b3e7200cb..ac24b6889c 100644 --- a/spec/features/work_packages/table/queries/summary_spec.rb +++ b/spec/features/work_packages/table/queries/summary_spec.rb @@ -36,7 +36,7 @@ describe 'Work package query summary item', type: :feature, js: true do let(:wp_page) { ::Pages::WorkPackagesTable.new project } let(:current_user) do FactoryBot.create :user, member_in_project: project, - member_through_role: role + member_through_role: role end before do diff --git a/spec/features/work_packages/table/queries/user_cf_filter_spec.rb b/spec/features/work_packages/table/queries/user_cf_filter_spec.rb index bd61c0852d..c40d8ca1ad 100644 --- a/spec/features/work_packages/table/queries/user_cf_filter_spec.rb +++ b/spec/features/work_packages/table/queries/user_cf_filter_spec.rb @@ -38,7 +38,6 @@ describe 'Work package filtering by user custom field', js: true do type.custom_fields << cf project.work_package_custom_fields << cf end - end let(:role) { FactoryBot.create(:role, permissions: %i[view_work_packages save_queries]) } let(:other_user) do diff --git a/spec/features/work_packages/table/relations_spec.rb b/spec/features/work_packages/table/relations_spec.rb index 9f4e28638e..73dbe16b48 100644 --- a/spec/features/work_packages/table/relations_spec.rb +++ b/spec/features/work_packages/table/relations_spec.rb @@ -18,15 +18,15 @@ describe 'Work Package table relations', js: true do let!(:relation) do FactoryBot.create(:relation, - from: wp_from, - to: wp_to, - relation_type: Relation::TYPE_FOLLOWS) + from: wp_from, + to: wp_to, + relation_type: Relation::TYPE_FOLLOWS) end let!(:relation2) do FactoryBot.create(:relation, - from: wp_from, - to: wp_to2, - relation_type: Relation::TYPE_FOLLOWS) + from: wp_from, + to: wp_to2, + relation_type: Relation::TYPE_FOLLOWS) end let!(:query) do query = FactoryBot.build(:query, user: user, project: project) diff --git a/spec/features/work_packages/table/scheduling/manual_scheduling_spec.rb b/spec/features/work_packages/table/scheduling/manual_scheduling_spec.rb index b93bf76d2f..4e0d5b8d16 100644 --- a/spec/features/work_packages/table/scheduling/manual_scheduling_spec.rb +++ b/spec/features/work_packages/table/scheduling/manual_scheduling_spec.rb @@ -70,7 +70,6 @@ describe 'Manual scheduling', js: true do expect(page).to have_selector('input[name="endDate"]:not([disabled])') expect(page).to have_selector('.datepicker-modal--action:not([disabled])', text: 'Cancel') expect(page).to have_selector('.datepicker-modal--action:not([disabled])', text: 'Save') - end start_date.cancel_by_click @@ -95,7 +94,6 @@ describe 'Manual scheduling', js: true do expect(page).to have_selector('input[name=endDate][disabled]') expect(page).to have_selector('.datepicker-modal--action:not([disabled])', text: 'Cancel') expect(page).to have_selector('.datepicker-modal--action[disabled]', text: 'Save') - end start_date.toggle_scheduling_mode diff --git a/spec/features/work_packages/tabs/activity_revisions_spec.rb b/spec/features/work_packages/tabs/activity_revisions_spec.rb index 9290f391a1..4780af67ac 100644 --- a/spec/features/work_packages/tabs/activity_revisions_spec.rb +++ b/spec/features/work_packages/tabs/activity_revisions_spec.rb @@ -93,14 +93,14 @@ describe 'Activity tab', js: true, selenium: true do end date_selector = ".work-package-details-activities-activity:nth-of-type(#{actual_index}) " + - '.activity-date' + '.activity-date' # Do not use :long format to match the printed date without double spaces # on the first 9 days of the month expected_date = if activity.is_a?(Journal) - activity.created_at - else - activity.committed_on - end.to_date.strftime("%B %-d, %Y") + activity.created_at + else + activity.committed_on + end.to_date.strftime("%B %-d, %Y") expect(page).to have_selector(date_selector, text: expected_date) diff --git a/spec/features/work_packages/tabs/watcher_tab_spec.rb b/spec/features/work_packages/tabs/watcher_tab_spec.rb index d4125f7ed1..f8ee72e8d6 100644 --- a/spec/features/work_packages/tabs/watcher_tab_spec.rb +++ b/spec/features/work_packages/tabs/watcher_tab_spec.rb @@ -8,12 +8,12 @@ describe 'Watcher tab', js: true, selenium: true do let(:tabs) { ::Components::WorkPackages::Tabs.new(work_package) } let(:user) { FactoryBot.create(:user, member_in_project: project, member_through_role: role) } let(:role) { FactoryBot.create(:role, permissions: permissions) } - let(:permissions) { + let(:permissions) do %i(view_work_packages view_work_package_watchers delete_work_package_watchers add_work_package_watchers) - } + end let(:watch_button) { find '#watch-button' } let(:watchers_tab) { find('.tabrow li.selected', text: 'WATCHERS') } @@ -83,12 +83,12 @@ describe 'Watcher tab', js: true, selenium: true do end context 'with a user with arbitrary characters' do - let!(:html_user) { + let!(:html_user) do FactoryBot.create :user, - firstname: 'foo', - member_in_project: project, - member_through_role: role - } + firstname: 'foo', + member_in_project: project, + member_through_role: role + end it 'escapes the user name' do autocomplete = find('.wp-watcher--autocomplete') @@ -119,7 +119,7 @@ describe 'Watcher tab', js: true, selenium: true do let(:wp_page) { Pages::FullWorkPackage.new(work_package) } it_behaves_like 'watchers tab' end - + context 'when the work package has a watcher' do let(:watchers) { FactoryBot.create(:watcher, watchable: work_package, user: user) } let(:wp_table) { Pages::WorkPackagesTable.new(project) } @@ -129,11 +129,11 @@ describe 'Watcher tab', js: true, selenium: true do login_as(user) wp_table.visit! wp_table.expect_work_package_listed work_package - end - + end + it 'should show the number of watchers [#33685]' do wp_table.open_full_screen_by_doubleclick(work_package) - expect(page).to have_selector('.wp-tabs-count', text: 1) + expect(page).to have_selector('.wp-tabs-count', text: 1) end end diff --git a/spec/features/work_packages/timeline/timeline_hierarchy_spec.rb b/spec/features/work_packages/timeline/timeline_hierarchy_spec.rb index 4d2b50cc2a..1e109c5fbf 100644 --- a/spec/features/work_packages/timeline/timeline_hierarchy_spec.rb +++ b/spec/features/work_packages/timeline/timeline_hierarchy_spec.rb @@ -43,15 +43,15 @@ RSpec.feature 'Work package timeline hierarchies', js: true, selenium: true do let!(:wp_root) do FactoryBot.create :work_package, - project: project + project: project end let!(:wp_leaf) do FactoryBot.create :work_package, - project: project, - parent: wp_root, - start_date: Date.today, - due_date: (Date.today + 5.days) + project: project, + parent: wp_root, + start_date: Date.today, + due_date: (Date.today + 5.days) end let!(:query) do @@ -91,15 +91,15 @@ RSpec.feature 'Work package timeline hierarchies', js: true, selenium: true do context 'with a relation being rendered to a hidden row' do let!(:wp_other) do FactoryBot.create :work_package, - project: project, - start_date: Date.today + 5.days, - due_date: (Date.today + 10.days) + project: project, + start_date: Date.today + 5.days, + due_date: (Date.today + 10.days) end let!(:relation) do FactoryBot.create(:relation, - from: wp_leaf, - to: wp_other, - relation_type: Relation::TYPE_FOLLOWS) + from: wp_leaf, + to: wp_other, + relation_type: Relation::TYPE_FOLLOWS) end it 'does not render the relation when hierarchy is collapsed' do diff --git a/spec/features/work_packages/timeline/timeline_labels_spec.rb b/spec/features/work_packages/timeline/timeline_labels_spec.rb index 6d4227e8fd..6ee6a07c40 100644 --- a/spec/features/work_packages/timeline/timeline_labels_spec.rb +++ b/spec/features/work_packages/timeline/timeline_labels_spec.rb @@ -57,27 +57,27 @@ RSpec.feature 'Work package timeline labels', end let(:today) { Date.today.iso8601 } - let(:tomorrow) { Date.tomorrow.iso8601 } - let(:future) { (Date.today + 5).iso8601 } + let(:tomorrow) { Date.tomorrow.iso8601 } + let(:future) { (Date.today + 5).iso8601 } let(:work_package) do FactoryBot.create :work_package, - project: project, - type: type, - assigned_to: user, - start_date: today, - due_date: tomorrow, - subject: 'My subject', - custom_field_values: { custom_field.id => custom_value_for('onions') } + project: project, + type: type, + assigned_to: user, + start_date: today, + due_date: tomorrow, + subject: 'My subject', + custom_field_values: { custom_field.id => custom_value_for('onions') } end let(:milestone_work_package) do FactoryBot.create :work_package, - project: project, - type: milestone_type, - start_date: future, - due_date: future, - subject: 'My milestone' + project: project, + type: milestone_type, + start_date: future, + due_date: future, + subject: 'My milestone' end before do @@ -177,6 +177,5 @@ RSpec.feature 'Work package timeline labels', row.expect_labels left: nil, right: future, farRight: milestone_work_package.subject - end end diff --git a/spec/features/work_packages/timeline/timeline_navigation_spec.rb b/spec/features/work_packages/timeline/timeline_navigation_spec.rb index e62c8932b6..b14c61fb3b 100644 --- a/spec/features/work_packages/timeline/timeline_navigation_spec.rb +++ b/spec/features/work_packages/timeline/timeline_navigation_spec.rb @@ -120,7 +120,6 @@ RSpec.feature 'Work package timeline navigation', js: true, selenium: true do wp_timeline.expect_work_package_listed work_package2 wp_timeline.ensure_work_package_not_listed! work_package - retry_block do find(".wp-row-#{work_package2.id}-timeline").right_click find('.menu-item', text: 'Add predecessor') diff --git a/spec/features/work_packages/work_package_workflow_form_spec.rb b/spec/features/work_packages/work_package_workflow_form_spec.rb index 36951674ed..bc05a4ce57 100644 --- a/spec/features/work_packages/work_package_workflow_form_spec.rb +++ b/spec/features/work_packages/work_package_workflow_form_spec.rb @@ -34,50 +34,50 @@ require 'features/page_objects/notification' describe 'Work package transitive status workflows', js: true do let(:dev_role) do FactoryBot.create :role, - permissions: [:view_work_packages, - :edit_work_packages] + permissions: %i[view_work_packages + edit_work_packages] end let(:dev) do FactoryBot.create :user, - firstname: 'Dev', - lastname: 'Guy', - member_in_project: project, - member_through_role: dev_role + firstname: 'Dev', + lastname: 'Guy', + member_in_project: project, + member_through_role: dev_role end let(:type) { FactoryBot.create :type } let(:project) { FactoryBot.create(:project, types: [type]) } - let(:work_package) { + let(:work_package) do work_package = FactoryBot.create :work_package, - project: project, - type: type, - created_at: 5.days.ago.to_date.to_s(:db) + project: project, + type: type, + created_at: 5.days.ago.to_date.to_s(:db) note_journal = work_package.journals.last note_journal.update(created_at: 5.days.ago.to_date.to_s) work_package - } + end let(:wp_page) { Pages::FullWorkPackage.new(work_package) } let(:status_from) { work_package.status } let(:status_intermediate) { FactoryBot.create :status } let(:status_to) { FactoryBot.create :status } - let(:workflows) { + let(:workflows) do FactoryBot.create :workflow, - type_id: type.id, - old_status: status_from, - new_status: status_intermediate, - role: dev_role + type_id: type.id, + old_status: status_from, + new_status: status_intermediate, + role: dev_role FactoryBot.create :workflow, - type_id: type.id, - old_status: status_intermediate, - new_status: status_to, - role: dev_role - } + type_id: type.id, + old_status: status_intermediate, + new_status: status_to, + role: dev_role + end before do login_as(dev) diff --git a/spec/features/work_packages/zen_mode_spec.rb b/spec/features/work_packages/zen_mode_spec.rb index 9d573dabd6..156c8d583c 100644 --- a/spec/features/work_packages/zen_mode_spec.rb +++ b/spec/features/work_packages/zen_mode_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' describe 'Zen mode', js: true do let(:dev_role) do FactoryBot.create :role, - permissions: [:view_work_packages, - :edit_work_packages] + permissions: %i[view_work_packages + edit_work_packages] end let(:dev) do FactoryBot.create :user, diff --git a/spec/features/workflows/copy_spec.rb b/spec/features/workflows/copy_spec.rb index 6e1748f726..bc06fec7b3 100644 --- a/spec/features/workflows/copy_spec.rb +++ b/spec/features/workflows/copy_spec.rb @@ -33,14 +33,14 @@ describe 'Workflow copy', type: :feature do let(:type) { FactoryBot.create(:type) } let(:admin) { FactoryBot.create(:admin) } let(:statuses) { (1..2).map { |_i| FactoryBot.create(:status) } } - let(:workflow) { + let(:workflow) do FactoryBot.create(:workflow, role_id: role.id, - type_id: type.id, - old_status_id: statuses[0].id, - new_status_id: statuses[1].id, - author: false, - assignee: false) - } + type_id: type.id, + old_status_id: statuses[0].id, + new_status_id: statuses[1].id, + author: false, + assignee: false) + end before do allow(User).to receive(:current).and_return(admin) diff --git a/spec/features/wysiwyg/custom_css_classes_spec.rb b/spec/features/wysiwyg/custom_css_classes_spec.rb index 1d26946d4d..ba58d4fcea 100644 --- a/spec/features/wysiwyg/custom_css_classes_spec.rb +++ b/spec/features/wysiwyg/custom_css_classes_spec.rb @@ -34,7 +34,7 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)', let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) } let(:editor) { ::Components::WysiwygEditor.new } - let(:wiki_page) { + let(:wiki_page) do page = FactoryBot.build :wiki_page_with_content page.content.text = <<~MARKDOWN paragraph @@ -100,7 +100,7 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)', MARKDOWN page - } + end before do login_as(user) @@ -111,7 +111,7 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)', end it 'custom classes are placed correctly' do - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| expect(editable).to have_css('p.op-uc-p', count: 5) expect(editable).to have_css('h1.op-uc-h1', count: 1) expect(editable).to have_css('h2.op-uc-h2', count: 1) diff --git a/spec/features/wysiwyg/linking_spec.rb b/spec/features/wysiwyg/linking_spec.rb index fb83f35ad3..53664f1b2b 100644 --- a/spec/features/wysiwyg/linking_spec.rb +++ b/spec/features/wysiwyg/linking_spec.rb @@ -56,7 +56,7 @@ describe 'Wysiwyg linking', expect(wiki_page.content.text).to eq( "[http://example.org/link with spaces](http://example.org/link%20with%20spaces)" - ) + ) expect(page).to have_selector('a[href="http://example.org/link%20with%20spaces"]') end diff --git a/spec/features/wysiwyg/macros/attribute_macros_spec.rb b/spec/features/wysiwyg/macros/attribute_macros_spec.rb index 0222e6b51a..06b8ac526f 100644 --- a/spec/features/wysiwyg/macros/attribute_macros_spec.rb +++ b/spec/features/wysiwyg/macros/attribute_macros_spec.rb @@ -35,7 +35,7 @@ describe 'Wysiwyg attribute macros', type: :feature, js: true do let!(:work_package) { FactoryBot.create(:work_package, subject: "Foo Bar", project: project) } let(:editor) { ::Components::WysiwygEditor.new } - let(:markdown) { + let(:markdown) do <<~MD # My headline @@ -62,7 +62,7 @@ describe 'Wysiwyg attribute macros', type: :feature, js: true do MD - } + end before do login_as(user) diff --git a/spec/features/wysiwyg/macros/child_pages_spec.rb b/spec/features/wysiwyg/macros/child_pages_spec.rb index 0dfd5a52ce..bcd14a5c67 100644 --- a/spec/features/wysiwyg/macros/child_pages_spec.rb +++ b/spec/features/wysiwyg/macros/child_pages_spec.rb @@ -32,33 +32,32 @@ require 'spec_helper' describe 'Wysiwyg child pages spec', type: :feature, js: true do - - let(:project) { + let(:project) do FactoryBot.create :project, enabled_module_names: %w[wiki] - } + end let(:role) { FactoryBot.create(:role, permissions: %i[view_wiki_pages edit_wiki_pages]) } - let(:user) { + let(:user) do FactoryBot.create(:user, member_in_project: project, member_through_role: role) - } + end - let(:wiki_page) { + let(:wiki_page) do FactoryBot.create :wiki_page, title: 'Test', content: FactoryBot.build(:wiki_content, text: '# My page') - } + end - let(:parent_page) { + let(:parent_page) do FactoryBot.create :wiki_page, title: 'Parent page', content: FactoryBot.build(:wiki_content, text: '# parent page') - } + end - let(:child_page) { + let(:child_page) do FactoryBot.create :wiki_page, title: 'Child page', content: FactoryBot.build(:wiki_content, text: '# child page') - } + end before do login_as(user) @@ -71,7 +70,6 @@ describe 'Wysiwyg child pages spec', project.wiki.save! end - let(:editor) { ::Components::WysiwygEditor.new } before do diff --git a/spec/features/wysiwyg/macros/code_block_macro_spec.rb b/spec/features/wysiwyg/macros/code_block_macro_spec.rb index 0fe7bfe788..8754c734c1 100644 --- a/spec/features/wysiwyg/macros/code_block_macro_spec.rb +++ b/spec/features/wysiwyg/macros/code_block_macro_spec.rb @@ -36,21 +36,21 @@ describe 'Wysiwyg code block macro', let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) } let(:editor) { ::Components::WysiwygEditor.new } - let(:snippet) { + let(:snippet) do <<~RUBY def foobar 'some ruby code' end RUBY - } + end - let(:expected) { + let(:expected) do <<~EXPECTED ```ruby #{snippet.strip} ``` EXPECTED - } + end before do login_as(user) diff --git a/spec/features/wysiwyg/macros/embedded_tables_spec.rb b/spec/features/wysiwyg/macros/embedded_tables_spec.rb index fa2238c17f..4d8b53de8c 100644 --- a/spec/features/wysiwyg/macros/embedded_tables_spec.rb +++ b/spec/features/wysiwyg/macros/embedded_tables_spec.rb @@ -34,7 +34,9 @@ describe 'Wysiwyg embedded work package tables', let(:user) { admin } let(:type_task) { FactoryBot.create :type_task } let(:type_bug) { FactoryBot.create :type_bug } - let(:project) { FactoryBot.create(:project, types: [type_task, type_bug], enabled_module_names: %w[wiki work_package_tracking]) } + let(:project) do + FactoryBot.create(:project, types: [type_task, type_bug], enabled_module_names: %w[wiki work_package_tracking]) + end let(:editor) { ::Components::WysiwygEditor.new } let!(:wp_task) { FactoryBot.create(:work_package, project: project, type: type_task) } let!(:wp_bug) { FactoryBot.create(:work_package, project: project, type: type_bug) } diff --git a/spec/features/wysiwyg/macros/quicklink_macros_spec.rb b/spec/features/wysiwyg/macros/quicklink_macros_spec.rb index 7cdab5385c..98cfae8e57 100644 --- a/spec/features/wysiwyg/macros/quicklink_macros_spec.rb +++ b/spec/features/wysiwyg/macros/quicklink_macros_spec.rb @@ -32,12 +32,12 @@ describe 'Wysiwyg work package quicklink macros', type: :feature, js: true do shared_let(:admin) { FactoryBot.create :admin } let(:user) { admin } let!(:project) { FactoryBot.create(:project, identifier: 'some-project', enabled_module_names: %w[wiki work_package_tracking]) } - let!(:work_package) { + let!(:work_package) do FactoryBot.create(:work_package, subject: "Foo Bar", project: project, start_date: '2020-01-01', due_date: '2020-02-01') - } + end let(:editor) { ::Components::WysiwygEditor.new } - let(:markdown) { + let(:markdown) do <<~MD # My headline @@ -45,7 +45,7 @@ describe 'Wysiwyg work package quicklink macros', type: :feature, js: true do ####{work_package.id} MD - } + end before do login_as(user) @@ -77,7 +77,7 @@ describe 'Wysiwyg work package quicklink macros', type: :feature, js: true do # Dates are being rendered in two nested spans expect(page).to have_selector('span', text: '01/01/2020', count: 2) expect(page).to have_selector('span', text: '02/01/2020', count: 2) - expect(page).to have_selector('.work-package--quickinfo.preview-trigger', text: "##{work_package.id}", count: 2) + expect(page).to have_selector('.work-package--quickinfo.preview-trigger', text: "##{work_package.id}", count: 2) end # Edit page again diff --git a/spec/features/wysiwyg/macros/work_package_button_spec.rb b/spec/features/wysiwyg/macros/work_package_button_spec.rb index 86a2bf2e2f..7ec30c4c42 100644 --- a/spec/features/wysiwyg/macros/work_package_button_spec.rb +++ b/spec/features/wysiwyg/macros/work_package_button_spec.rb @@ -55,7 +55,7 @@ describe 'Wysiwyg work package button spec', end it 'can add and edit an embedded table widget' do - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| editor.insert_macro 'Insert create work package button' expect(page).to have_selector('.op-modal--macro-modal') diff --git a/spec/features/wysiwyg/non_breaking_spaces_spec.rb b/spec/features/wysiwyg/non_breaking_spaces_spec.rb index 64ab2fc91d..f6902862fa 100644 --- a/spec/features/wysiwyg/non_breaking_spaces_spec.rb +++ b/spec/features/wysiwyg/non_breaking_spaces_spec.rb @@ -31,7 +31,7 @@ require 'spec_helper' describe 'Wysiwyg   behavior', type: :feature, js: true do shared_let(:admin) { FactoryBot.create :admin } - let(:user) { admin} + let(:user) { admin } let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) } let(:editor) { ::Components::WysiwygEditor.new } diff --git a/spec/features/wysiwyg/paragraphs_in_lists_spec.rb b/spec/features/wysiwyg/paragraphs_in_lists_spec.rb index 9a245ac10e..b1e58baf3d 100644 --- a/spec/features/wysiwyg/paragraphs_in_lists_spec.rb +++ b/spec/features/wysiwyg/paragraphs_in_lists_spec.rb @@ -34,7 +34,7 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)', let(:project) { FactoryBot.create(:project, enabled_module_names: %w[wiki]) } let(:editor) { ::Components::WysiwygEditor.new } - let(:wiki_page) { + let(:wiki_page) do page = FactoryBot.build :wiki_page_with_content page.content.text = <<~MARKDOWN 1. Step 1 @@ -48,7 +48,7 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)', MARKDOWN page - } + end before do login_as(user) @@ -59,7 +59,7 @@ describe 'Wysiwyg paragraphs in lists behavior (Regression #28765)', end it 'shows the list correctly' do - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| expect(editable).to have_selector('ol li', count: 3) expect(editable).to have_no_selector('ol li p') end diff --git a/spec/features/wysiwyg/tables_spec.rb b/spec/features/wysiwyg/tables_spec.rb index 6c9b498936..2a29cb30cf 100644 --- a/spec/features/wysiwyg/tables_spec.rb +++ b/spec/features/wysiwyg/tables_spec.rb @@ -130,7 +130,7 @@ describe 'Wysiwyg tables', # Edit again click_on 'Edit' - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| # Table should still have header expect(editable).to have_selector('th', count: 2) expect(editable).to have_selector('td', count: 2) @@ -194,7 +194,7 @@ describe 'Wysiwyg tables', # Edit again click_on 'Edit' - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| expect(editable).to have_selector('td[style*="background-color:#123456"]') # Change table styles @@ -250,7 +250,7 @@ describe 'Wysiwyg tables', click_on 'Edit' # Expect all previous changes to be there - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| expect(editable).to have_selector('td[style*="background-color:#123456"]') # table height and width is set on figure @@ -295,7 +295,6 @@ describe 'Wysiwyg tables', find('.ck-button-save').click expect(editable).to have_selector('td[style*="width:250px"]') - end # Save wiki page @@ -311,14 +310,14 @@ describe 'Wysiwyg tables', # Edit again click_on 'Edit' - editor.in_editor do |container, editable| + editor.in_editor do |_container, editable| expect(editable).to have_selector('td[style*="width:250px"]') end end end describe 'editing a wiki page with tables' do - let(:wiki_page) { + let(:wiki_page) do page = FactoryBot.build :wiki_page_with_content, title: 'Wiki page with titles' page.content.text = <<~MARKDOWN @@ -346,7 +345,7 @@ describe 'Wysiwyg tables', MARKDOWN page - } + end before do project.wiki.pages << wiki_page diff --git a/spec/features/wysiwyg/work_package_linking_spec.rb b/spec/features/wysiwyg/work_package_linking_spec.rb index 440f0dde9f..14f50469ea 100644 --- a/spec/features/wysiwyg/work_package_linking_spec.rb +++ b/spec/features/wysiwyg/work_package_linking_spec.rb @@ -45,7 +45,6 @@ describe 'Wysiwyg work package linking', end it 'can reference work packages' do - # single hash autocomplete editor.click_and_type_slowly "##{work_package.id}" editor.click_autocomplete work_package.subject diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 5b4ed9f2f2..926112f2c3 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -57,7 +57,9 @@ describe ApplicationHelper, type: :helper do OpenProject::Footer.content = nil end - it { expect(footer_content).to eq(I18n.t(:text_powered_by, link: link_to(OpenProject::Info.app_name, OpenProject::Info.url))) } + it { + expect(footer_content).to eq(I18n.t(:text_powered_by, link: link_to(OpenProject::Info.app_name, OpenProject::Info.url))) + } end context 'string as additional footer content' do @@ -66,8 +68,11 @@ describe ApplicationHelper, type: :helper do OpenProject::Footer.add_content('openproject', 'footer') end - it { expect(footer_content.include?(I18n.t(:text_powered_by, link: link_to(OpenProject::Info.app_name, OpenProject::Info.url)))).to be_truthy } - it { expect(footer_content.include?("footer")).to be_truthy } + it { + expect(footer_content.include?(I18n.t(:text_powered_by, + link: link_to(OpenProject::Info.app_name, OpenProject::Info.url)))).to be_truthy + } + it { expect(footer_content.include?("footer")).to be_truthy } end context 'proc as additional footer content' do @@ -76,7 +81,9 @@ describe ApplicationHelper, type: :helper do OpenProject::Footer.add_content('openproject', Proc.new { Date.parse(Time.now.to_s) }) end - it { expect(footer_content.include?("#{Date.parse(Time.now.to_s)}")).to be_truthy } + it { + expect(footer_content.include?("#{Date.parse(Time.now.to_s)}")).to be_truthy + } end context 'proc which returns nothing' do @@ -91,19 +98,19 @@ describe ApplicationHelper, type: :helper do describe '.link_to_if_authorized' do let(:project) { FactoryBot.create :valid_project } - let(:project_member) { + let(:project_member) do FactoryBot.create :user, - member_in_project: project, - member_through_role: FactoryBot.create(:role, - permissions: [:view_work_packages, :edit_work_packages, - :browse_repository, :view_changesets, :view_wiki_pages]) - } - let(:issue) { + member_in_project: project, + member_through_role: FactoryBot.create(:role, + permissions: %i[view_work_packages edit_work_packages + browse_repository view_changesets view_wiki_pages]) + end + let(:issue) do FactoryBot.create :work_package, - project: project, - author: project_member, - type: project.types.first - } + project: project, + author: project_member, + type: project.types.first + end context 'if user is authorized' do before do @@ -111,7 +118,8 @@ describe ApplicationHelper, type: :helper do @response = link_to_if_authorized('link_content', { controller: 'work_packages', action: 'show', - id: issue }, + id: issue + }, class: 'fancy_css_class') end @@ -128,7 +136,8 @@ describe ApplicationHelper, type: :helper do @response = link_to_if_authorized('link_content', { controller: 'work_packages', action: 'show', - id: issue }, + id: issue + }, class: 'fancy_css_class') end @@ -157,7 +166,9 @@ describe ApplicationHelper, type: :helper do before do @links = other_formats_links { |f| f.link_to 'Atom', url: { controller: :projects, action: :index } } end - it { expect(@links).to be_html_eql("

Also available in:Atom

") } + it { + expect(@links).to be_html_eql("

Also available in:Atom

") + } end context 'link given but disabled' do @@ -184,19 +195,19 @@ describe ApplicationHelper, type: :helper do context 'right now' do let(:time) { Time.now } - it { is_expected.to match /^\token and another token.' } + let(:expected_title) do + 'This is a token and another token.' + end it { is_expected.to eq expected_title } end @@ -78,7 +80,9 @@ describe 'search/index', type: :helper do context 'with multibyte title' do let(:tokens) { %w(token) } let(:title) { ('й' * 200) + ' token ' + ('й' * 200) } - let(:expected_title) { ('й' * 45) + ' ... ' + ('й' * 44) + ' token ' + ('й' * 44) + ' ... ' + ('й' * 45) } + let(:expected_title) do + ('й' * 45) + ' ... ' + ('й' * 44) + ' token ' + ('й' * 44) + ' ... ' + ('й' * 45) + end it { is_expected.to eq expected_title } end diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index 9522c91a4a..390a32eda9 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,9 +41,9 @@ describe SettingsHelper, type: :helper do expect(Setting).to receive(:field).and_return('2') end - subject(:output) { + subject(:output) do helper.setting_select :field, [['Popsickle', '1'], ['Jello', '2'], ['Ice Cream', '3']], options - } + end it_behaves_like 'labelled by default' it_behaves_like 'wrapped in field-container by default' @@ -59,9 +60,9 @@ describe SettingsHelper, type: :helper do expect(Setting).to receive(:field).at_least(:once).and_return('1') end - subject(:output) { + subject(:output) do helper.setting_multiselect :field, [['Popsickle', '1'], ['Jello', '2'], ['Ice Cream', '3']], options - } + end it_behaves_like 'wrapped in container' do let(:container_count) { 3 } @@ -86,8 +87,8 @@ describe SettingsHelper, type: :helper do expect(Setting).to receive(:field_b).at_least(:once).and_return('3') end - subject(:output) { - settings = [:field_a, :field_b] + subject(:output) do + settings = %i[field_a field_b] choices = [ { caption: 'Popsickle', @@ -106,7 +107,7 @@ describe SettingsHelper, type: :helper do } ] helper.settings_matrix settings, choices - } + end it_behaves_like 'not wrapped in container' @@ -159,9 +160,9 @@ describe SettingsHelper, type: :helper do expect(Setting).to receive(:field).and_return('important value') end - subject(:output) { + subject(:output) do helper.setting_text_field :field, options - } + end it_behaves_like 'labelled by default' it_behaves_like 'wrapped in field-container by default' @@ -180,9 +181,9 @@ describe SettingsHelper, type: :helper do expect(Setting).to receive(:field).and_return('important text') end - subject(:output) { + subject(:output) do helper.setting_text_area :field, options - } + end it_behaves_like 'labelled by default' it_behaves_like 'wrapped in field-container by default' @@ -197,9 +198,9 @@ important text end describe '#setting_check_box' do - subject(:output) { + subject(:output) do helper.setting_check_box :field, options - } + end context 'when setting is true' do before do @@ -233,9 +234,9 @@ important text end describe '#setting_label' do - subject(:output) { + subject(:output) do helper.setting_label :field - } + end it_behaves_like 'labelled' it_behaves_like 'not wrapped in container' @@ -246,9 +247,9 @@ important text expect(Setting).to receive(:notified_events).and_return(%w(interesting_stuff)) end - subject(:output) { + subject(:output) do helper.notification_field(notifiable, options) - } + end context 'when setting includes option' do let(:notifiable) { OpenStruct.new(name: 'interesting_stuff') } diff --git a/spec/helpers/sort_helper_spec.rb b/spec/helpers/sort_helper_spec.rb index 0ed0881169..fd57324b8c 100644 --- a/spec/helpers/sort_helper_spec.rb +++ b/spec/helpers/sort_helper_spec.rb @@ -30,16 +30,16 @@ require 'spec_helper' describe SortHelper, type: :helper do describe '#sort_header_tag' do - let(:output) { + let(:output) do helper.sort_header_tag('id') - } + end let(:sort_key) { '' } let(:sort_asc) { true } - let(:sort_criteria) { + let(:sort_criteria) do double('sort_criteria', first_key: sort_key, first_asc?: sort_asc, to_param: 'sort_criteria_params').as_null_object - } + end before do # helper relies on this instance var diff --git a/spec/helpers/tabs_helper_spec.rb b/spec/helpers/tabs_helper_spec.rb index c518d58c8b..ccf1b14255 100644 --- a/spec/helpers/tabs_helper_spec.rb +++ b/spec/helpers/tabs_helper_spec.rb @@ -31,31 +31,31 @@ require 'spec_helper' describe TabsHelper, type: :helper do include TabsHelper - let(:given_tab) { + let(:given_tab) do { name: 'avatar', partial: 'avatars/users/avatar_tab', path: ->(params) { tab_edit_user_path(params[:user], tab: :avatar) }, label: :label_avatar } - } + end - let(:expected_tab) { + let(:expected_tab) do { name: 'avatar', partial: 'avatars/users/avatar_tab', path: '/users/2/edit/avatar', label: :label_avatar } - } + end describe 'render_extensible_tabs' do before do allow_any_instance_of(TabsHelper) .to receive(:render_tabs) - .with([ expected_tab ]) - .and_return [ expected_tab ] + .with([expected_tab]) + .and_return [expected_tab] allow(::OpenProject::Ui::ExtensibleTabs) .to receive(:enabled_tabs) .with(:user) - .and_return [ given_tab ] + .and_return [given_tab] user = FactoryBot.build(:user, id: 2) @tabs = render_extensible_tabs(:user, user: user) @@ -63,7 +63,7 @@ describe TabsHelper, type: :helper do it "should return an evaluated path" do expect(response.status).to eq 200 - expect(@tabs).to eq([ expected_tab ]) + expect(@tabs).to eq([expected_tab]) end end end diff --git a/spec/helpers/text_formatting_helper_spec.rb b/spec/helpers/text_formatting_helper_spec.rb index 004824f237..7bb26c100f 100644 --- a/spec/helpers/text_formatting_helper_spec.rb +++ b/spec/helpers/text_formatting_helper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/helpers/toolbar_helper_spec.rb b/spec/helpers/toolbar_helper_spec.rb index 428d743add..d4480ee08b 100644 --- a/spec/helpers/toolbar_helper_spec.rb +++ b/spec/helpers/toolbar_helper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/helpers/versions_helper_spec.rb b/spec/helpers/versions_helper_spec.rb index 4e14bf65a6..e377ac9137 100644 --- a/spec/helpers/versions_helper_spec.rb +++ b/spec/helpers/versions_helper_spec.rb @@ -98,7 +98,8 @@ describe VersionsHelper, type: :helper do end it 'generates an option tag' do - expect(version_options_for_select([], version)).to eq("") + expect(version_options_for_select([], + version)).to eq("") end end end diff --git a/spec/helpers/work_packages_helper_spec.rb b/spec/helpers/work_packages_helper_spec.rb index 418324326a..e495ab7801 100644 --- a/spec/helpers/work_packages_helper_spec.rb +++ b/spec/helpers/work_packages_helper_spec.rb @@ -45,14 +45,18 @@ describe WorkPackagesHelper, type: :helper do describe 'without parameters' do it 'should return a link to the work package with the id as the text' do link_text = Regexp.new("^##{stub_work_package.id}$") - expect(helper.link_to_work_package(stub_work_package)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package)).to have_selector( + "a[href='#{work_package_path(stub_work_package)}']", text: link_text + ) end it 'should return a link to the work package with type and id as the text if type is set' do stub_work_package.type = stub_type link_text = Regexp.new("^#{stub_type.name} ##{stub_work_package.id}$") - expect(helper.link_to_work_package(stub_work_package)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package)).to have_selector( + "a[href='#{work_package_path(stub_work_package)}']", text: link_text + ) end it 'should additionally return the subject' do @@ -72,7 +76,10 @@ describe WorkPackagesHelper, type: :helper do stub_work_package.type = stub_type link_text = Regexp.new("^#{stub_type} ##{stub_work_package.id}: #{stub_work_package.subject}$") - expect(helper.link_to_work_package(stub_work_package, all_link: true)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package, + all_link: true)).to have_selector( + "a[href='#{work_package_path(stub_work_package)}']", text: link_text + ) end end @@ -103,7 +110,9 @@ describe WorkPackagesHelper, type: :helper do stub_work_package.type = stub_type link_text = Regexp.new("^##{stub_work_package.id}$") - expect(helper.link_to_work_package(stub_work_package, type: false)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package, + type: false)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", + text: link_text) end end @@ -128,7 +137,9 @@ describe WorkPackagesHelper, type: :helper do stub_work_package.type = stub_type link_text = Regexp.new("^##{stub_work_package.id}$") - expect(helper.link_to_work_package(stub_work_package, id_only: true)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package, + id_only: true)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", + text: link_text) end it 'should not have the subject as text' do @@ -139,7 +150,10 @@ describe WorkPackagesHelper, type: :helper do describe 'when only wanting the subject' do it 'should return a link with the subject as text' do link_text = Regexp.new("^#{stub_work_package.subject}$") - expect(helper.link_to_work_package(stub_work_package, subject_only: true)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package, + subject_only: true)).to have_selector( + "a[href='#{work_package_path(stub_work_package)}']", text: link_text + ) end end @@ -148,7 +162,9 @@ describe WorkPackagesHelper, type: :helper do stub_work_package.type = stub_type link_text = Regexp.new("^#{stub_type.name} ##{stub_work_package.id} #{stub_work_package.status}$") - expect(helper.link_to_work_package(stub_work_package, status: true)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", text: link_text) + expect(helper.link_to_work_package(stub_work_package, + status: true)).to have_selector("a[href='#{work_package_path(stub_work_package)}']", + text: link_text) end end end @@ -157,11 +173,11 @@ describe WorkPackagesHelper, type: :helper do let(:statuses) { (1..5).map { |_i| FactoryBot.build_stubbed(:status) } } let(:priority) { FactoryBot.build_stubbed :priority, is_default: true } let(:status) { statuses[0] } - let(:stub_work_package) { + let(:stub_work_package) do FactoryBot.build_stubbed(:work_package, - status: status, - priority: priority) - } + status: status, + priority: priority) + end it 'should always have the work_package class' do expect(helper.work_package_css_classes(stub_work_package)).to include('work_package') diff --git a/spec/lib/acts_as_watchable/lib/acts_as_watchable/routes_spec.rb b/spec/lib/acts_as_watchable/lib/acts_as_watchable/routes_spec.rb index c317bd2be3..53bdbd33b4 100644 --- a/spec/lib/acts_as_watchable/lib/acts_as_watchable/routes_spec.rb +++ b/spec/lib/acts_as_watchable/lib/acts_as_watchable/routes_spec.rb @@ -29,13 +29,13 @@ require 'spec_helper' describe OpenProject::Acts::Watchable::Routes do - let(:request) { + let(:request) do Struct.new(:type, :id) do def path_parameters { object_id: id, object_type: type } end end.new(type, id) - } + end describe 'matches?' do shared_examples_for 'watched model' do diff --git a/spec/lib/api/decorators/link_object_spec.rb b/spec/lib/api/decorators/link_object_spec.rb index 73dc4d1b8b..bee8ef495b 100644 --- a/spec/lib/api/decorators/link_object_spec.rb +++ b/spec/lib/api/decorators/link_object_spec.rb @@ -50,11 +50,11 @@ describe ::API::Decorators::LinkObject do describe 'parsing' do subject { represented } - let(:parsed_hash) { + let(:parsed_hash) do { 'href' => '/api/v3/foos/42' } - } + end it 'parses the id from the URL' do representer.from_hash parsed_hash @@ -62,29 +62,30 @@ describe ::API::Decorators::LinkObject do end context 'wrong namespace' do - let(:parsed_hash) { + let(:parsed_hash) do { 'href' => '/api/v3/bars/42' } - } + end it 'throws an error' do expect { representer.from_hash parsed_hash }.to raise_error( - ::API::Errors::InvalidResourceLink) + ::API::Errors::InvalidResourceLink + ) end end end end context 'full constructor call' do - let(:representer) { + let(:representer) do described_class.new(represented, property_name: :foo, path: :foo_path, namespace: 'fuhs', getter: :getter, setter: :'setter=') - } + end before do represented.getter = 1 @@ -100,11 +101,11 @@ describe ::API::Decorators::LinkObject do describe 'parsing' do subject { represented } - let(:parsed_hash) { + let(:parsed_hash) do { 'href' => '/api/v3/fuhs/42' } - } + end it 'parses the id from the URL' do representer.from_hash parsed_hash @@ -112,15 +113,16 @@ describe ::API::Decorators::LinkObject do end context 'wrong namespace' do - let(:parsed_hash) { + let(:parsed_hash) do { 'href' => '/api/v3/foos/42' } - } + end it 'throws an error' do expect { representer.from_hash parsed_hash }.to raise_error( - ::API::Errors::InvalidResourceLink) + ::API::Errors::InvalidResourceLink + ) end end end diff --git a/spec/lib/api/utilities/page_size_helper.rb b/spec/lib/api/utilities/page_size_helper.rb index d3e81ed870..c97b00ed9d 100644 --- a/spec/lib/api/utilities/page_size_helper.rb +++ b/spec/lib/api/utilities/page_size_helper.rb @@ -39,7 +39,6 @@ describe ::API::Utilities::PageSizeHelper do describe '#maximum_page_size' do context 'when small values in per_page_options', with_settings: { per_page_options: '20,100' } do - it 'uses the magical number 500' do expect(subject.maximum_page_size).to eq(500) end @@ -47,7 +46,6 @@ describe ::API::Utilities::PageSizeHelper do context 'when larger values in per_page_options', with_settings: { per_page_options: '20,100,1000' } do - it 'uses that value' do expect(subject.maximum_page_size).to eq(1000) end diff --git a/spec/lib/api/utilities/resource_link_parser_spec.rb b/spec/lib/api/utilities/resource_link_parser_spec.rb index 7f6c1f3734..7680c7b565 100644 --- a/spec/lib/api/utilities/resource_link_parser_spec.rb +++ b/spec/lib/api/utilities/resource_link_parser_spec.rb @@ -111,46 +111,46 @@ describe ::API::Utilities::ResourceLinkParser do end it 'accepts on matching version' do - expect { + expect do subject.parse_id('/api/v3/statuses/14', property: 'foo', expected_version: '3') - }.not_to raise_error + end.not_to raise_error end it 'accepts on matching version as integer' do - expect { + expect do subject.parse_id('/api/v3/statuses/14', property: 'foo', expected_version: 3) - }.not_to raise_error + end.not_to raise_error end it 'accepts on matching namespace' do - expect { + expect do subject.parse_id('/api/v3/statuses/14', property: 'foo', expected_namespace: 'statuses') - }.not_to raise_error + end.not_to raise_error end it 'accepts on matching namespace as symbol' do - expect { + expect do subject.parse_id('/api/v3/statuses/14', property: 'foo', expected_namespace: :statuses) - }.not_to raise_error + end.not_to raise_error end it 'raises on version mismatch' do - expect { + expect do subject.parse_id('/api/v4/statuses/14', property: 'foo', expected_version: '3') - }.to raise_error(::API::Errors::InvalidResourceLink) + end.to raise_error(::API::Errors::InvalidResourceLink) end it 'raises on namespace mismatch' do - expect { + expect do subject.parse_id('/api/v3/types/14', property: 'foo', expected_namespace: 'statuses') - }.to raise_error(::API::Errors::InvalidResourceLink) + end.to raise_error(::API::Errors::InvalidResourceLink) end it 'contains the property name in exception messages' do property_name = 'My Property Name' - expect { + expect do subject.parse_id('/api/v4/statuses/14', property: property_name, expected_version: '3') - }.to raise_error(Regexp.compile(property_name)) + end.to raise_error(Regexp.compile(property_name)) end end end diff --git a/spec/lib/api/v3/attachments/attachment_metadata_representer_spec.rb b/spec/lib/api/v3/attachments/attachment_metadata_representer_spec.rb index 1f8ea1ac4d..1ea8f18f73 100644 --- a/spec/lib/api/v3/attachments/attachment_metadata_representer_spec.rb +++ b/spec/lib/api/v3/attachments/attachment_metadata_representer_spec.rb @@ -68,7 +68,7 @@ describe ::API::V3::Attachments::AttachmentMetadataRepresenter do end describe 'parsing' do - let(:parsed_hash) { + let(:parsed_hash) do { 'fileName' => 'the parsed name', 'description' => { 'raw' => 'the parsed description' }, @@ -76,7 +76,7 @@ describe ::API::V3::Attachments::AttachmentMetadataRepresenter do 'fileSize' => 43, 'digest' => '0x00' } - } + end subject { metadata } diff --git a/spec/lib/api/v3/categories/category_collection_representer_spec.rb b/spec/lib/api/v3/categories/category_collection_representer_spec.rb index 530e2e2167..9bf18db55e 100644 --- a/spec/lib/api/v3/categories/category_collection_representer_spec.rb +++ b/spec/lib/api/v3/categories/category_collection_representer_spec.rb @@ -30,11 +30,11 @@ require 'spec_helper' describe ::API::V3::Categories::CategoryCollectionRepresenter do let(:categories) { FactoryBot.build_list(:category, 3) } - let(:representer) { + let(:representer) do described_class.new(categories, self_link: '/api/v3/projects/1/categories', current_user: double('current_user')) - } + end context 'generation' do subject(:collection) { representer.to_json } diff --git a/spec/lib/api/v3/categories/category_representer_spec.rb b/spec/lib/api/v3/categories/category_representer_spec.rb index cf212c14c2..3cfe6f8024 100644 --- a/spec/lib/api/v3/categories/category_representer_spec.rb +++ b/spec/lib/api/v3/categories/category_representer_spec.rb @@ -66,9 +66,9 @@ describe ::API::V3::Categories::CategoryRepresenter do end context 'default assignee set' do - let(:category) { + let(:category) do FactoryBot.build_stubbed(:category, assigned_to: user) - } + end it_behaves_like 'category has core values' it 'should link to its default assignee' do diff --git a/spec/lib/api/v3/posts/post_representer_rendering_spec.rb b/spec/lib/api/v3/posts/post_representer_rendering_spec.rb index 8f176c7153..a34ada8a44 100644 --- a/spec/lib/api/v3/posts/post_representer_rendering_spec.rb +++ b/spec/lib/api/v3/posts/post_representer_rendering_spec.rb @@ -50,7 +50,7 @@ describe ::API::V3::Posts::PostRepresenter, 'rendering' do before do allow(user) - .to receive(:allowed_to?) do |permission, project| + .to receive(:allowed_to?) do |permission, _project| permissions.include?(permission) end end diff --git a/spec/lib/api/v3/priorities/priority_collection_representer_spec.rb b/spec/lib/api/v3/priorities/priority_collection_representer_spec.rb index e168b52d39..e130b5e235 100644 --- a/spec/lib/api/v3/priorities/priority_collection_representer_spec.rb +++ b/spec/lib/api/v3/priorities/priority_collection_representer_spec.rb @@ -30,9 +30,9 @@ require 'spec_helper' describe ::API::V3::Priorities::PriorityCollectionRepresenter do let(:priorities) { FactoryBot.build_list(:priority, 3) } - let(:representer) { + let(:representer) do described_class.new(priorities, self_link: '/api/v3/priorities', current_user: double('current_user')) - } + end context 'generation' do subject(:collection) { representer.to_json } diff --git a/spec/lib/api/v3/projects/project_collection_representer_spec.rb b/spec/lib/api/v3/projects/project_collection_representer_spec.rb index 720e41418e..0d54b0e2c7 100644 --- a/spec/lib/api/v3/projects/project_collection_representer_spec.rb +++ b/spec/lib/api/v3/projects/project_collection_representer_spec.rb @@ -32,9 +32,9 @@ describe ::API::V3::Projects::ProjectCollectionRepresenter do let(:self_link) { '/api/v3/versions/1/projects' } let(:projects) { FactoryBot.build_list(:project, 3) } let(:current_user) { FactoryBot.build(:user) } - let(:representer) { + let(:representer) do described_class.new(projects, self_link: self_link, current_user: current_user) - } + end context 'generation' do subject(:collection) { representer.to_json } diff --git a/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb b/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb index 8eb7969165..2d6dc4e585 100644 --- a/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb +++ b/spec/lib/api/v3/queries/filters/query_filter_instance_representer_spec.rb @@ -150,7 +150,6 @@ describe ::API::V3::Queries::Filters::QueryFilterInstanceRepresenter do subproject project.reload - f = Queries::WorkPackages::Filter::SubprojectFilter.create!(context: project) f.operator = '=' f.values = [subproject.id] diff --git a/spec/lib/api/v3/queries/query_representer_generation_spec.rb b/spec/lib/api/v3/queries/query_representer_generation_spec.rb index 98c1c5a922..5882ee6ecd 100644 --- a/spec/lib/api/v3/queries/query_representer_generation_spec.rb +++ b/spec/lib/api/v3/queries/query_representer_generation_spec.rb @@ -90,7 +90,8 @@ describe ::API::V3::Queries::QueryRepresenter do context 'with params' do let(:representer) do - described_class.new(query, current_user: user, embed_links: embed_links, params: { "filters" => "something", "id" => "234" }) + described_class.new(query, current_user: user, embed_links: embed_links, + params: { "filters" => "something", "id" => "234" }) end it_behaves_like 'has a titled link' do @@ -462,7 +463,7 @@ describe ::API::V3::Queries::QueryRepresenter do context 'with sort_by' do let(:query) do FactoryBot.build_stubbed(:query, - sort_criteria: [['subject', 'asc'], ['assigned_to', 'desc']]) + sort_criteria: [['subject', 'asc'], ['assigned_to', 'desc']]) end it 'has an array of sortBy' do @@ -764,7 +765,7 @@ describe ::API::V3::Queries::QueryRepresenter do describe 'with sort criteria' do let(:query) do FactoryBot.build_stubbed(:query, - sort_criteria: [['subject', 'asc'], ['assigned_to', 'desc']]) + sort_criteria: [['subject', 'asc'], ['assigned_to', 'desc']]) end it 'has the sort criteria embedded' do diff --git a/spec/lib/api/v3/queries/schemas/project_filter_dependency_representer_spec.rb b/spec/lib/api/v3/queries/schemas/project_filter_dependency_representer_spec.rb index 1f5a1b8a7c..960a9c27be 100644 --- a/spec/lib/api/v3/queries/schemas/project_filter_dependency_representer_spec.rb +++ b/spec/lib/api/v3/queries/schemas/project_filter_dependency_representer_spec.rb @@ -48,7 +48,7 @@ describe ::API::V3::Queries::Schemas::ProjectFilterDependencyRepresenter, clear_ let(:path) { 'values' } let(:type) { '[]Project' } let(:filters) { "?filters=%5B%7B%22active%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%22t%22%5D%7D%7D%5D" } - let(:href) { api_v3_paths.projects + filters} + let(:href) { api_v3_paths.projects + filters } context "for operator 'Queries::Operators::Equals'" do let(:operator) { Queries::Operators::Equals } diff --git a/spec/lib/api/v3/relations/relation_collection_representer_spec.rb b/spec/lib/api/v3/relations/relation_collection_representer_spec.rb index cc5bd5abf3..1e5c5143e7 100644 --- a/spec/lib/api/v3/relations/relation_collection_representer_spec.rb +++ b/spec/lib/api/v3/relations/relation_collection_representer_spec.rb @@ -36,8 +36,8 @@ describe ::API::V3::Relations::RelationCollectionRepresenter do let(:relations) do (1..3).map do FactoryBot.build_stubbed(:relation, - from: work_package, - to: FactoryBot.build_stubbed(:work_package)) + from: work_package, + to: FactoryBot.build_stubbed(:work_package)) end end diff --git a/spec/lib/api/v3/repositories/revision_representer_spec.rb b/spec/lib/api/v3/repositories/revision_representer_spec.rb index a19e0ab578..3928d98b33 100644 --- a/spec/lib/api/v3/repositories/revision_representer_spec.rb +++ b/spec/lib/api/v3/repositories/revision_representer_spec.rb @@ -35,16 +35,15 @@ describe ::API::V3::Repositories::RevisionRepresenter do let(:project) { FactoryBot.build :project } let(:repository) { FactoryBot.build :repository_subversion, project: project } - let(:revision) { + let(:revision) do FactoryBot.build(:changeset, - id: 42, - revision: '1234', - repository: repository, - comments: commit_message, - committer: 'foo bar ', - committed_on: DateTime.now, - ) - } + id: 42, + revision: '1234', + repository: repository, + comments: commit_message, + committer: 'foo bar ', + committed_on: DateTime.now) + end let(:commit_message) { 'Some commit message' } @@ -91,14 +90,14 @@ describe ::API::V3::Repositories::RevisionRepresenter do context 'with referencing commit message' do let(:work_package) { FactoryBot.build_stubbed(:work_package, project: project) } let(:commit_message) { "Totally references ##{work_package.id}" } - let(:html_reference) { + let(:html_reference) do id = work_package.id str = 'Totally references " str << "##{id}" - } + end before do allow(User).to receive(:current).and_return(FactoryBot.build_stubbed(:admin)) diff --git a/spec/lib/api/v3/statuses/status_collection_representer_spec.rb b/spec/lib/api/v3/statuses/status_collection_representer_spec.rb index 12b8314533..4b62a48ab1 100644 --- a/spec/lib/api/v3/statuses/status_collection_representer_spec.rb +++ b/spec/lib/api/v3/statuses/status_collection_representer_spec.rb @@ -31,10 +31,10 @@ require 'spec_helper' describe ::API::V3::Statuses::StatusCollectionRepresenter do include API::V3::Utilities::PathHelper - let(:statuses) { FactoryBot.build_list(:status, 3) } - let(:representer) { + let(:statuses) { FactoryBot.build_list(:status, 3) } + let(:representer) do described_class.new(statuses, self_link: api_v3_paths.statuses, current_user: double('current_user')) - } + end context 'generation' do subject(:collection) { representer.to_json } diff --git a/spec/lib/api/v3/support/api_v3_filter_dependency.rb b/spec/lib/api/v3/support/api_v3_filter_dependency.rb index 93bbf5c431..d4da13a826 100644 --- a/spec/lib/api/v3/support/api_v3_filter_dependency.rb +++ b/spec/lib/api/v3/support/api_v3_filter_dependency.rb @@ -84,7 +84,6 @@ shared_examples_for 'filter dependency empty' do end end - shared_examples_for 'relation filter dependency' do include ::API::V3::Utilities::PathHelper diff --git a/spec/lib/api/v3/support/link_examples.rb b/spec/lib/api/v3/support/link_examples.rb index e41e38ccb4..21a452b136 100644 --- a/spec/lib/api/v3/support/link_examples.rb +++ b/spec/lib/api/v3/support/link_examples.rb @@ -42,7 +42,7 @@ shared_examples_for 'action link' do before do login_as(user) allow(user) - .to receive(:allowed_to?) do |permission, project| + .to receive(:allowed_to?) do |permission, _project| permissions.include?(permission) end end @@ -81,12 +81,12 @@ shared_context 'action link shared' do it 'indicates the desired method' do verb = begin - # the standard method #method on an object interferes - # with the let named 'method' conditionally defined - method - rescue ArgumentError - :get - end + # the standard method #method on an object interferes + # with the let named 'method' conditionally defined + method + rescue ArgumentError + :get + end if verb != :get is_expected diff --git a/spec/lib/api/v3/support/property_examples.rb b/spec/lib/api/v3/support/property_examples.rb index 40c3a95833..45fd1f52d2 100644 --- a/spec/lib/api/v3/support/property_examples.rb +++ b/spec/lib/api/v3/support/property_examples.rb @@ -38,7 +38,7 @@ shared_examples_for 'formattable property' do |name| it "has the #{name} property" do is_expected .to be_json_eql(value.to_json) - .at_path("#{name.to_s}/raw") + .at_path("#{name}/raw") end end diff --git a/spec/lib/api/v3/users/user_collection_representer_spec.rb b/spec/lib/api/v3/users/user_collection_representer_spec.rb index 801c977a79..eab799dc09 100644 --- a/spec/lib/api/v3/users/user_collection_representer_spec.rb +++ b/spec/lib/api/v3/users/user_collection_representer_spec.rb @@ -29,15 +29,15 @@ require 'spec_helper' describe ::API::V3::Users::UserCollectionRepresenter do - let(:users) { + let(:users) do FactoryBot.build_stubbed_list(:user, - 3) - } - let(:representer) { + 3) + end + let(:representer) do described_class.new(users, self_link: '/api/v3/work_package/1/watchers', current_user: users.first) - } + end context 'generation' do subject(:collection) { representer.to_json } diff --git a/spec/lib/api/v3/utilities/date_time_formatter_spec.rb b/spec/lib/api/v3/utilities/date_time_formatter_spec.rb index b0191b7745..608535a44f 100644 --- a/spec/lib/api/v3/utilities/date_time_formatter_spec.rb +++ b/spec/lib/api/v3/utilities/date_time_formatter_spec.rb @@ -77,16 +77,16 @@ describe :DateTimeFormatter do it 'rejects parsing non ISO date formats' do bad_format = date.strftime('%d.%m.%Y') - expect { + expect do subject.parse_date(bad_format, 'prop') - }.to raise_error(API::Errors::PropertyFormatError) + end.to raise_error(API::Errors::PropertyFormatError) end it 'rejects parsing ISO 8601 date + time formats' do bad_format = datetime.iso8601 - expect { + expect do subject.parse_date(bad_format, 'prop') - }.to raise_error(API::Errors::PropertyFormatError) + end.to raise_error(API::Errors::PropertyFormatError) end it_behaves_like 'can parse nil' do @@ -147,21 +147,21 @@ describe :DateTimeFormatter do end it 'rejects parsing non sense' do - expect { + expect do subject.parse_duration_to_hours('foo', 'prop') - }.to raise_error(API::Errors::PropertyFormatError) + end.to raise_error(API::Errors::PropertyFormatError) end it 'rejects parsing pure number strings' do - expect { + expect do subject.parse_duration_to_hours('5', 'prop') - }.to raise_error(API::Errors::PropertyFormatError) + end.to raise_error(API::Errors::PropertyFormatError) end it 'rejects parsing pure numbers' do - expect { + expect do subject.parse_duration_to_hours(5, 'prop') - }.to raise_error(API::Errors::PropertyFormatError) + end.to raise_error(API::Errors::PropertyFormatError) end it_behaves_like 'can parse nil' do diff --git a/spec/lib/api/v3/utilities/resource_link_generator_spec.rb b/spec/lib/api/v3/utilities/resource_link_generator_spec.rb index 9ef9e98fc4..9485f39187 100644 --- a/spec/lib/api/v3/utilities/resource_link_generator_spec.rb +++ b/spec/lib/api/v3/utilities/resource_link_generator_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,32 +37,32 @@ describe API::V3::Utilities::ResourceLinkGenerator do describe ':make_link' do it 'supports work packages' do wp = FactoryBot.build_stubbed(:work_package) - expect(subject.make_link wp).to eql api_v3_paths.work_package(wp.id) + expect(subject.make_link(wp)).to eql api_v3_paths.work_package(wp.id) end it 'supports priorities' do prio = FactoryBot.build_stubbed(:priority) - expect(subject.make_link prio).to eql api_v3_paths.priority(prio.id) + expect(subject.make_link(prio)).to eql api_v3_paths.priority(prio.id) end it 'supports statuses' do status = FactoryBot.build_stubbed(:status) - expect(subject.make_link status).to eql api_v3_paths.status(status.id) + expect(subject.make_link(status)).to eql api_v3_paths.status(status.id) end it 'supports the anonymous user' do user = FactoryBot.build_stubbed(:anonymous) - expect(subject.make_link user).to eql api_v3_paths.user(user.id) + expect(subject.make_link(user)).to eql api_v3_paths.user(user.id) end it 'returns nil for unsupported records' do record = FactoryBot.create(:custom_field) - expect(subject.make_link record).to be_nil + expect(subject.make_link(record)).to be_nil end it 'returns nil for non-AR types' do record = Object.new - expect(subject.make_link record).to be_nil + expect(subject.make_link(record)).to be_nil end end end diff --git a/spec/lib/api/v3/versions/version_representer_rendering_spec.rb b/spec/lib/api/v3/versions/version_representer_rendering_spec.rb index 7560ec1bf2..107f507706 100644 --- a/spec/lib/api/v3/versions/version_representer_rendering_spec.rb +++ b/spec/lib/api/v3/versions/version_representer_rendering_spec.rb @@ -44,7 +44,7 @@ describe ::API::V3::Versions::VersionRepresenter, 'rendering' do .to receive(:allowed_to?) do |permission, project| project == version.project && permissions.include?(permission) end - end + end let(:permissions) { [:manage_versions] } @@ -143,7 +143,7 @@ describe ::API::V3::Versions::VersionRepresenter, 'rendering' do .and_return([custom_field]) allow(version) - .to receive(:"custom_value_for") + .to receive(:custom_value_for) .with(custom_field) .and_return(custom_value) end @@ -270,7 +270,7 @@ describe ::API::V3::Versions::VersionRepresenter, 'rendering' do context 'custom fields' do let(:version) do - FactoryBot.build_stubbed(:version).tap do |v| + FactoryBot.build_stubbed(:version).tap do |_v| # Use this to force the custom field to be defined before the former_cache_key is calculated custom_field end diff --git a/spec/lib/api/v3/wiki_pages/wiki_page_representer_rendering_spec.rb b/spec/lib/api/v3/wiki_pages/wiki_page_representer_rendering_spec.rb index 9d3eacc592..deb427c17c 100644 --- a/spec/lib/api/v3/wiki_pages/wiki_page_representer_rendering_spec.rb +++ b/spec/lib/api/v3/wiki_pages/wiki_page_representer_rendering_spec.rb @@ -50,7 +50,7 @@ describe ::API::V3::WikiPages::WikiPageRepresenter, 'rendering' do before do allow(user) - .to receive(:allowed_to?) do |permission, project| + .to receive(:allowed_to?) do |permission, _project| permissions.include?(permission) end end diff --git a/spec/lib/api/v3/work_packages/create_form_representer_spec.rb b/spec/lib/api/v3/work_packages/create_form_representer_spec.rb index bb570fdf96..020e468f72 100644 --- a/spec/lib/api/v3/work_packages/create_form_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/create_form_representer_spec.rb @@ -213,10 +213,10 @@ describe ::API::V3::WorkPackages::CreateFormRepresenter do let(:type) { FactoryBot.build_stubbed(:type) } let(:work_package) do FactoryBot.build(:work_package, - id: 42, - created_at: DateTime.now, - updated_at: DateTime.now, - type: type) + id: 42, + created_at: DateTime.now, + updated_at: DateTime.now, + type: type) end before do diff --git a/spec/lib/api/v3/work_packages/create_project_form_representer_spec.rb b/spec/lib/api/v3/work_packages/create_project_form_representer_spec.rb index 9dccdb37f0..5f4ba80755 100644 --- a/spec/lib/api/v3/work_packages/create_project_form_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/create_project_form_representer_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -51,7 +52,8 @@ describe ::API::V3::WorkPackages::CreateProjectFormRepresenter do describe '_links' do it do is_expected.to be_json_eql( - api_v3_paths.create_project_work_package_form(work_package.project_id).to_json) + api_v3_paths.create_project_work_package_form(work_package.project_id).to_json + ) .at_path('_links/self/href') end @@ -62,7 +64,8 @@ describe ::API::V3::WorkPackages::CreateProjectFormRepresenter do describe 'validate' do it do is_expected.to be_json_eql( - api_v3_paths.create_project_work_package_form(work_package.project_id).to_json) + api_v3_paths.create_project_work_package_form(work_package.project_id).to_json + ) .at_path('_links/validate/href') end @@ -75,7 +78,9 @@ describe ::API::V3::WorkPackages::CreateProjectFormRepresenter do it do is_expected.to be_json_eql( api_v3_paths.render_markup( - link: api_v3_paths.project(work_package.project_id)).to_json) + link: api_v3_paths.project(work_package.project_id) + ).to_json + ) .at_path('_links/previewMarkup/href') end @@ -95,7 +100,8 @@ describe ::API::V3::WorkPackages::CreateProjectFormRepresenter do context 'valid work package' do it do is_expected.to be_json_eql( - api_v3_paths.work_packages_by_project(work_package.project_id).to_json) + api_v3_paths.work_packages_by_project(work_package.project_id).to_json + ) .at_path('_links/commit/href') end diff --git a/spec/lib/api/v3/work_packages/eager_loading/custom_value_integration_spec.rb b/spec/lib/api/v3/work_packages/eager_loading/custom_value_integration_spec.rb index 2381c1b0e9..99e4bb357e 100644 --- a/spec/lib/api/v3/work_packages/eager_loading/custom_value_integration_spec.rb +++ b/spec/lib/api/v3/work_packages/eager_loading/custom_value_integration_spec.rb @@ -157,7 +157,6 @@ describe ::API::V3::WorkPackages::EagerLoading::CustomValue do end end - describe '#usages returning an is_for_all custom field within multiple projects (Regression #28452)' do let!(:for_all_type_cf) do FactoryBot.create(:list_wp_custom_field, is_for_all: true).tap do |cf| diff --git a/spec/lib/api/v3/work_packages/form_representer_spec.rb b/spec/lib/api/v3/work_packages/form_representer_spec.rb index c708d47096..b4d87b89a3 100644 --- a/spec/lib/api/v3/work_packages/form_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/form_representer_spec.rb @@ -32,18 +32,18 @@ describe ::API::V3::WorkPackages::FormRepresenter do include API::V3::Utilities::PathHelper let(:errors) { [] } - let(:work_package) { + let(:work_package) do FactoryBot.build(:work_package, - id: 42, - created_at: DateTime.now, - updated_at: DateTime.now) - } - let(:current_user) { + id: 42, + created_at: DateTime.now, + updated_at: DateTime.now) + end + let(:current_user) do FactoryBot.build(:user, member_in_project: work_package.project) - } - let(:representer) { + end + let(:representer) do described_class.new(work_package, current_user: current_user, errors: errors) - } + end context 'generation' do subject(:generated) { representer.to_json } diff --git a/spec/lib/api/v3/work_packages/update_form_representer_spec.rb b/spec/lib/api/v3/work_packages/update_form_representer_spec.rb index 0afe02c49e..fd3350fd8e 100644 --- a/spec/lib/api/v3/work_packages/update_form_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/update_form_representer_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb index 2833cff257..0013a424fa 100644 --- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb @@ -466,6 +466,5 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do .at_path('_links/customFields') end end - end end diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb index 13c5387e1e..dbcf398137 100644 --- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb @@ -716,13 +716,15 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do context 'when the user has the permission to add and remove watchers' do it 'should have a link to add watcher' do expect(subject).to be_json_eql( - api_v3_paths.work_package_watchers(work_package.id).to_json) + api_v3_paths.work_package_watchers(work_package.id).to_json + ) .at_path('_links/addWatcher/href') end it 'should have a link to remove watcher' do expect(subject).to be_json_eql( - api_v3_paths.watcher('{user_id}', work_package.id).to_json) + api_v3_paths.watcher('{user_id}', work_package.id).to_json + ) .at_path('_links/removeWatcher/href') end end @@ -801,7 +803,8 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do it_behaves_like 'has a titled link' do let(:link) { 'timeEntries' } let(:href) do - api_v3_paths.path_for(:time_entries, filters: [{ work_package_id: { operator: "=", values: [work_package.id.to_s] } }]) + api_v3_paths.path_for(:time_entries, + filters: [{ work_package_id: { operator: "=", values: [work_package.id.to_s] } }]) end let(:title) { 'Time entries' } end @@ -1120,7 +1123,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do it 'is based on the representer\'s cache_key' do allow(OpenProject::Cache) .to receive(:fetch) - .and_return({_links: {}}.to_json) + .and_return({ _links: {} }.to_json) expect(OpenProject::Cache) .to receive(:fetch) .with(representer.json_cache_key) diff --git a/spec/lib/custom_field_form_builder_spec.rb b/spec/lib/custom_field_form_builder_spec.rb index 5434a6a20b..ac2049a071 100644 --- a/spec/lib/custom_field_form_builder_spec.rb +++ b/spec/lib/custom_field_form_builder_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -36,7 +37,7 @@ describe CustomFieldFormBuilder do let(:builder) { described_class.new(:user, resource, helper, {}) } describe '#custom_field' do - let(:options) { {class: 'custom-class'} } + let(:options) { { class: 'custom-class' } } let(:custom_field) do FactoryBot.build_stubbed(:custom_field) diff --git a/spec/lib/database_spec.rb b/spec/lib/database_spec.rb index a81196c5f6..257764beb2 100644 --- a/spec/lib/database_spec.rb +++ b/spec/lib/database_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/lib/deprecated_alias_spec.rb b/spec/lib/deprecated_alias_spec.rb index dfa6095912..8813b1707b 100644 --- a/spec/lib/deprecated_alias_spec.rb +++ b/spec/lib/deprecated_alias_spec.rb @@ -29,30 +29,34 @@ require 'spec_helper' describe DeprecatedAlias do - let(:clazz) { + let(:clazz) do Class.new do extend DeprecatedAlias def secret_key - @secret_key ||= 'happiness' + 'happiness' end deprecated_alias :special_key, :secret_key end - } + end subject(:object) { clazz.new } - let(:deprecation_warning) { - 'special_key is deprecated and will be removed in a future OpenProject version. ' + - 'Please use secret_key instead.' - } + let(:deprecation_warning) do + <<~MSG + special_key is deprecated and will be removed in a future OpenProject version. + + Please use secret_key instead. + + MSG + end before do expect(ActiveSupport::Deprecation).to receive(:warn) .with(deprecation_warning, an_instance_of(Array)) end - it 'should alias the method' do + it 'aliases the method' do expect(object.special_key).to eq('happiness') end end diff --git a/spec/lib/journal_formatter/diff_spec.rb b/spec/lib/journal_formatter/diff_spec.rb index f92fc75c12..03741a69a1 100644 --- a/spec/lib/journal_formatter/diff_spec.rb +++ b/spec/lib/journal_formatter/diff_spec.rb @@ -46,47 +46,47 @@ describe OpenProject::JournalFormatter::Diff do let(:instance) { klass.new(journal) } let(:key) { 'description' } - let(:url) { + let(:url) do url_helper.diff_journal_path(id: journal.id, field: key.downcase) - } - let(:full_url) { + end + let(:full_url) do url_helper.diff_journal_url(id: journal.id, field: key.downcase, protocol: Setting.protocol, host: Setting.host_name) - } + end let(:link) { link_to(I18n.t(:label_details), url, class: 'description-details') } let(:full_url_link) { link_to(I18n.t(:label_details), full_url, class: 'description-details') } describe '#render' do describe 'WITH the first value being nil, and the second a string' do - let(:expected) { + let(:expected) do I18n.t(:text_journal_set_with_diff, label: "#{key.camelize}", link: link) - } + end it { expect(instance.render(key, [nil, 'new value'])).to eq(expected) } end describe 'WITH the first value being a string, and the second a string' do - let(:expected) { + let(:expected) do I18n.t(:text_journal_changed_with_diff, label: "#{key.camelize}", link: link) - } + end it { expect(instance.render(key, ['old value', 'new value'])).to eq(expected) } end describe "WITH the first value being a string, and the second a string WITH de as locale" do - let(:expected) { + let(:expected) do I18n.t(:text_journal_changed_with_diff, label: 'Beschreibung', link: link) - } + end before do I18n.locale = :de @@ -100,54 +100,54 @@ describe OpenProject::JournalFormatter::Diff do end describe 'WITH the first value being a string, and the second nil' do - let(:expected) { + let(:expected) do I18n.t(:text_journal_deleted_with_diff, label: "#{key.camelize}", link: link) - } + end it { expect(instance.render(key, ['old_value', nil])).to eq(expected) } end describe "WITH the first value being nil, and the second a string WITH specifying not to output html" do - let(:expected) { + let(:expected) do I18n.t(:text_journal_set_with_diff, label: key.camelize, link: url) - } + end it { expect(instance.render(key, [nil, 'new value'], no_html: true)).to eq(expected) } end describe "WITH the first value being a string, and the second a string WITH specifying not to output html" do - let(:expected) { + let(:expected) do I18n.t(:text_journal_changed_with_diff, label: key.camelize, link: url) - } + end it { expect(instance.render(key, ['old value', 'new value'], no_html: true)).to eq(expected) } end describe "WITH the first value being a string, and the second a string WITH specifying to output a full url" do - let(:expected) { + let(:expected) do I18n.t(:text_journal_changed_with_diff, label: "#{key.camelize}", link: full_url_link) - } + end it { expect(instance.render(key, ['old value', 'new value'], only_path: false)).to eq(expected) } end describe 'WITH the first value being a string, and the second nil' do - let(:expected) { + let(:expected) do I18n.t(:text_journal_deleted_with_diff, label: key.camelize, link: url) - } + end it { expect(instance.render(key, ['old_value', nil], no_html: true)).to eq(expected) } end diff --git a/spec/lib/open_project/access_control_spec.rb b/spec/lib/open_project/access_control_spec.rb index b197a30998..2e09397d5c 100644 --- a/spec/lib/open_project/access_control_spec.rb +++ b/spec/lib/open_project/access_control_spec.rb @@ -29,7 +29,6 @@ require 'spec_helper' describe OpenProject::AccessControl do - def stash_access_control_permissions @stashed_permissions = OpenProject::AccessControl.permissions.dup OpenProject::AccessControl.clear_caches @@ -80,6 +79,7 @@ describe OpenProject::AccessControl do after do raise 'Test outdated' unless OpenProject::AccessControl.instance_variable_defined?(:@permissions) + OpenProject::AccessControl.instance_variable_set(:@permissions, all_former_permissions) OpenProject::AccessControl.clear_caches end diff --git a/spec/lib/open_project/configuration/helpers_spec.rb b/spec/lib/open_project/configuration/helpers_spec.rb index 3beaa7eb94..3c3a703a97 100644 --- a/spec/lib/open_project/configuration/helpers_spec.rb +++ b/spec/lib/open_project/configuration/helpers_spec.rb @@ -30,11 +30,11 @@ require 'spec_helper' require 'open_project/configuration/helpers' describe OpenProject::Configuration::Helpers do - let(:config) { + let(:config) do {}.tap do |config| config.extend OpenProject::Configuration::Helpers end - } + end describe '#array' do def array(value) diff --git a/spec/lib/open_project/configuration_spec.rb b/spec/lib/open_project/configuration_spec.rb index 085b4fd022..446268d46f 100644 --- a/spec/lib/open_project/configuration_spec.rb +++ b/spec/lib/open_project/configuration_spec.rb @@ -60,7 +60,8 @@ describe OpenProject::Configuration do 'default' => { 'somesetting' => 'foo' }, 'test' => {}, 'someother' => { 'somesetting' => 'bar' } - }, 'test') end + }, 'test') + end it 'should load a default setting' do expect(config['somesetting']).to eq('foo') @@ -72,7 +73,8 @@ describe OpenProject::Configuration do OpenProject::Configuration.send(:load_env_from_config, { 'default' => {}, 'test' => { 'somesetting' => 'foo' } - }, 'test') end + }, 'test') + end it 'should load a setting' do expect(config['somesetting']).to eq('foo') @@ -84,7 +86,8 @@ describe OpenProject::Configuration do OpenProject::Configuration.send(:load_env_from_config, { 'default' => { 'somesetting' => 'foo' }, 'test' => { 'somesetting' => 'bar' } - }, 'test') end + }, 'test') + end it 'should load the overriding value' do expect(config['somesetting']).to eq('bar') @@ -203,7 +206,9 @@ describe OpenProject::Configuration do 'address' => 'smtp.example.net', 'port' => 25, 'domain' => 'example.net' - } } } + } + } + } end context 'with delivery_method' do diff --git a/spec/lib/open_project/content_type_detector_spec.rb b/spec/lib/open_project/content_type_detector_spec.rb index e9dfcc9da9..0aad20acf2 100644 --- a/spec/lib/open_project/content_type_detector_spec.rb +++ b/spec/lib/open_project/content_type_detector_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -69,20 +70,21 @@ describe OpenProject::ContentTypeDetector do end it 'returns content type of file if it is an acceptable type' do - allow(MIME::Types).to receive(:type_for).and_return([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')]) + allow(MIME::Types).to receive(:type_for).and_return([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), + MIME::Type.new('audio/mp4')]) allow(::Open3).to receive(:capture2).and_return(['video/mp4', 0]) @filename = 'my_file.mp4' assert_equal 'video/mp4', OpenProject::ContentTypeDetector.new(@filename).detect end it 'returns the default when exitcode > 0' do - allow(MIME::Types).to receive(:type_for).and_return([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), MIME::Type.new('audio/mp4')]) + allow(MIME::Types).to receive(:type_for).and_return([MIME::Type.new('application/mp4'), MIME::Type.new('video/mp4'), + MIME::Type.new('audio/mp4')]) allow(::Open3).to receive(:capture2).and_return(['', 1]) @filename = 'my_file.mp4' assert_equal 'application/binary', OpenProject::ContentTypeDetector.new(@filename).detect end - it 'finds the right type in the list via the file command' do @filename = "#{Dir.tmpdir}/something.hahalolnotreal" File.open(@filename, 'w+') do |file| diff --git a/spec/lib/open_project/file_command_content_type_detector_spec.rb b/spec/lib/open_project/file_command_content_type_detector_spec.rb index ef8076c78a..ecce563d65 100644 --- a/spec/lib/open_project/file_command_content_type_detector_spec.rb +++ b/spec/lib/open_project/file_command_content_type_detector_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/lib/open_project/files_spec.rb b/spec/lib/open_project/files_spec.rb index a28bb3516a..9b8f9931db 100644 --- a/spec/lib/open_project/files_spec.rb +++ b/spec/lib/open_project/files_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -61,9 +62,9 @@ describe OpenProject::Files do describe 'build_uploaded_file' do let(:original_filename) { 'test.png' } let(:content_type) { 'image/png' } - let(:file) { + let(:file) do OpenProject::Files.create_temp_file(name: original_filename) - } + end subject { OpenProject::Files.build_uploaded_file(file, content_type) } diff --git a/spec/lib/open_project/form_tag_helper_spec.rb b/spec/lib/open_project/form_tag_helper_spec.rb index 612cdc5ce1..3b7adcb383 100644 --- a/spec/lib/open_project/form_tag_helper_spec.rb +++ b/spec/lib/open_project/form_tag_helper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,11 +34,11 @@ describe OpenProject::FormTagHelper, type: :helper do let(:options) { {} } describe '#styled_form_tag' do - subject(:output) { + subject(:output) do helper.styled_form_tag('/feedback', options) do content_tag(:p, 'Form content') end - } + end it_behaves_like 'not wrapped in container', 'form-container' @@ -51,9 +52,9 @@ describe OpenProject::FormTagHelper, type: :helper do end describe '#styled_select_tag' do - subject(:output) { + subject(:output) do helper.styled_select_tag('field', ''.html_safe, options) - } + end it_behaves_like 'wrapped in container', 'select-container' @@ -68,9 +69,9 @@ describe OpenProject::FormTagHelper, type: :helper do describe '#styled_text_field_tag' do let(:value) { 'Something to be seen' } - subject(:output) { + subject(:output) do helper.styled_text_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'text-field-container' @@ -84,11 +85,11 @@ describe OpenProject::FormTagHelper, type: :helper do describe '#styled_label_tag' do context 'with block' do - subject(:output) { + subject(:output) do helper.styled_label_tag('field', nil, options) do 'Label content' end - } + end it_behaves_like 'not wrapped in container', 'label-container' @@ -100,9 +101,9 @@ describe OpenProject::FormTagHelper, type: :helper do end context 'with content arg' do - subject(:output) { + subject(:output) do helper.styled_label_tag('field', 'Label content', options) - } + end it_behaves_like 'not wrapped in container', 'label-container' @@ -129,9 +130,9 @@ describe OpenProject::FormTagHelper, type: :helper do end it 'should strip any given inline HTML from the title tag (with block)' do - label = helper.styled_label_tag('field') { + label = helper.styled_label_tag('field') do helper.content_tag :span, 'Sif' - } + end expect(label).to be_html_eql(%{ }) @@ -147,9 +148,9 @@ describe OpenProject::FormTagHelper, type: :helper do end describe '#styled_file_field_tag' do - subject(:output) { + subject(:output) do helper.styled_file_field_tag('file_field', options) - } + end it_behaves_like 'wrapped in container', 'file-field-container' @@ -162,9 +163,9 @@ describe OpenProject::FormTagHelper, type: :helper do end describe '#styled_password_field_tag' do - subject(:output) { + subject(:output) do helper.styled_password_field_tag('password', 'nopE3king!', options) - } + end it_behaves_like 'wrapped in container', 'text-field-container' @@ -177,9 +178,9 @@ describe OpenProject::FormTagHelper, type: :helper do end describe '#styled_text_area_tag' do - subject(:output) { + subject(:output) do helper.styled_text_area_tag('field', 'Words are important', options) - } + end it_behaves_like 'wrapped in container', 'text-area-container' @@ -192,9 +193,9 @@ Words are important end describe '#styled_check_box_tag' do - subject(:output) { + subject(:output) do helper.styled_check_box_tag('field', '1', false, options) - } + end it_behaves_like 'wrapped in container', 'check-box-container' @@ -209,9 +210,9 @@ Words are important describe '#styled_radio_button_tag' do let(:value) { 'good choice' } - subject(:output) { + subject(:output) do helper.styled_radio_button_tag('field', value, false, options) - } + end it_behaves_like 'wrapped in container', 'radio-button-container' @@ -224,12 +225,12 @@ Words are important end describe '#styled_submit_tag' do - subject(:output) { + subject(:output) do helper.styled_submit_tag('Save it!', options) - } - subject(:html) { + end + subject(:html) do Capybara::Node::Simple.new(output) - } + end it_behaves_like 'not wrapped in container', 'submit-container' @@ -239,11 +240,11 @@ Words are important end describe '#styled_button_tag' do - subject(:output) { + subject(:output) do helper.styled_button_tag(options) do "Don't save!" end - } + end it_behaves_like 'not wrapped in container', 'button-container' @@ -255,11 +256,11 @@ Words are important end describe '#styled_field_set_tag' do - subject(:output) { + subject(:output) do helper.styled_field_set_tag('Fieldset Legend', options) do content_tag(:p, 'Fieldset content') end - } + end it_behaves_like 'not wrapped in container', 'fieldset-container' @@ -275,9 +276,9 @@ Words are important describe '#styled_search_field_tag' do let(:value) { 'Find me' } - subject(:output) { + subject(:output) do helper.styled_search_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'search-field-container' @@ -292,9 +293,9 @@ Words are important describe '#styled_telephone_field_tag' do let(:value) { '+49 555 111 999' } - subject(:output) { + subject(:output) do helper.styled_telephone_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'text-field-container' @@ -309,9 +310,9 @@ Words are important describe '#styled_url_field_tag' do let(:value) { 'https://blogger.org/' } - subject(:output) { + subject(:output) do helper.styled_url_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'text-field-container' @@ -326,9 +327,9 @@ Words are important describe '#styled_email_field_tag' do let(:value) { 'joe@blogger.com' } - subject(:output) { + subject(:output) do helper.styled_email_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'text-field-container' @@ -343,9 +344,9 @@ Words are important describe '#styled_number_field_tag' do let(:value) { 2 } - subject(:output) { + subject(:output) do helper.styled_number_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'text-field-container' @@ -359,9 +360,9 @@ Words are important describe '#styled_range_field_tag' do let(:value) { 2 } - subject(:output) { + subject(:output) do helper.styled_range_field_tag('field', value, options) - } + end it_behaves_like 'wrapped in container', 'range-field-container' diff --git a/spec/lib/open_project/notifications_spec.rb b/spec/lib/open_project/notifications_spec.rb index e07599a013..51e0595dc7 100644 --- a/spec/lib/open_project/notifications_spec.rb +++ b/spec/lib/open_project/notifications_spec.rb @@ -51,9 +51,9 @@ describe OpenProject::Notifications do describe '.subscribe' do it 'throws an error when no callback is given' do - expect { + expect do OpenProject::Notifications.subscribe('notifications_spec_send') - }.to raise_error ArgumentError, /provide a block as a callback/ + end.to raise_error ArgumentError, /provide a block as a callback/ end describe 'clear_subscriptions:' do diff --git a/spec/lib/open_project/object_linking_spec.rb b/spec/lib/open_project/object_linking_spec.rb index bb24087459..256e178d71 100644 --- a/spec/lib/open_project/object_linking_spec.rb +++ b/spec/lib/open_project/object_linking_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/lib/open_project/plugins/module_handler_spec.rb b/spec/lib/open_project/plugins/module_handler_spec.rb index df430c9ae8..a8b80dad23 100644 --- a/spec/lib/open_project/plugins/module_handler_spec.rb +++ b/spec/lib/open_project/plugins/module_handler_spec.rb @@ -37,6 +37,7 @@ describe OpenProject::Plugins::ModuleHandler do after do raise 'Test outdated' unless OpenProject::AccessControl.instance_variable_defined?(:@permissions) + OpenProject::AccessControl.instance_variable_set(:@permissions, all_former_permissions) OpenProject::AccessControl.clear_caches end diff --git a/spec/lib/open_project/scm/adapters/git_adapter_spec.rb b/spec/lib/open_project/scm/adapters/git_adapter_spec.rb index 72f2a7d037..85ebeb867c 100644 --- a/spec/lib/open_project/scm/adapters/git_adapter_spec.rb +++ b/spec/lib/open_project/scm/adapters/git_adapter_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,7 +36,7 @@ describe OpenProject::SCM::Adapters::Git do let(:url) { protocol + Rails.root.join('/tmp/does/not/exist.git').to_s } let(:config) { {} } let(:encoding) { nil } - let(:adapter) { + let(:adapter) do OpenProject::SCM::Adapters::Git.new( url, nil, @@ -44,7 +45,7 @@ describe OpenProject::SCM::Adapters::Git do encoding, "test-identifier" ) - } + end repos_dir = Dir.mktmpdir diff --git a/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb b/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb index 586caaf0c6..fddc82db8f 100644 --- a/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb +++ b/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/lib/open_project/scm/manager_spec.rb b/spec/lib/open_project/scm/manager_spec.rb index 861ebee687..878d9e0e3a 100644 --- a/spec/lib/open_project/scm/manager_spec.rb +++ b/spec/lib/open_project/scm/manager_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/lib/open_project/storage_spec.rb b/spec/lib/open_project/storage_spec.rb index e7fcd6390e..e26e0f408b 100644 --- a/spec/lib/open_project/storage_spec.rb +++ b/spec/lib/open_project/storage_spec.rb @@ -73,11 +73,11 @@ describe OpenProject::Storage do context 'with SCM configuration' do include_context 'with tmpdir' - let(:config) { + let(:config) do { git: { manages: File.join(tmpdir, 'git') } } - } + end let(:enabled_scms) { %w[git] } let(:returned_fs_info) { [{ id: 1, free: 1234 }] } @@ -118,8 +118,7 @@ describe OpenProject::Storage do .to eq(1 => { labels: [I18n.t(:label_managed_repositories_vendor, vendor: 'Git')], data: returned_fs_info[0] }, 2 => { labels: [I18n.t('attributes.attachments')], - data: returned_fs_info[1] } - ) + data: returned_fs_info[1] }) end end end diff --git a/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb b/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb index 1962d73e40..afdc5b821d 100644 --- a/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/child_pages_macro_spec.rb @@ -37,75 +37,75 @@ describe 'OpenProject child pages macro' do # no-op end - let(:project) { + let(:project) do FactoryBot.create :valid_project, enabled_module_names: %w[wiki] - } - let(:member_project) { + end + let(:member_project) do FactoryBot.create :valid_project, identifier: 'member-project', enabled_module_names: %w[wiki] - } - let(:invisible_project) { + end + let(:invisible_project) do FactoryBot.create :valid_project, identifier: 'other-project', enabled_module_names: %w[wiki] - } + end let(:role) { FactoryBot.create(:role, permissions: [:view_wiki_pages]) } - let(:user) { + let(:user) do FactoryBot.create(:user, member_in_projects: [project, member_project], member_through_role: role) - } + end - let(:current_page) { + let(:current_page) do FactoryBot.create :wiki_page, title: 'Current page', wiki: project.wiki, content: FactoryBot.build(:wiki_content, text: input) - } + end - let(:middle_page) { + let(:middle_page) do FactoryBot.create :wiki_page, title: 'Node from same project', wiki: project.wiki, parent_id: current_page.id, content: FactoryBot.build(:wiki_content, text: '# Node Page from same project') - } + end - let(:node_page_invisible_project) { + let(:node_page_invisible_project) do FactoryBot.create :wiki_page, title: 'Node page from invisible project', wiki: invisible_project.wiki, content: FactoryBot.build(:wiki_content, text: '# Page from invisible project') - } + end - let(:leaf_page) { + let(:leaf_page) do FactoryBot.create :wiki_page, title: 'Leaf page from same project', parent_id: middle_page.id, wiki: project.wiki, content: FactoryBot.build(:wiki_content, text: '# Leaf page from same project') - } + end - let(:leaf_page_invisible_project) { + let(:leaf_page_invisible_project) do FactoryBot.create :wiki_page, title: 'Leaf page from invisible project', parent_id: node_page_invisible_project.id, wiki: invisible_project.wiki, content: FactoryBot.build(:wiki_content, text: '# Leaf page from invisible project') - } + end - let(:leaf_page_member_project) { + let(:leaf_page_member_project) do FactoryBot.create :wiki_page, title: 'Leaf page from member project', wiki: member_project.wiki, content: FactoryBot.build(:wiki_content, text: '# Leaf page from member project') - } + end before do login_as(user) end - let(:input) { } + let(:input) {} subject { format_text(current_page.content, :text) } before do @@ -173,7 +173,9 @@ describe 'OpenProject child pages macro' do end context 'when referencing page from a member project' do - let(:input) { '' } + let(:input) do + '' + end before { leaf_page_member_project } it { is_expected.to match(leaf_page_member_project.title) } end diff --git a/spec/lib/open_project/text_formatting/markdown/code_spec.rb b/spec/lib/open_project/text_formatting/markdown/code_spec.rb index a7438f79ea..a0b79eefd7 100644 --- a/spec/lib/open_project/text_formatting/markdown/code_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/code_spec.rb @@ -149,6 +149,5 @@ describe OpenProject::TextFormatting, EXPECTED end end - end end diff --git a/spec/lib/open_project/text_formatting/markdown/images_spec.rb b/spec/lib/open_project/text_formatting/markdown/images_spec.rb index 96fe732b0d..7a08a80981 100644 --- a/spec/lib/open_project/text_formatting/markdown/images_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/images_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb b/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb index 98dbe26998..45d4d68f61 100644 --- a/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb @@ -191,13 +191,19 @@ describe OpenProject::TextFormatting, context 'Plain message' do subject { format_text("message##{message1.id}") } - it { is_expected.to be_html_eql("

#{link_to(message1.subject, topic_path(message1), class: 'message op-uc-link')}

") } + it { + is_expected.to be_html_eql("

#{link_to(message1.subject, topic_path(message1), + class: 'message op-uc-link')}

") + } end context 'Message with parent' do subject { format_text("message##{message2.id}") } - it { is_expected.to be_html_eql("

#{link_to(message2.subject, topic_path(message1, anchor: "message-#{message2.id}", r: message2.id), class: 'message op-uc-link')}

") } + it { + is_expected.to be_html_eql("

#{link_to(message2.subject, + topic_path(message1, anchor: "message-#{message2.id}", r: message2.id), class: 'message op-uc-link')}

") + } end end @@ -211,7 +217,9 @@ describe OpenProject::TextFormatting, context 'Plain work_package link' do subject { format_text("##{work_package.id}, [##{work_package.id}], (##{work_package.id}) and ##{work_package.id}.") } - it { is_expected.to be_html_eql("

#{work_package_link}, [#{work_package_link}], (#{work_package_link}) and #{work_package_link}.

") } + it { + is_expected.to be_html_eql("

#{work_package_link}, [#{work_package_link}], (#{work_package_link}) and #{work_package_link}.

") + } end context 'Plain work_package link with braces' do @@ -294,19 +302,28 @@ describe OpenProject::TextFormatting, context 'Plain project link' do subject { format_text("project##{subproject.id}") } - it { is_expected.to be_html_eql("

#{link_to(subproject.name, project_url, class: 'project op-uc-link')}

") } + it { + is_expected.to be_html_eql("

#{link_to(subproject.name, project_url, + class: 'project op-uc-link')}

") + } end context 'Plain project link via identifier' do subject { format_text("project:#{subproject.identifier}") } - it { is_expected.to be_html_eql("

#{link_to(subproject.name, project_url, class: 'project op-uc-link')}

") } + it { + is_expected.to be_html_eql("

#{link_to(subproject.name, project_url, + class: 'project op-uc-link')}

") + } end context 'Plain project link via name' do subject { format_text("project:\"#{subproject.name}\"") } - it { is_expected.to be_html_eql("

#{link_to(subproject.name, project_url, class: 'project op-uc-link')}

") } + it { + is_expected.to be_html_eql("

#{link_to(subproject.name, project_url, + class: 'project op-uc-link')}

") + } end end @@ -357,86 +374,114 @@ describe OpenProject::TextFormatting, context 'Plain wiki link' do subject { format_text('[[CookBook documentation]]') } - it { is_expected.to be_html_eql("

CookBook documentation

") } + it { + is_expected.to be_html_eql("

CookBook documentation

") + } end context 'Arbitrary wiki link' do title = '' subject { format_text("[[#{title}]]") } - it { is_expected.to be_html_eql("

#{h(title)}

") } + it { + is_expected.to be_html_eql("

#{h(title)}

") + } end context 'Plain wiki page link' do subject { format_text('[[Another page|Page]]') } - it { is_expected.to be_html_eql("

Page

") } + it { + is_expected.to be_html_eql("

Page

") + } end context 'Wiki link with anchor' do subject { format_text('[[CookBook documentation#One-section]]') } - it { is_expected.to be_html_eql("

CookBook documentation

") } + it { + is_expected.to be_html_eql("

CookBook documentation

") + } end context 'Wiki page link with anchor' do subject { format_text('[[Another page#anchor|Page]]') } - it { is_expected.to be_html_eql("

Page

") } + it { + is_expected.to be_html_eql("

Page

") + } end context 'Wiki link to an unknown page' do subject { format_text('[[Unknown page]]') } - it { is_expected.to be_html_eql("

Unknown page

") } + it { + is_expected.to be_html_eql("

Unknown page

") + } end context 'Wiki page link to an unknown page' do subject { format_text('[[Unknown page|404]]') } - it { is_expected.to be_html_eql("

404

") } + it { + is_expected.to be_html_eql("

404

") + } end context "Link to another project's wiki" do subject { format_text('[[onlinestore:]]') } - it { is_expected.to be_html_eql("

onlinestore

") } + it { + is_expected.to be_html_eql("

onlinestore

") + } end context "Link to another project's wiki with label" do subject { format_text('[[onlinestore:|Wiki]]') } - it { is_expected.to be_html_eql("

Wiki

") } + it { + is_expected.to be_html_eql("

Wiki

") + } end context "Link to another project's wiki page" do subject { format_text('[[onlinestore:Start page]]') } - it { is_expected.to be_html_eql("

Start Page

") } + it { + is_expected.to be_html_eql("

Start Page

") + } end context "Link to another project's wiki page with label" do subject { format_text('[[onlinestore:Start page|Text]]') } - it { is_expected.to be_html_eql("

Text

") } + it { + is_expected.to be_html_eql("

Text

") + } end context 'Link to an unknown wiki page in another project' do subject { format_text('[[onlinestore:Unknown page]]') } - it { is_expected.to be_html_eql("

Unknown page

") } + it { + is_expected.to be_html_eql("

Unknown page

") + } end context 'Struck through link to wiki page' do subject { format_text('~~[[Another page|Page]]~~') } - it { is_expected.to be_html_eql("

Page

") } + it { + is_expected.to be_html_eql("

Page

") + } end context 'Named struck through link to wiki page' do subject { format_text('~~[[Another page|Page]] link~~') } - it { is_expected.to be_html_eql("

Page link

") } + it { + is_expected.to be_html_eql("

Page link

") + } end context 'Escaped link to wiki page' do @@ -488,10 +533,13 @@ describe OpenProject::TextFormatting, 'source:"/some/file.ext". ' => link_to('source:/some/file.ext', source_url_with_ext, class: 'source op-uc-link') + '.', 'source:/some/file, ' => link_to('source:/some/file', source_url, class: 'source op-uc-link') + ',', 'source:/some/file@52' => link_to('source:/some/file@52', source_url(rev: 52), class: 'source op-uc-link'), - 'source:"/some/file.ext@52"' => link_to('source:/some/file.ext@52', source_url_with_ext(rev: 52), class: 'source op-uc-link'), + 'source:"/some/file.ext@52"' => link_to('source:/some/file.ext@52', source_url_with_ext(rev: 52), + class: 'source op-uc-link'), 'source:"/some/file#L110"' => link_to('source:/some/file#L110', source_url(anchor: 'L110'), class: 'source op-uc-link'), - 'source:"/some/file.ext#L110"' => link_to('source:/some/file.ext#L110', source_url_with_ext(anchor: 'L110'), class: 'source op-uc-link'), - 'source:"/some/file@52#L110"' => link_to('source:/some/file@52#L110', source_url(rev: 52, anchor: 'L110'), class: 'source op-uc-link'), + 'source:"/some/file.ext#L110"' => link_to('source:/some/file.ext#L110', source_url_with_ext(anchor: 'L110'), + class: 'source op-uc-link'), + 'source:"/some/file@52#L110"' => link_to('source:/some/file@52#L110', source_url(rev: 52, anchor: 'L110'), + class: 'source op-uc-link'), 'export:/some/file' => link_to('export:/some/file', source_url(format: 'raw'), class: 'source download op-uc-link'), # escaping '!source:/some/file' => 'source:/some/file', diff --git a/spec/lib/open_project/text_formatting/markdown/lists_spec.rb b/spec/lib/open_project/text_formatting/markdown/lists_spec.rb index fd92e70377..95dde46bf5 100644 --- a/spec/lib/open_project/text_formatting/markdown/lists_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/lists_spec.rb @@ -198,7 +198,7 @@ describe OpenProject::TextFormatting, let(:expected) do <<~EXPECTED -
+
#{' '}
@@ -302,7 +302,7 @@ describe OpenProject::TextFormatting, let(:expected) do <<~EXPECTED -
+
#{' '}
diff --git a/spec/lib/open_project/text_formatting/markdown/markdown_formatting_spec.rb b/spec/lib/open_project/text_formatting/markdown/markdown_formatting_spec.rb index 38d194b92d..f7ad76328e 100644 --- a/spec/lib/open_project/text_formatting/markdown/markdown_formatting_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/markdown_formatting_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -33,14 +34,14 @@ require_relative './expected_markdown' describe OpenProject::TextFormatting::Formats::Markdown::Formatter do it 'should modifiers' do assert_html_output( - '**bold**' => 'bold', - 'before **bold**' => 'before bold', - '**bold** after' => 'bold after', - '**two words**' => 'two words', - '**two*words**' => 'two*words', - '**two * words**' => 'two * words', - '**two** **words**' => 'twowords', - '**(two)** **(words)**' => '(two)(words)' + '**bold**' => 'bold', + 'before **bold**' => 'before bold', + '**bold** after' => 'bold after', + '**two words**' => 'two words', + '**two*words**' => 'two*words', + '**two * words**' => 'two * words', + '**two** **words**' => 'twowords', + '**(two)** **(words)**' => '(two)(words)' ) end diff --git a/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb b/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb index fe1a69be09..098eb7e7fd 100644 --- a/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb +++ b/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,12 +41,12 @@ describe OpenProject::TextFormatting::Formats::Markdown::PandocWrapper do context 'when wrap=preserve exists' do let(:usage_string) do <<~EOS - --list-output-formats - --list-highlight-languages - --list-highlight-styles - --wrap=auto|none|preserve - -v --version - -h --help + --list-output-formats#{' '} + --list-highlight-languages#{' '} + --list-highlight-styles#{' '} + --wrap=auto|none|preserve + -v --version#{' '} + -h --help EOS end @@ -57,12 +58,12 @@ describe OpenProject::TextFormatting::Formats::Markdown::PandocWrapper do context 'when only no-wrap exists' do let(:usage_string) do <<~EOS - --list-output-formats - --list-highlight-languages - --list-highlight-styles - --no-wrap - -v --version - -h --help + --list-output-formats#{' '} + --list-highlight-languages#{' '} + --list-highlight-styles#{' '} + --no-wrap + -v --version#{' '} + -h --help EOS end it do @@ -73,7 +74,9 @@ describe OpenProject::TextFormatting::Formats::Markdown::PandocWrapper do context 'when neither exists' do let(:usage_string) { 'wat?' } it do - expect { subject.wrap_mode }.to raise_error 'Your pandoc version has neither --no-wrap nor --wrap=preserve. Please install a recent version of pandoc.' + expect do + subject.wrap_mode + end.to raise_error 'Your pandoc version has neither --no-wrap nor --wrap=preserve. Please install a recent version of pandoc.' end end end diff --git a/spec/lib/open_project/text_formatting/plain_spec.rb b/spec/lib/open_project/text_formatting/plain_spec.rb index aaafc32ea4..649b9ac0eb 100644 --- a/spec/lib/open_project/text_formatting/plain_spec.rb +++ b/spec/lib/open_project/text_formatting/plain_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -46,7 +47,8 @@ describe OpenProject::TextFormatting::Formats::Plain::Formatter do def assert_html_output(to_test, expect_paragraph = true) to_test.each do |text, expected| - assert_equal((expect_paragraph ? "

#{expected}

" : expected), subject.to_html(text), "Formatting the following text failed:\n===\n#{text}\n===\n") + assert_equal((expect_paragraph ? "

#{expected}

" : expected), subject.to_html(text), + "Formatting the following text failed:\n===\n#{text}\n===\n") end end diff --git a/spec/lib/open_project/text_formatting/text_formatting_spec.rb b/spec/lib/open_project/text_formatting/text_formatting_spec.rb index ce2603f2ee..1c65a84dba 100644 --- a/spec/lib/open_project/text_formatting/text_formatting_spec.rb +++ b/spec/lib/open_project/text_formatting/text_formatting_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -42,17 +43,18 @@ describe OpenProject::TextFormatting do end it 'should link urls and email addresses' do - raw = <<-DIFF -This is a sample *text* with a link: http://www.redmine.org -and an email address foo@example.net -DIFF + raw = <<~DIFF + This is a sample *text* with a link: http://www.redmine.org + and an email address foo@example.net + DIFF - expected = <<-EXPECTED -

This is a sample *text* with a link: http://www.redmine.org
-and an email address foo@example.net

-EXPECTED + expected = <<~EXPECTED +

This is a sample *text* with a link: http://www.redmine.org
+ and an email address foo@example.net

+ EXPECTED - assert_equal expected.gsub(%r{[\r\n\t]}, ''), OpenProject::TextFormatting::Formats::Plain::Formatter.new({}).to_html(raw).gsub(%r{[\r\n\t]}, '') + assert_equal expected.gsub(%r{[\r\n\t]}, ''), + OpenProject::TextFormatting::Formats::Plain::Formatter.new({}).to_html(raw).gsub(%r{[\r\n\t]}, '') end describe 'options' do diff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rb index 18c143753c..f2d9aba0b4 100644 --- a/spec/lib/redmine/i18n_spec.rb +++ b/spec/lib/redmine/i18n_spec.rb @@ -46,30 +46,30 @@ module OpenProject end it 'returns a date in the user timezone for a utc timestamp' do Time.zone = 'UTC' - time = Time.zone.local(2013, 06, 30, 23, 59) + time = Time.zone.local(2013, 0o6, 30, 23, 59) expect(format_time_as_date(time, format)).to eq '01/07/2013' end it 'returns a date in the user timezone for a non-utc timestamp' do Time.zone = 'Berlin' - time = Time.zone.local(2013, 06, 30, 23, 59) + time = Time.zone.local(2013, 0o6, 30, 23, 59) expect(format_time_as_date(time, format)).to eq '01/07/2013' end end describe 'without user time zone' do - before do allow(User.current).to receive(:time_zone).and_return(nil) end + before { allow(User.current).to receive(:time_zone).and_return(nil) } it 'returns a date in the local system timezone for a utc timestamp' do Time.zone = 'UTC' - time = Time.zone.local(2013, 06, 30, 23, 59) - allow(time).to receive(:localtime).and_return(ActiveSupport::TimeZone['Athens'].local(2013, 07, 01, 01, 59)) + time = Time.zone.local(2013, 0o6, 30, 23, 59) + allow(time).to receive(:localtime).and_return(ActiveSupport::TimeZone['Athens'].local(2013, 0o7, 0o1, 0o1, 59)) expect(format_time_as_date(time, format)).to eq '01/07/2013' end it 'returns a date in the original timezone for a non-utc timestamp' do Time.zone = 'Berlin' - time = Time.zone.local(2013, 06, 30, 23, 59) + time = Time.zone.local(2013, 0o6, 30, 23, 59) expect(format_time_as_date(time, format)).to eq '30/06/2013' end end @@ -160,9 +160,9 @@ module OpenProject describe 'link_translation' do let(:locale) { :en } - let(:urls) { + let(:urls) do { url_1: 'http://openproject.com/foobar', url_2: '/baz' } - } + end before do allow(::I18n) @@ -176,7 +176,8 @@ module OpenProject expect(translated).to eq( "There is a link in this translation!" + - " Maybe even two?") + " Maybe even two?" + ) end context 'with locale' do @@ -186,7 +187,8 @@ module OpenProject expect(translated).to eq( "There is a link in this translation!" + - " Maybe even two?") + " Maybe even two?" + ) end end end diff --git a/spec/lib/redmine/unified_diff_spec.rb b/spec/lib/redmine/unified_diff_spec.rb index 01eb46f4ab..52e471f149 100644 --- a/spec/lib/redmine/unified_diff_spec.rb +++ b/spec/lib/redmine/unified_diff_spec.rb @@ -31,14 +31,14 @@ require 'spec_helper' module Redmine describe UnifiedDiff do before do - @diff = Redmine::UnifiedDiff.new(<<-DIFF ---- old.js Thu May 11 14:24:58 2014 -+++ new.js Thu May 11 14:25:02 2014 -@@ -0,0 +1,1 @@ -+ -@@ -1,2 +1,2 @@ --text text -+text modified + @diff = Redmine::UnifiedDiff.new(<<~DIFF + --- old.js Thu May 11 14:24:58 2014 + +++ new.js Thu May 11 14:25:02 2014 + @@ -0,0 +1,1 @@ + + + @@ -1,2 +1,2 @@ + -text text + +text modified DIFF ) end @@ -70,12 +70,12 @@ module Redmine Test 3 Test 4 DIFF - ) + ) end subject do [].tap do |lines| - diff.first.each_line { |_,l| lines << [l.html_line_left, l.html_line_right] } + diff.first.each_line { |_, l| lines << [l.html_line_left, l.html_line_right] } end end diff --git a/spec/lib/reminders/due_issues_reminder_spec.rb b/spec/lib/reminders/due_issues_reminder_spec.rb index 755abf5956..d317624226 100644 --- a/spec/lib/reminders/due_issues_reminder_spec.rb +++ b/spec/lib/reminders/due_issues_reminder_spec.rb @@ -99,7 +99,7 @@ describe OpenProject::Reminders::DueIssuesReminder do let(:user_ids) { [user.id] } it 'does notify' do expect(subject.notify_count).to eq 1 - expect(ActionMailer::Base.deliveries.count). to eq 1 + expect(ActionMailer::Base.deliveries.count).to eq 1 mail = ActionMailer::Base.deliveries.last expect(mail).to be_present diff --git a/spec/lib/tabular_form_builder_spec.rb b/spec/lib/tabular_form_builder_spec.rb index dc76fe8771..0a3dae0839 100644 --- a/spec/lib/tabular_form_builder_spec.rb +++ b/spec/lib/tabular_form_builder_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -35,10 +36,10 @@ describe TabularFormBuilder do let(:helper) { ActionView::Base.new(ActionView::LookupContext.new(''), {}, nil) } let(:resource) do FactoryBot.build(:user, - firstname: 'JJ', - lastname: 'Abrams', - login: 'lost', - mail: 'jj@lost-mail.com', + firstname: 'JJ', + lastname: 'Abrams', + login: 'lost', + mail: 'jj@lost-mail.com', failed_login_count: 45) end let(:builder) { TabularFormBuilder.new(:user, resource, helper, {}) } @@ -636,10 +637,10 @@ JJ Abrams context 'with ActiveModel and without specified label' do let(:resource) do FactoryBot.build_stubbed(:user, - firstname: 'JJ', - lastname: 'Abrams', - login: 'lost', - mail: 'jj@lost-mail.com', + firstname: 'JJ', + lastname: 'Abrams', + login: 'lost', + mail: 'jj@lost-mail.com', failed_login_count: 45) end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 7784139c2b..100aa56e88 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -508,9 +509,9 @@ describe UserMailer, type: :mailer do describe 'html mail' do let(:expected_translation) do - I18n.t(:done_ratio, scope: [:activerecord, - :attributes, - :work_package]) + I18n.t(:done_ratio, scope: %i[activerecord + attributes + work_package]) end let(:expected_prefix) { "
  • #{expected_translation}" } @@ -519,7 +520,9 @@ describe UserMailer, type: :mailer do end context 'changed done ratio' do - let(:expected) { "#{expected_prefix} changed from 40
    to 100" } + let(:expected) do + "#{expected_prefix} changed from 40
    to 100" + end before do allow(journal).to receive(:details).and_return('done_ratio' => [40, 100]) @@ -531,7 +534,9 @@ describe UserMailer, type: :mailer do end context 'new done ratio' do - let(:expected) { "#{expected_prefix} changed from 0
    to 100" } + let(:expected) do + "#{expected_prefix} changed from 0
    to 100" + end before do allow(journal).to receive(:details).and_return('done_ratio' => [nil, 100]) diff --git a/spec/models/activities/fetcher_integration_spec.rb b/spec/models/activities/fetcher_integration_spec.rb index 5d9dd25f4e..c154db4154 100644 --- a/spec/models/activities/fetcher_integration_spec.rb +++ b/spec/models/activities/fetcher_integration_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/models/announcement_spec.rb b/spec/models/announcement_spec.rb index 5e5d25f102..2d271db475 100644 --- a/spec/models/announcement_spec.rb +++ b/spec/models/announcement_spec.rb @@ -34,9 +34,9 @@ describe Announcement, type: :model do end describe 'WHEN the one announcement is active and today is before show_until' do - let!(:announcement) { + let!(:announcement) do FactoryBot.create(:active_announcement, show_until: Date.today + 14.days) - } + end it 'returns that announcement' do expect(Announcement.active_and_current).to eql announcement @@ -44,9 +44,9 @@ describe Announcement, type: :model do end describe 'WHEN the one announcement is active and today is after show_until' do - let!(:announcement) { + let!(:announcement) do FactoryBot.create(:active_announcement, show_until: Date.today - 14.days) - } + end it 'returns no announcement' do expect(Announcement.active_and_current).to be_nil @@ -54,9 +54,9 @@ describe Announcement, type: :model do end describe 'WHEN the one announcement is active and today equals show_until' do - let!(:announcement) { + let!(:announcement) do FactoryBot.create(:active_announcement, show_until: Date.today) - } + end it 'returns that announcement' do expect(Announcement.active_and_current).to eql announcement end @@ -72,25 +72,25 @@ describe Announcement, type: :model do end describe 'WHEN the announcement is active and today is before show_until' do - let(:announcement) { + let(:announcement) do FactoryBot.build(:active_announcement, show_until: Date.today + 14.days) - } + end it { expect(announcement.active_and_current?).to be_truthy } end describe 'WHEN the announcement is active and today is after show_until' do - let!(:announcement) { + let!(:announcement) do FactoryBot.create(:active_announcement, show_until: Date.today - 14.days) - } + end it { expect(announcement.active_and_current?).to be_falsey } end describe 'WHEN the announcement is active and today equals show_until' do - let!(:announcement) { + let!(:announcement) do FactoryBot.build(:active_announcement, show_until: Date.today) - } + end it { expect(announcement.active_and_current?).to be_truthy } end diff --git a/spec/models/color_spec.rb b/spec/models/color_spec.rb index fc84cebc23..828ff8cfd3 100644 --- a/spec/models/color_spec.rb +++ b/spec/models/color_spec.rb @@ -34,7 +34,7 @@ describe Color, type: :model do it 'can read planning_element_types w/ the help of the has_many association' do color = FactoryBot.create(:color) planning_element_type = FactoryBot.create(:type, - color_id: color.id) + color_id: color.id) color.reload @@ -45,7 +45,7 @@ describe Color, type: :model do it 'nullifies dependent planning_element_types' do color = FactoryBot.create(:color) planning_element_type = FactoryBot.create(:type, - color_id: color.id) + color_id: color.id) color.reload color.destroy @@ -57,10 +57,10 @@ describe Color, type: :model do end describe '- Validations ' do - let(:attributes) { - { name: 'Color No. 1', + let(:attributes) do + { name: 'Color No. 1', hexcode: '#FFFFFF' } - } + end describe 'name' do it 'is invalid w/o a name' do @@ -98,7 +98,7 @@ describe Color, type: :model do it 'is invalid w/ malformed hexcodes' do expect(Color.new(attributes.merge(hexcode: '0#FFFFFF'))).not_to be_valid expect(Color.new(attributes.merge(hexcode: '#FFFFFF0'))).not_to be_valid - expect(Color.new(attributes.merge(hexcode: 'white'))). not_to be_valid + expect(Color.new(attributes.merge(hexcode: 'white'))).not_to be_valid end it 'fixes some wrong formats of hexcode automatically' do @@ -120,7 +120,7 @@ describe Color, type: :model do end it 'is valid w/ proper hexcodes' do - expect(Color.new(attributes.merge(hexcode: '#FFFFFF'))). to be_valid + expect(Color.new(attributes.merge(hexcode: '#FFFFFF'))).to be_valid expect(Color.new(attributes.merge(hexcode: '#FF00FF'))).to be_valid end end diff --git a/spec/models/custom_actions/actions/custom_field_spec.rb b/spec/models/custom_actions/actions/custom_field_spec.rb index 3249c819a2..31bd0a0a30 100644 --- a/spec/models/custom_actions/actions/custom_field_spec.rb +++ b/spec/models/custom_actions/actions/custom_field_spec.rb @@ -31,14 +31,14 @@ require_relative '../shared_expectations' describe CustomActions::Actions::CustomField, type: :model do let(:list_custom_field) do FactoryBot.build_stubbed(:list_wp_custom_field, - custom_options: [FactoryBot.build_stubbed(:custom_option, value: 'A'), - FactoryBot.build_stubbed(:custom_option, value: 'B')]) + custom_options: [FactoryBot.build_stubbed(:custom_option, value: 'A'), + FactoryBot.build_stubbed(:custom_option, value: 'B')]) end let(:list_multi_custom_field) do FactoryBot.build_stubbed(:list_wp_custom_field, - custom_options: [FactoryBot.build_stubbed(:custom_option, value: 'A'), - FactoryBot.build_stubbed(:custom_option, value: 'B')], - multi_value: true) + custom_options: [FactoryBot.build_stubbed(:custom_option, value: 'A'), + FactoryBot.build_stubbed(:custom_option, value: 'B')], + multi_value: true) end let(:version_custom_field) do FactoryBot.build_stubbed(:version_wp_custom_field) @@ -529,7 +529,6 @@ describe CustomActions::Actions::CustomField, type: :model do string date list_multi].each do |type| - let(:custom_field) { send(:"#{type}_custom_field") } it "sets the value for #{type} custom fields" do diff --git a/spec/models/custom_actions/actions/responsible_spec.rb b/spec/models/custom_actions/actions/responsible_spec.rb index 3c1b85729c..db4fe684cd 100644 --- a/spec/models/custom_actions/actions/responsible_spec.rb +++ b/spec/models/custom_actions/actions/responsible_spec.rb @@ -33,7 +33,7 @@ describe CustomActions::Actions::Responsible, type: :model do let(:type) { :associated_property } let(:allowed_values) do principals = [FactoryBot.build_stubbed(:user), - FactoryBot.build_stubbed(:group)] + FactoryBot.build_stubbed(:group)] allow(User) .to receive_message_chain(:not_locked, :select, :ordered_by_name) diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index 85a7fbfea1..3260327752 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -139,7 +139,6 @@ describe CustomField, type: :model do describe "WITH a text field WITH an invalid regexp" do - before do field.field_format = 'text' field.regexp = '[0-9}' diff --git a/spec/models/custom_value/format_strategy_spec.rb b/spec/models/custom_value/format_strategy_spec.rb index ea6863e191..9f99e1b8b7 100644 --- a/spec/models/custom_value/format_strategy_spec.rb +++ b/spec/models/custom_value/format_strategy_spec.rb @@ -29,10 +29,10 @@ require 'spec_helper' describe CustomValue::FormatStrategy do - let(:custom_value) { + let(:custom_value) do double('CustomValue', value: value) - } + end describe '#value_present?' do subject { described_class.new(custom_value).value_present? } diff --git a/spec/models/custom_value/list_strategy_integration_spec.rb b/spec/models/custom_value/list_strategy_integration_spec.rb index 19d1ac9778..8155e2d748 100644 --- a/spec/models/custom_value/list_strategy_integration_spec.rb +++ b/spec/models/custom_value/list_strategy_integration_spec.rb @@ -42,12 +42,12 @@ describe CustomValue::ListStrategy, 'integration tests' do ) end - let!(:work_package) { + let!(:work_package) do FactoryBot.create :work_package, project: project, type: type, custom_values: { custom_field.id => custom_field.custom_options.find_by(value: 'A') } - } + end it 'can handle invalid CustomOptions (Regression test)' do expect(work_package.public_send(:"custom_field_#{custom_field.id}")).to eq(%w(A)) diff --git a/spec/models/custom_value_spec.rb b/spec/models/custom_value_spec.rb index 482da5990f..fc1a601b29 100644 --- a/spec/models/custom_value_spec.rb +++ b/spec/models/custom_value_spec.rb @@ -86,7 +86,7 @@ describe CustomValue do describe 'date custom value' do let(:format) { 'date' } - let(:value) { Date.new(2016,12,1) } + let(:value) { Date.new(2016, 12, 1) } it { expect(subject.typed_value).to eql(value) } diff --git a/spec/models/enabled_module_spec.rb b/spec/models/enabled_module_spec.rb index e38d742ffc..d578675b2e 100644 --- a/spec/models/enabled_module_spec.rb +++ b/spec/models/enabled_module_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -44,14 +45,14 @@ describe EnabledModule, type: :model do it 'should not create a separate wiki when one exists already' do expect(project.wiki).to_not be_nil - expect { + expect do project.enabled_module_names = [] project.reload - }.to_not change { Wiki.count } + end.to_not change { Wiki.count } - expect { + expect do project.enabled_module_names = ['wiki'] - }.to_not change { Wiki.count } + end.to_not change { Wiki.count } expect(project.wiki).to_not be_nil end @@ -87,14 +88,14 @@ describe EnabledModule, type: :model do project.reload expect(project.repository).to_not be_nil - expect { + expect do project.enabled_module_names = [] project.reload - }.to_not change { Repository.count } + end.to_not change { Repository.count } - expect { + expect do project.enabled_module_names = ['repository'] - }.to_not change { Repository.count } + end.to_not change { Repository.count } expect(project.repository).to_not be_nil end @@ -114,11 +115,11 @@ describe EnabledModule, type: :model do let(:vendor) { 'git' } include_context 'with tmpdir' - let(:config) { + let(:config) do { git: { manages: File.join(tmpdir, 'git') } } - } + end before do allow(Setting).to receive(:enabled_scm).and_return(['git']) diff --git a/spec/models/global_role_spec.rb b/spec/models/global_role_spec.rb index 162d055e5a..acfe39ea20 100644 --- a/spec/models/global_role_spec.rb +++ b/spec/models/global_role_spec.rb @@ -76,7 +76,7 @@ describe GlobalRole, type: :model do end describe 'WITH set permissions' do - before { @role = GlobalRole.new permissions: [:perm1, :perm2, :perm3] } + before { @role = GlobalRole.new permissions: %i[perm1 perm2 perm3] } describe '#has_permission?' do it { expect(@role.has_permission?(:perm1)).to be_truthy } diff --git a/spec/models/group_performance_spec.rb b/spec/models/group_performance_spec.rb index 32c365b552..695814e5b8 100644 --- a/spec/models/group_performance_spec.rb +++ b/spec/models/group_performance_spec.rb @@ -54,7 +54,8 @@ describe Group, type: :model do type: project.types.first, author: user, project: project, - status: status) + status: status + ) work_packages.first.tap do |wp| wp.assigned_to = group diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index f27eb5448d..bff8486259 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -39,9 +39,9 @@ describe Group, type: :model do let(:status) { FactoryBot.create(:status) } let(:package) do FactoryBot.build(:work_package, type: project.types.first, - author: user, - project: project, - status: status) + author: user, + project: project, + status: status) end it 'should create' do @@ -79,7 +79,6 @@ describe Group, type: :model do let!(:member) { FactoryBot.create :member, project: project, principal: group, role_ids: role_ids } let!(:group) { FactoryBot.create(:group, members: user) } - it 'should roles removed when removing group membership' do expect(user).to be_member_of project member.destroy @@ -101,7 +100,7 @@ describe Group, type: :model do member = FactoryBot.build :member roles = FactoryBot.create_list :role, 2 role_ids = roles.map(&:id) - member.attributes = {principal: group, role_ids: role_ids} + member.attributes = { principal: group, role_ids: role_ids } member.save! member.role_ids = [role_ids.first] @@ -184,7 +183,6 @@ describe Group, type: :model do build_preference create_preference create_preference!}.each do |method| - it "should not respond to #{method}" do expect(group).to_not respond_to method end diff --git a/spec/models/issue_priority_spec.rb b/spec/models/issue_priority_spec.rb index 09e6192bdc..cb52ec4b49 100644 --- a/spec/models/issue_priority_spec.rb +++ b/spec/models/issue_priority_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/models/journal/aggregated_journal_spec.rb b/spec/models/journal/aggregated_journal_spec.rb index 0ed4ee6d65..9c7547c723 100644 --- a/spec/models/journal/aggregated_journal_spec.rb +++ b/spec/models/journal/aggregated_journal_spec.rb @@ -31,7 +31,7 @@ require 'spec_helper' RSpec::Matchers.define :be_equivalent_to_journal do |expected| - ignored_attributes = [:notes_id, :notes_version] + ignored_attributes = %i[notes_id notes_version] match do |actual| expected_attributes = get_normalized_attributes expected @@ -130,10 +130,10 @@ describe Journal::AggregatedJournal, type: :model do end it 'returns the single journal for both original journals' do - expect(described_class.containing_journal work_package.journals.first) + expect(described_class.containing_journal(work_package.journals.first)) .to be_equivalent_to_journal subject.first - expect(described_class.containing_journal work_package.journals.second) + expect(described_class.containing_journal(work_package.journals.second)) .to be_equivalent_to_journal subject.first end @@ -173,15 +173,15 @@ describe Journal::AggregatedJournal, type: :model do end it 'returns the same aggregated journal for the first two originals' do - expect(described_class.containing_journal work_package.journals.first) + expect(described_class.containing_journal(work_package.journals.first)) .to be_equivalent_to_journal subject.first - expect(described_class.containing_journal work_package.journals.second) + expect(described_class.containing_journal(work_package.journals.second)) .to be_equivalent_to_journal subject.first end it 'returns a different aggregated journal for the last original' do - expect(described_class.containing_journal work_package.journals.last) + expect(described_class.containing_journal(work_package.journals.last)) .to be_equivalent_to_journal subject.second end end diff --git a/spec/models/ldap_auth_source_spec.rb b/spec/models/ldap_auth_source_spec.rb index 4879c0955a..720614661c 100644 --- a/spec/models/ldap_auth_source_spec.rb +++ b/spec/models/ldap_auth_source_spec.rb @@ -30,7 +30,8 @@ require 'spec_helper' describe LdapAuthSource, type: :model do it 'should create' do - a = LdapAuthSource.new(name: 'My LDAP', host: 'ldap.example.net', port: 389, base_dn: 'dc=example,dc=net', attr_login: 'sAMAccountName') + a = LdapAuthSource.new(name: 'My LDAP', host: 'ldap.example.net', port: 389, base_dn: 'dc=example,dc=net', + attr_login: 'sAMAccountName') expect(a.save).to eq true end @@ -57,7 +58,8 @@ describe LdapAuthSource, type: :model do describe 'with live LDAP' do before(:all) do ldif = Rails.root.join('spec/fixtures/ldap/users.ldif') - @ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com', ldif: ldif).start + @ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com', + ldif: ldif).start end after(:all) do @@ -67,7 +69,7 @@ describe LdapAuthSource, type: :model do # Ldap has three users aa729, bb459, cc414 let(:ldap) do FactoryBot.create :ldap_auth_source, - port: ParallelHelper.port_for_ldap.to_s, + port: ParallelHelper.port_for_ldap.to_s, account: 'uid=admin,ou=system', account_password: 'secret', base_dn: 'ou=people,dc=example,dc=com', diff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rb index 1f4f5608b2..f0e6d841d9 100644 --- a/spec/models/mail_handler_spec.rb +++ b/spec/models/mail_handler_spec.rb @@ -28,7 +28,8 @@ require 'spec_helper' -DEVELOPER_PERMISSIONS = [:view_messages, :delete_own_messages, :edit_own_messages, :add_project, :edit_project, :select_project_modules, :manage_members, :manage_versions, :manage_categories, :view_work_packages, :add_work_packages, :edit_work_packages, :manage_work_package_relations, :manage_subtasks, :add_work_package_notes, :move_work_packages, :delete_work_packages, :view_work_package_watchers, :add_work_package_watchers, :delete_work_package_watchers, :manage_public_queries, :save_queries, :view_gantt, :view_calendar, :log_time, :view_time_entries, :edit_time_entries, :delete_time_entries, :manage_news, :comment_news, :view_documents, :manage_documents, :view_wiki_pages, :export_wiki_pages, :view_wiki_edits, :edit_wiki_pages, :delete_wiki_pages_attachments, :protect_wiki_pages, :delete_wiki_pages, :rename_wiki_pages, :add_messages, :edit_messages, :delete_messages, :manage_forums, :view_files, :manage_files, :browse_repository, :manage_repository, :view_changesets, :manage_project_activities, :export_work_packages] +DEVELOPER_PERMISSIONS = %i[view_messages delete_own_messages edit_own_messages add_project edit_project + select_project_modules manage_members manage_versions manage_categories view_work_packages add_work_packages edit_work_packages manage_work_package_relations manage_subtasks add_work_package_notes move_work_packages delete_work_packages view_work_package_watchers add_work_package_watchers delete_work_package_watchers manage_public_queries save_queries view_gantt view_calendar log_time view_time_entries edit_time_entries delete_time_entries manage_news comment_news view_documents manage_documents view_wiki_pages export_wiki_pages view_wiki_edits edit_wiki_pages delete_wiki_pages_attachments protect_wiki_pages delete_wiki_pages rename_wiki_pages add_messages edit_messages delete_messages manage_forums view_files manage_files browse_repository manage_repository view_changesets manage_project_activities export_work_packages] describe MailHandler, type: :model do let(:anno_user) { User.anonymous } @@ -76,7 +77,7 @@ describe MailHandler, type: :model do member_in_project: project, member_with_permissions: permissions) end - let(:submit_options) { {allow_override: 'version'} } + let(:submit_options) { { allow_override: 'version' } } subject do submit_email('wp_on_given_project_case_insensitive.eml', **submit_options) @@ -254,7 +255,7 @@ describe MailHandler, type: :model do end include_context 'wp_on_given_project' do - let(:submit_options) { {issue: {type: default_type.name}} } + let(:submit_options) { { issue: { type: default_type.name } } } end it_behaves_like 'work package created' @@ -270,7 +271,7 @@ describe MailHandler, type: :model do Role.non_member.update_attribute :permissions, [:add_work_packages] project.update_attribute :public, true expect do - work_package = submit_email('ticket_by_unknown_user.eml', issue: {project: 'onlinestore'}, unknown_user: 'create') + work_package = submit_email('ticket_by_unknown_user.eml', issue: { project: 'onlinestore' }, unknown_user: 'create') work_package_created(work_package) expect(work_package.author.active?).to be_truthy expect(work_package.author.mail).to eq('john.doe@somenet.foo') @@ -323,14 +324,14 @@ describe MailHandler, type: :model do end end - context 'email from emission address', with_settings: {mail_from: 'openproject@example.net'} do + context 'email from emission address', with_settings: { mail_from: 'openproject@example.net' } do before do Role.non_member.add_permission!(:add_work_packages) end subject do submit_email('ticket_from_emission_address.eml', - issue: {project: public_project.identifier}, + issue: { project: public_project.identifier }, unknown_user: 'create') end @@ -394,7 +395,7 @@ describe MailHandler, type: :model do expect(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package) # Mail with two attachemnts, one of which is skipped by signature.asc filename match - submit_email 'update_ticket_with_attachment_and_sig.eml', issue: {project: 'onlinestore'} + submit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' } work_package.reload @@ -415,7 +416,7 @@ describe MailHandler, type: :model do expect(WorkPackage).to receive(:find_by).with(id: 123).and_return(work_package) # Mail with two attachemnts, one of which is skipped by signature.asc filename match - submit_email 'update_ticket_with_attachment_and_sig.eml', issue: {project: 'onlinestore'} + submit_email 'update_ticket_with_attachment_and_sig.eml', issue: { project: 'onlinestore' } expect(work_package.attachments.length).to eq 2 end @@ -439,7 +440,7 @@ describe MailHandler, type: :model do let(:custom_field) { FactoryBot.create :text_wp_custom_field, name: "Notes" } before do - submit_email 'work_package_with_text_custom_field.eml', issue: {project: project.identifier} + submit_email 'work_package_with_text_custom_field.eml', issue: { project: project.identifier } work_package.reload end @@ -455,7 +456,7 @@ describe MailHandler, type: :model do let(:custom_field) { FactoryBot.create :list_wp_custom_field, name: "Letters", possible_values: %w(A B C) } before do - submit_email 'work_package_with_list_custom_field.eml', issue: {project: project.identifier} + submit_email 'work_package_with_list_custom_field.eml', issue: { project: project.identifier } work_package.reload end @@ -471,7 +472,7 @@ describe MailHandler, type: :model do end context 'truncate emails based on the Setting' do - context 'with no setting', with_settings: {mail_handler_body_delimiters: ''} do + context 'with no setting', with_settings: { mail_handler_body_delimiters: '' } do include_context 'wp_on_given_project' it_behaves_like 'work package created' @@ -485,7 +486,7 @@ describe MailHandler, type: :model do end end - context 'with a single string', with_settings: {mail_handler_body_delimiters: '---'} do + context 'with a single string', with_settings: { mail_handler_body_delimiters: '---' } do include_context 'wp_on_given_project' it_behaves_like 'work package created' @@ -506,7 +507,7 @@ describe MailHandler, type: :model do end context 'with a single quoted reply (e.g. reply to a OpenProject email notification)', - with_settings: {mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---'} do + with_settings: { mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---' } do include_context 'wp_update_with_quoted_reply_above' it_behaves_like 'journal created' @@ -524,7 +525,7 @@ describe MailHandler, type: :model do end context 'with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)', - with_settings: {mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---'} do + with_settings: { mail_handler_body_delimiters: '--- Reply above. Do not remove this line. ---' } do include_context 'wp_update_with_quoted_reply_above' it_behaves_like 'journal created' @@ -542,7 +543,7 @@ describe MailHandler, type: :model do end context 'with multiple strings', - with_settings: {mail_handler_body_delimiters: "---\nBREAK"} do + with_settings: { mail_handler_body_delimiters: "---\nBREAK" } do include_context 'wp_on_given_project' it_behaves_like 'work package created' @@ -575,7 +576,7 @@ describe MailHandler, type: :model do project.update_attribute :public, true work_package = submit_email 'ticket_with_category.eml', - issue: {project: 'onlinestore'}, + issue: { project: 'onlinestore' }, allow_override: ['category'], unknown_user: 'create' work_package_created(work_package) diff --git a/spec/models/menu_items/query_menu_item_spec.rb b/spec/models/menu_items/query_menu_item_spec.rb index 3546a8eabc..874c0c2df0 100644 --- a/spec/models/menu_items/query_menu_item_spec.rb +++ b/spec/models/menu_items/query_menu_item_spec.rb @@ -36,13 +36,13 @@ describe MenuItems::QueryMenuItem, type: :model do describe 'it should destroy all items when destroying' do before(:each) do query_item = FactoryBot.create(:query_menu_item, - query: query, - name: 'Query Item', - title: 'Query Item') + query: query, + name: 'Query Item', + title: 'Query Item') another_query_item = FactoryBot.create(:query_menu_item, - query: another_query, - name: 'Another Query Item', - title: 'Another Query Item') + query: another_query, + name: 'Another Query Item', + title: 'Another Query Item') end it 'the associated query' do diff --git a/spec/models/menu_items/wiki_menu_item_spec.rb b/spec/models/menu_items/wiki_menu_item_spec.rb index a1486fbf65..568f25cd3a 100644 --- a/spec/models/menu_items/wiki_menu_item_spec.rb +++ b/spec/models/menu_items/wiki_menu_item_spec.rb @@ -54,8 +54,8 @@ describe MenuItems::WikiMenuItem, type: :model do wikipage = FactoryBot.create(:wiki_page, title: 'Oldtitle') menu_item_1 = FactoryBot.create(:wiki_menu_item, navigatable_id: wikipage.wiki.id, - title: 'Item 1', - name: wikipage.slug) + title: 'Item 1', + name: wikipage.slug) wikipage.title = 'Newtitle' wikipage.save! @@ -68,7 +68,8 @@ describe MenuItems::WikiMenuItem, type: :model do wikipage = FactoryBot.create(:wiki_page, title: 'Parent Page') parent = FactoryBot.create( - :wiki_menu_item, navigatable_id: wikipage.wiki.id, title: 'Item 1', name: wikipage.slug) + :wiki_menu_item, navigatable_id: wikipage.wiki.id, title: 'Item 1', name: wikipage.slug + ) child_1 = parent.children.create name: "child-1", title: "Child 1" child_2 = parent.children.build name: "child-1", title: "Child 2" @@ -82,13 +83,13 @@ describe MenuItems::WikiMenuItem, type: :model do @project.reload @menu_item_1 = FactoryBot.create(:wiki_menu_item, wiki: @project.wiki, - name: 'Item 1', - title: 'Item 1') + name: 'Item 1', + title: 'Item 1') @menu_item_2 = FactoryBot.create(:wiki_menu_item, wiki: @project.wiki, - name: 'Item 2', - parent_id: @menu_item_1.id, - title: 'Item 2') + name: 'Item 2', + parent_id: @menu_item_1.id, + title: 'Item 2') end it 'all children when deleting the parent' do diff --git a/spec/models/messages_spec.rb b/spec/models/messages_spec.rb index abf88a7513..a050771a97 100644 --- a/spec/models/messages_spec.rb +++ b/spec/models/messages_spec.rb @@ -102,7 +102,7 @@ describe Message, type: :model do let!(:message) { FactoryBot.create :message, forum: forum1 } it 'should moving message should update counters' do - expect { + expect do forum1.reload expect(forum1.topics_count).to eq 1 expect(forum1.messages_count).to eq 1 @@ -115,7 +115,7 @@ describe Message, type: :model do expect(forum2.reload.topics_count).to eq 1 expect(forum1.messages_count).to eq 0 expect(forum2.messages_count).to eq 1 - }.not_to change { Message.count } + end.not_to change { Message.count } end end @@ -134,7 +134,6 @@ describe Message, type: :model do expect(message.sticky).to eq 1 end - describe 'with reply set' do let!(:reply) do FactoryBot.create :message, forum: message.forum, parent: message diff --git a/spec/models/news_spec.rb b/spec/models/news_spec.rb index 815329745a..bd19f2286c 100644 --- a/spec/models/news_spec.rb +++ b/spec/models/news_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,18 +28,18 @@ # See docs/COPYRIGHT.rdoc for more details. #++ require 'spec_helper' -require File.expand_path('../../support/shared/become_member', __FILE__) +require File.expand_path('../support/shared/become_member', __dir__) require 'support/shared/acts_as_watchable' describe News, type: :model do include BecomeMember - let(:project) { + let(:project) do project = FactoryBot.create(:public_project) project.enabled_modules << EnabledModule.new(name: 'news') project.reload - } + end let!(:news) { FactoryBot.create(:news, project: project) } let(:permissions) { [] } diff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rb index f991ea0081..e3054ef52a 100644 --- a/spec/models/permitted_params_spec.rb +++ b/spec/models/permitted_params_spec.rb @@ -507,15 +507,15 @@ describe PermittedParams, type: :model do subject { PermittedParams.new(params, user).send(attribute, external_authentication, change_password_allowed).to_h } all_permissions = ['admin', - 'login', - 'firstname', - 'lastname', - 'mail', - 'mail_notification', - 'language', - 'custom_fields', - 'auth_source_id', - 'force_password_change'] + 'login', + 'firstname', + 'lastname', + 'mail', + 'mail_notification', + 'language', + 'custom_fields', + 'auth_source_id', + 'force_password_change'] describe :user_create_as_admin do let(:attribute) { :user_create_as_admin } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 86140f3c09..be353a8eff 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require File.expand_path('../../support/shared/become_member', __FILE__) +require File.expand_path('../support/shared/become_member', __dir__) describe Project, type: :model do include BecomeMember @@ -141,7 +141,7 @@ describe Project, type: :model do end describe 'name' do - let(:project) { FactoryBot.build_stubbed :project, name: ' Hello World '} + let(:project) { FactoryBot.build_stubbed :project, name: ' Hello World ' } before do project.valid? diff --git a/spec/models/projects/allowed_to_scope_spec.rb b/spec/models/projects/allowed_to_scope_spec.rb index f4a4f6f78c..9f76f544e6 100644 --- a/spec/models/projects/allowed_to_scope_spec.rb +++ b/spec/models/projects/allowed_to_scope_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -334,14 +335,14 @@ describe Project, 'allowed to', type: :model do context 'w/ the non member role having the permission w/o the project being active' do - let(:project_status) { false} + let(:project_status) { false } it_behaves_like 'is empty' end context 'w/ the permission being public and not module bound w/o the project being active' do - let(:project_status) { false} + let(:project_status) { false } it 'is empty' do expect(Project.allowed_to(user, public_non_module_action)).to be_empty diff --git a/spec/models/projects/customizable_spec.rb b/spec/models/projects/customizable_spec.rb index c5d5ac3b17..2c3de7fc7b 100644 --- a/spec/models/projects/customizable_spec.rb +++ b/spec/models/projects/customizable_spec.rb @@ -31,7 +31,7 @@ require 'spec_helper' describe Project, 'customizable', type: :model do let(:project) do FactoryBot.build_stubbed(:project, - custom_values: custom_values) + custom_values: custom_values) end let(:stub_available_custom_fields) do custom_fields_stub = double('custom fields stub') @@ -81,8 +81,8 @@ describe Project, 'customizable', type: :model do context 'with a value set' do let(:custom_value) do FactoryBot.build_stubbed(:custom_value, - custom_field: custom_field, - value: true) + custom_field: custom_field, + value: true) end let(:custom_values) { [custom_value] } @@ -98,13 +98,13 @@ describe Project, 'customizable', type: :model do let(:available_custom_fields) { [bool_custom_field, list_custom_field, text_custom_field] } let(:text_custom_value) do FactoryBot.build_stubbed(:custom_value, - custom_field: text_custom_field, - value: 'blubs') + custom_field: text_custom_field, + value: 'blubs') end let(:bool_custom_value) do FactoryBot.build_stubbed(:custom_value, - custom_field: bool_custom_field, - value: true) + custom_field: bool_custom_field, + value: true) end let(:custom_values) { [bool_custom_value, text_custom_value] } diff --git a/spec/models/projects/scopes/activated_time_activity_spec.rb b/spec/models/projects/scopes/activated_time_activity_spec.rb index 0ff08c874e..22686f308f 100644 --- a/spec/models/projects/scopes/activated_time_activity_spec.rb +++ b/spec/models/projects/scopes/activated_time_activity_spec.rb @@ -60,8 +60,8 @@ describe Projects::Scopes::ActivatedTimeActivity, type: :model do context 'with project specific overrides' do before do - TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: project.id, active: true } ) - TimeEntryActivitiesProject.insert( { activity_id: activity.id, project_id: other_project.id, active: false } ) + TimeEntryActivitiesProject.insert({ activity_id: activity.id, project_id: project.id, active: true }) + TimeEntryActivitiesProject.insert({ activity_id: activity.id, project_id: other_project.id, active: false }) end context 'and being active' do diff --git a/spec/models/projects/storage_spec.rb b/spec/models/projects/storage_spec.rb index 9cc60bb33b..3a9f3892b0 100644 --- a/spec/models/projects/storage_spec.rb +++ b/spec/models/projects/storage_spec.rb @@ -29,10 +29,10 @@ require 'spec_helper' describe Projects::Storage, type: :model do - let(:project1) { + let(:project1) do FactoryBot.create(:project) .reload # Reload required for wiki association to be available - } + end let(:project2) { FactoryBot.create(:project) } before do @@ -51,7 +51,6 @@ describe Projects::Storage, type: :model do describe '#with_required_storage' do it 'counts projects correctly' do - # TODO Using storage.find(project1.id) here causes work_package_required_space # to be nil or "2500" (Postgres only) occasionally with no definitive solution found. # The returned "2500" were pre-Rails4 behavior, thus this might be a Rails bug. diff --git a/spec/models/queries/work_packages/filter/estimated_hours_filter_spec.rb b/spec/models/queries/work_packages/filter/estimated_hours_filter_spec.rb index 51efd76187..c381db99d7 100644 --- a/spec/models/queries/work_packages/filter/estimated_hours_filter_spec.rb +++ b/spec/models/queries/work_packages/filter/estimated_hours_filter_spec.rb @@ -48,9 +48,9 @@ describe Queries::WorkPackages::Filter::EstimatedHoursFilter, type: :model do it_behaves_like 'non ar filter' describe '#where' do - let!(:work_package_zero_hour) {FactoryBot.create(:work_package, estimated_hours: 0)} - let!(:work_package_no_hours) {FactoryBot.create(:work_package, estimated_hours: nil)} - let!(:work_package_with_hours) {FactoryBot.create(:work_package, estimated_hours: 1)} + let!(:work_package_zero_hour) { FactoryBot.create(:work_package, estimated_hours: 0) } + let!(:work_package_no_hours) { FactoryBot.create(:work_package, estimated_hours: nil) } + let!(:work_package_with_hours) { FactoryBot.create(:work_package, estimated_hours: 1) } context 'with the operator being "none"' do before do @@ -62,5 +62,4 @@ describe Queries::WorkPackages::Filter::EstimatedHoursFilter, type: :model do end end end - end diff --git a/spec/models/query/results_cf_sorting_integration_spec.rb b/spec/models/query/results_cf_sorting_integration_spec.rb index d4828d2958..4c59bd8e8a 100644 --- a/spec/models/query/results_cf_sorting_integration_spec.rb +++ b/spec/models/query/results_cf_sorting_integration_spec.rb @@ -50,7 +50,7 @@ describe ::Query::Results, 'Sorting of custom field floats', type: :model, with_ FactoryBot.create :work_package, type: type, project: project, - custom_values: {custom_field.id => "6.25"} + custom_values: { custom_field.id => "6.25" } end let(:work_package_without_float) do diff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rb index c8078520f9..70a59a6ccb 100644 --- a/spec/models/query_spec.rb +++ b/spec/models/query_spec.rb @@ -651,7 +651,6 @@ describe Query, type: :model do end end - describe 'project limiting filter' do def subproject_filter?(filter) filter.is_a?(Queries::WorkPackages::Filter::SubprojectFilter) diff --git a/spec/models/repository/git_spec.rb b/spec/models/repository/git_spec.rb index 9083a1e034..b06684e743 100644 --- a/spec/models/repository/git_spec.rb +++ b/spec/models/repository/git_spec.rb @@ -55,7 +55,7 @@ describe Repository::Git, type: :model do end context 'with disabled types' do - let(:config) { { disabled_types: [:local, :managed] } } + let(:config) { { disabled_types: %i[local managed] } } it 'does not have any types' do expect(instance.class.available_types).to be_empty @@ -84,7 +84,7 @@ describe Repository::Git, type: :model do it 'is manageable' do expect(instance.manageable?).to be true - expect(instance.class.available_types).to eq([:local, :managed]) + expect(instance.class.available_types).to eq(%i[local managed]) end context 'with disabled managed typed' do @@ -107,7 +107,7 @@ describe Repository::Git, type: :model do it 'is no longer manageable' do expect(instance.class.available_types).to eq([]) - expect(instance.class.disabled_types).to eq([:managed, :local]) + expect(instance.class.disabled_types).to eq(%i[managed local]) expect(instance.manageable?).to be false end end @@ -178,12 +178,12 @@ describe Repository::Git, type: :model do describe 'with an actual repository' do with_git_repository do |repo_dir| let(:url) { repo_dir } - let(:instance) { + let(:instance) do FactoryBot.create(:repository_git, - path_encoding: encoding, - url: url, - root_url: url) - } + path_encoding: encoding, + url: url, + root_url: url) + end before do instance.fetch_changesets @@ -226,7 +226,7 @@ describe Repository::Git, type: :model do it 'should fetch changesets from scratch' do expect(instance.changesets.count).to eq(22) # This test fails on macs since they count file changes to be 33, *nix system count 34 - expect(instance.file_changes.count).to be_between(33,34) + expect(instance.file_changes.count).to be_between(33, 34) commit = instance.changesets.reorder(Arel.sql('committed_on ASC')).first expect(commit.comments).to eq("Initial import.\nThe repository contains 3 files.") @@ -239,7 +239,7 @@ describe Repository::Git, type: :model do expect(commit.scmid).to eq('7234cb2750b63f47bff735edc50a1c0a433c2518') expect(commit.file_changes.count).to eq(3) - change = commit.file_changes.sort_by(&:path).first + change = commit.file_changes.min_by(&:path) expect(change.path).to eq('README') expect(change.action).to eq('A') end @@ -444,21 +444,23 @@ describe Repository::Git, type: :model do instance.fetch_changesets instance.reload changesets = instance.latest_changesets( - "latin-1-dir/test-#{char1_hex}-subdir", '1ca7f5ed') + "latin-1-dir/test-#{char1_hex}-subdir", '1ca7f5ed' + ) expect(changesets.map(&:revision)) .to eq(['1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127']) end it 'should browse changesets' do changesets = instance.latest_changesets( - "latin-1-dir/test-#{char1_hex}-2.txt", '64f1f3e89') + "latin-1-dir/test-#{char1_hex}-2.txt", '64f1f3e89' + ) expect(changesets.map(&:revision)) .to eq(['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', - '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', - ]) + '4fc55c43bf3d3dc2efb66145365ddc17639ce81e']) changesets = instance.latest_changesets( - "latin-1-dir/test-#{char1_hex}-2.txt", '64f1f3e89', 1) + "latin-1-dir/test-#{char1_hex}-2.txt", '64f1f3e89', 1 + ) expect(changesets.map(&:revision)) .to eq(['64f1f3e89ad1cb57976ff0ad99a107012ba3481d']) end @@ -468,7 +470,6 @@ describe Repository::Git, type: :model do it_behaves_like 'is a countable repository' do let(:repository) { instance } end - end end diff --git a/spec/models/repository/subversion_spec.rb b/spec/models/repository/subversion_spec.rb index ef07c5356c..8dc2c30f45 100644 --- a/spec/models/repository/subversion_spec.rb +++ b/spec/models/repository/subversion_spec.rb @@ -63,7 +63,7 @@ describe Repository::Subversion, type: :model do end context 'with disabled types' do - let(:config) { { disabled_types: [:existing, :managed] } } + let(:config) { { disabled_types: %i[existing managed] } } it 'does not have any types' do expect(instance.class.available_types).to be_empty @@ -89,7 +89,7 @@ describe Repository::Subversion, type: :model do it 'is no longer manageable' do expect(instance.class.available_types).to eq([:existing]) - expect(instance.class.disabled_types).to eq([:managed, :unknowntype]) + expect(instance.class.disabled_types).to eq(%i[managed unknowntype]) expect(instance.manageable?).to be false end end @@ -107,7 +107,7 @@ describe Repository::Subversion, type: :model do it 'is manageable' do expect(instance.manageable?).to be true - expect(instance.class.available_types).to eq([:existing, :managed]) + expect(instance.class.available_types).to eq(%i[existing managed]) end context 'with disabled managed typed' do @@ -148,11 +148,10 @@ describe Repository::Subversion, type: :model do end describe 'with a remote repository' do - let(:instance) { + let(:instance) do FactoryBot.build(:repository_subversion, - url: 'https://somewhere.example.org/svn/foo' - ) - } + url: 'https://somewhere.example.org/svn/foo') + end it_behaves_like 'is not a countable repository' do let(:repository) { instance } @@ -181,7 +180,7 @@ describe Repository::Subversion, type: :model do instance.fetch_changesets # Remove changesets with revision > 5 - instance.changesets.each do |c| c.destroy if c.revision.to_i > 5 end + instance.changesets.each { |c| c.destroy if c.revision.to_i > 5 } instance.reload expect(instance.changesets.count).to eq(5) @@ -278,8 +277,8 @@ describe Repository::Subversion, type: :model do assert_equal s1.encode('UTF-8'), s2 end c = Changeset.new(repository: instance, - comments: s2, - revision: '123', + comments: s2, + revision: '123', committed_on: Time.now) expect(c.save).to be true expect(c.comments).to eq(s2) diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb index 06646c6803..9ffe51befd 100644 --- a/spec/models/role_spec.rb +++ b/spec/models/role_spec.rb @@ -29,7 +29,7 @@ require 'spec_helper' describe Role, type: :model do - let(:permissions) { [:permission1, :permission2] } + let(:permissions) { %i[permission1 permission2] } let(:build_role) { FactoryBot.build(:role, permissions: permissions) } let(:created_role) { FactoryBot.create(:role, permissions: permissions) } diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 3631ba803e..7c8f5438aa 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -220,9 +221,9 @@ describe Setting, type: :model do end context 'cache is not empty' do - let(:cached_hash) { + let(:cached_hash) do { 'available_languages' => "---\n- en\n- de\n" } - } + end before do Rails.cache.write(cache_key, cached_hash) diff --git a/spec/models/system_user_spec.rb b/spec/models/system_user_spec.rb index 37a966b0d8..2fd16d38fc 100644 --- a/spec/models/system_user_spec.rb +++ b/spec/models/system_user_spec.rb @@ -59,18 +59,18 @@ describe SystemUser, type: :model do let(:project) { FactoryBot.create(:project_with_types, public: false) } let(:user) { FactoryBot.build(:user) } let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) } - let(:member) { + let(:member) do FactoryBot.build(:member, project: project, roles: [role], principal: user) - } + end let(:status) { FactoryBot.create(:status) } - let(:issue) { + let(:issue) do FactoryBot.build(:work_package, type: project.types.first, author: user, project: project, status: status) - } + end before do issue.save! diff --git a/spec/models/type_spec.rb b/spec/models/type_spec.rb index 6eda37ec84..a1cfd22f0f 100644 --- a/spec/models/type_spec.rb +++ b/spec/models/type_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -73,11 +74,11 @@ describe ::Type, type: :model do let!(:type) { FactoryBot.create(:type) } let!(:workflow_a) do FactoryBot.create(:workflow, role_id: role.id, - type_id: type.id, - old_status_id: statuses[0].id, - new_status_id: statuses[1].id, - author: false, - assignee: false) + type_id: type.id, + old_status_id: statuses[0].id, + new_status_id: statuses[1].id, + author: false, + assignee: false) end it 'returns the statuses relation' do diff --git a/spec/models/user_deletion_spec.rb b/spec/models/user_deletion_spec.rb index 7722ed5f90..d5d7d1e304 100644 --- a/spec/models/user_deletion_spec.rb +++ b/spec/models/user_deletion_spec.rb @@ -35,20 +35,20 @@ describe User, 'deletion', type: :model do let(:member) { project.members.first } let(:role) { member.roles.first } let(:status) { FactoryBot.create(:status) } - let(:issue) { + let(:issue) do FactoryBot.create(:work_package, type: project.types.first, - author: user, - project: project, - status: status, - assigned_to: user) - } - let(:issue2) { + author: user, + project: project, + status: status, + assigned_to: user) + end + let(:issue2) do FactoryBot.create(:work_package, type: project.types.first, - author: user2, - project: project, - status: status, - assigned_to: user2) - } + author: user2, + project: project, + status: status, + assigned_to: user2) + end let(:substitute_user) { DeletedUser.first } @@ -179,25 +179,25 @@ describe User, 'deletion', type: :model do end describe 'WHEN the user has an issue created and assigned' do - let(:associated_instance) { + let(:associated_instance) do FactoryBot.build(:work_package, type: project.types.first, - project: project, - status: status) - } + project: project, + status: status) + end let(:associated_class) { WorkPackage } - let(:associations) { [:author, :assigned_to, :responsible] } + let(:associations) { %i[author assigned_to responsible] } it_should_behave_like 'created journalized associated object' end describe 'WHEN the user has an issue updated and assigned' do - let(:associated_instance) { + let(:associated_instance) do FactoryBot.build(:work_package, type: project.types.first, - project: project, - status: status) - } + project: project, + status: status) + end let(:associated_class) { WorkPackage } - let(:associations) { [:author, :assigned_to, :responsible] } + let(:associations) { %i[author assigned_to responsible] } before do allow(User).to receive(:current).and_return user2 @@ -286,12 +286,12 @@ describe User, 'deletion', type: :model do end describe 'WHEN the user has created a time entry' do - let(:associated_instance) { + let(:associated_instance) do FactoryBot.build(:time_entry, project: project, - work_package: issue, - hours: 2, - activity: FactoryBot.create(:time_entry_activity)) - } + work_package: issue, + hours: 2, + activity: FactoryBot.create(:time_entry_activity)) + end let(:associated_class) { TimeEntry } let(:associations) { [:user] } @@ -299,12 +299,12 @@ describe User, 'deletion', type: :model do end describe 'WHEN the user has worked on time_entry' do - let(:associated_instance) { + let(:associated_instance) do FactoryBot.build(:time_entry, project: project, - work_package: issue, - hours: 2, - activity: FactoryBot.create(:time_entry_activity)) - } + work_package: issue, + hours: 2, + activity: FactoryBot.create(:time_entry_activity)) + end let(:associated_class) { TimeEntry } let(:associations) { [:user] } @@ -314,10 +314,10 @@ describe User, 'deletion', type: :model do describe 'WHEN the user has commented' do let(:news) { FactoryBot.create(:news, author: user) } - let(:associated_instance) { + let(:associated_instance) do Comment.new(commented: news, comments: 'lorem') - } + end let(:associated_class) { Comment } let(:associations) { [:author] } @@ -342,10 +342,10 @@ describe User, 'deletion', type: :model do describe 'WHEN the user is watching something' do let(:watched) { FactoryBot.create(:work_package, project: project) } - let(:watch) { + let(:watch) do Watcher.new(user: user, watchable: watched) - } + end before do watch.save! @@ -357,9 +357,9 @@ describe User, 'deletion', type: :model do end describe 'WHEN the user has a token created' do - let(:token) { + let(:token) do Token::RSS.new(user: user, value: 'loremipsum') - } + end before do token.save! @@ -395,8 +395,8 @@ describe User, 'deletion', type: :model do with_virtual_subversion_repository do let(:associated_instance) do FactoryBot.build(:changeset, - repository_id: repository.id, - committer: user.login) + repository_id: repository.id, + committer: user.login) end let(:associated_class) { Changeset } @@ -410,8 +410,8 @@ describe User, 'deletion', type: :model do with_virtual_subversion_repository do let(:associated_instance) do FactoryBot.build(:changeset, - repository_id: repository.id, - committer: user2.login) + repository_id: repository.id, + committer: user2.login) end end @@ -447,10 +447,10 @@ describe User, 'deletion', type: :model do end describe 'WHEN the user is assigned an issue category' do - let(:category) { + let(:category) do FactoryBot.build(:category, assigned_to: user, - project: project) - } + project: project) + end before do category.save! diff --git a/spec/models/user_password_spec.rb b/spec/models/user_password_spec.rb index 1a54e638a9..8cea9681eb 100644 --- a/spec/models/user_password_spec.rb +++ b/spec/models/user_password_spec.rb @@ -61,13 +61,13 @@ describe UserPassword, type: :model do end describe '#rehash_as_active' do - let(:password) { + let(:password) do pass = FactoryBot.build(:legacy_sha1_password, user: user, plain_password: 'adminAdmin!') expect(pass).to receive(:salt_and_hash_password!).and_return nil pass.save! pass - } + end before do password @@ -76,9 +76,9 @@ describe UserPassword, type: :model do it 'rehashed the password when correct' do expect(user.current_password).to be_a(UserPassword::SHA1) - expect { + expect do password.matches_plaintext?('adminAdmin!') - }.to_not change { user.passwords.count } + end.to_not change { user.passwords.count } expect(user.current_password).to be_a(UserPassword::Bcrypt) expect(user.current_password.hashed_password).to start_with '$2a$' diff --git a/spec/models/user_passwords/sha1_spec.rb b/spec/models/user_passwords/sha1_spec.rb index 57b0231fb5..99a57fd74c 100644 --- a/spec/models/user_passwords/sha1_spec.rb +++ b/spec/models/user_passwords/sha1_spec.rb @@ -29,13 +29,13 @@ require 'spec_helper' describe UserPassword::SHA1, type: :model do - let(:legacy_password) { + let(:legacy_password) do pass = FactoryBot.build(:legacy_sha1_password, plain_password: 'adminAdmin!') expect(pass).to receive(:salt_and_hash_password!).and_return nil pass.save! pass - } + end describe '#matches_plaintext?' do it 'still matches for existing passwords' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0e6d1baffd..9e5dd2dd47 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -92,7 +92,6 @@ describe User, type: :model do end end - describe 'a user with and overly long firstname (> 256 chars)' do it 'is invalid' do user.firstname = 'a' * 257 @@ -109,7 +108,6 @@ describe User, type: :model do end end - describe 'login whitespace' do before do user.login = login @@ -337,7 +335,10 @@ describe User, type: :model do end it { expect(@u.valid?).to be_falsey } - it { expect(@u.errors[:password]).to include I18n.t('activerecord.errors.messages.too_short', count: Setting.password_min_length.to_i) } + it { + expect(@u.errors[:password]).to include I18n.t('activerecord.errors.messages.too_short', + count: Setting.password_min_length.to_i) + } end describe '#random_password' do @@ -445,7 +446,9 @@ describe User, type: :model do end describe '.default_admin_account_deleted_or_changed?' do - let(:default_admin) { FactoryBot.build(:user, login: 'admin', password: 'admin', password_confirmation: 'admin', admin: true) } + let(:default_admin) do + FactoryBot.build(:user, login: 'admin', password: 'admin', password_confirmation: 'admin', admin: true) + end before do Setting.password_min_length = 5 diff --git a/spec/models/users/allowed_scope_spec.rb b/spec/models/users/allowed_scope_spec.rb index 87d2aac70a..44177ab349 100644 --- a/spec/models/users/allowed_scope_spec.rb +++ b/spec/models/users/allowed_scope_spec.rb @@ -38,7 +38,7 @@ describe User, 'allowed scope' do let(:anonymous_role) { FactoryBot.build(:anonymous_role) } let(:member) do FactoryBot.build(:member, project: project, - roles: [role]) + roles: [role]) end let(:action) { :view_work_packages } diff --git a/spec/models/users/allowed_to_spec.rb b/spec/models/users/allowed_to_spec.rb index 40cb83da52..b43286b09f 100644 --- a/spec/models/users/allowed_to_spec.rb +++ b/spec/models/users/allowed_to_spec.rb @@ -36,16 +36,16 @@ describe User, 'allowed_to?' do let(:role) { FactoryBot.build(:role) } let(:role2) { FactoryBot.build(:role) } let(:anonymous_role) { FactoryBot.build(:anonymous_role) } - let(:member) { + let(:member) do FactoryBot.build(:member, project: project, - roles: [role], - principal: user) - } - let(:member2) { + roles: [role], + principal: user) + end + let(:member2) do FactoryBot.build(:member, project: project2, - roles: [role2], - principal: user) - } + roles: [role2], + principal: user) + end let(:global_permission) { OpenProject::AccessControl.permissions.find { |p| p.global? } } let(:global_role) { FactoryBot.build(:global_role, permissions: [global_permission.name]) } let(:global_member) do @@ -413,7 +413,6 @@ describe User, 'allowed_to?' do context "w/o the user being member in a project w/ the user having the global role w/ the global role having the necessary permission" do - before do project.save! @@ -576,7 +575,6 @@ describe User, 'allowed_to?' do context "w/o the user being member in a project w/ the user having a global role w/o the global role having the necessary permission" do - before do global_role.permissions = [] global_role.save! @@ -592,7 +590,6 @@ describe User, 'allowed_to?' do context "w/o the user being member in a project w/o the user having the global role w/ the global role having the necessary permission" do - before do global_role.save! end @@ -655,9 +652,9 @@ describe User, 'allowed_to?' do context 'w/ preloaded permissions' do it_behaves_like 'w/ inquiring for project' do - let(:final_setup_step) { + let(:final_setup_step) do user.preload_projects_allowed_to(permission) - } + end end end end diff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rb index 3c7e81d185..e5f886aee5 100644 --- a/spec/models/version_spec.rb +++ b/spec/models/version_spec.rb @@ -45,7 +45,7 @@ describe Version, type: :model do let(:other_project) { FactoryBot.build(:project) } it 'returns only the version for the same project' do - expect(version.to_s_for_project(version.project)).to eq("#{version.name}") + expect(version.to_s_for_project(version.project)).to eq(version.name.to_s) end it 'returns the project name and the version name for a different project' do diff --git a/spec/models/watcher_notification_mailer_spec.rb b/spec/models/watcher_notification_mailer_spec.rb index 094fb88ef2..d44de1cb81 100644 --- a/spec/models/watcher_notification_mailer_spec.rb +++ b/spec/models/watcher_notification_mailer_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -41,38 +42,38 @@ shared_examples 'WatcherNotificationMailer' do |watcher_notification_job| end describe 'watcher setup' do - let(:work_package) { + let(:work_package) do work_package = FactoryBot.build_stubbed(:work_package) journal = FactoryBot.build_stubbed(:work_package_journal) allow(work_package).to receive(:journals).and_return([journal]) work_package - } + end let(:watcher_changer) do FactoryBot.build_stubbed(:user, - mail_notification: watching_setting, - preference: user_pref) + mail_notification: watching_setting, + preference: user_pref) end let(:watching_setting) { 'all' } let(:self_notified) { true } - let(:watching_user) { + let(:watching_user) do FactoryBot.build_stubbed(:user, - mail_notification: watching_setting, - preference: user_pref) - } - let(:user_pref) { + mail_notification: watching_setting, + preference: user_pref) + end + let(:user_pref) do pref = FactoryBot.build_stubbed(:user_preference) allow(pref).to receive(:self_notified?).and_return(self_notified) pref - } + end let(:watcher) do FactoryBot.build_stubbed(:watcher, user: watching_user, - watchable: work_package) + watchable: work_package) end shared_examples_for 'notifies the added watcher for' do |setting| diff --git a/spec/models/wiki_content_spec.rb b/spec/models/wiki_content_spec.rb index 9daefe4dd5..180c8c0763 100644 --- a/spec/models/wiki_content_spec.rb +++ b/spec/models/wiki_content_spec.rb @@ -66,15 +66,16 @@ describe WikiContent, type: :model do describe '#save (create)' do let(:content) { FactoryBot.build(:wiki_content, page: page) } - it 'sends mails to the wiki`s watchers and project all watchers', with_settings: { notified_events: ['wiki_content_added'] } do + it 'sends mails to the wiki`s watchers and project all watchers', + with_settings: { notified_events: ['wiki_content_added'] } do wiki_watcher project_watcher - expect { + expect do perform_enqueued_jobs do content.save! end - } + end .to change { ActionMailer::Base.deliveries.size } .by(2) end @@ -89,11 +90,11 @@ describe WikiContent, type: :model do content.text = 'My new content' - expect { + expect do perform_enqueued_jobs do content.save! end - } + end .to change { ActionMailer::Base.deliveries.size } .by(3) end diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index c6e9816dc5..c3a19818ff 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -70,7 +70,9 @@ describe WikiPage, type: :model do describe '#nearest_main_item' do let(:child_page) { FactoryBot.create(:wiki_page, parent: wiki_page, wiki: wiki) } - let!(:child_page_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, wiki: wiki, name: child_page.slug, parent: wiki_page.menu_item) } + let!(:child_page_wiki_menu_item) do + FactoryBot.create(:wiki_menu_item, wiki: wiki, name: child_page.slug, parent: wiki_page.menu_item) + end let(:grand_child_page) { FactoryBot.create(:wiki_page, parent: child_page, wiki: wiki) } let!(:grand_child_page_wiki_menu_item) { FactoryBot.create(:wiki_menu_item, wiki: wiki, name: grand_child_page.slug) } diff --git a/spec/models/wiki_spec.rb b/spec/models/wiki_spec.rb index d2b3e88cd4..ec516a49ab 100644 --- a/spec/models/wiki_spec.rb +++ b/spec/models/wiki_spec.rb @@ -29,7 +29,6 @@ require 'spec_helper' describe Wiki, type: :model do - describe 'creation' do let(:project) { FactoryBot.create(:project, disable_modules: 'wiki') } let(:start_page) { 'The wiki start page' } diff --git a/spec/models/work_package/aggregate_ancestors_spec.rb b/spec/models/work_package/aggregate_ancestors_spec.rb index 78e8e87d22..4189053120 100644 --- a/spec/models/work_package/aggregate_ancestors_spec.rb +++ b/spec/models/work_package/aggregate_ancestors_spec.rb @@ -35,38 +35,38 @@ describe WorkPackage::Ancestors, type: :model do let!(:root_work_package) do FactoryBot.create :work_package, - project: project + project: project end let!(:intermediate) do FactoryBot.create :work_package, - parent: root_work_package, - project: project + parent: root_work_package, + project: project end let!(:intermediate_project2) do FactoryBot.create :work_package, - parent: root_work_package, - project: project2 + parent: root_work_package, + project: project2 end let!(:leaf) do FactoryBot.create :work_package, - parent: intermediate, - project: project + parent: intermediate, + project: project end let!(:leaf_project2) do FactoryBot.create :work_package, - parent: intermediate_project2, - project: project + parent: intermediate_project2, + project: project end let(:view_role) do FactoryBot.build(:role, - permissions: [:view_work_packages]) + permissions: [:view_work_packages]) end let(:none_role) do FactoryBot.build(:role, - permissions: []) + permissions: []) end let(:leaf_ids) { [leaf.id, leaf_project2.id] } @@ -82,9 +82,9 @@ describe WorkPackage::Ancestors, type: :model do context 'with permission in the first project' do before do FactoryBot.create :member, - user: user, - project: project, - roles: [view_role] + user: user, + project: project, + roles: [view_role] end describe 'fetching from db' do @@ -120,9 +120,9 @@ describe WorkPackage::Ancestors, type: :model do context 'and permission in second project' do before do FactoryBot.create :member, - user: user, - project: project2, - roles: [view_role] + user: user, + project: project2, + roles: [view_role] end describe 'leaf ids' do @@ -142,9 +142,9 @@ describe WorkPackage::Ancestors, type: :model do context 'no permissions' do before do FactoryBot.create :member, - user: user, - project: project, - roles: [none_role] + user: user, + project: project, + roles: [none_role] end describe 'leaf ids' do diff --git a/spec/models/work_package/ask_before_destruction_spec.rb b/spec/models/work_package/ask_before_destruction_spec.rb index e034380c36..368c82b78c 100644 --- a/spec/models/work_package/ask_before_destruction_spec.rb +++ b/spec/models/work_package/ask_before_destruction_spec.rb @@ -31,11 +31,11 @@ require 'spec_helper' describe WorkPackage, type: :model do let(:work_package) do FactoryBot.create(:work_package, project: project, - status: status) + status: status) end let(:work_package2) do FactoryBot.create(:work_package, project: project2, - status: status) + status: status) end let(:user) { FactoryBot.create(:user) } diff --git a/spec/models/work_package/openproject_notifications_spec.rb b/spec/models/work_package/openproject_notifications_spec.rb index 19fde2c2f7..65492fd83d 100644 --- a/spec/models/work_package/openproject_notifications_spec.rb +++ b/spec/models/work_package/openproject_notifications_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/models/work_package/work_package_action_mailer_spec.rb b/spec/models/work_package/work_package_action_mailer_spec.rb index dc27a104c9..800b7c6396 100644 --- a/spec/models/work_package/work_package_action_mailer_spec.rb +++ b/spec/models/work_package/work_package_action_mailer_spec.rb @@ -70,7 +70,11 @@ describe WorkPackage, type: :model do ActionMailer::Base.deliveries.clear work_package.subject = 'A different subject update' - work_package.save! rescue nil + begin + work_package.save! + rescue StandardError + nil + end end it { is_expected.to eq(0) } diff --git a/spec/models/work_package/work_package_acts_as_searchable_spec.rb b/spec/models/work_package/work_package_acts_as_searchable_spec.rb index a7ed140a12..6460e0f85c 100644 --- a/spec/models/work_package/work_package_acts_as_searchable_spec.rb +++ b/spec/models/work_package/work_package_acts_as_searchable_spec.rb @@ -32,15 +32,15 @@ describe WorkPackage, 'acts_as_searchable', type: :model do include BecomeMember let(:wp_subject) { 'the quick brown fox jumps over the lazy dog' } - let(:project) { + let(:project) do FactoryBot.create(:project, - public: false) - } - let(:work_package) { + public: false) + end + let(:work_package) do FactoryBot.create(:work_package, - subject: wp_subject, - project: project) - } + subject: wp_subject, + project: project) + end let(:user) { FactoryBot.create(:user) } describe '#search' do diff --git a/spec/models/work_package/work_package_acts_as_watchable_spec.rb b/spec/models/work_package/work_package_acts_as_watchable_spec.rb index 9360dc6e18..fdc4a81b37 100644 --- a/spec/models/work_package/work_package_acts_as_watchable_spec.rb +++ b/spec/models/work_package/work_package_acts_as_watchable_spec.rb @@ -32,10 +32,10 @@ require 'support/shared/acts_as_watchable' describe WorkPackage, type: :model do let(:project) { FactoryBot.create(:project) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, - project: project) - } + project: project) + end it_behaves_like 'acts_as_watchable included' do let(:model_instance) { FactoryBot.create(:work_package) } diff --git a/spec/models/work_package/work_package_custom_actions_spec.rb b/spec/models/work_package/work_package_custom_actions_spec.rb index 4b8fd6bd71..0530ced664 100644 --- a/spec/models/work_package/work_package_custom_actions_spec.rb +++ b/spec/models/work_package/work_package_custom_actions_spec.rb @@ -33,15 +33,15 @@ require 'spec_helper' describe WorkPackage, 'custom_actions', type: :model do let(:work_package) do FactoryBot.build_stubbed(:stubbed_work_package, - project: project) + project: project) end let(:project) { FactoryBot.create(:project) } let(:status) { FactoryBot.create(:status) } let(:other_status) { FactoryBot.create(:status) } let(:user) do FactoryBot.create(:user, - member_in_project: work_package.project, - member_through_role: role) + member_in_project: work_package.project, + member_through_role: role) end let(:role) do FactoryBot.create(:role) diff --git a/spec/models/work_package/work_package_notifications_spec.rb b/spec/models/work_package/work_package_notifications_spec.rb index 19d4887942..5ffe79137f 100644 --- a/spec/models/work_package/work_package_notifications_spec.rb +++ b/spec/models/work_package/work_package_notifications_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/models/work_package/work_package_scheduling_spec.rb b/spec/models/work_package/work_package_scheduling_spec.rb index 34981f1a54..0624759ea6 100644 --- a/spec/models/work_package/work_package_scheduling_spec.rb +++ b/spec/models/work_package/work_package_scheduling_spec.rb @@ -32,7 +32,7 @@ describe WorkPackage, type: :model do describe '#overdue' do let(:work_package) do FactoryBot.create(:work_package, - due_date: due_date) + due_date: due_date) end shared_examples_for 'overdue' do @@ -75,7 +75,7 @@ describe WorkPackage, type: :model do let(:due_date) { 1.day.ago.to_date } let(:status) do FactoryBot.create(:status, - is_closed: true) + is_closed: true) end before do @@ -89,9 +89,9 @@ describe WorkPackage, type: :model do describe '#behind_schedule?' do let(:work_package) do FactoryBot.create(:work_package, - start_date: start_date, - due_date: due_date, - done_ratio: done_ratio) + start_date: start_date, + due_date: due_date, + done_ratio: done_ratio) end shared_examples_for 'behind schedule' do diff --git a/spec/models/work_package/work_package_visibility_spec.rb b/spec/models/work_package/work_package_visibility_spec.rb index edaed6a5b9..a6e8c9c66e 100644 --- a/spec/models/work_package/work_package_visibility_spec.rb +++ b/spec/models/work_package/work_package_visibility_spec.rb @@ -63,9 +63,9 @@ describe 'WorkPackage-Visibility', type: :model do it 'is visible for members of the project, with the view_work_packages permissison' do FactoryBot.create(:member, - user: user, - project: private_project, - role_ids: [view_work_packages.id]) + user: user, + project: private_project, + role_ids: [view_work_packages.id]) expect(WorkPackage.visible(user)).to match_array [subject] end @@ -74,10 +74,10 @@ describe 'WorkPackage-Visibility', type: :model do subject FactoryBot.create(:member, - user: user, - project: private_project, - role_ids: [view_work_packages.id, - view_work_packages_role2.id]) + user: user, + project: private_project, + role_ids: [view_work_packages.id, + view_work_packages_role2.id]) expect(WorkPackage.visible(user).pluck(:id)).to match_array [subject.id] end @@ -89,9 +89,9 @@ describe 'WorkPackage-Visibility', type: :model do it 'is not visible for members of the project, without the view_work_packages permissison' do no_permission = FactoryBot.create(:role, permissions: [:no_permission]) FactoryBot.create(:member, - user: user, - project: private_project, - role_ids: [no_permission.id]) + user: user, + project: private_project, + role_ids: [no_permission.id]) expect(WorkPackage.visible(user)).to match_array [] end diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb index aaafdff685..92dcd8d501 100644 --- a/spec/models/work_package_spec.rb +++ b/spec/models/work_package_spec.rb @@ -130,7 +130,7 @@ describe WorkPackage, type: :model do subject do FactoryBot.create(:work_package, - assigned_to: group).assigned_to + assigned_to: group).assigned_to end it { is_expected.to eq(group) } @@ -142,8 +142,8 @@ describe WorkPackage, type: :model do let(:user_2) { FactoryBot.create(:user, member_in_project: project) } let(:category) do FactoryBot.create(:category, - project: project, - assigned_to: user_2) + project: project, + assigned_to: user_2) end before do diff --git a/spec/models/work_packages/scopes/for_scheduling_spec.rb b/spec/models/work_packages/scopes/for_scheduling_spec.rb index c228924b71..be9a21f455 100644 --- a/spec/models/work_packages/scopes/for_scheduling_spec.rb +++ b/spec/models/work_packages/scopes/for_scheduling_spec.rb @@ -103,7 +103,7 @@ describe WorkPackages::Scopes::ForScheduling, 'allowed scope' do end let(:existing_work_packages) { [] } - subject { } + subject {} describe '.for_scheduling' do it 'is a AR scope' do diff --git a/spec/models/workflow_spec.rb b/spec/models/workflow_spec.rb index f6831a637c..5b0855cd9f 100644 --- a/spec/models/workflow_spec.rb +++ b/spec/models/workflow_spec.rb @@ -39,7 +39,7 @@ describe Workflow, type: :model do let(:type_target) { FactoryBot.create(:type) } shared_examples_for 'copied workflow' do - before do Workflow.copy(type, role, type_target, role_target) end + before { Workflow.copy(type, role, type_target, role_target) } subject { Workflow.order(Arel.sql('id DESC')).first } @@ -57,37 +57,37 @@ describe Workflow, type: :model do end describe 'workflow w/o author or assignee' do - let!(:workflow_src) { + let!(:workflow_src) do FactoryBot.create(:workflow, - old_status: status_0, - new_status: status_1, - type_id: type.id, - role: role) - } + old_status: status_0, + new_status: status_1, + type_id: type.id, + role: role) + end it_behaves_like 'copied workflow' end describe 'workflow with author' do - let!(:workflow_src) { + let!(:workflow_src) do FactoryBot.create(:workflow, - old_status: status_0, - new_status: status_1, - type_id: type.id, - role: role, - author: true) - } + old_status: status_0, + new_status: status_1, + type_id: type.id, + role: role, + author: true) + end it_behaves_like 'copied workflow' end describe 'workflow with assignee' do - let!(:workflow_src) { + let!(:workflow_src) do FactoryBot.create(:workflow, - old_status: status_0, - new_status: status_1, - type_id: type.id, - role: role, - assignee: true) - } + old_status: status_0, + new_status: status_1, + type_id: type.id, + role: role, + assignee: true) + end it_behaves_like 'copied workflow' end end diff --git a/spec/permissions/copy_projects_spec.rb b/spec/permissions/copy_projects_spec.rb index 3f777c9dc9..16d24bfe6d 100644 --- a/spec/permissions/copy_projects_spec.rb +++ b/spec/permissions/copy_projects_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require File.expand_path('../../support/permission_specs', __FILE__) +require File.expand_path('../support/permission_specs', __dir__) describe CopyProjectsController, 'copy_projects permission', type: :controller do include PermissionSpecs diff --git a/spec/permissions/export_work_packages_spec.rb b/spec/permissions/export_work_packages_spec.rb index a7edadadc2..4d4d4a0ab0 100644 --- a/spec/permissions/export_work_packages_spec.rb +++ b/spec/permissions/export_work_packages_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require File.expand_path('../../support/permission_specs', __FILE__) +require File.expand_path('../support/permission_specs', __dir__) describe WorkPackagesController, 'export_work_packages permission', type: :controller do include PermissionSpecs diff --git a/spec/permissions/manage_forums_spec.rb b/spec/permissions/manage_forums_spec.rb index 29b9e92351..873e13d468 100644 --- a/spec/permissions/manage_forums_spec.rb +++ b/spec/permissions/manage_forums_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require File.expand_path('../../support/permission_specs', __FILE__) +require File.expand_path('../support/permission_specs', __dir__) describe ForumsController, 'manage_forums permission', type: :controller do include PermissionSpecs diff --git a/spec/permissions/manage_repositories_spec.rb b/spec/permissions/manage_repositories_spec.rb index 39ff46ff1f..4588c30999 100644 --- a/spec/permissions/manage_repositories_spec.rb +++ b/spec/permissions/manage_repositories_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require File.expand_path('../../support/permission_specs', __FILE__) +require File.expand_path('../support/permission_specs', __dir__) describe RepositoriesController, 'manage_repository permission', type: :controller do include PermissionSpecs diff --git a/spec/permissions/view_work_packages_spec.rb b/spec/permissions/view_work_packages_spec.rb index 00a21e3f28..f11a6bdcc7 100644 --- a/spec/permissions/view_work_packages_spec.rb +++ b/spec/permissions/view_work_packages_spec.rb @@ -27,7 +27,7 @@ #++ require 'spec_helper' -require File.expand_path('../../support/permission_specs', __FILE__) +require File.expand_path('../support/permission_specs', __dir__) describe WorkPackagesController, 'view_work_packages permission', type: :controller do include PermissionSpecs diff --git a/spec/policies/query_policy_spec.rb b/spec/policies/query_policy_spec.rb index 74ab307639..3f21c86661 100644 --- a/spec/policies/query_policy_spec.rb +++ b/spec/policies/query_policy_spec.rb @@ -43,7 +43,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'viewing queries' do |global| - context "#{ global ? 'in global context' : 'in project context' }" do + context (global ? 'in global context' : 'in project context').to_s do let(:other_user) { FactoryBot.build_stubbed(:user) } if global let(:project) { nil } @@ -58,9 +58,9 @@ describe QueryPolicy, type: :controller do context 'query belongs to a different user' do let(:query) do FactoryBot.build_stubbed(:query, - project: project, - user: user, - is_public: false) + project: project, + user: user, + is_public: false) end it 'is true if the query is private and the owner views it' do @@ -76,7 +76,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'action on persisted' do |action, global| - context "for #{action} #{ global ? 'in global context' : 'in project context' }" do + context "for #{action} #{global ? 'in global context' : 'in project context'}" do if global let(:project) { nil } end @@ -93,7 +93,7 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the save_query permission in the project ' + - 'AND the query is not persisted' do + 'AND the query is not persisted' do allow(user).to receive(:allowed_to?).with(:save_queries, project, global: project.nil?) @@ -104,7 +104,7 @@ describe QueryPolicy, type: :controller do end it 'is true if the user has the save_query permission in the project ' + - 'AND it is his query' do + 'AND it is his query' do allow(user).to receive(:allowed_to?).with(:save_queries, project, global: project.nil?) @@ -115,7 +115,7 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the save_query permission in the project ' + - 'AND it is not his query' do + 'AND it is not his query' do allow(user).to receive(:allowed_to?).with(:save_queries, project, global: project.nil?) @@ -127,7 +127,7 @@ describe QueryPolicy, type: :controller do end it 'is false if the user lacks the save_query permission in the project ' + - 'AND it is his query' do + 'AND it is his query' do allow(user).to receive(:allowed_to?).with(:save_queries, project, global: project.nil?) @@ -139,8 +139,8 @@ describe QueryPolicy, type: :controller do end it 'is true if the user has the manage_public_query permission in the project ' + - 'AND it is anothers query ' + - 'AND the query is public' do + 'AND it is anothers query ' + + 'AND the query is public' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -152,8 +152,8 @@ describe QueryPolicy, type: :controller do end it 'is false if the user lacks the manage_public_query permission in the project ' + - 'AND it is anothers query ' + - 'AND the query is public' do + 'AND it is anothers query ' + + 'AND the query is public' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -165,8 +165,8 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the manage_public_query permission in the project ' + - 'AND it is anothers query ' + - 'AND the query is not public' do + 'AND it is anothers query ' + + 'AND the query is not public' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -180,7 +180,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'action on unpersisted' do |action, global| - context "for #{action} #{ global ? 'in global context' : 'in project context' }" do + context "for #{action} #{global ? 'in global context' : 'in project context'}" do if global let(:project) { nil } end @@ -206,7 +206,7 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the save_query permission in the project ' + - 'AND the query is persisted' do + 'AND the query is persisted' do allow(user).to receive(:allowed_to?).with(:save_queries, project, global: global) @@ -220,7 +220,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'publicize' do |global| - context "#{ global ? 'in global context' : 'in project context' }" do + context (global ? 'in global context' : 'in project context').to_s do if global let(:project) { nil } end @@ -232,7 +232,7 @@ describe QueryPolicy, type: :controller do end it 'is true if the user has the manage_public_query permission in the project ' + - 'AND it is his query' do + 'AND it is his query' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -242,8 +242,8 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the manage_public_query permission in the project ' + - 'AND the query is not public ' + - 'AND it is not his query' do + 'AND the query is not public ' + + 'AND it is not his query' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -257,7 +257,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'depublicize' do |global| - context "#{ global ? 'in global context' : 'in project context' }" do + context (global ? 'in global context' : 'in project context').to_s do if global let(:project) { nil } end @@ -269,8 +269,8 @@ describe QueryPolicy, type: :controller do end it 'is true if the user has the manage_public_query permission in the project ' + - 'AND the query belongs to another user' + - 'AND the query is public' do + 'AND the query belongs to another user' + + 'AND the query is public' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -283,7 +283,7 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the manage_public_query permission in the project ' + - 'AND the query is not public' do + 'AND the query is not public' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -296,7 +296,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'star' do |global| - context "#{ global ? 'in global context' : 'in project context' }" do + context (global ? 'in global context' : 'in project context').to_s do if global let(:project) { nil } end @@ -310,7 +310,7 @@ describe QueryPolicy, type: :controller do end shared_examples 'update ordered_work_packages' do |global| - context "#{ global ? 'in global context' : 'in project context' }" do + context (global ? 'in global context' : 'in project context').to_s do if global let(:project) { nil } end @@ -351,9 +351,8 @@ describe QueryPolicy, type: :controller do expect(subject.allowed?(query, :reorder_work_packages)).to be_truthy end - it 'is true if the user has the manage_public_query permission in the project ' + - 'AND it is a public query' do + 'AND it is a public query' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) @@ -364,8 +363,8 @@ describe QueryPolicy, type: :controller do end it 'is false if the user has the manage_public_query permission in the project ' + - 'AND the query is not public ' + - 'AND it is not his query' do + 'AND the query is not public ' + + 'AND it is not his query' do allow(user).to receive(:allowed_to?).with(:manage_public_queries, project, global: project.nil?) diff --git a/spec/policies/redirect_policy_spec.rb b/spec/policies/redirect_policy_spec.rb index 9859981c97..e3bb9b2390 100644 --- a/spec/policies/redirect_policy_spec.rb +++ b/spec/policies/redirect_policy_spec.rb @@ -34,14 +34,14 @@ describe RedirectPolicy, type: :controller do let(:return_escaped) { true } let(:default) { 'http://test.foo/default' } - let(:policy) { + let(:policy) do described_class.new( back_url, default: default, hostname: host, return_escaped: return_escaped ) - } + end let(:subject) { policy.redirect_url } shared_examples 'redirects to default' do |url| diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6f9f93196c..756d8f2205 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -26,13 +26,12 @@ # See docs/COPYRIGHT.rdoc for more details. ENV['RAILS_ENV'] ||= 'test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) require 'factory_bot_rails' require 'rspec/rails' require 'shoulda/matchers' require 'test_prof/recipes/rspec/before_all' - # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end diff --git a/spec/requests/api/v3/activities_by_work_package_resource_spec.rb b/spec/requests/api/v3/activities_by_work_package_resource_spec.rb index cd74cd7e3e..986d127b17 100644 --- a/spec/requests/api/v3/activities_by_work_package_resource_spec.rb +++ b/spec/requests/api/v3/activities_by_work_package_resource_spec.rb @@ -69,7 +69,7 @@ describe API::V3::Activities::ActivitiesByWorkPackageAPI, type: :request do shared_context 'create activity' do before do - header "Content-Type", "application/json" + header "Content-Type", "application/json" post api_v3_paths.work_package_activities(work_package.id), { comment: { raw: comment } }.to_json end diff --git a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb index b44f070c0e..e6ef3af91e 100644 --- a/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb +++ b/spec/requests/api/v3/attachments/attachment_resource_shared_examples.rb @@ -61,7 +61,7 @@ shared_examples 'it supports direct uploads' do expect(subject.status).to eq(404) end end - + context 'with remote AWS storage', with_direct_uploads: true do before do request! diff --git a/spec/requests/api/v3/attachments_spec.rb b/spec/requests/api/v3/attachments_spec.rb index a0956d3c48..aa3135a29b 100644 --- a/spec/requests/api/v3/attachments_spec.rb +++ b/spec/requests/api/v3/attachments_spec.rb @@ -69,7 +69,9 @@ describe API::V3::Attachments::AttachmentsAPI, type: :request do describe 'GET /uploaded' do let(:digest) { "" } - let(:attachment) { FactoryBot.create :attachment, digest: digest, author: current_user, container: nil, container_type: nil, downloads: -1 } + let(:attachment) do + FactoryBot.create :attachment, digest: digest, author: current_user, container: nil, container_type: nil, downloads: -1 + end before do get "/api/v3/attachments/#{attachment.id}/uploaded" diff --git a/spec/requests/api/v3/authentication_spec.rb b/spec/requests/api/v3/authentication_spec.rb index e876cc63ac..41e4cb9bae 100644 --- a/spec/requests/api/v3/authentication_spec.rb +++ b/spec/requests/api/v3/authentication_spec.rb @@ -35,9 +35,9 @@ describe API::V3, type: :request do let(:response_401) do { - '_type' => 'Error', + '_type' => 'Error', 'errorIdentifier' => 'urn:openproject-org:api:v3:errors:Unauthenticated', - 'message' => expected_message + 'message' => expected_message } end @@ -128,7 +128,6 @@ describe API::V3, type: :request do expect(last_response.headers['Content-Type']).to eq 'application/hal+json; charset=utf-8' end - it 'should return the WWW-Authenticate header' do expect(last_response.header['WWW-Authenticate']) .to include 'Basic realm="OpenProject API"' diff --git a/spec/requests/api/v3/cors_header_spec.rb b/spec/requests/api/v3/cors_header_spec.rb index 08c69dff1d..c720b75215 100644 --- a/spec/requests/api/v3/cors_header_spec.rb +++ b/spec/requests/api/v3/cors_header_spec.rb @@ -38,10 +38,8 @@ describe 'API v3 CORS headers', context 'with setting enabled', with_settings: { apiv3_cors_enabled: true } do - context 'with allowed origin set to specific values', with_settings: { apiv3_cors_origins: %w[https://foo.example.com bla.test] } do - it 'outputs CORS headers', :aggregate_failures do options '/api/v3', nil, diff --git a/spec/requests/api/v3/custom_actions/custom_actions_api_spec.rb b/spec/requests/api/v3/custom_actions/custom_actions_api_spec.rb index 917db6d4ca..da153d92d8 100644 --- a/spec/requests/api/v3/custom_actions/custom_actions_api_spec.rb +++ b/spec/requests/api/v3/custom_actions/custom_actions_api_spec.rb @@ -34,18 +34,18 @@ describe 'API::V3::CustomActions::CustomActionsAPI', type: :request do let(:role) do FactoryBot.create(:role, - permissions: %i[edit_work_packages view_work_packages]) + permissions: %i[edit_work_packages view_work_packages]) end let(:project) { FactoryBot.create(:project) } let(:work_package) do FactoryBot.create(:work_package, - project: project, - assigned_to: user) + project: project, + assigned_to: user) end let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let(:action) do FactoryBot.create(:custom_action, actions: [CustomActions::Actions::AssignedTo.new(nil)]) diff --git a/spec/requests/api/v3/custom_options/custom_options_resource_spec.rb b/spec/requests/api/v3/custom_options/custom_options_resource_spec.rb index 1a9c6fd48b..b149085026 100644 --- a/spec/requests/api/v3/custom_options/custom_options_resource_spec.rb +++ b/spec/requests/api/v3/custom_options/custom_options_resource_spec.rb @@ -35,8 +35,8 @@ describe 'API v3 Custom Options resource' do let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let(:project) { FactoryBot.create(:project) } let(:role) { FactoryBot.create(:role, permissions: permissions) } @@ -50,7 +50,7 @@ describe 'API v3 Custom Options resource' do end let(:custom_option) do FactoryBot.create(:custom_option, - custom_field: custom_field) + custom_field: custom_field) end subject(:response) { last_response } diff --git a/spec/requests/api/v3/groups/group_resource_spec.rb b/spec/requests/api/v3/groups/group_resource_spec.rb index d45818f99b..a1c0c17e2d 100644 --- a/spec/requests/api/v3/groups/group_resource_spec.rb +++ b/spec/requests/api/v3/groups/group_resource_spec.rb @@ -36,16 +36,16 @@ describe 'API v3 Group resource', type: :request, content_type: :json do let(:project) { FactoryBot.create(:project) } let(:group) do FactoryBot.create(:group, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let(:group_project) { project } let(:role) { FactoryBot.create(:role, permissions: permissions) } let(:permissions) { [:view_members] } let(:current_user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end subject(:response) { last_response } diff --git a/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb b/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb index 38efc7349e..62b105b512 100644 --- a/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb +++ b/spec/requests/api/v3/help_texts/help_texts_resource_spec.rb @@ -37,8 +37,8 @@ describe 'API v3 Help texts resource' do let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) } let(:current_user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let!(:help_texts) do diff --git a/spec/requests/api/v3/membership_resources_spec.rb b/spec/requests/api/v3/membership_resources_spec.rb index 68032773fb..cba14147c8 100644 --- a/spec/requests/api/v3/membership_resources_spec.rb +++ b/spec/requests/api/v3/membership_resources_spec.rb @@ -675,7 +675,7 @@ describe 'API v3 memberships resource', type: :request, content_type: :json do .to match_array [another_role] # Assigning a new role also updates the member - expect(other_member.updated_at > other_member_updated_at ) + expect(other_member.updated_at > other_member_updated_at) .to be_truthy end diff --git a/spec/requests/api/v3/priority_resource_spec.rb b/spec/requests/api/v3/priority_resource_spec.rb index 4cc688e537..60ab3ad94e 100644 --- a/spec/requests/api/v3/priority_resource_spec.rb +++ b/spec/requests/api/v3/priority_resource_spec.rb @@ -37,8 +37,8 @@ describe 'API v3 Priority resource' do let(:project) { FactoryBot.create(:project, public: false) } let(:current_user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let!(:priorities) { FactoryBot.create_list(:priority, 2) } diff --git a/spec/requests/api/v3/projects/version_resource_spec.rb b/spec/requests/api/v3/projects/version_resource_spec.rb index 30f4ca1c0a..a92fa34805 100644 --- a/spec/requests/api/v3/projects/version_resource_spec.rb +++ b/spec/requests/api/v3/projects/version_resource_spec.rb @@ -35,8 +35,8 @@ describe "API v3 project's versions resource" do let(:current_user) do user = FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) allow(User).to receive(:current).and_return user diff --git a/spec/requests/api/v3/queries/columns/query_columns_resource_spec.rb b/spec/requests/api/v3/queries/columns/query_columns_resource_spec.rb index e66de513f7..7f43820a94 100644 --- a/spec/requests/api/v3/queries/columns/query_columns_resource_spec.rb +++ b/spec/requests/api/v3/queries/columns/query_columns_resource_spec.rb @@ -41,8 +41,8 @@ describe 'API v3 Query Column resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do diff --git a/spec/requests/api/v3/queries/create_form_api_spec.rb b/spec/requests/api/v3/queries/create_form_api_spec.rb index 07b8827deb..65d2d7b685 100644 --- a/spec/requests/api/v3/queries/create_form_api_spec.rb +++ b/spec/requests/api/v3/queries/create_form_api_spec.rb @@ -190,10 +190,10 @@ describe "POST /api/v3/queries/form", type: :request do context 'with relation columns allowed by the enterprise token' do it 'has the static, custom field and relation columns' do expected_columns = static_columns_json + - custom_field_columns_json + - relation_to_type_columns_json + - relation_of_type_columns_json + - non_project_type_relation_column_json + custom_field_columns_json + + relation_to_type_columns_json + + relation_of_type_columns_json + + non_project_type_relation_column_json actual_columns = form.dig('_embedded', 'schema', @@ -216,7 +216,7 @@ describe "POST /api/v3/queries/form", type: :request do it 'has the static and custom field' do expected_columns = static_columns_json + - custom_field_columns_json + custom_field_columns_json actual_columns = form.dig('_embedded', 'schema', @@ -283,9 +283,9 @@ describe "POST /api/v3/queries/form", type: :request do context 'with relation columns allowed by the enterprise token' do it 'has the static, custom field and relation columns' do expected_columns = static_columns_json + - custom_field_columns_json + - relation_to_type_columns_json + - relation_of_type_columns_json + custom_field_columns_json + + relation_to_type_columns_json + + relation_of_type_columns_json actual_columns = form.dig('_embedded', 'schema', @@ -309,7 +309,7 @@ describe "POST /api/v3/queries/form", type: :request do it 'has the static and custom field' do expected_columns = static_columns_json + - custom_field_columns_json + custom_field_columns_json actual_columns = form.dig('_embedded', 'schema', @@ -580,15 +580,14 @@ describe "POST /api/v3/queries/form", type: :request do let!(:type) { FactoryBot.create(:type, custom_fields: [custom_field]) } let!(:project) { FactoryBot.create(:project, types: [type], work_package_custom_fields: [custom_field]) } - - let(:path_with_cf) { + let(:path_with_cf) do uri = Addressable::URI.parse(path) uri.query = { filters: [{ "customField#{custom_field.id}": { "operator": "=", "values": ["ABC"] } }] }.to_query uri.to_s - } + end let(:parameters) do { diff --git a/spec/requests/api/v3/queries/create_query_spec.rb b/spec/requests/api/v3/queries/create_query_spec.rb index f393fb94e8..2ef9a0ca62 100644 --- a/spec/requests/api/v3/queries/create_query_spec.rb +++ b/spec/requests/api/v3/queries/create_query_spec.rb @@ -118,7 +118,7 @@ describe "POST /api/v3/queries", type: :request do expect(query).to be_present expect(query.group_by_column.name).to eq :assigned_to expect(query.sort_criteria).to eq [["id", "desc"], ["assigned_to", "asc"]] - expect(query.columns.map(&:name)).to eq [:id, :subject, :status, :assigned_to] + expect(query.columns.map(&:name)).to eq %i[id subject status assigned_to] expect(query.user).to eq user expect(query.project).to eq project diff --git a/spec/requests/api/v3/queries/filters/query_filters_resource_spec.rb b/spec/requests/api/v3/queries/filters/query_filters_resource_spec.rb index 9276422e95..967d7aeb13 100644 --- a/spec/requests/api/v3/queries/filters/query_filters_resource_spec.rb +++ b/spec/requests/api/v3/queries/filters/query_filters_resource_spec.rb @@ -41,8 +41,8 @@ describe 'API v3 Query Filter resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do diff --git a/spec/requests/api/v3/queries/group_bys/query_group_bys_resource_spec.rb b/spec/requests/api/v3/queries/group_bys/query_group_bys_resource_spec.rb index 84649a70f4..5fe61ae976 100644 --- a/spec/requests/api/v3/queries/group_bys/query_group_bys_resource_spec.rb +++ b/spec/requests/api/v3/queries/group_bys/query_group_bys_resource_spec.rb @@ -41,8 +41,8 @@ describe 'API v3 Query Group By resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do diff --git a/spec/requests/api/v3/queries/operators/query_operators_resource_spec.rb b/spec/requests/api/v3/queries/operators/query_operators_resource_spec.rb index 15ff6938eb..16b5fcbfbc 100644 --- a/spec/requests/api/v3/queries/operators/query_operators_resource_spec.rb +++ b/spec/requests/api/v3/queries/operators/query_operators_resource_spec.rb @@ -41,8 +41,8 @@ describe 'API v3 Query Operator resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do diff --git a/spec/requests/api/v3/queries/order/query_order_api_spec.rb b/spec/requests/api/v3/queries/order/query_order_api_spec.rb index 3d14d3d027..916a6b5763 100644 --- a/spec/requests/api/v3/queries/order/query_order_api_spec.rb +++ b/spec/requests/api/v3/queries/order/query_order_api_spec.rb @@ -56,7 +56,7 @@ describe "/api/v3/queries/:id/order", type: :request do expect(last_response.status).to eq 200 expect(body).to be_a Hash - expect(body).to eq( { wp1.id => 0, wp2.id => 8192 }.stringify_keys ) + expect(body).to eq({ wp1.id => 0, wp2.id => 8192 }.stringify_keys) end end diff --git a/spec/requests/api/v3/queries/query_resource_spec.rb b/spec/requests/api/v3/queries/query_resource_spec.rb index 047c2235ff..39377ce65e 100644 --- a/spec/requests/api/v3/queries/query_resource_spec.rb +++ b/spec/requests/api/v3/queries/query_resource_spec.rb @@ -232,7 +232,7 @@ describe 'API v3 Query resource', type: :request, content_type: :json do describe '#delete queries/:id' do let(:path) { api_v3_paths.query query.id } - let(:permissions) { [:view_work_packages, :manage_public_queries] } + let(:permissions) { %i[view_work_packages manage_public_queries] } before do delete path @@ -308,7 +308,7 @@ describe 'API v3 Query resource', type: :request, content_type: :json do describe 'public queries' do context 'user with permission to manage public queries' do - let(:permissions) { [:view_work_packages, :manage_public_queries] } + let(:permissions) { %i[view_work_packages manage_public_queries] } context 'when starring an unstarred query' do it 'should respond with 200' do @@ -350,7 +350,7 @@ describe 'API v3 Query resource', type: :request, content_type: :json do describe 'private queries' do context 'user with permission to save queries' do let(:query) { FactoryBot.create(:private_query, project: project, user: current_user) } - let(:permissions) { [:view_work_packages, :save_queries] } + let(:permissions) { %i[view_work_packages save_queries] } context 'starring his own query' do it 'should respond with 200' do @@ -386,7 +386,7 @@ describe 'API v3 Query resource', type: :request, content_type: :json do let(:query) { FactoryBot.create(:public_query, project: project) } context 'user with permission to manage public queries' do - let(:permissions) { [:view_work_packages, :manage_public_queries] } + let(:permissions) { %i[view_work_packages manage_public_queries] } context 'when unstarring a starred query' do before(:each) do @@ -443,7 +443,7 @@ describe 'API v3 Query resource', type: :request, content_type: :json do describe 'private queries' do context 'user with permission to save queries' do let(:query) { FactoryBot.create(:private_query, project: project, user: current_user) } - let(:permissions) { [:view_work_packages, :save_queries] } + let(:permissions) { %i[view_work_packages save_queries] } before(:each) do patch unstar_path end diff --git a/spec/requests/api/v3/queries/schemas/query_filter_instance_schema_resource_spec.rb b/spec/requests/api/v3/queries/schemas/query_filter_instance_schema_resource_spec.rb index 231802c062..f444482d6b 100644 --- a/spec/requests/api/v3/queries/schemas/query_filter_instance_schema_resource_spec.rb +++ b/spec/requests/api/v3/queries/schemas/query_filter_instance_schema_resource_spec.rb @@ -44,8 +44,8 @@ describe 'API v3 Query Filter Schema resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do @@ -76,8 +76,8 @@ describe 'API v3 Query Filter Schema resource', type: :request do end describe '#get queries/filter_instance_schemas' do - [:global, - :project].each do |current_path| + %i[global + project].each do |current_path| context current_path do let(:path) { send "#{current_path}_path".to_sym } diff --git a/spec/requests/api/v3/queries/schemas/query_schema_resource_spec.rb b/spec/requests/api/v3/queries/schemas/query_schema_resource_spec.rb index 48343e2f70..ae8720ca7a 100644 --- a/spec/requests/api/v3/queries/schemas/query_schema_resource_spec.rb +++ b/spec/requests/api/v3/queries/schemas/query_schema_resource_spec.rb @@ -38,8 +38,8 @@ describe 'API v3 Query Schema resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do diff --git a/spec/requests/api/v3/queries/sort_bys/query_sort_bys_resource_spec.rb b/spec/requests/api/v3/queries/sort_bys/query_sort_bys_resource_spec.rb index fb9432b937..008c20a580 100644 --- a/spec/requests/api/v3/queries/sort_bys/query_sort_bys_resource_spec.rb +++ b/spec/requests/api/v3/queries/sort_bys/query_sort_bys_resource_spec.rb @@ -42,8 +42,8 @@ describe 'API v3 Query Sort Bys resource', type: :request do let(:permissions) { [:view_work_packages] } let(:user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end before do diff --git a/spec/requests/api/v3/queries/update_query_spec.rb b/spec/requests/api/v3/queries/update_query_spec.rb index ada6a2f4b9..6a90d14991 100644 --- a/spec/requests/api/v3/queries/update_query_spec.rb +++ b/spec/requests/api/v3/queries/update_query_spec.rb @@ -134,7 +134,7 @@ describe "PATCH /api/v3/queries/:id", type: :request do expect(query.group_by_column.name).to eq :assigned_to expect(query.sort_criteria).to eq [["id", "desc"], ["assigned_to", "asc"]] - expect(query.columns.map(&:name)).to eq [:id, :subject, :status, :assigned_to] + expect(query.columns.map(&:name)).to eq %i[id subject status assigned_to] expect(query.project).to eq project expect(query.is_public).to eq true expect(query.display_sums).to eq false diff --git a/spec/requests/api/v3/rack_deflater_spec.rb b/spec/requests/api/v3/rack_deflater_spec.rb index 8b70c10f5e..85397a041d 100644 --- a/spec/requests/api/v3/rack_deflater_spec.rb +++ b/spec/requests/api/v3/rack_deflater_spec.rb @@ -43,7 +43,7 @@ describe Rack::Deflater, type: :request do etag = last_response.headers['Etag'] content_length = last_response.headers['Content-Length'].to_i - header "Accept-Encoding", "gzip" + header "Accept-Encoding", "gzip" get api_v3_paths.configuration expect(last_response.headers['Etag']).to eql etag diff --git a/spec/requests/api/v3/render_resource_spec.rb b/spec/requests/api/v3/render_resource_spec.rb index 3d58d1741f..6afea6d914 100644 --- a/spec/requests/api/v3/render_resource_spec.rb +++ b/spec/requests/api/v3/render_resource_spec.rb @@ -80,11 +80,11 @@ describe 'API v3 Render resource', type: :request do let(:params) { "Hello World! Have a look at ##{work_package.id}" } let(:id) { work_package.id } let(:href) { "/work_packages/#{id}" } - let(:text) { + let(:text) do '

    Hello World! Have a look at ##{id}

    " - } + end context 'with work package context' do let(:context) { api_v3_paths.work_package work_package.id } @@ -103,9 +103,9 @@ describe 'API v3 Render resource', type: :request do describe 'invalid' do context 'content type' do let(:content_type) { 'application/json' } - let(:params) { + let(:params) do { 'text' => "Hello World! Have a look at ##{work_package.id}" }.to_json - } + end it_behaves_like 'unsupported content type', I18n.t('api_v3.errors.invalid_content_type', diff --git a/spec/requests/api/v3/repositories/revisions_by_work_package_resource_spec.rb b/spec/requests/api/v3/repositories/revisions_by_work_package_resource_spec.rb index 951ec64ac8..96f797e2a5 100644 --- a/spec/requests/api/v3/repositories/revisions_by_work_package_resource_spec.rb +++ b/spec/requests/api/v3/repositories/revisions_by_work_package_resource_spec.rb @@ -34,14 +34,14 @@ describe 'API v3 Revisions by work package resource', type: :request do include API::V3::Utilities::PathHelper include FileHelpers - let(:current_user) { + let(:current_user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) - } + member_in_project: project, + member_through_role: role) + end let(:project) { FactoryBot.create(:project, public: false) } let(:role) { FactoryBot.create(:role, permissions: permissions) } - let(:permissions) { [:view_work_packages, :view_changesets] } + let(:permissions) { %i[view_work_packages view_changesets] } let(:repository) { FactoryBot.create(:repository_subversion, project: project) } let(:work_package) { FactoryBot.create(:work_package, author: current_user, project: project) } let(:revisions) { [] } @@ -56,7 +56,7 @@ describe 'API v3 Revisions by work package resource', type: :request do let(:get_path) { api_v3_paths.work_package_revisions work_package.id } before do - revisions.each do |rev| rev.save! end + revisions.each { |rev| rev.save! } get get_path end @@ -66,15 +66,13 @@ describe 'API v3 Revisions by work package resource', type: :request do it_behaves_like 'API V3 collection response', 0, 0, 'Revision' - context 'with existing revisions' do - let(:revisions) { + let(:revisions) do FactoryBot.build_list(:changeset, - 5, - comments: "This commit references ##{work_package.id}", - repository: repository - ) - } + 5, + comments: "This commit references ##{work_package.id}", + repository: repository) + end it_behaves_like 'API V3 collection response', 5, 5, 'Revision' @@ -96,20 +94,19 @@ describe 'API v3 Revisions by work package resource', type: :request do describe 'revisions linked from another project' do let(:subproject) { FactoryBot.create(:project, parent: project) } let(:repository) { FactoryBot.create(:repository_subversion, project: subproject) } - let!(:revisions) { + let!(:revisions) do FactoryBot.build_list(:changeset, - 2, - comments: "This commit references ##{work_package.id}", - repository: repository - ) - } + 2, + comments: "This commit references ##{work_package.id}", + repository: repository) + end context 'with permissions in subproject' do - let(:current_user) { + let(:current_user) do FactoryBot.create(:user, - member_in_projects: [project, subproject], - member_through_role: role) - } + member_in_projects: [project, subproject], + member_through_role: role) + end it_behaves_like 'API V3 collection response', 2, 2, 'Revision' end diff --git a/spec/requests/api/v3/repositories/revisions_resource_spec.rb b/spec/requests/api/v3/repositories/revisions_resource_spec.rb index 7e315e6c8d..1ffffb38de 100644 --- a/spec/requests/api/v3/repositories/revisions_resource_spec.rb +++ b/spec/requests/api/v3/repositories/revisions_resource_spec.rb @@ -34,26 +34,25 @@ describe 'API v3 Revisions resource', type: :request do include Capybara::RSpecMatchers include API::V3::Utilities::PathHelper - let(:revision) { + let(:revision) do FactoryBot.create(:changeset, - repository: repository, - comments: 'Some commit message', - committer: 'foo bar ' - ) - } - let(:repository) { + repository: repository, + comments: 'Some commit message', + committer: 'foo bar ') + end + let(:repository) do FactoryBot.create(:repository_subversion, project: project) - } - let(:project) { + end + let(:project) do FactoryBot.create(:project, identifier: 'test_project', public: false) - } - let(:role) { + end + let(:role) do FactoryBot.create(:role, - permissions: [:view_changesets]) - } - let(:current_user) { + permissions: [:view_changesets]) + end + let(:current_user) do FactoryBot.create(:user, member_in_project: project, member_through_role: role) - } + end let(:unauthorized_user) { FactoryBot.create(:user) } diff --git a/spec/requests/api/v3/root_resource_spec.rb b/spec/requests/api/v3/root_resource_spec.rb index a82a581970..4b6113f30f 100644 --- a/spec/requests/api/v3/root_resource_spec.rb +++ b/spec/requests/api/v3/root_resource_spec.rb @@ -33,9 +33,9 @@ describe 'API v3 Root resource' do include Rack::Test::Methods include API::V3::Utilities::PathHelper - let(:current_user) { + let(:current_user) do FactoryBot.create(:user, member_in_project: project, member_through_role: role) - } + end let(:role) { FactoryBot.create(:role, permissions: []) } let(:project) { FactoryBot.create(:project, public: false) } diff --git a/spec/requests/api/v3/support/api_v3_collection_response.rb b/spec/requests/api/v3/support/api_v3_collection_response.rb index 8f830ea4cf..143debd7c5 100644 --- a/spec/requests/api/v3/support/api_v3_collection_response.rb +++ b/spec/requests/api/v3/support/api_v3_collection_response.rb @@ -51,7 +51,6 @@ shared_examples_for 'API V3 collection response' do |total, count, type| it 'returns a collection successfully' do aggregate_failures do - expect(last_response.status).to eql(200) expect(subject).to be_json_eql('Collection'.to_json).at_path('_type') expect(subject).to be_json_eql(count_number.to_json).at_path('count') diff --git a/spec/requests/api/v3/support/response_examples.rb b/spec/requests/api/v3/support/response_examples.rb index 217ad4f6cd..eb2a0dbde6 100644 --- a/spec/requests/api/v3/support/response_examples.rb +++ b/spec/requests/api/v3/support/response_examples.rb @@ -29,9 +29,9 @@ require 'spec_helper' shared_examples_for 'error response' do |code, id, provided_message = nil| - let(:expected_message) { + let(:expected_message) do provided_message || message - } + end it 'has the expected status code' do expect(last_response.status).to eq(code) @@ -52,7 +52,7 @@ shared_examples_for 'error response' do |code, id, provided_message = nil| it { expect(subject['message']).to include(expected_message) } it 'includes punctuation' do - expect(subject['message']).to match(/(\.|\?|\!)\z/) + expect(subject['message']).to match(/(\.|\?|!)\z/) end end end @@ -210,8 +210,10 @@ shared_examples_for 'multiple errors of the same type with messages' do end before do - raise "Need to have 'message' defined to state\ - which message is expected".squish unless defined?(message) + unless defined?(message) + raise "Need to have 'message' defined to state\ + which message is expected".squish + end end it { expect(actual_messages).to match_array(Array(message)) } diff --git a/spec/requests/api/v3/types/type_resource_spec.rb b/spec/requests/api/v3/types/type_resource_spec.rb index 9c9616b6c0..b02540f117 100644 --- a/spec/requests/api/v3/types/type_resource_spec.rb +++ b/spec/requests/api/v3/types/type_resource_spec.rb @@ -37,8 +37,8 @@ describe 'API v3 Type resource' do let(:project) { FactoryBot.create(:project, no_types: true, public: false) } let(:current_user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let!(:types) { FactoryBot.create_list(:type, 4) } diff --git a/spec/requests/api/v3/types/types_by_project_resource_spec.rb b/spec/requests/api/v3/types/types_by_project_resource_spec.rb index 679c224b7d..1d63c516b7 100644 --- a/spec/requests/api/v3/types/types_by_project_resource_spec.rb +++ b/spec/requests/api/v3/types/types_by_project_resource_spec.rb @@ -38,8 +38,8 @@ describe '/api/v3/projects/:id/types' do let(:requested_project) { project } let(:current_user) do FactoryBot.create(:user, - member_in_project: project, - member_through_role: role) + member_in_project: project, + member_through_role: role) end let!(:irrelevant_types) { FactoryBot.create_list(:type, 4) } diff --git a/spec/requests/api/v3/user/create_user_common_examples.rb b/spec/requests/api/v3/user/create_user_common_examples.rb index 87b7ff9125..9403287010 100644 --- a/spec/requests/api/v3/user/create_user_common_examples.rb +++ b/spec/requests/api/v3/user/create_user_common_examples.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -79,12 +80,12 @@ shared_examples 'create user request flow' do describe 'invited status' do let(:status) { 'invited' } - let(:invitation_request) { + let(:invitation_request) do { status: status, email: 'foo@example.org' } - } + end describe 'invitation successful' do before do @@ -152,4 +153,4 @@ shared_examples 'create user request flow' do .to include 'Status is not a valid status for new users.' end end -end \ No newline at end of file +end diff --git a/spec/requests/api/v3/user/create_user_resource_spec.rb b/spec/requests/api/v3/user/create_user_resource_spec.rb index 1e80be778f..6d5338edaa 100644 --- a/spec/requests/api/v3/user/create_user_resource_spec.rb +++ b/spec/requests/api/v3/user/create_user_resource_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -34,7 +35,7 @@ describe ::API::V3::Users::UsersAPI, type: :request do include API::V3::Utilities::PathHelper let(:path) { api_v3_paths.users } - let(:parameters) { + let(:parameters) do { status: 'active', login: 'myusername', @@ -43,7 +44,7 @@ describe ::API::V3::Users::UsersAPI, type: :request do email: 'foobar@example.org', language: 'de' } - } + end before do login_as(current_user) @@ -129,7 +130,7 @@ describe ::API::V3::Users::UsersAPI, type: :request do end describe 'active status' do - let(:parameters) { + let(:parameters) do { status: 'active', login: 'myusername', @@ -138,7 +139,7 @@ describe ::API::V3::Users::UsersAPI, type: :request do email: 'foobar@example.org', language: 'de' } - } + end context 'with identity_url' do let(:identity_url) { 'google:3289272389298' } diff --git a/spec/requests/api/v3/user/update_user_resource_spec.rb b/spec/requests/api/v3/user/update_user_resource_spec.rb index 2a65f33845..7ef94ac5a0 100644 --- a/spec/requests/api/v3/user/update_user_resource_spec.rb +++ b/spec/requests/api/v3/user/update_user_resource_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -42,7 +43,7 @@ describe ::API::V3::Users::UsersAPI, type: :request do end def send_request - header "Content-Type", "application/json" + header "Content-Type", "application/json" patch path, parameters.to_json end @@ -124,7 +125,6 @@ describe ::API::V3::Users::UsersAPI, type: :request do expect(last_response.status).to eql(404) end end - end describe 'user with global add_user permission' do diff --git a/spec/requests/api/v3/user/user_resource_spec.rb b/spec/requests/api/v3/user/user_resource_spec.rb index 98a40a4902..65a2f40eb4 100644 --- a/spec/requests/api/v3/user/user_resource_spec.rb +++ b/spec/requests/api/v3/user/user_resource_spec.rb @@ -94,12 +94,12 @@ describe 'API v3 User resource', context 'on filtering for name' do let(:get_path) do - filter = [{'name' => { + filter = [{ 'name' => { 'operator' => '~', 'values' => [user.name] - }}] + } }] - "#{api_v3_paths.users}?#{{filters: filter.to_json}.to_query}" + "#{api_v3_paths.users}?#{{ filters: filter.to_json }.to_query}" end it 'contains the filtered user in the response' do @@ -123,7 +123,7 @@ describe 'API v3 User resource', let(:get_path) do sort = [['name', 'desc']] - "#{api_v3_paths.users}?#{{sortBy: sort.to_json}.to_query}" + "#{api_v3_paths.users}?#{{ sortBy: sort.to_json }.to_query}" end it 'contains the first user as the first element' do @@ -141,12 +141,12 @@ describe 'API v3 User resource', context 'on an invalid filter' do let(:get_path) do - filter = [{'name' => { + filter = [{ 'name' => { 'operator' => 'a', 'values' => [user.name] - }}] + } }] - "#{api_v3_paths.users}?#{{filters: filter.to_json}.to_query}" + "#{api_v3_paths.users}?#{{ filters: filter.to_json }.to_query}" end it 'returns an error' do diff --git a/spec/requests/api/v3/user/userlock_resource_spec.rb b/spec/requests/api/v3/user/userlock_resource_spec.rb index a495850562..f30c3e40bd 100644 --- a/spec/requests/api/v3/user/userlock_resource_spec.rb +++ b/spec/requests/api/v3/user/userlock_resource_spec.rb @@ -63,9 +63,9 @@ describe 'API v3 UserLock resource', type: :request, content_type: :json do end context 'user account is incompatible' do - let(:user) { + let(:user) do FactoryBot.create(:user, status: User.statuses[:registered]) - } + end it 'should fail for invalid transitions' do expect(subject.status).to eq(400) end @@ -110,9 +110,9 @@ describe 'API v3 UserLock resource', type: :request, content_type: :json do end context 'user account is incompatible' do - let(:user) { + let(:user) do FactoryBot.create(:user, status: User.statuses[:registered]) - } + end it 'should fail for invalid transitions' do expect(subject.status).to eq(400) end diff --git a/spec/requests/api/v3/versions/available_projects_resource_spec.rb b/spec/requests/api/v3/versions/available_projects_resource_spec.rb index ed008c0810..1b2b5bcca3 100644 --- a/spec/requests/api/v3/versions/available_projects_resource_spec.rb +++ b/spec/requests/api/v3/versions/available_projects_resource_spec.rb @@ -59,7 +59,7 @@ describe 'API v3 members available projects resource', type: :request do user: current_user) end end - #let(:membered_project) do + # let(:membered_project) do # FactoryBot.create(:project).tap do |p| # FactoryBot.create(:member, # roles: [FactoryBot.create(:role, permissions: permissions)], @@ -71,7 +71,7 @@ describe 'API v3 members available projects resource', type: :request do # project: p, # user: other_user) # end - #end + # end let(:unauthorized_project) do FactoryBot.create(:public_project) end diff --git a/spec/requests/api/v3/versions/project_resource_spec.rb b/spec/requests/api/v3/versions/project_resource_spec.rb index e32f54aeea..9f1c8932a0 100644 --- a/spec/requests/api/v3/versions/project_resource_spec.rb +++ b/spec/requests/api/v3/versions/project_resource_spec.rb @@ -61,13 +61,13 @@ describe "API v3 version's projects resource" do # this is to be included FactoryBot.create(:member, user: current_user, - project: project2, - roles: [role]) + project: project2, + roles: [role]) # this is to be included as the user is a member of the project, the # lack of permissions is irrelevant. FactoryBot.create(:member, user: current_user, - project: project3, - roles: [role_without_permissions]) + project: project3, + roles: [role_without_permissions]) # project4 should NOT be included project4 diff --git a/spec/requests/api/v3/watcher_resource_spec.rb b/spec/requests/api/v3/watcher_resource_spec.rb index 6d7dee0fd6..d96ff764ca 100644 --- a/spec/requests/api/v3/watcher_resource_spec.rb +++ b/spec/requests/api/v3/watcher_resource_spec.rb @@ -242,7 +242,7 @@ describe 'API v3 Watcher resource', type: :request, content_type: :json do let(:permissions) { %i[add_work_package_watchers view_work_packages] } let(:available_watchers_path) { api_v3_paths.available_watchers work_package.id } let(:returned_user_ids) do - JSON.parse(subject.body)['_embedded']['elements'].map {|user| user['id'] } + JSON.parse(subject.body)['_embedded']['elements'].map { |user| user['id'] } end before do diff --git a/spec/requests/api/v3/work_package_resource_spec.rb b/spec/requests/api/v3/work_package_resource_spec.rb index d0dca06ff6..f022b1b0fe 100644 --- a/spec/requests/api/v3/work_package_resource_spec.rb +++ b/spec/requests/api/v3/work_package_resource_spec.rb @@ -324,7 +324,6 @@ describe 'API v3 Work package resource', FactoryBot.create(:work_package, project_id: project.id, description: 'lorem ipsum').tap do |wp| - FactoryBot.create(:relation, relates: 1, from: wp, to: directly_related_wp) FactoryBot.create(:relation, relates: 1, from: directly_related_wp, to: transitively_related_wp) end @@ -652,7 +651,7 @@ describe 'API v3 Work package resource', context 'valid type changing custom fields' do let(:custom_field) { FactoryBot.create(:work_package_custom_field) } - let(:custom_field_parameter) { { :"customField#{custom_field.id}" => true } } + let(:custom_field_parameter) { { "customField#{custom_field.id}": true } } let(:params) { valid_params.merge(type_parameter).merge(custom_field_parameter) } before do @@ -731,7 +730,7 @@ describe 'API v3 Work package resource', context 'with a custom field defined on the target project' do let(:custom_field) { FactoryBot.create(:work_package_custom_field) } - let(:custom_field_parameter) { { :"customField#{custom_field.id}" => true } } + let(:custom_field_parameter) { { "customField#{custom_field.id}": true } } let(:params) { valid_params.merge(project_parameter).merge(custom_field_parameter) } before do @@ -796,7 +795,7 @@ describe 'API v3 Work package resource', describe 'valid' do shared_examples_for 'valid user assignment' do - let(:title) { "#{assigned_user.name}".to_json } + let(:title) { assigned_user.name.to_s.to_json } it { expect(response.status).to eq(200) } diff --git a/spec/requests/api/v3/work_packages/available_projects_on_edit_api_spec.rb b/spec/requests/api/v3/work_packages/available_projects_on_edit_api_spec.rb index d66f877680..85cbd8d581 100644 --- a/spec/requests/api/v3/work_packages/available_projects_on_edit_api_spec.rb +++ b/spec/requests/api/v3/work_packages/available_projects_on_edit_api_spec.rb @@ -33,8 +33,8 @@ describe 'API::V3::WorkPackages::AvailableProjectsOnEditAPI', type: :request do include API::V3::Utilities::PathHelper let(:edit_role) do - FactoryBot.create(:role, permissions: [:edit_work_packages, - :view_work_packages]) + FactoryBot.create(:role, permissions: %i[edit_work_packages + view_work_packages]) end let(:move_role) do FactoryBot.create(:role, permissions: [:move_work_packages]) @@ -44,13 +44,13 @@ describe 'API::V3::WorkPackages::AvailableProjectsOnEditAPI', type: :request do let(:work_package) { FactoryBot.create(:work_package, project: project) } let(:user) do user = FactoryBot.create(:user, - member_in_project: project, - member_through_role: edit_role) + member_in_project: project, + member_through_role: edit_role) FactoryBot.create(:member, - user: user, - project: target_project, - roles: [move_role]) + user: user, + project: target_project, + roles: [move_role]) user end diff --git a/spec/requests/api/v3/work_packages/available_relation_candidates_spec.rb b/spec/requests/api/v3/work_packages/available_relation_candidates_spec.rb index a18d7338e1..863a3e536b 100644 --- a/spec/requests/api/v3/work_packages/available_relation_candidates_spec.rb +++ b/spec/requests/api/v3/work_packages/available_relation_candidates_spec.rb @@ -83,7 +83,6 @@ describe ::API::V3::Relations::RelationRepresenter, type: :request do context "without cross project relations", with_settings: { cross_project_work_package_relations: false } do - describe "relation candidates for wp_1 (in hierarchy)" do it "should return an empty list" do # as relations to ancestors or descendents is not allowed expect(result["count"]).to eq 0 @@ -117,7 +116,6 @@ describe ::API::V3::Relations::RelationRepresenter, type: :request do context "with cross project relations", with_settings: { cross_project_work_package_relations: true } do - describe "relation candidates for wp_1 (in hierarchy)" do let(:href) { "/api/v3/work_packages/#{wp_1.id}/available_relation_candidates?query=WP" } diff --git a/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb b/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb index b588755adc..0ad23b007d 100644 --- a/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/create_project_form_resource_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb b/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb index fc83d99d2b..529b69a808 100644 --- a/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/work_packages_by_project_resource_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -290,7 +291,7 @@ describe API::V3::WorkPackages::WorkPackagesByProjectAPI, type: :request do end describe '#post' do - let(:permissions) { [:add_work_packages, :view_project] } + let(:permissions) { %i[add_work_packages view_project] } let(:status) { FactoryBot.build(:status, is_default: true) } let(:priority) { FactoryBot.build(:priority, is_default: true) } let(:parameters) do @@ -314,7 +315,7 @@ describe API::V3::WorkPackages::WorkPackagesByProjectAPI, type: :request do end context 'notifications' do - let(:permissions) { [:add_work_packages, :view_project, :view_work_packages] } + let(:permissions) { %i[add_work_packages view_project view_work_packages] } it 'sends a mail by default' do expect(DeliverWorkPackageNotificationJob).to have_been_enqueued diff --git a/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb b/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb index 3022d927ff..28cc6be278 100644 --- a/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb +++ b/spec/requests/api/v3/work_packages/work_packages_schemas_resource_spec.rb @@ -142,7 +142,7 @@ describe API::V3::WorkPackages::Schema::WorkPackageSchemasAPI, type: :request do end it 'should set a weak ETag' do - expect(last_response.headers['ETag']).to match(/W\/\"\w+\"/) + expect(last_response.headers['ETag']).to match(/W\/"\w+"/) end it 'caches the response' do diff --git a/spec/requests/auth/token_based_access_spec.rb b/spec/requests/auth/token_based_access_spec.rb index 6515514325..2426ac6b9a 100644 --- a/spec/requests/auth/token_based_access_spec.rb +++ b/spec/requests/auth/token_based_access_spec.rb @@ -48,7 +48,7 @@ describe 'Token based access', type: :rails_request, with_settings: { login_requ # access is possible with a token get "/work_packages/#{work_package.id}.atom?key=#{rss_key}" expect(response.body) - .to include("OpenProject - #{work_package.to_s}") + .to include("OpenProject - #{work_package}") # but for the next request, the user is not logged in get "/work_packages/#{work_package.id}" diff --git a/spec/requests/oauth/client_credentials_flow_spec.rb b/spec/requests/oauth/client_credentials_flow_spec.rb index 30fd91de74..e8b4126ea7 100644 --- a/spec/requests/oauth/client_credentials_flow_spec.rb +++ b/spec/requests/oauth/client_credentials_flow_spec.rb @@ -35,7 +35,7 @@ describe 'OAuth client credentials flow', type: :request do let!(:application) { FactoryBot.create(:oauth_application, client_credentials_user_id: user_id, name: 'Cool API app!') } let(:client_secret) { application.plaintext_secret } - let(:access_token) { + let(:access_token) do response = post '/oauth/token', grant_type: 'client_credentials', scope: 'api_v3', @@ -45,7 +45,7 @@ describe 'OAuth client credentials flow', type: :request do expect(response).to be_successful body = JSON.parse(response.body) body['access_token'] - } + end subject do # Perform request with it diff --git a/spec/routing/enterprise_routing_spec.rb b/spec/routing/enterprise_routing_spec.rb index 3020824f69..97f634b219 100644 --- a/spec/routing/enterprise_routing_spec.rb +++ b/spec/routing/enterprise_routing_spec.rb @@ -33,7 +33,7 @@ describe EnterprisesController, type: :routing do it 'should connect GET /admin/enterprise to enterprises#show' do allow(OpenProject::Configuration).to receive(:ee_manager_visible?).and_return(true) expect(get('/admin/enterprise')).to route_to(controller: 'enterprises', - action: 'show') + action: 'show') end end @@ -44,7 +44,7 @@ describe EnterprisesController, type: :routing do # Think of cloud solutions for instance. allow(OpenProject::Configuration).to receive(:ee_manager_visible?).and_return(false) expect(get('/admin/enterprise')).not_to route_to(controller: 'enterprises', - action: 'show') + action: 'show') end end end diff --git a/spec/routing/project_settings_routing_spec.rb b/spec/routing/project_settings_routing_spec.rb index 5d0674122f..50671babcd 100644 --- a/spec/routing/project_settings_routing_spec.rb +++ b/spec/routing/project_settings_routing_spec.rb @@ -32,50 +32,50 @@ describe ProjectSettingsController, type: :routing do describe 'show' do it do expect(get('/projects/123/settings/generic')).to route_to( - controller: 'project_settings/generic', action: 'show', id: '123' - ) + controller: 'project_settings/generic', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/modules')).to route_to( - controller: 'project_settings/modules', action: 'show', id: '123' - ) + controller: 'project_settings/modules', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/custom_fields')).to route_to( - controller: 'project_settings/custom_fields', action: 'show', id: '123' - ) + controller: 'project_settings/custom_fields', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/versions')).to route_to( - controller: 'project_settings/versions', action: 'show', id: '123' - ) + controller: 'project_settings/versions', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/categories')).to route_to( - controller: 'project_settings/categories', action: 'show', id: '123' - ) + controller: 'project_settings/categories', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/repository')).to route_to( - controller: 'project_settings/repository', action: 'show', id: '123' - ) + controller: 'project_settings/repository', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/activities')).to route_to( - controller: 'project_settings/activities', action: 'show', id: '123' - ) + controller: 'project_settings/activities', action: 'show', id: '123' + ) end it do expect(get('/projects/123/settings/types')).to route_to( - controller: 'project_settings/types', action: 'show', id: '123' - ) + controller: 'project_settings/types', action: 'show', id: '123' + ) end end diff --git a/spec/routing/status_routing_spec.rb b/spec/routing/status_routing_spec.rb index c0d94005c5..391505250a 100644 --- a/spec/routing/status_routing_spec.rb +++ b/spec/routing/status_routing_spec.rb @@ -53,7 +53,8 @@ describe StatusesController, type: :routing do it do expect(post('/statuses/update_work_package_done_ratio')).to route_to( controller: 'statuses', - action: 'update_work_package_done_ratio') + action: 'update_work_package_done_ratio' + ) end end end diff --git a/spec/routing/work_packages_spec.rb b/spec/routing/work_packages_spec.rb index 30658f8dc3..d3b2120330 100644 --- a/spec/routing/work_packages_spec.rb +++ b/spec/routing/work_packages_spec.rb @@ -91,7 +91,6 @@ describe WorkPackagesController, type: :routing do id: '1') end - it 'should connect GET /work_packages/:work_package_id/moves/new to work_packages/moves#new' do expect(get('/work_packages/1/move/new')).to route_to(controller: 'work_packages/moves', action: 'new', diff --git a/spec/security/active_support_to_json_spec.rb b/spec/security/active_support_to_json_spec.rb index 5b8a9c17d5..0626d84dca 100644 --- a/spec/security/active_support_to_json_spec.rb +++ b/spec/security/active_support_to_json_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/seeders/setting_seeder_spec.rb b/spec/seeders/setting_seeder_spec.rb index a02b6d9d58..cb536e5ec9 100644 --- a/spec/seeders/setting_seeder_spec.rb +++ b/spec/seeders/setting_seeder_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/add_work_package_note_service_spec.rb b/spec/services/add_work_package_note_service_spec.rb index 0d5720db48..49955eea4d 100644 --- a/spec/services/add_work_package_note_service_spec.rb +++ b/spec/services/add_work_package_note_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/api/v3/parse_query_params_service_spec.rb b/spec/services/api/v3/parse_query_params_service_spec.rb index 45d5541add..3636672aa6 100644 --- a/spec/services/api/v3/parse_query_params_service_spec.rb +++ b/spec/services/api/v3/parse_query_params_service_spec.rb @@ -150,7 +150,7 @@ describe ::API::V3::ParseQueryParamsService, context 'with display_representation' do it_behaves_like 'transforms' do let(:params) { { displayRepresentation: 'cards' } } - let(:expected) { { display_representation:'cards' } } + let(:expected) { { display_representation: 'cards' } } end end diff --git a/spec/services/api/v3/update_query_from_v3_params_service_spec.rb b/spec/services/api/v3/update_query_from_v3_params_service_spec.rb index e4a7c4b4d4..0041f924b0 100644 --- a/spec/services/api/v3/update_query_from_v3_params_service_spec.rb +++ b/spec/services/api/v3/update_query_from_v3_params_service_spec.rb @@ -30,7 +30,6 @@ require 'spec_helper' describe ::API::V3::UpdateQueryFromV3ParamsService, type: :model do - let(:user) { FactoryBot.build_stubbed(:user) } let(:query) { FactoryBot.build_stubbed(:query) } diff --git a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb index 6f7659febf..6410e1fb6a 100644 --- a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb +++ b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb @@ -41,7 +41,6 @@ describe ::API::V3::WorkPackageCollectionFromQueryService, allow(query) .to receive(:manually_sorted?) .and_return(query_manually_sorted) - end end let(:query_manually_sorted) { false } @@ -86,7 +85,6 @@ describe ::API::V3::WorkPackageCollectionFromQueryService, :per_page, :embed_schemas, :current_user) do - def initialize(work_packages, self_link:, query:, @@ -117,7 +115,6 @@ describe ::API::V3::WorkPackageCollectionFromQueryService, :query, :sums, :current_user) do - def initialize(group, count, query:, diff --git a/spec/services/attachments/create_service_spec.rb b/spec/services/attachments/create_service_spec.rb index adb1e188c1..bebda3ca5b 100644 --- a/spec/services/attachments/create_service_spec.rb +++ b/spec/services/attachments/create_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/services/authentication/omniauth_service_spec.rb b/spec/services/authentication/omniauth_service_spec.rb index 9daa455312..4c959dacff 100644 --- a/spec/services/authentication/omniauth_service_spec.rb +++ b/spec/services/authentication/omniauth_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -37,8 +38,7 @@ describe Authentication::OmniauthService do info: { name: 'foo', email: 'foo@bar.com', first_name: 'foo', - last_name: 'bar' - } + last_name: 'bar' } ) end let(:controller) { double('Controller', session: session_stub) } @@ -111,7 +111,6 @@ describe Authentication::OmniauthService do context 'without remapping allowed', with_settings: { oauth_allow_remapping_of_existing_users?: false } do - it 'does not look for the user by login' do # Regular find expect(User) diff --git a/spec/services/authorization/query_transformation_spec.rb b/spec/services/authorization/query_transformation_spec.rb index 2174e0b26b..6f9e5714f0 100644 --- a/spec/services/authorization/query_transformation_spec.rb +++ b/spec/services/authorization/query_transformation_spec.rb @@ -33,7 +33,7 @@ describe Authorization::QueryTransformation do let(:name) { 'name' } let(:after) { 'after' } let(:before) { 'before' } - let(:block) { -> (*args) { args } } + let(:block) { ->(*args) { args } } let(:instance) do described_class.new on, diff --git a/spec/services/authorization/query_transformations_spec.rb b/spec/services/authorization/query_transformations_spec.rb index 13a1670a00..6ca7d8fd7c 100644 --- a/spec/services/authorization/query_transformations_spec.rb +++ b/spec/services/authorization/query_transformations_spec.rb @@ -141,13 +141,13 @@ describe Authorization::QueryTransformations do args end - expected_order = [:transformation1, :transformation2] + expected_order = %i[transformation1 transformation2] - expect { + expect do instance.register(:on, :transformation2, before: [:transformation1]) do |*args| args.join(', ') end - }.to raise_error "Cannot sort #{expected_order} into the list of transformations" + end.to raise_error "Cannot sort #{expected_order} into the list of transformations" end end end diff --git a/spec/services/authorization/user_allowed_query_spec.rb b/spec/services/authorization/user_allowed_query_spec.rb index 2bd345f37b..492fec23ce 100644 --- a/spec/services/authorization/user_allowed_query_spec.rb +++ b/spec/services/authorization/user_allowed_query_spec.rb @@ -40,7 +40,7 @@ describe Authorization::UserAllowedQuery do let(:non_member_role) { FactoryBot.build(:non_member) } let(:member) do FactoryBot.build(:member, project: project, - roles: [role]) + roles: [role]) end let(:action) { :view_work_packages } diff --git a/spec/services/authorization/user_global_roles_query_spec.rb b/spec/services/authorization/user_global_roles_query_spec.rb index 3a0aecff20..5ac358bfd6 100644 --- a/spec/services/authorization/user_global_roles_query_spec.rb +++ b/spec/services/authorization/user_global_roles_query_spec.rb @@ -38,16 +38,16 @@ describe Authorization::UserGlobalRolesQuery do let(:role2) { FactoryBot.build(:role) } let(:anonymous_role) { FactoryBot.build(:anonymous_role) } let(:non_member) { FactoryBot.build(:non_member) } - let(:member) { + let(:member) do FactoryBot.build(:member, project: project, - roles: [role], - principal: user) - } - let(:member2) { + roles: [role], + principal: user) + end + let(:member2) do FactoryBot.build(:member, project: project2, - roles: [role2], - principal: user) - } + roles: [role2], + principal: user) + end let(:global_permission) { OpenProject::AccessControl.permissions.find { |p| p.global? } } let(:global_role) do FactoryBot.build(:global_role, diff --git a/spec/services/authorization/user_project_roles_query_spec.rb b/spec/services/authorization/user_project_roles_query_spec.rb index d9bc2756de..0048582daf 100644 --- a/spec/services/authorization/user_project_roles_query_spec.rb +++ b/spec/services/authorization/user_project_roles_query_spec.rb @@ -38,16 +38,16 @@ describe Authorization::UserProjectRolesQuery do let(:role2) { FactoryBot.build(:role) } let(:anonymous_role) { FactoryBot.build(:anonymous_role) } let(:non_member) { FactoryBot.build(:non_member) } - let(:member) { + let(:member) do FactoryBot.build(:member, project: project, - roles: [role], - principal: user) - } - let(:member2) { + roles: [role], + principal: user) + end + let(:member2) do FactoryBot.build(:member, project: project2, - roles: [role2], - principal: user) - } + roles: [role2], + principal: user) + end describe '.query' do before do diff --git a/spec/services/base/base_callable_spec.rb b/spec/services/base/base_callable_spec.rb index 9792d783e0..8ecca257bb 100644 --- a/spec/services/base/base_callable_spec.rb +++ b/spec/services/base/base_callable_spec.rb @@ -31,7 +31,7 @@ require 'spec_helper' describe ::BaseServices::BaseCallable, type: :model do let(:test_service) do Class.new(::BaseServices::BaseCallable) do - def perform(params) + def perform(_params) state.test = 'foo' ServiceResult.new(success: true, result: 'something') end @@ -44,7 +44,7 @@ describe ::BaseServices::BaseCallable, type: :model do let(:test_service2) do Class.new(::BaseServices::BaseCallable) do - def perform(params) + def perform(_params) state.test2 = 'foo' ServiceResult.new(success: true, result: 'something') end diff --git a/spec/services/create_type_service_spec.rb b/spec/services/create_type_service_spec.rb index ac2ead11ed..250f9a6d20 100644 --- a/spec/services/create_type_service_spec.rb +++ b/spec/services/create_type_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/custom_actions/update_work_package_service_spec.rb b/spec/services/custom_actions/update_work_package_service_spec.rb index 8cc5afe0c9..c7ddfcb674 100644 --- a/spec/services/custom_actions/update_work_package_service_spec.rb +++ b/spec/services/custom_actions/update_work_package_service_spec.rb @@ -205,7 +205,7 @@ describe CustomActions::UpdateWorkPackageService do allow(contract) .to receive(:errors) - .and_return(:base => ['invalid']) + .and_return(base: ['invalid']) work_package.lock_version = 200 diff --git a/spec/services/custom_fields/create_service_spec.rb b/spec/services/custom_fields/create_service_spec.rb index 9b62b50986..23a7d8165a 100644 --- a/spec/services/custom_fields/create_service_spec.rb +++ b/spec/services/custom_fields/create_service_spec.rb @@ -31,10 +31,8 @@ require 'spec_helper' require 'services/base_services/behaves_like_create_service' - describe CustomFields::CreateService, type: :model do it_behaves_like 'BaseServices create service' do - context 'when creating a project cf' do let(:model_instance) { FactoryBot.build_stubbed :project_custom_field } diff --git a/spec/services/messages/create_service_spec.rb b/spec/services/messages/create_service_spec.rb index c5b06442cd..a64345c942 100644 --- a/spec/services/messages/create_service_spec.rb +++ b/spec/services/messages/create_service_spec.rb @@ -31,7 +31,6 @@ require 'spec_helper' require 'services/base_services/behaves_like_create_service' - describe Messages::CreateService, type: :model do it_behaves_like 'BaseServices create service' end diff --git a/spec/services/notifications/journal_notification_service_spec.rb b/spec/services/notifications/journal_notification_service_spec.rb index a11732973c..02b0ba9e43 100644 --- a/spec/services/notifications/journal_notification_service_spec.rb +++ b/spec/services/notifications/journal_notification_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/notifications/journal_wp_mail_service_spec.rb b/spec/services/notifications/journal_wp_mail_service_spec.rb index 1de94681d3..aea18c8f78 100644 --- a/spec/services/notifications/journal_wp_mail_service_spec.rb +++ b/spec/services/notifications/journal_wp_mail_service_spec.rb @@ -69,7 +69,9 @@ describe Notifications::JournalWpMailService do work_package.journals.last end let(:send_mails) { true } - let(:notification_setting) { %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated) } + let(:notification_setting) do + %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated) + end def call described_class.call(journal, send_mails) diff --git a/spec/services/parse_schema_filter_params_service_spec.rb b/spec/services/parse_schema_filter_params_service_spec.rb index f81560f3d3..d2cfefee4e 100644 --- a/spec/services/parse_schema_filter_params_service_spec.rb +++ b/spec/services/parse_schema_filter_params_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rb index 9aa5d67664..cff0afd26b 100644 --- a/spec/services/projects/copy_service_integration_spec.rb +++ b/spec/services/projects/copy_service_integration_spec.rb @@ -34,7 +34,9 @@ describe Projects::CopyService, 'integration', type: :model do shared_let(:status_locked) { FactoryBot.create :status, is_readonly: true } shared_let(:source) { FactoryBot.create :project, enabled_module_names: %w[wiki work_package_tracking] } shared_let(:source_wp) { FactoryBot.create :work_package, project: source, subject: 'source wp' } - shared_let(:source_wp_locked) { FactoryBot.create :work_package, project: source, subject: 'source wp locked', status: status_locked } + shared_let(:source_wp_locked) do + FactoryBot.create :work_package, project: source, subject: 'source wp locked', status: status_locked + end shared_let(:source_query) { FactoryBot.create :query, project: source, name: 'My query' } shared_let(:source_category) { FactoryBot.create :category, project: source, name: 'Stock management' } shared_let(:source_version) { FactoryBot.create :version, project: source, name: 'Version A' } @@ -187,8 +189,9 @@ describe Projects::CopyService, 'integration', type: :model do let!(:user) { FactoryBot.create :user } let!(:another_role) { FactoryBot.create(:role) } - let!(:group) { FactoryBot.create :group, members: [user] - } + let!(:group) do + FactoryBot.create :group, members: [user] + end it 'will copy them as well' do source.add_member! group, another_role diff --git a/spec/services/projects/set_attributes_service_spec.rb b/spec/services/projects/set_attributes_service_spec.rb index 432533625b..cb0dfe14af 100644 --- a/spec/services/projects/set_attributes_service_spec.rb +++ b/spec/services/projects/set_attributes_service_spec.rb @@ -102,7 +102,7 @@ describe Projects::SetAttributesService, type: :model do end context 'identifier default value' do - context 'with a default identifier configured', with_settings: {sequential_project_identifiers: true} do + context 'with a default identifier configured', with_settings: { sequential_project_identifiers: true } do context 'with an identifier provided' do let(:call_attributes) do { @@ -128,7 +128,7 @@ describe Projects::SetAttributesService, type: :model do end end - context 'without a default identifier configured', with_settings: {sequential_project_identifiers: false} do + context 'without a default identifier configured', with_settings: { sequential_project_identifiers: false } do context 'with an identifier provided' do let(:call_attributes) do { diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb index 14342e24c3..68a2b0a39e 100644 --- a/spec/services/projects/update_service_spec.rb +++ b/spec/services/projects/update_service_spec.rb @@ -34,7 +34,7 @@ require 'services/base_services/behaves_like_update_service' describe Projects::UpdateService, type: :model do it_behaves_like 'BaseServices update service' do let!(:model_instance) do - FactoryBot.build_stubbed(:project, status: project_status).tap do |p| + FactoryBot.build_stubbed(:project, status: project_status).tap do |_p| project_status.clear_changes_information end end diff --git a/spec/services/queries/update_from_params_service_spec.rb b/spec/services/queries/update_from_params_service_spec.rb index 48d52dbcad..80081dbaa6 100644 --- a/spec/services/queries/update_from_params_service_spec.rb +++ b/spec/services/queries/update_from_params_service_spec.rb @@ -69,7 +69,7 @@ describe UpdateQueryFromParamsService, expect(query.group_by).to eql('status') expect(query.show_hierarchies).to eql(true) - expect(subject).not_to be_success + expect(subject).not_to be_success end end end diff --git a/spec/services/queries/update_service_spec.rb b/spec/services/queries/update_service_spec.rb index eca2bf69c2..78a813e241 100644 --- a/spec/services/queries/update_service_spec.rb +++ b/spec/services/queries/update_service_spec.rb @@ -65,8 +65,8 @@ describe Queries::UpdateService do before do # violating the validations violating_menu_item = FactoryBot.build(:query_menu_item, - name: menu_item.name, - navigatable_id: menu_item.navigatable_id) + name: menu_item.name, + navigatable_id: menu_item.navigatable_id) violating_menu_item.save(validate: false) diff --git a/spec/services/scm/checkout_instructions_service_spec.rb b/spec/services/scm/checkout_instructions_service_spec.rb index f6ccc7f85a..790c23d00b 100644 --- a/spec/services/scm/checkout_instructions_service_spec.rb +++ b/spec/services/scm/checkout_instructions_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -33,24 +34,23 @@ describe SCM::CheckoutInstructionsService do let(:project) { FactoryBot.build(:project) } let(:url) { 'file:///tmp/some/svn/repo' } - let(:repository) { + let(:repository) do FactoryBot.build(:repository_subversion, - url: url, - project: project) - } + url: url, + project: project) + end let(:base_url) { 'http://example.org/svn/' } let(:path) { nil } let(:text) { 'foo' } - let(:checkout_hash) { + let(:checkout_hash) do { 'git' => { 'enabled' => '0' }, 'subversion' => { 'enabled' => '1', 'text' => text, - 'base_url' => base_url - } + 'base_url' => base_url } } - } + end subject(:service) { SCM::CheckoutInstructionsService.new(repository, user: user, path: path) } diff --git a/spec/services/scm/create_managed_repository_service_spec.rb b/spec/services/scm/create_managed_repository_service_spec.rb index bd660c3800..ad20415c64 100644 --- a/spec/services/scm/create_managed_repository_service_spec.rb +++ b/spec/services/scm/create_managed_repository_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -55,11 +56,11 @@ describe SCM::CreateManagedRepositoryService do context 'with managed repository' do # Must not .create a managed repository, or it will call this service itself! - let(:repository) { + let(:repository) do repo = Repository::Subversion.new(scm_type: :managed) repo.project = project repo - } + end context 'but no managed config' do it 'does not create a filesystem repository' do @@ -71,14 +72,14 @@ describe SCM::CreateManagedRepositoryService do context 'with managed local config' do include_context 'with tmpdir' - let(:config) { + let(:config) do { subversion: { manages: File.join(tmpdir, 'svn') }, git: { manages: File.join(tmpdir, 'git') } } - } + end - let(:repository) { + let(:repository) do repo = Repository::Subversion.new(scm_type: :managed) repo.project = project repo.configure(:managed, nil) @@ -87,7 +88,7 @@ describe SCM::CreateManagedRepositoryService do allow(repo).to receive(:create_managed_repository) repo.save! repo - } + end before do allow_any_instance_of(SCM::CreateLocalRepositoryJob) @@ -144,18 +145,18 @@ describe SCM::CreateManagedRepositoryService do context 'with managed remote config', webmock: true do let(:url) { 'http://myreposerver.example.com/api/' } - let(:config) { + let(:config) do { subversion: { manages: url } } - } + end - let(:repository) { + let(:repository) do repo = FactoryBot.build(:repository_subversion, scm_type: :managed) repo.project = project repo.configure(:managed, nil) repo - } + end it 'detects the remote config' do expect(repository.class.managed_remote.to_s).to eq(url) @@ -200,11 +201,11 @@ describe SCM::CreateManagedRepositoryService do context 'with https' do let(:url) { 'https://myreposerver.example.com/api/' } - let(:config) { + let(:config) do { subversion: { manages: url, insecure: insecure } } - } + end let(:instance) { SCM::CreateRemoteRepositoryJob.new } let(:job_call) { instance.perform(repository) } diff --git a/spec/services/scm/delete_managed_repository_service_spec.rb b/spec/services/scm/delete_managed_repository_service_spec.rb index a76ebf1bb7..033bc28a5f 100644 --- a/spec/services/scm/delete_managed_repository_service_spec.rb +++ b/spec/services/scm/delete_managed_repository_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -65,14 +66,14 @@ describe SCM::DeleteManagedRepositoryService do context 'with managed repository and managed config' do include_context 'with tmpdir' - let(:config) { + let(:config) do { subversion: { manages: File.join(tmpdir, 'svn') }, git: { manages: File.join(tmpdir, 'git') } } - } + end - let(:repository) { + let(:repository) do repo = Repository::Subversion.new(scm_type: :managed) repo.project = project repo.configure(:managed, nil) @@ -80,7 +81,7 @@ describe SCM::DeleteManagedRepositoryService do repo.save! perform_enqueued_jobs repo - } + end it 'deletes the repository' do expect(File.directory?(repository.root_url)).to be true @@ -99,9 +100,9 @@ describe SCM::DeleteManagedRepositoryService do context 'and parent project' do let(:parent) { FactoryBot.create(:project) } let(:project) { FactoryBot.create(:project, parent: parent) } - let(:repo_path) { + let(:repo_path) do Pathname.new(File.join(tmpdir, 'svn', project.identifier)) - } + end it 'does not delete anything but the repository itself' do expect(service.call).to be true @@ -118,23 +119,23 @@ describe SCM::DeleteManagedRepositoryService do context 'with managed remote config', webmock: true do let(:url) { 'http://myreposerver.example.com/api/' } - let(:config) { + let(:config) do { subversion: { manages: url } } - } + end - let(:repository) { + let(:repository) do repo = Repository::Subversion.new(scm_type: :managed) repo.project = project repo.configure(:managed, nil) repo - } + end context 'with a valid remote' do before do - stub_request(:post, url).to_return(status: 200, body: {}.to_json ) + stub_request(:post, url).to_return(status: 200, body: {}.to_json) end it 'calls the callback' do @@ -161,7 +162,6 @@ describe SCM::DeleteManagedRepositoryService do .to receive(:perform_now) .and_call_original - expect(service.call).to be false expect(service.localized_rejected_reason) diff --git a/spec/services/scm/repository_factory_service_spec.rb b/spec/services/scm/repository_factory_service_spec.rb index 6a7abf89d5..a098f019d9 100644 --- a/spec/services/scm/repository_factory_service_spec.rb +++ b/spec/services/scm/repository_factory_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -52,9 +53,9 @@ describe SCM::RepositoryFactoryService do end context 'with valid vendor' do - let(:params_hash) { + let(:params_hash) do { scm_vendor: 'subversion' } - } + end it 'should allow temporary build repository' do expect(service.build_temporary).to be true @@ -70,9 +71,9 @@ describe SCM::RepositoryFactoryService do end context 'with invalid vendor' do - let(:params_hash) { + let(:params_hash) do { scm_vendor: 'not_subversion', scm_type: 'foo' } - } + end it 'should not allow to temporary build repository' do expect { service.build_temporary }.not_to raise_error @@ -90,9 +91,9 @@ describe SCM::RepositoryFactoryService do end context 'with vendor and type' do - let(:params_hash) { + let(:params_hash) do { scm_vendor: 'subversion', scm_type: 'existing' } - } + end it 'should not allow to persist a repository without URL' do expect(service.build_and_save).not_to be true @@ -103,12 +104,12 @@ describe SCM::RepositoryFactoryService do end context 'with invalid hash' do - let(:params_hash) { + let(:params_hash) do { scm_vendor: 'subversion', scm_type: 'existing', repository: { url: '/tmp/foo.svn' } } - } + end it 'should not allow to persist a repository URL' do expect(service.build_and_save).not_to be true @@ -119,12 +120,12 @@ describe SCM::RepositoryFactoryService do end context 'with valid hash' do - let(:params_hash) { + let(:params_hash) do { scm_vendor: 'subversion', scm_type: 'existing', repository: { url: 'file:///tmp/foo.svn' } } - } + end it 'should allow to persist a repository without URL' do expect(service.build_and_save).to be true diff --git a/spec/services/service_result_spec.rb b/spec/services/service_result_spec.rb index 67e801d4d0..7775103d25 100644 --- a/spec/services/service_result_spec.rb +++ b/spec/services/service_result_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/shared_type_service.rb b/spec/services/shared_type_service.rb index 4a812f8006..793f174e5d 100644 --- a/spec/services/shared_type_service.rb +++ b/spec/services/shared_type_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/update_projects_types_service.rb b/spec/services/update_projects_types_service.rb index 5702601d33..9b645f5277 100644 --- a/spec/services/update_projects_types_service.rb +++ b/spec/services/update_projects_types_service.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/services/update_query_from_params_service_spec.rb b/spec/services/update_query_from_params_service_spec.rb index b9cd494d09..827ab75208 100644 --- a/spec/services/update_query_from_params_service_spec.rb +++ b/spec/services/update_query_from_params_service_spec.rb @@ -30,7 +30,6 @@ require 'spec_helper' describe UpdateQueryFromParamsService, type: :model do - let(:user) { FactoryBot.build_stubbed(:user) } let(:query) { FactoryBot.build_stubbed(:query) } @@ -140,7 +139,7 @@ describe UpdateQueryFromParamsService, context 'default highlighting mode', with_ee: %i[conditional_highlighting] do let(:params) do - { } + {} end it 'sets the highlighting_mode' do diff --git a/spec/services/update_type_service_spec.rb b/spec/services/update_type_service_spec.rb index 460a5d443d..99aa9e41a9 100644 --- a/spec/services/update_type_service_spec.rb +++ b/spec/services/update_type_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/services/update_user_email_settings_service_spec.rb b/spec/services/update_user_email_settings_service_spec.rb index 70b108f6c5..33ae46b8e7 100644 --- a/spec/services/update_user_email_settings_service_spec.rb +++ b/spec/services/update_user_email_settings_service_spec.rb @@ -86,9 +86,9 @@ describe UpdateUserEmailSettingsService, type: :model do it 'set the notified_project_ids on successful saving and mail_notifications is "selected"' do allow(user).to receive(:mail_notification).and_return 'selected' - expect(user).to receive(:notified_project_ids=).with([1,2,3]) + expect(user).to receive(:notified_project_ids=).with([1, 2, 3]) - service.call(notified_project_ids: [1,2,3]) + service.call(notified_project_ids: [1, 2, 3]) end end end diff --git a/spec/services/users/create_user_service_spec.rb b/spec/services/users/create_user_service_spec.rb index cc20f6d8fd..1d3d137ad7 100644 --- a/spec/services/users/create_user_service_spec.rb +++ b/spec/services/users/create_user_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -47,7 +48,7 @@ describe Users::CreateService do it 'will call not call UserInvitation' do expect(::UserInvitation).not_to receive(:invite_user!) expect(subject).not_to be_success - expect(subject.errors.details[:mail]).to eq [{error: :blank}] + expect(subject.errors.details[:mail]).to eq [{ error: :blank }] end end end diff --git a/spec/services/users/delete_service_spec.rb b/spec/services/users/delete_service_spec.rb index 5020d65cb7..7eb1d4374c 100644 --- a/spec/services/users/delete_service_spec.rb +++ b/spec/services/users/delete_service_spec.rb @@ -52,7 +52,6 @@ describe ::Users::DeleteService, type: :model do end end - context 'if deletion by admins allowed', with_settings: { users_deletable_by_admins: true } do context 'with admin user' do let(:actor) { FactoryBot.build_stubbed(:admin) } diff --git a/spec/services/users/login_service_spec.rb b/spec/services/users/login_service_spec.rb index ae661d34ff..dbfb2707df 100644 --- a/spec/services/users/login_service_spec.rb +++ b/spec/services/users/login_service_spec.rb @@ -32,7 +32,7 @@ describe ::Users::LoginService, type: :model do let(:input_user) { FactoryBot.build_stubbed(:user) } let(:controller) { double('ApplicationController') } let(:session) { {} } - let(:flash) { ActionDispatch::Flash::FlashHash.new() } + let(:flash) { ActionDispatch::Flash::FlashHash.new } let(:instance) { described_class.new(controller: controller) } diff --git a/spec/services/users/register_user_service_spec.rb b/spec/services/users/register_user_service_spec.rb index f587912562..430e939f77 100644 --- a/spec/services/users/register_user_service_spec.rb +++ b/spec/services/users/register_user_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH @@ -94,7 +95,7 @@ describe Users::RegisterUserService do end it 'does not return an error for all cases except disabled' do - with_all_registration_options(except: :disabled) do |type| + with_all_registration_options(except: :disabled) do |_type| user = User.new instance = described_class.new(user) @@ -263,6 +264,5 @@ describe Users::RegisterUserService do end describe '#with_saved_user_result' do - end end diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb index e38cb148e3..4bde00cc68 100644 --- a/spec/services/users/update_service_spec.rb +++ b/spec/services/users/update_service_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2020 the OpenProject GmbH diff --git a/spec/services/work_packages/copy_service_integration_spec.rb b/spec/services/work_packages/copy_service_integration_spec.rb index a0d41c46db..bfa8c2a510 100644 --- a/spec/services/work_packages/copy_service_integration_spec.rb +++ b/spec/services/work_packages/copy_service_integration_spec.rb @@ -141,9 +141,9 @@ describe WorkPackages::CopyService, 'integration', type: :model do let(:custom_field) do FactoryBot.create( :work_package_custom_field, - field_format: 'text', - is_required: true, - is_for_all: false + field_format: 'text', + is_required: true, + is_for_all: false ) end let(:target_custom_fields) { [custom_field] } diff --git a/spec/services/work_packages/set_schedule_service_spec.rb b/spec/services/work_packages/set_schedule_service_spec.rb index 4972153e61..8d7dcfc49d 100644 --- a/spec/services/work_packages/set_schedule_service_spec.rb +++ b/spec/services/work_packages/set_schedule_service_spec.rb @@ -176,10 +176,10 @@ describe WorkPackages::SetScheduleService do it 'returns only the original and the changed work packages' do expected_to_change = if defined?(unchanged) - expected.keys - unchanged - else - expected.keys - end + expected.keys - unchanged + else + expected.keys + end expected_to_change << work_package diff --git a/spec/services/work_packages/update_ancestors_service_spec.rb b/spec/services/work_packages/update_ancestors_service_spec.rb index c0934fb43d..41070ad50d 100644 --- a/spec/services/work_packages/update_ancestors_service_spec.rb +++ b/spec/services/work_packages/update_ancestors_service_spec.rb @@ -195,7 +195,7 @@ describe WorkPackages::UpdateAncestorsService, type: :model, with_mail: false do end let!(:parent) do FactoryBot.create :work_package, - parent: grandparent + parent: grandparent end let!(:sibling) do FactoryBot.create :work_package, @@ -207,7 +207,7 @@ describe WorkPackages::UpdateAncestorsService, type: :model, with_mail: false do let!(:work_package) do FactoryBot.create :work_package, - parent: parent + parent: parent end subject do diff --git a/spec/services/workflows/bulk_update_service_integration_spec.rb b/spec/services/workflows/bulk_update_service_integration_spec.rb index 54c8007cc0..a164277b7c 100644 --- a/spec/services/workflows/bulk_update_service_integration_spec.rb +++ b/spec/services/workflows/bulk_update_service_integration_spec.rb @@ -84,7 +84,7 @@ describe Workflows::BulkUpdateService, 'integration', type: :model do let(:params) do { status4.id => { status5.id => ['always'] }, - status3.id => { status1.id => ['author'], status2.id => ['assignee'], status4.id => %w(author assignee)} + status3.id => { status1.id => ['author'], status2.id => ['assignee'], status4.id => %w(author assignee) } } end diff --git a/spec/support/angular.rb b/spec/support/angular.rb index 0c67b14c0e..d4bc55165d 100644 --- a/spec/support/angular.rb +++ b/spec/support/angular.rb @@ -31,4 +31,3 @@ def expect_angular_frontend_initialized expect(page).to have_selector('.__ng2-bootstrap-has-run', wait: 20) end - diff --git a/spec/support/api/v3/work_packages/work_package_representer_eager_loading.rb b/spec/support/api/v3/work_packages/work_package_representer_eager_loading.rb index 2372233d68..5b4ff1ec14 100644 --- a/spec/support/api/v3/work_packages/work_package_representer_eager_loading.rb +++ b/spec/support/api/v3/work_packages/work_package_representer_eager_loading.rb @@ -31,7 +31,7 @@ shared_context 'eager loaded work package representer' do before do allow(::API::V3::WorkPackages::WorkPackageEagerLoadingWrapper) - .to receive(:wrap_one) do |work_package, user| + .to receive(:wrap_one) do |work_package, _user| allow(work_package) .to receive(:cache_checksum) .and_return(srand) diff --git a/spec/support/browsers/chrome.rb b/spec/support/browsers/chrome.rb index ee3c985b3b..e491de8ae4 100644 --- a/spec/support/browsers/chrome.rb +++ b/spec/support/browsers/chrome.rb @@ -97,6 +97,6 @@ register_chrome 'en', name: :chrome_billy do |options, capabilities| end # Register Revit add in -register_chrome 'en', name: :chrome_revit_add_in do |options, capabilities| +register_chrome 'en', name: :chrome_revit_add_in do |options, _capabilities| options.add_argument("user-agent='foo bar Revit'") end diff --git a/spec/support/browsers/firefox.rb b/spec/support/browsers/firefox.rb index d4b4d01302..dce2ac47af 100644 --- a/spec/support/browsers/firefox.rb +++ b/spec/support/browsers/firefox.rb @@ -42,23 +42,23 @@ def register_firefox(language, name: :"firefox_#{language}") options.args << "--headless" end - if ENV['SELENIUM_GRID_URL'] - driver = Capybara::Selenium::Driver.new( - app, - browser: :remote, - url: ENV['SELENIUM_GRID_URL'], - desired_capabilities: capabilities, - options: options - ) - else - driver = Capybara::Selenium::Driver.new( - app, - browser: :firefox, - desired_capabilities: capabilities, - options: options, - http_client: client - ) - end + driver = if ENV['SELENIUM_GRID_URL'] + Capybara::Selenium::Driver.new( + app, + browser: :remote, + url: ENV['SELENIUM_GRID_URL'], + desired_capabilities: capabilities, + options: options + ) + else + Capybara::Selenium::Driver.new( + app, + browser: :firefox, + desired_capabilities: capabilities, + options: options, + http_client: client + ) + end Capybara::Screenshot.register_driver(name) do |driver, path| driver.browser.save_screenshot(path) diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index c7a0be6c27..30099df9b3 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -5,7 +5,7 @@ require 'capybara-screenshot/rspec' require 'rack_session_access/capybara' require 'action_dispatch' -RSpec.configure do |config| +RSpec.configure do |_config| Capybara.default_max_wait_time = 4 Capybara.javascript_driver = :chrome_en diff --git a/spec/support/clear_notification_subscriptions.rb b/spec/support/clear_notification_subscriptions.rb index d29970b151..7b5fa09e63 100644 --- a/spec/support/clear_notification_subscriptions.rb +++ b/spec/support/clear_notification_subscriptions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,7 +29,7 @@ #++ RSpec.configure do |config| - config.after(:each) do |example| + config.after(:each) do |_example| OpenProject::Notifications.subscriptions.clear end end diff --git a/spec/support/components/admin/type_configuration_form.rb b/spec/support/components/admin/type_configuration_form.rb index 1c008c9a6f..699b637eb6 100644 --- a/spec/support/components/admin/type_configuration_form.rb +++ b/spec/support/components/admin/type_configuration_form.rb @@ -211,10 +211,10 @@ module Components end def expect_no_attribute(attribute, group) - expect(find_group(group)).not_to have_selector("#{attribute_selector(attribute)}") + expect(find_group(group)).not_to have_selector(attribute_selector(attribute).to_s) end - def expect_group(label, translation, *attributes) + def expect_group(_label, translation, *attributes) expect(find_group(translation)).to have_selector(".group-edit-handler", text: translation.upcase) within find_group(translation) do diff --git a/spec/support/components/attachments/attachments.rb b/spec/support/components/attachments/attachments.rb index debfd575e5..94931650d9 100644 --- a/spec/support/components/attachments/attachments.rb +++ b/spec/support/components/attachments/attachments.rb @@ -28,7 +28,7 @@ module Components end def js_drop_files - @js_file ||= File.read(File.expand_path('../attachments_input.js', __FILE__)) + @js_file ||= File.read(File.expand_path('attachments_input.js', __dir__)) end end end diff --git a/spec/support/components/datepicker/datepicker.rb b/spec/support/components/datepicker/datepicker.rb index e3cd3ea71f..892af4aa5d 100644 --- a/spec/support/components/datepicker/datepicker.rb +++ b/spec/support/components/datepicker/datepicker.rb @@ -28,12 +28,12 @@ module Components current_month = Date::MONTHNAMES.index(container.first('.cur-month').text) if current_month < month - while (current_month < month) do + while current_month < month container.find('.flatpickr-next-month').click current_month = Date::MONTHNAMES.index(container.first('.cur-month').text) end elsif current_month > month - while (current_month > month) do + while current_month > month container.find('.flatpickr-prev-month').click current_month = Date::MONTHNAMES.index(container.first('.cur-month').text) end @@ -54,8 +54,8 @@ module Components container .first('.flatpickr-days .flatpickr-day:not(.nextMonthDay):not(.prevMonthDay)', - text: value, - exact_text: true) + text: value, + exact_text: true) .click end diff --git a/spec/support/components/global_search.rb b/spec/support/components/global_search.rb index aa618d2109..04fc928beb 100644 --- a/spec/support/components/global_search.rb +++ b/spec/support/components/global_search.rb @@ -67,17 +67,17 @@ module Components def expect_work_package_marked(wp) expect(page) - .to have_selector('.ng-option-marked', text: "#{wp.subject}", wait: 10) + .to have_selector('.ng-option-marked', text: wp.subject.to_s, wait: 10) end def expect_work_package_option(wp) expect(page) - .to have_selector('.global-search--option', text: "#{wp.subject}", wait: 10) + .to have_selector('.global-search--option', text: wp.subject.to_s, wait: 10) end def expect_no_work_package_option(wp) expect(page) - .to have_no_selector('.global-search--option', text: "#{wp.subject}") + .to have_no_selector('.global-search--option', text: wp.subject.to_s) end def click_work_package(wp) @@ -85,7 +85,7 @@ module Components end def find_work_package(wp) - find_option "#{wp.subject}" + find_option wp.subject.to_s end def find_option(text) diff --git a/spec/support/components/grids/grid_area.rb b/spec/support/components/grids/grid_area.rb index 160e6fef22..e40b8a349a 100644 --- a/spec/support/components/grids/grid_area.rb +++ b/spec/support/components/grids/grid_area.rb @@ -67,7 +67,6 @@ module Components ['grid-column-start', startColumn * 2], ['grid-row-end', endRow * 2 - 1], ['grid-column-end', endColumn * 2 - 1]].each do |style, expected| - actual = area.native.style(style) expect(actual) diff --git a/spec/support/components/table_pagination.rb b/spec/support/components/table_pagination.rb index 6f93f09282..03e00a589d 100644 --- a/spec/support/components/table_pagination.rb +++ b/spec/support/components/table_pagination.rb @@ -47,10 +47,8 @@ module Components protected - def within_pagination - within('.pagination') do - yield - end + def within_pagination(&block) + within('.pagination', &block) end end end diff --git a/spec/support/components/work_packages/columns.rb b/spec/support/components/work_packages/columns.rb index c54b66c88b..fcb4a9867a 100644 --- a/spec/support/components/work_packages/columns.rb +++ b/spec/support/components/work_packages/columns.rb @@ -143,10 +143,8 @@ module Components private - def within_modal - page.within('.wp-table--configuration-modal') do - yield - end + def within_modal(&block) + page.within('.wp-table--configuration-modal', &block) end def modal_open? diff --git a/spec/support/components/work_packages/destroy_modal.rb b/spec/support/components/work_packages/destroy_modal.rb index 0e6404b7d9..6296d873f3 100644 --- a/spec/support/components/work_packages/destroy_modal.rb +++ b/spec/support/components/work_packages/destroy_modal.rb @@ -42,7 +42,8 @@ module Components wp = wps.first expect(page).to have_selector('strong', text: "#{wp.type.name} ##{wp.id} #{wp.subject}") else - expect(page).to have_selector('.danger-zone--warning', text: 'Are you sure you want to delete the following work packages ?') + expect(page).to have_selector('.danger-zone--warning', + text: 'Are you sure you want to delete the following work packages ?') wps.each do |wp| expect(page).to have_selector('li', text: "##{wp.id} #{wp.subject}") end diff --git a/spec/support/components/work_packages/display_representation.rb b/spec/support/components/work_packages/display_representation.rb index f955ce1e31..f4e7e391ff 100644 --- a/spec/support/components/work_packages/display_representation.rb +++ b/spec/support/components/work_packages/display_representation.rb @@ -42,7 +42,7 @@ module Components def switch_to_list_layout expect_button 'Table' select_view 'Table' - end + end def switch_to_gantt_layout expect_button 'Gantt' @@ -68,10 +68,8 @@ module Components end end - def within_view_context_menu - page.within('#wp-view-context-menu') do - yield - end + def within_view_context_menu(&block) + page.within('#wp-view-context-menu', &block) end end end diff --git a/spec/support/components/work_packages/group_by.rb b/spec/support/components/work_packages/group_by.rb index 6dce98deea..b4506044ed 100644 --- a/spec/support/components/work_packages/group_by.rb +++ b/spec/support/components/work_packages/group_by.rb @@ -68,10 +68,8 @@ module Components page.find(".generic-table--sort-header ##{name.downcase}").click end - def within_column_context_menu - page.within('#column-context-menu') do - yield - end + def within_column_context_menu(&block) + page.within('#column-context-menu', &block) end end end diff --git a/spec/support/components/work_packages/query_title.rb b/spec/support/components/work_packages/query_title.rb index 3ff241657e..b434d2f848 100644 --- a/spec/support/components/work_packages/query_title.rb +++ b/spec/support/components/work_packages/query_title.rb @@ -32,7 +32,6 @@ module Components include Capybara::DSL include RSpec::Matchers - def expect_changed expect(page).to have_selector '.editable-toolbar-title--save' expect(page).to have_selector '.editable-toolbar-title--input.-changed' diff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rb index 093678822b..76c5b5df66 100644 --- a/spec/support/components/work_packages/relations.rb +++ b/spec/support/components/work_packages/relations.rb @@ -174,6 +174,7 @@ module Components def openChildrenAutocompleter retry_block do next if page.has_selector?('.wp-relations--children .ng-input input') + SeleniumHubWaiter.wait find('.wp-inline-create--reference-link', text: I18n.t('js.relation_buttons.add_existing_child')).click diff --git a/spec/support/components/work_packages/sort_by.rb b/spec/support/components/work_packages/sort_by.rb index 58611c2e47..f14805b031 100644 --- a/spec/support/components/work_packages/sort_by.rb +++ b/spec/support/components/work_packages/sort_by.rb @@ -44,14 +44,13 @@ module Components end end - def update_criteria(first, second=nil, third=nil) + def update_criteria(first, second = nil, third = nil) open_modal SeleniumHubWaiter.wait [first, second, third] .compact .each_with_index do |entry, i| - column, direction = entry update_nth_criteria(i, column, descending: descending?(direction)) end @@ -59,14 +58,13 @@ module Components apply_changes end - def expect_criteria(first, second=nil, third=nil) + def expect_criteria(first, second = nil, third = nil) open_modal SeleniumHubWaiter.wait [first, second, third] .compact .each_with_index do |entry, i| - column, direction = entry page.within(".modal-sorting-row-#{i}") do expect(page).to have_selector("#modal-sorting-attribute-#{i} option", text: column) @@ -121,10 +119,8 @@ module Components page.find(".generic-table--sort-header ##{id}").click end - def within_column_context_menu - page.within('#column-context-menu') do - yield - end + def within_column_context_menu(&block) + page.within('#column-context-menu', &block) end end end diff --git a/spec/support/components/work_packages/table_configuration/graph_general.rb b/spec/support/components/work_packages/table_configuration/graph_general.rb index 86249bd36d..7d713b5b5b 100644 --- a/spec/support/components/work_packages/table_configuration/graph_general.rb +++ b/spec/support/components/work_packages/table_configuration/graph_general.rb @@ -67,10 +67,8 @@ module Components private - def within_modal - page.within('.wp-table--configuration-modal') do - yield - end + def within_modal(&block) + page.within('.wp-table--configuration-modal', &block) end end end diff --git a/spec/support/components/work_packages/table_configuration/highlighting.rb b/spec/support/components/work_packages/table_configuration/highlighting.rb index d24f333cca..76e08510da 100644 --- a/spec/support/components/work_packages/table_configuration/highlighting.rb +++ b/spec/support/components/work_packages/table_configuration/highlighting.rb @@ -93,10 +93,8 @@ module Components private - def within_modal - page.within('.wp-table--configuration-modal') do - yield - end + def within_modal(&block) + page.within('.wp-table--configuration-modal', &block) end def modal_open? diff --git a/spec/support/components/work_packages/tabs_counter.rb b/spec/support/components/work_packages/tabs_counter.rb index 2b93a159b8..b2ba82601b 100644 --- a/spec/support/components/work_packages/tabs_counter.rb +++ b/spec/support/components/work_packages/tabs_counter.rb @@ -15,7 +15,7 @@ module Components # Check value of counter for the given tab def expect_counter(tab, content) - expect(tab).to have_selector('.wp-tabs-count', text: "#{content}") + expect(tab).to have_selector('.wp-tabs-count', text: content.to_s) end # Counter should not be displayed, if there are no relations or watchers diff --git a/spec/support/components/wysiwyg/wysiwyg_editor.rb b/spec/support/components/wysiwyg/wysiwyg_editor.rb index ac329ece3f..20a4e864cb 100644 --- a/spec/support/components/wysiwyg/wysiwyg_editor.rb +++ b/spec/support/components/wysiwyg/wysiwyg_editor.rb @@ -71,7 +71,7 @@ module Components ## # Create an image fixture with the optional caption def drag_attachment(image_fixture, caption = 'Some caption') - in_editor do |container, editable| + in_editor do |_container, editable| sleep 0.5 editable.base.send_keys(:enter, 'some text', :enter, :enter) @@ -81,7 +81,6 @@ module Components expect(page) .to have_selector('figure img[src^="/api/v3/attachments/"]', count: images.length + 1, wait: 10) - expect(page).not_to have_selector('notification-upload-progress') sleep 0.5 @@ -112,7 +111,7 @@ module Components def refocus editor_element.first('*').click - rescue => e + rescue StandardError => e warn "Failed to refocus on first editor element #{e}" end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 446583bb8f..0c08beeec0 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,5 +1,4 @@ RSpec.configure do |config| - # Since Rails 5.1., we can force the application server and capybara to share the same connection, # which results in database_cleaner no longer being necessary. # This will only work with a server that works in single mode (e.g., Puma) diff --git a/spec/support/download_list.rb b/spec/support/download_list.rb index 0df23523b3..c52b7d0026 100644 --- a/spec/support/download_list.rb +++ b/spec/support/download_list.rb @@ -3,7 +3,7 @@ class DownloadList ENV.fetch("CAPYBARA_DOWNLOADED_FILE_DIR", Rails.root.join('tmp/test/downloads')) ).join( ENV.fetch('TEST_ENV_NUMBER', '1') - ).tap {|f| p ["DownloadList::SHARED_PATH", f.to_s] ; f.mkpath } + ).tap { |f| p ["DownloadList::SHARED_PATH", f.to_s]; f.mkpath } def initialize @history = [] @@ -16,7 +16,7 @@ class DownloadList page.visit("about:downloads") # give some time for page to load sleep 0.5 - download_name = page.evaluate_script("document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('div#content #file-link')").text() + download_name = page.evaluate_script("document.querySelector('downloads-manager').shadowRoot.querySelector('#downloadsList downloads-item').shadowRoot.querySelector('div#content #file-link')").text if download_name && !@history.include?(download_name) Timeout.timeout(Capybara.default_max_wait_time) do sleep 0.1 until SHARED_PATH.join(download_name).exist? @@ -26,7 +26,7 @@ class DownloadList end else sleep 0.5 - @latest = Dir.glob(SHARED_PATH.join("*").to_s).max_by {|f| File.mtime(f) } + @latest = Dir.glob(SHARED_PATH.join("*").to_s).max_by { |f| File.mtime(f) } @history << @latest end self @@ -34,11 +34,13 @@ class DownloadList def latest_download return nil if @latest.nil? + SHARED_PATH.join(@latest) end def latest_downloaded_content return nil if @latest.nil? + SHARED_PATH.join(@latest).read end diff --git a/spec/support/edit_fields/date_edit_field.rb b/spec/support/edit_fields/date_edit_field.rb index bc7c9e804d..787ffa6753 100644 --- a/spec/support/edit_fields/date_edit_field.rb +++ b/spec/support/edit_fields/date_edit_field.rb @@ -1,8 +1,7 @@ require_relative './edit_field' class DateEditField < EditField - attr_accessor :milestone - attr_accessor :is_table + attr_accessor :milestone, :is_table def initialize(context, property_name, diff --git a/spec/support/edit_fields/edit_field.rb b/spec/support/edit_fields/edit_field.rb index 23ed285b3a..f635328626 100644 --- a/spec/support/edit_fields/edit_field.rb +++ b/spec/support/edit_fields/edit_field.rb @@ -146,7 +146,7 @@ class EditField ## # Set or select the given value. # For fields of type select, will check for an option with that value. - def unset_value(content, multi=false) + def unset_value(content, multi = false) scroll_to_element(input_element) if field_type.end_with?('-autocompleter') diff --git a/spec/support/edit_fields/text_area_field.rb b/spec/support/edit_fields/text_area_field.rb index 51ea62ef07..5516c57312 100644 --- a/spec/support/edit_fields/text_area_field.rb +++ b/spec/support/edit_fields/text_area_field.rb @@ -1,7 +1,6 @@ require_relative './edit_field' class TextAreaField < EditField - def input_selector 'textarea' end @@ -39,7 +38,8 @@ class TextAreaField < EditField end def control_link(action = :save) - raise 'Invalid link' unless [:save, :cancel].include?(action) + raise 'Invalid link' unless %i[save cancel].include?(action) + ".inplace-edit--control--#{action}" end end diff --git a/spec/support/edit_fields/text_editor_field.rb b/spec/support/edit_fields/text_editor_field.rb index e5e72508de..94e905367b 100644 --- a/spec/support/edit_fields/text_editor_field.rb +++ b/spec/support/edit_fields/text_editor_field.rb @@ -62,7 +62,8 @@ class TextEditorField < EditField end def control_link(action = :save) - raise 'Invalid link' unless [:save, :cancel].include?(action) + raise 'Invalid link' unless %i[save cancel].include?(action) + ".inplace-edit--control--#{action}" end end diff --git a/spec/support/edit_fields/work_package_status_field.rb b/spec/support/edit_fields/work_package_status_field.rb index bd4c81c8a8..43136210de 100644 --- a/spec/support/edit_fields/work_package_status_field.rb +++ b/spec/support/edit_fields/work_package_status_field.rb @@ -11,7 +11,7 @@ class WorkPackageStatusField < EditField end def input_element - page.find "#{input_selector}" + page.find input_selector.to_s end def display_element @@ -47,7 +47,7 @@ class WorkPackageStatusField < EditField def expect_active! expect(page).to have_selector(input_selector, wait: 10), - "Expected context menu for status." + "Expected context menu for status." end def expect_inactive! diff --git a/spec/support/flash.rb b/spec/support/flash.rb index 1b7b26f145..dacb7c3384 100644 --- a/spec/support/flash.rb +++ b/spec/support/flash.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/identical_ext.rb b/spec/support/identical_ext.rb index e71dfcdb3a..30adbd769a 100644 --- a/spec/support/identical_ext.rb +++ b/spec/support/identical_ext.rb @@ -45,8 +45,9 @@ end Hash.class_eval do def identical?(o) return false unless self.class === o + (o.keys + keys).uniq.all? do |key| - (o[key].identical?(self[key])) + o[key].identical?(self[key]) end end end @@ -54,6 +55,7 @@ end Array.class_eval do def identical?(o) return false unless self.class === o + all? do |ea| (o.any? { |other_each| other_each.identical?(ea) }) end diff --git a/spec/support/local_storage_cleanup.rb b/spec/support/local_storage_cleanup.rb index 480ed5dbbe..1f6dd4f285 100644 --- a/spec/support/local_storage_cleanup.rb +++ b/spec/support/local_storage_cleanup.rb @@ -28,6 +28,8 @@ RSpec.configure do |config| config.after(:each, js: true) do - Capybara.current_session.driver.execute_script('window.localStorage.clear()') rescue nil + Capybara.current_session.driver.execute_script('window.localStorage.clear()') + rescue StandardError + nil end end diff --git a/spec/support/matchers/be_boolean.rb b/spec/support/matchers/be_boolean.rb index 6074c11b7f..c52ea87e0e 100644 --- a/spec/support/matchers/be_boolean.rb +++ b/spec/support/matchers/be_boolean.rb @@ -2,4 +2,4 @@ RSpec::Matchers.define :be_boolean do match do |value| [true, false].include? value end -end \ No newline at end of file +end diff --git a/spec/support/matchers/be_html_eql.rb b/spec/support/matchers/be_html_eql.rb index e48ae518e6..11030ee588 100644 --- a/spec/support/matchers/be_html_eql.rb +++ b/spec/support/matchers/be_html_eql.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/matchers/has_conditional_selector.rb b/spec/support/matchers/has_conditional_selector.rb index 0e4a384337..5708d91c3e 100644 --- a/spec/support/matchers/has_conditional_selector.rb +++ b/spec/support/matchers/has_conditional_selector.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/matchers/has_focus_on.rb b/spec/support/matchers/has_focus_on.rb index 42a45f1065..f30490439f 100644 --- a/spec/support/matchers/has_focus_on.rb +++ b/spec/support/matchers/has_focus_on.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/matchers/raise_if_found.rb b/spec/support/matchers/raise_if_found.rb index 822b2c66d6..04c2b49525 100644 --- a/spec/support/matchers/raise_if_found.rb +++ b/spec/support/matchers/raise_if_found.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/noop_contract.rb b/spec/support/noop_contract.rb index c4a83d50c3..6893b9a2e1 100644 --- a/spec/support/noop_contract.rb +++ b/spec/support/noop_contract.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -28,8 +29,7 @@ #++ class NoopContract - def initialize(*_) - end + def initialize(*_); end def validate true diff --git a/spec/support/onboarding_helper.rb b/spec/support/onboarding_helper.rb index c4cf572170..ea8b4f8683 100644 --- a/spec/support/onboarding_helper.rb +++ b/spec/support/onboarding_helper.rb @@ -29,13 +29,13 @@ require 'spec_helper' module OnboardingHelper - def step_through_onboarding_wp_tour project, wp + def step_through_onboarding_wp_tour(project, wp) expect(page).not_to have_selector('.loading-indicator') - expect(page).to have_text 'This is the Work package list' + expect(page).to have_text 'This is the Work package list' next_button.click expect(page).to have_current_path project_work_package_path(project, wp.id, 'activity') - expect(page).to have_text 'Within the Work package details you find all relevant information' + expect(page).to have_text 'Within the Work package details you find all relevant information' next_button.click expect(page).to have_text 'With the arrow you can navigate back to the work package list.' diff --git a/spec/support/pages/admin/custom_actions/index.rb b/spec/support/pages/admin/custom_actions/index.rb index 62589f82b0..9c65492d43 100644 --- a/spec/support/pages/admin/custom_actions/index.rb +++ b/spec/support/pages/admin/custom_actions/index.rb @@ -96,19 +96,15 @@ module Pages private - def within_row_of(name) + def within_row_of(name, &block) within 'table' do - within find('tr', text: name) do - yield - end + within find('tr', text: name), &block end end - def within_buttons_of(name) + def within_buttons_of(name, &block) within_row_of(name) do - within find('.buttons') do - yield - end + within find('.buttons'), &block end end end diff --git a/spec/support/pages/admin/users/edit.rb b/spec/support/pages/admin/users/edit.rb index ac9b086f52..7950e39232 100644 --- a/spec/support/pages/admin/users/edit.rb +++ b/spec/support/pages/admin/users/edit.rb @@ -67,11 +67,9 @@ module Pages page.within("#member-#{membership.id}-roles-form") do page.all('.form--check-box').each do |f| - begin - f.set false - rescue Selenium::WebDriver::Error::InvalidElementStateError - # Happens if an element is disabled - end + f.set false + rescue Selenium::WebDriver::Error::InvalidElementStateError + # Happens if an element is disabled end Array(roles).each { |role| page.check role } page.find('.user-memberships--edit-submit-button').click diff --git a/spec/support/pages/admin/users/index.rb b/spec/support/pages/admin/users/index.rb index 9dbefff164..83e5980549 100644 --- a/spec/support/pages/admin/users/index.rb +++ b/spec/support/pages/admin/users/index.rb @@ -107,11 +107,9 @@ module Pages private - def within_user_row(user) + def within_user_row(user, &block) row = find('tr.user', text: user.login) - within row do - yield - end + within row, &block end end end diff --git a/spec/support/pages/form_filler.rb b/spec/support/pages/form_filler.rb index 837e8e938d..aac6354a94 100644 --- a/spec/support/pages/form_filler.rb +++ b/spec/support/pages/form_filler.rb @@ -65,7 +65,7 @@ module Pages end ## - # Checks (or unchecks) a check box. + # Checks (or unchecks) a check box. def set_checked!(field, key) if fields.include? key checked = fields[field] diff --git a/spec/support/pages/messages/show.rb b/spec/support/pages/messages/show.rb index 6871cccfbb..8a7f9d93fd 100644 --- a/spec/support/pages/messages/show.rb +++ b/spec/support/pages/messages/show.rb @@ -60,7 +60,7 @@ module Pages::Messages Message.last end - def quote(quoted_message: nil, subject: nil, content:) + def quote(content:, quoted_message: nil, subject: nil) if quoted_message within "#message-#{quoted_message.id} .contextual" do click_on 'Quote' diff --git a/spec/support/pages/page.rb b/spec/support/pages/page.rb index 915edc2354..1c50fdeac2 100644 --- a/spec/support/pages/page.rb +++ b/spec/support/pages/page.rb @@ -85,7 +85,7 @@ module Pages expect(current_path).to eql expected_path end - def expect_notification(type: :success, message:) + def expect_notification(message:, type: :success) if notification_type == :angular expect(page).to have_selector(".notification-box.-#{type}", text: message, wait: 20) elsif type == :error @@ -97,7 +97,7 @@ module Pages end end - def expect_and_dismiss_notification(type: :success, message:) + def expect_and_dismiss_notification(message:, type: :success) expect_notification(type: type, message: message) dismiss_notification! expect_no_notification(type: type, message: message) diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb index 22f086a3d6..d2e136f7af 100644 --- a/spec/support/pages/projects/index.rb +++ b/spec/support/pages/projects/index.rb @@ -65,7 +65,7 @@ module Pages set_toggle_filter(values) when 'created_at' set_created_at_filter(human_operator, values) - when /cf_[\d]+/ + when /cf_\d+/ set_custom_field_filter(selected_filter, human_operator, values) end end diff --git a/spec/support/pages/projects/settings.rb b/spec/support/pages/projects/settings.rb index 60af46c63d..d8064e9054 100644 --- a/spec/support/pages/projects/settings.rb +++ b/spec/support/pages/projects/settings.rb @@ -44,7 +44,7 @@ module Pages end # only notice is used as opposed to notification-box - def expect_notification(type: :notice, message:) + def expect_notification(message:, type: :notice) expect(page).to have_selector(".flash.#{type}", text: message, wait: 10) end diff --git a/spec/support/pages/work_packages/embedded_work_packages_table.rb b/spec/support/pages/work_packages/embedded_work_packages_table.rb index 12d37a541c..60631f8214 100644 --- a/spec/support/pages/work_packages/embedded_work_packages_table.rb +++ b/spec/support/pages/work_packages/embedded_work_packages_table.rb @@ -28,7 +28,7 @@ require 'support/pages/page' require 'support/pages/work_packages/work_packages_table' -require 'support/components/ng_select_autocomplete_helpers.rb' +require 'support/components/ng_select_autocomplete_helpers' module Pages class EmbeddedWorkPackagesTable < WorkPackagesTable diff --git a/spec/support/pages/work_packages/work_packages_table.rb b/spec/support/pages/work_packages/work_packages_table.rb index a8706d0984..633cd26c51 100644 --- a/spec/support/pages/work_packages/work_packages_table.rb +++ b/spec/support/pages/work_packages/work_packages_table.rb @@ -61,7 +61,7 @@ module Pages within(table_container) do attr_value_hash.each do |column, value| expect(page).to have_selector( - ".wp-row-#{work_package.id} td.#{column.to_s}", text: value.to_s, wait: 20 + ".wp-row-#{work_package.id} td.#{column}", text: value.to_s, wait: 20 ) end end @@ -294,6 +294,7 @@ module Pages filter_container = label_field.find(:xpath, '..') raise 'Missing ID on Filter (Angular not ready?)' if filter_container['id'].nil? + filter_container['id'].gsub('filter_', '') end end diff --git a/spec/support/pages/work_packages/work_packages_timeline.rb b/spec/support/pages/work_packages/work_packages_timeline.rb index 2a8f946719..ab4bb2594e 100644 --- a/spec/support/pages/work_packages/work_packages_timeline.rb +++ b/spec/support/pages/work_packages/work_packages_timeline.rb @@ -94,7 +94,7 @@ module Pages end def timeline_row(wp_id) - ::Components::Timelines::TimelineRow.new page.find(timeline_row_selector(wp_id)) + ::Components::Timelines::TimelineRow.new page.find(timeline_row_selector(wp_id)) end def zoom_in_button diff --git a/spec/support/permission_specs.rb b/spec/support/permission_specs.rb index 0a844107e6..27fdad6bb9 100644 --- a/spec/support/permission_specs.rb +++ b/spec/support/permission_specs.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require File.expand_path('../shared/become_member', __FILE__) +require File.expand_path('shared/become_member', __dir__) module PermissionSpecs def self.included(base) diff --git a/spec/support/puffing_billy_proxy.rb b/spec/support/puffing_billy_proxy.rb index 2892abbcba..65ca140f3d 100644 --- a/spec/support/puffing_billy_proxy.rb +++ b/spec/support/puffing_billy_proxy.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,7 +41,6 @@ require 'billy/capybara/rspec' require 'table_print' # Add this dependency to your gemfile - ## # Patch `puffing-billy`'s proxy so that it doesn't try to stop # eventmachine's reactor if it's not running. @@ -48,9 +48,8 @@ require 'table_print' # Add this dependency to your gemfile module BillyProxyPatch def stop return unless EM.reactor_running? - rescue Errno::ECONNRESET => e - STDERR.puts "Got error while shutting down Billy proxy" + warn "Got error while shutting down Billy proxy" end end diff --git a/spec/support/repository_helpers.rb b/spec/support/repository_helpers.rb index bfd6779841..11e0ecf348 100644 --- a/spec/support/repository_helpers.rb +++ b/spec/support/repository_helpers.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -38,14 +39,11 @@ def with_filesystem_repository(vendor, command = nil, &block) repo_dir = Dir.mktmpdir("#{vendor}_repository") fixture = File.join(Rails.root, "spec/fixtures/repositories/#{vendor}_repository.tar.gz") - ['tar', command].compact.each do |cmd| - begin - # Avoid `which`, as it's not POSIX - Open3.capture2e(cmd, '--version') - rescue Errno::ENOENT - skip "#{cmd} was not found in PATH. Skipping local repository specs" - end + # Avoid `which`, as it's not POSIX + Open3.capture2e(cmd, '--version') + rescue Errno::ENOENT + skip "#{cmd} was not found in PATH. Skipping local repository specs" end after(:all) do diff --git a/spec/support/request_with_header.rb b/spec/support/request_with_header.rb index cdcfd02691..d696b7528e 100644 --- a/spec/support/request_with_header.rb +++ b/spec/support/request_with_header.rb @@ -7,10 +7,7 @@ RSpec.configure do |c| end end - c.before(:each, type: :request, content_type: :json) do |ex| + c.before(:each, type: :request, content_type: :json) do |_ex| header('Content-Type', 'application/json') end end - - - diff --git a/spec/support/roles.rb b/spec/support/roles.rb index 146be660d2..f1f3cdf565 100644 --- a/spec/support/roles.rb +++ b/spec/support/roles.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -# shared_context 'with non-member permissions from non_member_permissions' do around do |example| non_member = Role.non_member diff --git a/spec/support/rspec_cleanup.rb b/spec/support/rspec_cleanup.rb index f50793f879..03a751fca2 100644 --- a/spec/support/rspec_cleanup.rb +++ b/spec/support/rspec_cleanup.rb @@ -19,6 +19,7 @@ RSpec.configure do |config| config.append_after(:suite) do [User, Project, WorkPackage].each do |cls| next if cls.count == 0 + raise <<-EOS Your specs left a #{cls} in the DB Did you use before(:all) instead of before diff --git a/spec/support/rspec_retry.rb b/spec/support/rspec_retry.rb index 0d61f13bff..b7b680762c 100644 --- a/spec/support/rspec_retry.rb +++ b/spec/support/rspec_retry.rb @@ -42,7 +42,7 @@ def retry_block(args: {}, screenshot: false, &block) end log_errors = Proc.new do |exception, try, elapsed_time, next_interval| - $stderr.puts <<-EOS.strip_heredoc + warn <<-EOS.strip_heredoc #{exception.class}: '#{exception.message}' #{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try. EOS @@ -51,7 +51,7 @@ def retry_block(args: {}, screenshot: false, &block) begin Capybara::Screenshot.screenshot_and_save_page rescue StandardError => e - $stderr.puts "Failed to take screenshot in retry_block: #{e} #{e.message}" + warn "Failed to take screenshot in retry_block: #{e} #{e.message}" end end end diff --git a/spec/support/scm/countable_repository.rb b/spec/support/scm/countable_repository.rb index 71b0c9d06a..23a44c70e7 100644 --- a/spec/support/scm/countable_repository.rb +++ b/spec/support/scm/countable_repository.rb @@ -72,7 +72,7 @@ shared_examples_for 'is a countable repository' do it 'falls back to using ruby when du is unavailable' do expect(::Open3).to receive(:capture3).with('du', any_args) - .and_raise(SystemCallError.new 'foo') + .and_raise(SystemCallError.new('foo')) expect(repository.scm).to receive(:count_storage_fallback).and_return(12345) expect(repository.scm.count_repository!).to eq(12345) diff --git a/spec/support/scm/relocate_repository.rb b/spec/support/scm/relocate_repository.rb index 6b987aa66e..b7ced5c201 100644 --- a/spec/support/scm/relocate_repository.rb +++ b/spec/support/scm/relocate_repository.rb @@ -3,17 +3,17 @@ shared_examples_for 'repository can be relocated' do |vendor| ::SCM::RelocateRepositoryJob.perform_now repository end let(:project) { FactoryBot.build :project } - let(:repository) { + let(:repository) do repo = FactoryBot.build("repository_#{vendor}".to_sym, - project: project, - scm_type: :managed) + project: project, + scm_type: :managed) repo.configure(:managed, nil) repo.save! perform_enqueued_jobs repo - } + end before do allow(Repository).to receive(:find).and_return(repository) @@ -47,14 +47,14 @@ shared_examples_for 'repository can be relocated' do |vendor| let(:url) { 'http://myreposerver.example.com/api/' } let(:config) { { manages: url } } - let(:repository) { + let(:repository) do stub_request(:post, url) .to_return(status: 200, body: { success: true, url: 'file:///foo/bar', path: '/tmp/foo/bar' }.to_json) FactoryBot.create("repository_#{vendor}".to_sym, - project: project, - scm_type: :managed) - } + project: project, + scm_type: :managed) + end before do stub_request(:post, url) diff --git a/spec/support/selector_helpers.rb b/spec/support/selector_helpers.rb index 1df496ae60..a8f253b3ea 100644 --- a/spec/support/selector_helpers.rb +++ b/spec/support/selector_helpers.rb @@ -26,7 +26,6 @@ # See docs/COPYRIGHT.rdoc for more details. #++ - module SelectorHelpers module_function diff --git a/spec/support/shared/acts_as_attachable.rb b/spec/support/shared/acts_as_attachable.rb index 5662bb4382..b15a4ee43b 100644 --- a/spec/support/shared/acts_as_attachable.rb +++ b/spec/support/shared/acts_as_attachable.rb @@ -134,7 +134,8 @@ shared_examples_for 'acts_as_attachable included' do expect(attachment2.reload.container).to eql model_instance if described_class.journaled? - expect(model_instance.journals.last.attachable_journals.map(&:attachment_id)).to match_array [attachment1.id, attachment2.id] + expect(model_instance.journals.last.attachable_journals.map(&:attachment_id)).to match_array [attachment1.id, + attachment2.id] end end end diff --git a/spec/support/shared/become_member.rb b/spec/support/shared/become_member.rb index f3e175f631..517308ac35 100644 --- a/spec/support/shared/become_member.rb +++ b/spec/support/shared/become_member.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/shared/forms_html.rb b/spec/support/shared/forms_html.rb index f0d2f6a285..5c5b0707a0 100644 --- a/spec/support/shared/forms_html.rb +++ b/spec/support/shared/forms_html.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/shared/permissions.rb b/spec/support/shared/permissions.rb index 01868c2851..87074c54db 100644 --- a/spec/support/shared/permissions.rb +++ b/spec/support/shared/permissions.rb @@ -29,7 +29,7 @@ module PermissionSpecHelpers def spec_permissions(test_denied = true) describe 'w/ valid auth' do - before do allow(User).to receive(:current).and_return valid_user end + before { allow(User).to receive(:current).and_return valid_user } it 'grants access' do fetch @@ -53,16 +53,16 @@ module PermissionSpecHelpers end end - describe 'w/o valid auth' do - before do allow(User).to receive(:current).and_return invalid_user end + if test_denied + describe 'w/o valid auth' do + before { allow(User).to receive(:current).and_return invalid_user } - it 'denies access' do - fetch + it 'denies access' do + fetch - if invalid_user.logged? - expect(response.response_code).to eq(403) - else - if controller.send(:api_request?) + if invalid_user.logged? + expect(response.response_code).to eq(403) + elsif controller.send(:api_request?) expect(response.response_code).to eq(401) else expect(response).to be_redirect @@ -70,7 +70,7 @@ module PermissionSpecHelpers end end end - end if test_denied + end end end diff --git a/spec/support/shared/with_config.rb b/spec/support/shared/with_config.rb index ee371630ba..bcfb916657 100644 --- a/spec/support/shared/with_config.rb +++ b/spec/support/shared/with_config.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/shared/with_direct_uploads.rb b/spec/support/shared/with_direct_uploads.rb index 28d4bc2600..280e3a99d2 100644 --- a/spec/support/shared/with_direct_uploads.rb +++ b/spec/support/shared/with_direct_uploads.rb @@ -98,7 +98,7 @@ class WithDirectUploads proxy.stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'options').and_return( headers: { 'Access-Control-Allow-Methods' => 'POST', - 'Access-Control-Allow-Origin' => '*' + 'Access-Control-Allow-Origin' => '*' }, code: 200 ) @@ -113,7 +113,7 @@ class WithDirectUploads def stub_with_redirect proxy .stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'post') - .and_return(Proc.new { |params, headers, body, url, method| + .and_return(Proc.new do |_params, _headers, body, _url, _method| key = body.scan(/key"\s*([^\s]+)\s/m).flatten.first redirect_url = body.scan(/success_action_redirect"\s*(http[^\s]+)\s/m).flatten.first ok = body =~ /X-Amz-Signature/ # check that the expected post to AWS was made with the form fields @@ -123,24 +123,24 @@ class WithDirectUploads headers: { 'Location' => ok ? redirect_url + '?key=' + CGI.escape(key) : nil, 'Access-Control-Allow-Methods' => 'POST', - 'Access-Control-Allow-Origin' => '*' + 'Access-Control-Allow-Origin' => '*' } } - }) + end) end def stub_with_status proxy .stub("https://" + OpenProject::Configuration.remote_storage_upload_host + ":443/", method: 'post') - .and_return(Proc.new { |params, headers, body, url, method| + .and_return(Proc.new do |_params, _headers, body, _url, _method| { - code: (body =~ /X-Amz-Signature/) ? 201 : 403, # check that the expected post to AWS was made with the form fields + code: body =~ /X-Amz-Signature/ ? 201 : 403, # check that the expected post to AWS was made with the form fields headers: { 'Access-Control-Allow-Methods' => 'POST', - 'Access-Control-Allow-Origin' => '*' + 'Access-Control-Allow-Origin' => '*' } } - }) + end) end def stub_uploader diff --git a/spec/support/shared/with_ee.rb b/spec/support/shared/with_ee.rb index 829093523c..66980abb82 100644 --- a/spec/support/shared/with_ee.rb +++ b/spec/support/shared/with_ee.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/shared/with_settings.rb b/spec/support/shared/with_settings.rb index 2bdb8ed739..05d65b38f6 100644 --- a/spec/support/shared/with_settings.rb +++ b/spec/support/shared/with_settings.rb @@ -53,7 +53,7 @@ RSpec.configure do |config| raise "#{k} is not a valid setting" unless Setting.respond_to?(name) - expect(name).not_to start_with("localized_"), ->() do + expect(name).not_to start_with("localized_"), -> do base = name[10..-1] "Don't use `#{name}` in `with_settings`. Do this: `with_settings: { #{base}: { \"en\" => \"#{v}\" } }`" diff --git a/spec/support/tempdir.rb b/spec/support/tempdir.rb index 0ce41f65f0..61ba41932c 100644 --- a/spec/support/tempdir.rb +++ b/spec/support/tempdir.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/support/webmock.rb b/spec/support/webmock.rb index 576bdeda8e..61edfb8805 100644 --- a/spec/support/webmock.rb +++ b/spec/support/webmock.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -37,17 +38,15 @@ RSpec.configure do |config| end config.around(:example, webmock: true) do |example| - begin - # When we enable webmock, no connections other than stubbed ones are allowed. - # We will exempt local connections from this block, since selenium etc. - # uses localhost to communicate with the browser. - # Leaving this off will randomly fail some specs with WebMock::NetConnectNotAllowedError - WebMock.disable_net_connect!(allow_localhost: true, allow: ["selenium-hub", Capybara.server_host]) - WebMock.enable! - example.run - ensure - WebMock.allow_net_connect! - WebMock.disable! - end + # When we enable webmock, no connections other than stubbed ones are allowed. + # We will exempt local connections from this block, since selenium etc. + # uses localhost to communicate with the browser. + # Leaving this off will randomly fail some specs with WebMock::NetConnectNotAllowedError + WebMock.disable_net_connect!(allow_localhost: true, allow: ["selenium-hub", Capybara.server_host]) + WebMock.enable! + example.run + ensure + WebMock.allow_net_connect! + WebMock.disable! end end diff --git a/spec/views/layouts/base.html.erb_spec.rb b/spec/views/layouts/base.html.erb_spec.rb index 6816feba6a..3e2cb5102c 100644 --- a/spec/views/layouts/base.html.erb_spec.rb +++ b/spec/views/layouts/base.html.erb_spec.rb @@ -90,8 +90,7 @@ describe 'layouts/base', type: :view do end context 'with omni_auth_direct_login enabled', - with_config: { omniauth_direct_login_provider: 'some_provider' } do - + with_config: { omniauth_direct_login_provider: 'some_provider' } do it 'shows just a sign-in link, no menu' do expect(rendered).to have_selector "a[href='/login']" expect(rendered).not_to have_selector 'div#nav-login-content' diff --git a/spec/views/users/edit.html.erb_spec.rb b/spec/views/users/edit.html.erb_spec.rb index 0fe3443b87..7a60b1f94c 100644 --- a/spec/views/users/edit.html.erb_spec.rb +++ b/spec/views/users/edit.html.erb_spec.rb @@ -41,7 +41,7 @@ describe 'users/edit', type: :view do context 'authentication provider' do let(:user) do FactoryBot.build :user, id: 1, # id is required to create route to edit - identity_url: 'test_provider:veryuniqueid' + identity_url: 'test_provider:veryuniqueid' end before do diff --git a/spec/views/users/index.html.erb_spec.rb b/spec/views/users/index.html.erb_spec.rb index 31946b5844..79fdfa0d1a 100644 --- a/spec/views/users/index.html.erb_spec.rb +++ b/spec/views/users/index.html.erb_spec.rb @@ -56,7 +56,7 @@ describe 'users/index', type: :view do context "with an Enterprise token" do before do - allow(OpenProject::Enterprise).to receive(:token).and_return(Struct.new(:restrictions).new({active_user_count: 5})) + allow(OpenProject::Enterprise).to receive(:token).and_return(Struct.new(:restrictions).new({ active_user_count: 5 })) end it "shows the current number of active and allowed users" do diff --git a/spec/views/work_package/auto_complete/index_spec.rb b/spec/views/work_package/auto_complete/index_spec.rb index 202f69cdb9..e51da0275c 100644 --- a/spec/views/work_package/auto_complete/index_spec.rb +++ b/spec/views/work_package/auto_complete/index_spec.rb @@ -29,10 +29,10 @@ require 'spec_helper' describe 'work_packages/auto_completes/index.html.erb', type: :view do - let(:work_package) { + let(:work_package) do FactoryBot.build(:work_package, - subject: '') - } + subject: '') + end it 'escapes work package subject in auto-completion' do assign :work_packages, [work_package] diff --git a/spec/workers/application_job_spec.rb b/spec/workers/application_job_spec.rb index 86abca766d..8e28ab5a2d 100644 --- a/spec/workers/application_job_spec.rb +++ b/spec/workers/application_job_spec.rb @@ -41,7 +41,7 @@ describe ApplicationJob do describe 'resets request store' do it 'resets request store on each perform' do - job = JobMock.new(->() do + job = JobMock.new(-> do expect(RequestStore[:test_value]).to be_nil RequestStore[:test_value] = 42 end) diff --git a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb index 6e6ed6b0d6..dc83bfc03c 100644 --- a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb +++ b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb @@ -110,4 +110,4 @@ describe Attachments::FinishDirectUploadJob, 'integration', type: :job do it_behaves_like 'turning pending attachment into a standard attachment' it_behaves_like "adding a journal to the attachment in the name of the attachment's author" end -end \ No newline at end of file +end diff --git a/spec/workers/copy_project_job_spec.rb b/spec/workers/copy_project_job_spec.rb index d24825e4f5..7161608dea 100644 --- a/spec/workers/copy_project_job_spec.rb +++ b/spec/workers/copy_project_job_spec.rb @@ -32,7 +32,7 @@ describe CopyProjectJob, type: :model do let(:project) { FactoryBot.create(:project, public: false) } let(:user) { FactoryBot.create(:user) } let(:role) { FactoryBot.create(:role, permissions: [:copy_projects]) } - let(:params) { {name: 'Copy', identifier: 'copy'} } + let(:params) { { name: 'Copy', identifier: 'copy' } } let(:maildouble) { double('Mail::Message', deliver: true) } before do @@ -57,10 +57,9 @@ describe CopyProjectJob, type: :model do end copy_job.perform user_id: user_de.id, - source_project_id: source_project.id, - target_project_params: {}, - associations_to_copy: [] - + source_project_id: source_project.id, + target_project_params: {}, + associations_to_copy: [] end end @@ -88,8 +87,10 @@ describe CopyProjectJob, type: :model do CopyProjectJob.new(job_args).tap(&:perform_now) end - let(:params) { {name: 'Copy', identifier: 'copy', type_ids: [type.id], work_package_custom_field_ids: [custom_field.id]} } - let(:expected_error_message) { "#{WorkPackage.model_name.human} '#{work_package.type.name} ##{work_package.id}: #{work_package.subject}': #{custom_field.name} #{I18n.t('errors.messages.blank')}." } + let(:params) { { name: 'Copy', identifier: 'copy', type_ids: [type.id], work_package_custom_field_ids: [custom_field.id] } } + let(:expected_error_message) do + "#{WorkPackage.model_name.human} '#{work_package.type.name} ##{work_package.id}: #{work_package.subject}': #{custom_field.name} #{I18n.t('errors.messages.blank')}." + end before do source_project.work_package_custom_fields << custom_field @@ -162,7 +163,7 @@ describe CopyProjectJob, type: :model do end end - let(:params) { {name: 'Copy', identifier: 'copy'} } + let(:params) { { name: 'Copy', identifier: 'copy' } } before do allow(User).to receive(:current).and_return(admin) diff --git a/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb b/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb index 03d28fbfc8..806fccfc7f 100644 --- a/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb +++ b/spec/workers/mail_notification_jobs/deliver_watcher_notification_job_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec/workers/mail_notification_jobs/deliver_work_package_notification_job_spec.rb b/spec/workers/mail_notification_jobs/deliver_work_package_notification_job_spec.rb index 4465f32d19..9da5e3c841 100644 --- a/spec/workers/mail_notification_jobs/deliver_work_package_notification_job_spec.rb +++ b/spec/workers/mail_notification_jobs/deliver_work_package_notification_job_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,15 +33,15 @@ require 'spec_helper' describe DeliverWorkPackageNotificationJob, type: :model do let(:project) { FactoryBot.create(:project) } let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) } - let(:recipient) { + let(:recipient) do FactoryBot.create(:user, member_in_project: project, member_through_role: role) - } + end let(:author) { FactoryBot.create(:user) } - let(:work_package) { + let(:work_package) do FactoryBot.create(:work_package, - project: project, - author: author) - } + project: project, + author: author) + end let(:journal) { work_package.journals.first } let(:instance) { described_class.new } subject { instance.perform(journal.id, recipient.id, author.id) } diff --git a/spec/workers/scm/create_local_repository_job_spec.rb b/spec/workers/scm/create_local_repository_job_spec.rb index 795e945896..6e2238665a 100644 --- a/spec/workers/scm/create_local_repository_job_spec.rb +++ b/spec/workers/scm/create_local_repository_job_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -49,16 +50,16 @@ describe SCM::CreateLocalRepositoryJob do include_context 'with tmpdir' let(:project) { FactoryBot.build(:project) } - let(:repository) { + let(:repository) do repo = Repository::Subversion.new(scm_type: :managed) repo.project = project repo.configure(:managed, nil) repo - } + end - let(:config) { + let(:config) do { subversion: { mode: mode, manages: tmpdir } } - } + end shared_examples 'creates a directory with mode' do |expected| it 'creates the directory' do @@ -71,7 +72,7 @@ describe SCM::CreateLocalRepositoryJob do end context 'with mode set' do - let(:mode) { 0770 } + let(:mode) { 0o770 } it 'uses the correct mode' do expect(instance).to receive(:create).with(mode) @@ -84,7 +85,7 @@ describe SCM::CreateLocalRepositoryJob do context 'with string mode' do let(:mode) { '0770' } it 'uses the correct mode' do - expect(instance).to receive(:create).with(0770) + expect(instance).to receive(:create).with(0o770) subject end @@ -94,7 +95,7 @@ describe SCM::CreateLocalRepositoryJob do context 'with no mode set' do let(:mode) { nil } it 'uses the default mode' do - expect(instance).to receive(:create).with(0700) + expect(instance).to receive(:create).with(0o700) subject end diff --git a/spec/workers/work_packages/exports/export_job_spec.rb b/spec/workers/work_packages/exports/export_job_spec.rb index e1937bf276..e9ae9a9a51 100644 --- a/spec/workers/work_packages/exports/export_job_spec.rb +++ b/spec/workers/work_packages/exports/export_job_spec.rb @@ -100,7 +100,7 @@ describe WorkPackages::Exports::ExportJob do describe 'query passing' do context 'passing in group_by through attributes' do - let(:query_attributes) { { group_by: 'assigned_to' }} + let(:query_attributes) { { group_by: 'assigned_to' } } let(:mime_type) { :pdf } it 'updates the query from attributes' do diff --git a/spec_legacy/fixtures/files/060719210727_source.rb b/spec_legacy/fixtures/files/060719210727_source.rb index 53f651bbaa..c27ad5d18c 100644 --- a/spec_legacy/fixtures/files/060719210727_source.rb +++ b/spec_legacy/fixtures/files/060719210727_source.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/functional/application_controller_spec.rb b/spec_legacy/functional/application_controller_spec.rb index 4edbc8ae5f..8926311e28 100644 --- a/spec_legacy/functional/application_controller_spec.rb +++ b/spec_legacy/functional/application_controller_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/functional/sys_controller_spec.rb b/spec_legacy/functional/sys_controller_spec.rb index 051372a6f3..1ba8318824 100644 --- a/spec_legacy/functional/sys_controller_spec.rb +++ b/spec_legacy/functional/sys_controller_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -39,7 +40,6 @@ describe SysController, type: :controller do describe 'when enabled', with_settings: { sys_api_enabled?: true } do - it 'should projects with repository enabled' do get :projects assert_response :success diff --git a/spec_legacy/functional/user_mailer_spec.rb b/spec_legacy/functional/user_mailer_spec.rb index 93a3a7c89b..a61791de95 100644 --- a/spec_legacy/functional/user_mailer_spec.rb +++ b/spec_legacy/functional/user_mailer_spec.rb @@ -223,7 +223,7 @@ describe UserMailer, type: :mailer do end it 'should message posted message id' do - user = FactoryBot.create(:user) + user = FactoryBot.create(:user) FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false }) message = FactoryBot.create(:message) UserMailer.message_posted(user, message, user).deliver_now @@ -238,7 +238,7 @@ describe UserMailer, type: :mailer do end it 'should reply posted message id' do - user = FactoryBot.create(:user) + user = FactoryBot.create(:user) FactoryBot.create(:user_preference, user: user, others: { no_self_notified: false }) parent = FactoryBot.create(:message) message = FactoryBot.create(:message, parent: parent) @@ -249,7 +249,8 @@ describe UserMailer, type: :mailer do assert_match mail.references, UserMailer.generate_message_id(parent, user) assert_select_email do # link to the reply - assert_select 'a[href=?]', "#{Setting.protocol}://#{Setting.host_name}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", text: message.subject + assert_select 'a[href=?]', + "#{Setting.protocol}://#{Setting.host_name}/topics/#{message.root.id}?r=#{message.id}#message-#{message.id}", text: message.subject end end @@ -357,7 +358,7 @@ describe UserMailer, type: :mailer do context 'layout', with_settings: { - available_languages: [:en, :de], + available_languages: %i[en de], emails_header: { "de" => 'deutscher header' } @@ -386,30 +387,30 @@ describe UserMailer, type: :mailer do project.save related_issue = FactoryBot.create(:work_package, - subject: 'My related Ticket', - type: type, - project: project) + subject: 'My related Ticket', + type: type, + project: project) issue = FactoryBot.create(:work_package, - subject: 'My awesome Ticket', - type: type, - project: project, - description: 'nothing here yet') + subject: 'My awesome Ticket', + type: type, + project: project, + description: 'nothing here yet') # now change the issue, to get a nice journal issue.description = "This is related to issue ##{related_issue.id}\n" repository = FactoryBot.create(:repository_subversion, - project: project) + project: project) changeset = FactoryBot.create :changeset, - repository: repository, - comments: 'This commit fixes #1, #2 and references #1 and #3' + repository: repository, + comments: 'This commit fixes #1, #2 and references #1 and #3' issue.description += " A reference to a changeset r#{changeset.revision}\n" if changeset attachment = FactoryBot.build(:attachment, - author: issue.author) + author: issue.author) issue.attachments << attachment diff --git a/spec_legacy/functional/wiki_controller_spec.rb b/spec_legacy/functional/wiki_controller_spec.rb index ce6e277e17..05dc4bff25 100644 --- a/spec_legacy/functional/wiki_controller_spec.rb +++ b/spec_legacy/functional/wiki_controller_spec.rb @@ -88,11 +88,11 @@ describe WikiController, type: :controller do it 'should create page' do session[:user_id] = 2 post :create, params: { project_id: 1, - id: 'New page', - content: { comments: 'Created the page', - text: "h1. New page\n\nThis is a new page", - page: { title: 'New page', - parent_id: '' } } } + id: 'New page', + content: { comments: 'Created the page', + text: "h1. New page\n\nThis is a new page", + page: { title: 'New page', + parent_id: '' } } } assert_redirected_to action: 'show', project_id: 'ecookbook', id: 'new-page' page = wiki.find_page('New page') assert !page.new_record? @@ -127,17 +127,17 @@ describe WikiController, type: :controller do it 'should history' do FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: 'h1. CookBook documentation') + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: 'h1. CookBook documentation') FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...") + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...") FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: "h1. CookBook documentation\nSome updated [[documentation]] here...") + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: "h1. CookBook documentation\nSome updated [[documentation]] here...") get :history, params: { project_id: 1, id: 'CookBook documentation' } assert_response :success @@ -149,9 +149,9 @@ describe WikiController, type: :controller do it 'should history with one version' do FactoryBot.create :wiki_content_journal, - journable_id: 2, - data: FactoryBot.build(:journal_wiki_content_journal, - text: "h1. Another page\n\n\nthis is a link to ticket: #2") + journable_id: 2, + data: FactoryBot.build(:journal_wiki_content_journal, + text: "h1. Another page\n\n\nthis is a link to ticket: #2") get :history, params: { project_id: 1, id: 'Another page' } assert_response :success assert_template 'history' @@ -162,32 +162,33 @@ describe WikiController, type: :controller do it 'should diff' do journal_from = FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: 'h1. CookBook documentation') + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: 'h1. CookBook documentation') journal_to = FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...") + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: "h1. CookBook documentation\n\n\nSome updated [[documentation]] here...") - get :diff, params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version, version_from: journal_from.version } + get :diff, + params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version, version_from: journal_from.version } assert_response :success assert_template 'diff' assert_select 'ins', attributes: { class: 'diffins' }, - content: /updated/ + content: /updated/ end it 'should annotate' do FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: 'h1. CookBook documentation') + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: 'h1. CookBook documentation') journal_to = FactoryBot.create :wiki_content_journal, - journable_id: 1, - data: FactoryBot.build(:journal_wiki_content_journal, - text: "h1. CookBook documentation\n\n\nSome [[documentation]] here...") + journable_id: 1, + data: FactoryBot.build(:journal_wiki_content_journal, + text: "h1. CookBook documentation\n\n\nSome [[documentation]] here...") - get :annotate, params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version } + get :annotate, params: { project_id: 1, id: 'CookBook documentation', version: journal_to.version } assert_response :success assert_template 'annotate' # Line 1 @@ -291,14 +292,14 @@ describe WikiController, type: :controller do assert_equal pages.first.content.updated_at, pages.first.updated_at assert_select 'ul', attributes: { class: 'pages-hierarchy' }, - child: { tag: 'li', child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/CookBook%20documentation' }, - content: 'CookBook documentation' }, - child: { tag: 'ul', - child: { tag: 'li', - child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/Page%20with%20an%20inline%20image' }, - content: 'Page with an inline image' } } } }, - child: { tag: 'li', child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/Another%20page' }, - content: 'Another page' } } + child: { tag: 'li', child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/CookBook%20documentation' }, + content: 'CookBook documentation' }, + child: { tag: 'ul', + child: { tag: 'li', + child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/Page%20with%20an%20inline%20image' }, + content: 'Page with an inline image' } } } }, + child: { tag: 'li', child: { tag: 'a', attributes: { href: '/projects/ecookbook/wiki/Another%20page' }, + content: 'Another page' } } end it 'should index should include atom link' do diff --git a/spec_legacy/legacy_spec_helper.rb b/spec_legacy/legacy_spec_helper.rb index 552c21613d..1fd3857133 100644 --- a/spec_legacy/legacy_spec_helper.rb +++ b/spec_legacy/legacy_spec_helper.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,7 @@ ENV['RAILS_ENV'] = 'test' -require File.expand_path('../../config/environment', __FILE__) +require File.expand_path('../config/environment', __dir__) require 'fileutils' require 'rspec/mocks' diff --git a/spec_legacy/support/legacy_assertions.rb b/spec_legacy/support/legacy_assertions.rb index 0f6e3861f6..9f268f2be6 100644 --- a/spec_legacy/support/legacy_assertions.rb +++ b/spec_legacy/support/legacy_assertions.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -47,12 +48,13 @@ module LegacyAssertionsAndHelpers def initialize_attachments Attachment.all.each do |a| if a.file.filename.nil? - begin # existing file under `spec/fixtures/files` + # existing file under `spec/fixtures/files` + begin a.file = uploaded_test_file a.disk_filename, a.attributes['content_type'], original_filename: a.attributes['filename'] - rescue # imaginary file: create it on-the-fly + rescue StandardError # imaginary file: create it on-the-fly a.file = LegacyFileHelpers.mock_uploaded_file name: a.attributes['filename'], - content_type: a.attributes['content_type'] + content_type: a.attributes['content_type'] end a.save! @@ -84,7 +86,7 @@ module LegacyAssertionsAndHelpers def with_settings(options, &_block) saved_settings = options.keys.inject({}) { |h, k| h[k] = Setting[k].dup; h } - options.each do |k, v| Setting[k] = v end + options.each { |k, v| Setting[k] = v } yield ensure saved_settings.each { |k, v| Setting[k] = v } @@ -132,15 +134,15 @@ module LegacyAssertionsAndHelpers return false if !!ENV['CI'] @test_ldap = Net::LDAP.new(host: '127.0.0.1', port: 389) - return @test_ldap.bind + @test_ldap.bind rescue Exception => e # LDAP is not listening - return nil + nil end # Returns the path to the test +vendor+ repository def repository_path(vendor) - File.join(Rails.root.to_s.gsub(%r{config\/\.\.}, ''), "/tmp/test/#{vendor.downcase}_repository") + File.join(Rails.root.to_s.gsub(%r{config/\.\.}, ''), "/tmp/test/#{vendor.downcase}_repository") end # Returns the url of the subversion test repository @@ -371,10 +373,9 @@ module LegacyAssertionsAndHelpers # # @param [String] url Request def should_respond_with_content_type_based_on_url(url) - case - when url.match(/xml/i) + if url.match(/xml/i) should_respond_with_content_type 'application/xml' - when url.match(/json/i) + elsif url.match(/json/i) should_respond_with_content_type 'application/json' else raise "Unknown content type for should_respond_with_content_type_based_on_url: #{url}" @@ -388,10 +389,9 @@ module LegacyAssertionsAndHelpers # # @param [String] url Request def should_be_a_valid_response_string_based_on_url(url) - case - when url.match(/xml/i) + if url.match(/xml/i) should_be_a_valid_xml_string - when url.match(/json/i) + elsif url.match(/json/i) should_be_a_valid_json_string else raise "Unknown content type for should_be_a_valid_response_based_on_url: #{url}" diff --git a/spec_legacy/unit/category_spec.rb b/spec_legacy/unit/category_spec.rb index 92549865c7..f9435200c9 100644 --- a/spec_legacy/unit/category_spec.rb +++ b/spec_legacy/unit/category_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/comment_spec.rb b/spec_legacy/unit/comment_spec.rb index f4220b1940..c649717b86 100644 --- a/spec_legacy/unit/comment_spec.rb +++ b/spec_legacy/unit/comment_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/custom_value_spec.rb b/spec_legacy/unit/custom_value_spec.rb index 08bb0af153..0dfef0ba3f 100644 --- a/spec_legacy/unit/custom_value_spec.rb +++ b/spec_legacy/unit/custom_value_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -123,9 +124,9 @@ describe CustomValue, type: :model do user = FactoryBot.create :user custom_field = FactoryBot.create :user_custom_field, field_format: 'string' custom_value = FactoryBot.create :principal_custom_value, - custom_field: custom_field, - customized: user, - value: '01 23 45 67 89' + custom_field: custom_field, + customized: user, + value: '01 23 45 67 89' user.reload assert !user.custom_values.empty? diff --git a/spec_legacy/unit/enumeration_spec.rb b/spec_legacy/unit/enumeration_spec.rb index afd321ad13..13d12603a4 100644 --- a/spec_legacy/unit/enumeration_spec.rb +++ b/spec_legacy/unit/enumeration_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/helpers/sort_helper_spec.rb b/spec_legacy/unit/helpers/sort_helper_spec.rb index 6f882a626c..6bf7446f75 100644 --- a/spec_legacy/unit/helpers/sort_helper_spec.rb +++ b/spec_legacy/unit/helpers/sort_helper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/lib/redmine/hook_spec.rb b/spec_legacy/unit/lib/redmine/hook_spec.rb index a3da0d070f..b689c7a575 100644 --- a/spec_legacy/unit/lib/redmine/hook_spec.rb +++ b/spec_legacy/unit/lib/redmine/hook_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/lib/redmine/i18n_spec.rb b/spec_legacy/unit/lib/redmine/i18n_spec.rb index e1c0752ac3..8092f7b9c2 100644 --- a/spec_legacy/unit/lib/redmine/i18n_spec.rb +++ b/spec_legacy/unit/lib/redmine/i18n_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,13 +41,13 @@ describe Redmine::I18n do Setting.date_format = '' valid_languages.each do |lang| set_language_if_valid lang - expect { + expect do format_date(Date.today) format_time(Time.now) format_time(Time.now, false) refute_equal 'default', ::I18n.l(Date.today, format: :default), "date.formats.default missing in #{lang}" refute_equal 'time', ::I18n.l(Time.now, format: :time), "time.formats.time missing in #{lang}" - }.not_to raise_error + end.not_to raise_error assert I18n.t('date.day_names').is_a?(Array) assert_equal 7, I18n.t('date.day_names').size @@ -102,9 +103,9 @@ describe Redmine::I18n do it 'should number to human size for each language' do valid_languages.each do |lang| set_language_if_valid lang - expect { + expect do number_to_human_size(1024 * 1024 * 4) - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec_legacy/unit/lib/redmine/menu_manager/mapper_spec.rb b/spec_legacy/unit/lib/redmine/menu_manager/mapper_spec.rb index bbd1a7eee6..743387e718 100644 --- a/spec_legacy/unit/lib/redmine/menu_manager/mapper_spec.rb +++ b/spec_legacy/unit/lib/redmine/menu_manager/mapper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -29,7 +30,6 @@ require 'legacy_spec_helper' describe Redmine::MenuManager::Mapper do - it 'should push onto root' do menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {}) menu_mapper.push :test_overview, { controller: 'projects', action: 'show' }, {} @@ -175,12 +175,12 @@ describe Redmine::MenuManager::Mapper do menu.push :help, OpenProject::Static::Links.help_link, last: true end - expect { + expect do Redmine::MenuManager.map :test_menu do |menu| menu.delete(:administration) menu.delete(:help) menu.push :test_overview, { controller: 'projects', action: 'show' }, {} end - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec_legacy/unit/lib/redmine/menu_manager/menu_helper_spec.rb b/spec_legacy/unit/lib/redmine/menu_manager/menu_helper_spec.rb index 2d21dbc925..deaac6b14a 100644 --- a/spec_legacy/unit/lib/redmine/menu_manager/menu_helper_spec.rb +++ b/spec_legacy/unit/lib/redmine/menu_manager/menu_helper_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -96,17 +97,17 @@ describe Redmine::MenuManager::MenuHelper, type: :helper do parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, { controller: 'work_packages', action: 'index' }, - - children: Proc.new {|_p| + children: Proc.new do |_p| children = [] 3.times do |time| children << Redmine::MenuManager::MenuItem.new("test_child_#{time}", - { controller: 'work_packages', action: 'index' }, + { + controller: 'work_packages', action: 'index' + }, {}) end children - } - ) + end) @response.body = render_menu_node(parent_node, Project.find(1)) html_node = Nokogiri::HTML(@response.body) @@ -125,27 +126,27 @@ describe Redmine::MenuManager::MenuHelper, type: :helper do parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, { controller: 'work_packages', action: 'index' }, - - children: Proc.new {|_p| + children: Proc.new do |_p| children = [] 3.times do |time| - children << Redmine::MenuManager::MenuItem.new("test_child_#{time}", { controller: 'work_packages', action: 'index' }, {}) + children << Redmine::MenuManager::MenuItem.new("test_child_#{time}", + { controller: 'work_packages', action: 'index' }, {}) end children - } - ) + end) parent_node << Redmine::MenuManager::MenuItem.new(:child_node, { controller: 'work_packages', action: 'index' }, - - children: Proc.new {|_p| + children: Proc.new do |_p| children = [] 6.times do |time| - children << Redmine::MenuManager::MenuItem.new("test_dynamic_child_#{time}", { controller: 'work_packages', action: 'index' }, {}) + children << Redmine::MenuManager::MenuItem.new( + "test_dynamic_child_#{time}", { controller: 'work_packages', + action: 'index' }, {} + ) end children - } - ) + end) @response.body = render_menu_node(parent_node, Project.find(1)) @@ -172,9 +173,10 @@ describe Redmine::MenuManager::MenuHelper, type: :helper do it 'should render menu node with children without an array' do parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, { controller: 'work_packages', action: 'index' }, - - children: Proc.new { |_p| Redmine::MenuManager::MenuItem.new('test_child', { controller: 'work_packages', action: 'index' }, {}) }, - ) + children: Proc.new do |_p| + Redmine::MenuManager::MenuItem.new('test_child', + { controller: 'work_packages', action: 'index' }, {}) + end) assert_raises Redmine::MenuManager::MenuError, ':children must be an array of MenuItems' do @response.body = render_menu_node(parent_node, Project.find(1)) @@ -184,9 +186,7 @@ describe Redmine::MenuManager::MenuHelper, type: :helper do it 'should render menu node with incorrect children' do parent_node = Redmine::MenuManager::MenuItem.new(:parent_node, { controller: 'work_packages', action: 'index' }, - - children: Proc.new { |_p| ['a string'] } - ) + children: Proc.new { |_p| ['a string'] }) assert_raises Redmine::MenuManager::MenuError, ':children must be an array of MenuItems' do @response.body = render_menu_node(parent_node, Project.find(1)) diff --git a/spec_legacy/unit/lib/redmine/menu_manager/menu_item_spec.rb b/spec_legacy/unit/lib/redmine/menu_manager/menu_item_spec.rb index 75b67ff5f8..f45057e516 100644 --- a/spec_legacy/unit/lib/redmine/menu_manager/menu_item_spec.rb +++ b/spec_legacy/unit/lib/redmine/menu_manager/menu_item_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -40,8 +41,8 @@ describe Redmine::MenuManager::MenuItem do Redmine::MenuManager.map :test_menu do |menu| menu.push(:parent, '/test', {}) - menu.push(:child_menu, '/test', parent: :parent) - menu.push(:child2_menu, '/test', parent: :parent) + menu.push(:child_menu, '/test', parent: :parent) + menu.push(:child2_menu, '/test', parent: :parent) end # context new menu item @@ -70,47 +71,36 @@ describe Redmine::MenuManager::MenuItem do it 'should new menu item should require a proc to use for the if condition' do assert_raises ArgumentError do Redmine::MenuManager::MenuItem.new(:test_error, '/test', - - if: ['not_a_proc'] - ) + if: ['not_a_proc']) end assert Redmine::MenuManager::MenuItem.new(:test_good_if, '/test', - - if: Proc.new {} - ) + if: Proc.new {}) end it 'should new menu item should allow a hash for extra html options' do assert_raises ArgumentError do Redmine::MenuManager::MenuItem.new(:test_error, '/test', - - html: ['not_a_hash'] - ) + html: ['not_a_hash']) end assert Redmine::MenuManager::MenuItem.new(:test_good_html, '/test', - html: { data: 'foo' } - ) + html: { data: 'foo' }) end it 'should new menu item should require a proc to use the children option' do assert_raises ArgumentError do Redmine::MenuManager::MenuItem.new(:test_error, '/test', - - children: ['not_a_proc'] - ) + children: ['not_a_proc']) end assert Redmine::MenuManager::MenuItem.new(:test_good_children, '/test', - - children: Proc.new {} - ) + children: Proc.new {}) end it 'should new should not allow setting the parent item to the current item' do assert_raises ArgumentError do - Redmine::MenuManager::MenuItem.new(:test_error, '/test', parent: :test_error) + Redmine::MenuManager::MenuItem.new(:test_error, '/test', parent: :test_error) end end diff --git a/spec_legacy/unit/lib/redmine/mime_type_spec.rb b/spec_legacy/unit/lib/redmine/mime_type_spec.rb index b3c9289184..60659c18eb 100644 --- a/spec_legacy/unit/lib/redmine/mime_type_spec.rb +++ b/spec_legacy/unit/lib/redmine/mime_type_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,8 +33,7 @@ describe Redmine::MimeType do it 'should of' do to_test = { 'test.unk' => nil, 'test.txt' => 'text/plain', - 'test.c' => 'text/x-c', - } + 'test.c' => 'text/x-c' } to_test.each do |name, expected| assert_equal expected, Redmine::MimeType.of(name) end @@ -42,8 +42,7 @@ describe Redmine::MimeType do it 'should css class of' do to_test = { 'test.unk' => nil, 'test.txt' => 'text-plain', - 'test.c' => 'text-x-c', - } + 'test.c' => 'text-x-c' } to_test.each do |name, expected| assert_equal expected, Redmine::MimeType.css_class_of(name) end @@ -52,8 +51,7 @@ describe Redmine::MimeType do it 'should main mimetype of' do to_test = { 'test.unk' => nil, 'test.txt' => 'text', - 'test.c' => 'text', - } + 'test.c' => 'text' } to_test.each do |name, expected| assert_equal expected, Redmine::MimeType.main_mimetype_of(name) end @@ -62,8 +60,7 @@ describe Redmine::MimeType do it 'should is type' do to_test = { ['text', 'test.unk'] => false, ['text', 'test.txt'] => true, - ['text', 'test.c'] => true, - } + ['text', 'test.c'] => true } to_test.each do |args, expected| assert_equal expected, Redmine::MimeType.is_type?(*args) end diff --git a/spec_legacy/unit/lib/redmine/notifiable_spec.rb b/spec_legacy/unit/lib/redmine/notifiable_spec.rb index 6880749659..4a040c0c0c 100644 --- a/spec_legacy/unit/lib/redmine/notifiable_spec.rb +++ b/spec_legacy/unit/lib/redmine/notifiable_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -32,7 +33,8 @@ describe Redmine::Notifiable do it 'should all' do assert_equal 11, Redmine::Notifiable.all.length - %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated news_added news_comment_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable| + %w(work_package_added work_package_updated work_package_note_added status_updated work_package_priority_updated news_added + news_comment_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable| assert Redmine::Notifiable.all.map(&:name).include?(notifiable), "missing #{notifiable}" end end diff --git a/spec_legacy/unit/lib/redmine/unified_diff_spec.rb b/spec_legacy/unit/lib/redmine/unified_diff_spec.rb index 00a692b76f..bcc8cee09e 100644 --- a/spec_legacy/unit/lib/redmine/unified_diff_spec.rb +++ b/spec_legacy/unit/lib/redmine/unified_diff_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -27,7 +28,7 @@ # See docs/COPYRIGHT.rdoc for more details. #++ -require 'legacy_spec_helper' +require_relative '../../../legacy_spec_helper' describe Redmine::UnifiedDiff do it 'should subversion diff' do @@ -99,58 +100,58 @@ describe Redmine::UnifiedDiff do end it 'should line starting with dashes' do - diff = Redmine::UnifiedDiff.new(<<-DIFF ---- old.txt Wed Nov 11 14:24:58 2009 -+++ new.txt Wed Nov 11 14:25:02 2009 -@@ -1,8 +1,4 @@ --Lines that starts with dashes: -- -------------------------- ---- file.c -------------------------- -+A line that starts with dashes: + diff = Redmine::UnifiedDiff.new(<<~DIFF + --- old.txt Wed Nov 11 14:24:58 2009 + +++ new.txt Wed Nov 11 14:25:02 2009 + @@ -1,8 +1,4 @@ + -Lines that starts with dashes: + - + ------------------------- + --- file.c + ------------------------- + +A line that starts with dashes: - and removed. + and removed. -@@ -23,4 +19,4 @@ + @@ -23,4 +19,4 @@ --Another chunk of change -+Another chunk of changes + -Another chunk of change + +Another chunk of changes -DIFF + DIFF ) assert_equal 1, diff.size end it 'should one line new files' do - diff = Redmine::UnifiedDiff.new(<<-DIFF -diff -r 000000000000 -r ea98b14f75f0 README1 ---- /dev/null -+++ b/README1 -@@ -0,0 +1,1 @@ -+test1 -diff -r 000000000000 -r ea98b14f75f0 README2 ---- /dev/null -+++ b/README2 -@@ -0,0 +1,1 @@ -+test2 -diff -r 000000000000 -r ea98b14f75f0 README3 ---- /dev/null -+++ b/README3 -@@ -0,0 +1,3 @@ -+test4 -+test5 -+test6 -diff -r 000000000000 -r ea98b14f75f0 README4 ---- /dev/null -+++ b/README4 -@@ -0,0 +1,3 @@ -+test4 -+test5 -+test6 -DIFF + diff = Redmine::UnifiedDiff.new(<<~DIFF + diff -r 000000000000 -r ea98b14f75f0 README1 + --- /dev/null + +++ b/README1 + @@ -0,0 +1,1 @@ + +test1 + diff -r 000000000000 -r ea98b14f75f0 README2 + --- /dev/null + +++ b/README2 + @@ -0,0 +1,1 @@ + +test2 + diff -r 000000000000 -r ea98b14f75f0 README3 + --- /dev/null + +++ b/README3 + @@ -0,0 +1,3 @@ + +test4 + +test5 + +test6 + diff -r 000000000000 -r ea98b14f75f0 README4 + --- /dev/null + +++ b/README4 + @@ -0,0 +1,3 @@ + +test4 + +test5 + +test6 + DIFF ) assert_equal 4, diff.size end diff --git a/spec_legacy/unit/lib/redmine_spec.rb b/spec_legacy/unit/lib/redmine_spec.rb index 200d408ed4..b26b9fcda3 100644 --- a/spec_legacy/unit/lib/redmine_spec.rb +++ b/spec_legacy/unit/lib/redmine_spec.rb @@ -36,7 +36,8 @@ module RedmineMenuTestHelper end def assert_menu_contains_item_named(menu_name, item_name) - assert Redmine::MenuManager.items(menu_name).map(&:name).include?(item_name.to_sym), "Menu did not have an item named #{item_name}" + assert Redmine::MenuManager.items(menu_name).map(&:name).include?(item_name.to_sym), + "Menu did not have an item named #{item_name}" end # Helpers diff --git a/spec_legacy/unit/mail_handler_spec.rb b/spec_legacy/unit/mail_handler_spec.rb index 6799f2a235..a98f3b20d6 100644 --- a/spec_legacy/unit/mail_handler_spec.rb +++ b/spec_legacy/unit/mail_handler_spec.rb @@ -373,7 +373,9 @@ describe MailHandler, type: :model do it 'should email with long subject line' do issue = submit_email('ticket_with_long_subject.eml') assert issue.is_a?(WorkPackage) - assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0, 255] + assert_equal issue.subject, + 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[ +0, 255] end it 'should new user from attributes should return valid user' do @@ -383,8 +385,12 @@ describe MailHandler, type: :model do ['jsmith@example.net', 'John'] => ['jsmith@example.net', 'John', '-'], ['jsmith@example.net', 'John Smith'] => ['jsmith@example.net', 'John', 'Smith'], ['jsmith@example.net', 'John Paul Smith'] => ['jsmith@example.net', 'John', 'Paul Smith'], - ['jsmith@example.net', 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength Smith'] => ['jsmith@example.net', 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength', 'Smith'], - ['jsmith@example.net', 'John AVeryLongLastnameThatNoLongerExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', 'AVeryLongLastnameThatNoLongerExceedsTheMaximumLength'] + ['jsmith@example.net', + 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength Smith'] => ['jsmith@example.net', + 'AVeryLongFirstnameThatNoLongerExceedsTheMaximumLength', 'Smith'], + ['jsmith@example.net', + 'John AVeryLongLastnameThatNoLongerExceedsTheMaximumLength'] => ['jsmith@example.net', 'John', + 'AVeryLongLastnameThatNoLongerExceedsTheMaximumLength'] } to_test.each do |attrs, expected| diff --git a/spec_legacy/unit/member_spec.rb b/spec_legacy/unit/member_spec.rb index 5d4c678682..2c6ddda738 100644 --- a/spec_legacy/unit/member_spec.rb +++ b/spec_legacy/unit/member_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -42,8 +43,8 @@ describe Member, type: :model do it 'should create' do member = Member.new.tap do |m| m.attributes = { project_id: @project.id, - user_id: FactoryBot.create(:user).id, - role_ids: [@role.id] } + user_id: FactoryBot.create(:user).id, + role_ids: [@role.id] } end assert member.save member.reload @@ -98,7 +99,7 @@ describe Member, type: :model do Watcher.create!(watchable: FactoryBot.create(:wiki, project: @private_project), user: @watcher_user) @private_project.reload # to access @private_project.wiki Watcher.create!(watchable: FactoryBot.create(:wiki_page, wiki: @private_project.wiki), user: @watcher_user) - @private_role = FactoryBot.create :role, permissions: [:view_wiki_pages, :view_work_packages] + @private_role = FactoryBot.create :role, permissions: %i[view_wiki_pages view_work_packages] @private_project.public = false @private_project.save @@ -108,8 +109,8 @@ describe Member, type: :model do before do (@member = Member.new.tap do |m| m.attributes = { project_id: @private_project.id, - user_id: @watcher_user.id, - role_ids: [@private_role.id, FactoryBot.create(:role).id] } + user_id: @watcher_user.id, + role_ids: [@private_role.id, FactoryBot.create(:role).id] } end).save! end @@ -138,8 +139,8 @@ describe Member, type: :model do @group = FactoryBot.create :group, members: @watcher_user @member = (Member.new.tap do |m| m.attributes = { project_id: @private_project.id, - user_id: @group.id, - role_ids: [@private_role.id, FactoryBot.create(:role).id] } + user_id: @group.id, + role_ids: [@private_role.id, FactoryBot.create(:role).id] } end) @group.members << @member diff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rb index 073d41424e..fc68361482 100644 --- a/spec_legacy/unit/project_spec.rb +++ b/spec_legacy/unit/project_spec.rb @@ -135,7 +135,7 @@ describe Project, type: :model do it 'should descendants' do d = Project.find(1).descendants.pluck(:id) - assert_equal [3,4,5,6], d.sort + assert_equal [3, 4, 5, 6], d.sort end it 'should users by role' do diff --git a/spec_legacy/unit/search_spec.rb b/spec_legacy/unit/search_spec.rb index 39a9d4c638..5773e7e2de 100644 --- a/spec_legacy/unit/search_spec.rb +++ b/spec_legacy/unit/search_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/time_entry_activity_spec.rb b/spec_legacy/unit/time_entry_activity_spec.rb index 2ab6fb3bc4..3e0f32d7e2 100644 --- a/spec_legacy/unit/time_entry_activity_spec.rb +++ b/spec_legacy/unit/time_entry_activity_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/user_preference_spec.rb b/spec_legacy/unit/user_preference_spec.rb index 07f9bb6845..f535d4d7a4 100644 --- a/spec_legacy/unit/user_preference_spec.rb +++ b/spec_legacy/unit/user_preference_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb index 33b4563fb9..f69af09b5a 100644 --- a/spec_legacy/unit/user_spec.rb +++ b/spec_legacy/unit/user_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -155,7 +156,8 @@ describe User, type: :model do end it 'should select the exact matching user first' do - case_sensitive_user = FactoryBot.create(:user, login: 'changed', password: 'adminADMIN!', password_confirmation: 'adminADMIN!') + case_sensitive_user = FactoryBot.create(:user, login: 'changed', password: 'adminADMIN!', + password_confirmation: 'adminADMIN!') # bypass validations to make it appear like existing data case_sensitive_user.update_attribute(:login, 'ADMIN') diff --git a/spec_legacy/unit/version_spec.rb b/spec_legacy/unit/version_spec.rb index aa82d3bf69..addcb1c44b 100644 --- a/spec_legacy/unit/version_spec.rb +++ b/spec_legacy/unit/version_spec.rb @@ -118,7 +118,7 @@ describe Version, type: :model do add_work_package(v, done_ratio: 20) add_work_package(v, status: Status.where(is_closed: true).first) assert_progress_equal (0.0 + 20.0 + 100.0) / 3, v.completed_percent - assert_progress_equal (100.0) / 3, v.closed_percent + assert_progress_equal 100.0 / 3, v.closed_percent end it 'should progress should consider estimated hours to weigth issues' do diff --git a/spec_legacy/unit/wiki_content_spec.rb b/spec_legacy/unit/wiki_content_spec.rb index 2270e54fa3..b8afd9ebe8 100644 --- a/spec_legacy/unit/wiki_content_spec.rb +++ b/spec_legacy/unit/wiki_content_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/wiki_page_spec.rb b/spec_legacy/unit/wiki_page_spec.rb index 1b59435fde..cb809d7db2 100644 --- a/spec_legacy/unit/wiki_page_spec.rb +++ b/spec_legacy/unit/wiki_page_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/wiki_redirect_spec.rb b/spec_legacy/unit/wiki_redirect_spec.rb index 548c2384b3..531508be4a 100644 --- a/spec_legacy/unit/wiki_redirect_spec.rb +++ b/spec_legacy/unit/wiki_redirect_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH diff --git a/spec_legacy/unit/wiki_spec.rb b/spec_legacy/unit/wiki_spec.rb index 8fbd27ab5c..594cabc58d 100644 --- a/spec_legacy/unit/wiki_spec.rb +++ b/spec_legacy/unit/wiki_spec.rb @@ -1,4 +1,5 @@ #-- encoding: UTF-8 + #-- copyright # OpenProject is an open source project management software. # Copyright (C) 2012-2021 the OpenProject GmbH @@ -26,7 +27,8 @@ # # See docs/COPYRIGHT.rdoc for more details. #++ -require 'legacy_spec_helper' + +require_relative '../legacy_spec_helper' describe Wiki, type: :model do fixtures :all