I set up Devise for my Rails App and everything is working fine so far. The only problem I have is that Devise redirects to a wrong path after a failed registration.
This is how the error looks like when testing:
Failures:
1) Register with wrong credentials
Failure/Error: expect(page.current_path).to eq new_user_registration_path
expected: "/register"
got: "/"
My test looks like this:
feature 'Register' do
scenario 'with wrong credentials' do
visit new_user_registration_path
fill_in 'First Name', with: ''
fill_in 'Email', with: ''
fill_in 'Password', with: ''
fill_in 'Confirm Password', with: '...'
click_on 'Register'
expect(page.current_path).to eq new_user_registration_path
expect(page).to have_content 'errors'
end
end
And here are my routes:
devise_for :users,
path: '/',
path_names: { sign_in: 'log_in', sign_out: 'log_out', sign_up: 'register'},
controllers: { registrations: 'registrations'}
I tried to overwrite devise/registrations#create like mentioned here, but ended up loosing the default error-flash message:
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
# instead of
# respond_with resources
# I wrote:
redirect_to new_user_registration_path
end
end
I'm using: Ruby 2.2.0, Rails 4.2.0 and Devise 3.4.1.