discourse-topic-voting/spec/requests/lists_controller_spec.rb
Natalie Tay 3d3037729c
DEV: Scope topic voting tables to avoid confusion with post voting (#196)
Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics.

This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
2024-07-17 20:26:40 +08:00

56 lines
1.7 KiB
Ruby

# frozen_string_literal: true
require "rails_helper"
describe ListController do
fab!(:user)
fab!(:topic)
# "topics/voted-by/:username"
before { SiteSetting.topic_voting_enabled = true }
it "allow anons to view votes" do
DiscourseTopicVoting::Vote.create!(user: user, topic: topic)
get "/topics/voted-by/#{user.username}.json"
topic_json = response.parsed_body.dig("topic_list", "topics").first
expect(topic_json["id"]).to eq(topic.id)
end
it "returns a 404 when we don't show votes on profiles" do
DiscourseTopicVoting::Vote.create!(user: user, topic: topic)
SiteSetting.topic_voting_show_votes_on_profile = false
get "/topics/voted-by/#{user.username}.json"
expect(response.status).to eq(404)
end
context "in a category" do
fab!(:category1) { Fabricate(:category) }
fab!(:category2) { Fabricate(:category) }
fab!(:topic1) do
Fabricate(:topic, category: category1, title: "Topic in votes-enabled category 1")
end
fab!(:topic2) do
Fabricate(:topic, category: category2, title: "Topic in votes-enabled category 2")
end
before do
DiscourseTopicVoting::CategorySetting.create!(category: category1)
DiscourseTopicVoting::CategorySetting.create!(category: category2)
end
it "allows anons to view votes RSS feed" do
DiscourseTopicVoting::Vote.create!(user: user, topic: topic1)
DiscourseTopicVoting::Vote.create!(user: user, topic: topic2)
get "/c/#{category2.slug}/#{category2.id}/l/votes.rss"
expect(response.status).to eq(200)
expect(response.body).to include(topic2.title)
# ensure we don't include votes from other categories
expect(response.body).not_to include(topic1.title)
end
end
end