From: Andy Allan Date: Wed, 31 May 2017 13:51:53 +0000 (+0100) Subject: Refactor some controller tests to use factories. X-Git-Tag: live~3377 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/f735b073093bb4611da54530fc8e749554ccda7d?hp=938786e1ee6520d705ed09524d8d3f4d8f875791 Refactor some controller tests to use factories. --- diff --git a/test/controllers/changeset_controller_test.rb b/test/controllers/changeset_controller_test.rb index ca8a80271..d90ee0eee 100644 --- a/test/controllers/changeset_controller_test.rb +++ b/test/controllers/changeset_controller_test.rb @@ -1235,14 +1235,15 @@ EOF 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" - 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 @@ -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 + 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 @@ -1550,9 +1554,8 @@ EOF # 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 diff --git a/test/controllers/relation_controller_test.rb b/test/controllers/relation_controller_test.rb index 613e95d16..5ecd18fc7 100644 --- a/test/controllers/relation_controller_test.rb +++ b/test/controllers/relation_controller_test.rb @@ -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 - 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| - 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 @@ -675,11 +679,11 @@ class RelationControllerTest < ActionController::TestCase # 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 - 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 @@ -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 - 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. @@ -918,7 +922,7 @@ OSM 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.