Fix validations, don't hide database errors.

Fixes OUT-2525

Test Plan:
- Import a CSV with a long (>255 character) vendor_guid.
- Verify that on import, you get an email with an error referencing
  the specific line that failed.

Change-Id: I9b71e937666e404ac70d9ff0014d0f81ce541657
Reviewed-on: https://gerrit.instructure.com/168903
Tested-by: Jenkins
Reviewed-by: Neil Gupta <ngupta@instructure.com>
Reviewed-by: Augusto Callejas <acallejas@instructure.com>
QA-Review: Dariusz Dzien <ddzien@instructure.com>
Product-Review: Neil Gupta <ngupta@instructure.com>
This commit is contained in:
Frank Murphy 2018-10-17 14:09:35 -04:00 committed by Frank Murphy III
parent e547154967
commit 87d6183c6e
4 changed files with 16 additions and 0 deletions

View File

@ -47,6 +47,7 @@ class LearningOutcome < ActiveRecord::Base
validates :description, length: { maximum: maximum_text_length, allow_nil: true, allow_blank: true }
validates :short_description, length: { maximum: maximum_string_length }
validates :vendor_guid, length: { maximum: maximum_string_length, allow_nil: true }
validates :display_name, length: { maximum: maximum_string_length, allow_nil: true, allow_blank: true }
validates :calculation_method, inclusion: { in: CALCULATION_METHODS.keys,
message: -> { t(

View File

@ -28,6 +28,7 @@ class LearningOutcomeGroup < ActiveRecord::Base
belongs_to :context, polymorphic: [:account, :course]
before_save :infer_defaults
validates :vendor_guid, length: { maximum: maximum_string_length, allow_nil: true }
validates_length_of :description, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true
validates_length_of :title, :maximum => maximum_string_length, :allow_nil => true, :allow_blank => true
validates_presence_of :title, :workflow_state

View File

@ -61,6 +61,8 @@ module Outcomes
raise DataFormatError, I18n.t("Invalid CSV File")
rescue ParseError => e
raise DataFormatError, e.message
rescue ActiveRecord::StatementInvalid => e
raise DataFormatError, I18n.t("Database error (%{err})", err: e.message)
end
status = {
errors: file_errors,

View File

@ -428,6 +428,18 @@ describe Outcomes::CsvImporter do
)
end
it 'raises a line error when vendor_guid is too long' do
expect_import_error(
[
headers,
outcome_row(vendor_guid: 'long-' * 200),
],
[
[2, "Vendor guid is too long (maximum is 255 characters)"],
]
)
end
it 'if a group receives invalid fields' do
expect_import_error(
[