diff --git a/public/javascripts/application.js b/public/javascripts/application.js index d498632..6f7b8df 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -227,59 +227,52 @@ $(function() { $('#loader').show(); }, error: function(data) { - console.log(data); $('#loader').hide(); $('#info_window').show(); $(submitButton).attr("disabled", false); + if(data.errors.email) { + errors.push($('#user_email')); + $('#user_email_label').addClass('error', 500); + $('#user_email').addClass('error', 500); + } + if(data.errors.name) { + errors.push($('#user_name')); + $('#user_name_label').addClass('error', 500); + $('#user_name').addClass('error', 500); + } + if(data.errors.organization) { + errors.push($('#user_organization')); + $('#user_organization_label').addClass('error', 500); + $('#user_organization').addClass('error', 500); + } + if(data.errors.voice_number) { + errors.push($('#user_voice_number')); + $('#user_voice_number_label').addClass('error', 500); + $('#user_voice_number').addClass('error', 500); + } + if(data.errors.sms_number) { + errors.push($('#user_sms_number')); + $('#user_sms_number_label').addClass('error', 500); + $('#user_sms_number').addClass('error', 500); + } + if(data.errors.password) { + errors.push($('#user_password_confirmation')); + $('#user_password_confirmation_label').addClass('error', 500); + $('#user_password_confirmation').addClass('error', 500); + } + errors[0].focus(); }, success: function(data) { - if(data.errors) { - $('#loader').hide(); - $('#info_window').show(); - $(submitButton).attr("disabled", false); - if(data.errors.email) { - errors.push($('#user_email')); - $('#user_email_label').addClass('error', 500); - $('#user_email').addClass('error', 500); + $.ajax({ + type: 'GET', + url: '/hydrant', + data: { + 'hydrant_id': activeHydrantId + }, + success: function(data) { + activeInfoWindow.setContent(data); } - if(data.errors.name) { - errors.push($('#user_name')); - $('#user_name_label').addClass('error', 500); - $('#user_name').addClass('error', 500); - } - if(data.errors.organization) { - errors.push($('#user_organization')); - $('#user_organization_label').addClass('error', 500); - $('#user_organization').addClass('error', 500); - } - if(data.errors.voice_number) { - errors.push($('#user_voice_number')); - $('#user_voice_number_label').addClass('error', 500); - $('#user_voice_number').addClass('error', 500); - } - if(data.errors.sms_number) { - errors.push($('#user_sms_number')); - $('#user_sms_number_label').addClass('error', 500); - $('#user_sms_number').addClass('error', 500); - } - if(data.errors.password) { - errors.push($('#user_password_confirmation')); - $('#user_password_confirmation_label').addClass('error', 500); - $('#user_password_confirmation').addClass('error', 500); - } - errors[0].focus(); - } else { - $.ajax({ - type: 'GET', - url: '/hydrant', - data: { - 'hydrant_id': activeHydrantId - }, - success: function(data) { - activeInfoWindow.setContent(data); - } - }); - } + }); } }); } @@ -314,31 +307,24 @@ $(function() { $('#loader').show(); }, error: function(data) { - console.log(data); $('#loader').hide(); $('#info_window').show(); $(submitButton).attr("disabled", false); + $('#user_password_label').addClass('error', 500); + $('#user_password').addClass('error', 500); + $('#user_password').focus(); }, success: function(data) { - if(data.errors) { - $('#loader').hide(); - $('#info_window').show(); - $(submitButton).attr("disabled", false); - $('#user_password_label').addClass('error', 500); - $('#user_password').addClass('error', 500); - $('#user_password').focus(); - } else { - $.ajax({ - type: 'GET', - url: '/hydrant', - data: { - 'hydrant_id': activeHydrantId - }, - success: function(data) { - activeInfoWindow.setContent(data); - } - }); - } + $.ajax({ + type: 'GET', + url: '/hydrant', + data: { + 'hydrant_id': activeHydrantId + }, + success: function(data) { + activeInfoWindow.setContent(data); + } + }); } }); } @@ -363,23 +349,16 @@ $(function() { $('#loader').show(); }, error: function(data) { - console.log(data); $('#loader').hide(); $('#info_window').show(); $(submitButton).attr("disabled", false); + $('#user_email_label').addClass('error', 500); + $('#user_email').addClass('error', 500); + $('#user_email').focus(); }, success: function() { - if(data.errors) { - $('#loader').hide(); - $('#info_window').show(); - $(submitButton).attr("disabled", false); - $('#user_email_label').addClass('error', 500); - $('#user_email').addClass('error', 500); - $('#user_email').focus(); - } else { - $('#user_forgot_password_fields').slideUp(); - $('#user_sign_in_fields').slideDown(); - } + $('#user_forgot_password_fields').slideUp(); + $('#user_sign_in_fields').slideDown(); } }); } @@ -633,55 +612,48 @@ $(function() { $('#loader').show(); }, error: function(data) { - console.log(data); $('#loader').hide(); $('#info_window').show(); $(submitButton).attr("disabled", false); + if(data.errors.email) { + errors.push($('#user_email')); + $('#user_email_label').addClass('error', 500); + $('#user_email').addClass('error', 500); + } + if(data.errors.name) { + errors.push($('#user_name')); + $('#user_name_label').addClass('error', 500); + $('#user_name').addClass('error', 500); + } + if(data.errors.organization) { + errors.push($('#user_organization')); + $('#user_organization_label').addClass('error', 500); + $('#user_organization').addClass('error', 500); + } + if(data.errors.voice_number) { + errors.push($('#user_voice_number')); + $('#user_voice_number_label').addClass('error', 500); + $('#user_voice_number').addClass('error', 500); + } + if(data.errors.sms_number) { + errors.push($('#user_sms_number')); + $('#user_sms_number_label').addClass('error', 500); + $('#user_sms_number').addClass('error', 500); + } + if(data.errors.password) { + errors.push($('#user_password')); + $('#user_password_label').addClass('error', 500); + $('#user_password').addClass('error', 500); + } + if(data.errors.current_password) { + errors.push($('#user_current_password')); + $('#user_current_password_label').addClass('error', 500); + $('#user_current_password').addClass('error', 500); + } + errors[0].focus(); }, success: function(data) { - if(data.errors) { - $('#loader').hide(); - $('#info_window').show(); - $(submitButton).attr("disabled", false); - if(data.errors.email) { - errors.push($('#user_email')); - $('#user_email_label').addClass('error', 500); - $('#user_email').addClass('error', 500); - } - if(data.errors.name) { - errors.push($('#user_name')); - $('#user_name_label').addClass('error', 500); - $('#user_name').addClass('error', 500); - } - if(data.errors.organization) { - errors.push($('#user_organization')); - $('#user_organization_label').addClass('error', 500); - $('#user_organization').addClass('error', 500); - } - if(data.errors.voice_number) { - errors.push($('#user_voice_number')); - $('#user_voice_number_label').addClass('error', 500); - $('#user_voice_number').addClass('error', 500); - } - if(data.errors.sms_number) { - errors.push($('#user_sms_number')); - $('#user_sms_number_label').addClass('error', 500); - $('#user_sms_number').addClass('error', 500); - } - if(data.errors.password) { - errors.push($('#user_password')); - $('#user_password_label').addClass('error', 500); - $('#user_password').addClass('error', 500); - } - if(data.errors.current_password) { - errors.push($('#user_current_password')); - $('#user_current_password_label').addClass('error', 500); - $('#user_current_password').addClass('error', 500); - } - errors[0].focus(); - } else { - activeInfoWindow.setContent(data); - } + activeInfoWindow.setContent(data); } }); } diff --git a/test/functional/passwords_controller_test.rb b/test/functional/passwords_controller_test.rb index 9edab60..3c2d74b 100644 --- a/test/functional/passwords_controller_test.rb +++ b/test/functional/passwords_controller_test.rb @@ -28,11 +28,11 @@ class PasswordsControllerTest < ActionController::TestCase assert_response :error end - test 'should render edit view' do - # skip 'Password reset not yet implemented' - # get :edit, :reset_password_token => 'token' - # assert_response :success - end + # test 'should render edit view' do + # skip 'Password reset not yet implemented' + # get :edit, :reset_password_token => 'token' + # assert_response :success + # end test 'should reset user password with an valid reset password token' do old_password = @user.password diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb index e0bc04c..3af40be 100644 --- a/test/functional/sessions_controller_test.rb +++ b/test/functional/sessions_controller_test.rb @@ -10,13 +10,15 @@ class SessionsControllerTest < ActionController::TestCase test 'should render combo form' do get :new assert_response :success - assert_select 'form' do + assert_template :new + assert_select 'form#combo_form' do assert_select '[action=?]', '/users/sign_in' assert_select '[method=?]', 'post' end assert_select 'h2', 'Adopt this Hydrant' assert_select 'input', :count => 15 assert_select 'label', :count => 10 + assert_select 'input[name="commit"]', :count => 3 end test 'should redirect if user is already authenticated' do