diff --git a/app/models/note.rb b/app/models/note.rb index 0f0e1cff7..e8348312e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -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 diff --git a/test/unit/note_test.rb b/test/unit/note_test.rb index dd995a5ed..5cda32308 100644 --- a/test/unit/note_test.rb +++ b/test/unit/note_test.rb @@ -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)