I'm working on a Rails application having a REST API in JSON format and versioned (according to this excellent Ryan's cast: #350 REST API Versioning - RailsCasts).
For instance, there is a spec/requests spec:
require 'spec_helper'
describe "My Friends" do describe "GET /my/friends.json" do it "should get my_friends_path" do get v1_my_friends_path, {}, {'HTTP_ACCEPT' => 'application/vnd.myapp+json; level=1'} response.status.should be(401) end end end
And it works well. But (keeping this example) how can we write the routing spec? For instance this spec isn't correct:
require 'spec_helper'
describe "friends routing" do it "routes to #index" do get("/my/friends.json", nil, {'HTTP_ACCEPT' => 'application/vnd.myapp+json; level=1'}). should route_to({ action: "index", controller: "api/v1/private/my/friends", format: "json" }) end end
...because `get` can take only 1 param.
I tried different ways (such as with request.headers['Accept'] or @request.headers['Accept']... where request is undefined and @request is nil). I really don't see how to do.
I'm on Ruby 1.9.3, Rails 3.2.6 and rspec-rails 2.11.0. Thanks.