@ -1,9 +1,7 @@
require 'rails_helper'
require 'rails_helper'
RSpec . describe NotifyService , type : :service do
RSpec . describe NotifyService , type : :service do
subject do
subject { described_class . new . call ( recipient , type , activity ) }
- > { described_class . new . call ( recipient , type , activity ) }
end
let ( :user ) { Fabricate ( :user ) }
let ( :user ) { Fabricate ( :user ) }
let ( :recipient ) { user . account }
let ( :recipient ) { user . account }
@ -11,42 +9,42 @@ RSpec.describe NotifyService, type: :service do
let ( :activity ) { Fabricate ( :follow , account : sender , target_account : recipient ) }
let ( :activity ) { Fabricate ( :follow , account : sender , target_account : recipient ) }
let ( :type ) { :follow }
let ( :type ) { :follow }
it { is_expected . to change ( Notification , :count ) . by ( 1 ) }
it { expect { subject } . to change ( Notification , :count ) . by ( 1 ) }
it 'does not notify when sender is blocked' do
it 'does not notify when sender is blocked' do
recipient . block! ( sender )
recipient . block! ( sender )
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
it 'does not notify when sender is muted with hide_notifications' do
it 'does not notify when sender is muted with hide_notifications' do
recipient . mute! ( sender , notifications : true )
recipient . mute! ( sender , notifications : true )
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
it 'does notify when sender is muted without hide_notifications' do
it 'does notify when sender is muted without hide_notifications' do
recipient . mute! ( sender , notifications : false )
recipient . mute! ( sender , notifications : false )
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
it 'does not notify when sender\'s domain is blocked' do
it 'does not notify when sender\'s domain is blocked' do
recipient . block_domain! ( sender . domain )
recipient . block_domain! ( sender . domain )
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
it 'does still notify when sender\'s domain is blocked but sender is followed' do
it 'does still notify when sender\'s domain is blocked but sender is followed' do
recipient . block_domain! ( sender . domain )
recipient . block_domain! ( sender . domain )
recipient . follow! ( sender )
recipient . follow! ( sender )
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
it 'does not notify when sender is silenced and not followed' do
it 'does not notify when sender is silenced and not followed' do
sender . silence!
sender . silence!
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
it 'does not notify when recipient is suspended' do
it 'does not notify when recipient is suspended' do
recipient . suspend!
recipient . suspend!
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
context 'for direct messages' do
context 'for direct messages' do
@ -61,7 +59,7 @@ RSpec.describe NotifyService, type: :service do
let ( :enabled ) { true }
let ( :enabled ) { true }
it 'does not notify' do
it 'does not notify' do
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
context 'if the message chain is initiated by recipient, but is not direct message' do
context 'if the message chain is initiated by recipient, but is not direct message' do
@ -70,7 +68,7 @@ RSpec.describe NotifyService, type: :service do
let ( :activity ) { Fabricate ( :mention , account : recipient , status : Fabricate ( :status , account : sender , visibility : :direct , thread : reply_to ) ) }
let ( :activity ) { Fabricate ( :mention , account : recipient , status : Fabricate ( :status , account : sender , visibility : :direct , thread : reply_to ) ) }
it 'does not notify' do
it 'does not notify' do
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
end
end
@ -81,7 +79,7 @@ RSpec.describe NotifyService, type: :service do
let ( :activity ) { Fabricate ( :mention , account : recipient , status : Fabricate ( :status , account : sender , visibility : :direct , thread : dummy_reply ) ) }
let ( :activity ) { Fabricate ( :mention , account : recipient , status : Fabricate ( :status , account : sender , visibility : :direct , thread : dummy_reply ) ) }
it 'does not notify' do
it 'does not notify' do
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
end
end
@ -91,7 +89,7 @@ RSpec.describe NotifyService, type: :service do
let ( :activity ) { Fabricate ( :mention , account : recipient , status : Fabricate ( :status , account : sender , visibility : :direct , thread : reply_to ) ) }
let ( :activity ) { Fabricate ( :mention , account : recipient , status : Fabricate ( :status , account : sender , visibility : :direct , thread : reply_to ) ) }
it 'does notify' do
it 'does notify' do
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
end
end
end
end
@ -100,7 +98,7 @@ RSpec.describe NotifyService, type: :service do
let ( :enabled ) { false }
let ( :enabled ) { false }
it 'does notify' do
it 'does notify' do
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
end
end
end
end
@ -112,17 +110,17 @@ RSpec.describe NotifyService, type: :service do
it 'shows reblogs by default' do
it 'shows reblogs by default' do
recipient . follow! ( sender )
recipient . follow! ( sender )
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
it 'shows reblogs when explicitly enabled' do
it 'shows reblogs when explicitly enabled' do
recipient . follow! ( sender , reblogs : true )
recipient . follow! ( sender , reblogs : true )
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
it 'shows reblogs when disabled' do
it 'shows reblogs when disabled' do
recipient . follow! ( sender , reblogs : false )
recipient . follow! ( sender , reblogs : false )
is_expected . to change ( Notification , :count )
expect { subject } . to change ( Notification , :count )
end
end
end
end
@ -134,12 +132,12 @@ RSpec.describe NotifyService, type: :service do
it 'does not notify when conversation is muted' do
it 'does not notify when conversation is muted' do
recipient . mute_conversation! ( activity . status . conversation )
recipient . mute_conversation! ( activity . status . conversation )
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
it 'does not notify when it is a reply to a blocked user' do
it 'does not notify when it is a reply to a blocked user' do
recipient . block! ( asshole )
recipient . block! ( asshole )
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
end
end
@ -147,7 +145,7 @@ RSpec.describe NotifyService, type: :service do
let ( :sender ) { recipient }
let ( :sender ) { recipient }
it 'does not notify when recipient is the sender' do
it 'does not notify when recipient is the sender' do
is_expected . to_not change ( Notification , :count )
expect { subject } . to_not change ( Notification , :count )
end
end
end
end
@ -163,7 +161,7 @@ RSpec.describe NotifyService, type: :service do
let ( :enabled ) { true }
let ( :enabled ) { true }
it 'sends email' do
it 'sends email' do
is_expected . to change ( ActionMailer :: Base . deliveries , :count ) . by ( 1 )
expect { subject } . to change ( ActionMailer :: Base . deliveries , :count ) . by ( 1 )
end
end
end
end
@ -171,7 +169,7 @@ RSpec.describe NotifyService, type: :service do
let ( :enabled ) { false }
let ( :enabled ) { false }
it " doesn't send email " do
it " doesn't send email " do
is_expected . to_not change ( ActionMailer :: Base . deliveries , :count ) . from ( 0 )
expect { subject } . to_not change ( ActionMailer :: Base . deliveries , :count ) . from ( 0 )
end
end
end
end
end
end