diff --git a/app/models/article.rb b/app/models/article.rb index a22573e04..41c930d58 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -112,9 +112,10 @@ class Article < ApplicationRecord scope :admin_published_with, lambda { |tag_name| published - .where(user_id: SiteConfig.staff_user_id) - .order(published_at: :desc) - .tagged_with(tag_name) + .where(user_id: User.with_role(:super_admin) + .union(User.with_role(:admin)) + .union(id: [SiteConfig.staff_user_id, SiteConfig.mascot_user_id].compact) + .select(:id)).order(published_at: :desc).tagged_with(tag_name) } scope :user_published_with, lambda { |user_id, tag_name| diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 01350a4a4..bca4ec074 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -53,6 +53,34 @@ RSpec.describe Article, type: :model do it { is_expected.not_to allow_value("foo").for(:main_image_background_hex_color) } + describe "::admin_published_with" do + it "includes mascot-published articles" do + allow(SiteConfig).to receive(:mascot_user_id).and_return(3) + user = create(:user, id: 3) + create(:article, user: user, tags: "challenge") + expect(described_class.admin_published_with("challenge").count).to eq(1) + end + + it "includes staff-user-published articles" do + allow(SiteConfig).to receive(:staff_user_id).and_return(3) + user = create(:user, id: 3) + create(:article, user: user, tags: "challenge") + expect(described_class.admin_published_with("challenge").count).to eq(1) + end + + it "includes admin published articles" do + user = create(:user, :admin) + create(:article, user: user, tags: "challenge") + expect(described_class.admin_published_with("challenge").count).to eq(1) + end + + it "does not include regular user published articles" do + user = create(:user) + create(:article, user: user, tags: "challenge") + expect(described_class.admin_published_with("challenge").count).to eq(0) + end + end + describe "#body_markdown" do it "is unique scoped for user_id and title" do art2 = build(:article, body_markdown: article.body_markdown, user: article.user, title: article.title)