Skip to content

Commit

Permalink
FIX: enabling suppress_from_homepage should only remove the category …
Browse files Browse the repository at this point in the history
…from the homepage
  • Loading branch information
ZogStriP committed Jan 20, 2016
1 parent a601d4b commit 74b5d06
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/controllers/list_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ class ListController < ApplicationController
list_opts.merge!(options) if options
user = list_target_user

if filter == :latest && params[:category].blank?
list_opts[:no_definitions] = true
end

if filter.to_s == current_homepage
list_opts.merge!(exclude_category_ids: get_excluded_category_ids(list_opts[:category]))
if params[:category].blank?
if filter == :latest
list_opts[:no_definitions] = true
end
if filter.to_s == current_homepage
list_opts[:exclude_category_ids] = get_excluded_category_ids(list_opts[:category])
end
end

list = TopicQuery.new(user, list_opts).public_send("list_#{filter}")

list.more_topics_url = construct_url_with(:next, list_opts)
list.prev_topics_url = construct_url_with(:prev, list_opts)
if Discourse.anonymous_filters.include?(filter)
Expand Down Expand Up @@ -165,7 +167,7 @@ def parent_category_category_top
top_options[:per_page] = SiteSetting.topics_per_period_in_top_page

if "top".freeze == current_homepage
top_options.merge!(exclude_category_ids: get_excluded_category_ids(top_options[:category]))
top_options[:exclude_category_ids] = get_excluded_category_ids(top_options[:category])
end

user = list_target_user
Expand Down
26 changes: 26 additions & 0 deletions spec/controllers/list_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,30 @@

end

describe "categories suppression" do
let(:category_one) { Fabricate(:category) }
let(:sub_category) { Fabricate(:category, parent_category: category_one, suppress_from_homepage: true) }
let!(:topic_in_sub_category) { Fabricate(:topic, category: sub_category) }

let(:category_two) { Fabricate(:category, suppress_from_homepage: true) }
let!(:topic_in_category_two) { Fabricate(:topic, category: category_two) }

it "suppresses categories from the homepage" do
get SiteSetting.homepage, format: :json
expect(response).to be_success

topic_titles = JSON.parse(response.body)["topic_list"]["topics"].map { |t| t["title"] }
expect(topic_titles).not_to include(topic_in_sub_category.title, topic_in_category_two.title)
end

it "does not suppress" do
get SiteSetting.homepage, category: category_one.id, format: :json
expect(response).to be_success

topic_titles = JSON.parse(response.body)["topic_list"]["topics"].map { |t| t["title"] }
expect(topic_titles).to include(topic_in_sub_category.title)
end

end

end

0 comments on commit 74b5d06

Please sign in to comment.