Skip to content

Commit

Permalink
More test coverage improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Mar 1, 2015
1 parent d6bbcae commit bc056a5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 22 deletions.
3 changes: 2 additions & 1 deletion app/controllers/amf_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ def putrelation(renumberednodes, renumberedways, usertoken, changeset_id, versio
# 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
Expand Down
82 changes: 64 additions & 18 deletions test/controllers/amf_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@ def test_routes
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
Expand Down Expand Up @@ -863,6 +868,7 @@ def test_putpoi_invalid_latlon
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
Expand Down Expand Up @@ -904,6 +910,46 @@ def test_putway_update_valid
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
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_user_preferred_editor
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
Expand All @@ -173,7 +173,7 @@ def test_visible
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
Expand All @@ -186,7 +186,7 @@ def test_active
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
Expand Down

0 comments on commit bc056a5

Please sign in to comment.