posts: limit sources to 1200 chars long.

The longest sources on Danbooru are DeviantArt wixmp.com sources, which
max out at ~900 chars.
This commit is contained in:
evazion
2020-12-21 18:57:04 -06:00
parent 6ac9882711
commit 6c99bbbf47
2 changed files with 8 additions and 0 deletions

View File

@@ -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

View File

@@ -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