From 1704e0066a491144e88b9b7bd243d5007c7a80cc Mon Sep 17 00:00:00 2001 From: David Yip Date: Thu, 25 Jan 2018 22:42:19 -0600 Subject: [PATCH] Don't save mute notes if the note is blank (#193) --- app/models/glitch/note.rb | 2 ++ app/services/mute_service.rb | 2 +- spec/services/mute_service_spec.rb | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/models/glitch/note.rb b/app/models/glitch/note.rb index 2950a75af9..0028b53a4e 100644 --- a/app/models/glitch/note.rb +++ b/app/models/glitch/note.rb @@ -13,5 +13,7 @@ class Glitch::Note < ApplicationRecord belongs_to :target, polymorphic: true + validates :note, presence: true + alias_attribute :text, :note end diff --git a/app/services/mute_service.rb b/app/services/mute_service.rb index 5b2462b01e..fdd2c7a6a0 100644 --- a/app/services/mute_service.rb +++ b/app/services/mute_service.rb @@ -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 diff --git a/spec/services/mute_service_spec.rb b/spec/services/mute_service_spec.rb index 2b3e3e152b..cca59e1e20 100644 --- a/spec/services/mute_service_spec.rb +++ b/spec/services/mute_service_spec.rb @@ -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