我正在尋找一個奇怪問題的解決方案。我有一個控制器,需要認證(與設計寶石)。我添加了設計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