2011-01-19 24 views
0

我在使用Devise的Rails應用程序中添加了username字段。我做了所有必要的步驟,例如將該字段添加到視圖,將其添加到User模型,遷移我的數據庫等。現在,當我手動運行註冊步驟時,一切正常。但只要我嘗試在黃瓜中編寫一個功能,我就會遇到一大堆錯誤。在使用黃瓜測試時添加自定義字段以設計問題

下面是錯誤的一個很短的名單上運行我的黃瓜功能

Scenario: New user registration with valid info # features/user_access.feature:7 
When I sign up as a new user with valid info # features/step_definitions/user_access_steps.rb:5 
    undefined method `username' for #<User:0x00000102f7dcf0> (ActionView::Template::Error) 
    /Users/Daniel/.rvm/gems/[email protected]/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing' 
    /Users/Daniel/.rvm/gems/[email protected]/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:in `method_missing' 
    /Users/Daniel/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1019:in `value_before_type_cast' 
    /Users/Daniel/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1007:in `value_before_type_cast' 
    /Users/Daniel/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `block in to_input_field_tag' 
    /Users/Daniel/.rvm/gems/[email protected]/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `fetch' 

我已經分離出的錯誤我的設計圖時,我得到。由於某種原因,黃瓜不喜歡以下幾行

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 
<%= devise_error_messages! % > 

<p><%= f.label :username %><br /> 
<%= f.text_field :username %></p> 

由於某些原因,黃瓜不會和用戶名標籤和text_field一起玩。我在我的黃瓜步驟中所做的所有工作都將進入註冊頁面,並嘗試填寫名稱爲username

任何想法是什麼導致這個錯誤,以及如何解決它?

回答

2

您是否更新了測試數據庫? rake db:test:prepare

+0

omg我覺得很蠢。謝謝! – Lan 2011-01-19 13:09:16