5     class RelationsControllerTest < ActionDispatch::IntegrationTest
 
   7       # test all routes which lead to this controller
 
  10           { :path => "/api/0.6/node/1/relations", :method => :get },
 
  11           { :controller => "api/nodes/relations", :action => "index", :node_id => "1" }
 
  14           { :path => "/api/0.6/node/1/relations.json", :method => :get },
 
  15           { :controller => "api/nodes/relations", :action => "index", :node_id => "1", :format => "json" }
 
  20       # check that all relations containing a particular node, and no extra
 
  21       # relations, are returned.
 
  24         # should include relations with that node as a member
 
  25         relation_with_node = create(:relation_member, :member => node).relation
 
  26         # should ignore relations without that node as a member
 
  27         _relation_without_node = create(:relation_member).relation
 
  28         # should ignore relations with the node involved indirectly, via a way
 
  29         way = create(:way_node, :node => node).way
 
  30         _relation_with_way = create(:relation_member, :member => way).relation
 
  31         # should ignore relations with the node involved indirectly, via a relation
 
  32         second_relation = create(:relation_member, :member => node).relation
 
  33         _super_relation = create(:relation_member, :member => second_relation).relation
 
  34         # should combine multiple relation_member references into just one relation entry
 
  35         create(:relation_member, :member => node, :relation => relation_with_node)
 
  36         # should not include deleted relations
 
  37         deleted_relation = create(:relation, :deleted)
 
  38         create(:relation_member, :member => node, :relation => deleted_relation)
 
  40         get api_node_relations_path(node)
 
  42         assert_response :success
 
  44         # count one osm element
 
  45         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", 1
 
  47         # we should have only the expected number of relations
 
  48         expected_relations = [relation_with_node, second_relation]
 
  49         assert_select "osm>relation", expected_relations.size
 
  51         # and each of them should contain the element we originally searched for
 
  52         expected_relations.each do |containing_relation|
 
  53           # The relation should appear once, but the element could appear multiple times
 
  54           assert_select "osm>relation[id='#{containing_relation.id}']", 1
 
  55           assert_select "osm>relation[id='#{containing_relation.id}']>member[type='node'][ref='#{node.id}']"
 
  61         containing_relation = create(:relation_member, :member => node).relation
 
  63         get api_node_relations_path(node, :format => "json")
 
  65         assert_response :success
 
  66         js = ActiveSupport::JSON.decode(@response.body)
 
  68         assert_equal 1, js["elements"].count
 
  69         js_relations = js["elements"].filter { |e| e["type"] == "relation" }
 
  70         assert_equal 1, js_relations.count
 
  71         assert_equal containing_relation.id, js_relations[0]["id"]