From 12d83408abef9ccf68f5029d3a04c66cb037f160 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 4 May 2020 03:07:30 -0500 Subject: [PATCH] BURs: make the reason required. --- app/models/bulk_update_request.rb | 1 + test/factories/bulk_update_request.rb | 1 + test/functional/bulk_update_requests_controller_test.rb | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index bd3207102..cd8d34c76 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -10,6 +10,7 @@ class BulkUpdateRequest < ApplicationRecord before_validation :normalize_text before_validation :update_tags + validates_presence_of :reason, on: :create validates_presence_of :script validates_presence_of :title, if: ->(rec) {rec.forum_topic_id.blank?} validates_presence_of :forum_topic, if: ->(rec) {rec.forum_topic_id.present?} diff --git a/test/factories/bulk_update_request.rb b/test/factories/bulk_update_request.rb index 4e987a920..1e3dd0740 100644 --- a/test/factories/bulk_update_request.rb +++ b/test/factories/bulk_update_request.rb @@ -3,6 +3,7 @@ FactoryBot.define do user title {"xxx"} script {"create alias aaa -> bbb"} + reason { FFaker::Lorem.sentences.join(" ") } skip_secondary_validations {true} end end diff --git a/test/functional/bulk_update_requests_controller_test.rb b/test/functional/bulk_update_requests_controller_test.rb index e9f7f3dd3..13800bd06 100644 --- a/test/functional/bulk_update_requests_controller_test.rb +++ b/test/functional/bulk_update_requests_controller_test.rb @@ -25,10 +25,17 @@ 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: {skip_secondary_validations: "1", script: "create alias aaa -> bbb", title: "xxx"}} + post_auth bulk_update_requests_path, @user, params: { bulk_update_request: attributes_for(:bulk_update_request) } assert_response :redirect 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: "") } + assert_response :success + end + end end context "#update" do