首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rails教程,Michael Hartl Ch 11

rails教程,Michael Hartl Ch 11
EN

Stack Overflow用户
提问于 2014-03-04 00:51:29
回答 1查看 444关注 0票数 0

嗨,我正在完成这是红宝石 on rails。

我只是想把它弄完,所以我熬夜把它结束了。瞧,编码虽然累了,但我犯了一个愚蠢的错误,现在我找不到了。这可能很简单,但我就是看不见。

我在11.2.5部分之后的某个地方犯了错误

当我运行bundle exec rspec规范/我得到以下错误

代码语言:javascript
复制
  1) Authentication authorization for non-signed-in users in the Users controlle
r visiting the following page
     Failure/Error: it { should have_title('Sign in') }
       expected #has_title?("Sign in") to return true, got false
     # ./spec/requests/authentication_pages_spec.rb:55:in `block (6 levels) in <
top (required)>'

  2) Authentication authorization for non-signed-in users in the Users controlle
r visiting the followers page
     Failure/Error: it { should have_title('Sign in') }
       expected #has_title?("Sign in") to return true, got false
     # ./spec/requests/authentication_pages_spec.rb:60:in `block (6 levels) in <
top (required)>'

Finished in 16.24 seconds
142 examples, 2 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:55 # Authentication authoriza
tion for non-signed-in users in the Users controller visiting the following page

rspec ./spec/requests/authentication_pages_spec.rb:60 # Authentication authoriza
tion for non-signed-in users in the Users controller visiting the followers page

这是我的authentication_pages_spec.rb:

代码语言:javascript
复制
   require 'spec_helper'

describe "Authentication" do

  subject { page }

  describe "signin page" 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') }

      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('Users',       href: users_path) }
      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) }
    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
        describe "visiting the user index" do
          before { visit users_path }
          it { should have_title('Sign in') }
        end
         describe "visiting the following page" do
          before { visit following_user_path(user) }
          it { should have_title('Sign in') }
        end

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


    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
            expect(page).to have_title('Edit user')
          end
        end
  end



    describe "in the Microposts controller" do

        describe "submitting to the create action" do
          before { post microposts_path }
          specify { expect(response).to redirect_to(signin_path) }
        end

        describe "submitting to the destroy action" do
          before { delete micropost_path(FactoryGirl.create(:micropost)) }
          specify { expect(response).to redirect_to(signin_path) }
        end
    end

    describe "in the Relationships controller" do
        describe "submitting to the create action" do
          before { post relationships_path }
          specify { expect(response).to redirect_to(signin_path) }
    end

    describe "submitting to the destroy action" do
          before { delete relationship_path(1) }
          specify { expect(response).to redirect_to(signin_path) }
    end
    end
  end


  describe "as wrong user" do
      let(:user) { FactoryGirl.create(:user) }
      let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
      before { sign_in user, no_capybara: true }

      describe "submitting a GET request to the Users#edit action" do
        before { get edit_user_path(wrong_user) }
        specify { expect(response.body).not_to match(full_title('Edit user')) }
        specify { expect(response).to redirect_to(root_url) }
      end

      describe "submitting a PATCH request to the Users#update action" do
        before { patch user_path(wrong_user) }
        specify { expect(response).to redirect_to(root_url) }
      end
    end
      describe "as non-admin user" do
      let(:user) { FactoryGirl.create(:user) }
      let(:non_admin) { FactoryGirl.create(:user) }

      before { sign_in non_admin, no_capybara: true }

      describe "submitting a DELETE request to the Users#destroy action" do
        before { delete user_path(user) }
        specify { expect(response).to redirect_to(root_url) }
      end
    end
end
end

我认为这个文件有问题,但是如果您想看到我的其他文件,只需注释一下,我就会在这里发布代码。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-04 01:06:17

你是否在你的before_action中添加了:跟随者和:追随者?

代码语言:javascript
复制
before_action :signed_in_user,
            only: [:index, :edit, :update, :destroy, :following, :followers]
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22160724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档