diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb
index 6c76ab2e8..05a9f61f7 100644
--- a/app/views/account/login.html.erb
+++ b/app/views/account/login.html.erb
@@ -5,7 +5,7 @@
|
- <%= text_field_tag 'username', nil, :tabindex => '1' %> |
+ <%= text_field_tag 'username', params[:username], :tabindex => '1' %> |
|
@@ -36,7 +36,12 @@
-<%= javascript_tag "$('#username').focus();" %>
<% end %>
<%= call_hook :view_account_login_bottom %>
+
+<% if params[:username].present? %>
+<%= javascript_tag "$('#password').focus();" %>
+<% else %>
+<%= javascript_tag "$('#username').focus();" %>
+<% end %>
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb
index 7b5a449e5..05c3b047b 100644
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -31,6 +31,15 @@ class AccountControllerTest < ActionController::TestCase
User.current = nil
end
+ def test_get_login
+ get :login
+ assert_response :success
+ assert_template 'login'
+
+ assert_select 'input[name=username]'
+ assert_select 'input[name=password]'
+ end
+
def test_login_should_redirect_to_back_url_param
# request.uri is "test.host" in test environment
post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
@@ -46,9 +55,11 @@ class AccountControllerTest < ActionController::TestCase
post :login, :username => 'admin', :password => 'bad'
assert_response :success
assert_template 'login'
- assert_tag 'div',
- :attributes => { :class => "flash error" },
- :content => /Invalid user or password/
+
+ assert_select 'div.flash.error', :text => /Invalid user or password/
+ assert_select 'input[name=username][value=admin]'
+ assert_select 'input[name=password]'
+ assert_select 'input[name=password][value]', 0
end
def test_login_should_rescue_auth_source_exception