More test coverage improvements

This commit is contained in:
Tom Hughes 2015-03-01 00:44:32 +00:00
parent d6bbcae9db
commit bc056a5e98
4 changed files with 82 additions and 22 deletions

View file

@ -610,7 +610,8 @@ class AmfController < ApplicationController
# 3. new way id,
# 4. hash of renumbered nodes (old id=>new id),
# 5. way version,
# 6. hash of node versions (node=>version)
# 6. hash of changed node versions (node=>version)
# 7. hash of deleted node versions (node=>version)
def putway(renumberednodes, usertoken, changeset_id, wayversion, originalway, pointlist, attributes, nodes, deletednodes) #:doc:
amf_handle_error("'putway' #{originalway}", "way", originalway) do

View file

@ -19,25 +19,30 @@ class AmfControllerTest < ActionController::TestCase
end
def test_getpresets
amf_content "getpresets", "/1", ["test@example.com:test", ""]
post :amf_read
assert_response :success
amf_parse_response
presets = amf_result("/1")
[:public_user, :german_user].each do |id|
user = users(id)
assert_equal 15, presets.length
assert_equal POTLATCH_PRESETS[0], presets[0]
assert_equal POTLATCH_PRESETS[1], presets[1]
assert_equal POTLATCH_PRESETS[2], presets[2]
assert_equal POTLATCH_PRESETS[3], presets[3]
assert_equal POTLATCH_PRESETS[4], presets[4]
assert_equal POTLATCH_PRESETS[5], presets[5]
assert_equal POTLATCH_PRESETS[6], presets[6]
assert_equal POTLATCH_PRESETS[7], presets[7]
assert_equal POTLATCH_PRESETS[8], presets[8]
assert_equal POTLATCH_PRESETS[9], presets[9]
assert_equal POTLATCH_PRESETS[10], presets[10]
assert_equal POTLATCH_PRESETS[12], presets[12]
amf_content "getpresets", "/1", ["#{user.email}:test", ""]
post :amf_read
assert_response :success
amf_parse_response
presets = amf_result("/1")
assert_equal 15, presets.length
assert_equal POTLATCH_PRESETS[0], presets[0]
assert_equal POTLATCH_PRESETS[1], presets[1]
assert_equal POTLATCH_PRESETS[2], presets[2]
assert_equal POTLATCH_PRESETS[3], presets[3]
assert_equal POTLATCH_PRESETS[4], presets[4]
assert_equal POTLATCH_PRESETS[5], presets[5]
assert_equal POTLATCH_PRESETS[6], presets[6]
assert_equal POTLATCH_PRESETS[7], presets[7]
assert_equal POTLATCH_PRESETS[8], presets[8]
assert_equal POTLATCH_PRESETS[9], presets[9]
assert_equal POTLATCH_PRESETS[10], presets[10]
assert_equal POTLATCH_PRESETS[12], presets[12]
assert_equal user.languages.first, presets[13]["__potlatch_locale"]
end
end
def test_getway
@ -863,6 +868,7 @@ class AmfControllerTest < ActionController::TestCase
def test_putway_update_valid
way = current_ways(:way_with_multiple_nodes)
cs_id = changesets(:public_user_first_change).id
amf_content "putway", "/1", ["test@example.com:test", cs_id, way.version, way.id, way.nds, { "test" => "ok" }, [], {}]
post :amf_write
assert_response :success
@ -904,6 +910,46 @@ class AmfControllerTest < ActionController::TestCase
assert_equal way.version + 2, new_way.version
assert_equal [4, 6, 15, 1], new_way.nds
assert_equal way.tags, new_way.tags
amf_content "putway", "/1", ["test@example.com:test", cs_id, way.version + 2, way.id, [4, -1, 6, 15], way.tags, [[4.56, 12.34, -1, 0, { "test" => "new" }], [12.34, 4.56, 6, 1, { "test" => "ok" }]], { 1 => 1 }]
post :amf_write
assert_response :success
amf_parse_response
result = amf_result("/1")
new_node_id = result[4]["-1"].to_i
assert_equal 8, result.size
assert_equal 0, result[0]
assert_equal "", result[1]
assert_equal way.id, result[2]
assert_equal way.id, result[3]
assert_equal({ "-1" => new_node_id }, result[4])
assert_equal way.version + 3, result[5]
assert_equal({ new_node_id.to_s => 1, "6" => 2 }, result[6])
assert_equal({ "1" => 1 }, result[7])
new_way = Way.find(way.id)
assert_equal way.version + 3, new_way.version
assert_equal [4, new_node_id, 6, 15], new_way.nds
assert_equal way.tags, new_way.tags
new_node = Node.find(new_node_id)
assert_equal 1, new_node.version
assert_equal true, new_node.visible
assert_equal 4.56, new_node.lon
assert_equal 12.34, new_node.lat
assert_equal({ "test" => "new" }, new_node.tags)
changed_node = Node.find(6)
assert_equal 2, changed_node.version
assert_equal true, changed_node.visible
assert_equal 12.34, changed_node.lon
assert_equal 4.56, changed_node.lat
assert_equal({ "test" => "ok" }, changed_node.tags)
deleted_node = Node.find(1)
assert_equal 2, deleted_node.version
assert_equal false, deleted_node.visible
end
def test_startchangeset_invalid_xmlchar_comment

View file

@ -228,3 +228,16 @@ north_pole_user:
languages: en
home_lat: 89.9
home_lon: 146.8
german_user:
id: 18
email: german@example.com
status: active
pass_crypt: <%= Digest::MD5.hexdigest('test') %>
creation_time: "2008-05-01 01:23:45"
display_name: germanuser
data_public: true
description: deutsch sprechen
terms_agreed: "2010-01-01 11:22:33"
terms_seen: true
languages: de

View file

@ -163,7 +163,7 @@ class UserTest < ActiveSupport::TestCase
end
def test_visible
assert_equal 15, User.visible.count
assert_equal 16, User.visible.count
assert_raise ActiveRecord::RecordNotFound do
User.visible.find(users(:suspended_user).id)
end
@ -173,7 +173,7 @@ class UserTest < ActiveSupport::TestCase
end
def test_active
assert_equal 14, User.active.count
assert_equal 15, User.active.count
assert_raise ActiveRecord::RecordNotFound do
User.active.find(users(:inactive_user).id)
end
@ -186,7 +186,7 @@ class UserTest < ActiveSupport::TestCase
end
def test_identifiable
assert_equal 16, User.identifiable.count
assert_equal 17, User.identifiable.count
assert_raise ActiveRecord::RecordNotFound do
User.identifiable.find(users(:normal_user).id)
end