Fix #4441: BUR form: display original request in the error page.
This commit is contained in:
@@ -73,7 +73,7 @@ class AliasAndImplicationImporter
|
||||
# okay
|
||||
|
||||
else
|
||||
raise Error, "Unknown token: #{token[0]}"
|
||||
raise NotImplementedError, "Unknown token: #{token[0]}" # should never happen
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -90,6 +90,8 @@ class AliasAndImplicationImporter
|
||||
args[0]
|
||||
end
|
||||
end.sort.uniq
|
||||
rescue Error
|
||||
[]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -15,7 +15,6 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
validates_presence_of :title, if: ->(rec) {rec.forum_topic_id.blank?}
|
||||
validates_presence_of :forum_topic, if: ->(rec) {rec.forum_topic_id.present?}
|
||||
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
||||
validate :script_formatted_correctly
|
||||
validate :validate_script, :on => :create
|
||||
|
||||
after_create :create_forum_topic
|
||||
@@ -110,15 +109,9 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
|
||||
module ValidationMethods
|
||||
def script_formatted_correctly
|
||||
AliasAndImplicationImporter.tokenize(script)
|
||||
rescue StandardError => e
|
||||
errors[:base] << e.message
|
||||
end
|
||||
|
||||
def validate_script
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
|
||||
rescue RuntimeError => e
|
||||
rescue AliasAndImplicationImporter::Error => e
|
||||
errors[:base] << e.message
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,6 +30,13 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
should "fail for an invalid script" do
|
||||
assert_difference("BulkUpdateRequest.count", 0) do
|
||||
post_auth bulk_update_requests_path, @user, params: { bulk_update_request: attributes_for(:bulk_update_request).merge(script: "create alis gray -> grey") }
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
should "fail for a blank reason" do
|
||||
assert_difference("BulkUpdateRequest.count", 0) do
|
||||
post_auth bulk_update_requests_path, @user, params: { bulk_update_request: attributes_for(:bulk_update_request).merge(reason: "") }
|
||||
|
||||
Reference in New Issue
Block a user