diff --git a/app/models/csv_upload.rb b/app/models/csv_upload.rb index 149ee4e..ec9dca5 100644 --- a/app/models/csv_upload.rb +++ b/app/models/csv_upload.rb @@ -8,4 +8,13 @@ def parsed_data rescue CSV::MalformedCSVError nil end + + def table_attrs + [ + ["Parser Class Name", parser_class_name], + ["Original Filename", original_filename], + ["Created At", created_at.to_formatted_s(:long)], + ["Updated At", updated_at.to_formatted_s(:long)] + ] + end end diff --git a/app/views/admin/csv_uploads/show.html.haml b/app/views/admin/csv_uploads/show.html.haml index 0c4d096..562ed6c 100644 --- a/app/views/admin/csv_uploads/show.html.haml +++ b/app/views/admin/csv_uploads/show.html.haml @@ -1 +1,8 @@ %h1 CSV Upload #{csv_upload.id} + += render partial: "attrs_table", locals: { attrs: csv_upload.table_attrs } + +%h2 Data + +%pre.text-off-black.h-72 + %code= csv_upload.data diff --git a/spec/system/csv_uploads/admin_views_csv_upload_spec.rb b/spec/system/csv_uploads/admin_views_csv_upload_spec.rb new file mode 100644 index 0000000..407e851 --- /dev/null +++ b/spec/system/csv_uploads/admin_views_csv_upload_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +describe "Admin views CsvUpload" do + include_context "admin password matches" + + scenario "views CsvUpload" do + csv_upload = FactoryBot.create( + :csv_upload, + data: "foo,bar,baz", + original_filename: "dummy-data.csv", + parser_class_name: "DummyParser" + ) + + visit "/admin/csv_uploads/#{csv_upload.id}" + + expect(page).to have_content "CSV Upload #{csv_upload.id}" + + actual_values = page.all("tr").map do |table_row| + table_row.all("td").map(&:text) + end + + expect(actual_values).to eq( + [ + ["Parser Class Name", "DummyParser"], + ["Original Filename", "dummy-data.csv"], + ["Created At", csv_upload.created_at.to_formatted_s(:long)], + ["Updated At", csv_upload.updated_at.to_formatted_s(:long)] + ] + ) + + expect(page.find("code").text).to eq csv_upload.data + end +end