about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-15 03:04:13 +0200
committerGitHub <noreply@github.com>2017-05-15 03:04:13 +0200
commitd0dd9eb5b5d2c0d80a756a6e432b5d502ed0e0fc (patch)
tree74845d93fd7bf5d85db9489b2f2c23e5989314e0 /spec
parenta588358f41f36b2df1dcc4bb2c3df6c54ed52f88 (diff)
Feature conversations muting (#3017)
* Add <ostatus:conversation /> tag to Atom input/output

Only uses ref attribute (not href) because href would be
the alternate link that's always included also.

Creates new conversation for every non-reply status. Carries
over conversation for every reply. Keeps remote URIs verbatim,
generates local URIs on the fly like the rest of them.

* Conversation muting - prevents notifications that reference a conversation
(including replies, favourites, reblogs) from being created. API endpoints
/api/v1/statuses/:id/mute and /api/v1/statuses/:id/unmute

Currently no way to tell when a status/conversation is muted, so the web UI
only has a "disable notifications" button, doesn't work as a toggle

* Display "Dismiss notifications" on all statuses in notifications column, not just own

* Add "muted" as a boolean attribute on statuses JSON

For now always false on contained reblogs, since it's only relevant for
statuses returned from the notifications endpoint, which are not nested

Remove "Disable notifications" from detailed status view, since it's
only relevant in the notifications column

* Up max class length

* Remove pending test for conversation mute

* Add tests, clean up

* Rename to "mute conversation" and "unmute conversation"

* Raise validation error when trying to mute/unmute status without conversation
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/statuses_controller_spec.rb33
-rw-r--r--spec/fabricators/conversation_mute_fabricator.rb2
-rw-r--r--spec/models/conversation_mute_spec.rb5
-rw-r--r--spec/models/status_spec.rb48
-rw-r--r--spec/services/notify_service_spec.rb42
5 files changed, 129 insertions, 1 deletions
diff --git a/spec/controllers/api/v1/statuses_controller_spec.rb b/spec/controllers/api/v1/statuses_controller_spec.rb
index 74faed269..ac3b2dc7d 100644
--- a/spec/controllers/api/v1/statuses_controller_spec.rb
+++ b/spec/controllers/api/v1/statuses_controller_spec.rb
@@ -183,6 +183,39 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
         expect(user.account.favourited?(status)).to be false
       end
     end
+
+    describe 'POST #mute' do
+      let(:status) { Fabricate(:status, account: user.account) }
+
+      before do
+        post :mute, params: { id: status.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'creates a conversation mute' do
+        expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to_not be_nil
+      end
+    end
+
+    describe 'POST #unmute' do
+      let(:status) { Fabricate(:status, account: user.account) }
+
+      before do
+        post :mute,   params: { id: status.id }
+        post :unmute, params: { id: status.id }
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'destroys the conversation mute' do
+        expect(ConversationMute.find_by(account: user.account, conversation_id: status.conversation_id)).to be_nil
+      end
+    end
   end
 
   context 'without an oauth token' do
diff --git a/spec/fabricators/conversation_mute_fabricator.rb b/spec/fabricators/conversation_mute_fabricator.rb
new file mode 100644
index 000000000..84f131c26
--- /dev/null
+++ b/spec/fabricators/conversation_mute_fabricator.rb
@@ -0,0 +1,2 @@
+Fabricator(:conversation_mute) do
+end
diff --git a/spec/models/conversation_mute_spec.rb b/spec/models/conversation_mute_spec.rb
new file mode 100644
index 000000000..b602e80c1
--- /dev/null
+++ b/spec/models/conversation_mute_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ConversationMute, type: :model do
+
+end
diff --git a/spec/models/status_spec.rb b/spec/models/status_spec.rb
index f9f5c1603..d280525fc 100644
--- a/spec/models/status_spec.rb
+++ b/spec/models/status_spec.rb
@@ -196,6 +196,54 @@ RSpec.describe Status, type: :model do
     pending
   end
 
+  describe '.mutes_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.mutes_map([status.conversation.id], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      account.mute_conversation!(status.conversation)
+      expect(subject[status.conversation.id]).to be true
+    end
+  end
+
+  describe '.favourites_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.favourites_map([status], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      Fabricate(:favourite, status: status, account: account)
+      expect(subject[status.id]).to be true
+    end
+  end
+
+  describe '.reblogs_map' do
+    let(:status)  { Fabricate(:status) }
+    let(:account) { Fabricate(:account) }
+
+    subject { Status.reblogs_map([status], account) }
+
+    it 'returns a hash' do
+      expect(subject).to be_a Hash
+    end
+
+    it 'contains true value' do
+      Fabricate(:status, account: account, reblog: status)
+      expect(subject[status.id]).to be true
+    end
+  end
+
   describe '.local_only' do
     it 'returns only statuses from local accounts' do
       local_account = Fabricate(:account, domain: nil)
diff --git a/spec/services/notify_service_spec.rb b/spec/services/notify_service_spec.rb
index 86848e1ff..032c37a28 100644
--- a/spec/services/notify_service_spec.rb
+++ b/spec/services/notify_service_spec.rb
@@ -7,10 +7,50 @@ RSpec.describe NotifyService do
 
   let(:user) { Fabricate(:user) }
   let(:recipient) { user.account }
-  let(:activity) { Fabricate(:follow, target_account: recipient) }
+  let(:sender) { Fabricate(:account) }
+  let(:activity) { Fabricate(:follow, account: sender, target_account: recipient) }
 
   it { is_expected.to change(Notification, :count).by(1) }
 
+  it 'does not notify when sender is blocked' do
+    recipient.block!(sender)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does not notify when sender is silenced and not followed' do
+    sender.update(silenced: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  it 'does not notify when recipient is suspended' do
+    recipient.update(suspended: true)
+    is_expected.to_not change(Notification, :count)
+  end
+
+  context do
+    let(:asshole)  { Fabricate(:account, username: 'asshole') }
+    let(:reply_to) { Fabricate(:status, account: asshole) }
+    let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, thread: reply_to)) }
+
+    it 'does not notify when conversation is muted' do
+      recipient.mute_conversation!(activity.status.conversation)
+      is_expected.to_not change(Notification, :count)
+    end
+
+    it 'does not notify when it is a reply to a blocked user' do
+      recipient.block!(asshole)
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+
+  context do
+    let(:sender) { recipient }
+
+    it 'does not notify when recipient is the sender' do
+      is_expected.to_not change(Notification, :count)
+    end
+  end
+
   describe 'email' do
     before do
       ActionMailer::Base.deliveries.clear