开发者

rails3 routing and yaml based API, using devise and cancan

开发者 https://www.devze.com 2023-03-28 08:27 出处:网络
I have an开发者_如何学Python application that will have an API, with a /api/v1/ namespace: namespace :api do

I have an开发者_如何学Python application that will have an API, with a /api/v1/ namespace:

namespace :api do
  namespace :v1 do
    resources :gateways do
      resources :mappings do
        # maybe more stuff
      end
    end
  end
end

my application uses devise and cancan.

My mappings controller down in app/controllers/api/v1/mappings_controller.rb works correctly from rspec test cases if I leave out :format=>:yaml (asking for HTML, and getting a 406). If I ask for :yaml, devise seems to think that my test user is not allowed.

My test case is stupid simple:

  describe "Agent access to mappings" do
    it "gets a list of mappings that includes test_user mapping" do
      @test_agent = users(:firewallagent)
      sign_in(@test_agent)    
      get :show, {:gateway_id => 1, :id => 2} #, :format => :yaml
      assert_response 200
    end
  end

I can't see anything in devise/warden which would be format specific, but maybe I've missed it.


The fault was that :format=>:yaml needs to go into the first hash, rather than into the second hash for get. So:

get :show, {:gateway_id => 1, :id => 2, :format => :yaml}
0

精彩评论

暂无评论...
验证码 换一张
取 消