Другой корневой путь '/' для пользователей в зависимости от того, аутентифицированы ли они (с помощью devise )

Я пишу приложение rails, в котором у меня есть редактор и публикация модель. Я использую devise для аутентификации редакторов, и, поскольку редактор ничего не может делать в качестве гостя, я написал собственный макет для использования для страницы входа и хочу, чтобы гостевой пользователь мог видеть только страницу входа.

Теперь Я пытаюсь добиться в своем приложении следующего поведения, но безуспешно:

require 'spec_helper'
require 'capybara/rails'

describe "Authentication" do

  describe "when logged in" do
    before(:each) do
      @editor = Factory(:editor, :password => 'secret')
      visit '/'
      fill_in 'Login', :with => @editor.login
      fill_in 'Password', :with => 'secret'
      click_button 'Sign in'
      page.should have_content('Signed in successfully.')
    end

    it "getting / should render publication page with no redirection" do
      visit '/'
      page.should_not have_content('Login')
      page.should have_content('Publications')
      # assert that there is no redirection
      page.current_path.should == '/'
    end

    it "visits the sign_in page should redirect to /" do
      visit '/editors/sign_in'
      page.should have_content('Publications')
      page.current_path.should == '/'
    end

  end

  describe "when not logged in" do
    it "getting / should not display the sign in warning" do
      visit '/'
      # I want to get rid of this message
      page.should_not have_content('You need to sign in or sign up before continuing.')
    end

    it "getting / should not redirect to the sign_in default page" do
      visit '/'
      page.should have_content('Login')
      # assert that there is no redirection
      page.current_path.should == '/'
    end

    it "getting the the sign_in default path works" do
      visit '/editors/sign_in'
      page.should have_content('Login')
      page.current_path.should == '/editors/sign_in'
    end

    it "login works and redirect me to the publications page (with /)" do
      @editor = Factory(:editor, :password => 'secret')
      visit '/'
      fill_in 'Login', :with => @editor.login
      fill_in 'Password', :with => 'secret'
      click_button 'Sign in'
      page.should have_content('Signed in successfully.')
      page.current_path.should == '/'
      page.should have_content('Publications')
    end
  end
end

Основная проблема заключается в том, что я хочу избавиться от «Вам необходимо войти или зарегистрироваться, прежде чем продолжить». сообщение, когда гостевой пользователь посещает '/'.

Я пробовал с подсказками, взятыми из здесь и здесь , но безуспешно.

Любой намек на то, как реализовать это с помощью devise ?

Спасибо.

16
задан Community 23 May 2017 в 12:18
поделиться