我正在关注 rails_admin 自述文件。我已经设置了 devise 和 cancan,只有组 admin 的用户可以访问 rails_admin。这是测试
test "try to access rails_admin as a non admin user" do
get_via_redirect '/users/auth/facebook'
assert_response :success
assert_match 'Successfully authenticated', flash[:notice]
puts User.all.count
puts User.first.name
puts Group.find(User.first.group_id).name
assert_equal Ability.new(User.first).can?(:access, :dashboard), false
puts session
get '/admin'
assert_response :found
assert_redirected_to '/'
assert_match 'You are not authorized', flash[:alert]
end
当我运行 'ruby -Itest test/integration/test.rb' 时全部通过。输出是
1
Facebook User
user
{"session_id"=>"5345e64582b2557d0d02cd2011461467", "warden.user.user.key"=>["User", [2], "$2a$04$B.nVokuCXSWOpZ2Ezf60Cu"], "flash"=>#<ActionDispatch::Flash::FlashHash:0xb49d9a4 @used=#<Set: {:notice}>, @closed=false, @flashes={:notice=>"Successfully authenticated from facebook account."}, @now=nil>}
当我运行“bundle exec rake test:integration”时,测试失败。输出是
1
Facebook User
user
{"session_id"=>"0005d96c17c75d0843166e5dbb4dcc05", "warden.user.user.key"=>["User", [3], "$2a$04$4f5/I9uSZbMWBdCgDA086O"], "flash"=>#<ActionDispatch::Flash::FlashHash:0xa4c0db0 @used=#<Set: {:notice}>, @closed=false, @flashes={:notice=>"Successfully authenticated from facebook account."}, @now=nil>}
F.
Finished tests in 1.054687s, 3.7926 tests/s, 24.6519 assertions/s.
1) Failure:
test_try_to_access_rails_admin_as_a_non_admin_user(RailsAdminTest):
Expected response to be a <:found>, but was <200>
我也试过“assert_select 'body', 'something'”。运行 rake test:integration 时,它会输出一些 html,例如标准 rails_admin dashborad 页面。看起来用户有权访问 rails_admin。
我正在使用 rails 3.2.6、devise 2.1.2、cancan 1.6.8、rails_admin 0.0.5
有任何想法吗?谢谢。