1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-03-26 02:31:09 +00:00

Fixes for Performance/StringIdentifierArgument introduced in RuboCop Performance 1.13.0 (#35142).

git-svn-id: http://svn.redmine.org/redmine/trunk@21330 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2021-12-29 06:12:27 +00:00
parent 52aef905ff
commit b6a26a60f3
17 changed files with 43 additions and 43 deletions

View File

@ -41,7 +41,7 @@ class GanttsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html {render :action => "show", :layout => !request.xhr?} format.html {render :action => "show", :layout => !request.xhr?}
if @gantt.respond_to?('to_image') if @gantt.respond_to?(:to_image)
format.png do format.png do
send_data(@gantt.to_image, send_data(@gantt.to_image,
:disposition => 'inline', :type => 'image/png', :disposition => 'inline', :type => 'image/png',

View File

@ -1179,7 +1179,7 @@ class Issue < ActiveRecord::Base
).all ).all
issues.each do |issue| issues.each do |issue|
issue.instance_variable_set( issue.instance_variable_set(
"@relations", :@relations,
relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id} relations.select {|r| r.issue_from_id == issue.id || r.issue_to_id == issue.id}
) )
end end
@ -1191,7 +1191,7 @@ class Issue < ActiveRecord::Base
if issues.any? if issues.any?
hours_by_issue_id = TimeEntry.visible(user).where(:issue_id => issues.map(&:id)).group(:issue_id).sum(:hours) hours_by_issue_id = TimeEntry.visible(user).where(:issue_id => issues.map(&:id)).group(:issue_id).sum(:hours)
issues.each do |issue| issues.each do |issue|
issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0.0) issue.instance_variable_set :@spent_hours, (hours_by_issue_id[issue.id] || 0.0)
end end
end end
end end
@ -1204,7 +1204,7 @@ class Issue < ActiveRecord::Base
" AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt"). " AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt").
where("parent.id IN (?)", issues.map(&:id)).group("parent.id").sum(:hours) where("parent.id IN (?)", issues.map(&:id)).group("parent.id").sum(:hours)
issues.each do |issue| issues.each do |issue|
issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0.0) issue.instance_variable_set :@total_spent_hours, (hours_by_issue_id[issue.id] || 0.0)
end end
end end
end end
@ -1225,7 +1225,7 @@ class Issue < ActiveRecord::Base
relations_from.select {|relation| relation.issue_from_id == issue.id} + relations_from.select {|relation| relation.issue_from_id == issue.id} +
relations_to.select {|relation| relation.issue_to_id == issue.id} relations_to.select {|relation| relation.issue_to_id == issue.id}
issue.instance_variable_set "@relations", IssueRelation::Relations.new(issue, relations.sort) issue.instance_variable_set :@relations, IssueRelation::Relations.new(issue, relations.sort)
end end
end end
end end
@ -1254,7 +1254,7 @@ class Issue < ActiveRecord::Base
issues.each do |issue| issues.each do |issue|
journal = journals.detect {|j| j.journalized_id == issue.id} journal = journals.detect {|j| j.journalized_id == issue.id}
issue.instance_variable_set("@last_updated_by", journal.try(:user) || '') issue.instance_variable_set(:@last_updated_by, journal.try(:user) || '')
end end
end end
end end
@ -1274,7 +1274,7 @@ class Issue < ActiveRecord::Base
issues.each do |issue| issues.each do |issue|
journal = journals.detect {|j| j.journalized_id == issue.id} journal = journals.detect {|j| j.journalized_id == issue.id}
issue.instance_variable_set("@last_notes", journal.try(:notes) || '') issue.instance_variable_set(:@last_notes, journal.try(:notes) || '')
end end
end end
end end

View File

@ -190,7 +190,7 @@ class Journal < ActiveRecord::Base
journals.each do |journal| journals.each do |journal|
journal.details.each do |detail| journal.details.each do |detail|
if detail.property == 'cf' if detail.property == 'cf'
detail.instance_variable_set "@custom_field", fields_by_id[detail.prop_key.to_i] detail.instance_variable_set :@custom_field, fields_by_id[detail.prop_key.to_i]
end end
end end
end end

