Make responses more RESTful

This commit is contained in:
Erik Michaels-Ober 2011-05-15 23:34:14 -07:00
parent 391f5c1e55
commit b034953be3
3 changed files with 103 additions and 129 deletions

View File

@ -227,13 +227,6 @@ $(function() {
$('#loader').show(); $('#loader').show();
}, },
error: function(data) { error: function(data) {
console.log(data);
$('#loader').hide();
$('#info_window').show();
$(submitButton).attr("disabled", false);
},
success: function(data) {
if(data.errors) {
$('#loader').hide(); $('#loader').hide();
$('#info_window').show(); $('#info_window').show();
$(submitButton).attr("disabled", false); $(submitButton).attr("disabled", false);
@ -268,7 +261,8 @@ $(function() {
$('#user_password_confirmation').addClass('error', 500); $('#user_password_confirmation').addClass('error', 500);
} }
errors[0].focus(); errors[0].focus();
} else { },
success: function(data) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/hydrant', url: '/hydrant',
@ -280,7 +274,6 @@ $(function() {
} }
}); });
} }
}
}); });
} }
} else if($(this).data('state') === 'user_sign_in') { } else if($(this).data('state') === 'user_sign_in') {
@ -314,20 +307,14 @@ $(function() {
$('#loader').show(); $('#loader').show();
}, },
error: function(data) { error: function(data) {
console.log(data);
$('#loader').hide();
$('#info_window').show();
$(submitButton).attr("disabled", false);
},
success: function(data) {
if(data.errors) {
$('#loader').hide(); $('#loader').hide();
$('#info_window').show(); $('#info_window').show();
$(submitButton).attr("disabled", false); $(submitButton).attr("disabled", false);
$('#user_password_label').addClass('error', 500); $('#user_password_label').addClass('error', 500);
$('#user_password').addClass('error', 500); $('#user_password').addClass('error', 500);
$('#user_password').focus(); $('#user_password').focus();
} else { },
success: function(data) {
$.ajax({ $.ajax({
type: 'GET', type: 'GET',
url: '/hydrant', url: '/hydrant',
@ -339,7 +326,6 @@ $(function() {
} }
}); });
} }
}
}); });
} }
} else if($(this).data('state') === 'user_forgot_password') { } else if($(this).data('state') === 'user_forgot_password') {
@ -363,24 +349,17 @@ $(function() {
$('#loader').show(); $('#loader').show();
}, },
error: function(data) { error: function(data) {
console.log(data);
$('#loader').hide();
$('#info_window').show();
$(submitButton).attr("disabled", false);
},
success: function() {
if(data.errors) {
$('#loader').hide(); $('#loader').hide();
$('#info_window').show(); $('#info_window').show();
$(submitButton).attr("disabled", false); $(submitButton).attr("disabled", false);
$('#user_email_label').addClass('error', 500); $('#user_email_label').addClass('error', 500);
$('#user_email').addClass('error', 500); $('#user_email').addClass('error', 500);
$('#user_email').focus(); $('#user_email').focus();
} else { },
success: function() {
$('#user_forgot_password_fields').slideUp(); $('#user_forgot_password_fields').slideUp();
$('#user_sign_in_fields').slideDown(); $('#user_sign_in_fields').slideDown();
} }
}
}); });
} }
} }
@ -633,13 +612,6 @@ $(function() {
$('#loader').show(); $('#loader').show();
}, },
error: function(data) { error: function(data) {
console.log(data);
$('#loader').hide();
$('#info_window').show();
$(submitButton).attr("disabled", false);
},
success: function(data) {
if(data.errors) {
$('#loader').hide(); $('#loader').hide();
$('#info_window').show(); $('#info_window').show();
$(submitButton).attr("disabled", false); $(submitButton).attr("disabled", false);
@ -679,10 +651,10 @@ $(function() {
$('#user_current_password').addClass('error', 500); $('#user_current_password').addClass('error', 500);
} }
errors[0].focus(); errors[0].focus();
} else { },
success: function(data) {
activeInfoWindow.setContent(data); activeInfoWindow.setContent(data);
} }
}
}); });
} }
return false; return false;

View File

@ -28,11 +28,11 @@ class PasswordsControllerTest < ActionController::TestCase
assert_response :error assert_response :error
end end
test 'should render edit view' do # test 'should render edit view' do
# skip 'Password reset not yet implemented' # skip 'Password reset not yet implemented'
# get :edit, :reset_password_token => 'token' # get :edit, :reset_password_token => 'token'
# assert_response :success # assert_response :success
end # end
test 'should reset user password with an valid reset password token' do test 'should reset user password with an valid reset password token' do
old_password = @user.password old_password = @user.password

View File

@ -10,13 +10,15 @@ class SessionsControllerTest < ActionController::TestCase
test 'should render combo form' do test 'should render combo form' do
get :new get :new
assert_response :success assert_response :success
assert_select 'form' do assert_template :new
assert_select 'form#combo_form' do
assert_select '[action=?]', '/users/sign_in' assert_select '[action=?]', '/users/sign_in'
assert_select '[method=?]', 'post' assert_select '[method=?]', 'post'
end end
assert_select 'h2', 'Adopt this Hydrant' assert_select 'h2', 'Adopt this Hydrant'
assert_select 'input', :count => 15 assert_select 'input', :count => 15
assert_select 'label', :count => 10 assert_select 'label', :count => 10
assert_select 'input[name="commit"]', :count => 3
end end
test 'should redirect if user is already authenticated' do test 'should redirect if user is already authenticated' do