https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Despr�s <nicolas.despres(a)gmail.com>
Inject graph_form_controller into benches_controller.
* web/ranch/test/functional/graph_form_controller_test.rb: Remove.
Inject ...
* web/ranch/test/functional/benches_controller_test.rb: ...here.
* web/ranch/app/controllers/graph_form_controller.rb: Remove.
Becomes...
* web/ranch/app/controllers/benches_controller.rb: ... regression
request.
* web/ranch/app/views/graph_form: Remove.
* web/ranch/app/views/graph_form/draw.rhtml: Remove. Becomes ...
* web/ranch/app/views/benches/regression.rhtml: New. ...it.
* web/ranch/app/views/benches/_list.rhtml: Redirect to the show
request instead of the index one.
* web/ranch/app/views/benches/_menubar.rhtml: Add the regression
item.
app/controllers/benches_controller.rb | 52 +++++++++++++
app/views/benches/_list.rhtml | 2
app/views/benches/_menubar.rhtml | 5 +
app/views/benches/regression.rhtml | 12 +--
test/functional/benches_controller_test.rb | 112 +++++++++++++++++++++++++++--
5 files changed, 170 insertions(+), 13 deletions(-)
Index: web/ranch/test/functional/benches_controller_test.rb
--- web/ranch/test/functional/benches_controller_test.rb (revision 48)
+++ web/ranch/test/functional/benches_controller_test.rb (working copy)
@@ -5,6 +5,8 @@
class BenchesController; def rescue_action(e) raise e end; end
class BenchesControllerTest < Test::Unit::TestCase
+ fixtures :projects, :benches, :outputs, :inputs
+
def setup
@controller = BenchesController.new
@request = ActionController::TestRequest.new
@@ -12,11 +14,9 @@
end
def test_index
- get :index, { :project_id => 2 }
+ get :index, { :project_id => 1 }
assert_response :redirect
- assert_redirected_to(:controller => 'benches',
- :action => 'show',
- :bench_id => 4)
+ assert_redirected_to(:action => 'show', :bench_id => 1)
assert_not_nil assigns(:project)
assert_not_nil assigns(:benches)
end
@@ -30,4 +30,108 @@
assert_not_nil assigns(:bench)
end
+ def test_regression
+ get :regression, { :bench_id => 1 }
+ assert_response :success
+ assert_template 'regression'
+
+ assert_not_nil assigns(:project)
+ assert_not_nil assigns(:bench)
+ assert_not_nil assigns(:output_arg_num)
+ assert_not_nil assigns(:inputs)
+ assert_kind_of Hash, assigns(:revision)
+ assert assigns(:revision)[:start] < assigns(:revision)[:stop]
+ assert assigns(:revision)[:start] >= 1
+ end
+
+ def test_regression_regular_revision_range
+ post :regression, {
+ :bench_id => 1,
+ :revision => { :range => "2-8" }
+ }
+ assert_response :success
+ assert_template 'regression'
+
+ assert_not_nil assigns(:project)
+ assert_not_nil assigns(:bench)
+ assert_not_nil assigns(:output_arg_num)
+ assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
+ assert_kind_of Hash, assigns(:revision)
+ assert_equal 2, assigns(:revision)[:start]
+ assert_equal 8, assigns(:revision)[:stop]
+ assert_nil flash[:error]
+ end
+
+ def test_regression_bad_revision_range
+ post :regression, {
+ :bench_id => 1,
+ :revision => { :range => "-42-500" }
+ }
+ assert_response :success
+ assert_template 'regression'
+
+ assert_not_nil assigns(:project)
+ assert_not_nil assigns(:bench)
+ assert_not_nil assigns(:output_arg_num)
+ assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
+ assert_kind_of Hash, assigns(:revision)
+ assert_equal 1, assigns(:revision)[:start]
+ assert_equal assigns(:project).head_revision, assigns(:revision)[:stop]
+ assert_nil flash[:error]
+ end
+
+ def test_draw_start_sup_stop
+ post :regression, {
+ :bench_id => 1,
+ :revision => { :range => "42-10" }
+ }
+ assert_response :success
+ assert_template 'regression'
+
+ assert_equal 1, assigns(:project).id
+ assert_equal 'determinize', assigns(:bench).name
+ assert(flash.has_key?(:error))
+ assert_not_nil assigns(:output_arg_num)
+ assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
+ assert_not_nil flash[:error]
+ end
+
+ def test_draw_output_arg_num
+ post :regression, {
+ :bench_id => 1,
+ :revision => { :range => "1-10" },
+ :output_arg_num => 0,
+ }
+ assert_response :success
+ assert_template 'regression'
+
+ assert_equal 1, assigns(:project).id
+ assert_equal 'determinize', assigns(:bench).name
+ assert_equal 0, assigns(:output_arg_num)
+ assert_equal 3, assigns(:output_arg_nb)
+ assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
+ assert_nil flash[:error]
+ end
+
+ def test_draw_bad_revision_format
+ post :regression, {
+ :bench_id => 1,
+ :revision => { :range => "-42---10" }
+ }
+ assert_response :success
+ assert_template 'regression'
+
+ assert_equal 1, assigns(:project).id
+ assert_equal 'determinize', assigns(:bench).name
+ assert(flash.has_key?(:error))
+ assert_not_nil assigns(:output_arg_num)
+ assert_not_nil assigns(:inputs)
+ assert_not_nil assigns(:input_set_num)
+ assert_not_nil flash[:error]
+ end
+
end
Index: web/ranch/app/controllers/benches_controller.rb
--- web/ranch/app/controllers/benches_controller.rb (revision 48)
+++ web/ranch/app/controllers/benches_controller.rb (working copy)
@@ -2,8 +2,12 @@
layout 'benches'
+ helper :graph, :graph_form
+
before_filter :list
+ DEFAULT_REVISION_RANGE = 100
+
def index
redirect_to :action => 'show', :bench_id => @benches.first.id
end
@@ -11,6 +15,28 @@
def show
end
+ def regression
+ flash[:error] = nil
+ @inputs = @bench.input
+ @input_set_num = params[:input_set_num].to_i
+ @output_arg_num = params[:output_arg_num].to_i
+ if @output_arg_num.zero?
+ @output_arg_nb = Output.find_by_sql "SELECT outputs.arg_num " +
+ "FROM outputs " +
+ "WHERE outputs.bench_id = #{(a)bench.id} " +
+ "AND outputs.set_num = #@input_set_num " +
+ "GROUP BY outputs.arg_num " +
+ "ORDER BY outputs.arg_num "
+ @output_arg_nb = @output_arg_nb.size
+ end
+ if params[:revision].nil? or params[:revision][:range].nil?
+ @revision = {}
+ @revision[:stop], @revision[:start] = default_revision
+ else
+ @revision = get_revision_range(params[:revision][:range])
+ end
+ end
+
protected
def list
@@ -23,4 +49,30 @@
@benches = @project.bench_ordered_by_name
end
+ def get_revision_range(revision, head_rev=(a)project.head_revision)
+ stop_rev, start_rev = default_revision(head_rev)
+ result = { :stop => stop_rev, :start => start_rev }
+ if revision =~ /^(-?\d+)-(-?\d+)$/
+ result[:start] = $1
+ result[:stop] = $2
+ result[:stop] = result[:stop].to_i
+ result[:stop] = head_rev if result[:stop] > head_rev
+ result[:start] = result[:start].to_i
+ result[:start] = 1 if result[:start] < 1
+ if result[:start] > result[:stop]
+ flash[:error] = 'Start revision greater than stop revision.'
+ end
+ else
+ flash[:error] = "Bad revision range format."
+ end
+ result
+ end
+
+ def default_revision(head_rev=(a)project.head_revision)
+ stop_rev = head_rev
+ start_rev = stop_rev - DEFAULT_REVISION_RANGE
+ start_rev = 1 if start_rev < 1
+ [ stop_rev, start_rev ]
+ end
+
end
Index: web/ranch/app/views/benches/_list.rhtml
--- web/ranch/app/views/benches/_list.rhtml (revision 48)
+++ web/ranch/app/views/benches/_list.rhtml (working copy)
@@ -3,7 +3,7 @@
<tr>
<td>
<%= link_to @project.name, :controller => "projects",
- :action => "index",
+ :action => "show",
:project_id => @project.id %>
</td>
</tr>
Index: web/ranch/app/views/benches/regression.rhtml
--- web/ranch/app/views/benches/regression.rhtml (revision 48)
+++ web/ranch/app/views/benches/regression.rhtml (working copy)
@@ -1,6 +1,6 @@
<!-- -*- html -*- -->
<%= content_tag "h3", "#{(a)project.name}name}: #{(a)bench.name}" %>
-<%= start_form_tag :action => "draw",
+<%= start_form_tag :action => "regression",
:bench_id => @bench.id %>
<table cellspacing=10>
@@ -74,7 +74,9 @@
<!-- DRAWING -->
<p>
-<% if @draw_on %>
+<% if flash[:error] %>
+ <p style="color: red;"><%= flash[:error] %></p>
+<% else %>
<% if @output_arg_num.zero? %>
<% 1.upto(@output_arg_nb) do |i| %>
<p>
@@ -88,11 +90,5 @@
@revision[:start], @revision[:stop],
@output_arg_num, @input_set_num %>
<% end %>
-<% else %>
- <% if flash[:error] %>
- <p style="color: red;"><%= flash[:error] %></p>
- <% else %>
- <%= content_tag "p", "No chart to display - click on Draw"
%>
- <% end %>
<% end %>
Index: web/ranch/app/views/benches/_menubar.rhtml
--- web/ranch/app/views/benches/_menubar.rhtml (revision 48)
+++ web/ranch/app/views/benches/_menubar.rhtml (working copy)
@@ -7,6 +7,11 @@
:action => "show",
:bench_id => @bench.id %>
</td>
+ <td>
+ <%= link_to "regression", :controller => "benches",
+ :action => "regression",
+ :bench_id => @bench.id %>
+ </td>
</tr>
</table>
<hr>