Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

rubocop auto-amendments

Kabiru Mwenja338174f27efa
diff --git a/app/components/work_packages/activities_tab/journals/item_component/reactions.rb b/app/components/work_packages/activities_tab/journals/item_component/reactions.rb
index 2c35315dc30..8fd1605a5e1 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/reactions.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/reactions.rb
@@ -60,19 +60,21 @@ module WorkPackages
max_displayed_users_count = 5
user_count = users.length
- displayed_users = users.take(max_displayed_users_count).map { |u| u[:name] }
+ displayed_users = users.take(max_displayed_users_count).pluck(:name)
result = if user_count <= max_displayed_users_count
- displayed_users.join(', ')
- elsif user_count == max_displayed_users_count + 1
- "#{displayed_users.join(', ')} #{I18n.t("reactions.and_n_others_singular", n: 1)}"
- else
- "#{displayed_users.join(', ')} #{I18n.t("reactions.and_n_others_plural", n: user_count - max_displayed_users_count)}"
- end
+ displayed_users.join(", ")
+ elsif user_count == max_displayed_users_count + 1
+ "#{displayed_users.join(', ')} #{I18n.t('reactions.and_n_others_singular', n: 1)}"
+ else
+ "#{displayed_users.join(', ')} #{I18n.t('reactions.and_n_others_plural',
+ n: user_count - max_displayed_users_count)}"
+ end
result += " "
result += I18n.t("reactions.reacted_with", emoji_shortcode: EmojiReaction.shortcode(emoji))
+ result
end
end
end
diff --git a/app/contracts/emoji_reactions/base_contract.rb b/app/contracts/emoji_reactions/base_contract.rb
index 821f801aa49..8a0658291d7 100644
--- a/app/contracts/emoji_reactions/base_contract.rb
+++ b/app/contracts/emoji_reactions/base_contract.rb
@@ -54,7 +54,7 @@ module EmojiReactions
end
def validate_reactable_exists
- errors.add :reactable, :error_not_found unless model.reactable.present?
+ errors.add :reactable, :error_not_found if model.reactable.blank?
end
def validate_emoji_type
diff --git a/app/models/concerns/reactable.rb b/app/models/concerns/reactable.rb
index a6b658aa858..ef5eb26e433 100644
--- a/app/models/concerns/reactable.rb
+++ b/app/models/concerns/reactable.rb
@@ -34,11 +34,11 @@ module Reactable
end
def add_reaction(user, emoji)
- emoji_reactions.create(user: user, emoji: emoji)
+ emoji_reactions.create(user:, emoji:)
end
def remove_reaction(user, emoji)
- emoji_reactions.find_by(user: user, emoji: emoji)&.destroy
+ emoji_reactions.find_by(user:, emoji:)&.destroy
end
def grouped_emoji_reactions
@@ -49,9 +49,9 @@ module Reactable
# TODO: Refactor this to be database agnostic
# fetch all emoji reactions and group them by emoji with their count and user ids
emoji_groups = emoji_reactions
- .select('emoji, COUNT(*) as count, ARRAY_AGG(user_id) as user_ids')
+ .select("emoji, COUNT(*) as count, ARRAY_AGG(user_id) as user_ids")
.group(:emoji)
- .order('emoji ASC')
+ .order("emoji ASC")
# avoid N+1 queries by preloading all reacting users
user_ids = emoji_groups.flat_map(&:user_ids).uniq
@@ -62,7 +62,7 @@ module Reactable
{
emoji: result.emoji,
count: result.count,
- users: result.user_ids.map { |id| { id: id, name: users[id].name } }
+ users: result.user_ids.map { |id| { id:, name: users[id].name } }
}
end.index_by { |r| r[:emoji] }
end
diff --git a/app/models/emoji_reaction.rb b/app/models/emoji_reaction.rb
index ef998557ee6..15c8468f37d 100644
--- a/app/models/emoji_reaction.rb
+++ b/app/models/emoji_reaction.rb
@@ -44,13 +44,13 @@ class EmojiReaction < ApplicationRecord
belongs_to :reactable, polymorphic: true
validates :emoji, presence: true, inclusion: { in: AVAILABLE_EMOJIS }
- validates :user_id, uniqueness: { scope: [:reactable_type, :reactable_id, :emoji] }
+ validates :user_id, uniqueness: { scope: %i[reactable_type reactable_id emoji] }
def self.available_emojis
AVAILABLE_EMOJIS
end
def self.shortcode(html_code)
- EMOJI_MAP.key(html_code)&.to_s&.prepend(':')&.concat(':') || html_code
+ EMOJI_MAP.key(html_code)&.to_s&.prepend(":")&.concat(":") || html_code
end
end
diff --git a/db/migrate/20240624103354_create_emoji_reactions.rb b/db/migrate/20240624103354_create_emoji_reactions.rb
index 365aa4b7603..d0f6ac11456 100644
--- a/db/migrate/20240624103354_create_emoji_reactions.rb
+++ b/db/migrate/20240624103354_create_emoji_reactions.rb
@@ -7,6 +7,7 @@ class CreateEmojiReactions < ActiveRecord::Migration[7.1]
t.timestamps
end
- add_index :emoji_reactions, [:user_id, :reactable_type, :reactable_id, :emoji], unique: true, name: 'index_emoji_reactions_uniqueness'
+ add_index :emoji_reactions, %i[user_id reactable_type reactable_id emoji], unique: true,
+ name: "index_emoji_reactions_uniqueness"
end
end