테스트 시나리오를 작성하기 위해 튜토리얼을 따랐습니다. 사용자가 정보 페이지를 편집하지만 아직 로그인하지 않은 경우 리디렉션됩니다. 페이지에 로그인하고 로그인 한 후 수정 페이지로 리디렉션됩니다. 하지만 튜토리얼처럼 모두 끝내면 wrong number of arguments (0 for 1)
오류가 발생하므로 테스트를 실행하고 실패합니다. RoR Tutorial 9 장 (9.2.3 절) 잘못된 인수 수 (0은 1)
이
오류 정보입니다 : 내가 가진이 내 사양/요청/authentication_pages_spec.rb 응용 프로그램/도우미/sessions_helper.rb에서describe "authorization" do
describe "for non-signed-in users" do
let(:user) { FactoryGirl.create(:user) }
describe "when attempting to visit a protected page" do
before do
visit edit_user_path(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
page.should have_selector('title', text: 'Edit user')
end
end
end
.
.
.
입니다
AuthenticationPages authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
Failure/Error: click_button "Sign in"
ArgumentError: wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:31:inredirect_back_or'
create'
# ./app/controllers/sessions_controller.rb:11:in
# (eval):2:inclick_button' # ./spec/requests/authentication_pages_spec.rb:58:in
block (5 levels) in..
두 가지 방법, store_location
및 redirect_back_or
을 저장하고 로그인하기 전에 사용자가 방문한 URL 주소로 다시 리디렉션 :
module SessionsHelper
.
.
.
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete[:return_to]
end
def store_location
session[:return_to] = request.url
end
end
그럼 내가 응용 프로그램/컨트롤러/users_controller.rb에서 store_location
방법 사용 :
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:edit, :update]
before_filter :correct_user, only: [:edit, :update]
.
.
private
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
을 그리고 난 애플 리케이션/컨트롤러/sessions_controller.rb에서 redirect_back_or
방법 사용 :
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:email].downcase)
if user && user.authenticate(params[:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = "Invalid email/password combination"
render 'new'
end
end
모르겠다을 이 오류가 발생하는 이유는, 내가 redirect_back_or
메서드는 이미 인수가 user
걸릴 생각하지만 여전히 오류가 있다고 생각합니다. 아무도 내가이 문제를 해결하도록 도울 수 있니? 정말 고마워.
감사에 대한 SessionsHelper이
session.delete[:return_to]
: D – Thanh