mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Add support for different column separator in csv import logic (#1096)
* add col_sep to import model * add validation for col_sep column * add col_sep option to csv import model * make use of col_sep option in import model * add column separator field to new/edit action of an import * add col_sep parameter to create/update action * fix spacing between fields Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Alexander Schrot <alexander@axs-labs.com> --------- Signed-off-by: Alexander Schrot <alexander@axs-labs.com> Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
This commit is contained in:
parent
707c5ca0ca
commit
4527482aa2
11 changed files with 117 additions and 19 deletions
|
@ -10,6 +10,21 @@ class ImportTest < ActiveSupport::TestCase
|
|||
@loaded_import.update! raw_csv_str: valid_csv_str
|
||||
end
|
||||
|
||||
test "validates the correct col_sep" do
|
||||
assert_equal ",", @empty_import.col_sep
|
||||
|
||||
assert @empty_import.valid?
|
||||
|
||||
@empty_import.col_sep = "invalid"
|
||||
assert @empty_import.invalid?
|
||||
|
||||
@empty_import.col_sep = ","
|
||||
assert @empty_import.valid?
|
||||
|
||||
@empty_import.col_sep = ";"
|
||||
assert @empty_import.valid?
|
||||
end
|
||||
|
||||
test "raw csv input must conform to csv spec" do
|
||||
@empty_import.raw_csv_str = malformed_csv_str
|
||||
assert_not @empty_import.valid?
|
||||
|
@ -83,4 +98,18 @@ class ImportTest < ActiveSupport::TestCase
|
|||
@empty_import.reload
|
||||
assert @empty_import.failed?
|
||||
end
|
||||
|
||||
test "can create transactions from csv with custom column separator" do
|
||||
loaded_import = @empty_import.dup
|
||||
|
||||
loaded_import.update! raw_csv_str: valid_csv_str_with_semicolon_separator, col_sep: ";"
|
||||
transactions = loaded_import.dry_run
|
||||
|
||||
assert_equal 4, transactions.count
|
||||
|
||||
data = transactions.first.as_json(only: [ :name, :amount, :date ])
|
||||
assert_equal data, { "amount" => "8.55", "date" => "2024-01-01", "name" => "Starbucks drink" }
|
||||
|
||||
assert_equal valid_csv_str, loaded_import.normalized_csv_str
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue