Originally in Andrew Smith's blog. https://www.andrewsouthpaw.com/testing-an-attachment-with-rspec-and-controllers/
def index
@users = User.all
respond_to do |format|
format.csv { send_data @users.to_csv, filename: "users-#{Date.today}.csv" }
end
end
expect(response.headers['Content-Disposition'])
.to eq 'attachment; filename=users-2020-10-23.csv'
expect(response.body).to eq some_path.read
Top comments (0)