DEV Community

Augusts Bautra
Augusts Bautra

Posted on

How to test `send_data` in request specs

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
Enter fullscreen mode Exit fullscreen mode
expect(response.headers['Content-Disposition'])
  .to eq 'attachment; filename=users-2020-10-23.csv'

expect(response.body).to eq some_path.read
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Feature flag article image

Create a feature flag in your IDE in 5 minutes with LaunchDarkly’s MCP server 🏁

How to create, evaluate, and modify flags from within your IDE or AI client using natural language with LaunchDarkly's new MCP server. Follow along with this tutorial for step by step instructions.

Read full post

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay