我正在寻找一个奇怪问题的解决方案。我有一个控制器,需要认证(与设计宝石)。我添加了设计TestHelpers,但我无法得到它的工作。设计认证的Ruby on Rails功能测试
require 'test_helper'
class KeysControllerTest < ActionController::TestCase
include Devise::TestHelpers
fixtures :keys
def setup
@user = User.create!(
:email => '[email protected]',
: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
末
和我在我的“耙测试”窗口中下面的输出:
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使用完全相同的过程,它的工作原理非常完美。
太棒了!是的,我正在使用可确认的设置。既然像你描述的那样改变它,它就像一个魅力。 :) – axx 2011-04-10 16:35:52
这真的有用吗?我的意思是,设计在将密码放入数据库之前对密码进行加密,并且据我所知,夹具直接写入数据库。这意味着解密应该失败(因为abcdef1不能正确解密)。 – 2011-10-27 11:34:43
陈旧。不适用于较新的设计。 – oma 2012-02-23 12:53:51