Slide 81
Slide 81 text
Caleb Hearth dice.club/@caleb calebhearth.com Test Double
describe '#mute!' do
end
context 'Mute does not exist yet' do
it 'returns a Mute' do
expect(account.mute!(target_account))
.to be_kind_of Mute
end
it 'creates a Mute when :notifications is nil' do
expect do
account.mute!(target_account, notifications: nil)
end.to change { account.mute_relationships.count }.by 1
end
it 'creates a Mute when :notifications is false' do
expect do
account.mute!(target_account, notifications: false)
end.to change { account.mute_relationships.count }.by 1
end
it 'creates a Mute when :notifications is true' do
expect do
account.mute!(target_account, notifications: true)
end.to change { account.mute_relationships.count }.by 1
end
end
context 'Mute already exists' do
context 'mute.hide_notifications is true' do
it 'does not update mute.hide_notifications when :notifications is nil' do
mute = Fabricate :mute,
account: account,
target_account: target_account,
hide_notifications: true
account.mute_relationships << mute
expect do
account.mute!(target_account, notifications: nil)
end.not_to change { mute.reload.hide_notifications? }.from(true)
end
it 'updates mute.hide_notifications false when :notifications is false' do
mute = Fabricate :mute,
account: account,
target_account: target_account,
hide_notifications: true
account.mute_relationships << mute
expect do
account.mute!(target_account, notifications: false)
end.to change { mute.reload.hide_notifications? }.from(true).to(false)
end
it 'doesnt update mute.hide_notifications false when :notifications=true' do
mute = Fabricate :mute,
account: account,
target_account: target_account,
hide_notifications: true
account.mute_relationships << mute
expect do
account.mute!(target_account, notifications: true)
end.not_to change { mute.reload.hide_notifications? }.from(true)
end
end
context 'mute.hide_notifications is false' do
it 'updates mute.hide_notifications true when arg :notifications is nil' do
mute = Fabricate :mute,
account: account,
target_account: target_account,
hide_notifications: false
account.mute_relationships << mute
expect do
account.mute!(target_account, notifications: nil)
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
end
it 'doesnt update mute.hide_notifications when arg :notifications is false' do
mute = Fabricate :mute,
account: account,
target_account: target_account,
hide_notifications: false
account.mute_relationships << mute
expect do
account.mute!(target_account, notifications: false)
end.not_to change { mute.reload.hide_notifications? }.from(false)
end
it 'updates mute.hide_notifications true when arg :notifications is true' do
mute = Fabricate :mute,
account: account,
target_account: target_account,
hide_notifications: false
account.mute_relationships << mute
expect do
account.mute!(target_account, notifications: true)
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
end
end
end