Sha256: d9702b79729b1afd41976f2f656398adb491cc390b675a167bfaa12e9527354e

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'
describe ActiveAdmin::ResourceController do

  let(:mime) { Mime::Type.lookup_by_extension(:xlsx) }

  let(:request) do
    ActionController::TestRequest.new.tap do |test_request|
      test_request.accept = mime
    end
  end

  let(:response) { ActionController::TestResponse.new }

  let(:controller) do
    Admin::CategoriesController.new.tap do |controller|
      controller.request = request
      controller.response = response
    end
  end

  let(:filename) { "#{controller.resource_class.to_s.downcase.pluralize}-#{Time.now.strftime("%Y-%m-%d")}.xlsx" }

  it 'generates an xlsx filename' do
    controller.xlsx_filename.should == filename
  end

  context 'when making requests with the xlsx mime type' do
     it 'returns xlsx attachment when requested' do
      controller.send :index
      response.headers["Content-Disposition"].should == "attachment; filename=\"#{filename}\""
      response.headers["Content-Transfer-Encoding"].should == 'binary'
    end

    it 'returns max_csv_records for per_page' do
      controller.send(:per_page).should == controller.send(:max_csv_records)
    end

    it 'kicks back to the default per_page when we are not specifying a xlsx mime type' do
      controller.request.accept = 'text/html'
      controller.send(:per_page).should == ActiveAdmin.application.default_per_page
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin-axlsx-2.1.2 spec/axlsx/unit/resource_controller_spec.rb
activeadmin-axlsx-2.1.1 spec/axlsx/unit/resource_controller_spec.rb