Use anonymous block forwarding introduced in Ruby 3.1 (#38585).

git-svn-id: https://svn.redmine.org/redmine/trunk@22973 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-08-21 00:46:15 +00:00
parent c069ea3a24
commit 93645a279e
33 changed files with 78 additions and 78 deletions

View File

@@ -638,8 +638,8 @@ module ApplicationHelper
# Yields the given block for each project with its level in the tree # Yields the given block for each project with its level in the tree
# #
# Wrapper for Project#project_tree # Wrapper for Project#project_tree
def project_tree(projects, options={}, &block) def project_tree(projects, options={}, &)
Project.project_tree(projects, options, &block) Project.project_tree(projects, options, &)
end end
def principals_check_box_tags(name, principals) def principals_check_box_tags(name, principals)
@@ -755,7 +755,7 @@ module ApplicationHelper
elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil elements.any? ? content_tag('p', (args.join(" \xc2\xbb ") + " \xc2\xbb ").html_safe, :class => 'breadcrumb') : nil
end end
def other_formats_links(&block) def other_formats_links(&)
concat('<p class="other-formats">'.html_safe + l(:label_export_to)) concat('<p class="other-formats">'.html_safe + l(:label_export_to))
yield Redmine::Views::OtherFormatsBuilder.new(self) yield Redmine::Views::OtherFormatsBuilder.new(self)
concat('</p>'.html_safe) concat('</p>'.html_safe)
@@ -820,8 +820,8 @@ module ApplicationHelper
end end
end end
def actions_dropdown(&block) def actions_dropdown(&)
content = capture(&block) content = capture(&)
if content.present? if content.present?
trigger = trigger =
content_tag('span', l(:button_actions), :class => 'icon-only icon-actions', content_tag('span', l(:button_actions), :class => 'icon-only icon-actions',
@@ -1508,21 +1508,21 @@ module ApplicationHelper
(blank ? [["(#{l('label_option_auto_lang')})", ""]] : []) + languages_options (blank ? [["(#{l('label_option_auto_lang')})", ""]] : []) + languages_options
end end
def labelled_form_for(*args, &proc) def labelled_form_for(*args, &)
args << {} unless args.last.is_a?(Hash) args << {} unless args.last.is_a?(Hash)
options = args.last options = args.last
if args.first.is_a?(Symbol) if args.first.is_a?(Symbol)
options[:as] = args.shift options[:as] = args.shift
end end
options[:builder] = Redmine::Views::LabelledFormBuilder options[:builder] = Redmine::Views::LabelledFormBuilder
form_for(*args, &proc) form_for(*args, &)
end end
def labelled_fields_for(*args, &proc) def labelled_fields_for(*args, &)
args << {} unless args.last.is_a?(Hash) args << {} unless args.last.is_a?(Hash)
options = args.last options = args.last
options[:builder] = Redmine::Views::LabelledFormBuilder options[:builder] = Redmine::Views::LabelledFormBuilder
fields_for(*args, &proc) fields_for(*args, &)
end end
def form_tag_html(html_options) def form_tag_html(html_options)
@@ -1866,17 +1866,17 @@ module ApplicationHelper
end end
end end
def render_if_exist(options = {}, locals = {}, &block) def render_if_exist(options = {}, locals = {}, &)
# Remove test_render_if_exist_should_be_render_partial and test_render_if_exist_should_be_render_nil # Remove test_render_if_exist_should_be_render_partial and test_render_if_exist_should_be_render_nil
# along with this method in Redmine 7.0 # along with this method in Redmine 7.0
Rails.application.deprecators[:redmine].warn 'ApplicationHelper#render_if_exist is deprecated and will be removed in Redmine 7.0.' Rails.application.deprecators[:redmine].warn 'ApplicationHelper#render_if_exist is deprecated and will be removed in Redmine 7.0.'
if options[:partial] if options[:partial]
if lookup_context.exists?(options[:partial], lookup_context.prefixes, true) if lookup_context.exists?(options[:partial], lookup_context.prefixes, true)
render(options, locals, &block) render(options, locals, &)
end end
else else
render(options, locals, &block) render(options, locals, &)
end end
end end

View File

@@ -178,7 +178,7 @@ module CustomFieldsHelper
# Yields the given block for each custom field value of object that should be # Yields the given block for each custom field value of object that should be
# displayed, with the custom field and the formatted value as arguments # displayed, with the custom field and the formatted value as arguments
def render_custom_field_values(object, &block) def render_custom_field_values(object, &)
object.visible_custom_field_values.each do |custom_value| object.visible_custom_field_values.each do |custom_value|
formatted = show_value(custom_value) formatted = show_value(custom_value)
if formatted.present? if formatted.present?

View File

@@ -22,7 +22,7 @@ module IssuesHelper
include Redmine::Export::PDF::IssuesPdfHelper include Redmine::Export::PDF::IssuesPdfHelper
include IssueStatusesHelper include IssueStatusesHelper
def issue_list(issues, &block) def issue_list(issues, &)
ancestors = [] ancestors = []
issues.each do |issue| issues.each do |issue|
while ancestors.any? && while ancestors.any? &&
@@ -34,7 +34,7 @@ module IssuesHelper
end end
end end
def grouped_issue_list(issues, query, &block) def grouped_issue_list(issues, query, &)
ancestors = [] ancestors = []
grouped_query_results(issues, query) do |issue, group_name, group_count, group_totals| grouped_query_results(issues, query) do |issue, group_name, group_count, group_totals|
while ancestors.any? && while ancestors.any? &&

View File

@@ -194,7 +194,7 @@ module ProjectsHelper
link_to text, url, remote: true, method: method, class: css link_to text, url, remote: true, method: method, class: css
end end
def grouped_project_list(projects, query, &block) def grouped_project_list(projects, query, &)
ancestors = [] ancestors = []
grouped_query_results(projects, query) do |project, group_name, group_count, group_totals| grouped_query_results(projects, query) do |project, group_name, group_count, group_totals|
ancestors.pop while ancestors.any? && !project.is_descendant_of?(ancestors.last) ancestors.pop while ancestors.any? && !project.is_descendant_of?(ancestors.last)

View File

@@ -151,7 +151,7 @@ module QueriesHelper
tags tags
end end
def grouped_query_results(items, query, &block) def grouped_query_results(items, query, &)
result_count_by_group = query.result_count_by_group result_count_by_group = query.result_count_by_group
previous_group, first = false, true previous_group, first = false, true
totals_by_group = query.totalable_columns.inject({}) do |h, column| totals_by_group = query.totalable_columns.inject({}) do |h, column|

View File

@@ -553,7 +553,7 @@ class Attachment < ApplicationRecord
# Singleton class method is public # Singleton class method is public
class << self class << self
# Claims a unique ASCII or hashed filename, yields the open file handle # Claims a unique ASCII or hashed filename, yields the open file handle
def create_diskfile(filename, directory=nil, &block) def create_diskfile(filename, directory=nil, &)
timestamp = DateTime.now.strftime("%y%m%d%H%M%S") timestamp = DateTime.now.strftime("%y%m%d%H%M%S")
ascii = '' ascii = ''
if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50 if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50
@@ -572,7 +572,7 @@ class Attachment < ApplicationRecord
File.join(path, name), File.join(path, name),
flags: File::CREAT | File::EXCL | File::WRONLY, flags: File::CREAT | File::EXCL | File::WRONLY,
binmode: true, binmode: true,
&block &
) )
rescue Errno::EEXIST rescue Errno::EEXIST
timestamp.succ! timestamp.succ!

View File

@@ -137,7 +137,7 @@ class AuthSourceLdap < AuthSource
private private
def with_timeout(&block) def with_timeout(&)
timeout = self.timeout timeout = self.timeout
timeout = 20 unless timeout && timeout > 0 timeout = 20 unless timeout && timeout > 0
Timeout.timeout(timeout) do Timeout.timeout(timeout) do

View File

@@ -639,7 +639,7 @@ class Mailer < ActionMailer::Base
end end
# Activates/desactivates email deliveries during +block+ # Activates/desactivates email deliveries during +block+
def self.with_deliveries(enabled = true, &block) def self.with_deliveries(enabled = true, &)
was_enabled = ActionMailer::Base.perform_deliveries was_enabled = ActionMailer::Base.perform_deliveries
ActionMailer::Base.perform_deliveries = !!enabled ActionMailer::Base.perform_deliveries = !!enabled
yield yield
@@ -652,7 +652,7 @@ class Mailer < ActionMailer::Base
# Using the asynchronous queue from a Rake task will generally not work because # Using the asynchronous queue from a Rake task will generally not work because
# Rake will likely end, causing the in-process thread pool to be deleted, before # Rake will likely end, causing the in-process thread pool to be deleted, before
# any/all of the .deliver_later emails are processed # any/all of the .deliver_later emails are processed
def self.with_synched_deliveries(&block) def self.with_synched_deliveries(&)
adapter = ActionMailer::MailDeliveryJob.queue_adapter adapter = ActionMailer::MailDeliveryJob.queue_adapter
ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new ActionMailer::MailDeliveryJob.queue_adapter = ActiveJob::QueueAdapters::InlineAdapter.new
yield yield

View File

@@ -1097,7 +1097,7 @@ class Query < ApplicationRecord
private private
def grouped_query(&block) def grouped_query(&)
r = nil r = nil
if grouped? if grouped?
r = yield base_group_scope r = yield base_group_scope
@@ -1136,13 +1136,13 @@ class Query < ApplicationRecord
group(group_by_statement) group(group_by_statement)
end end
def total_for_custom_field(custom_field, scope, &block) def total_for_custom_field(custom_field, scope, &)
total = custom_field.format.total_for_scope(custom_field, scope) total = custom_field.format.total_for_scope(custom_field, scope)
total = map_total(total) {|t| custom_field.format.cast_total_value(custom_field, t)} total = map_total(total) {|t| custom_field.format.cast_total_value(custom_field, t)}
total total
end end
def map_total(total, &block) def map_total(total, &)
if total.is_a?(Hash) if total.is_a?(Hash)
total.each_key {|k| total[k] = yield total[k]} total.each_key {|k| total[k] = yield total[k]}
else else

View File

@@ -770,8 +770,8 @@ class User < Principal
# NB: this method is not used anywhere in the core codebase as of # NB: this method is not used anywhere in the core codebase as of
# 2.5.2, but it's used by many plugins so if we ever want to remove # 2.5.2, but it's used by many plugins so if we ever want to remove
# it it has to be carefully deprecated for a version or two. # it it has to be carefully deprecated for a version or two.
def allowed_to_globally?(action, options={}, &block) def allowed_to_globally?(action, options={}, &)
allowed_to?(action, nil, options.reverse_merge(:global => true), &block) allowed_to?(action, nil, options.reverse_merge(:global => true), &)
end end
def allowed_to_view_all_time_entries?(context) def allowed_to_view_all_time_entries?(context)

View File

@@ -73,8 +73,8 @@ ActionMailer::Base.add_delivery_method :tmp_file, DeliveryMethods::TmpFile
module ActionController module ActionController
module MimeResponds module MimeResponds
class Collector class Collector
def api(&block) def api(&)
any(:xml, :json, &block) any(:xml, :json, &)
end end
end end
end end

View File

@@ -26,7 +26,7 @@ module Redmine
@@providers = Hash.new {|h, k| h[k]=[]} @@providers = Hash.new {|h, k| h[k]=[]}
class << self class << self
def map(&block) def map(&)
yield self yield self
end end

View File

@@ -60,7 +60,7 @@ module Redmine
end end
# Yields to filter the activity scope # Yields to filter the activity scope
def scope_select(&block) def scope_select(&)
@scope = @scope.select {|t| yield t} @scope = @scope.select {|t| yield t}
end end

View File

@@ -30,7 +30,7 @@ module Redmine
include Redmine::I18n include Redmine::I18n
class << self class << self
def generate(options = {}, &block) def generate(options = {}, &)
col_sep = (options[:field_separator].presence || l(:general_csv_separator)) col_sep = (options[:field_separator].presence || l(:general_csv_separator))
encoding = Encoding.find(options[:encoding]) rescue Encoding.find(l(:general_csv_encoding)) encoding = Encoding.find(options[:encoding]) rescue Encoding.find(l(:general_csv_encoding))
@@ -41,7 +41,7 @@ module Redmine
(+'').force_encoding(encoding) (+'').force_encoding(encoding)
end end
super(str, :col_sep => col_sep, :encoding => encoding, &block) super(str, :col_sep => col_sep, :encoding => encoding, &)
end end
end end

View File

@@ -187,7 +187,7 @@ module Redmine
end end
end end
def parse_keyword(custom_field, keyword, &block) def parse_keyword(custom_field, keyword, &)
separator = Regexp.escape "," separator = Regexp.escape ","
keyword = keyword.dup.to_s keyword = keyword.dup.to_s

View File

@@ -152,7 +152,7 @@ module Redmine
# Yields the given block with the text and parameters # Yields the given block with the text and parameters
# for each pagination link and returns a string that represents the links # for each pagination link and returns a string that represents the links
def pagination_links_each(paginator, count=nil, options={}, &block) def pagination_links_each(paginator, count=nil, options={}, &)
options.assert_valid_keys :per_page_links options.assert_valid_keys :per_page_links
per_page_links = options.delete(:per_page_links) per_page_links = options.delete(:per_page_links)
@@ -205,7 +205,7 @@ module Redmine
info = ''.html_safe info = ''.html_safe
info << content_tag('span', "(#{paginator.first_item}-#{paginator.last_item}/#{paginator.item_count})", :class => 'items') + ' ' info << content_tag('span', "(#{paginator.first_item}-#{paginator.last_item}/#{paginator.item_count})", :class => 'items') + ' '
if per_page_links != false && links = per_page_links(paginator, &block) if per_page_links != false && links = per_page_links(paginator, &)
info << content_tag('span', links.to_s, :class => 'per-page') info << content_tag('span', links.to_s, :class => 'per-page')
end end
html << content_tag('span', info) html << content_tag('span', info)
@@ -214,7 +214,7 @@ module Redmine
end end
# Renders the "Per page" links. # Renders the "Per page" links.
def per_page_links(paginator, &block) def per_page_links(paginator, &)
values = per_page_options(paginator.per_page, paginator.item_count) values = per_page_options(paginator.per_page, paginator.item_count)
if values.any? if values.any?
links = values.collect do |n| links = values.collect do |n|

View File

@@ -90,9 +90,9 @@ module Redmine
# version '0.0.1' # version '0.0.1'
# requires_redmine version_or_higher: '3.0.0' # requires_redmine version_or_higher: '3.0.0'
# end # end
def self.register(id, &block) def self.register(id, &)
p = new(id) p = new(id)
p.instance_eval(&block) p.instance_eval(&)
# Set a default name if it was not provided during registration # Set a default name if it was not provided during registration
p.name(id.to_s.humanize) if p.name.nil? p.name(id.to_s.humanize) if p.name.nil?
@@ -378,9 +378,9 @@ module Redmine
# permission :view_contacts, { :contacts => [:list, :show] }, :public => true # permission :view_contacts, { :contacts => [:list, :show] }, :public => true
# permission :destroy_contacts, { :contacts => :destroy } # permission :destroy_contacts, { :contacts => :destroy }
# end # end
def project_module(name, &block) def project_module(name, &)
@project_module = name @project_module = name
self.instance_eval(&block) self.instance_eval(&)
@project_module = nil @project_module = nil
end end

View File

@@ -206,8 +206,8 @@ module Redmine
self.class.logger self.class.logger
end end
def shellout(cmd, options = {}, &block) def shellout(cmd, options = {}, &)
self.class.shellout(cmd, options, &block) self.class.shellout(cmd, options, &)
end end
# Path to the file where scm stderr output is logged # Path to the file where scm stderr output is logged

View File

@@ -297,7 +297,7 @@ module Redmine
@aro @aro
end end
def scm_cmd(*args, &block) def scm_cmd(*args, &)
full_args = [] full_args = []
full_args += args full_args += args
full_args_locale = [] full_args_locale = []
@@ -308,7 +308,7 @@ module Redmine
shellout( shellout(
self.class.sq_bin + ' ' + self.class.sq_bin + ' ' +
full_args_locale.map {|e| shell_quote e.to_s}.join(' '), full_args_locale.map {|e| shell_quote e.to_s}.join(' '),
&block &
) )
if $? && $?.exitstatus != 0 if $? && $?.exitstatus != 0
raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}" raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}"
@@ -318,7 +318,7 @@ module Redmine
end end
private :scm_cmd private :scm_cmd
def scm_cmd_no_raise(*args, &block) def scm_cmd_no_raise(*args, &)
full_args = [] full_args = []
full_args += args full_args += args
full_args_locale = [] full_args_locale = []
@@ -329,7 +329,7 @@ module Redmine
shellout( shellout(
self.class.sq_bin + ' ' + self.class.sq_bin + ' ' +
full_args_locale.map {|e| shell_quote e.to_s}.join(' '), full_args_locale.map {|e| shell_quote e.to_s}.join(' '),
&block &
) )
ret ret
end end

