Merge pull request #2120 from internetee/500-csv-export

Admin: adding export to CSV
This commit is contained in:
Timo Võhmar 2021-08-18 17:50:24 +03:00 committed by GitHub
commit 37fb8de3f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
44 changed files with 214 additions and 47 deletions

View file

@ -21,5 +21,17 @@ module Admin
def paginate? def paginate?
params[:results_per_page].to_i.positive? params[:results_per_page].to_i.positive?
end end
def render_by_format(page, filename)
respond_to do |format|
format.html { render page }
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "#{filename}_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
end end
end end

View file

@ -8,6 +8,8 @@ module Admin
@q = domains.search(params[:q]) @q = domains.search(params[:q])
@domains = @q.result.page(params[:page]) @domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render_by_format('admin/blocked_domains/index', 'blocked_domains')
end end
def new def new

View file

@ -28,6 +28,7 @@ module Admin
@versions = @q.result.page(params[:page]) @versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render_by_format('admin/contact_versions/index', 'contact_history')
end end
def show def show

View file

@ -24,6 +24,8 @@ module Admin
end end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render_by_format('admin/contacts/index', 'contacts')
end end
def filter_by_flags(contacts) def filter_by_flags(contacts)

View file

@ -10,6 +10,8 @@ module Admin
params[:q] ||= {} params[:q] ||= {}
@disputes = sortable_dispute_query_for(Dispute.active.all, params[:q]) @disputes = sortable_dispute_query_for(Dispute.active.all, params[:q])
@closed_disputes = sortable_dispute_query_for(Dispute.closed.all, params[:q], closed: true) @closed_disputes = sortable_dispute_query_for(Dispute.closed.all, params[:q], closed: true)
render_by_format('admin/disputes/index', 'disputes')
end end
# GET /admin/disputes/1 # GET /admin/disputes/1

View file

@ -44,7 +44,8 @@ module Admin
@q = versions.search(params[:q]) @q = versions.search(params[:q])
@versions = @q.result.page(params[:page]) @versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render "admin/domain_versions/archive"
render_by_format('admin/domain_versions/archive', 'domain_history')
end end
def show def show

View file

@ -29,15 +29,7 @@ module Admin
end end
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format| render_by_format('admin/domains/index', 'domains')
format.html do
@domains
end
format.csv do
raw_csv = @domains.to_csv
send_data raw_csv, filename: 'domains.csv', type: "#{Mime[:csv]}; charset=utf-8"
end
end
end end
def show def show

View file

@ -13,6 +13,8 @@ module Admin
@epp_logs = @epp_logs.page(params[:page]) @epp_logs = @epp_logs.page(params[:page])
@count = @q.result.count @count = @q.result.count
@epp_logs = @epp_logs.per(params[:results_per_page]) if paginate? @epp_logs = @epp_logs.per(params[:results_per_page]) if paginate?
render_by_format('admin/epp_logs/index', 'epp_logs')
end end
def show def show
@ -31,7 +33,6 @@ module Admin
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
end end
end end
end end
end end

View file

@ -13,6 +13,8 @@ module Admin
@repp_logs = @repp_logs.page(params[:page]) @repp_logs = @repp_logs.page(params[:page])
@count = @q.result.count @count = @q.result.count
@repp_logs = @repp_logs.per(params[:results_per_page]) if paginate? @repp_logs = @repp_logs.per(params[:results_per_page]) if paginate?
render_by_format('admin/repp_logs/index', 'repp_logs')
end end
def show def show
@ -32,7 +34,6 @@ module Admin
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d") params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
end end
end end
end end
end end

View file

@ -9,6 +9,8 @@ module Admin
@q = domains.search(params[:q]) @q = domains.search(params[:q])
@domains = @q.result.page(params[:page]) @domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive? @domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render_by_format('admin/reserved_domains/index', 'reserved_domains')
end end
def new def new

10
app/lib/to_csv.rb Normal file
View file

@ -0,0 +1,10 @@
module ToCsv
def to_csv
CSV.generate do |csv|
csv << column_names
all.find_each do |item|
csv << item.attributes.values_at(*column_names)
end
end
end
end

View file

@ -1,4 +1,5 @@
module ApiLog module ApiLog
class EppLog < Db class EppLog < Db
extend ToCsv
end end
end end

View file

@ -1,4 +1,5 @@
module ApiLog module ApiLog
class ReppLog < Db class ReppLog < Db
extend ToCsv
end end
end end

View file

@ -1,5 +1,6 @@
class BlockedDomain < ApplicationRecord class BlockedDomain < ApplicationRecord
include Versions include Versions
extend ToCsv
before_save :generate_data before_save :generate_data
after_destroy :remove_data after_destroy :remove_data

View file

@ -1,4 +1,5 @@
class Dispute < ApplicationRecord class Dispute < ApplicationRecord
extend ToCsv
include WhoisStatusPopulate include WhoisStatusPopulate
validates :domain_name, :password, :starts_at, :expires_at, presence: true validates :domain_name, :password, :starts_at, :expires_at, presence: true
before_validation :fill_empty_passwords, :set_expiry_date before_validation :fill_empty_passwords, :set_expiry_date

View file

@ -280,6 +280,21 @@ class Domain < ApplicationRecord
) )
end end
def to_csv
CSV.generate do |csv|
headers = column_names.dup
swap_elements(headers, [[0, 1], [1, 5]])
headers[0] = 'Domain'
headers[1] = headers[1].humanize
csv << headers
all.find_each do |item|
row = item.attributes.values_at(*column_names)
swap_elements(row, [[0, 1], [1, 5]])
csv << row
end
end
end
private private
def registrant_user_domains_by_registrant(registrant_user) def registrant_user_domains_by_registrant(registrant_user)
@ -720,15 +735,6 @@ class Domain < ApplicationRecord
contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq
end end
def self.to_csv
CSV.generate do |csv|
csv << column_names
all.each do |domain|
csv << domain.attributes.values_at(*column_names)
end
end
end
def self.pdf(html) def self.pdf(html)
kit = PDFKit.new(html) kit = PDFKit.new(html)
kit.to_pdf kit.to_pdf
@ -749,4 +755,11 @@ class Domain < ApplicationRecord
def self.uses_zone?(zone) def self.uses_zone?(zone)
exists?(["name ILIKE ?", "%.#{zone.origin}"]) exists?(["name ILIKE ?", "%.#{zone.origin}"])
end end
def self.swap_elements(array, indexes)
indexes.each do |index|
array[index[0]], array[index[1]] = array[index[1]], array[index[0]]
end
array
end
end end

View file

@ -1,4 +1,5 @@
class ReservedDomain < ApplicationRecord class ReservedDomain < ApplicationRecord
extend ToCsv
include Versions # version/reserved_domain_version.rb include Versions # version/reserved_domain_version.rb
include WhoisStatusPopulate include WhoisStatusPopulate
before_save :fill_empty_passwords before_save :fill_empty_passwords

View file

@ -1,7 +1,7 @@
class Version::ContactVersion < PaperTrail::Version class Version::ContactVersion < PaperTrail::Version
extend ToCsv
include VersionSession include VersionSession
self.table_name = :log_contacts self.table_name = :log_contacts
self.sequence_name = :log_contacts_id_seq self.sequence_name = :log_contacts_id_seq
# scope :deleted, -> { where(event: 'destroy') }
end end

View file

@ -1,4 +1,5 @@
class Version::DomainVersion < PaperTrail::Version class Version::DomainVersion < PaperTrail::Version
extend ToCsv
include VersionSession include VersionSession
self.table_name = :log_domains self.table_name = :log_domains

View file

@ -23,11 +23,12 @@
.form-group .form-group
= label_tag t(:results_per_page) = label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'} .col-md-4{style: 'padding-top: 25px;'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.csv_btn'), admin_blocked_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_blocked_domains_path, class: 'btn btn-default') = link_to(t('.reset_btn'), admin_blocked_domains_path, class: 'btn btn-default')
%hr %hr
.row .row

