https://svn.lrde.epita.fr/svn/ranch/trunk
Index: ChangeLog
from Nicolas Despr�s <nicolas.despres(a)gmail.com>
Check that Start rev > Stop rev.
* web/ranch/app/views/graph_form/index.rhtml: Display an error message
if the the revision range is invalid.
* web/ranch/app/controllers/graph_form_controller.rb: Check for
revision range validity and raise an error message.
* web/ranch/test/functional/graph_form_controller_test.rb: Test that
the error handling works fine.
app/controllers/graph_form_controller.rb | 16 ++++++++++------
app/views/graph_form/index.rhtml | 9 +++++----
test/functional/graph_form_controller_test.rb | 14 ++++++++++++++
3 files changed, 29 insertions(+), 10 deletions(-)
Index: web/ranch/app/views/graph_form/index.rhtml
--- web/ranch/app/views/graph_form/index.rhtml (revision 17)
+++ web/ranch/app/views/graph_form/index.rhtml (working copy)
@@ -21,16 +21,17 @@
"value" => @revision[:stop] %></td>
</tr>
</table>
-</p><p>
-<%= submit_tag "Draw" %>
-</p><p>
+</p>
+<p style="color: red;"><%= flash[:error] %></p>
+<p><%= submit_tag "Draw" %></p>
+<p>
<%= end_form_tag %>
<% if @draw_on %>
<%= graph_reg_tag @project.id, @bench_name,
@revision[:start], @revision[:stop] %>
<% else %>
- <%= content_tag "p", "No chart to display - click Draw" %>
+ <%= content_tag "p", "No chart to display - click on Draw"
%>
<% end %>
</p></center></p>
<p><%= link_to "Back", :controller => "benches",
Index: web/ranch/app/controllers/graph_form_controller.rb
--- web/ranch/app/controllers/graph_form_controller.rb (revision 17)
+++ web/ranch/app/controllers/graph_form_controller.rb (working copy)
@@ -8,9 +8,7 @@
@bench_name = params[:bench_name]
@project = Project.find params[:project_id]
@draw_on = false
- @revision ||= {}
-
- # Ensure revision number correctness
+ @revision = {}
@revision[:stop] = @project.head_revision
@revision[:start] = @revision[:stop] - DEFAULT_REVISION_RANGE
@revision[:start] = 1 if @revision[:start] < 1
@@ -21,14 +19,20 @@
@project = Project.find params[:project_id]
@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
+ if @revision[:start] < @revision[:stop]
+ @draw_on = true
render :action => 'index'
+ else
+ flash[:error] = 'The start revision must be lesser than ' +
+ 'the stop revision.'
+ redirect_to(:action => 'index',
+ :project_id => @project.id,
+ :bench_name => @bench_name)
+ end
end
-
end
Index: web/ranch/test/functional/graph_form_controller_test.rb
--- web/ranch/test/functional/graph_form_controller_test.rb (revision 17)
+++ web/ranch/test/functional/graph_form_controller_test.rb (working copy)
@@ -60,4 +60,18 @@
assert assigns(:draw_on)
end
+ def test_draw_start_sup_stop
+ post :draw, {
+ :project_id => 1,
+ :bench_name => 'determinize',
+ :revision => { :start => 42, :stop => 10 }
+ }
+ assert_response :redirect
+ assert_redirected_to :action => 'index'
+
+ assert_equal 1, assigns(:project).id
+ assert_equal 'determinize', assigns(:bench_name)
+ assert flash.has_key? :error
+ end
+
end