3 class SearchControllerTest < ActionController::TestCase
5 # test all routes which lead to this controller
8 { :path => "/api/0.6/search", :method => :get },
9 { :controller => "search", :action => "search_all" }
12 { :path => "/api/0.6/nodes/search", :method => :get },
13 { :controller => "search", :action => "search_nodes" }
16 { :path => "/api/0.6/ways/search", :method => :get },
17 { :controller => "search", :action => "search_ways" }
20 { :path => "/api/0.6/relations/search", :method => :get },
21 { :controller => "search", :action => "search_relations" }
26 # test searching nodes
28 get :search_nodes, :params => { :type => "test" }
29 assert_response :service_unavailable
30 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
32 get :search_nodes, :params => { :type => "test", :value => "yes" }
33 assert_response :service_unavailable
34 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
36 get :search_nodes, :params => { :name => "Test Node" }
37 assert_response :service_unavailable
38 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
44 first_way = create(:way_with_nodes, :nodes_count => 2)
45 deleted_way = create(:way_with_nodes, :deleted, :nodes_count => 2)
46 third_way = create(:way_with_nodes, :nodes_count => 2)
48 [first_way, deleted_way, third_way].each do |way|
49 create(:way_tag, :way => way, :k => "test", :v => "yes")
51 create(:way_tag, :way => third_way, :k => "name", :v => "Test Way")
53 get :search_ways, :params => { :type => "test" }
54 assert_response :service_unavailable
55 assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
57 get :search_ways, :params => { :type => "test", :value => "yes" }
58 assert_response :success
59 assert_select "way", 3
61 get :search_ways, :params => { :name => "Test Way" }
62 assert_response :success
63 assert_select "way", 1
67 # test searching relations
68 def test_search_relations
69 first_relation = create(:relation)
70 deleted_relation = create(:relation)
71 third_relation = create(:relation)
73 [first_relation, deleted_relation, third_relation].each do |relation|
74 create(:relation_tag, :relation => relation, :k => "test", :v => "yes")
76 create(:relation_tag, :relation => third_relation, :k => "name", :v => "Test Relation")
78 get :search_relations, :params => { :type => "test" }
79 assert_response :service_unavailable
80 assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
82 get :search_relations, :params => { :type => "test", :value => "yes" }
83 assert_response :success
84 assert_select "relation", 3
86 get :search_relations, :params => { :name => "Test Relation" }
87 assert_response :success
88 assert_select "relation", 1
92 # test searching nodes, ways and relations
94 get :search_all, :params => { :type => "test" }
95 assert_response :service_unavailable
96 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
98 get :search_all, :params => { :type => "test", :value => "yes" }
99 assert_response :service_unavailable
100 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
102 get :search_all, :params => { :name => "Test" }
103 assert_response :service_unavailable
104 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]