5 class WaysControllerTest < ActionDispatch::IntegrationTest
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/node/1/ways", :method => :get },
11 { :controller => "api/nodes/ways", :action => "index", :node_id => "1" }
14 { :path => "/api/0.6/node/1/ways.json", :method => :get },
15 { :controller => "api/nodes/ways", :action => "index", :node_id => "1", :format => "json" }
20 # test that a call to ways_for_node returns all ways that contain the node
21 # and none that don't.
26 create(:way_node, :way => way1, :node => node)
27 create(:way_node, :way => way2, :node => node)
28 # create an unrelated way
29 create(:way_with_nodes, :nodes_count => 2)
30 # create a way which used to use the node
31 way3_v1 = create(:old_way, :version => 1)
32 _way3_v2 = create(:old_way, :current_way => way3_v1.current_way, :version => 2)
33 create(:old_way_node, :old_way => way3_v1, :node => node)
35 get api_node_ways_path(node)
36 assert_response :success
37 ways_xml = XML::Parser.string(@response.body).parse
38 assert_not_nil ways_xml, "failed to parse ways_for_node response"
40 # check that the set of IDs match expectations
41 expected_way_ids = [way1.id,
43 found_way_ids = ways_xml.find("//osm/way").collect { |w| w["id"].to_i }
44 assert_equal expected_way_ids.sort, found_way_ids.sort,
45 "expected ways for node #{node.id} did not match found"
47 # check the full ways to ensure we're not missing anything
48 expected_way_ids.each do |id|
49 way_xml = ways_xml.find("//osm/way[@id='#{id}']").first
50 assert_ways_are_equal(Way.find(id),
51 Way.from_xml_node(way_xml))
58 create(:way_node, :way => way, :node => node)
60 get api_node_ways_path(node, :format => "json")
62 assert_response :success
63 js = ActiveSupport::JSON.decode(@response.body)
65 assert_equal 1, js["elements"].count
66 js_ways = js["elements"].filter { |e| e["type"] == "way" }
67 assert_equal 1, js_ways.count
68 assert_equal way.id, js_ways[0]["id"]