Fix admin accounts CSV output

This commit is contained in:
Thiago Youssef 2022-03-14 12:12:22 +02:00
parent 7d79e6528d
commit 1fac9d9618
3 changed files with 24 additions and 0 deletions

View file

@ -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

4
test/fixtures/files/accounts.csv vendored Normal file
View file

@ -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
1 Id Balance Currency Registrar
2 112846265 100.0 EUR Best Names
3 298486374 100.0 EUR Good Names
4 597560588 0.0 EUR Not in use

View file

@ -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