我的测试如下:
test "should post make_admin" do
user = FactoryGirl.create(:user, admin: true)
sign_in(user)
before_value = user.admin
post :make_admin, id: user.id
after_value = user.admin
assert_not_equal before_value, after_value
assert_response :redirect
end
,控制器如下所示:
def make_admin
user = User.find_by_id(params[:id])
user.toggle!(:admin)
redirect_to static_pages_user_index_path
end
然而我一直收到这个错误:
Failure:
test_should_post_make_admin(StaticPagesControllerTest) [..../functional/static_pages_controller_test.rb:48]:
<true> expected to be != to
<true>.
关于我做错的任何想法?
答案 0 :(得分:4)
我会替换:
after_value = user.admin
使用:
after_value = user.reload.admin