4 class SearchControllerTest < ActionController::TestCase
6 # test all routes which lead to this controller
9 { :path => "/api/0.6/search", :method => :get },
10 { :controller => "api/search", :action => "search_all" }
13 { :path => "/api/0.6/nodes/search", :method => :get },
14 { :controller => "api/search", :action => "search_nodes" }
17 { :path => "/api/0.6/ways/search", :method => :get },
18 { :controller => "api/search", :action => "search_ways" }
21 { :path => "/api/0.6/relations/search", :method => :get },
22 { :controller => "api/search", :action => "search_relations" }
27 # test searching nodes
29 get :search_nodes, :params => { :type => "test" }
30 assert_response :service_unavailable
31 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
33 get :search_nodes, :params => { :type => "test", :value => "yes" }
34 assert_response :service_unavailable
35 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
37 get :search_nodes, :params => { :name => "Test Node" }
38 assert_response :service_unavailable
39 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
45 first_way = create(:way_with_nodes, :nodes_count => 2)
46 deleted_way = create(:way_with_nodes, :deleted, :nodes_count => 2)
47 third_way = create(:way_with_nodes, :nodes_count => 2)
49 [first_way, deleted_way, third_way].each do |way|
50 create(:way_tag, :way => way, :k => "test", :v => "yes")
52 create(:way_tag, :way => third_way, :k => "name", :v => "Test Way")
54 get :search_ways, :params => { :type => "test" }
55 assert_response :service_unavailable
56 assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
58 get :search_ways, :params => { :type => "test", :value => "yes" }
59 assert_response :success
60 assert_select "way", 3
62 get :search_ways, :params => { :name => "Test Way" }
63 assert_response :success
64 assert_select "way", 1
68 # test searching relations
69 def test_search_relations
70 first_relation = create(:relation)
71 deleted_relation = create(:relation)
72 third_relation = create(:relation)
74 [first_relation, deleted_relation, third_relation].each do |relation|
75 create(:relation_tag, :relation => relation, :k => "test", :v => "yes")
77 create(:relation_tag, :relation => third_relation, :k => "name", :v => "Test Relation")
79 get :search_relations, :params => { :type => "test" }
80 assert_response :service_unavailable
81 assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
83 get :search_relations, :params => { :type => "test", :value => "yes" }
84 assert_response :success
85 assert_select "relation", 3
87 get :search_relations, :params => { :name => "Test Relation" }
88 assert_response :success
89 assert_select "relation", 1
93 # test searching nodes, ways and relations
95 get :search_all, :params => { :type => "test" }
96 assert_response :service_unavailable
97 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
99 get :search_all, :params => { :type => "test", :value => "yes" }
100 assert_response :service_unavailable
101 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
103 get :search_all, :params => { :name => "Test" }
104 assert_response :service_unavailable
105 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]