View File

@@ -152,7 +152,7 @@ module Redmine
# Returns all revisions found between identifier_from and identifier_to # Returns all revisions found between identifier_from and identifier_to
# in the repository. both identifier have to be dates or nil. # in the repository. both identifier have to be dates or nil.
# these method returns nothing but yield every result in block # these method returns nothing but yield every result in block
def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &block) def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}, &)
path_with_project_utf8 = path_with_proj(path) path_with_project_utf8 = path_with_proj(path)
path_with_project_locale = scm_iconv(@path_encoding, 'UTF-8', path_with_project_utf8) path_with_project_locale = scm_iconv(@path_encoding, 'UTF-8', path_with_project_utf8)
logger.debug "<cvs> revisions path:" + logger.debug "<cvs> revisions path:" +
@@ -381,7 +381,7 @@ module Redmine
end end
end end
def scm_cmd(*args, &block) def scm_cmd(*args, &)
full_args = ['-d', root_url] full_args = ['-d', root_url]
full_args += args full_args += args
full_args_locale = [] full_args_locale = []
@@ -392,7 +392,7 @@ module Redmine
shellout( shellout(
self.class.sq_bin + ' ' + self.class.sq_bin + ' ' +
full_args_locale.map {|e| shell_quote e.to_s}.join(' '), full_args_locale.map {|e| shell_quote e.to_s}.join(' '),
&block &
) )
if $? && $?.exitstatus != 0 if $? && $?.exitstatus != 0
raise ScmCommandAborted, "cvs exited with non-zero status: #{$?.exitstatus}" raise ScmCommandAborted, "cvs exited with non-zero status: #{$?.exitstatus}"

View File

@@ -440,7 +440,7 @@ module Redmine
private private
def git_cmd(args, options = {}, &block) def git_cmd(args, options = {}, &)
repo_path = root_url || url repo_path = root_url || url
full_args = ['--git-dir', repo_path] full_args = ['--git-dir', repo_path]
if self.class.client_version_above?([1, 7, 2]) if self.class.client_version_above?([1, 7, 2])
@@ -452,7 +452,7 @@ module Redmine
shellout( shellout(
self.class.sq_bin + ' ' + full_args.map {|e| shell_quote e.to_s}.join(' '), self.class.sq_bin + ' ' + full_args.map {|e| shell_quote e.to_s}.join(' '),
options, options,
&block &
) )
if $? && $?.exitstatus != 0 if $? && $?.exitstatus != 0
raise ScmCommandAborted, "git exited with non-zero status: #{$?.exitstatus}" raise ScmCommandAborted, "git exited with non-zero status: #{$?.exitstatus}"

View File

@@ -313,7 +313,7 @@ module Redmine
private_constant :HG_EARLY_BOOL_ARG, :HG_EARLY_LIST_ARG private_constant :HG_EARLY_BOOL_ARG, :HG_EARLY_LIST_ARG
# Runs 'hg' command with the given args # Runs 'hg' command with the given args
def hg(*args, &block) def hg(*args, &)
# as of hg 4.4.1, early parsing of bool options is not terminated at '--' # as of hg 4.4.1, early parsing of bool options is not terminated at '--'
if args.any? {|s| HG_EARLY_BOOL_ARG.match?(s)} if args.any? {|s| HG_EARLY_BOOL_ARG.match?(s)}
raise HgCommandArgumentError, "malicious command argument detected" raise HgCommandArgumentError, "malicious command argument detected"
@@ -331,7 +331,7 @@ module Redmine
ret = ret =
shellout( shellout(
self.class.sq_bin + ' ' + full_args.map {|e| shell_quote e.to_s}.join(' '), self.class.sq_bin + ' ' + full_args.map {|e| shell_quote e.to_s}.join(' '),
&block &
) )
if $? && $?.exitstatus != 0 if $? && $?.exitstatus != 0
raise HgCommandAborted, "hg exited with non-zero status: #{$?.exitstatus}" raise HgCommandAborted, "hg exited with non-zero status: #{$?.exitstatus}"

View File

@@ -23,7 +23,7 @@ module Redmine
@@available_search_types = [] @@available_search_types = []
class << self class << self
def map(&block) def map(&)
yield self yield self
end end

View File

@@ -72,7 +72,7 @@ module Redmine
@formatter = formatter @formatter = formatter
end end
def stream(tokens, &b) def stream(tokens, &)
token_lines(tokens) do |line| token_lines(tokens) do |line|
line.each do |tok, val| line.each do |tok, val|
yield @formatter.span(tok, val) yield @formatter.span(tok, val)

View File

@@ -27,7 +27,7 @@ module Redmine
@response = response @response = response
end end
def array(tag, options={}, &block) def array(tag, options={}, &)
@struct << [] @struct << []
yield(self) yield(self)
ret = @struct.pop ret = @struct.pop

View File

@@ -33,16 +33,16 @@ module Redmine
end end
# Overrides Builder::XmlBase#tag! to format timestamps in ISO 8601 # Overrides Builder::XmlBase#tag! to format timestamps in ISO 8601
def tag!(sym, *args, &block) def tag!(sym, *args, &)
if args.size == 1 && args.first.is_a?(::Time) if args.size == 1 && args.first.is_a?(::Time)
tag! sym, args.first.xmlschema, &block tag!(sym, args.first.xmlschema, &)
else else
super super
end end
end end
def array(name, options={}, &block) def array(name, options={}, &)
__send__ name, (options || {}).merge(:type => 'array'), &block __send__(name, (options || {}).merge(:type => 'array'), &)
end end
end end
end end

