Sha256: 87e49e2d97074bb09887c2806a624bfbda0bcb7346f7be3e731591dfa606b9b5

Contents?: true

Size: 1.79 KB

Versions: 47

Compression:

Stored size: 1.79 KB

Contents

CSVLib = if RUBY_VERSION =~ /^1.8/
            require 'fastercsv'
            FasterCSV
          else
            require 'csv'
            CSV
          end

Then "I should see nicely formatted datetimes" do
  page.body.should =~ /\w+ \d{1,2}, \d{4} \d{2}:\d{2}/
end

Then /^I should see a link to download "([^"]*)"$/ do |format_type|
  page.should have_css("#index_footer a", :text => format_type)
end

Then /^I should not see a link to download "([^"]*)"$/ do |format_type|
  page.should_not have_css("#index_footer a", :text => format_type)
end

# Check first rows of the displayed CSV.
Then /^I should download a CSV file with "([^"]*)" separator for "([^"]*)" containing:$/ do |sep, resource_name, table|
  page.response_headers['Content-Type'].should == 'text/csv; charset=utf-8'
  csv_filename = "#{resource_name}-#{Time.now.strftime("%Y-%m-%d")}.csv"
  page.response_headers['Content-Disposition'].should == %{attachment; filename="#{csv_filename}"}
  body = page.driver.response.body

  begin
    csv = CSVLib.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?
          cell.should be_nil
        else
          (cell || '').should 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|
  body = page.driver.response.body
  body.should match(/\"#{text}\"/)
end

Version data entries

47 entries across 47 versions & 2 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/features/step_definitions/format_steps.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/features/step_definitions/format_steps.rb