1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'old_way_controller'
4 class OldWayControllerTest < ActionController::TestCase
7 # -------------------------------------
8 # Test reading old ways.
9 # -------------------------------------
11 def test_history_visible
12 # check that a visible way is returned properly
13 get :history, :id => ways(:visible_way).id
14 assert_response :success
17 def test_history_invisible
18 # check that an invisible way's history is returned properly
19 get :history, :id => ways(:invisible_way).id
20 assert_response :success
23 def test_history_invalid
24 # check chat a non-existent way is not returned
25 get :history, :id => 0
26 assert_response :not_found
30 # check that we can retrieve versions of a way
32 check_current_version(current_ways(:visible_way).id)
33 check_current_version(current_ways(:used_way).id)
34 check_current_version(current_ways(:way_with_versions).id)
38 # check that returned history is the same as getting all
39 # versions of a way from the api.
40 def test_history_equals_versions
41 check_history_equals_versions(current_ways(:visible_way).id)
42 check_history_equals_versions(current_ways(:used_way).id)
43 check_history_equals_versions(current_ways(:way_with_versions).id)
47 # check that the current version of a way is equivalent to the
48 # version which we're getting from the versions call.
49 def check_current_version(way_id)
50 # get the current version
51 current_way = with_controller(WayController.new) do
52 get :read, :id => way_id
53 assert_response :success, "can't get current way #{way_id}"
54 Way.from_xml(@response.body)
56 assert_not_nil current_way, "getting way #{way_id} returned nil"
58 # get the "old" version of the way from the version method
59 get :version, :id => way_id, :version => current_way.version
60 assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
61 old_way = Way.from_xml(@response.body)
63 # check that the ways are identical
64 assert_ways_are_equal current_way, old_way
68 # look at all the versions of the way in the history and get each version from
69 # the versions call. check that they're the same.
70 def check_history_equals_versions(way_id)
71 get :history, :id => way_id
72 assert_response :success, "can't get way #{way_id} from API"
73 history_doc = XML::Parser.string(@response.body).parse
74 assert_not_nil history_doc, "parsing way #{way_id} history failed"
76 history_doc.find("//osm/way").each do |way_doc|
77 history_way = Way.from_xml_node(way_doc)
78 assert_not_nil history_way, "parsing way #{way_id} version failed"
80 get :version, :id => way_id, :version => history_way.version
81 assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}"
82 version_way = Way.from_xml(@response.body)
83 assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}"
85 assert_ways_are_equal history_way, version_way