Skip to content

Commit

Permalink
Add modeling for csv uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Feb 17, 2024
1 parent 73e3b64 commit 7bc5dd9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/csv_upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class CsvUpload < ApplicationRecord
validates_presence_of :data, :original_filename, :parser_class_name
end
10 changes: 10 additions & 0 deletions db/migrate/20240213142420_create_csv_uploads.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateCsvUploads < ActiveRecord::Migration[7.1]
def change
create_table :csv_uploads do |t|
t.text :data
t.string :parser_class_name
t.string :original_filename
t.timestamps
end
end
end
7 changes: 7 additions & 0 deletions spec/factories/csv_upload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :csv_upload do
data { "123,foo,true" }
original_filename { "sample-data.csv" }
parser_class_name { "SampleParser" }
end
end
24 changes: 24 additions & 0 deletions spec/models/csv_upload_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "rails_helper"

describe CsvUpload do
describe "validation" do
context "without required attrs" do
it "is invalid" do
csv_upload = CsvUpload.new
expect(csv_upload).to_not be_valid
end
end

context "with required attrs" do
it "is valid" do
csv_upload = CsvUpload.new(
data: "foo,bar,baz",
original_filename: "dummy-data.csv",
parser_class_name: "DummyParser"
)

expect(csv_upload).to be_valid
end
end
end
end
5 changes: 4 additions & 1 deletion spec/system/model_counts/admin_views_model_counts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
expected_rows = [
"Artwork 0",
"Book 0",
"CsvUpload 0",
"FinancialAccount 0",
"FinancialStatement 0",
"FinancialTransaction 0",
Expand All @@ -31,6 +32,7 @@

scenario "with some models" do
FactoryBot.create(:book)
FactoryBot.create(:csv_upload)
FactoryBot.create(:gift_idea)
FactoryBot.create(:killswitch)
FactoryBot.create(:post_bin_request)
Expand Down Expand Up @@ -61,6 +63,7 @@
expected_rows = [
"Artwork 1",
"Book 1",
"CsvUpload 1",
"FinancialAccount 1",
"FinancialStatement 1",
"FinancialTransaction 1",
Expand All @@ -78,6 +81,6 @@

expect(actual_rows).to match_array(expected_rows)

expect(page.find("tfoot tr").text).to eq "Total 15"
expect(page.find("tfoot tr").text).to eq "Total 16"
end
end

0 comments on commit 7bc5dd9

Please sign in to comment.