Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a nicer way to set POST body data in rspec on rails?

Than request.env['RAW_POST_DATA'] = json_body?

like image 558
avocade Avatar asked Feb 24 '11 12:02

avocade


1 Answers

I'm not sure if this is what you mean, but you can set the request headers to indicate JSON:

  describe "POST 'create'" do
    it "should be successful" do
      request.env["HTTP_ACCEPT"] = "application/json"
      post 'create', :article => { :title => "Foo" }.to_json
      response.should be_success
    end
  end
like image 161
zetetic Avatar answered Nov 12 '22 11:11

zetetic