X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/c56f7a37fc056d921fdbd8b3eec49a9d84f092c9..c51786d10bc6dda488964f468a6a3071dd6912a8:/test/controllers/api/relations_controller_test.rb diff --git a/test/controllers/api/relations_controller_test.rb b/test/controllers/api/relations_controller_test.rb index b7c17a176..5116ddb02 100644 --- a/test/controllers/api/relations_controller_test.rb +++ b/test/controllers/api/relations_controller_test.rb @@ -13,10 +13,18 @@ module Api { :path => "/api/0.6/relation/1/full", :method => :get }, { :controller => "api/relations", :action => "full", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/relation/1/full.json", :method => :get }, + { :controller => "api/relations", :action => "full", :id => "1", :format => "json" } + ) assert_routing( { :path => "/api/0.6/relation/1", :method => :get }, { :controller => "api/relations", :action => "show", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/relation/1.json", :method => :get }, + { :controller => "api/relations", :action => "show", :id => "1", :format => "json" } + ) assert_routing( { :path => "/api/0.6/relation/1", :method => :put }, { :controller => "api/relations", :action => "update", :id => "1" } @@ -29,6 +37,10 @@ module Api { :path => "/api/0.6/relations", :method => :get }, { :controller => "api/relations", :action => "index" } ) + assert_routing( + { :path => "/api/0.6/relations.json", :method => :get }, + { :controller => "api/relations", :action => "index", :format => "json" } + ) assert_routing( { :path => "/api/0.6/node/1/relations", :method => :get }, @@ -42,6 +54,18 @@ module Api { :path => "/api/0.6/relation/1/relations", :method => :get }, { :controller => "api/relations", :action => "relations_for_relation", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/node/1/relations.json", :method => :get }, + { :controller => "api/relations", :action => "relations_for_node", :id => "1", :format => "json" } + ) + assert_routing( + { :path => "/api/0.6/way/1/relations.json", :method => :get }, + { :controller => "api/relations", :action => "relations_for_way", :id => "1", :format => "json" } + ) + assert_routing( + { :path => "/api/0.6/relation/1/relations.json", :method => :get }, + { :controller => "api/relations", :action => "relations_for_relation", :id => "1", :format => "json" } + ) end # ------------------------------------- @@ -187,6 +211,18 @@ module Api assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1 end + # test a working call with json format + get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}", :format => "json" } + + js = ActiveSupport::JSON.decode(@response.body) + assert_not_nil js + assert_equal 4, js["elements"].count + assert_equal 4, (js["elements"].count { |a| a["type"] == "relation" }) + assert_equal 1, (js["elements"].count { |a| a["id"] == relation1.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == relation2.id && a["visible"] == false }) + assert_equal 1, (js["elements"].count { |a| a["id"] == relation3.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == relation4.id && a["visible"].nil? }) + # check error when a non-existent relation is included get :index, :params => { :relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0" } assert_response :not_found @@ -268,8 +304,8 @@ module Api "saved relation does not belong in the changeset it was assigned to" assert_equal user.id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" - assert_equal true, checkrelation.visible, - "saved relation is not visible" + assert checkrelation.visible, + "saved relation is not visible" # ok the relation is there but can we also retrieve it? get :show, :params => { :id => relationid } assert_response :success @@ -298,8 +334,8 @@ module Api "saved relation does not belong in the changeset it was assigned to" assert_equal user.id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" - assert_equal true, checkrelation.visible, - "saved relation is not visible" + assert checkrelation.visible, + "saved relation is not visible" # ok the relation is there but can we also retrieve it? get :show, :params => { :id => relationid } @@ -328,8 +364,8 @@ module Api "saved relation does not belong in the changeset it was assigned to" assert_equal user.id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" - assert_equal true, checkrelation.visible, - "saved relation is not visible" + assert checkrelation.visible, + "saved relation is not visible" # ok the relation is there but can we also retrieve it? get :show, :params => { :id => relationid } @@ -359,8 +395,8 @@ module Api "saved relation does not belong in the changeset it was assigned to" assert_equal user.id, checkrelation.changeset.user_id, "saved relation does not belong to user that created it" - assert_equal true, checkrelation.visible, - "saved relation is not visible" + assert checkrelation.visible, + "saved relation is not visible" # ok the relation is there but can we also retrieve it? get :show, :params => { :id => relationid } assert_response :success