View File

@ -1095,7 +1095,7 @@ class Query < ActiveRecord::Base
end end
if column.is_a?(QueryCustomFieldColumn) if column.is_a?(QueryCustomFieldColumn)
custom_field = column.custom_field custom_field = column.custom_field
send "total_for_custom_field", custom_field, scope send :total_for_custom_field, custom_field, scope
else else
send "total_for_#{column.name}", scope send "total_for_#{column.name}", scope
end end

View File

@ -997,7 +997,7 @@ module Redmine
elsif value.is_a?(String) elsif value.is_a?(String)
value = set_custom_field_value_by_id(custom_field, custom_field_value, value) value = set_custom_field_value_by_id(custom_field, custom_field_value, value)
end end
custom_field_value.instance_variable_set "@attachment_present", attachment_present custom_field_value.instance_variable_set :@attachment_present, attachment_present
value value
end end
@ -1021,7 +1021,7 @@ module Redmine
errors = [] errors = []
if custom_value.value.blank? if custom_value.value.blank?
if custom_value.instance_variable_get("@attachment_present") if custom_value.instance_variable_get(:@attachment_present)
errors << ::I18n.t('activerecord.errors.messages.invalid') errors << ::I18n.t('activerecord.errors.messages.invalid')
end end
else else

View File

@ -86,7 +86,7 @@ module Redmine
end end
def supports_annotate? def supports_annotate?
respond_to?('annotate') respond_to?(:annotate)
end end
def root_url def root_url

View File

@ -26,7 +26,7 @@ module Redmine
class << self class << self
# Returns the relative root url of the application # Returns the relative root url of the application
def relative_url_root def relative_url_root
if ActionController::Base.respond_to?('relative_url_root') if ActionController::Base.respond_to?(:relative_url_root)
ActionController::Base.relative_url_root.to_s ActionController::Base.relative_url_root.to_s
else else
ActionController::Base.config.relative_url_root.to_s ActionController::Base.config.relative_url_root.to_s
@ -35,7 +35,7 @@ module Redmine
# Sets the relative root url of the application # Sets the relative root url of the application
def relative_url_root=(arg) def relative_url_root=(arg)
if ActionController::Base.respond_to?('relative_url_root=') if ActionController::Base.respond_to?(:relative_url_root=)
ActionController::Base.relative_url_root=arg ActionController::Base.relative_url_root=arg
else else
ActionController::Base.config.relative_url_root = arg ActionController::Base.config.relative_url_root = arg

View File

@ -2375,11 +2375,11 @@ class IssuesControllerTest < Redmine::ControllerTest
assert_select 'div#issue_tree span.issues-stat' do assert_select 'div#issue_tree span.issues-stat' do
assert_select 'span.badge', text: '4' assert_select 'span.badge', text: '4'
assert_select 'span.open a', text: '3 open' assert_select 'span.open a', text: '3 open'
assert_equal CGI.unescape(css_select('span.open a').first.attr('href')), assert_equal CGI.unescape(css_select('span.open a').first.attr(:href)),
"/issues?parent_id=~1&set_filter=true&status_id=o" "/issues?parent_id=~1&set_filter=true&status_id=o"
assert_select 'span.closed a', text: '1 closed' assert_select 'span.closed a', text: '1 closed'
assert_equal CGI.unescape(css_select('span.closed a').first.attr('href')), assert_equal CGI.unescape(css_select('span.closed a').first.attr(:href)),
"/issues?parent_id=~1&set_filter=true&status_id=c" "/issues?parent_id=~1&set_filter=true&status_id=c"
end end
end end
@ -2392,7 +2392,7 @@ class IssuesControllerTest < Redmine::ControllerTest
assert_select 'div#issue_tree span.issues-stat' do assert_select 'div#issue_tree span.issues-stat' do
assert_select 'span.open a', text: '1 open' assert_select 'span.open a', text: '1 open'
assert_equal CGI.unescape(css_select('span.open a').first.attr('href')), assert_equal CGI.unescape(css_select('span.open a').first.attr(:href)),
"/issues?parent_id=~1&set_filter=true&status_id=o" "/issues?parent_id=~1&set_filter=true&status_id=o"
assert_select 'span.closed', text: '0 closed' assert_select 'span.closed', text: '0 closed'
assert_select 'span.closed a', 0 assert_select 'span.closed a', 0

View File

@ -265,7 +265,7 @@ class MyControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_select '#block-issuesupdatedbyme' do assert_select '#block-issuesupdatedbyme' do
report_url = CGI.unescape(css_select('h3 a').first.attr('href')) report_url = CGI.unescape(css_select('h3 a').first.attr(:href))
assert_match 'f[]=project.status', report_url assert_match 'f[]=project.status', report_url
assert_match 'v[project.status][]=1', report_url assert_match 'v[project.status][]=1', report_url
assert_match 'f[]=updated_by', report_url assert_match 'f[]=updated_by', report_url
@ -306,7 +306,7 @@ class MyControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_select '#block-issuesassignedtome table.issues tbody' do assert_select '#block-issuesassignedtome table.issues tbody' do
report_url = css_select('h3 a').map {|e| e.attr('href')}.first report_url = css_select('h3 a').map {|e| e.attr(:href)}.first
assert_match 'f%5B%5D=project.status', report_url assert_match 'f%5B%5D=project.status', report_url
assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url
@ -334,7 +334,7 @@ class MyControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_select '#block-issuesreportedbyme' do assert_select '#block-issuesreportedbyme' do
report_url = css_select('h3 a').map {|e| e.attr('href')}.first report_url = css_select('h3 a').map {|e| e.attr(:href)}.first
assert_match 'f%5B%5D=project.status', report_url assert_match 'f%5B%5D=project.status', report_url
assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url
@ -366,7 +366,7 @@ class MyControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_select '#block-issueswatched table.issues tbody' do assert_select '#block-issueswatched table.issues tbody' do
report_url = css_select('h3 a').map {|e| e.attr('href')}.first report_url = css_select('h3 a').map {|e| e.attr(:href)}.first
assert_match 'f%5B%5D=project.status', report_url assert_match 'f%5B%5D=project.status', report_url
assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url assert_match 'v%5Bproject.status%5D%5B%5D=1', report_url

View File

@ -139,8 +139,8 @@ class ProjectsControllerTest < Redmine::ControllerTest
} }
assert_response :success assert_response :success
child_level1 = css_select('tr#project-5').map {|e| e.attr('class')}.first.split(' ') child_level1 = css_select('tr#project-5').map {|e| e.attr(:class)}.first.split(' ')
child_level2 = css_select('tr#project-6').map {|e| e.attr('class')}.first.split(' ') child_level2 = css_select('tr#project-6').map {|e| e.attr(:class)}.first.split(' ')
assert_include 'idnt', child_level1 assert_include 'idnt', child_level1
assert_include 'idnt-1', child_level1 assert_include 'idnt-1', child_level1

View File

@ -71,7 +71,7 @@ class RolesControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_equal( assert_equal(
%w(view_documents view_issues), %w(view_documents view_issues),
css_select('input[name="role[permissions][]"][checked=checked]').map {|e| e.attr('value')}.sort css_select('input[name="role[permissions][]"][checked=checked]').map {|e| e.attr(:value)}.sort
) )
end end

View File

@ -1165,7 +1165,7 @@ class TimelogControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_equal( assert_equal(
[t2, t1, t3].map(&:id).map(&:to_s), [t2, t1, t3].map(&:id).map(&:to_s),
css_select('input[name="ids[]"]').map {|e| e.attr('value')} css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
) )
get( get(
:index, :index,
@ -1180,7 +1180,7 @@ class TimelogControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_equal( assert_equal(
[t3, t1, t2].map(&:id).map(&:to_s), [t3, t1, t2].map(&:id).map(&:to_s),
css_select('input[name="ids[]"]').map {|e| e.attr('value')} css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
) )
end end
@ -1206,7 +1206,7 @@ class TimelogControllerTest < Redmine::ControllerTest
get :index, :params => params.dup.merge(sort_criteria) get :index, :params => params.dup.merge(sort_criteria)
assert_response :success assert_response :success
expected_ids = expected.map(&:id).map(&:to_s) expected_ids = expected.map(&:id).map(&:to_s)
actual_ids = css_select('input[name="ids[]"]').map {|e| e.attr('value')} actual_ids = css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
assert_equal expected_ids, actual_ids assert_equal expected_ids, actual_ids
end end
end end
@ -1242,7 +1242,7 @@ class TimelogControllerTest < Redmine::ControllerTest
} }
) )
assert_response :success assert_response :success
assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
end end
def test_index_with_project_status_filter def test_index_with_project_status_filter
@ -1261,7 +1261,7 @@ class TimelogControllerTest < Redmine::ControllerTest
) )
assert_response :success assert_response :success
time_entries = css_select('input[name="ids[]"]').map {|e| e.attr('value')} time_entries = css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
assert_include '1', time_entries assert_include '1', time_entries
assert_not_include '4', time_entries assert_not_include '4', time_entries
end end
@ -1308,7 +1308,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'issue.tracker_id' => ['2']} :v => {'issue.tracker_id' => ['2']}
} }
assert_response :success assert_response :success
assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')} assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
end end
def test_index_with_issue_tracker_column def test_index_with_issue_tracker_column
@ -1348,7 +1348,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'issue.category_id' => ['1']} :v => {'issue.category_id' => ['1']}
} }
assert_response :success assert_response :success
assert_equal ['1', '2'], css_select('input[name="ids[]"]').map {|e| e.attr('value')} assert_equal ['1', '2'], css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
end end
def test_index_with_issue_category_column def test_index_with_issue_category_column
@ -1383,7 +1383,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'author_id' => ['2']} :v => {'author_id' => ['2']}
} }
assert_response :success assert_response :success
assert_equal ['1'], css_select('input[name="ids[]"]').map {|e| e.attr('value')} assert_equal ['1'], css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
end end
def test_index_with_author_column def test_index_with_author_column
@ -1447,7 +1447,7 @@ class TimelogControllerTest < Redmine::ControllerTest
assert_response :success assert_response :success
assert_equal( assert_equal(
[entry].map(&:id).map(&:to_s), [entry].map(&:id).map(&:to_s),
css_select('input[name="ids[]"]').map {|e| e.attr('value')} css_select('input[name="ids[]"]').map {|e| e.attr(:value)}
) )
end end

View File

@ -86,10 +86,10 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest
# link to the attachment # link to the attachment
link = css_select(".cf_#{@field.id} .value a:not(.icon-download)") link = css_select(".cf_#{@field.id} .value a:not(.icon-download)")
assert_equal 1, link.size assert_equal 1, link.size
assert_equal "testfile.txt", link.text assert_equal "testfile.txt", link.first.text
# preview the attachment # preview the attachment
get link.attr('href') get link.first.attr(:href)
assert_response :success assert_response :success
assert_select 'h2', :text => "#{issue.tracker} ##{issue.id} » testfile.txt" assert_select 'h2', :text => "#{issue.tracker} ##{issue.id} » testfile.txt"
end end

View File

@ -165,7 +165,7 @@ class JournalTest < ActiveSupport::TestCase
d = JournalDetail.new(:property => 'cf', :prop_key => '2') d = JournalDetail.new(:property => 'cf', :prop_key => '2')
journals = [Journal.new(:details => [d])] journals = [Journal.new(:details => [d])]
d.expects(:instance_variable_set).with("@custom_field", CustomField.find(2)).once d.expects(:instance_variable_set).with(:@custom_field, CustomField.find(2)).once
Journal.preload_journals_details_custom_fields(journals) Journal.preload_journals_details_custom_fields(journals)
end end

View File

@ -58,8 +58,8 @@ class Redmine::Helpers::GanttHelperTest < Redmine::HelperTest
@gantt.project = @project @gantt.project = @project
@gantt.query = IssueQuery.new(:project => @project, :name => 'Gantt') @gantt.query = IssueQuery.new(:project => @project, :name => 'Gantt')
@gantt.view = self @gantt.view = self
@gantt.instance_variable_set('@date_from', options[:date_from] || (today - 14)) @gantt.instance_variable_set(:@date_from, options[:date_from] || (today - 14))
@gantt.instance_variable_set('@date_to', options[:date_to] || (today + 14)) @gantt.instance_variable_set(:@date_to, options[:date_to] || (today + 14))
end end
private :create_gantt private :create_gantt

View File

@ -73,14 +73,14 @@ class Redmine::SafeAttributesTest < ActiveSupport::TestCase
def test_set_safe_attributes def test_set_safe_attributes
p = Person.new p = Person.new
p.send('safe_attributes=', {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.anonymous) p.send(:safe_attributes=, {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.anonymous)
assert_equal 'John', p.firstname assert_equal 'John', p.firstname
assert_equal 'Smith', p.lastname assert_equal 'Smith', p.lastname
assert_nil p.login assert_nil p.login
p = Person.new p = Person.new
User.current = User.find(1) User.current = User.find(1)
p.send('safe_attributes=', {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.find(1)) p.send(:safe_attributes=, {'firstname' => 'John', 'lastname' => 'Smith', 'login' => 'jsmith'}, User.find(1))
assert_equal 'John', p.firstname assert_equal 'John', p.firstname
assert_equal 'Smith', p.lastname assert_equal 'Smith', p.lastname
assert_equal 'jsmith', p.login assert_equal 'jsmith', p.login

View File

@ -1686,7 +1686,7 @@ class QueryTest < ActiveSupport::TestCase
q = IssueQuery.new(:name => '_', :column_names => [:subject, :spent_hours]) q = IssueQuery.new(:name => '_', :column_names => [:subject, :spent_hours])
assert q.has_column?(:spent_hours) assert q.has_column?(:spent_hours)
issues = q.issues issues = q.issues
assert_not_nil issues.first.instance_variable_get("@spent_hours") assert_not_nil issues.first.instance_variable_get(:@spent_hours)
end end
def test_query_should_preload_last_updated_by def test_query_should_preload_last_updated_by
@ -1696,7 +1696,7 @@ class QueryTest < ActiveSupport::TestCase
assert q.has_column?(:last_updated_by) assert q.has_column?(:last_updated_by)
issues = q.issues.sort_by(&:id) issues = q.issues.sort_by(&:id)
assert issues.all? {|issue| !issue.instance_variable_get("@last_updated_by").nil?} assert issues.all? {|issue| !issue.instance_variable_get(:@last_updated_by).nil?}
assert_equal ["User", "User", "NilClass"], issues.map {|i| i.last_updated_by.class.name} assert_equal ["User", "User", "NilClass"], issues.map {|i| i.last_updated_by.class.name}
assert_equal ["John Smith", "John Smith", ""], issues.map {|i| i.last_updated_by.to_s} assert_equal ["John Smith", "John Smith", ""], issues.map {|i| i.last_updated_by.to_s}
end end
@ -1706,7 +1706,7 @@ class QueryTest < ActiveSupport::TestCase
q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_notes]) q = IssueQuery.new(:name => '_', :column_names => [:subject, :last_notes])
assert q.has_column?(:last_notes) assert q.has_column?(:last_notes)
issues = q.issues issues = q.issues
assert_not_nil issues.first.instance_variable_get("@last_notes") assert_not_nil issues.first.instance_variable_get(:@last_notes)
end end
def test_groupable_columns_should_include_custom_fields def test_groupable_columns_should_include_custom_fields