ref: refs/heads/master
commit 5999213cc018e7721bf5c192622a66d1139b2e8b
Author: Klaus Kämpf
Date: Fri Jul 10 14:30:07 2009 +0200
Clean up sessions controller and test, document workflow
---
webclient/app/controllers/sessions_controller.rb | 22 ++++++++-----
webclient/app/views/sessions/new.rhtml | 26 ++++++++--------
webclient/doc/Workflow | 16 ++++++++++
.../test/functional/sessions_controller_test.rb | 32 +++++++++++++++-----
4 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/webclient/app/controllers/sessions_controller.rb b/webclient/app/controllers/sessions_controller.rb
index 630a2c2..2ca0bc4 100644
--- a/webclient/app/controllers/sessions_controller.rb
+++ b/webclient/app/controllers/sessions_controller.rb
@@ -20,36 +20,42 @@ class SessionsController < ApplicationController
#
# Start new session
+ # render login screen
#
def new
- @hostname = params[:hostname]
-
# we can't create session if we are logged in
if logged_in?
- redirect_to session_path
+ redirect_to :action => "index"
return
end
# if the hostname is not set, go to the webservices controller
# to pickup a service
- if not params.has_key?(:hostname)
+ if params[:hostname].blank?
flash[:notice] = _("Please select a host to connect to.") unless flash[:notice]
redirect_to :controller => 'webservices'
return
end
+
+ @hostname = params[:hostname]
+
+ # render login screen, asking for username/password
end
+ # create session
+ # this is called from login form and expects to have username and password set
+ #
# if the create action is called without the hostname
# it will show the login form
def create
# if the user or password is not there, then render the login form
- if not params.has_key?(:hostname) or params[:hostname].empty?
+ if params[:hostname].blank?
flash[:warning] = _("You need to specify the hostname")
- redirect_to new_session_path(:hostname => params[:hostname])
+ redirect_to :action => "new"
return
- elsif not params.has_key?(:password) or params[:password].empty?
+ elsif params[:password].blank?
flash[:warning] = _("No password specified")
- redirect_to new_session_path(:hostname => params[:hostname])
+ redirect_to :action => "new", :hostname => params[:hostname]
return
else
# otherwise, we have all the data, try to login
diff --git a/webclient/app/views/sessions/new.rhtml b/webclient/app/views/sessions/new.rhtml
index 1514803..4db83f5 100644
--- a/webclient/app/views/sessions/new.rhtml
+++ b/webclient/app/views/sessions/new.rhtml
@@ -1,19 +1,19 @@
+<div class="content">
+ <% form_tag( :action => 'create' ) do %>
+ <span id="title">Login</span>
-<div class="content">
-<% form_tag( :action => 'create' ) do %>
-<h2>Login</h2>
-<p><%= _("Use your administrator (root) account to login.") %></p>
+ <p><%= _("Enter login credentials for host #{@hostname}.") %></p>
+
+ <%= hidden_field_tag 'hostname', @hostname %>
+
+ <p><label for="login"><%= _("Username:") %></label><br>
+ <%= text_field_tag 'login', @user %></p>
-<p><label for="login"><%= _("Username:") %></label><br>
-<%= hidden_field_tag'hostname', @hostname %>
-<%= text_field_tag 'login', @user %></p>
+ <p><label for="password"><%= _("Password:") %></label><br>
+ <%= password_field_tag 'password', @password %></p>
-<p><label for="password"><%= _("Password:") %></label><br>
-<%= password_field_tag 'password', @password %></p>
-<%= hidden_field_tag'hostname', @hostname %>
+ <%= submit_tag(_('Login'), :class => "button") %>
-<%= submit_tag(_('Login'), :class => "button") %>
+ <% end %>
</div>
-</form>
-<% end %>
diff --git a/webclient/doc/Workflow b/webclient/doc/Workflow
index fd30c1f..adf0ba5 100644
--- a/webclient/doc/Workflow
+++ b/webclient/doc/Workflow
@@ -8,7 +8,23 @@ you'll see:
root / {:controller=>"main", :action=>"index"}
+Main
+----
MainController is just a redirector, either to Controlpanel (session
established) or to Session.new (no session).
+Session
+-------
+
+Session.new checks for params[:hostname]. If none is found, the user
+has to choose a host via Webservices.index first.
+
+If a hostname is found, a login screen asks for username and password,
+and calls Session.create
+
+
+Webservices
+-----------
+
+This is a 'host chooser' redirecting to Session.new afterwards
\ No newline at end of file
diff --git a/webclient/test/functional/sessions_controller_test.rb b/webclient/test/functional/sessions_controller_test.rb
index 075b679..ae7c768 100644
--- a/webclient/test/functional/sessions_controller_test.rb
+++ b/webclient/test/functional/sessions_controller_test.rb
@@ -1,9 +1,9 @@
-#require File.dirname(__FILE__) + '/../test_helper'
-require 'test_helper'
-require 'sessions_controller'
+require File.dirname(__FILE__) + '/../test_helper'
+
require 'active_resource/http_mock'
# Re-raise errors caught by the controller.
+require 'sessions_controller'
class SessionsController; def rescue_action(e) raise e end; end
# test the web client part of the login, which
@@ -15,13 +15,9 @@ class SessionsControllerTest < ActionController::TestCase
# Then, you can remove it from this and the units test.
include AuthenticatedTestHelper
-# fixtures :accounts
+ fixtures :accounts
def setup
- @controller = SessionsController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
-
@login_granted = "<hash><login>granted</login></hash>"
@login_denied = "<hash><login>denied</login></hash>"
@logout_granted = "<hash><logout>Goodbye!</logout></hash>"
@@ -31,6 +27,26 @@ class SessionsControllerTest < ActionController::TestCase
ActiveResource::Base.site = @hostname
end
+ # new without any parameters should redirect to webservices
+ def test_new
+ get :new
+ assert_redirected_to :controller => :webservices
+ end
+
+ # new with :hostname empty
+ def test_new_with_empty_hostname
+ get :new, :hostname => ""
+ assert_redirected_to :controller => :webservices
+ assert flash[:notice]
+ end
+
+ # new with hostname, must show login
+ def test_new_shows_login
+ get :new, :hostname => @hostname
+ assert_select "form input", 2
+ assert_select "title", "Login"
+ end
+
# without a service hostname to to login, we should
# be redirected to web service choosing...
def test_should_redirect_to_select_hostname
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org