1 require File.dirname(__FILE__) + '/../test_helper'
2 require 'old_way_controller'
4 class OldWayControllerTest < ActionController::TestCase
8 # test all routes which lead to this controller
11 { :path => "/api/0.6/way/1/history", :method => :get },
12 { :controller => "old_way", :action => "history", :id => "1" }
15 { :path => "/api/0.6/way/1/2", :method => :get },
16 { :controller => "old_way", :action => "version", :id => "1", :version => "2" }
20 # -------------------------------------
21 # Test reading old ways.
22 # -------------------------------------
24 def test_history_visible
25 # check that a visible way is returned properly
26 get :history, :id => ways(:visible_way).way_id
27 assert_response :success
30 def test_history_invisible
31 # check that an invisible way's history is returned properly
32 get :history, :id => ways(:invisible_way).way_id
33 assert_response :success
36 def test_history_invalid
37 # check chat a non-existent way is not returned
38 get :history, :id => 0
39 assert_response :not_found
43 # check that we can retrieve versions of a way
45 check_current_version(current_ways(:visible_way).id)
46 check_current_version(current_ways(:used_way).id)
47 check_current_version(current_ways(:way_with_versions).id)
51 # check that returned history is the same as getting all
52 # versions of a way from the api.
53 def test_history_equals_versions
54 check_history_equals_versions(current_ways(:visible_way).id)
55 check_history_equals_versions(current_ways(:used_way).id)
56 check_history_equals_versions(current_ways(:way_with_versions).id)
60 # check that the current version of a way is equivalent to the
61 # version which we're getting from the versions call.
62 def check_current_version(way_id)
63 # get the current version
64 current_way = with_controller(WayController.new) do
65 get :read, :id => way_id
66 assert_response :success, "can't get current way #{way_id}"
67 Way.from_xml(@response.body)
69 assert_not_nil current_way, "getting way #{way_id} returned nil"
71 # get the "old" version of the way from the version method
72 get :version, :id => way_id, :version => current_way.version
73 assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
74 old_way = Way.from_xml(@response.body)
76 # check that the ways are identical
77 assert_ways_are_equal current_way, old_way
81 # look at all the versions of the way in the history and get each version from
82 # the versions call. check that they're the same.
83 def check_history_equals_versions(way_id)
84 get :history, :id => way_id
85 assert_response :success, "can't get way #{way_id} from API"
86 history_doc = XML::Parser.string(@response.body).parse
87 assert_not_nil history_doc, "parsing way #{way_id} history failed"
89 history_doc.find("//osm/way").each do |way_doc|
90 history_way = Way.from_xml_node(way_doc)
91 assert_not_nil history_way, "parsing way #{way_id} version failed"
93 get :version, :id => way_id, :version => history_way.version
94 assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}"
95 version_way = Way.from_xml(@response.body)
96 assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}"
98 assert_ways_are_equal history_way, version_way