[ranch] 48: Add the benches controller.

https://svn.lrde.epita.fr/svn/ranch/trunk Index: ChangeLog from Nicolas Despr�s <nicolas.despres@gmail.com> Add the benches controller. * web/ranch/test/functional/benches_controller_test.rb: New. Test it. * web/ranch/app/helpers/benches_helper.rb: New. Nothing by now but generated by Rails. * web/ranch/app/models/project.rb: Select only id and name fields. * web/ranch/app/controllers/benches_controller.rb: New. Handle index and show request. * web/ranch/app/views/layouts/benches.rhtml: New. Layout of the controller. * web/ranch/app/views/benches: New. * web/ranch/app/views/benches/_list.rhtml: New. The left margin part of the layout. * web/ranch/app/views/benches/show.rhtml: New. Template for the show request. * web/ranch/app/views/benches/_menubar.rhtml: New. The menu bar of the controller. * web/ranch/app/views/projects/_menubar.rhtml: Add a link in the menu bar to see go to the benchmarks of a project. app/controllers/benches_controller.rb | 26 +++++++++++++++++++ app/helpers/benches_helper.rb | 2 + app/models/project.rb | 5 ++- app/views/benches/_list.rhtml | 30 ++++++++++++++++++++++ app/views/benches/_menubar.rhtml | 12 ++++++++ app/views/benches/show.rhtml | 10 +++++++ app/views/layouts/benches.rhtml | 39 +++++++++++++++++++++++++++++ app/views/projects/_menubar.rhtml | 5 +++ test/functional/benches_controller_test.rb | 33 ++++++++++++++++++++++++ 9 files changed, 161 insertions(+), 1 deletion(-) Index: web/ranch/test/functional/benches_controller_test.rb --- web/ranch/test/functional/benches_controller_test.rb (revision 0) +++ web/ranch/test/functional/benches_controller_test.rb (revision 0) @@ -0,0 +1,33 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'benches_controller' + +# Re-raise errors caught by the controller. +class BenchesController; def rescue_action(e) raise e end; end + +class BenchesControllerTest < Test::Unit::TestCase + def setup + @controller = BenchesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_index + get :index, { :project_id => 2 } + assert_response :redirect + assert_redirected_to(:controller => 'benches', + :action => 'show', + :bench_id => 4) + assert_not_nil assigns(:project) + assert_not_nil assigns(:benches) + end + + def test_show + get :show, { :bench_id => 1 } + assert_response :success + assert_template 'show' + assert_not_nil assigns(:project) + assert_not_nil assigns(:benches) + assert_not_nil assigns(:bench) + end + +end Index: web/ranch/app/helpers/benches_helper.rb --- web/ranch/app/helpers/benches_helper.rb (revision 0) +++ web/ranch/app/helpers/benches_helper.rb (revision 0) @@ -0,0 +1,2 @@ +module BenchesHelper +end Index: web/ranch/app/models/project.rb --- web/ranch/app/models/project.rb (revision 47) +++ web/ranch/app/models/project.rb (working copy) @@ -8,7 +8,10 @@ validates_length_of :name, :maximum => 255 def bench_ordered_by_name - Bench.find :all, :conditions => [ "project_id = ?", id ], :order => "name" + Bench.find(:all, + :select => "id, name", + :conditions => [ "project_id = ?", id ], + :order => "name") end protected Index: web/ranch/app/controllers/benches_controller.rb --- web/ranch/app/controllers/benches_controller.rb (revision 0) +++ web/ranch/app/controllers/benches_controller.rb (revision 0) @@ -0,0 +1,26 @@ +class BenchesController < ApplicationController + + layout 'benches' + + before_filter :list + + def index + redirect_to :action => 'show', :bench_id => @benches.first.id + end + + def show + end + + protected + + def list + if params[:project_id] + @project = Project.find_by_id params[:project_id] + elsif params[:bench_id] + @bench = Bench.find_by_id params[:bench_id] + @project = @bench.project + end + @benches = @project.bench_ordered_by_name + end + +end Index: web/ranch/app/views/layouts/benches.rhtml --- web/ranch/app/views/layouts/benches.rhtml (revision 0) +++ web/ranch/app/views/layouts/benches.rhtml (revision 0) @@ -0,0 +1,39 @@ + <!-- -*- html -*- --> + +<html> + <%= render :partial => "layouts/head" %> + <body> + <%= render :partial => "layouts/top_banner" %> + <%= render :partial => "layouts/menubar" %> + + <p> + <table cellspacing=0 cellpadding=0 border=0 width="100%" height="80%" cols=2> + <tr> + <td class=left_margin valign=top width="15%"> + <%= render :partial => "benches/list" %> + </td> + <td class=content align=left valign=top width="80%"> + + <% if @bench.nil? %> + No benchmark + <% else %> + <table width="100%"> + <tr><td> + <%= render :partial => "benches/menubar" %> + </td></tr> + <tr><td> + <%= @content_for_layout %> + </td></tr> + </table> + <% end %> + + </td> + </tr> + </table> + </p> + + <%= render :partial => "layouts/bottom_banner" %> + </body> +</html> + + Index: web/ranch/app/views/benches/_list.rhtml --- web/ranch/app/views/benches/_list.rhtml (revision 0) +++ web/ranch/app/views/benches/_list.rhtml (revision 0) @@ -0,0 +1,30 @@ + <!-- -*- html -*- --> +<table> + <tr> + <td> + <%= link_to @project.name, :controller => "projects", + :action => "index", + :project_id => @project.id %> + </td> + </tr> + <% if @benches.nil? or @benches.empty? %> + No benchmarks available. + <% else %> + <tr> + <td> + <table> + <% for bench in @benches %> + <tr> + <td width=10></td> + <td> + <%= link_to bench.name, :controller => "benches", + :action => "show", + :bench_id => bench.id %> + </td> + </tr> + <% end %> + </table> + </td> + </tr> + <% end %> +</table> Index: web/ranch/app/views/benches/show.rhtml --- web/ranch/app/views/benches/show.rhtml (revision 0) +++ web/ranch/app/views/benches/show.rhtml (revision 0) @@ -0,0 +1,10 @@ + <!-- -*- html -*- --> + +<p> +<table> + <tr> + <td>Name:</td> + <td><%= @bench.name %></td> + </tr> +</table> +</p> Index: web/ranch/app/views/benches/_menubar.rhtml --- web/ranch/app/views/benches/_menubar.rhtml (revision 0) +++ web/ranch/app/views/benches/_menubar.rhtml (revision 0) @@ -0,0 +1,12 @@ + <!-- -*- html -*- --> +<table> + <tr> + <td><%= content_tag "h3", @bench.name %></td> + <td> + <%= link_to "show", :controller => "benches", + :action => "show", + :bench_id => @bench.id %> + </td> + </tr> +</table> +<hr> Index: web/ranch/app/views/projects/_menubar.rhtml --- web/ranch/app/views/projects/_menubar.rhtml (revision 47) +++ web/ranch/app/views/projects/_menubar.rhtml (working copy) @@ -7,6 +7,11 @@ :action => "show", :project_id => @project.id %> </td> + <td> + <%= link_to "benchmarks", :controller => "benches", + :action => "index", + :project_id => @project.id %> + </td> </tr> </table> <hr>
participants (1)
-
Nicolas Despr�s