Skip to content

Commit

Permalink
Admin views csv upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured authored and github-actions[bot] committed Feb 18, 2024
1 parent 4dcd946 commit 74243d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/csv_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions app/views/admin/csv_uploads/show.html.haml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions spec/system/csv_uploads/admin_views_csv_upload_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74243d9

Please sign in to comment.