【发布时间】:2017-05-23 05:30:39
【问题描述】:
我正在尝试对我在控制器中使用的模型方法进行存根,但它似乎永远无法正常工作。有人可以告诉我正确的方法吗
用户控制器
if current_user.user_token
@user = @account.users.find(params[:id])
@user.revoke_seat(:admin, current_user)
render :template => "/admin/users/revoke_seat"
else
render :js => "window.location.href='#{server_url}/oauth/authorize?response_type=code&client_id=#{client_id}&state=#{request.referrer}?auto_revoke_seat=true&redirect_uri=#{auth_service_callback_url}";
end
Rspec
before do
users(:admin).stub(:internal_admin?).and_return(true)
login_as :admin
user.stub(:user_token).and_return("123123")# THIS IS NOT WORKING
end
it "should redirect to authentication service to generate access token" do
expect(user).to receive(:user_token).and_return(true)
xhr :put, :revoke_seat, account_id: account.id, id: user.id
expect(response).to render_template('admin/users/revoke_seat')
expect(assigns(:account)).to eq(account)
expect(assigns(:user)).to eq(user)
end
【问题讨论】:
标签: ruby-on-rails-3 rspec rspec-rails