about summary refs log tree commit diff
path: root/spec/services
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/activitypub/fetch_remote_status_service_spec.rb2
-rw-r--r--spec/services/after_block_service_spec.rb4
-rw-r--r--spec/services/batched_remove_status_service_spec.rb4
-rw-r--r--spec/services/fan_out_on_write_service_spec.rb4
-rw-r--r--spec/services/follow_service_spec.rb58
-rw-r--r--spec/services/mute_service_spec.rb36
-rw-r--r--spec/services/notify_service_spec.rb63
-rw-r--r--spec/services/remove_status_service_spec.rb4
8 files changed, 161 insertions, 14 deletions
diff --git a/spec/services/activitypub/fetch_remote_status_service_spec.rb b/spec/services/activitypub/fetch_remote_status_service_spec.rb
index ebf422392..51f3fe3a1 100644
--- a/spec/services/activitypub/fetch_remote_status_service_spec.rb
+++ b/spec/services/activitypub/fetch_remote_status_service_spec.rb
@@ -27,7 +27,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService do
 
       it 'creates status' do
         status = sender.statuses.first
-        
+
         expect(status).to_not be_nil
         expect(status.text).to eq 'Lorem ipsum'
       end
diff --git a/spec/services/after_block_service_spec.rb b/spec/services/after_block_service_spec.rb
index 65f36c7d1..1b115c938 100644
--- a/spec/services/after_block_service_spec.rb
+++ b/spec/services/after_block_service_spec.rb
@@ -18,8 +18,8 @@ RSpec.describe AfterBlockService do
     end
 
     it "clears account's statuses" do
-      FeedManager.instance.push(:home, account, status)
-      FeedManager.instance.push(:home, account, other_account_status)
+      FeedManager.instance.push_to_home(account, status)
+      FeedManager.instance.push_to_home(account, other_account_status)
 
       is_expected.to change {
         Redis.current.zrange(home_timeline_key, 0, -1)
diff --git a/spec/services/batched_remove_status_service_spec.rb b/spec/services/batched_remove_status_service_spec.rb
index c82c45e09..437da2a9d 100644
--- a/spec/services/batched_remove_status_service_spec.rb
+++ b/spec/services/batched_remove_status_service_spec.rb
@@ -30,11 +30,11 @@ RSpec.describe BatchedRemoveStatusService do
   end
 
   it 'removes statuses from author\'s home feed' do
-    expect(Feed.new(:home, alice).get(10)).to_not include([status1.id, status2.id])
+    expect(HomeFeed.new(alice).get(10)).to_not include([status1.id, status2.id])
   end
 
   it 'removes statuses from local follower\'s home feed' do
-    expect(Feed.new(:home, jeff).get(10)).to_not include([status1.id, status2.id])
+    expect(HomeFeed.new(jeff).get(10)).to_not include([status1.id, status2.id])
   end
 
   it 'notifies streaming API of followers' do
diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb
index 6ee225c4c..764318e34 100644
--- a/spec/services/fan_out_on_write_service_spec.rb
+++ b/spec/services/fan_out_on_write_service_spec.rb
@@ -19,12 +19,12 @@ RSpec.describe FanOutOnWriteService do
   end
 
   it 'delivers status to home timeline' do
-    expect(Feed.new(:home, author).get(10).map(&:id)).to include status.id
+    expect(HomeFeed.new(author).get(10).map(&:id)).to include status.id
   end
 
   it 'delivers status to local followers' do
     pending 'some sort of problem in test environment causes this to sometimes fail'
-    expect(Feed.new(:home, follower).get(10).map(&:id)).to include status.id
+    expect(HomeFeed.new(follower).get(10).map(&:id)).to include status.id
   end
 
   it 'delivers status to hashtag' do
diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb
index ceb39e5e6..e59a2f1a6 100644
--- a/spec/services/follow_service_spec.rb
+++ b/spec/services/follow_service_spec.rb
@@ -13,8 +13,20 @@ RSpec.describe FollowService do
         subject.call(sender, bob.acct)
       end
 
-      it 'creates a follow request' do
-        expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
+      it 'creates a follow request with reblogs' do
+        expect(FollowRequest.find_by(account: sender, target_account: bob, show_reblogs: true)).to_not be_nil
+      end
+    end
+
+    describe 'locked account, no reblogs' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account }
+
+      before do
+        subject.call(sender, bob.acct, reblogs: false)
+      end
+
+      it 'creates a follow request without reblogs' do
+        expect(FollowRequest.find_by(account: sender, target_account: bob, show_reblogs: false)).to_not be_nil
       end
     end
 
@@ -25,8 +37,22 @@ RSpec.describe FollowService do
         subject.call(sender, bob.acct)
       end
 
-      it 'creates a following relation' do
+      it 'creates a following relation with reblogs' do
+        expect(sender.following?(bob)).to be true
+        expect(sender.muting_reblogs?(bob)).to be false
+      end
+    end
+
+    describe 'unlocked account, no reblogs' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+      before do
+        subject.call(sender, bob.acct, reblogs: false)
+      end
+
+      it 'creates a following relation without reblogs' do
         expect(sender.following?(bob)).to be true
+        expect(sender.muting_reblogs?(bob)).to be true
       end
     end
 
@@ -42,6 +68,32 @@ RSpec.describe FollowService do
         expect(sender.following?(bob)).to be true
       end
     end
