Don't save mute notes if the note is blank (#193)

This commit is contained in:
David Yip 2018-01-25 22:42:19 -06:00
parent 27f8d2c739
commit 1704e0066a
No known key found for this signature in database
GPG Key ID: 7DA0036508FCC0CC
3 changed files with 17 additions and 1 deletions

View File

@ -13,5 +13,7 @@
class Glitch::Note < ApplicationRecord
belongs_to :target, polymorphic: true
validates :note, presence: true
alias_attribute :text, :note
end

View File

@ -6,7 +6,7 @@ class MuteService < BaseService
ActiveRecord::Base.transaction do
mute = account.mute!(target_account, notifications: notifications)
mute.create_note!(note: note) if note
mute.create_note!(note: note) if !note.blank?
BlockWorker.perform_async(account.id, target_account.id)
mute
end

View File

@ -64,4 +64,18 @@ RSpec.describe MuteService do
}.from(false)
end
end
context 'with a note string' do
it 'adds a note to the mute' do
mute = described_class.new.call(account, target_account, note: 'Too many jorts')
note = mute.note
expect(note.text).to eq('Too many jorts')
end
it 'does not add a note if the note is blank' do
mute = described_class.new.call(account, target_account, note: ' ')
note = mute.note
expect(note).to be_nil
end
end
end