From 1fac9d9618e3a250c544d2b2171d17ba6db33e9a Mon Sep 17 00:00:00 2001 From: Thiago Youssef Date: Mon, 14 Mar 2022 12:12:22 +0200 Subject: [PATCH] Fix admin accounts CSV output --- app/models/account.rb | 8 ++++++++ test/fixtures/files/accounts.csv | 4 ++++ test/system/admin_area/accounts_test.rb | 12 ++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 test/fixtures/files/accounts.csv diff --git a/app/models/account.rb b/app/models/account.rb index fe0820888..73911817c 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -12,4 +12,12 @@ class Account < ApplicationRecord def activities account_activities end + + def as_csv_row + [id, balance, currency, registrar] + end + + def self.csv_header + ['Id', 'Balance', 'Currency', 'Registrar'].freeze + end end diff --git a/test/fixtures/files/accounts.csv b/test/fixtures/files/accounts.csv new file mode 100644 index 000000000..5bc44fc48 --- /dev/null +++ b/test/fixtures/files/accounts.csv @@ -0,0 +1,4 @@ +Id,Balance,Currency,Registrar +112846265,100.0,EUR,Best Names +298486374,100.0,EUR,Good Names +597560588,0.0,EUR,Not in use diff --git a/test/system/admin_area/accounts_test.rb b/test/system/admin_area/accounts_test.rb index f07ced9c3..393c3445a 100644 --- a/test/system/admin_area/accounts_test.rb +++ b/test/system/admin_area/accounts_test.rb @@ -29,4 +29,16 @@ class AdminAccountsSystemTest < ApplicationSystemTestCase assert_text 'Account has been successfully updated' assert_text '234' end + + def test_download_accounts_list_as_csv + travel_to Time.zone.parse('2010-07-05 10:30') + + get admin_accounts_path(format: :csv) + + assert_response :ok + assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type'] + assert_equal %(attachment; filename="accounts_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''accounts_#{Time.zone.now.to_formatted_s(:number)}.csv), + response.headers['Content-Disposition'] + assert_equal file_fixture('accounts.csv').read, response.body + end end