I want to make sure my CSV download contain the correct columns. When I test a CSV download with RSpec I cannot access the file contents. How do I access the contents of the CSV file?
require 'spec_helper'
include Devise::TestHelpers
describe Admin::ApplicationsController do
before(:each) do
@application = FactoryGirl.create :application
@user = FactoryGirl.create( :admin_user )
sign_in @user
end
it "downloads a csv"
it "gives us only the columns we want" do
get :index, format: :csv
p response.body
p response.headers
end
end
The output of the test:
# This is the output in the terminal
# ""
# {"Content-Type"=>"text/csv; charset=utf-8", "Content-Disposition"=>"attachment; filename=\"applications-2013-12-17.csv\""}
At your describe block call render_views
as in:
describe Admin::ApplicationsController do
render_views
... # all the other code
end
Calling render_views
instructs RSpec to render the view contents inside a controller spec. This is turned off by default because when you're running controller specs you usually don't care about the view contents and this makes your tests run faster.
You can see the official documentation for the latest Rails version here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With