Rails3 路由和基于 yaml 的 API,使用 devise 和 cancan
我有一个具有 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 中看不到任何特定于格式的内容,但也许我错过了它。
I have an 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误在于 :format=>:yaml 需要进入第一个哈希,而不是进入第二个哈希以获得 get。所以:
The fault was that :format=>:yaml needs to go into the first hash, rather than into the second hash for get. So: