-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from CLOSER-Cohorts/feature/276-three-and-fou…
…r-column-txt-import-exports Feature/276 three and four column txt import exports
- Loading branch information
Showing
24 changed files
with
336 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<% @collection.each do |qc| %> | ||
<%= qc.label %><%= "\t" %><%= qc.fully_resolved_topic_code %> | ||
<% end %> | ||
<%= qc.control_construct_scheme %><%= "\t" %><%= qc.label %><%= "\t" %><%= qc.fully_resolved_topic_code %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<% @object.dv_mappings.order(id: 'ASC').each do |map| %> | ||
<%= map.variable %><%= "\t" %><%= map.source %> | ||
<% end %> | ||
<%= map.dataset_instance_name %><%= "\t" %><%= map.variable %><%= "\t" %><%= map.dataset_instance_name %><%= "\t" %><%= map.source %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<% @object.qv_mappings.order(id: 'ASC').each do |map| %> | ||
<%= map.question_with_cell %><%= "\t" %><%= map.variable %> | ||
<% end %> | ||
<%= map.control_construct_scheme %><%= "\t" %><%= map.question_with_cell %><%= "\t" %><%= map.dataset_instance_name %><%= "\t" %><%= map.variable %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<% @collection.each do |v| %> | ||
<%= v.name %><%= "\t" %><%= v.fully_resolved_topic_code %> | ||
<% end %> | ||
<%= v.dataset_instance_name %><%= "\t" %><%= v.name %><%= "\t" %><%= v.fully_resolved_topic_code %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require 'test_helper' | ||
require 'active_support/core_ext/hash/conversions' | ||
|
||
class Importers::TXT::Mapper::DVTest < ActiveSupport::TestCase | ||
|
||
setup do | ||
@dataset = FactoryBot.create(:dataset) | ||
@source_variable = FactoryBot.create(:variable, dataset: @dataset) | ||
@derived_variable = FactoryBot.create(:variable, dataset: @dataset) | ||
@derived_variable.src_variables << @source_variable | ||
end | ||
|
||
describe "where instrument already has dv mappings" do | ||
describe "dv mappings from tab delimited text file" do | ||
it "should create a new mappings for the source and derived variables" do | ||
source_variable = FactoryBot.create(:variable, dataset: @dataset) | ||
new_txt = "#{@dataset.instance_name}\t#{@derived_variable}\t#{@dataset.instance_name}\t#{source_variable.name}\n" | ||
import = FactoryBot.create(:import, dataset: @dataset, import_type: 'ImportJob::DV') | ||
doc = Document.create(file: new_txt, item: @dataset) | ||
Importers::TXT::Mapper::DV.new(doc.id, {:object=>@dataset.id.to_s, :import_id => import.id}).import | ||
import = import.reload | ||
assert_equal('success', import.state) | ||
last_dv_mapping = @dataset.reload.dv_mappings.last | ||
assert_equal [source_variable.name, @derived_variable.name], [last_dv_mapping.source, last_dv_mapping.variable] | ||
end | ||
end | ||
end | ||
describe "dataset from the tab delimited text file does not match the instrument for the import" do | ||
it "should mark the import has an error" do | ||
other_dataset = FactoryBot.create(:dataset) | ||
new_txt = "#{other_dataset.instance_name}\t#{@derived_variable}\t#{@dataset.instance_name}\t#{@source_variable.name}\n" | ||
import = FactoryBot.create(:import, dataset: @dataset, import_type: 'ImportJob::DV') | ||
doc = Document.create(file: new_txt, item: @dataset) | ||
Importers::TXT::Mapper::DV.new(doc.id, {:object=>@dataset.id.to_s, :import_id => import.id}).import | ||
import = import.reload | ||
assert_equal('failure', import.state) | ||
assert_equal(import.parsed_log.first[:outcome], I18n.t('importers.txt.mapper.dv.record_invalid_dataset', dataset_from_line: other_dataset.instance_name, dataset_from_object: @dataset.instance_name)) | ||
end | ||
end | ||
describe "tab delimited text contains less than 4 columns" do | ||
it "should mark the import has an error" do | ||
new_txt = "#{@dataset.instance_name}\t#{@derived_variable}\t#{@dataset.instance_name}\n#{@dataset.instance_name}\t#{@derived_variable}\n" | ||
import = FactoryBot.create(:import, dataset: @dataset, import_type: 'ImportJob::DV') | ||
doc = Document.create(file: new_txt, item: @dataset) | ||
Importers::TXT::Mapper::DV.new(doc.id, {:object=>@dataset.id.to_s, :import_id => import.id}).import | ||
import = import.reload | ||
assert_equal('failure', import.state) | ||
assert_equal(import.parsed_log.first[:outcome], I18n.t('importers.txt.mapper.dv.wrong_number_of_columns', actual_number_of_columns: 3)) | ||
assert_equal(import.parsed_log[1][:outcome], I18n.t('importers.txt.mapper.dv.wrong_number_of_columns', actual_number_of_columns: 2)) | ||
end | ||
end | ||
end |
Oops, something went wrong.