Skip to content

Commit 33da5fe

Browse files
committed
add specs to check new full-export headings for institutions
1 parent 0a03311 commit 33da5fe

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

lib/common/exporter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def write_versioned_row(csv, csv_headers)
104104
raise(MissingAttributeError, "#{klass.name} is not versioned") unless klass.has_attribute?('version_id')
105105

106106
klass.includes(:version)
107-
.limit(4).each do |record|
107+
.find_each(batch_size: Settings.active_record.batch_size.find_each) do |record|
108108
csv << csv_headers.keys.map { |k| record.respond_to?(k) == false ? nil : format(k, record.public_send(k)) }
109109
end
110110
end

spec/controllers/dashboards_controller_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ def load_table(klass)
159159
it 'redirects to index on error' do
160160
expect(get(:export_version, params: { format: :xml, number: 1 })).to redirect_to(action: :index)
161161
end
162+
163+
context 'when requesting a full export' do
164+
before do
165+
# build some real institutions to populate the CSV file, but skip the slow geocoding step
166+
allow(InstitutionBuilder::Factory).to receive(:geocode_using_csv_file)
167+
InstitutionBuilder.run(User.first)
168+
end
169+
170+
it 'generates a CSV with the appropriate column headers' do
171+
get(:export_version, params: { format: :csv, number: 1, export_all: true })
172+
csv_data = CSV.parse(response.body, headers: true)
173+
174+
# just pick a reasonable sample of column headers
175+
%w[
176+
version
177+
weams_priority_enrollment
178+
weams_physical_city
179+
scorecard_hbcu
180+
sec_103_solely_requires_coe
181+
computed_complaints_refund_by_ope_id_do_not_sum
182+
sec_109_closure109
183+
sva_student_veteran
184+
].each do |header_name|
185+
expect(csv_data.headers).to include(header_name)
186+
end
187+
end
188+
end
162189
end
163190

164191
describe 'GET api_fetch' do

spec/models/shared_examples/shared_examples_for_exportable_by_version.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414
# Pull the default CSV options to be used
1515
default_options = Common::Shared.file_type_defaults(described_class.name)
1616

17-
def check_attributes_from_records(rows, header_row)
17+
def check_attributes_from_records(rows, header_row, use_full_export_name = false)
1818
described_class.find_each.with_index do |record, i|
1919
attributes = {}
2020

2121
rows[i].each.with_index do |value, j|
2222
header = Common::Shared.convert_csv_header(header_row[j])
23-
attributes[mapping[header][:column]] = value
24-
attributes[mapping[header][:column]] = version if mapping[header][:column].eql? :version
23+
24+
column_info = use_full_export_name ? mapping.values.find{|m| m[:full_export_name] == header} : mapping[header]
25+
attributes[column_info[:column]] = value
26+
attributes[column_info[:column]] = version if column_info[:column].eql? :version
2527
end
2628

2729
csv_record = described_class.new(attributes)
2830
csv_record.derive_dependent_columns if csv_record.respond_to?(:derive_dependent_columns)
29-
3031
ignored_attributes = %w[id version created_at updated_at csv_row version_id institution_search]
3132
csv_test_attributes = csv_record.attributes.except(*ignored_attributes)
3233
test_attributes = record.attributes.except(*ignored_attributes)
@@ -54,7 +55,7 @@ def check_attributes_from_records(rows, header_row)
5455
rows = described_class.export_by_version(true).split("\n")
5556
header_row = rows.shift.split(default_options[:col_sep]).map(&:downcase)
5657
rows = CSV.parse(rows.join("\n"), col_sep: default_options[:col_sep])
57-
check_attributes_from_records(rows, header_row)
58+
check_attributes_from_records(rows, header_row, true)
5859
expect(header_row.size).to eq 149
5960
end
6061
end

0 commit comments

Comments
 (0)