Style/HashSyntax:
EnforcedStyle: no_mixed_keys
+Style/HashEachMethods:
+ Exclude:
+ - 'db/migrate/072_add_enumerations_position.rb'
+ - 'db/migrate/078_add_custom_fields_position.rb'
+
Style/IdenticalConditionalBranches:
Exclude:
- 'config/initializers/10-patches.rb'
- 'app/controllers/enumerations_controller.rb'
- 'app/models/board.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-# Configuration parameters: AllowedReceivers.
-# AllowedReceivers: Thread.current
-Style/HashEachMethods:
- Exclude:
- - 'app/controllers/groups_controller.rb'
- - 'app/models/mailer.rb'
- - 'app/models/role.rb'
- - 'test/functional/issues_custom_fields_visibility_test.rb'
- - 'test/unit/auth_source_ldap_test.rb'
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowIfModifier.
Style/IfInsideElse:
end
def user_count_by_group_id
- h = User.joins(:groups).group('group_id').count
- h.keys.each do |key|
- h[key.to_i] = h.delete(key)
- end
- h
+ User.joins(:groups).group(:group_id).count.transform_keys(&:to_i)
end
end
def update
if @roles && @trackers && params[:transitions]
transitions = params[:transitions].deep_dup
- transitions.each do |old_status_id, transitions_by_new_status|
- transitions_by_new_status.each do |new_status_id, transition_by_rule|
+ transitions.each_value do |transitions_by_new_status|
+ transitions_by_new_status.each_value do |transition_by_rule|
transition_by_rule.reject! {|rule, transition| transition == 'no_change'}
end
end
def update_permissions
if @roles && @trackers && params[:permissions]
permissions = params[:permissions].deep_dup
- permissions.each do |field, rule_by_status_id|
+ permissions.each_value do |rule_by_status_id|
rule_by_status_id.reject! {|status_id, rule| rule == 'no_change'}
end
WorkflowPermission.replace_permissions(@trackers, @roles, permissions)
def render_api_attachment(attachment, api, options={})
api.attachment do
render_api_attachment_attributes(attachment, api)
- options.each {|key, value| eval("api.#{key} value")}
+ options.each_key {|key| eval("api.#{key} value")}
end
end
# custom fields changes
if @custom_values_before_change
values_by_custom_field_id = {}
- @custom_values_before_change.each do |custom_field_id, value|
+ @custom_values_before_change.each_key do |custom_field_id|
values_by_custom_field_id[custom_field_id] = nil
end
journalized.custom_field_values.each do |c|
scope = scope.where(:tracker_id => tracker.id) if tracker
issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).
group_by(&:assigned_to)
- issues_by_assignee.keys.each do |assignee|
+ issues_by_assignee.keys.each do |assignee| # rubocop:disable Style/HashEachMethods
if assignee.is_a?(Group)
assignee.users.each do |user|
issues_by_assignee[user] ||= []
# Store status and reopen locked/closed versions
version_statuses = versions.reject(&:open?).map {|version| [version, version.status]}
- version_statuses.each do |version, status|
+ version_statuses.each do |version, _| # rubocop:disable Style/HashEachMethods
version.update_attribute :status, 'open'
end
def permissions_tracker_ids=(arg)
h = arg.to_hash
- h.values.each {|v| v.reject!(&:blank?)}
+ h.each_value {|v| v.reject!(&:blank?)}
super(h)
end
# Unknown actions have default validity_time
condition = t[:action].not_in(self.actions.keys).and(t[:created_on].lt(invalid_when_created_before))
- self.actions.each do |action, options|
+ self.actions.each_key do |action|
validity_time = invalid_when_created_before(action)
# Do not delete tokens, which don't become invalid
mentionable_attrs = self.mentionable_attributes
saved_mentionable_attrs = self.saved_changes.select{|a| mentionable_attrs.include?(a)}
- saved_mentionable_attrs.each do |key, attr|
+ saved_mentionable_attrs.each_value do |attr|
old_value, new_value = attr
get_mentioned_users(old_value, new_value)
end
# anonymous user is never notified
users_to_test = @users_to_test.reject {|k, v| k.anonymous?}
- users_to_test.keys.each do |user|
+ users_to_test.each_key do |user|
Watcher.create!(:user => user, :watchable => @issue)
end
ActionMailer::Base.deliveries.clear
# anonymous user is never notified
users_to_test = @users_to_test.reject {|k, v| k.anonymous?}
- users_to_test.keys.each do |user|
+ users_to_test.each_key do |user|
Watcher.create!(:user => user, :watchable => @issue)
end
ActionMailer::Base.deliveries.clear
assert_equal 'One', attributes[:lastname]
assert_equal 'example1@redmine.org', attributes[:mail]
assert_equal auth.id, attributes[:auth_source_id]
- attributes.keys.each do |attribute|
+ attributes.each_key do |attribute|
assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned"
end
end