mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 17:40:43 +08:00
PERF: Only send down suggested payload when loading last chunk.
This commit is contained in:
38
spec/serializers/topic_view_serializer_spec.rb
Normal file
38
spec/serializers/topic_view_serializer_spec.rb
Normal file
@ -0,0 +1,38 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe TopicViewSerializer do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe '#suggested_topics' do
|
||||
let(:topic2) { Fabricate(:topic) }
|
||||
|
||||
before do
|
||||
TopicUser.update_last_read(user, topic2.id, 0, 0)
|
||||
end
|
||||
|
||||
describe 'when loading last chunk' do
|
||||
it 'should include suggested topics' do
|
||||
topic_view = TopicView.new(topic.id, user)
|
||||
json = described_class.new(topic_view, scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
expect(json[:suggested_topics].first.id).to eq(topic2.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when not loading last chunk' do
|
||||
let(:post) { Fabricate(:post, topic: topic) }
|
||||
let(:post2) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should not include suggested topics' do
|
||||
post
|
||||
post2
|
||||
topic_view = TopicView.new(topic.id, user, post_ids: [post.id])
|
||||
topic_view.next_page
|
||||
json = described_class.new(topic_view, scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
expect(json[:suggested_topics]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user