製品コントローラーにbeforeフィルターがあります。
before_filter :authorize, only: [:create, :edit, :update]
私のauthorize
メソッドは私の中で次のように定義されてapplication_controller
います:
def authorize
redirect_to login_url, alert: "Not authorized" if current_user.nil?
end
current_userは次のように定義されます。
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
私のrspecでは、次のことを試みています。
before(:each) do
session.stub!(:user_id).and_return("admin@email.com")
end
しかし、私はまだ次のようなエラーが発生しています:
ProductsController PUT update with valid params redirects to the product
Failure/Error: response.should redirect_to(product)
Expected response to be a redirect to <http://test.host/products/1> but was a redirect to <http://test.host/login>
。。。これは、リクエスト時にテストがログインしていないことを意味します。
ここで何が欠けていますか?
この状況にアプローチするためのより良い方法はありますか?