Allow outcomes CSVs with no workflow_state column.
Fixes OUT-2104 Test Plan: - Create a CSV file (possibly from spec/lib/outcomes/fixtures) with no workflow_state header / column. - Import, verify that the outcomes and groups are properly imported. Change-Id: I2175c974085045c9b6263588ab903ab4729b4072 Reviewed-on: https://gerrit.instructure.com/145553 Tested-by: Jenkins Reviewed-by: Michael Brewer-Davis <mbd@instructure.com> QA-Review: Leo Abner <rabner@instructure.com> Product-Review: Sidharth Oberoi <soberoi@instructure.com>
This commit is contained in:
parent
9cd6d0d8ca
commit
5ae9ab5600
|
@ -22,7 +22,7 @@ module Outcomes
|
|||
class InvalidDataError < RuntimeError; end
|
||||
|
||||
OBJECT_ONLY_FIELDS = %i[calculation_method calculation_int ratings].freeze
|
||||
VALID_WORKFLOWS = ['', 'active', 'deleted'].freeze
|
||||
VALID_WORKFLOWS = [nil, '', 'active', 'deleted'].freeze
|
||||
|
||||
def check_object(object)
|
||||
%i[vendor_guid title].each do |field|
|
||||
|
@ -95,7 +95,7 @@ module Outcomes
|
|||
model.vendor_guid = group[:vendor_guid]
|
||||
model.title = group[:title]
|
||||
model.description = group[:description] || ''
|
||||
model.workflow_state = group[:workflow_state] || 'active'
|
||||
model.workflow_state = group[:workflow_state].presence || 'active'
|
||||
model.learning_outcome_group = parent
|
||||
model.outcome_import_id = outcome_import_id
|
||||
model.save!
|
||||
|
|
|
@ -38,7 +38,7 @@ describe Outcomes::CsvImporter do
|
|||
end
|
||||
end
|
||||
|
||||
def outcome_row(**changes)
|
||||
def outcome_row_with_headers(outcome_headers, **changes)
|
||||
valid = {
|
||||
title: 'title',
|
||||
vendor_guid: SecureRandom.uuid,
|
||||
|
@ -50,10 +50,14 @@ describe Outcomes::CsvImporter do
|
|||
}
|
||||
|
||||
row = valid.merge(changes)
|
||||
headers.map { |k| row[k.to_sym] }
|
||||
outcome_headers.map { |k| row[k.to_sym] }
|
||||
end
|
||||
|
||||
def group_row(**changes)
|
||||
def outcome_row(**changes)
|
||||
outcome_row_with_headers(headers, **changes)
|
||||
end
|
||||
|
||||
def group_row_with_headers(group_headers, **changes)
|
||||
valid = {
|
||||
title: 'title',
|
||||
vendor_guid: SecureRandom.uuid,
|
||||
|
@ -65,7 +69,11 @@ describe Outcomes::CsvImporter do
|
|||
}
|
||||
|
||||
row = valid.merge(changes)
|
||||
headers.map { |k| row[k.to_sym] }
|
||||
group_headers.map { |k| row[k.to_sym] }
|
||||
end
|
||||
|
||||
def group_row(**changes)
|
||||
group_row_with_headers(headers, **changes)
|
||||
end
|
||||
|
||||
before :once do
|
||||
|
@ -231,6 +239,17 @@ describe Outcomes::CsvImporter do
|
|||
import_fake_csv(rows, separator: ';')
|
||||
expect(LearningOutcomeGroup.count).to eq(4)
|
||||
end
|
||||
|
||||
it 'does not require workflow_state' do
|
||||
no_workflow = headers - ['workflow_state']
|
||||
rows = [no_workflow] + (1..3).map do |ix|
|
||||
group_row_with_headers(no_workflow, vendor_guid: ix)
|
||||
end
|
||||
rows = rows.to_a + [outcome_row_with_headers(no_workflow, vendor_guid: 'outcome')]
|
||||
import_fake_csv(rows)
|
||||
expect(LearningOutcomeGroup.count).to eq(4)
|
||||
expect(LearningOutcome.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_import_error(rows, expected)
|
||||
|
|
Loading…
Reference in New Issue