Skip to content

Commit

Permalink
FIX: Render votes RSS feed (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmusaraj committed Jan 18, 2024
1 parent d030113 commit 98115fa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/discourse_topic_voting/list_controller_extension.rb
Expand Up @@ -4,8 +4,8 @@ module DiscourseTopicVoting
module ListControllerExtension
def self.prepended(base)
base.class_eval do
before_action :ensure_discourse_topic_voting, only: %i[voted_by]
skip_before_action :ensure_logged_in, only: %i[voted_by]
before_action :ensure_discourse_topic_voting, only: %i[voted_by votes_feed]
skip_before_action :ensure_logged_in, only: %i[voted_by votes_feed]
end
end

Expand All @@ -18,6 +18,15 @@ def voted_by
respond_with_list(list)
end

def votes_feed
category_slug_path_with_id = params.require(:category_slug_path_with_id)

@category = Category.find_by_slug_path_with_id(category_slug_path_with_id)
@topic_list = TopicQuery.new(current_user, { category: @category.id }).list_votes

render "list", formats: [:rss]
end

protected

def ensure_discourse_topic_voting
Expand Down
4 changes: 4 additions & 0 deletions plugin.rb
Expand Up @@ -223,6 +223,10 @@ class Engine < ::Rails::Engine
get "who" => "votes#who"
end

Discourse::Application.routes.prepend do
get "c/*category_slug_path_with_id/l/votes.rss" => "list#votes_feed", :format => :rss
end

Discourse::Application.routes.append do
mount ::DiscourseTopicVoting::Engine, at: "/voting"

Expand Down
28 changes: 28 additions & 0 deletions spec/requests/lists_controller_spec.rb
Expand Up @@ -25,4 +25,32 @@

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

0 comments on commit 98115fa

Please sign in to comment.