* Ensuring we don't track views of author or unpublished Prior to this commit, I was surprised to learn that we: 1) Tracked an author's view of their article. 2) Tracked views of an unpublished article. This came up from a Forem creator asking if they could reset the view counter. Or trigger the reset on publication. I think a general business logic policy of don't track views for the author and don't track views for unpublished articles is a reasonable default. Were we to pursue the clear views on publication, we'd need to consider something that went from unpublished -> published -> unpublished -> published. Without a more explicit state machine, triggering a busineiss logic behavior seems a bit unexpected. In other words, I wrote an article. There are 20 views when I realize that I need to unpublished it. I make the changes in the unpublished state, and re-publish. I'd assume that those 20 views would still be "recorded" and counted towards my article's view counts. * Adjusting condition structure Prior to this commit, the `if` clause was rather far to the right. This helps make the if clause more pronounced.
33 lines
929 B
Ruby
33 lines
929 B
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Articles::PageViewUpdater do
|
|
describe "#call" do
|
|
subject(:method_call) { described_class.call(article_id: article.id, user_id: user.id) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
context "when article published and written by another user" do
|
|
let(:article) { create(:article, user: create(:user)) }
|
|
|
|
it "updates a user's page view" do
|
|
expect { method_call }.to change(PageView, :count)
|
|
end
|
|
end
|
|
|
|
context "when article is unpublished" do
|
|
let(:article) { create(:article, published: false, published_at: nil) }
|
|
|
|
it "skips updating" do
|
|
expect { method_call }.not_to change(PageView, :count)
|
|
end
|
|
end
|
|
|
|
context "when article written by given user" do
|
|
let(:article) { create(:article, user: user) }
|
|
|
|
it "skips updating" do
|
|
expect { method_call }.not_to change(PageView, :count)
|
|
end
|
|
end
|
|
end
|
|
end
|