1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'old_way_controller'
4 # Re-raise errors caught by the controller.
5 class OldWayController; def rescue_action(e) raise e end; end
7 class OldWayControllerTest < Test::Unit::TestCase
11 @controller = OldWayController.new
12 @request = ActionController::TestRequest.new
13 @response = ActionController::TestResponse.new
16 # -------------------------------------
17 # Test reading old ways.
18 # -------------------------------------
20 def test_history_visible
21 # check that a visible way is returned properly
22 get :history, :id => ways(:visible_way).id
23 assert_response :success
26 def test_history_invisible
27 # check that an invisible way's history is returned properly
28 get :history, :id => ways(:invisible_way).id
29 assert_response :success
32 def test_history_invalid
33 # check chat a non-existent way is not returned
34 get :history, :id => 0
35 assert_response :not_found
39 # check that we can retrieve versions of a way
41 check_current_version(current_ways(:visible_way).id)
42 check_current_version(current_ways(:used_way).id)
43 check_current_version(current_ways(:way_with_versions).id)
47 # check that returned history is the same as getting all
48 # versions of a way from the api.
49 def test_history_equals_versions
50 check_history_equals_versions(current_ways(:visible_way).id)
51 check_history_equals_versions(current_ways(:used_way).id)
52 check_history_equals_versions(current_ways(:way_with_versions).id)
56 # check that the current version of a way is equivalent to the
57 # version which we're getting from the versions call.
58 def check_current_version(way_id)
59 # get the current version
60 current_way = with_controller(WayController.new) do
61 get :read, :id => way_id
62 assert_response :success, "can't get current way #{way_id}"
63 Way.from_xml(@response.body)
65 assert_not_nil current_way, "getting way #{way_id} returned nil"
67 # get the "old" version of the way from the version method
68 get :version, :id => way_id, :version => current_way.version
69 assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
70 old_way = Way.from_xml(@response.body)
72 # check that the ways are identical
73 assert_ways_are_equal current_way, old_way
77 # look at all the versions of the way in the history and get each version from
78 # the versions call. check that they're the same.
79 def check_history_equals_versions(way_id)
80 get :history, :id => way_id
81 assert_response :success, "can't get way #{way_id} from API"
82 history_doc = XML::Parser.string(@response.body).parse
83 assert_not_nil history_doc, "parsing way #{way_id} history failed"
85 history_doc.find("//osm/way").each do |way_doc|
86 history_way = Way.from_xml_node(way_doc)
87 assert_not_nil history_way, "parsing way #{way_id} version failed"
89 get :version, :id => way_id, :version => history_way.version
90 assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}"
91 version_way = Way.from_xml(@response.body)
92 assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}"
94 assert_ways_are_equal history_way, version_way