mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 20:16:19 +08:00
digest interfaces returning empty objects (except for id) interface needed correction
This commit is contained in:
parent
b6028c39d7
commit
c0f610daf6
|
@ -5,15 +5,14 @@ module Jobs
|
|||
recurrence { daily.hour_of_day(6) }
|
||||
|
||||
def execute(args)
|
||||
target_users.each do |u|
|
||||
Jobs.enqueue(:user_email, type: :digest, user_id: u.id)
|
||||
target_user_ids.each do |user_id|
|
||||
Jobs.enqueue(:user_email, type: :digest, user_id: user_id)
|
||||
end
|
||||
end
|
||||
|
||||
def target_users
|
||||
def target_user_ids
|
||||
# Users who want to receive emails and haven't been emailed in the last day
|
||||
query = User.select(:id)
|
||||
.where(email_digests: true, active: true)
|
||||
query = User.where(email_digests: true, active: true)
|
||||
.where("COALESCE(last_emailed_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
|
||||
.where("COALESCE(last_seen_at, '2010-01-01') <= CURRENT_TIMESTAMP - ('1 DAY'::INTERVAL * digest_after_days)")
|
||||
|
||||
|
@ -22,7 +21,7 @@ module Jobs
|
|||
query = query.where("approved OR moderator OR admin")
|
||||
end
|
||||
|
||||
query
|
||||
query.pluck(:id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -10,33 +10,33 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:user_no_digests) { Fabricate(:active_user, email_digests: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
|
||||
|
||||
it "doesn't return users with email disabled" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.include?(user_no_digests).should be_false
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_no_digests.id).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
context 'unapproved users' do
|
||||
Given!(:unapproved_user) { Fabricate(:active_user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
|
||||
When { SiteSetting.stubs(:must_approve_users?).returns(true) }
|
||||
Then { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(false) }
|
||||
Then { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(false) }
|
||||
|
||||
# As a moderator
|
||||
And { unapproved_user.update_column(:moderator, true) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(true) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
|
||||
# As an admin
|
||||
And { unapproved_user.update_attributes(admin: true, moderator: false) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(true) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
|
||||
# As an approved user
|
||||
And { unapproved_user.update_attributes(admin: false, moderator: false, approved: true ) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_users.include?(unapproved_user)).to eq(true) }
|
||||
And { expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(unapproved_user.id)).to eq(true) }
|
||||
end
|
||||
|
||||
context 'recently emailed' do
|
||||
let!(:user_emailed_recently) { Fabricate(:active_user, last_emailed_at: 6.days.ago) }
|
||||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.include?(user_emailed_recently).should be_false
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_emailed_recently.id).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:inactive_user) { Fabricate(:user) }
|
||||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.include?(inactive_user).should be_false
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(inactive_user.id).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,7 +53,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:user_visited_today) { Fabricate(:active_user, last_seen_at: 6.days.ago) }
|
||||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.include?(user_visited_today).should be_false
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_visited_today.id).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,7 +62,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:user) { Fabricate(:active_user) }
|
||||
|
||||
it "returns the user" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.should == [user]
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.should == [user.id]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,7 +73,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
Jobs::EnqueueDigestEmails.any_instance.expects(:target_users).returns([user])
|
||||
Jobs::EnqueueDigestEmails.any_instance.expects(:target_user_ids).returns([user.id])
|
||||
end
|
||||
|
||||
it "enqueues the digest email job" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user