Sha256: 10b68dc2b1983de0db4d854718d7a297c47882c0ddc8fea5c368d5ba8f15550f

Contents?: true

Size: 1.77 KB

Versions: 20

Compression:

Stored size: 1.77 KB

Contents

require 'csv'

Then "I should see nicely formatted datetimes" do
  expect(page.body).to match /\w+ \d{1,2}, \d{4} \d{2}:\d{2}/
end

Then /^I should( not)? see a link to download "([^"]*)"$/ do |negate, format|
  method = negate ? :to_not : :to
  expect(page).send method, have_css("#index_footer a", text: format)
end

# Check first rows of the displayed CSV.
Then /^I should download a CSV file with "([^"]*)" separator for "([^"]*)" containing:$/ do |sep, resource_name, table|
  body   = page.driver.response.body
  content_type_header, content_disposition_header = %w[Content-Type Content-Disposition].map do |header_name|
    page.response_headers[header_name]
  end
  expect(content_type_header).to eq 'text/csv; charset=utf-8'
  expect(content_disposition_header).to match /\Aattachment; filename=".+?\.csv"\z/

  begin
    csv = CSV.parse(body, col_sep: sep)
    table.raw.each_with_index do |expected_row, row_index|
      expected_row.each_with_index do |expected_cell, col_index|
        cell = csv.try(:[], row_index).try(:[], col_index)
        if expected_cell.blank?
          expect(cell).to be_nil
        else
          expect(cell || '').to match /#{expected_cell}/
        end
      end
    end
  rescue
    puts "Expecting:"
    p table.raw
    puts "to match:"
    p csv
    raise $!
  end
end

Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_name, table|
  step %{I should download a CSV file with "," separator for "#{resource_name}" containing:}, table
end

Then /^the CSV file should contain "([^"]*)" in quotes$/ do |text|
  expect(page.driver.response.body).to match /"#{text}"/
end

Then /^the encoding of the CSV file should be "([^"]*)"$/ do |text|
  expect(page.driver.response.body.encoding).to be Encoding.find(Encoding.aliases[text] || text)
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/features/step_definitions/format_steps.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.17.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.16.pre features/step_definitions/format_steps.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/features/step_definitions/format_steps.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/features/step_definitions/format_steps.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.15.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.14.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.13.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.12.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.11.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.10.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.9.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.8.pre features/step_definitions/format_steps.rb
activeadmin-1.0.0.pre2 features/step_definitions/format_steps.rb
activeadmin-1.0.0.pre1 features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.7.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.6.pre features/step_definitions/format_steps.rb
yousty-activeadmin-1.0.5.pre features/step_definitions/format_steps.rb