How to write controller tests when you override devise registration controller?

THe problem is that Devise is unable to map routes from the test back to the original controller. That means that while your app actually works fine if you open it in the browser, your controller tests will still fail.

Up vote 3 down vote favorite share g+ share fb share tw.

I wish to override the Devise::RegistrationsController to implement some custom functionalality. To do this, I've created a new RegistrationsController like so: # /app/controllers/registrations_controller. Rb class RegistrationsController { :registrations => "registrations" } and tried to test it like this: describe RegistrationsController do describe "GET 'new'" do it "should be successful" do get :new response.

Should be_success end end end but that gives me an error: 1) RegistrationsController GET 'new' should be successful Failure/Error: get :new AbstractController::ActionNotFound: Could not find devise mapping for path "/users/sign_up". Maybe you forgot to wrap your route inside the scope block? For example: devise_scope :user do match "/some/route" => "some_devise_controller" end # .

/spec/controllers/registrations_controller_spec. Rb:13:in `block (3 levels) in ' So what am I doing wrong? Ruby-on-rails ruby-on-rails-3 routing devise routes link|improve this question edited Jul 13 '11 at 2:20 asked Jul 12 '11 at 4:37David Tuite1,770620 90% accept rate.

THe problem is that Devise is unable to map routes from the test back to the original controller. That means that while your app actually works fine if you open it in the browser, your controller tests will still fail. The solution is to add the devise matting to the request before each test like so: before :each do request.

Env'devise. Mapping' = Devise. Mappings:user end.

What file do you add this to - I can't figure it out, thanks. – eWizardII Nov 12 '11 at 3:58 Put it in your controller tests, just inside the first describe block. – David Tuite Nov 12 '11 at 6:48 In spec - I have controllers the registration_controller is where I put it as follows to no avail: require 'spec_helper' describe RegistrationsController do describe "GET 'edit'" do before :each do request.

Env'devise. Mapping' = Devise. Mappings:user end it "should be successful" do get 'edit' response.

Should be_success end end end – eWizardII Nov 12 '11 at 7:41 I'd suggest you make a new question. That's pretty hard to read! – David Tuite Nov 12 '11 at 7:43 Thanks, I updated my already open question on the matter here - stackoverflow.com/questions/8102511/… – eWizardII Nov 12 '11 at 7:49.

Your route should look like this: devise_for :users, :controllers => { :registrations => "registrations" } do get "/users/sign_up/:invitation_token" => 'registrations#new' end.

The only difference is the hash synatax -> registrations: vs :registrations =>. That shouldn't make a difference unless I run my app in Ruby Didn't know that. Never seen that syntax before.

Thanks. – Kevin Tsoi Jul 12 '11 at 7:31 ;) It's much nicer when you get used to it! I think it'll edit my question anyway, just in case It confuses anyone.

– David Tuite Jul 12 '11 at 7:37.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions