about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/accounts/credentials_controller_spec.rb4
-rw-r--r--spec/controllers/api/v1/accounts_controller_spec.rb29
-rw-r--r--spec/controllers/api/v1/mutes_controller_spec.rb22
-rw-r--r--spec/lib/feed_manager_spec.rb7
-rw-r--r--spec/models/account_spec.rb8
-rw-r--r--spec/models/concerns/account_interactions_spec.rb40
-rw-r--r--spec/services/mute_service_spec.rb32
-rw-r--r--spec/services/notify_service_spec.rb10
-rw-r--r--spec/validators/status_length_validator_spec.rb23
-rw-r--r--spec/views/about/show.html.haml_spec.rb6
10 files changed, 166 insertions, 15 deletions
diff --git a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
index 461b8b34b..247420d08 100644
--- a/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts/credentials_controller_spec.rb
@@ -51,7 +51,9 @@ describe Api::V1::Accounts::CredentialsController do
 
       describe 'with invalid data' do
         before do
-          patch :update, params: { note: 'This is too long. ' * 10 }
+          note = 'This is too long. '
+          note = note + 'a' * (Account::MAX_NOTE_LENGTH - note.length + 1)
+          patch :update, params: { note: note }
         end
 
         it 'returns http unprocessable entity' do
diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb
index c770649ec..053c53e5a 100644
--- a/spec/controllers/api/v1/accounts_controller_spec.rb
+++ b/spec/controllers/api/v1/accounts_controller_spec.rb
@@ -137,6 +137,35 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
     it 'creates a muting relation' do
       expect(user.account.muting?(other_account)).to be true
     end
+
+    it 'mutes notifications' do
+      expect(user.account.muting_notifications?(other_account)).to be true
+    end
+  end
+
+  describe 'POST #mute with notifications set to false' do
+    let(:other_account) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
+
+    before do
+      user.account.follow!(other_account)
+      post :mute, params: {id: other_account.id, notifications: false }
+    end
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'does not remove the following relation between user and target user' do
+      expect(user.account.following?(other_account)).to be true
+    end
+
+    it 'creates a muting relation' do
+      expect(user.account.muting?(other_account)).to be true
+    end
+
+    it 'does not mute notifications' do
+      expect(user.account.muting_notifications?(other_account)).to be false
+    end
   end
 
   describe 'POST #unmute' do
diff --git a/spec/controllers/api/v1/mutes_controller_spec.rb b/spec/controllers/api/v1/mutes_controller_spec.rb
index 3e6fa887b..7387b9d2d 100644
--- a/spec/controllers/api/v1/mutes_controller_spec.rb
+++ b/spec/controllers/api/v1/mutes_controller_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Api::V1::MutesController, type: :controller do
   let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
 
   before do
-    Fabricate(:mute, account: user.account)
+    Fabricate(:mute, account: user.account, hide_notifications: false)
     allow(controller).to receive(:doorkeeper_token) { token }
   end
 
@@ -18,4 +18,24 @@ RSpec.describe Api::V1::MutesController, type: :controller do
       expect(response).to have_http_status(:success)
     end
   end
+
+  describe 'GET #details' do
+    before do
+      get :details, params: { limit: 1 }
+    end
+
+    let(:mutes) { JSON.parse(response.body) }
+
+    it 'returns http success' do
+      expect(response).to have_http_status(:success)
+    end
+
+    it 'returns one mute' do
+      expect(mutes.size).to be(1)
+    end
+
+    it 'returns whether the mute hides notifications' do
+      expect(mutes.first["hide_notifications"]).to be(false)
+    end 
+  end
 end
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb
index 0f97a579e..1861cc6ed 100644
--- a/spec/lib/feed_manager_spec.rb
+++ b/spec/lib/feed_manager_spec.rb
@@ -105,6 +105,13 @@ RSpec.describe FeedManager do
         expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true
       end
 
+      it 'returns true for status by followee mentioning muted account' do
+        bob.mute!(jeff)
+        bob.follow!(alice)
+        status = PostStatusService.new.call(alice, 'Hey @jeff')
+        expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true
+      end
+
       it 'returns true for reblog of a personally blocked domain' do
         alice.block_domain!('example.com')
         alice.follow!(jeff)
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index aef0c3082..361577eff 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -558,8 +558,8 @@ RSpec.describe Account, type: :model do
         expect(account).to model_have_error_on_field(:display_name)
       end
 
-      it 'is invalid if the note is longer than 160 characters' do
-        account = Fabricate.build(:account, note: Faker::Lorem.characters(161))
+      it 'is invalid if the note is longer than 500 characters' do
+        account = Fabricate.build(:account, note: Faker::Lorem.characters(501))
         account.valid?
         expect(account).to model_have_error_on_field(:note)
       end
@@ -598,8 +598,8 @@ RSpec.describe Account, type: :model do
         expect(account).not_to model_have_error_on_field(:display_name)
       end
 
-      it 'is valid even if the note is longer than 160 characters' do
-        account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(161))
+      it 'is valid even if the note is longer than 500 characters' do
+        account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(501))
         account.valid?
         expect(account).not_to model_have_error_on_field(:note)
       end
diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account_interactions_spec.rb
new file mode 100644
index 000000000..ef957fc1d
--- /dev/null
+++ b/spec/models/concerns/account_interactions_spec.rb
@@ -0,0 +1,40 @@
+require 'rails_helper'
+
+describe AccountInteractions do
+  describe 'muting an account' do
+    before do
+      @me = Fabricate(:account, username: 'Me')
+      @you = Fabricate(:account, username: 'You')
+    end
+
+    context 'with the notifications option unspecified' do
+      before do
+        @me.mute!(@you)
+      end
+
+      it 'defaults to muting notifications' do
+        expect(@me.muting_notifications?(@you)).to be(true)
+      end
+    end
+
+    context 'with the notifications option set to false' do
+      before do
+        @me.mute!(@you, notifications: false)
+      end
+
+      it 'does not mute notifications' do
+        expect(@me.muting_notifications?(@you)).to be(false)
+      end
+    end
+
+    context 'with the notifications option set to true' do
+      before do
+        @me.mute!(@you, notifications: true)
+      end
+
+      it 'does mute notifications' do
+        expect(@me.muting_notifications?(@you)).to be(true)
+      end
+    end
+  end
+end
diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb
index 8097cb250..800140b6f 100644
--- a/spec/services/mute_service_spec.rb
+++ b/spec/services/mute_service_spec.rb
@@ -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..7088ae9d1 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)
diff --git a/spec/validators/status_length_validator_spec.rb b/spec/validators/status_length_validator_spec.rb
index e2d1a15ec..9355c7e3f 100644
--- a/spec/validators/status_length_validator_spec.rb
+++ b/spec/validators/status_length_validator_spec.rb
@@ -7,26 +7,31 @@ describe StatusLengthValidator do
     it 'does not add errors onto remote statuses'
     it 'does not add errors onto local reblogs'
 
-    it 'adds an error when content warning is over 500 characters' do
-      status = double(spoiler_text: 'a' * 520, text: '', errors: double(add: nil), local?: true, reblog?: false)
+    it 'adds an error when content warning is over MAX_CHARS characters' do
+      chars = StatusLengthValidator::MAX_CHARS + 1
+      status = double(spoiler_text: 'a' * chars, text: '', errors: double(add: nil), local?: true, reblog?: false)
       subject.validate(status)
       expect(status.errors).to have_received(:add)
     end
 
-    it 'adds an error when text is over 500 characters' do
-      status = double(spoiler_text: '', text: 'a' * 520, errors: double(add: nil), local?: true, reblog?: false)
+    it 'adds an error when text is over MAX_CHARS characters' do
+      chars = StatusLengthValidator::MAX_CHARS + 1
+      status = double(spoiler_text: '', text: 'a' * chars, errors: double(add: nil), local?: true, reblog?: false)
       subject.validate(status)
       expect(status.errors).to have_received(:add)
     end
 
-    it 'adds an error when text and content warning are over 500 characters total' do
-      status = double(spoiler_text: 'a' * 250, text: 'b' * 251, errors: double(add: nil), local?: true, reblog?: false)
+    it 'adds an error when text and content warning are over MAX_CHARS characters total' do
+      chars1 = 20
+      chars2 = StatusLengthValidator::MAX_CHARS + 1 - chars1
+      status = double(spoiler_text: 'a' * chars1, text: 'b' * chars2, errors: double(add: nil), local?: true, reblog?: false)
       subject.validate(status)
       expect(status.errors).to have_received(:add)
     end
 
     it 'counts URLs as 23 characters flat' do
-      text   = ('a' * 476) + " http://#{'b' * 30}.com/example"
+      chars = StatusLengthValidator::MAX_CHARS - 1 - 23
+      text   = ('a' * chars) + " http://#{'b' * 30}.com/example"
       status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
 
       subject.validate(status)
@@ -34,7 +39,9 @@ describe StatusLengthValidator do
     end
 
     it 'counts only the front part of remote usernames' do
-      text   = ('a' * 475) + " @alice@#{'b' * 30}.com"
+      username = '@alice'
+      chars = StatusLengthValidator::MAX_CHARS - 1 - username.length
+      text   = ('a' * 475) + " #{username}@#{'b' * 30}.com"
       status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
 
       subject.validate(status)
diff --git a/spec/views/about/show.html.haml_spec.rb b/spec/views/about/show.html.haml_spec.rb
index 724643cbc..ca59fa9e3 100644
--- a/spec/views/about/show.html.haml_spec.rb
+++ b/spec/views/about/show.html.haml_spec.rb
@@ -3,6 +3,8 @@
 require 'rails_helper'
 
 describe 'about/show.html.haml', without_verify_partial_doubles: true do
+  let(:commit_hash) { '8925731c9869f55780644304e4420a1998e52607' }
+
   before do
     allow(view).to receive(:site_hostname).and_return('example.com')
     allow(view).to receive(:site_title).and_return('example site')
@@ -16,7 +18,9 @@ describe 'about/show.html.haml', without_verify_partial_doubles: true do
                                 source_url: 'https://github.com/tootsuite/mastodon',
                                 open_registrations: false,
                                 thumbnail: nil,
-                                closed_registrations_message: 'yes')
+                                closed_registrations_message: 'yes',
+                                commit_hash: commit_hash)
+
     assign(:instance_presenter, instance_presenter)
     render