close #411 segments should not be allowed where node_a == node_b
authorSteve Coast <steve@asklater.com>
Sun, 22 Apr 2007 10:10:43 +0000 (10:10 +0000)
committerSteve Coast <steve@asklater.com>
Sun, 22 Apr 2007 10:10:43 +0000 (10:10 +0000)
app/controllers/segment_controller.rb
config/environment.rb

index 28c7580df370db0a691c21e41e0efa85fe024685..c6d4ad611a7129288a8d831f76644b27f1805be2 100644 (file)
@@ -14,9 +14,14 @@ class SegmentController < ApplicationController
 
         segment.from_node = Node.find(segment.node_a.to_i)
         segment.to_node = Node.find(segment.node_b.to_i)
+          
+        if segment.from_node == segment.to_node
+          render :nothing => true, :status => HTTP_EXPECTATION_FAILED
+          return
+        end
         
         unless segment.preconditions_ok? # are the nodes visible?
-          render :nothing => true, :status => 412
+          render :nothing => true, :status => HTTP_PRECONDITION_FAILED
         end
 
         if segment.save_with_history
@@ -65,13 +70,19 @@ class SegmentController < ApplicationController
       segment.timestamp = Time.now
       segment.user_id = @user.id
 
+      if new_segment.node_a == new_segment.node_b
+        render :nothing => true, :status => HTTP_EXPECTATION_FAILED
+        return
+      end
+
       segment.node_a = new_segment.node_a
       segment.node_b = new_segment.node_b
+      
       segment.tags = new_segment.tags
       segment.visible = new_segment.visible
 
       if segment.id == new_segment.id and segment.save_with_history
-        render :nothing => true, :status => 200
+        render :nothing => true, :status => HTTP_OK
       else
         render :nothing => true, :status => 500
       end
index b55fbe44104e4b2896613e69b6d91a8d99168ee7..ac50d21f734c71b86d1ab5644e03fcd2b95f4d52 100644 (file)
@@ -61,3 +61,18 @@ ActionMailer::Base.server_settings = {
   :port  => 25, 
   :domain  => 'localhost',
 } 
+
+
+# HTTP CODES
+
+# 200's
+
+HTTP_OK = 200
+
+# 400's
+
+HTTP_PRECONDITION_FAILED = 412
+HTTP_EXPECTATION_FAILED = 417
+
+
+