]> git.openstreetmap.org Git - rails.git/commitdiff
Refactor some controller tests to use factories.
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 31 May 2017 13:51:53 +0000 (14:51 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 31 May 2017 13:51:53 +0000 (14:51 +0100)
test/controllers/changeset_controller_test.rb
test/controllers/relation_controller_test.rb

index ca8a802714a288104682712634790d7b5a9f2275..d90ee0eeec587bd9721872938a1f4225619ad4ac 100644 (file)
@@ -1235,14 +1235,15 @@ EOF
     assert_response :success
     changeset_id = @response.body.to_i
 
     assert_response :success
     changeset_id = @response.body.to_i
 
-    old_way = current_ways(:visible_way)
+    old_way = create(:way)
+    create(:way_node, :way => old_way, :node => create(:node, :lat => 1, :lon => 1))
 
     diff = XML::Document.new
     diff.root = XML::Node.new "osmChange"
     modify = XML::Node.new "modify"
     xml_old_way = old_way.to_xml_node
     nd_ref = XML::Node.new "nd"
 
     diff = XML::Document.new
     diff.root = XML::Node.new "osmChange"
     modify = XML::Node.new "modify"
     xml_old_way = old_way.to_xml_node
     nd_ref = XML::Node.new "nd"
-    nd_ref["ref"] = current_nodes(:visible_node).id.to_s
+    nd_ref["ref"] = create(:node, :lat => 3, :lon => 3).id.to_s
     xml_old_way << nd_ref
     xml_old_way["changeset"] = changeset_id.to_s
     modify << xml_old_way
     xml_old_way << nd_ref
     xml_old_way["changeset"] = changeset_id.to_s
     modify << xml_old_way
@@ -1510,6 +1511,9 @@ EOF
   # check that the bounding box of a changeset gets updated correctly
   # FIXME: This should really be moded to a integration test due to the with_controller
   def test_changeset_bbox
   # check that the bounding box of a changeset gets updated correctly
   # FIXME: This should really be moded to a integration test due to the with_controller
   def test_changeset_bbox
+    way = create(:way)
+    create(:way_node, :way => way, :node => create(:node, :lat => 3, :lon => 3))
+
     basic_authorization create(:user).email, "test"
 
     # create a new changeset
     basic_authorization create(:user).email, "test"
 
     # create a new changeset
@@ -1550,9 +1554,8 @@ EOF
 
     # add (delete) a way to it, which contains a point at (3,3)
     with_controller(WayController.new) do
 
     # add (delete) a way to it, which contains a point at (3,3)
     with_controller(WayController.new) do
-      content update_changeset(current_ways(:visible_way).to_xml,
-                               changeset_id)
-      put :delete, :id => current_ways(:visible_way).id
+      content update_changeset(way.to_xml, changeset_id)
+      put :delete, :id => way.id
       assert_response :success, "Couldn't delete a way."
     end
 
       assert_response :success, "Couldn't delete a way."
     end
 
index 613e95d162a0e6d79a57306301dfa79785b4700a..5ecd18fc7219edf0077694d77ac47892d6cda314 100644 (file)
@@ -654,15 +654,19 @@ class RelationControllerTest < ActionController::TestCase
   # add a member to a relation and check the bounding box is only that
   # element.
   def test_add_member_bounding_box
   # add a member to a relation and check the bounding box is only that
   # element.
   def test_add_member_bounding_box
-    relation_id = current_relations(:visible_relation).id
-
-    [current_nodes(:used_node_1),
-     current_nodes(:used_node_2),
-     current_ways(:used_way),
-     current_ways(:way_with_versions)].each_with_index do |element, _version|
+    relation = create(:relation)
+    node1 = create(:node, :lat => 4, :lon => 4)
+    node2 = create(:node, :lat => 7, :lon => 7)
+    way1 = create(:way)
+    create(:way_node, :way => way1, :node => create(:node, :lat => 8, :lon => 8))
+    way2 = create(:way)
+    create(:way_node, :way => way2, :node => create(:node, :lat => 9, :lon => 9), :sequence_id => 1)
+    create(:way_node, :way => way2, :node => create(:node, :lat => 10, :lon => 10), :sequence_id => 2)
+
+    [node1, node2, way1, way2].each do |element|
       bbox = element.bbox.to_unscaled
       check_changeset_modify(bbox) do |changeset_id|
       bbox = element.bbox.to_unscaled
       check_changeset_modify(bbox) do |changeset_id|
-        relation_xml = Relation.find(relation_id).to_xml
+        relation_xml = Relation.find(relation.id).to_xml
         relation_element = relation_xml.find("//osm/relation").first
         new_member = XML::Node.new("member")
         new_member["ref"] = element.id.to_s
         relation_element = relation_xml.find("//osm/relation").first
         new_member = XML::Node.new("member")
         new_member["ref"] = element.id.to_s
@@ -675,11 +679,11 @@ class RelationControllerTest < ActionController::TestCase
 
         # upload the change
         content relation_xml
 
         # upload the change
         content relation_xml
-        put :update, :id => current_relations(:visible_relation).id
+        put :update, :id => relation.id
         assert_response :success, "can't update relation for add #{element.class}/bbox test: #{@response.body}"
 
         # get it back and check the ordering
         assert_response :success, "can't update relation for add #{element.class}/bbox test: #{@response.body}"
 
         # get it back and check the ordering
-        get :read, :id => relation_id
+        get :read, :id => relation.id
         assert_response :success, "can't read back the relation: #{@response.body}"
         check_ordering(relation_xml, @response.body)
       end
         assert_response :success, "can't read back the relation: #{@response.body}"
         check_ordering(relation_xml, @response.body)
       end
@@ -907,7 +911,7 @@ OSM
   # that the changeset bounding box is +bbox+.
   def check_changeset_modify(bbox)
     ## First test with the private user to check that you get a forbidden
   # that the changeset bounding box is +bbox+.
   def check_changeset_modify(bbox)
     ## First test with the private user to check that you get a forbidden
-    basic_authorization(users(:normal_user).email, "test")
+    basic_authorization(create(:user, :data_public => false).email, "test")
 
     # create a new changeset for this operation, so we are assured
     # that the bounding box will be newly-generated.
 
     # create a new changeset for this operation, so we are assured
     # that the bounding box will be newly-generated.
@@ -918,7 +922,7 @@ OSM
     end
 
     ## Now do the whole thing with the public user
     end
 
     ## Now do the whole thing with the public user
-    basic_authorization(users(:public_user).email, "test")
+    basic_authorization(create(:user).email, "test")
 
     # create a new changeset for this operation, so we are assured
     # that the bounding box will be newly-generated.
 
     # create a new changeset for this operation, so we are assured
     # that the bounding box will be newly-generated.