diff --git a/app/models/post.rb b/app/models/post.rb index 9fd75b7ad..58e7079d3 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -20,6 +20,7 @@ class Post < ApplicationRecord before_validation :remove_parent_loops validates_uniqueness_of :md5, :on => :create, message: ->(obj, data) { "duplicate: #{Post.find_by_md5(obj.md5).id}"} validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e" + validates :source, length: { maximum: 1200 } validate :added_tags_are_valid validate :removed_tags_are_valid validate :has_artist_tag diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index ee470de05..c2fa690fa 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -1076,6 +1076,13 @@ class PostTest < ActiveSupport::TestCase @post.update(:tag_string => "source:https://img18.pixiv.net/img/evazion/14901720.png") assert_equal(14901720, @post.pixiv_id) end + + should "validate the max source length" do + @post.update(source: "X"*1201) + + assert_equal(false, @post.valid?) + assert_equal(["is too long (maximum is 1200 characters)"], @post.errors[:source]) + end end context "of" do