+
+    describe 'already followed account, turning reblogs off' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+      before do
+        sender.follow!(bob, reblogs: true)
+        subject.call(sender, bob.acct, reblogs: false)
+      end
+
+      it 'disables reblogs' do
+        expect(sender.muting_reblogs?(bob)).to be true
+      end
+    end
+
+    describe 'already followed account, turning reblogs on' do
+      let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+      before do
+        sender.follow!(bob, reblogs: false)
+        subject.call(sender, bob.acct, reblogs: true)
+      end
+
+      it 'disables reblogs' do
+        expect(sender.muting_reblogs?(bob)).to be false
+      end
+    end
   end
 
   context 'remote OStatus account' do
diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb
index 8097cb250..2b3e3e152 100644
--- a/spec/services/mute_service_spec.rb
+++ b/spec/services/mute_service_spec.rb
@@ -18,8 +18,8 @@ RSpec.describe MuteService do
     end
 
     it "clears account's statuses" do
-      FeedManager.instance.push(:home, account, status)
-      FeedManager.instance.push(:home, account, other_account_status)
+      FeedManager.instance.push_to_home(account, status)
+      FeedManager.instance.push_to_home(account, other_account_status)
 
       is_expected.to change {
         Redis.current.zrange(home_timeline_key, 0, -1)
@@ -32,4 +32,36 @@ RSpec.describe MuteService do
       account.muting?(target_account)
     }.from(false).to(true)
   end
+
+  context 'without specifying a notifications parameter' do
+    it 'mutes notifications from the account' do
+      is_expected.to change {
+        account.muting_notifications?(target_account)
+      }.from(false).to(true)
+    end
+  end
+
+  context 'with a true notifications parameter' do
+    subject do
+      -> { described_class.new.call(account, target_account, notifications: true) }
+    end
+
+    it 'mutes notifications from the account' do
+      is_expected.to change {
+        account.muting_notifications?(target_account)
+      }.from(false).to(true)
+    end
+  end
+
+  context 'with a false notifications parameter' do
+    subject do
+      -> { described_class.new.call(account, target_account, notifications: false) }
+    end
+
+    it 'does not mute notifications from the account' do
+      is_expected.to_not change {
+        account.muting_notifications?(target_account)
+      }.from(false)
+    end
+  end
 end
diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb
index 7a66bd0fe..a8ebc16b8 100644
--- a/spec/services/notify_service_spec.rb
+++ b/spec/services/notify_service_spec.rb
@@ -17,6 +17,16 @@ RSpec.describe NotifyService do
     is_expected.to_not change(Notification, :count)
   end
 
+  it 'does not notify when sender is muted with hide_notifications' do
+    recipient.mute!(sender, notifications: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does notify when sender is muted without hide_notifications' do
+    recipient.mute!(sender, notifications: false)
+    is_expected.to change(Notification, :count)
+  end
+
   it 'does not notify when sender\'s domain is blocked' do
     recipient.block_domain!(sender.domain)
     is_expected.to_not change(Notification, :count)
@@ -38,6 +48,59 @@ RSpec.describe NotifyService do
     is_expected.to_not change(Notification, :count)
   end
 
+  describe 'reblogs' do
+    let(:status)   { Fabricate(:status, account: Fabricate(:account)) }
+    let(:activity) { Fabricate(:status, account: sender, reblog: status) }
+
+    it 'shows reblogs by default' do
+      recipient.follow!(sender)
+      is_expected.to change(Notification, :count)
+    end
+
+    it 'shows reblogs when explicitly enabled' do
+      recipient.follow!(sender, reblogs: true)
+      is_expected.to change(Notification, :count)
+    end
+
+    it 'hides reblogs when disabled' do
+      recipient.follow!(sender, reblogs: false)
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+  
+  context 'for direct messages' do
+    let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct)) }
+
+    before do
+      user.settings.interactions = user.settings.interactions.merge('must_be_following_dm' => enabled)
+    end
+
+    context 'if recipient is supposed to be following sender' do
+      let(:enabled) { true }
+
+      it 'does not notify' do
+        is_expected.to_not change(Notification, :count)
+      end
+
+      context 'if the message chain initiated by recipient' 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 notify' do
+          is_expected.to change(Notification, :count)
+        end
+      end
+    end
+
+    context 'if recipient is NOT supposed to be following sender' do
+      let(:enabled) { false }
+
+      it 'does notify' do
+        is_expected.to change(Notification, :count)
+      end
+    end
+  end
+
   context do
     let(:asshole)  { Fabricate(:account, username: 'asshole') }
     let(:reply_to) { Fabricate(:status, account: asshole) }
diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb
index b60015928..5bb75b820 100644
--- a/spec/services/remove_status_service_spec.rb
+++ b/spec/services/remove_status_service_spec.rb
@@ -25,11 +25,11 @@ RSpec.describe RemoveStatusService do
   end
 
   it 'removes status from author\'s home feed' do
-    expect(Feed.new(:home, alice).get(10)).to_not include(@status.id)
+    expect(HomeFeed.new(alice).get(10)).to_not include(@status.id)
   end
 
   it 'removes status from local follower\'s home feed' do
-    expect(Feed.new(:home, jeff).get(10)).to_not include(@status.id)
+    expect(HomeFeed.new(jeff).get(10)).to_not include(@status.id)
   end
 
   it 'sends PuSH update to PuSH subscribers' do