notes: clean up note-locked validation.
This commit is contained in:
@@ -8,7 +8,7 @@ class Note < ApplicationRecord
|
|||||||
validate :note_within_image
|
validate :note_within_image
|
||||||
after_save :update_post
|
after_save :update_post
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
validate :post_must_not_be_note_locked
|
validate :validate_post_is_not_locked
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def active
|
def active
|
||||||
@@ -27,10 +27,8 @@ class Note < ApplicationRecord
|
|||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
|
||||||
def post_must_not_be_note_locked
|
def validate_post_is_not_locked
|
||||||
if is_locked?
|
errors[:post] << "is note locked" if post.is_note_locked?
|
||||||
errors.add :post, "is note locked"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def note_within_image
|
def note_within_image
|
||||||
@@ -40,10 +38,6 @@ class Note < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_locked?
|
|
||||||
Post.exists?(["id = ? AND is_note_locked = ?", post_id, true])
|
|
||||||
end
|
|
||||||
|
|
||||||
def rescale!(x_scale, y_scale)
|
def rescale!(x_scale, y_scale)
|
||||||
self.x *= x_scale
|
self.x *= x_scale
|
||||||
self.y *= y_scale
|
self.y *= y_scale
|
||||||
|
|||||||
@@ -58,12 +58,6 @@ class NoteTest < ActiveSupport::TestCase
|
|||||||
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
|
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
|
||||||
end
|
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
|
should "not validate if the body is blank" do
|
||||||
@note = FactoryBot.build(:note, body: " ", :post => @post)
|
@note = FactoryBot.build(:note, body: " ", :post => @post)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user