diff --git a/app/models/topic_posters_summary.rb b/app/models/topic_posters_summary.rb index 9e23865374d..7808d09521b 100644 --- a/app/models/topic_posters_summary.rb +++ b/app/models/topic_posters_summary.rb @@ -16,7 +16,7 @@ class TopicPostersSummary TopicPoster.new.tap do |topic_poster| topic_poster.user = user topic_poster.description = descriptions_for(user) - topic_poster.extras = 'latest' if is_latest_poster?(user) + topic_poster.extras = 'latest' if include_latest_class?(user) end end @@ -29,6 +29,10 @@ class TopicPostersSummary end end + def include_latest_class?(user) + topic.last_post_user_id == user.id && user_ids.uniq.size > 1 + end + def descriptions_for(user) descriptions_by_id[user.id].join ', ' end @@ -56,10 +60,6 @@ class TopicPostersSummary topic.user_id == topic.last_post_user_id end - def is_latest_poster?(user) - topic.last_post_user_id == user.id - end - def sorted_top_posters shuffle_last_poster_to_back_in top_posters end diff --git a/spec/models/topic_posters_summary_spec.rb b/spec/models/topic_posters_summary_spec.rb index 06d02f9db13..72cd027c69d 100644 --- a/spec/models/topic_posters_summary_spec.rb +++ b/spec/models/topic_posters_summary_spec.rb @@ -27,7 +27,6 @@ describe TopicPostersSummary do summary.first.tap do |topic_poster| expect(topic_poster.user).to eq topic_creator - expect(topic_poster.extras).to eq 'latest' expect(topic_poster.description).to eq( "#{I18n.t(:original_poster)}, #{I18n.t(:most_recent_poster)}" ) @@ -65,6 +64,8 @@ describe TopicPostersSummary do featured_user1, featured_user2, featured_user3, last_poster ]) + # If more than one user, attach the latest class + expect(summary.last.extras).to eq 'latest' end end end