FIX: Render votes RSS feed (#180)
This commit is contained in:
parent
d030113a45
commit
98115faada
|
@ -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
|
||||
|
||||
|
@ -18,6 +18,15 @@ module DiscourseTopicVoting
|
|||
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
|
||||
|
|
|
@ -223,6 +223,10 @@ after_initialize do
|
|||
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"
|
||||
|
||||
|
|
|
@ -25,4 +25,32 @@ describe ListController do
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue