我可以在运行rails server
后打开视图,我会看到新创建的billing_name文本字段,如下所示,它可以正常工作。
视图/注册/ new.html.erb
<h2>My New Signup</h2>
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<p><%= f.label :email %><br />
<%= f.email_field :email %></p>
<p><%= f.label :password %><br />
<%= f.password_field :password %></p>
<p><%= f.label :password_confirmation, 'Password Confirmation' %><br />
<%= f.password_field :password_confirmation %></p>
<p><%= f.label :billing_name, 'Billing Name' %><br />
<%= f.text_field :billing_name %></p>
<p><%= f.submit "Sign up" %></p>
<% end %>
但是,当我运行我的规范时,它似乎在查看默认设计视图,但找不到新创建的billing_name字段。如果我在我的规范中尝试访问该字段之前save_and_open_page
显示默认设计注册页面,即使我运行rails server -e test
时,它也会显示我的新自定义视图。
以下是规范:
规格/请求/ registration_spec.rb
require 'spec_helper'
describe "Registraion" do
describe "GET /signup" do
it "allows signup with proper credentials" do
visit signup_path
fill_in "user_email", :with => "sample@email.com"
fill_in "user_password", :with => "password"
fill_in "user_password_confirmation", :with => "password"
save_and_open_page
fill_in "user_billing_name", :with => "First Last"
end
end
end
我的规范助手就是自动生成的基本助手:
规格/ spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
end
答案 0 :(得分:0)
当您覆盖Devise控制器时,请务必覆盖devise_for路由。
例如(在routes.rb中):
devise_for :users, :controllers => { :registrations => 'registrations' }
Devise wiki也有一个example。