diff --git a/lib/jobs/enqueue_digest_emails.rb b/lib/jobs/enqueue_digest_emails.rb index 19daf9a6443..9c79c8ad244 100644 --- a/lib/jobs/enqueue_digest_emails.rb +++ b/lib/jobs/enqueue_digest_emails.rb @@ -12,7 +12,7 @@ module Jobs def target_users # Users who want to receive emails and haven't been emailed int he last day query = User.select(:id) - .where(email_digests: true) + .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)") diff --git a/spec/components/jobs/enqueue_digest_emails_spec.rb b/spec/components/jobs/enqueue_digest_emails_spec.rb index d682daf49ca..15900f04abc 100644 --- a/spec/components/jobs/enqueue_digest_emails_spec.rb +++ b/spec/components/jobs/enqueue_digest_emails_spec.rb @@ -7,7 +7,7 @@ describe Jobs::EnqueueDigestEmails do describe '#target_users' do context 'disabled digests' do - let!(:user_no_digests) { Fabricate(:user, email_digests: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) } + 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 @@ -15,7 +15,7 @@ describe Jobs::EnqueueDigestEmails do end context 'unapproved users' do - Given!(:unapproved_user) { Fabricate(:user, approved: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) } + 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) } @@ -33,15 +33,24 @@ describe Jobs::EnqueueDigestEmails do end context 'recently emailed' do - let!(:user_emailed_recently) { Fabricate(:user, last_emailed_at: 6.days.ago) } + 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 end end + context "inactive user" 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 + end + end + + context 'visited the site today' do - let!(:user_visited_today) { Fabricate(:user, last_seen_at: 6.days.ago) } + 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 @@ -50,7 +59,7 @@ describe Jobs::EnqueueDigestEmails do context 'regular users' do - let!(:user) { Fabricate(:user) } + let!(:user) { Fabricate(:active_user) } it "returns the user" do Jobs::EnqueueDigestEmails.new.target_users.should == [user] diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 149ece720de..4b400035d1c 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -48,3 +48,13 @@ Fabricator(:newuser, from: :user) do email 'newbie@new.com' trust_level TrustLevel.levels[:newuser] end + +Fabricator(:active_user, from: :user) do + name 'Luke Skywalker' + username { sequence(:username) { |i| "luke#{i}" } } + email { sequence(:email) { |i| "luke#{i}@skywalker.com" } } + password 'myawesomepassword' + trust_level TrustLevel.levels[:basic] + active true + bio_raw "Don't as me about my dad!" +end \ No newline at end of file diff --git a/spec/models/email_token_spec.rb b/spec/models/email_token_spec.rb index 18f74ee608b..a27d76dc668 100644 --- a/spec/models/email_token_spec.rb +++ b/spec/models/email_token_spec.rb @@ -8,7 +8,7 @@ describe EmailToken do context '#create' do - let(:user) { Fabricate(:user) } + let(:user) { Fabricate(:user, active: false) } let!(:original_token) { user.email_tokens.first } let!(:email_token) { user.email_tokens.create(email: 'bubblegum@adevnturetime.ooo') } @@ -42,7 +42,7 @@ describe EmailToken do context '#confirm' do - let(:user) { Fabricate(:user) } + let(:user) { Fabricate(:user, active: false) } let(:email_token) { user.email_tokens.first } it 'returns nil with a nil token' do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 97a665c152c..7b286a481e9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -567,7 +567,7 @@ describe User do describe 'passwords' do before do - @user = Fabricate.build(:user) + @user = Fabricate.build(:user, active: false) @user.password = "ilovepasta" @user.save! end