notes: clean up note-locked validation.

This commit is contained in:
evazion
2020-02-16 23:19:49 -06:00
parent 7723597675
commit 9a8aa1990d
2 changed files with 3 additions and 15 deletions

View File

@@ -8,7 +8,7 @@ class Note < ApplicationRecord
validate :note_within_image
after_save :update_post
after_save :create_version
validate :post_must_not_be_note_locked
validate :validate_post_is_not_locked
module SearchMethods
def active
@@ -27,10 +27,8 @@ class Note < ApplicationRecord
extend SearchMethods
def post_must_not_be_note_locked
if is_locked?
errors.add :post, "is note locked"
end
def validate_post_is_not_locked
errors[:post] << "is note locked" if post.is_note_locked?
end
def note_within_image
@@ -40,10 +38,6 @@ class Note < ApplicationRecord
end
end
def is_locked?
Post.exists?(["id = ? AND is_note_locked = ?", post_id, true])
end
def rescale!(x_scale, y_scale)
self.x *= x_scale
self.y *= y_scale

View File

@@ -58,12 +58,6 @@ class NoteTest < ActiveSupport::TestCase
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
end
should "not validate if the post does not exist" do
@note = FactoryBot.build(:note, :x => 500, :y => 500, :post_id => -1)
@note.save
assert_equal(["Post must exist"], @note.errors.full_messages)
end
should "not validate if the body is blank" do
@note = FactoryBot.build(:note, body: " ", :post => @post)