Merge 16110:16487 from trunk.

This commit is contained in:
Tom Hughes 2009-07-14 08:03:24 +00:00
commit 64fb530581
99 changed files with 5157 additions and 1281 deletions

View file

@ -280,10 +280,13 @@ class AmfControllerTest < ActionController::TestCase
# ['way',wayid,history]
assert_equal 'way', history[0]
assert_equal latest.id, history[1]
# for some reason undocumented, the potlatch API now prefers dates
# over version numbers. presumably no-one edits concurrently any more?
assert_equal latest.timestamp.strftime("%d %b %Y, %H:%M:%S"), history[2].first[0]
assert_equal oldest.timestamp.strftime("%d %b %Y, %H:%M:%S"), history[2].last[0]
# We use dates rather than version numbers here, because you might
# have moved a node within a way (i.e. way version not incremented).
# The timestamp is +1 (timestamp.succ) because we say "give me the
# revision of 15:33:02", but that might actually include changes at
# 15:33:02.457.
assert_equal latest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), history[2].first[0]
assert_equal oldest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"), history[2].last[0]
end
def test_getway_history_nonexistent
@ -308,21 +311,18 @@ class AmfControllerTest < ActionController::TestCase
history = amf_result("/1")
# ['node',nodeid,history]
# note that (as per getway_history) we actually round up
# to the next second
assert_equal history[0], 'node',
'first element should be "node"'
assert_equal history[1], latest.id,
'second element should be the input node ID'
# NOTE: changed this test to match what amf_controller actually
# outputs - which may or may not be what potlatch is expecting.
# someone who knows potlatch (i.e: richard f) should review this.
# NOTE2: wow - this is the second time this has changed in the
# API and the tests are being patched up.
assert_equal history[2].first[0],
latest.timestamp.strftime("%d %b %Y, %H:%M:%S"),
'first part of third element should be the latest version'
latest.timestamp.succ.strftime("%d %b %Y, %H:%M:%S"),
'first element in third element (array) should be the latest version'
assert_equal history[2].last[0],
nodes(:node_with_versions_v1).timestamp.strftime("%d %b %Y, %H:%M:%S"),
'second part of third element should be the initial version'
nodes(:node_with_versions_v1).timestamp.succ.strftime("%d %b %Y, %H:%M:%S"),
'last element in third element (array) should be the initial version'
end
def test_getnode_history_nonexistent

View file

@ -1490,11 +1490,11 @@ EOF
def test_list
changesets = Changeset.find(:all, :order => "created_at DESC", :conditions => ['min_lat IS NOT NULL'], :limit=> 20)
assert changesets.size <= 20
get :list
get :list, {:format => "html"}
assert_response :success
assert_template "list"
# Now check that all 20 (or however many were returned) changesets are in the html
assert_select "h1", :text => "Recent Changes", :count => 1
assert_select "h1", :text => "Changesets", :count => 1
assert_select "table[id='changeset_list'] tr", :count => changesets.size + 1
changesets.each do |changeset|
# FIXME this test needs rewriting - test for table contents
@ -1505,16 +1505,16 @@ EOF
# Checks the display of the user changesets listing
def test_list_user
user = users(:public_user)
get :list_user, {:display_name => user.display_name}
get :list, {:format => "html", :display_name => user.display_name}
assert_response :success
assert_template 'list_user'
assert_template "list"
## FIXME need to add more checks to see which if edits are actually shown if your data is public
end
##
# Check the not found of the list user changesets
def test_list_user_not_found
get :list_user, {:display_name => "Some random user"}
get :list, {:format => "html", :display_name => "Some random user"}
assert_response :not_found
assert_template 'user/no_such_user'
end

View file

@ -0,0 +1,35 @@
require File.dirname(__FILE__) + '/../test_helper'
class ShortLinkTest < ActionController::IntegrationTest
##
# test the short link with various parameters and ensure they're
# kept in the redirect.
def test_short_link_params
assert_short_link_redirect('1N8H@P_5W')
assert_short_link_redirect(ShortLink::encode(-0.107846, 51.50771, 18))
end
##
# utility method to test short links
def assert_short_link_redirect(short_link)
lon, lat, zoom = ShortLink::decode(short_link)
# test without marker
get '/go/' + short_link
assert_redirected_to :controller => 'site', :action => 'index', :lat => lat, :lon => lon, :zoom => zoom
# test with marker
get '/go/' + short_link + "?m"
assert_redirected_to :controller => 'site', :action => 'index', :mlat => lat, :mlon => lon, :zoom => zoom
# test with layers and a marker
get '/go/' + short_link + "?m&layers=B000FTF"
assert_redirected_to :controller => 'site', :action => 'index', :mlat => lat, :mlon => lon, :zoom => zoom, :layers => "B000FTF"
get '/go/' + short_link + "?layers=B000FTF&m"
assert_redirected_to :controller => 'site', :action => 'index', :mlat => lat, :mlon => lon, :zoom => zoom, :layers => "B000FTF"
# test with some random query parameters we haven't even implemented yet
get '/go/' + short_link + "?foobar=yes"
assert_redirected_to :controller => 'site', :action => 'index', :lat => lat, :lon => lon, :zoom => zoom, :foobar => "yes"
end
end

View file

@ -0,0 +1,26 @@
require File.dirname(__FILE__) + '/../test_helper'
class ShortLinkTest < ActiveSupport::TestCase
##
# tests that encoding and decoding are working to within
# the acceptable quantisation range.
def test_encode_decode
cases = Array.new
1000.times do
cases << [ 180.0 * rand - 90.0, 360.0 * rand - 180.0, (18 * rand).to_i ]
end
cases.each do |lat, lon, zoom|
lon2, lat2, zoom2 = ShortLink.decode(ShortLink.encode(lon, lat, zoom))
# zooms should be identical
assert_equal zoom, zoom2, "Decoding a encoded short link gives different zoom for (#{lat}, #{lon}, #{zoom})."
# but the location has a quantisation error introduced at roughly
# one pixel (i.e: zoom + 8). the sqrt(5) is because each position
# has an extra bit of accuracy in the lat coordinate, due to the
# smaller range.
distance = Math.sqrt((lat - lat2) ** 2 + (lon - lon2) ** 2)
max_distance = 360.0 / (1 << (zoom + 8)) * 0.5 * Math.sqrt(5)
assert max_distance > distance, "Maximum expected error exceeded: #{max_distance} <= #{distance} for (#{lat}, #{lon}, #{zoom})."
end
end
end