Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need a custom Devise controller if only changing the Sign Up view?

I have the following steps in a capybara/rspec integration test, that is simply trying to sign up a new member.

 visit new_member_registration_path
 fill_in('Name:',                     :with => 'Rob Doe' )
 fill_in('member_email',              :with => '[email protected]' )
 fill_in('member_email_confirmation', :with => '[email protected]' )
 fill_in('member_password',           :with => 'secret')
 fill_in('Company or Venue Name:',    :with => 'Rob Inc.')
 fill_in('Contact Number:',           :with => '040544404440')
 click_button('Sign up')
 save_and_open_page

For some reason the 'email' and 'password' data is not being passed to the DeviseRegistrations controller (it is blank when viewing the test log) and therefore causing the validation to fail. However up until the save_and_open_page there is no rspec errors (so those fields are being filled in).

What am I missing? Do I need to subclass the DeviseRegistrations controller?

Tested on Rails 3.0.7 with rack-test 0.5.7 and rails 3.1rc1 and rack-test 0.6.0

like image 624
robzolkos Avatar asked May 18 '11 01:05

robzolkos


People also ask

Does every model need a controller?

You need a controller just when you have request actions on the relative model; When a model is just for data calculation and basic business logic implementation, don't generate the controller.

Does devise work with Rails 7?

Our out-of-the box Devise setup is now working with Rails 7. Once again, if you'd like to refer to any of the code for this setup, or use the template wholesale for a new app, the code is available on GitHub, and you may also use it as a template repo to kick off your own Rails 7 devise projects.


2 Answers

Assuming you have debugger in your Gemfile, here's how you can use it. (This assumes you're using the Rack driver for Capybara.)

# test.rb
visit new_member_registration_path
fill_in('Name:',                     :with => 'Rob Doe' )
debugger

The terminal will stop your script and wait for you to do something.

# Terminal
/file/path/to/you/test.rb:12
fill_in('Name:',                     :with => 'Rob Doe' )
(rdb:1)

Open up an IRB session here:

(rdb:1) irb

You can do any RSpec or Capybara method here:

>> current_path.should == 'foo/bar'

Try submitting the form at this point:

>> click_button "Sign Up"
>> save_and_open_page

See what error messages Devise gave to you on the resulting page. With the Rack driver, you won't see the fields being filled in. In that case, you might want to try using the Selenium driver

# test.rb
Capybara.default_driver = :selenium
visit new_member_registration_path

However, you can't drive Capybara from IRB using the Selenium driver. You will, though, be able to see what form values Selenium is putting into your form. Since things happen quickly with Selenium, you can use debugger to pause the test, while you inspect the page that Selenium opened up in your browser.

like image 51
monocle Avatar answered Sep 29 '22 10:09

monocle


The problem was in the application layout file. I had another (albeit hidden) form that was posting the blank form fields.

After I created a blank project and saw that it worked perfectly, I peeled back all the potential parts of my app until I found the culprit.

So the answer to the question is, no, a custom devise controller is not required when you are using custom devise views.

like image 45
robzolkos Avatar answered Sep 29 '22 12:09

robzolkos