Commit 827cb23a5e3648fe8ff5dcfdea3d623232045dba

Authored by Stephen Crosby
1 parent dd14f778
Exists in master and in 1 other branch production

fixes #811 ensure friendly error on invalid creds

config/initializers/overrides.rb
1 -require Rails.root.join('lib/overrides/devise/failure_app')  
2 require Rails.root.join('lib/overrides/hoptoad_notifier/hoptoad_notifier') 1 require Rails.root.join('lib/overrides/hoptoad_notifier/hoptoad_notifier')
3 2
4 class BSON::ObjectId 3 class BSON::ObjectId
lib/overrides/devise/failure_app.rb
@@ -1,15 +0,0 @@ @@ -1,15 +0,0 @@
1 -Devise::FailureApp.class_eval do  
2 - protected  
3 - # Handles both 'email_invalid' and 'username_invalid' messages.  
4 - def i18n_message(default = nil)  
5 - message = warden.message || warden_options[:message] || default || :unauthenticated  
6 -  
7 - if message.is_a?(Symbol)  
8 - I18n.t(:"#{scope}.#{Devise.authentication_keys.first}_#{message}", :resource_name => scope,  
9 - :scope => "devise.failure", :default => [message, message.to_s])  
10 - else  
11 - message.to_s  
12 - end  
13 - end  
14 -end  
15 -  
spec/controllers/devise_sessions_controller_spec.rb
@@ -19,5 +19,10 @@ describe Devise::SessionsController, type: 'controller' do @@ -19,5 +19,10 @@ describe Devise::SessionsController, type: 'controller' do
19 post :create, { :user => { 'email' => user.email, 'password' => user.password } } 19 post :create, { :user => { 'email' => user.email, 'password' => user.password } }
20 expect(response).to redirect_to(app_path(app)) 20 expect(response).to redirect_to(app_path(app))
21 end 21 end
  22 +
  23 + it 'displays a friendly error when credentials are invalid' do
  24 + post :create, { :user => { 'email' => 'whatever', 'password' => 'somethinginvalid' } }
  25 + expect(request.flash["alert"]).to eq(I18n.t 'devise.failure.user.email_invalid')
  26 + end
22 end 27 end
23 end 28 end