View File

@@ -822,7 +822,7 @@ class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
private private
def with_cache(&block) def with_cache(&)
before = ActionController::Base.perform_caching before = ActionController::Base.perform_caching
ActionController::Base.perform_caching = true ActionController::Base.perform_caching = true
yield yield

View File

@@ -72,8 +72,8 @@ module ObjectHelpers
tracker tracker
end end
def Tracker.generate!(attributes={}, &block) def Tracker.generate!(attributes={}, &)
tracker = Tracker.generate(attributes, &block) tracker = Tracker.generate(attributes, &)
tracker.save! tracker.save!
tracker tracker
end end
@@ -102,8 +102,8 @@ module ObjectHelpers
# Generates a saved Issue # Generates a saved Issue
# Doesn't send notifications by default, use :notify => true to send them # Doesn't send notifications by default, use :notify => true to send them
def Issue.generate!(attributes={}, &block) def Issue.generate!(attributes={}, &)
issue = Issue.generate(attributes, &block) issue = Issue.generate(attributes, &)
issue.save! issue.save!
issue.reload issue.reload
end end
@@ -155,8 +155,8 @@ module ObjectHelpers
entry entry
end end
def TimeEntry.generate!(attributes={}, &block) def TimeEntry.generate!(attributes={}, &)
entry = TimeEntry.generate(attributes, &block) entry = TimeEntry.generate(attributes, &)
entry.save! entry.save!
entry entry
end end

View File

@@ -87,7 +87,7 @@ class ActiveSupport::TestCase
Attachment.storage_path = "#{Rails.root}/test/fixtures/files" Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
end end
def with_settings(options, &block) def with_settings(options, &)
saved_settings = options.keys.inject({}) do |h, k| saved_settings = options.keys.inject({}) do |h, k|
h[k] = h[k] =
case Setting[k] case Setting[k]
@@ -105,7 +105,7 @@ class ActiveSupport::TestCase
end end
# Yields the block with user as the current user # Yields the block with user as the current user
def with_current_user(user, &block) def with_current_user(user, &)
saved_user = User.current saved_user = User.current
User.current = user User.current = user
yield yield
@@ -113,7 +113,7 @@ class ActiveSupport::TestCase
User.current = saved_user User.current = saved_user
end end
def with_locale(locale, &block) def with_locale(locale, &)
saved_localed = ::I18n.locale saved_localed = ::I18n.locale
::I18n.locale = locale ::I18n.locale = locale
yield yield
@@ -219,13 +219,13 @@ class ActiveSupport::TestCase
# Asserts that a new record for the given class is created # Asserts that a new record for the given class is created
# and returns it # and returns it
def new_record(klass, &block) def new_record(klass, &)
new_records(klass, 1, &block).first new_records(klass, 1, &).first
end end
# Asserts that count new records for the given class are created # Asserts that count new records for the given class are created
# and returns them as an array order by object id # and returns them as an array order by object id
def new_records(klass, count, &block) def new_records(klass, count, &)
assert_difference "#{klass}.count", count do assert_difference "#{klass}.count", count do
yield yield
end end

