X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/fffc572767a9b70c646a2b7d085cadc4686e826f..241c724adb5d8099da6c1264f1c61266cc42bcb3:/test/controllers/changeset_controller_test.rb diff --git a/test/controllers/changeset_controller_test.rb b/test/controllers/changeset_controller_test.rb index ca8a80271..c7309ff67 100644 --- a/test/controllers/changeset_controller_test.rb +++ b/test/controllers/changeset_controller_test.rb @@ -2,8 +2,6 @@ require "test_helper" require "changeset_controller" class ChangesetControllerTest < ActionController::TestCase - api_fixtures - ## # test all routes which lead to this controller def test_routes @@ -424,6 +422,9 @@ EOF def test_upload_create_valid user = create(:user) changeset = create(:changeset, :user => user) + node = create(:node) + way = create(:way_with_nodes, :nodes_count => 2) + relation = create(:relation) basic_authorization user.email, "test" @@ -436,14 +437,14 @@ EOF - + - - - + + + @@ -870,6 +871,7 @@ EOF ## # upload multiple versions of the same element in the same diff. def test_upload_multiple_valid + node = create(:node) changeset = create(:changeset) basic_authorization changeset.user.email, "test" @@ -879,14 +881,14 @@ EOF diff = < - - - - - - - - + + + + + + + + EOF @@ -907,6 +909,7 @@ EOF # upload multiple versions of the same element in the same diff, but # keep the version numbers the same. def test_upload_multiple_duplicate + node = create(:node) changeset = create(:changeset) basic_authorization changeset.user.email, "test" @@ -914,8 +917,8 @@ EOF diff = < - - + + EOF @@ -1235,14 +1238,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 @@ -1314,6 +1318,8 @@ EOF # when we make some simple changes we get the same changes back from the # diff download. def test_diff_download_simple + node = create(:node) + ## First try with a non-public user, which should get a forbidden basic_authorization(create(:user, :data_public => false).email, "test") @@ -1339,14 +1345,14 @@ EOF diff = < - - - - - - - - + + + + + + + + EOF @@ -1430,6 +1436,9 @@ OSMFILE # when we make some complex changes we get the same changes back from the # diff download. def test_diff_download_complex + node = create(:node) + node2 = create(:node) + way = create(:way) basic_authorization(create(:user).email, "test") # create a temporary changeset @@ -1444,7 +1453,7 @@ OSMFILE diff = < - + @@ -1452,9 +1461,9 @@ OSMFILE - - - + + + @@ -1510,6 +1519,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 +1562,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 @@ -1627,14 +1638,16 @@ EOF user = create(:user) changeset = create(:changeset, :user => user) closed_changeset = create(:changeset, :closed, :user => user, :created_at => Time.utc(2008, 1, 1, 0, 0, 0), :closed_at => Time.utc(2008, 1, 2, 0, 0, 0)) + changeset2 = create(:changeset, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 15 * GeoRecord::SCALE, :max_lon => 15 * GeoRecord::SCALE) + changeset3 = create(:changeset, :min_lat => 4.5 * GeoRecord::SCALE, :min_lon => 4.5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE) get :query, :bbox => "-10,-10, 10, 10" assert_response :success, "can't get changesets in bbox" - assert_changesets [1, 4, 6] + assert_changesets [changeset2.id, changeset3.id] get :query, :bbox => "4.5,4.5,4.6,4.6" assert_response :success, "can't get changesets in bbox" - assert_changesets [1] + assert_changesets [changeset3.id] # not found when looking for changesets of non-existing users get :query, :user => User.maximum(:id) + 1 @@ -1668,23 +1681,23 @@ EOF get :query, :time => "2007-12-31" assert_response :success, "can't get changesets by time-since" - assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id] + assert_changesets [private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id, changeset2.id, changeset3.id] get :query, :time => "2008-01-01T12:34Z" assert_response :success, "can't get changesets by time-since with hour" - assert_changesets [1, 2, 4, 5, 6, private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id] + assert_changesets [private_user_changeset.id, private_user_closed_changeset.id, changeset.id, closed_changeset.id, changeset2.id, changeset3.id] get :query, :time => "2007-12-31T23:59Z,2008-01-02T00:01Z" assert_response :success, "can't get changesets by time-range" - assert_changesets [1, 5, 6, closed_changeset.id] + assert_changesets [closed_changeset.id] get :query, :open => "true" assert_response :success, "can't get changesets by open-ness" - assert_changesets [1, 2, 4, private_user_changeset.id, changeset.id] + assert_changesets [private_user_changeset.id, changeset.id, changeset2.id, changeset3.id] get :query, :closed => "true" assert_response :success, "can't get changesets by closed-ness" - assert_changesets [3, 5, 6, 7, 8, 9, private_user_closed_changeset.id, closed_changeset.id] + assert_changesets [private_user_closed_changeset.id, closed_changeset.id] get :query, :closed => "true", :user => private_user.id assert_response :success, "can't get changesets by closed-ness and user" @@ -2033,37 +2046,46 @@ EOF ## # This should display the last 20 changesets closed def test_feed + changeset = create(:changeset, :num_changes => 1) + _empty_changeset = create(:changeset, :num_changes => 0) + get :feed, :format => :atom assert_response :success assert_template "list" assert_equal "application/atom+xml", response.content_type - check_feed_result(Changeset.all) + check_feed_result([changeset]) end ## # This should display the last 20 changesets closed in a specific area def test_feed_bbox + changeset = create(:changeset, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE) + closed_changeset = create(:changeset, :closed, :num_changes => 1, :min_lat => 5 * GeoRecord::SCALE, :min_lon => 5 * GeoRecord::SCALE, :max_lat => 5 * GeoRecord::SCALE, :max_lon => 5 * GeoRecord::SCALE) + _elsewhere_changeset = create(:changeset, :num_changes => 1, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE) + _empty_changeset = create(:changeset, :num_changes => 0, :min_lat => -5 * GeoRecord::SCALE, :min_lon => -5 * GeoRecord::SCALE, :max_lat => -5 * GeoRecord::SCALE, :max_lon => -5 * GeoRecord::SCALE) + get :feed, :format => :atom, :bbox => "4.5,4.5,5.5,5.5" assert_response :success assert_template "list" assert_equal "application/atom+xml", response.content_type - check_feed_result(Changeset.where("min_lon < 55000000 and max_lon > 45000000 and min_lat < 55000000 and max_lat > 45000000")) + check_feed_result([changeset, closed_changeset]) end ## # Checks the display of the user changesets feed def test_feed_user user = create(:user) - create_list(:changeset, 3, :user => user, :num_changes => 4) + changesets = create_list(:changeset, 3, :user => user, :num_changes => 4) + _other_changeset = create(:changeset) get :feed, :format => :atom, :display_name => user.display_name assert_response :success assert_template "list" assert_equal "application/atom+xml", response.content_type - check_feed_result(user.changesets) + check_feed_result(changesets) end ## @@ -2477,9 +2499,6 @@ EOF ## # check the result of a feed def check_feed_result(changesets) - changesets = changesets.where("num_changes > 0") - .order(:created_at => :desc) - .limit(20) assert changesets.size <= 20 assert_select "feed", :count => [changesets.size, 1].min do