diff --git a/app/models/csv_upload.rb b/app/models/csv_upload.rb new file mode 100644 index 0000000..ae44476 --- /dev/null +++ b/app/models/csv_upload.rb @@ -0,0 +1,3 @@ +class CsvUpload < ApplicationRecord + validates_presence_of :data, :original_filename, :parser_class_name +end diff --git a/db/migrate/20240213142420_create_csv_uploads.rb b/db/migrate/20240213142420_create_csv_uploads.rb new file mode 100644 index 0000000..a9ba600 --- /dev/null +++ b/db/migrate/20240213142420_create_csv_uploads.rb @@ -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 diff --git a/spec/factories/csv_upload.rb b/spec/factories/csv_upload.rb new file mode 100644 index 0000000..bc01dfd --- /dev/null +++ b/spec/factories/csv_upload.rb @@ -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 diff --git a/spec/models/csv_upload_spec.rb b/spec/models/csv_upload_spec.rb new file mode 100644 index 0000000..5717f0c --- /dev/null +++ b/spec/models/csv_upload_spec.rb @@ -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 diff --git a/spec/system/model_counts/admin_views_model_counts_spec.rb b/spec/system/model_counts/admin_views_model_counts_spec.rb index b91d521..7df9bdc 100644 --- a/spec/system/model_counts/admin_views_model_counts_spec.rb +++ b/spec/system/model_counts/admin_views_model_counts_spec.rb @@ -11,6 +11,7 @@ expected_rows = [ "Artwork 0", "Book 0", + "CsvUpload 0", "FinancialAccount 0", "FinancialStatement 0", "FinancialTransaction 0", @@ -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) @@ -61,6 +63,7 @@ expected_rows = [ "Artwork 1", "Book 1", + "CsvUpload 1", "FinancialAccount 1", "FinancialStatement 1", "FinancialTransaction 1", @@ -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