mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-03 20:07:47 +08:00
Removed in 2022 because of perf considerations. This restores it and updates the implementation and styling. The perf should not be an issue anymore: 1. it's now rendered only in the crawler view (and not for regular logged-in users or anons) 2. it previously used Rails' partial rendering which re-read file on each request. `register_html_builder` is more efficient (and this particular block skips rendering completely when not applicable)
64 lines
2 KiB
Ruby
64 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe TopicsController do
|
|
fab!(:user)
|
|
fab!(:topic) { Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE) }
|
|
fab!(:post) { create_post(topic: topic) }
|
|
fab!(:comment) { Fabricate(:post_voting_comment, raw: "this is a comment!", post: post) }
|
|
|
|
fab!(:answer) { create_post(topic: topic) }
|
|
fab!(:answer_2) { create_post(topic: topic) }
|
|
fab!(:answer_3) { create_post(topic: topic) }
|
|
|
|
fab!(:vote) do
|
|
PostVoting::VoteManager.vote(answer_2, user, direction: PostVotingVote.directions[:up])
|
|
end
|
|
|
|
fab!(:vote_2) do
|
|
PostVoting::VoteManager.vote(answer, user, direction: PostVotingVote.directions[:down])
|
|
end
|
|
|
|
before { SiteSetting.post_voting_enabled = true }
|
|
|
|
describe "#show" do
|
|
it "orders posts by number of votes for a Post Voting topic" do
|
|
get "/t/#{topic.id}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
payload = response.parsed_body
|
|
|
|
expect(payload["post_stream"]["posts"].map { |p| p["id"] }).to eq(
|
|
[post.id, answer_2.id, answer_3.id, answer.id],
|
|
)
|
|
end
|
|
|
|
it "does not error for topic views without any posts" do
|
|
get "/t/#{topic.id}.json?page=2"
|
|
|
|
expect(response.status).to eq(404)
|
|
end
|
|
|
|
it "orders posts by date of creation when 'activity' filter is provided" do
|
|
get "/t/#{topic.id}.json?filter=#{TopicView::ACTIVITY_FILTER}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
payload = response.parsed_body
|
|
|
|
expect(payload["post_stream"]["posts"].map { |p| p["id"] }).to eq(
|
|
[post.id, answer.id, answer_2.id, answer_3.id],
|
|
)
|
|
end
|
|
|
|
it "includes post_voting comments in crawler view" do
|
|
get "/t/#{topic.slug}/#{topic.id}", env: { "HTTP_USER_AGENT" => "Googlebot" }
|
|
|
|
expect(response.status).to eq(200)
|
|
expect(response.body).to match(
|
|
%r{<span class="post-voting-comments__comment-cooked" itemprop="text"><p>this is a comment!</p></span>},
|
|
)
|
|
expect(response.body).to match(%r{<span class="post-voting-answer-count__value">3</span>})
|
|
end
|
|
end
|
|
end
|