From 8641f0a93e2caa1c718940b389d8ea8b911c2a85 Mon Sep 17 00:00:00 2001 From: Ridhwana Date: Mon, 17 Feb 2020 19:18:33 +0200 Subject: [PATCH] Update the number of `Published Posts` to match the approved articles where necessary. (#6098) * feat: the number of published posts should show up by approved article. * chore: Do not use spaces between -> and ( in lambda literals * refactor: use the existing function in order to spawn the one where we need approval * refactor: move logic to the controller instead of the view :) * chore: code climate syntax * chore: more codeclimate --- app/controllers/stories_controller.rb | 6 ++++++ app/models/article.rb | 2 ++ app/views/articles/tags/_sidebar.html.erb | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index a297cf223..f883bee25 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -87,6 +87,12 @@ class StoriesController < ApplicationController return end + @num_published_articles = if @tag_model.requires_approval? + Article.published.cached_tagged_by_approval_with(@tag).size + else + Article.published.cached_tagged_with(@tag).size + end + @stories = Articles::Feed.new(number_of_articles: 8, tag: @tag).published_articles_by_tag @stories = @stories.where(approved: true) if @tag_model&.requires_approval diff --git a/app/models/article.rb b/app/models/article.rb index e579251b6..ff3f2a935 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -80,6 +80,8 @@ class Article < ApplicationRecord scope :cached_tagged_with, ->(tag) { where("cached_tag_list ~* ?", "^#{tag},| #{tag},|, #{tag}$|^#{tag}$") } + scope :cached_tagged_by_approval_with, ->(tag) { cached_tagged_with(tag).where(approved: true) } + scope :active_help, lambda { published. cached_tagged_with("help"). diff --git a/app/views/articles/tags/_sidebar.html.erb b/app/views/articles/tags/_sidebar.html.erb index ff617cf09..f19eff703 100644 --- a/app/views/articles/tags/_sidebar.html.erb +++ b/app/views/articles/tags/_sidebar.html.erb @@ -63,7 +63,7 @@ <% end %>