【问题标题】:rails3 routing and yaml based API, using devise and cancanrails3 路由和基于 yaml 的 API,使用 devise 和 cancan
【发布时间】:2011-08-13 01:59:57
【问题描述】:

我有一个应用程序,它有一个 API,带有 /api/v1/ 命名空间:

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

我的应用程序使用 devise 和 cancan。

如果我遗漏 :format=>:yaml (请求 HTML 并获得 406),我在 app/controllers/api/v1/mappings_controller.rb 中的映射控制器可以从 rspec 测试用例正常工作。 如果我要求 :yaml,devise 似乎认为我的测试用户是不允许的。

我的测试用例很简单:

  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

我在 devise/warden 中看不到任何特定于格式的内容,但也许我错过了。

【问题讨论】:

    标签: ruby-on-rails-3 devise cancan


    【解决方案1】:

    错误在于 :format=>:yaml 需要进入第一个哈希,而不是进入第二个哈希以获得获取。所以:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多