0

パスの質問を見ましたが、問題を解決する質問が見つかりませんでした。これらの失敗したテストを取得します。ブラウザ経由でユーザーのインデックス ページにアクセスしたところ、サインインのタイトルが表示されました。

Failures:

1) authorization for non-signed-in users in the Users controller visiting the edit page 
 Failure/Error: it { should have_selector('title', text: 'Sign in') }
   expected css "title" with text "Sign in" to return something
 # ./spec/requests/authentication_pages_spec.rb:75:in `block (5 levels) in <top (required)>'

2) authorization for non-signed-in users in the Users controller visiting the user index 
 Failure/Error: it { should have_selector('title', text: 'Sign in') }
   expected css "title" with text "Sign in" to return something
 # ./spec/requests/authentication_pages_spec.rb:85:in `block (5 levels) in <top (required)>'

Finished in 4.65 seconds
69 examples, 2 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:75 # authorization for non-signed-in 
users in the Users controller visiting the edit page 

rspec ./spec/requests/authentication_pages_spec.rb:85 # authorization for non-signed-in 
users in the Users controller visiting the user index 

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


    describe "in the Users controller" do

      let(:user) { FactoryGirl.create(:user) }

      describe "visiting the edit page" do
        before { visit edit_user_path(user) }
        it { should have_selector('title', text: 'Sign in') }
      end

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

      describe "visiting the user index" do
        before { visit users_path }
        it { should have_selector('title', text: 'Sign in') }
      end
    end

Routes.rb

SampleApp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]

root to: 'static_pages#home'

match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete

match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'

users_controllers.rb

    class UsersController < ApplicationController
      before_filter :signed_in_user, 
                    only: [:index, :edit, :update]
      before_filter :correct_user, only: [:edit, :update]

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

      def new
        @user = User.new
      end

      def index
        @users = User.all
      end

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

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

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

      private

      def correct_user
        @user = User.find(params[:id])
        redirect_to(root_path) unless current_user?(@user)
      end  
    end

前もって感謝します

4

1 に答える 1