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