1

我的测试如下:

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>.

关于我做错了什么的任何想法?

4

1 回答 1

4

我会替换:

after_value = user.admin

和:

after_value = user.reload.admin
于 2012-08-31T19:29:34.700 回答