mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: take into account unlisted banners
This commit is contained in:
parent
41e427bd2e
commit
efb02ae561
2 changed files with 24 additions and 6 deletions
|
@ -162,12 +162,12 @@ class TopicsController < ApplicationController
|
|||
params.require(:category_id)
|
||||
category_id = params[:category_id].to_i
|
||||
|
||||
topics = Topic.listable_topics.visible
|
||||
visible_topics = Topic.listable_topics.visible
|
||||
|
||||
render json: {
|
||||
pinned_in_category_count: topics.where(category_id: category_id).where(pinned_globally: false).where.not(pinned_at: nil).count,
|
||||
pinned_globally_count: topics.where(pinned_globally: true).where.not(pinned_at: nil).count,
|
||||
banner_count: topics.where(archetype: Archetype.banner).count,
|
||||
pinned_in_category_count: visible_topics.where(category_id: category_id).where(pinned_globally: false).where.not(pinned_at: nil).count,
|
||||
pinned_globally_count: visible_topics.where(pinned_globally: true).where.not(pinned_at: nil).count,
|
||||
banner_count: Topic.listable_topics.where(archetype: Archetype.banner).count,
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -976,7 +976,6 @@ describe TopicsController do
|
|||
|
||||
xhr :put, :remove_bookmarks, topic_id: post.topic_id
|
||||
expect(PostAction.where(user_id: user.id, post_action_type: bookmark).count).to eq(0)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -996,8 +995,27 @@ describe TopicsController do
|
|||
xhr :put, :reset_new
|
||||
user.reload
|
||||
expect(user.user_stat.new_since.to_date).not_to eq(old_date.to_date)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "feature_stats" do
|
||||
it "works" do
|
||||
xhr :get, :feature_stats, category_id: 1
|
||||
|
||||
expect(response).to be_success
|
||||
json = JSON.parse(response.body)
|
||||
expect(json["pinned_in_category_count"]).to eq(0)
|
||||
expect(json["pinned_globally_count"]).to eq(0)
|
||||
expect(json["banner_count"]).to eq(0)
|
||||
end
|
||||
|
||||
it "allows unlisted banner topic" do
|
||||
Fabricate(:topic, category_id: 1, archetype: Archetype.banner, visible: false)
|
||||
|
||||
xhr :get, :feature_stats, category_id: 1
|
||||
json = JSON.parse(response.body)
|
||||
expect(json["banner_count"]).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue