From a3ecfdb79d0447c07e54b43a316f4c76bba4d590 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 28 Apr 2017 19:34:27 -0500 Subject: [PATCH] notes: disallow blank note bodies. --- app/models/note.rb | 7 +------ test/unit/note_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index 34dda61d0..06f4dd32f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -8,8 +8,7 @@ class Note < ActiveRecord::Base has_many :versions, lambda {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy before_validation :initialize_creator, :on => :create before_validation :initialize_updater - before_validation :blank_body - validates_presence_of :post_id, :creator_id, :updater_id, :x, :y, :width, :height + validates_presence_of :post_id, :creator_id, :updater_id, :x, :y, :width, :height, :body validate :post_must_exist validate :note_within_image after_save :update_post @@ -124,10 +123,6 @@ class Note < ActiveRecord::Base Post.exists?(["id = ? AND is_note_locked = ?", post_id, true]) end - def blank_body - self.body = "(empty)" if body.blank? - end - def creator_name User.id_to_name(creator_id).tr("_", " ") end diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index b4c597718..7b817f758 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -67,6 +67,13 @@ class NoteTest < ActiveSupport::TestCase assert_equal(["Post must exist"], @note.errors.full_messages) end + should "not validate if the body is blank" do + @note = FactoryGirl.build(:note, body: " ") + + assert_equal(false, @note.valid?) + assert_equal(["Body can't be blank"], @note.errors.full_messages) + end + should "create a version" do assert_difference("NoteVersion.count", 1) do Timecop.travel(1.day.from_now) do