about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/concerns/user_tracking_concern_spec.rb46
-rw-r--r--spec/mailers/previews/user_mailer_preview.rb5
-rw-r--r--spec/mailers/user_mailer_spec.rb10
-rw-r--r--spec/services/notify_service_spec.rb11
4 files changed, 58 insertions, 14 deletions
diff --git a/spec/controllers/concerns/user_tracking_concern_spec.rb b/spec/controllers/concerns/user_tracking_concern_spec.rb
index 168d44ba6..1e5620221 100644
--- a/spec/controllers/concerns/user_tracking_concern_spec.rb
+++ b/spec/controllers/concerns/user_tracking_concern_spec.rb
@@ -43,15 +43,45 @@ describe ApplicationController, type: :controller do
       expect_updated_sign_in_at(user)
     end
 
-    it 'regenerates feed when sign in is older than two weeks' do
-      allow(RegenerationWorker).to receive(:perform_async)
-      user.update(current_sign_in_at: 3.weeks.ago)
-      sign_in user, scope: :user
-      get :show
+    describe 'feed regeneration' do
+      before do
+        alice = Fabricate(:account)
+        bob   = Fabricate(:account)
 
-      expect_updated_sign_in_at(user)
-      expect(Redis.current.get("account:#{user.account_id}:regeneration")).to eq 'true'
-      expect(RegenerationWorker).to have_received(:perform_async)
+        user.account.follow!(alice)
+        user.account.follow!(bob)
+
+        Fabricate(:status, account: alice, text: 'hello world')
+        Fabricate(:status, account: bob, text: 'yes hello')
+        Fabricate(:status, account: user.account, text: 'test')
+
+        user.update(last_sign_in_at: 'Tue, 04 Jul 2017 14:45:56 UTC +00:00', current_sign_in_at: 'Wed, 05 Jul 2017 22:10:52 UTC +00:00')
+
+        sign_in user, scope: :user
+      end
+
+      it 'sets a regeneration marker while regenerating' do
+        allow(RegenerationWorker).to receive(:perform_async)
+        get :show
+
+        expect_updated_sign_in_at(user)
+        expect(Redis.current.get("account:#{user.account_id}:regeneration")).to eq 'true'
+        expect(RegenerationWorker).to have_received(:perform_async)
+      end
+
+      it 'sets the regeneration marker to expire' do
+        allow(RegenerationWorker).to receive(:perform_async)
+        get :show
+        expect(Redis.current.ttl("account:#{user.account_id}:regeneration")).to be >= 0
+      end
+
+      it 'regenerates feed when sign in is older than two weeks' do
+        get :show
+
+        expect_updated_sign_in_at(user)
+        expect(Redis.current.zcard(FeedManager.instance.key(:home, user.account_id))).to eq 3
+        expect(Redis.current.get("account:#{user.account_id}:regeneration")).to be_nil
+      end
     end
 
     def expect_updated_sign_in_at(user)
diff --git a/spec/mailers/previews/user_mailer_preview.rb b/spec/mailers/previews/user_mailer_preview.rb
index 6ed0090f4..8d2a9368d 100644
--- a/spec/mailers/previews/user_mailer_preview.rb
+++ b/spec/mailers/previews/user_mailer_preview.rb
@@ -29,4 +29,9 @@ class UserMailerPreview < ActionMailer::Preview
   def reset_password_instructions
     UserMailer.reset_password_instructions(User.first, 'spec')
   end
+
+  # Preview this email at http://localhost:3000/rails/mailers/user_mailer/welcome
+  def welcome
+    UserMailer.welcome(User.first)
+  end
 end
diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb
index 9f17993e0..6b430b505 100644
--- a/spec/mailers/user_mailer_spec.rb
+++ b/spec/mailers/user_mailer_spec.rb
@@ -23,7 +23,7 @@ describe UserMailer, type: :mailer do
 
     it 'renders confirmation instructions' do
       receiver.update!(locale: nil)
-      expect(mail.body.encoded).to include receiver.email
+      expect(mail.body.encoded).to include I18n.t('devise.mailer.confirmation_instructions.title')
       expect(mail.body.encoded).to include 'spec'
       expect(mail.body.encoded).to include Rails.configuration.x.local_domain
     end
@@ -38,7 +38,7 @@ describe UserMailer, type: :mailer do
 
     it 'renders reconfirmation instructions' do
       receiver.update!(email: 'new-email@example.com', locale: nil)
-      expect(mail.body.encoded).to include 'new-email@example.com'
+      expect(mail.body.encoded).to include I18n.t('devise.mailer.reconfirmation_instructions.title')
       expect(mail.body.encoded).to include 'spec'
       expect(mail.body.encoded).to include Rails.configuration.x.local_domain
       expect(mail.subject).to eq I18n.t('devise.mailer.reconfirmation_instructions.subject',
@@ -52,7 +52,7 @@ describe UserMailer, type: :mailer do
 
     it 'renders reset password instructions' do
       receiver.update!(locale: nil)
-      expect(mail.body.encoded).to include receiver.email
+      expect(mail.body.encoded).to include I18n.t('devise.mailer.reset_password_instructions.title')
       expect(mail.body.encoded).to include 'spec'
     end
 
@@ -65,7 +65,7 @@ describe UserMailer, type: :mailer do
 
     it 'renders password change notification' do
       receiver.update!(locale: nil)
-      expect(mail.body.encoded).to include receiver.email
+      expect(mail.body.encoded).to include I18n.t('devise.mailer.password_change.title')
     end
 
     include_examples 'localized subject',
@@ -77,7 +77,7 @@ describe UserMailer, type: :mailer do
 
     it 'renders email change notification' do
       receiver.update!(locale: nil)
-      expect(mail.body.encoded).to include receiver.email
+      expect(mail.body.encoded).to include I18n.t('devise.mailer.email_changed.title')
     end
 
     include_examples 'localized subject',
diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb
index bb7601e76..1435ec917 100644
--- a/spec/services/notify_service_spec.rb
+++ b/spec/services/notify_service_spec.rb
@@ -82,10 +82,19 @@ RSpec.describe NotifyService do
         is_expected.to_not change(Notification, :count)
       end
 
-      context 'if the message chain initiated by recipient' do
+      context 'if the message chain initiated by recipient, but is not direct message' do
         let(:reply_to) { Fabricate(:status, account: recipient) }
         let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
 
+        it 'does not notify' do
+          is_expected.to_not change(Notification, :count)
+        end
+      end
+
+      context 'if the message chain initiated by recipient and is direct message' do
+        let(:reply_to) { Fabricate(:status, account: recipient, visibility: :direct) }
+        let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
+
         it 'does notify' do
           is_expected.to change(Notification, :count)
         end