开发者

Problem adding a custom field to Devise while testing with cucumber

I added a username field to my Rails app that's using Devise. I did all the necessary steps like adding the field to the views, adding it to the User model, migrating my database, etc. Now, when I run through the registration steps manually everything works fine. But as soon as I try to write a feature in Cucumber I get a huge page of errors.

Here's a very short list of the errors I get when running my cucumber feature

  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/ruby-1.9.2-p136@Flow1/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
  /Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:in `method_missing'
  /Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1019:in `value_before_type_cast'
  /Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1007:in `value_before_type_cast'
  /Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `block in to_input_field_tag'
  /Users/Daniel/.rvm/gems/ruby-1.9.2-p136@Flow1/g开发者_Go百科ems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `fetch'

I have isolated the error to my Devise view. For some reason cucumber doesn't like the following lines

<%= 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>

For some reason cucumber wont play nice with the :username label and text_field. All I am doing in my cucumber steps is going to the registration page and trying to fill in username with a name.

Any idea what is causing this error and how to fix it?


Have you updated the test database? rake db:test:prepare

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