FIX: exclude topics from latest in /categories on refresh

When you hit refresh on categories page it would not supress correctly
This commit is contained in:
Sam 2018-04-24 09:54:51 +10:00 committed by Robin Ward
parent fd14ee4797
commit 146a6c3592
2 changed files with 36 additions and 17 deletions

View File

@ -42,7 +42,8 @@ class CategoriesController < ApplicationController
style = SiteSetting.desktop_category_page_style
topic_options = {
per_page: SiteSetting.categories_topics,
no_definitions: true
no_definitions: true,
exclude_category_ids: Category.where(suppress_from_latest: true).pluck(:id)
}
if style == "categories_and_latest_topics".freeze

View File

@ -1,24 +1,42 @@
require 'rails_helper'
describe GroupsController do
let(:admin) { Fabricate(:admin) }
let(:category) { Fabricate(:category, user: admin) }
describe CategoriesController do
before do
category
sign_in(admin)
context 'index' do
it 'suppresses categories correctly' do
post = create_post(title: 'super AMAZING AMAZING post')
get "/categories"
expect(response.body).to include('AMAZING AMAZING')
post.topic.category.update_columns(suppress_from_latest: true)
get "/categories"
expect(response.body).not_to include('AMAZING AMAZING')
end
end
it "triggers a extensibility event" do
event = DiscourseEvent.track_events {
put "/categories/#{category.id}.json", params: {
name: 'hello',
color: 'ff0',
text_color: 'fff'
}
}.last
context 'extensibility event' do
let(:admin) { Fabricate(:admin) }
let(:category) { Fabricate(:category, user: admin) }
expect(event[:event_name]).to eq(:category_updated)
expect(event[:params].first).to eq(category)
before do
category
sign_in(admin)
end
it "triggers a extensibility event" do
event = DiscourseEvent.track_events {
put "/categories/#{category.id}.json", params: {
name: 'hello',
color: 'ff0',
text_color: 'fff'
}
}.last
expect(event[:event_name]).to eq(:category_updated)
expect(event[:params].first).to eq(category)
end
end
end