]> git.openstreetmap.org Git - rails.git/blob - test/functional/old_way_controller_test.rb
cover the other extreme in the map bounary sanitizeation. Ading some documentation...
[rails.git] / test / functional / old_way_controller_test.rb
1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'old_way_controller'
3
4 # Re-raise errors caught by the controller.
5 class OldWayController; def rescue_action(e) raise e end; end
6
7 class OldWayControllerTest < Test::Unit::TestCase
8   api_fixtures
9
10   def setup
11     @controller = OldWayController.new
12     @request    = ActionController::TestRequest.new
13     @response   = ActionController::TestResponse.new
14   end
15
16   # -------------------------------------
17   # Test reading old ways.
18   # -------------------------------------
19
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
24   end
25   
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
30   end
31   
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
36   end
37   
38   ##
39   # check that we can retrieve versions of a way
40   def test_version
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)
44   end
45
46   ##
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)
53   end
54
55   ##
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)
64     end
65     assert_not_nil current_way, "getting way #{way_id} returned nil"
66
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)
71
72     # check that the ways are identical
73     assert_ways_are_equal current_way, old_way
74   end
75
76   ##
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"
84
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"
88
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}"
93       
94       assert_ways_are_equal history_way, version_way
95     end
96   end
97
98 end