From: Matt Amos Date: Mon, 13 Oct 2008 14:08:31 +0000 (+0000) Subject: Fixed node functional tests. A couple of changes to the old_node model and node contr... X-Git-Tag: live~7577^2~280 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/a2498928e470b358f69902d9fdc72a1a80aa5bf8 Fixed node functional tests. A couple of changes to the old_node model and node controller for changesets. --- diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 29bf672e2..62e680388 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -96,7 +96,7 @@ class NodeController < ApplicationController if new_node and new_node.id == node.id node.delete_with_history(new_node, @user) - render :nothing => true, :status => :success + render :nothing => true else render :nothing => true, :status => :bad_request end diff --git a/app/models/old_node.rb b/app/models/old_node.rb index d4d9f1775..e7d803044 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -38,6 +38,7 @@ class OldNode < ActiveRecord::Base el1['id'] = self.id.to_s el1['lat'] = self.lat.to_s el1['lon'] = self.lon.to_s + el1['changeset'] = self.changeset.id.to_s el1['user'] = self.changeset.user.display_name if self.changeset.user.data_public? self.tags.each do |k,v| diff --git a/lib/geo_record.rb b/lib/geo_record.rb index 273419757..645ddc93a 100644 --- a/lib/geo_record.rb +++ b/lib/geo_record.rb @@ -53,8 +53,6 @@ module GeoRecord raise OSM::APIVersionMismatchError.new(new.version, old.version) elsif new.changeset.nil? raise OSM::APIChangesetMissingError.new - elsif new.changeset.empty? - raise OSM::APIChangesetMissingError.new elsif new.changeset.user_id != user.id raise OSM::APIUserChangesetMismatchError.new elsif not new.changeset.is_open? diff --git a/test/fixtures/node_tags.yml b/test/fixtures/node_tags.yml index c32dc6c55..8c80128b0 100644 --- a/test/fixtures/node_tags.yml +++ b/test/fixtures/node_tags.yml @@ -1,17 +1,17 @@ t1: - id: visible_node + id: 1 k: testvisible v: yes version: 1 t2: - id: used_node_1 + id: 3 k: testused v: yes version: 1 t3: - id: used_node_2 + id: 4 k: test v: yes version: 1 diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb index 59b28e114..a8ef700a3 100644 --- a/test/functional/node_controller_test.rb +++ b/test/functional/node_controller_test.rb @@ -21,10 +21,14 @@ class NodeControllerTest < Test::Unit::TestCase # create a node with random lat/lon lat = rand(100)-50 + rand lon = rand(100)-50 + rand - content("") + # normal user has a changeset open, so we'll use that. + changeset = changesets(:normal_user_first_change) + # create a minimal xml file + content("") put :create # hope for success assert_response :success, "node upload did not return success status" + # read id of created node and search for it nodeid = @response.body checknode = Node.find(nodeid) @@ -32,7 +36,7 @@ class NodeControllerTest < Test::Unit::TestCase # compare values assert_in_delta lat * 10000000, checknode.latitude, 1, "saved node does not match requested latitude" assert_in_delta lon * 10000000, checknode.longitude, 1, "saved node does not match requested longitude" - assert_equal users(:normal_user).id, checknode.user_id, "saved node does not belong to user that created it" + assert_equal changesets(:normal_user_first_change).id, checknode.changeset_id, "saved node does not belong to changeset that it was created in" assert_equal true, checknode.visible, "saved node is not visible" end @@ -61,11 +65,13 @@ class NodeControllerTest < Test::Unit::TestCase # now set auth basic_authorization(users(:normal_user).email, "test"); - # this should work + # delete now takes a payload + content(nodes(:visible_node).to_xml) delete :delete, :id => current_nodes(:visible_node).id assert_response :success # this won't work since the node is already deleted + content(nodes(:invisible_node).to_xml) delete :delete, :id => current_nodes(:invisible_node).id assert_response :gone @@ -74,6 +80,7 @@ class NodeControllerTest < Test::Unit::TestCase assert_response :not_found # this won't work since the node is in use + content(nodes(:used_node_1).to_xml) delete :delete, :id => current_nodes(:used_node_1).id assert_response :precondition_failed end @@ -84,6 +91,6 @@ class NodeControllerTest < Test::Unit::TestCase end def content(c) - @request.env["RAW_POST_DATA"] = c + @request.env["RAW_POST_DATA"] = c.to_s end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 22cc0e15c..0c03aac34 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -27,12 +27,15 @@ class Test::Unit::TestCase # Load standard fixtures needed to test API methods def self.api_fixtures - fixtures :users + fixtures :users, :changesets - fixtures :current_nodes, :nodes, :current_node_tags + fixtures :current_nodes, :nodes set_fixture_class :current_nodes => :Node set_fixture_class :nodes => :OldNode + + fixtures :current_node_tags,:node_tags set_fixture_class :current_node_tags => :NodeTag + set_fixture_class :node_tags => :OldNodeTag fixtures :current_ways, :current_way_nodes, :current_way_tags set_fixture_class :current_ways => :Way