
https://svn.lrde.epita.fr/svn/ranch/trunk Index: ChangeLog from Nicolas Desprès <nicolas.despres@gmail.com> Add the benchmark list page. * web/ranch/test/functional/benches_controller_test.rb: New. Test of the list request on the benches controller. * web/ranch/test/fixtures/benches.yml: New. * web/ranch/app/helpers/benches_helper.rb: New. * web/ranch/app/models/bench.rb: New. Model associated to the benches table. * web/ranch/test/unit/bench_test.rb: New. Test of the model Bench. * web/ranch/app/models/project.rb: Add the 'has_many' relationship with the bench model. * web/ranch/app/controllers/benches_controller.rb: New. Control the benches list. * web/ranch/app/views/benches: New. * web/ranch/app/views/benches/list.rhtml: New. View for the list request on the benches controller. * web/ranch/app/views/projects/list.rhtml: Give the project_id as parameter of the benches controller. * web/ranch/db/schema.rb: Add the benches table. app/controllers/benches_controller.rb | 12 ++++++++++++ app/helpers/benches_helper.rb | 2 ++ app/models/bench.rb | 5 +++++ app/models/project.rb | 3 +++ app/views/benches/list.rhtml | 22 ++++++++++++++++++++++ app/views/projects/list.rhtml | 6 +++--- db/schema.rb | 7 +++++++ test/fixtures/benches.yml | 19 +++++++++++++++++++ test/functional/benches_controller_test.rb | 26 ++++++++++++++++++++++++++ test/unit/bench_test.rb | 10 ++++++++++ 10 files changed, 109 insertions(+), 3 deletions(-) Index: web/ranch/test/unit/bench_test.rb --- web/ranch/test/unit/bench_test.rb (revision 0) +++ web/ranch/test/unit/bench_test.rb (revision 0) @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class BenchTest < Test::Unit::TestCase + fixtures :benches + + # Replace this with your real tests. + def test_truth + assert_kind_of Bench, benches(:first) + end +end 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,26 @@ +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 + fixtures :benches + fixtures :projects + + def setup + @controller = BenchesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_list + get :list, { 'project_id' => 1 } + + assert_response :success + assert_template 'list' + + assert_not_nil assigns(:project) + assert_not_nil assigns(:benches) + end +end Index: web/ranch/test/fixtures/benches.yml --- web/ranch/test/fixtures/benches.yml (revision 0) +++ web/ranch/test/fixtures/benches.yml (revision 0) @@ -0,0 +1,19 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +determinize: + id: 1 + project_id: 1 + name: determinize +quotient: + id: 2 + project_id: 1 + name: quotient + +open: + id: 3 + project_id: 2 + name: open +close: + id: 4 + project_id: 2 + name: close + 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/bench.rb --- web/ranch/app/models/bench.rb (revision 0) +++ web/ranch/app/models/bench.rb (revision 0) @@ -0,0 +1,5 @@ +class Bench < ActiveRecord::Base + + belongs_to :project + +end Index: web/ranch/app/models/project.rb --- web/ranch/app/models/project.rb (revision 9) +++ web/ranch/app/models/project.rb (working copy) @@ -1,2 +1,5 @@ class Project < ActiveRecord::Base + + has_many :bench + end 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,12 @@ +class BenchesController < ApplicationController + + layout 'ranch' + + def list + @project = Project.find_by_id(@params[:project_id]) + @benches = Bench.find_all_by_project_id(@project.id).sort do |a, b| + a.name <=> b.name + end + end + +end 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,22 @@ + <!-- -*- html -*- --> +<div style="text-align: center;"> +<h2><%= @project.name %></h2> +<p> +Select a benchmark: +</p> +<p> +<center> +<table> + <% for bench in @benches %> + <tr> + <td> + <%= link_to bench.name, :controller => "reggraph", + :action => "index", + :bench => bench %> + </td> + </tr> + <% end %> +</table> +</center> +</p> +</div> Index: web/ranch/app/views/projects/list.rhtml --- web/ranch/app/views/projects/list.rhtml (revision 9) +++ web/ranch/app/views/projects/list.rhtml (working copy) @@ -13,9 +13,9 @@ <% for project in @projects %> <tr> <td> - <%= link_to project.name, :controller => "benchmark", - :action => "index", - :id => project.id %> + <%= link_to project.name, :controller => "benches", + :action => "list", + :project_id => project.id %> </td> </tr> <% end %> Index: web/ranch/db/schema.rb --- web/ranch/db/schema.rb (revision 9) +++ web/ranch/db/schema.rb (working copy) @@ -4,6 +4,13 @@ ActiveRecord::Schema.define() do + create_table "benches", :force => true do |t| + t.column "name", :string, :limit => 128, :default => "noname", :null => false + t.column "project_id", :integer, :limit => 10, :default => 0, :null => false + end + + add_index "benches", ["project_id"], :name => "project_id" + create_table "projects", :force => true do |t| t.column "name", :string, :default => "noname", :null => false end