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

chore[Op#40437]: improve var naming; make less generic

Kabiru Mwenja80cea6e41ed5
diff --git a/app/models/concerns/reactable.rb b/app/models/concerns/reactable.rb
index 72f4600b1b4..10392482fc2 100644
--- a/app/models/concerns/reactable.rb
+++ b/app/models/concerns/reactable.rb
@@ -46,8 +46,8 @@ module Reactable
grouped_emoji_reactions(reactable_id:, reactable_type:).each_with_object({}) do |row, hash|
hash[row.reactable_id] ||= {}
hash[row.reactable_id][row.reaction.to_sym] = {
- count: row.count,
- users: row.user_details.map { |(id, name)| { id:, name: } }
+ count: row.reactions_count,
+ users: row.reacting_users.map { |(id, name)| { id:, name: } }
}
end
end
@@ -65,11 +65,12 @@ module Reactable
def emoji_reactions_group_selection_sql
<<~SQL.squish
- emoji_reactions.reactable_id, emoji_reactions.reaction, COUNT(emoji_reactions.id) as count,
+ emoji_reactions.reactable_id, emoji_reactions.reaction,
+ COUNT(emoji_reactions.id) as reactions_count,
json_agg(
json_build_array(users.id, #{user_name_concat_format_sql})
ORDER BY emoji_reactions.created_at
- ) as user_details,
+ ) as reacting_users,
MIN(emoji_reactions.created_at) as first_created_at
SQL
end
diff --git a/spec/models/concerns/reactable_spec.rb b/spec/models/concerns/reactable_spec.rb
index 5ac0e6067f7..34530f4e2f6 100644
--- a/spec/models/concerns/reactable_spec.rb
+++ b/spec/models/concerns/reactable_spec.rb
@@ -135,19 +135,19 @@ RSpec.describe Reactable do
result = Journal.grouped_emoji_reactions(reactable_id: work_package.journal_ids, reactable_type: "Journal")
expect(result[0].reaction).to eq("thumbs_up")
- expect(result[0].count).to eq(2)
- expect(result[0].user_details).to eq([[user1.id, user1.name], [user2.id, user2.name]])
+ expect(result[0].reactions_count).to eq(2)
+ expect(result[0].reacting_users).to eq([[user1.id, user1.name], [user2.id, user2.name]])
expect(result[1].reaction).to eq("thumbs_down")
- expect(result[1].count).to eq(1)
- expect(result[1].user_details).to eq([[user2.id, user2.name]])
+ expect(result[1].reactions_count).to eq(1)
+ expect(result[1].reacting_users).to eq([[user2.id, user2.name]])
end
context "when user format is set to :username", with_settings: { user_format: :username } do
it "returns grouped emoji reactions with usernames" do
result = Journal.grouped_emoji_reactions(reactable_id: work_package.journal_ids, reactable_type: "Journal")
- expect(result[0].user_details).to eq([[user1.id, user1.login], [user2.id, user2.login]])
+ expect(result[0].reacting_users).to eq([[user1.id, user1.login], [user2.id, user2.login]])
end
end
@@ -155,7 +155,7 @@ RSpec.describe Reactable do
it "returns grouped emoji reactions with first and last names" do
result = Journal.grouped_emoji_reactions(reactable_id: wp_journal2.id, reactable_type: "Journal")
- expect(result[0].user_details).to eq([[user2.id, user2.firstname]])
+ expect(result[0].reacting_users).to eq([[user2.id, user2.firstname]])
end
end
@@ -163,7 +163,7 @@ RSpec.describe Reactable do
it "returns grouped emoji reactions with last coma firstname" do
result = Journal.grouped_emoji_reactions(reactable_id: wp_journal1.id, reactable_type: "Journal")
- expect(result[0].user_details).to eq(
+ expect(result[0].reacting_users).to eq(
[
[user1.id, "#{user1.lastname}, #{user1.firstname}"],
[user2.id, "#{user2.lastname}, #{user2.firstname}"]
@@ -176,7 +176,7 @@ RSpec.describe Reactable do
it "returns grouped emoji reactions with last firstname" do
result = Journal.grouped_emoji_reactions(reactable_id: wp_journal1.id, reactable_type: "Journal")
- expect(result[0].user_details).to eq(
+ expect(result[0].reacting_users).to eq(
[
[user1.id, "#{user1.lastname}#{user1.firstname}"],
[user2.id, "#{user2.lastname}#{user2.firstname}"]