https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Despr�s <nicolas.despres(a)gmail.com>
Check revision range correctness.
* web/ranch/test/functional/graph_form_controller_test.rb: Test it.
* web/ranch/app/controllers/graph_form_controller.rb: Ensure it.
* web/ranch/app/views/graph_form/index.rhtml: Keep the range
displayed when it drawn the graph.
app/controllers/graph_form_controller.rb | 17 ++++++++++++++-
app/views/graph_form/index.rhtml | 4 +--
test/functional/graph_form_controller_test.rb | 28 +++++++++++++++++++++++---
3 files changed, 43 insertions(+), 6 deletions(-)
Index: web/ranch/test/functional/graph_form_controller_test.rb
--- web/ranch/test/functional/graph_form_controller_test.rb (revision 16)
+++ web/ranch/test/functional/graph_form_controller_test.rb (working copy)
@@ -21,20 +21,42 @@
assert_not_nil assigns(:project)
assert_not_nil assigns(:bench_name)
assert !assigns(:draw_on)
+ assert_kind_of Hash, assigns(:revision)
+ assert assigns(:revision)[:start] < assigns(:revision)[:stop]
+ assert assigns(:revision)[:start] >= 1
end
- def test_draw
+ def test_draw_regular_revision_range
post :draw, {
:project_id => 1,
:bench_name => 'determinize',
- :revision => { :start => 0, :stop => 10 }
+ :revision => { :start => 2, :stop => 8 }
}
assert_response :success
assert_template 'index'
assert_not_nil assigns(:project)
assert_not_nil assigns(:bench_name)
- assert_not_nil assigns(:revision)
+ assert_kind_of Hash, assigns(:revision)
+ assert_equal 2, assigns(:revision)[:start]
+ assert_equal 8, assigns(:revision)[:stop]
+ assert assigns(:draw_on)
+ end
+
+ def test_draw_bad_revision_range
+ post :draw, {
+ :project_id => 1,
+ :bench_name => 'determinize',
+ :revision => { :start => -42, :stop => 500 }
+ }
+ assert_response :success
+ assert_template 'index'
+
+ assert_not_nil assigns(:project)
+ assert_not_nil assigns(:bench_name)
+ assert_kind_of Hash, assigns(:revision)
+ assert_equal 1, assigns(:revision)[:start]
+ assert_equal assigns(:project).head_revision, assigns(:revision)[:stop]
assert assigns(:draw_on)
end
Index: web/ranch/app/controllers/graph_form_controller.rb
--- web/ranch/app/controllers/graph_form_controller.rb (revision 16)
+++ web/ranch/app/controllers/graph_form_controller.rb (working copy)
@@ -2,17 +2,32 @@
helper :graph
layout 'ranch'
+ DEFAULT_REVISION_RANGE = 100
+
def index
@bench_name = params[:bench_name]
@project = Project.find params[:project_id]
@draw_on = false
+ @revision ||= {}
+
+ # Ensure revision number correctness
+ @revision[:stop] = @project.head_revision
+ @revision[:start] = @revision[:stop] - DEFAULT_REVISION_RANGE
+ @revision[:start] = 1 if @revision[:start] < 1
end
def draw
@bench_name = params[:bench_name]
@project = Project.find params[:project_id]
- @revision = params[:revision]
@draw_on = true
+ @revision = params[:revision]
+
+ # Ensure revision number correctness
+ head_rev = @project.head_revision
+ @revision[:stop] = @revision[:stop].to_i
+ @revision[:stop] = head_rev if @revision[:stop] > head_rev
+ @revision[:start] = @revision[:start].to_i
+ @revision[:start] = 1 if @revision[:start] < 1
render :action => 'index'
end
Index: web/ranch/app/views/graph_form/index.rhtml
--- web/ranch/app/views/graph_form/index.rhtml (revision 16)
+++ web/ranch/app/views/graph_form/index.rhtml (working copy)
@@ -16,9 +16,9 @@
</tr>
<tr>
<td><%= text_field "revision", "start", "size"
=> 8,
- "value" => 0 %></td>
+ "value" => @revision[:start] %></td>
<td><%= text_field "revision", "stop", "size"
=> 8,
- "value" => @project.head_revision %></td>
+ "value" => @revision[:stop] %></td>
</tr>
</table>
</p><p>