From 03d51d6519ebbf5edab9fbda2899e3113a73fba7 Mon Sep 17 00:00:00 2001 From: romanrizzi Date: Tue, 27 Aug 2019 12:13:38 -0300 Subject: [PATCH] FIX: Display actual readers on the first post --- app/controllers/post_readers_controller.rb | 3 ++- spec/requests/post_readers_controller_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/post_readers_controller.rb b/app/controllers/post_readers_controller.rb index 76d75a70ac1..a5fd76fafc3 100644 --- a/app/controllers/post_readers_controller.rb +++ b/app/controllers/post_readers_controller.rb @@ -10,7 +10,8 @@ class PostReadersController < ApplicationController readers = User .joins(:topic_users) - .where('topic_users.topic_id = ? AND COALESCE(topic_users.last_read_post_number, 1) >= ?', post.topic_id, post.post_number) + .where.not(topic_users: { last_read_post_number: nil }) + .where('topic_users.topic_id = ? AND topic_users.last_read_post_number >= ?', post.topic_id, post.post_number) .where.not(id: [current_user.id, post.user_id]) readers = readers.map do |r| diff --git a/spec/requests/post_readers_controller_spec.rb b/spec/requests/post_readers_controller_spec.rb index fa2cf3d8728..d5d60c8ed22 100644 --- a/spec/requests/post_readers_controller_spec.rb +++ b/spec/requests/post_readers_controller_spec.rb @@ -65,6 +65,16 @@ describe PostReadersController do expect(reader).to be_nil end + + it "doesn't include users without reading progress on first post" do + @post.update(post_number: 1) + TopicUser.create!(user: reader, topic: @group_message, last_read_post_number: nil) + + get '/post_readers.json', params: { id: @post.id } + readers = JSON.parse(response.body)['post_readers'] + + expect(readers).to be_empty + end end def assert_reader_is_correctly_serialized(reader_data, reader, post)