FEATURE: Count views on published pages (#17878)

* FEATURE: Count views on published pages

* Removed trailing whitespaces

* Fixed the test
This commit is contained in:
Frank 2022-08-19 00:11:19 +08:00 committed by GitHub
parent c63580b226
commit 6e682cc7c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -35,6 +35,8 @@ class PublishedPagesController < ApplicationController
@site_url = Discourse.base_url
@border_color = "#" + ColorScheme.base_colors["tertiary"]
TopicViewItem.add(pp.topic.id, request.remote_ip, current_user ? current_user.id : nil)
@body_classes = Set.new([
'published-page',
params[:slug],

View File

@ -4,6 +4,7 @@ RSpec.describe PublishedPagesController do
fab!(:published_page) { Fabricate(:published_page) }
fab!(:admin) { Fabricate(:admin) }
fab!(:user) { Fabricate(:user) }
fab!(:user2) { Fabricate(:user) }
context "when enabled" do
before do
@ -39,6 +40,14 @@ RSpec.describe PublishedPagesController do
end
describe "#show" do
it 'records a view' do
sign_in(user2)
expect do
get published_page.path
end.to change(TopicViewItem, :count).by(1)
end
it "returns 404 for a missing article" do
get "/pub/no-article-here-no-thx"
expect(response.status).to eq(404)