Move api element index tests up
This commit is contained in:
parent
35d5276587
commit
1d04b69e86
3 changed files with 160 additions and 160 deletions
|
@ -5,6 +5,14 @@ module Api
|
|||
##
|
||||
# test all routes which lead to this controller
|
||||
def test_routes
|
||||
assert_routing(
|
||||
{ :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/relation/create", :method => :put },
|
||||
{ :controller => "api/relations", :action => "create" }
|
||||
|
@ -33,14 +41,6 @@ module Api
|
|||
{ :path => "/api/0.6/relation/1", :method => :delete },
|
||||
{ :controller => "api/relations", :action => "delete", :id => "1" }
|
||||
)
|
||||
assert_routing(
|
||||
{ :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 },
|
||||
|
@ -68,6 +68,51 @@ module Api
|
|||
)
|
||||
end
|
||||
|
||||
##
|
||||
# test fetching multiple relations
|
||||
def test_index
|
||||
relation1 = create(:relation)
|
||||
relation2 = create(:relation, :deleted)
|
||||
relation3 = create(:relation, :with_history, :version => 2)
|
||||
relation4 = create(:relation, :with_history, :version => 2)
|
||||
relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
|
||||
|
||||
# check error when no parameter provided
|
||||
get api_relations_path
|
||||
assert_response :bad_request
|
||||
|
||||
# check error when no parameter value provided
|
||||
get api_relations_path(:relations => "")
|
||||
assert_response :bad_request
|
||||
|
||||
# test a working call
|
||||
get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
|
||||
assert_response :success
|
||||
assert_select "osm" do
|
||||
assert_select "relation", :count => 4
|
||||
assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
|
||||
assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
|
||||
assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
|
||||
assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
|
||||
end
|
||||
|
||||
# test a working call with json format
|
||||
get api_relations_path(: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 api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
|
||||
assert_response :not_found
|
||||
end
|
||||
|
||||
# -------------------------------------
|
||||
# Test showing relations.
|
||||
# -------------------------------------
|
||||
|
@ -164,51 +209,6 @@ module Api
|
|||
# FIXME: check whether this contains the stuff we want!
|
||||
end
|
||||
|
||||
##
|
||||
# test fetching multiple relations
|
||||
def test_index
|
||||
relation1 = create(:relation)
|
||||
relation2 = create(:relation, :deleted)
|
||||
relation3 = create(:relation, :with_history, :version => 2)
|
||||
relation4 = create(:relation, :with_history, :version => 2)
|
||||
relation4.old_relations.find_by(:version => 1).redact!(create(:redaction))
|
||||
|
||||
# check error when no parameter provided
|
||||
get api_relations_path
|
||||
assert_response :bad_request
|
||||
|
||||
# check error when no parameter value provided
|
||||
get api_relations_path(:relations => "")
|
||||
assert_response :bad_request
|
||||
|
||||
# test a working call
|
||||
get api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id}")
|
||||
assert_response :success
|
||||
assert_select "osm" do
|
||||
assert_select "relation", :count => 4
|
||||
assert_select "relation[id='#{relation1.id}'][visible='true']", :count => 1
|
||||
assert_select "relation[id='#{relation2.id}'][visible='false']", :count => 1
|
||||
assert_select "relation[id='#{relation3.id}'][visible='true']", :count => 1
|
||||
assert_select "relation[id='#{relation4.id}'][visible='true']", :count => 1
|
||||
end
|
||||
|
||||
# test a working call with json format
|
||||
get api_relations_path(: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 api_relations_path(:relations => "#{relation1.id},#{relation2.id},#{relation3.id},#{relation4.id},0")
|
||||
assert_response :not_found
|
||||
end
|
||||
|
||||
# -------------------------------------
|
||||
# Test simple relation creation.
|
||||
# -------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue