5     class RelationsControllerTest < ActionDispatch::IntegrationTest
 
   7       # test all routes which lead to this controller
 
  10           { :path => "/api/0.6/relation/1/relations", :method => :get },
 
  11           { :controller => "api/relations/relations", :action => "index", :relation_id => "1" }
 
  14           { :path => "/api/0.6/relation/1/relations.json", :method => :get },
 
  15           { :controller => "api/relations/relations", :action => "index", :relation_id => "1", :format => "json" }
 
  20         relation = create(:relation)
 
  21         # should include relations with that relation as a member
 
  22         relation_with_relation = create(:relation_member, :member => relation).relation
 
  23         # should ignore any relation without that relation as a member
 
  24         _relation_without_relation = create(:relation_member).relation
 
  25         # should ignore relations with the relation involved indirectly, via a relation
 
  26         second_relation = create(:relation_member, :member => relation).relation
 
  27         _super_relation = create(:relation_member, :member => second_relation).relation
 
  28         # should combine multiple relation_member references into just one relation entry
 
  29         create(:relation_member, :member => relation, :relation => relation_with_relation)
 
  30         # should not include deleted relations
 
  31         deleted_relation = create(:relation, :deleted)
 
  32         create(:relation_member, :member => relation, :relation => deleted_relation)
 
  34         get api_relation_relations_path(relation)
 
  36         assert_response :success
 
  38         # count one osm element
 
  39         assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", 1
 
  41         # we should have only the expected number of relations
 
  42         expected_relations = [relation_with_relation, second_relation]
 
  43         assert_select "osm>relation", expected_relations.size
 
  45         # and each of them should contain the element we originally searched for
 
  46         expected_relations.each do |containing_relation|
 
  47           # The relation should appear once, but the element could appear multiple times
 
  48           assert_select "osm>relation[id='#{containing_relation.id}']", 1
 
  49           assert_select "osm>relation[id='#{containing_relation.id}']>member[type='relation'][ref='#{relation.id}']"
 
  54         relation = create(:relation)
 
  55         containing_relation = create(:relation_member, :member => relation).relation
 
  57         get api_relation_relations_path(relation, :format => "json")
 
  59         assert_response :success
 
  60         js = ActiveSupport::JSON.decode(@response.body)
 
  62         assert_equal 1, js["elements"].count
 
  63         js_relations = js["elements"].filter { |e| e["type"] == "relation" }
 
  64         assert_equal 1, js_relations.count
 
  65         assert_equal containing_relation.id, js_relations[0]["id"]