X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/2b1bac1279e268c8e5fcca34c950f30d2c06ec1c..7a1615bc55aee72dd03a5dd43c08b4f13f669f06:/test/controllers/api/ways_controller_test.rb diff --git a/test/controllers/api/ways_controller_test.rb b/test/controllers/api/ways_controller_test.rb index 433b43f27..ae7f18161 100644 --- a/test/controllers/api/ways_controller_test.rb +++ b/test/controllers/api/ways_controller_test.rb @@ -13,10 +13,18 @@ module Api { :path => "/api/0.6/way/1/full", :method => :get }, { :controller => "api/ways", :action => "full", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/way/1/full.json", :method => :get }, + { :controller => "api/ways", :action => "full", :id => "1", :format => "json" } + ) assert_routing( { :path => "/api/0.6/way/1", :method => :get }, { :controller => "api/ways", :action => "show", :id => "1" } ) + assert_routing( + { :path => "/api/0.6/way/1.json", :method => :get }, + { :controller => "api/ways", :action => "show", :id => "1", :format => "json" } + ) assert_routing( { :path => "/api/0.6/way/1", :method => :put }, { :controller => "api/ways", :action => "update", :id => "1" } @@ -29,6 +37,10 @@ module Api { :path => "/api/0.6/ways", :method => :get }, { :controller => "api/ways", :action => "index" } ) + assert_routing( + { :path => "/api/0.6/ways.json", :method => :get }, + { :controller => "api/ways", :action => "index", :format => "json" } + ) end # ------------------------------------- @@ -104,6 +116,18 @@ module Api assert_select "way[id='#{way4.id}'][visible='true']", :count => 1 end + # test a working call with json format + get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.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"] == "way" }) + assert_equal 1, (js["elements"].count { |a| a["id"] == way1.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == way2.id && a["visible"] == false }) + assert_equal 1, (js["elements"].count { |a| a["id"] == way3.id && a["visible"].nil? }) + assert_equal 1, (js["elements"].count { |a| a["id"] == way4.id && a["visible"].nil? }) + # check error when a non-existent way is included get :index, :params => { :ways => "#{way1.id},#{way2.id},#{way3.id},#{way4.id},0" } assert_response :not_found @@ -166,8 +190,8 @@ module Api "saved way does not belong to the correct changeset" assert_equal user.id, checkway.changeset.user_id, "saved way does not belong to user that created it" - assert_equal true, checkway.visible, - "saved way is not visible" + assert checkway.visible, + "saved way is not visible" end # -------------------------------------