forked from e621ng/e621ng
[TagRelations] Require a reason on create
This commit is contained in:
parent
98ab543e59
commit
3187ee169b
@ -5,6 +5,7 @@ class TagRelationshipRequest
|
||||
|
||||
validate :validate_tag_relationship
|
||||
validate :validate_forum_topic
|
||||
validates :reason, length: { minimum: 5 }, unless: :skip_forum
|
||||
|
||||
def initialize(attributes)
|
||||
@antecedent_name = attributes[:antecedent_name].strip.tr(" ", "_")
|
||||
|
@ -14,7 +14,8 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
validate :forum_topic_id_not_invalid
|
||||
validate :validate_script, on: :create
|
||||
validate :check_validate_script, on: :update
|
||||
before_validation :initialize_attributes, :on => :create
|
||||
validates :reason, length: { minimum: 5 }, on: :create, unless: :skip_forum
|
||||
before_validation :initialize_attributes, on: :create
|
||||
before_validation :normalize_text
|
||||
after_create :create_forum_topic
|
||||
|
||||
|
@ -2,5 +2,6 @@ FactoryBot.define do
|
||||
factory(:bulk_update_request) do |f|
|
||||
title { "xxx" }
|
||||
script { "create alias aaa -> bbb" }
|
||||
reason { "xxxxx" }
|
||||
end
|
||||
end
|
||||
|
@ -17,7 +17,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "#create" do
|
||||
should "succeed" do
|
||||
assert_difference("BulkUpdateRequest.count", 1) do
|
||||
post_auth bulk_update_requests_path, @user, params: {bulk_update_request: {script: "create alias aaa -> bbb", title: "xxx"}}
|
||||
post_auth bulk_update_requests_path, @user, params: { bulk_update_request: { script: "create alias aaa -> bbb", title: "xxx", reason: "xxxxx" } }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class TagAliasRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "create action" do
|
||||
should "render" do
|
||||
assert_difference("ForumTopic.count", 1) do
|
||||
post_auth tag_alias_request_path, @user, params: {:tag_alias_request => {:antecedent_name => "aaa", :consequent_name => "bbb", :reason => "ccc"}}
|
||||
post_auth tag_alias_request_path, @user, params: { tag_alias_request: { antecedent_name: "aaa", consequent_name: "bbb", reason: "ccccc" } }
|
||||
end
|
||||
assert_redirected_to(forum_topic_path(ForumTopic.last))
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ class TagImplicationRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "create action" do
|
||||
should "create forum post" do
|
||||
assert_difference("ForumTopic.count", 1) do
|
||||
post_auth tag_implication_request_path, @user, params: {:tag_implication_request => {:antecedent_name => "aaa", :consequent_name => "bbb", :reason => "ccc"}}
|
||||
post_auth tag_implication_request_path, @user, params: { tag_implication_request: { antecedent_name: "aaa", consequent_name: "bbb", reason: "ccccc" } }
|
||||
end
|
||||
assert_redirected_to(forum_topic_path(ForumTopic.last))
|
||||
end
|
||||
|
@ -71,7 +71,13 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
|
||||
|
||||
should "create a forum topic" do
|
||||
assert_difference("ForumTopic.count", 1) do
|
||||
BulkUpdateRequest.create(:title => "abc", :reason => "zzz", :script => "create alias aaa -> bbb")
|
||||
create(:bulk_update_request)
|
||||
end
|
||||
end
|
||||
|
||||
should "not create a forum when skip_forum is true" do
|
||||
assert_no_difference("ForumTopic.count") do
|
||||
create(:bulk_update_request, skip_forum: true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -46,5 +46,18 @@ class TagAliasRequestTest < ActiveSupport::TestCase
|
||||
tar.create
|
||||
assert_equal(tar.forum_topic.posts.first.id, tar.tag_relationship.forum_post.id)
|
||||
end
|
||||
|
||||
should "fail validation if the reason is too short" do
|
||||
tar = TagAliasRequest.new(antecedent_name: "aaa", consequent_name: "bbb", reason: "")
|
||||
tar.create
|
||||
assert_match(/Reason is too short/, tar.errors.full_messages.join)
|
||||
end
|
||||
|
||||
should "not create a forum post if skip_forum is true" do
|
||||
assert_no_difference("ForumPost.count") do
|
||||
tar = TagAliasRequest.new(antecedent_name: "aaa", consequent_name: "bbb", skip_forum: true)
|
||||
tar.create
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user