Move dev/mascot account to class methods (#6694)
This commit is contained in:
parent
ea70d4c4b9
commit
a333da23d1
3 changed files with 37 additions and 8 deletions
|
|
@ -161,9 +161,6 @@ class User < ApplicationRecord
|
|||
|
||||
alias_attribute :positive_reactions_count, :reactions_count
|
||||
|
||||
scope :dev_account, -> { find_by(id: SiteConfig.staff_user_id) }
|
||||
scope :mascot_account, -> { find_by(id: SiteConfig.mascot_user_id) }
|
||||
|
||||
scope :with_this_week_comments, lambda { |number|
|
||||
includes(:counters).joins(:counters).where("(user_counters.data -> 'comments_these_7_days')::int >= ?", number)
|
||||
}
|
||||
|
|
@ -225,16 +222,24 @@ class User < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def estimated_default_language
|
||||
language_settings["estimated_default_language"]
|
||||
end
|
||||
|
||||
def self.trigger_delayed_index(record, remove)
|
||||
return if remove
|
||||
|
||||
Search::IndexWorker.perform_async("User", record.id)
|
||||
end
|
||||
|
||||
def self.dev_account
|
||||
find_by(id: SiteConfig.staff_user_id)
|
||||
end
|
||||
|
||||
def self.mascot_account
|
||||
find_by(id: SiteConfig.mascot_user_id)
|
||||
end
|
||||
|
||||
def estimated_default_language
|
||||
language_settings["estimated_default_language"]
|
||||
end
|
||||
|
||||
def tag_line
|
||||
summary
|
||||
end
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ welcome_thread_content = <<~HEREDOC
|
|||
Leave a comment below to introduce yourself to the community!✌️
|
||||
HEREDOC
|
||||
|
||||
Article.create(
|
||||
Article.create!(
|
||||
body_markdown: welcome_thread_content,
|
||||
user: User.dev_account,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -957,4 +957,28 @@ RSpec.describe User, type: :model do
|
|||
expect(user.receives_follower_email_notifications?).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".dev_account" do
|
||||
it "returns nil if the account does not exist" do
|
||||
expect(described_class.dev_account).to be_nil
|
||||
end
|
||||
|
||||
it "returns the user if the account exists" do
|
||||
allow(SiteConfig).to receive(:staff_user_id).and_return(user.id)
|
||||
|
||||
expect(described_class.dev_account).to eq(user)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".mascot_account" do
|
||||
it "returns nil if the account does not exist" do
|
||||
expect(described_class.mascot_account).to be_nil
|
||||
end
|
||||
|
||||
it "returns the user if the account exists" do
|
||||
allow(SiteConfig).to receive(:mascot_user_id).and_return(user.id)
|
||||
|
||||
expect(described_class.mascot_account).to eq(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue