2013-08-05 2 views
3

Hartl의 레일 튜토리얼 9.2.1 절에서 작업 중입니다. 내 검사가 통과하지 못했습니다. 이유를 알아낼 수 없습니다. 누군가가 도움이되기를 바랍니다. 비 로그인 한 사용자에게 사용자의 컨트롤러가를 방문해hartl 튜토리얼 9.2.1 끝 시험 실패

1) 인증의 인증 : 나는

실패 아래의 오류 메시지와 두 개의 관련 파일 1) authentication_pages_spec.rb 2) users_controller.rb를 첨부 수정 페이지 오류/오류 : {have have_title ('로그인')} 예상 #has_title? ("로그인") 참을 반환하고 거짓을 받음 # ./spec/requests/authentication_pages_spec.rb:57:in '블록 (6 수준)'

2) 업데이트 작업에 제출하는 사용자 컨트롤러에서 로그인하지 않은 사용자에 대한 인증 권한 부여 장애/오류 : 찾을 수 없습니다 PARAM : 사용자 # ./app/controllers/users_controller.rb:40:in user_params' # ./app/controllers/users_controller.rb:27:in 갱신 ' #의 ./spec/requests {패치 user_path (사용자)} ActionController :: ParameterMissing 전

RSpec에 ./spec/requests/authentication_pages_spec : 2.08 초 60 실시 예 2 개 실패

실패 예에서 마무리

'에서 블록 (6 단계)`/authentication_pages_spec.rb:61:in. rb : 57 # 서명되지 않은 서명에 대한 인증 권한 부여 대한 편집 페이지 RSpec에 ./spec/requests/authentication_pages_spec.rb:62 # 인증 권한 부여를 방문하는 사용자 컨트롤러의 사용자 비 로그인으로 업데이트 작업

내 authentication_pages_spec.rb에 제출하는 사용자 컨트롤러의 사용자 이다

require 'spec_helper' 

describe "Authentication" do 

subject { page } 


describe "signin page" do 
    before { visit signin_path } 

    it { should have_content('Sign in') } 
    it { should have_title('Sign in') } 
    end 


describe "signin" do 
     before { visit signin_path } 

     describe "with invalid information" do 
      before { click_button "Sign in" } 

      it { should have_title('Sign in') } 
      it { should have_selector('div.alert.alert-error', text: 'Invalid') } 

      describe "after visiting another page" do 
       before { click_link "Home" } 
       it { should_not have_selector('div.alert.alert-error') } 
      end 
      end 

    describe "with valid information" do 
     let(:user) { FactoryGirl.create(:user) } 
     before { sign_in user } 

     it { should have_title(user.name) } 
     it { should have_link('Profile',  href: user_path(user)) } 
     it { should have_link('Settings', href: edit_user_path(user)) } 
     it { should have_link('Sign out', href: signout_path) } 
     it { should_not have_link('Sign in', href: signin_path) } 


    describe "followed by signout" do 
     before { click_link "Sign out" } 
     it { should have_link('Sign in') } 
     end 
    end 
    end 

    describe "authorization" do 
    describe "for non-signed-in users" do 
     let(:user) { FactoryGirl.create(:user) } 

     describe "in the Users controller" do 

     describe "visiting the edit page" do 
      before { visit edit_user_path(user) } 
      it { should have_title('Sign in') } 
     end 

     describe "submitting to the update action" do 
      before { patch user_path(user) } 
      specify { expect(response).to redirect_to(signin_path) } 
     end 
     end 
    end 
    end   
end 

users_controller.rb 당신은 당신의 users_controller.rb의 2 행에 당신의 signed_in_user 필터로 전화를 누락

class UsersController < ApplicationController 

def show 
@user = User.find(params[:id]) 
end 

def new 
@user = User.new 
end 

def create 
    @user = User.new(user_params) 
    if @user.save 
    flash[:success] = "Welcome to the Sample App!" 
    redirect_to @user 
    else 
    render 'new' 
    end 
end 

def edit 
    @user = User.find(params[:id]) 
    end 

def update 
    @user = User.find(params[:id]) 
    if @user.update_attributes(user_params) 
    flash[:success] = "Profile updated" 
    sign_in @user 
    redirect_to @user  
    else 
    render 'edit' 
    end 
end 


private 

    def user_params 
    params.require(:user).permit(:name, :email, :password, 
           :password_confirmation) 
    end 

    # Before filters 

    def signed_in_user 
    redirect_to signin_url, notice: "Please sign in." unless signed_in? 
    end  
end 
+1

유용 할 경우 aanswer를 수락해야합니다 ... – frandroid

답변

4

입니다. 컨트롤러 끝에서 필터를 정의했지만 호출하지 않았습니다! :) 튜토리얼의 맨 끝에

, 그 라인은 다음과 같아야합니다

before_action :signed_in_user, only: [:index, :edit, :update, :destroy, :following, :followers] 

을 그러나 아직 추종자를 작성하지 않은 이후로, 내가 이런 식으로 뭔가 보일 것입니다 생각 :

before_action :signed_in_user, only: [:index, :edit, :update, :destroy] 

하드 드라이브에 코드의 최종 소스를 복사하는 것이 매우 유용하므로이 책을 읽는 동안 버그가 발생할 때마다 원본과 코드를 비교할 수 있습니다.

관련 문제