【发布时间】:2011-08-02 12:44:15
【问题描述】:
我正在寻找一个奇怪问题的解决方案。我有一个控制器,需要身份验证(使用设计 gem)。我添加了 Devise TestHelpers,但无法正常工作。
require 'test_helper'
class KeysControllerTest < ActionController::TestCase
include Devise::TestHelpers
fixtures :keys
def setup
@user = User.create!(
:email => 'testuser@demomailtest.com',
:password => 'MyTestingPassword',
:password_confirmation => 'MyTestingPassword'
)
sign_in @user
@key = keys(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:keys)
end
test "should get new" do
get :new
assert_response :success
end
test "should create key" do
assert_difference('Key.count') do
post :create, :key => @key.attributes
end
assert_redirected_to key_path(assigns(:key))
end
test "should destroy key" do
assert_difference('Key.count', -1) do
delete :destroy, :id => @key.to_param
end
assert_redirected_to keys_path
end
结束
我在“rake 测试”窗口中得到以下输出:
29) Failure:
test_should_create_key(KeysControllerTest) [/test/functional/keys_controller_test.rb:29]:
"Key.count" didn't change by 1.
<3> expected but was
<2>.
30) Failure:
test_should_destroy_key(KeysControllerTest) [/test/functional/keys_controller_test.rb:37]:
"Key.count" didn't change by -1.
<1> expected but was
<2>.
31) Failure:
test_should_get_index(KeysControllerTest) [/test/functional/keys_controller_test.rb:19]:
Expected response to be a <:success>, but was <302>
32) Failure:
test_should_get_new(KeysControllerTest) [/test/functional/keys_controller_test.rb:25]:
Expected response to be a <:success>, but was <302>
有人可以告诉我,为什么设计不进行身份验证?我对 AdminController 使用完全相同的程序,并且效果很好。
【问题讨论】:
标签: ruby-on-rails authentication tdd device functional-testing