我正在编写一个Rails应用,其中有一个Editor模型和一个Publication模型。我正在使用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中实现这个功能?谢谢。