]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/way_controller_test.rb
Merge remote-tracking branch 'openstreetmap/pull/1395'
[rails.git] / test / controllers / way_controller_test.rb
index 8226f435ce09a68195f9d699ddd14cdd5320cc7b..650977078a1c31c1899e453ebd63e79bb1fcdaf1 100644 (file)
@@ -121,8 +121,8 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with pre-existing nodes
     content "<osm><way changeset='#{changeset_id}'>" +
-      "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
-      "<tag k='test' v='yes' /></way></osm>"
+            "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
+            "<tag k='test' v='yes' /></way></osm>"
     put :create
     # hope for failure
     assert_response :forbidden,
@@ -138,8 +138,8 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with pre-existing nodes
     content "<osm><way changeset='#{changeset_id}'>" +
-      "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
-      "<tag k='test' v='yes' /></way></osm>"
+            "<nd ref='#{nid1}'/><nd ref='#{nid2}'/>" +
+            "<tag k='test' v='yes' /></way></osm>"
     put :create
     # hope for success
     assert_response :success,
@@ -179,7 +179,7 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with non-existing node
     content "<osm><way changeset='#{open_changeset_id}'>" +
-      "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
+            "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
     put :create
     # expect failure
     assert_response :forbidden,
@@ -187,7 +187,7 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with no nodes
     content "<osm><way changeset='#{open_changeset_id}'>" +
-      "<tag k='test' v='yes' /></way></osm>"
+            "<tag k='test' v='yes' /></way></osm>"
     put :create
     # expect failure
     assert_response :forbidden,
@@ -195,7 +195,7 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way inside a closed changeset
     content "<osm><way changeset='#{closed_changeset_id}'>" +
-      "<nd ref='#{nid1}'/></way></osm>"
+            "<nd ref='#{nid1}'/></way></osm>"
     put :create
     # expect failure
     assert_response :forbidden,
@@ -211,7 +211,7 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with non-existing node
     content "<osm><way changeset='#{open_changeset_id}'>" +
-      "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
+            "<nd ref='0'/><tag k='test' v='yes' /></way></osm>"
     put :create
     # expect failure
     assert_response :precondition_failed,
@@ -220,7 +220,7 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with no nodes
     content "<osm><way changeset='#{open_changeset_id}'>" +
-      "<tag k='test' v='yes' /></way></osm>"
+            "<tag k='test' v='yes' /></way></osm>"
     put :create
     # expect failure
     assert_response :precondition_failed,
@@ -229,7 +229,7 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way inside a closed changeset
     content "<osm><way changeset='#{closed_changeset_id}'>" +
-      "<nd ref='#{nid1}'/></way></osm>"
+            "<nd ref='#{nid1}'/></way></osm>"
     put :create
     # expect failure
     assert_response :conflict,
@@ -237,9 +237,9 @@ class WayControllerTest < ActionController::TestCase
 
     # create a way with a tag which is too long
     content "<osm><way changeset='#{open_changeset_id}'>" +
-      "<nd ref='#{nid1}'/>" +
-      "<tag k='foo' v='#{'x' * 256}'/>" +
-      "</way></osm>"
+            "<nd ref='#{nid1}'/>" +
+            "<tag k='foo' v='#{'x' * 256}'/>" +
+            "</way></osm>"
     put :create
     # expect failure
     assert_response :bad_request,
@@ -538,10 +538,12 @@ class WayControllerTest < ActionController::TestCase
     # setup auth
     basic_authorization(users(:normal_user).email, "test")
 
+    existing = create(:way_tag, :way => current_ways(:visible_way))
+
     # add an identical tag to the way
     tag_xml = XML::Node.new("tag")
-    tag_xml["k"] = current_way_tags(:t1).k
-    tag_xml["v"] = current_way_tags(:t1).v
+    tag_xml["k"] = existing.k
+    tag_xml["v"] = existing.v
 
     # add the tag into the existing xml
     way_xml = current_ways(:visible_way).to_xml
@@ -559,8 +561,8 @@ class WayControllerTest < ActionController::TestCase
 
     # add an identical tag to the way
     tag_xml = XML::Node.new("tag")
-    tag_xml["k"] = current_way_tags(:t1).k
-    tag_xml["v"] = current_way_tags(:t1).v
+    tag_xml["k"] = existing.k
+    tag_xml["v"] = existing.v
 
     # add the tag into the existing xml
     way_xml = current_ways(:visible_way).to_xml
@@ -571,7 +573,7 @@ class WayControllerTest < ActionController::TestCase
     put :update, :id => current_ways(:visible_way).id
     assert_response :bad_request,
                     "adding a duplicate tag to a way should fail with 'bad request'"
-    assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{current_way_tags(:t1).k}", @response.body
+    assert_equal "Element way/#{current_ways(:visible_way).id} has duplicate tags with key #{existing.k}", @response.body
   end
 
   ##
@@ -673,8 +675,7 @@ class WayControllerTest < ActionController::TestCase
 
     # check that the set of IDs match expectations
     expected_way_ids = [current_ways(:visible_way).id,
-                        current_ways(:used_way).id
-                       ]
+                        current_ways(:used_way).id]
     found_way_ids = ways_xml.find("//osm/way").collect { |w| w["id"].to_i }
     assert_equal expected_way_ids.sort, found_way_ids.sort,
                  "expected ways for node #{current_nodes(:used_node_1).id} did not match found"