X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b56f57ec43dfefa4171dc0cefe26d9e75d4ca2bc..850bd333eb6b53dc76ccf64218012b110396af57:/test/functional/node_controller_test.rb
diff --git a/test/functional/node_controller_test.rb b/test/functional/node_controller_test.rb
index dbc00cbb2..bc9ffa489 100644
--- a/test/functional/node_controller_test.rb
+++ b/test/functional/node_controller_test.rb
@@ -1,21 +1,11 @@
require File.dirname(__FILE__) + '/../test_helper'
-require 'node_controller'
-# Re-raise errors caught by the controller.
-class NodeController; def rescue_action(e) raise e end; end
-
-class NodeControllerTest < Test::Unit::TestCase
+class NodeControllerTest < ActionController::TestCase
api_fixtures
- def setup
- @controller = NodeController.new
- @request = ActionController::TestRequest.new
- @response = ActionController::TestResponse.new
- end
-
def test_create
# cannot read password from fixture as it is stored as MD5 digest
- basic_authorization(users(:normal_user).email, "test");
+ basic_authorization(users(:normal_user).email, "test")
# create a node with random lat/lon
lat = rand(100)-50 + rand
@@ -39,6 +29,32 @@ class NodeControllerTest < Test::Unit::TestCase
assert_equal true, checknode.visible, "saved node is not visible"
end
+ def test_create_invalid_xml
+ # Initial setup
+ basic_authorization(users(:normal_user).email, "test")
+ # normal user has a changeset open, so we'll use that.
+ changeset = changesets(:normal_user_first_change)
+ lat = 3.434
+ lon = 3.23
+
+ # test that the upload is rejected when no lat is supplied
+ # create a minimal xml file
+ content("")
+ put :create
+ # hope for success
+ assert_response :bad_request, "node upload did not return bad_request status"
+ assert_equal 'Cannot parse valid node from xml string . lat missing', @response.body
+
+ # test that the upload is rejected when no lon is supplied
+ # create a minimal xml file
+ content("")
+ put :create
+ # hope for success
+ assert_response :bad_request, "node upload did not return bad_request status"
+ assert_equal 'Cannot parse valid node from xml string . lon missing', @response.body
+
+ end
+
def test_read
# check that a visible node is returned properly
get :read, :id => current_nodes(:visible_node).id
@@ -203,7 +219,8 @@ class NodeControllerTest < Test::Unit::TestCase
content node_xml
put :update, :id => current_nodes(:visible_node).id
assert_response :bad_request,
- "adding duplicate tags to a node should fail with 'bad request'"
+ "adding duplicate tags to a node should fail with 'bad request'"
+ assert_equal "Element node/#{current_nodes(:visible_node).id} has duplicate tags with key #{current_node_tags(:t1).k}.", @response.body
end
# test whether string injection is possible