View File

@@ -124,7 +124,7 @@ class IssueNestedSetConcurrencyTest < ActiveSupport::TestCase
private private
def threaded(count, &block) def threaded(count, &)
with_settings :notified_events => [] do with_settings :notified_events => [] do
threads = [] threads = []
count.times do |i| count.times do |i|

View File

@@ -124,7 +124,7 @@ class Redmine::Views::Builders::JsonTest < ActiveSupport::TestCase
end end
end end
def assert_json_output(expected, &block) def assert_json_output(expected, &)
builder = Redmine::Views::Builders::Json.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create) builder = Redmine::Views::Builders::Json.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create)
yield(builder) yield(builder)
assert_equal(expected, ActiveSupport::JSON.decode(builder.output)) assert_equal(expected, ActiveSupport::JSON.decode(builder.output))

View File

@@ -60,7 +60,7 @@ class Redmine::Views::Builders::XmlTest < ActiveSupport::TestCase
end end
end end
def assert_xml_output(expected, &block) def assert_xml_output(expected, &)
builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create) builder = Redmine::Views::Builders::Xml.new(ActionDispatch::TestRequest.create, ActionDispatch::TestResponse.create)
yield(builder) yield(builder)
assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output) assert_equal('<?xml version="1.0" encoding="UTF-8"?>' + expected, builder.output)

View File

@@ -131,7 +131,7 @@ class MailerLocalisationTest < ActiveSupport::TestCase
private private
def with_each_user_language(&block) def with_each_user_language(&)
user = User.find(2) user = User.find(2)
valid_languages.each do |lang| valid_languages.each do |lang|
user.update_attribute :language, lang user.update_attribute :language, lang