View file

@ -21,18 +21,19 @@
= label_tag :action = label_tag :action
= select_tag '[q][event]', options_for_select([['Update', 'update'], ['Destroy', 'destroy'], ['Create', 'create']], params[:q][:event]), { include_blank:true, multiple: false, placeholder: t(:choose), class: 'form-control js-combobox' } = select_tag '[q][event]', options_for_select([['Update', 'update'], ['Destroy', 'destroy'], ['Create', 'create']], params[:q][:event]), { include_blank:true, multiple: false, placeholder: t(:choose), class: 'form-control js-combobox' }
.row .row
.col-md-3 .col-md-3
.col-md-3 .col-md-3
.col-md-3 .col-md-3
.form-group .form-group
= label_tag t(:results_per_page) = label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'} .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.reset_btn'), admin_contact_versions_path, class: 'btn btn-default') = link_to(t('.csv_btn'), admin_contact_versions_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_contact_versions_path, class: 'btn btn-default')
%hr %hr

View file

@ -69,11 +69,12 @@
= check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right' = check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right'
.row .row
.col-md-3{style: 'padding-top: 25px;float:right;'} .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.csv_btn'), admin_contacts_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_contacts_path, class: 'btn btn-default') = link_to(t('.reset_btn'), admin_contacts_path, class: 'btn btn-default')
%hr %hr
.row .row

View file

@ -32,12 +32,13 @@
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %> <%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
</div> </div>
</div> </div>
<div class="col-md-3" style="padding-top: 25px;"> <div class="col-md-4" style="padding-top: 25px;">
<button class="btn btn-primary"> <button class="btn btn-primary">
&nbsp; &nbsp;
<span class="glyphicon glyphicon-search"></span> <span class="glyphicon glyphicon-search"></span>
&nbsp; &nbsp;
</button> </button>
<%= link_to(t('.csv_btn'), admin_disputes_path(format: :csv, params: params.permit!), class: 'btn btn-default') %>
<%= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') %> <%= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') %>
</div> </div>
</div> </div>

View file

@ -27,11 +27,12 @@
.form-group .form-group
= label_tag t(:results_per_page) = label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'} .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.csv_btn'), admin_domain_versions_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_domain_versions_path, class: 'btn btn-default') = link_to(t('.reset_btn'), admin_domain_versions_path, class: 'btn btn-default')
%hr %hr

View file

@ -36,11 +36,12 @@
.form-group .form-group
= f.label t(:created_before) = f.label t(:created_before)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before) = f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before)
.col-md-3{style: 'padding-top: 25px;'} .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.csv_btn'), admin_epp_logs_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_epp_logs_path, class: 'btn btn-default') = link_to(t('.reset_btn'), admin_epp_logs_path, class: 'btn btn-default')
.row .row
.col-md-12 .col-md-12
@ -49,6 +50,7 @@
.pull-right .pull-right
.pagination .pagination
= t(:result_count, count: @count) if @count > 0 = t(:result_count, count: @count) if @count > 0
.row
.table-responsive .table-responsive
%table.table.table-hover.table-bordered.table-condensed %table.table.table-hover.table-bordered.table-condensed
%thead %thead

View file

@ -35,11 +35,12 @@
.form-group .form-group
= f.label t(:created_before) = f.label t(:created_before)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before) = f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before)
.col-md-3{style: 'padding-top: 25px;'} .col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.csv_btn'), admin_repp_logs_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_repp_logs_path, class: 'btn btn-default') = link_to(t('.reset_btn'), admin_repp_logs_path, class: 'btn btn-default')
%hr %hr
.row .row
@ -48,6 +49,7 @@
.pull-right .pull-right
.pagination .pagination
= t(:result_count, count: @count) if @count > 0 = t(:result_count, count: @count) if @count > 0
.row
.table-responsive .table-responsive
%table.table.table-hover.table-bordered.table-condensed %table.table.table-hover.table-bordered.table-condensed
%thead %thead

View file

@ -23,11 +23,12 @@
.form-group .form-group
= label_tag t(:results_per_page) = label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) = text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'} .col-md-4{style: 'padding-top: 25px;'}
%button.btn.btn-primary %button.btn.btn-primary
&nbsp; &nbsp;
%span.glyphicon.glyphicon-search %span.glyphicon.glyphicon-search
&nbsp; &nbsp;
= link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default') = link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default')
%hr %hr
.row .row

View file

@ -5,3 +5,4 @@ en:
title: Blocked domains title: Blocked domains
new_btn: New blocked domain new_btn: New blocked domain
reset_btn: Reset reset_btn: Reset
csv_btn: CSV

View file

@ -3,3 +3,4 @@ en:
contact_versions: contact_versions:
index: index:
reset_btn: Reset reset_btn: Reset
csv_btn: CSV

View file

@ -3,6 +3,7 @@ en:
contacts: contacts:
index: index:
reset_btn: Reset reset_btn: Reset
csv_btn: CSV
edit: edit:
new_status_btn: Add new status new_status_btn: Add new status

View file

@ -12,6 +12,7 @@ en:
title: Disputed domains title: Disputed domains
new_btn: New disputed domain new_btn: New disputed domain
reset_btn: Reset reset_btn: Reset
csv_btn: CSV
form: form:
password_hint: Generated automatically if left blank password_hint: Generated automatically if left blank

View file

@ -3,6 +3,7 @@ en:
domain_versions: domain_versions:
archive: archive:
reset_btn: Reset reset_btn: Reset
csv_btn: CSV
registrant_placeholder: Registrant registrant_placeholder: Registrant
registrant: Registrant registrant: Registrant

View file

@ -4,5 +4,6 @@ en:
index: index:
title: EPP log title: EPP log
reset_btn: Reset reset_btn: Reset
csv_btn: CSV
show: show:
title: EPP log title: EPP log

View file

@ -4,6 +4,7 @@ en:
index: index:
title: REPP log title: REPP log
reset_btn: Reset reset_btn: Reset
csv_btn: CSV
show: show:
title: REPP log title: REPP log

View file

@ -5,6 +5,7 @@ en:
title: Reserved domains title: Reserved domains
new_btn: New reserved domain new_btn: New reserved domain
reset_btn: Reset reset_btn: Reset
csv_btn: CSV
form: form:
password_hint: Generated automatically if left blank password_hint: Generated automatically if left blank

View file

@ -3,7 +3,7 @@ require 'application_system_test_case'
# /admin/blocked_domains # /admin/blocked_domains
class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCase class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCase
setup do setup do
WebMock.allow_net_connect! WebMock.allow_net_connect!
sign_in users(:admin) sign_in users(:admin)
@ -48,6 +48,19 @@ class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCa
assert_text @domain.name assert_text @domain.name
end end
def test_download_blocked_domains
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_blocked_domains_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="blocked_domains_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''blocked_domains_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
private private
def visit_admin_blocked_domains_path def visit_admin_blocked_domains_path

View file

@ -70,4 +70,17 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
assert_text 'Dispute already exists for this domain at given timeframe' assert_text 'Dispute already exists for this domain at given timeframe'
end end
def test_download_disputes
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_disputes_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="disputes_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''disputes_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end end

View file

@ -36,6 +36,19 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase
assert_match /#{date_now}/, epp_log_date assert_match /#{date_now}/, epp_log_date
end end
def test_download_epp_logs
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_epp_logs_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="epp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''epp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
private private
def send_epp_request_hello def send_epp_request_hello

View file

@ -15,9 +15,22 @@ class AdminAreaReppLogsIntegrationTest < ApplicationSystemTestCase
visit admin_repp_logs_path visit admin_repp_logs_path
get repp_v1_contacts_path get repp_v1_contacts_path
visit admin_repp_logs_path visit admin_repp_logs_path
find(:xpath, "//tbody/tr/td/a", match: :first).click find(:xpath, "//tbody/tr/td/a", match: :first).click
assert_text 'REPP log' assert_text 'REPP log'
end end
def test_download_repp_logs
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_repp_logs_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="repp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''repp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end end

View file

@ -12,7 +12,7 @@ class AdminAreaReservedDomainsIntegrationTest < JavaScriptApplicationSystemTestC
end end
def test_remove_reserved_domain def test_remove_reserved_domain
visit admin_reserved_domains_path visit admin_reserved_domains_path
click_link_or_button 'Delete', match: :first click_link_or_button 'Delete', match: :first
page.driver.browser.switch_to.alert.accept page.driver.browser.switch_to.alert.accept
@ -36,4 +36,17 @@ class AdminAreaReservedDomainsIntegrationTest < JavaScriptApplicationSystemTestC
assert_text 'Domain updated!' assert_text 'Domain updated!'
end end
def test_download_reserved_domains
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_reserved_domains_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="reserved_domains_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''reserved_domains_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end end

View file

@ -26,7 +26,7 @@ class ContactVersionsTest < ApplicationSystemTestCase
VALUES ('Contact', 75, 'update', '1-AdminUser', VALUES ('Contact', 75, 'update', '1-AdminUser',
'{"id": 75, "code": "test_code", "auth_info": "8b4d462aa04194ca78840a", "registrar_id": #{@registrar.id}, "old_field": "value", '{"id": 75, "code": "test_code", "auth_info": "8b4d462aa04194ca78840a", "registrar_id": #{@registrar.id}, "old_field": "value",
"legal_id": "123"}', "legal_id": "123"}',
'{"other_made_up_field": "value"}', '{"other_made_up_field": "value"}',
'2018-04-23 15:50:48.113491', '2018-04-23 12:44:56', '2018-04-23 15:50:48.113491', '2018-04-23 12:44:56',
'{"legal_documents":[null]}', null, null '{"legal_documents":[null]}', null, null
) )
@ -56,4 +56,17 @@ class ContactVersionsTest < ApplicationSystemTestCase
assert_text 'Best Names' assert_text 'Best Names'
assert_text '23.04.18, 18:50 update 1-AdminUser' assert_text '23.04.18, 18:50 update 1-AdminUser'
end end
def test_download_contact_history
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_contact_versions_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end end

View file

@ -39,4 +39,17 @@ class AdminContactsTest < ApplicationSystemTestCase
assert_text('Street Main Street City New York Postcode 12345 ' \ assert_text('Street Main Street City New York Postcode 12345 ' \
'State New York State Country United States of America') 'State New York State Country United States of America')
end end
def test_download_contacts
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_contacts_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="contacts_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''contacts_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end end

View file

@ -88,6 +88,19 @@ class DomainVersionsTest < ApplicationSystemTestCase
'http://www.example.com/admin/domain_versions?q[name]=shop.test&q[registrant]=&q[registrar]=&q[event]=&results_per_page=' 'http://www.example.com/admin/domain_versions?q[name]=shop.test&q[registrant]=&q[registrar]=&q[event]=&results_per_page='
end end
def test_download_domain_history
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_domain_versions_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
def test_search_event_param def test_search_event_param
# TODO # TODO
end end

View file

@ -12,7 +12,7 @@ class AdminAreaCsvTest < ApplicationSystemTestCase
travel_to Time.zone.parse('2010-07-05 10:30') travel_to Time.zone.parse('2010-07-05 10:30')
visit admin_domains_url visit admin_domains_url
click_link('CSV') click_link('CSV')
assert_equal "attachment; filename=\"domains.csv\"; filename*=UTF-8''domains.csv", response_headers['Content-Disposition'] assert_equal "attachment; filename=\"domains_#{Time.zone.now.to_formatted_s(:number)}.csv\"; filename*=UTF-8''domains_#{Time.zone.now.to_formatted_s(:number)}.csv", response_headers['Content-Disposition']
assert_equal expected_csv, page.body assert_equal expected_csv, page.body
end end
end end