【发布时间】:2011-08-09 03:59:47
【问题描述】:
我正在编写一个 Rails 应用程序,其中有一个 Editor 和一个 Publication 模型。我正在使用设计进行编辑器身份验证,并且由于编辑器不能以访客身份执行任何操作,因此我编写了一个自定义布局用于登录页面,并且我希望访客用户只能看到登录页面。
现在我试图在我的应用中实现以下行为但没有成功:
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
主要问题是我想摆脱“您需要先登录或注册才能继续”。访客用户访问“/”时的消息。
我尝试使用来自 here 和 here 的提示,但没有成功。
关于如何用设计实现这一点的任何提示?
谢谢。
【问题讨论】:
-
听起来你可以创建一个命名空间......你考虑过这个吗?
-
什么意思?你能解释一下吗?谢谢。
标签: ruby-on-rails routes devise