3 class SearchControllerTest < ActionController::TestCase
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/search", :method => :get },
11 { :controller => "search", :action => "search_all" }
14 { :path => "/api/0.6/nodes/search", :method => :get },
15 { :controller => "search", :action => "search_nodes" }
18 { :path => "/api/0.6/ways/search", :method => :get },
19 { :controller => "search", :action => "search_ways" }
22 { :path => "/api/0.6/relations/search", :method => :get },
23 { :controller => "search", :action => "search_relations" }
28 # test searching nodes
30 get :search_nodes, :type => "test"
31 assert_response :service_unavailable
32 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
34 get :search_nodes, :type => "test", :value => "yes"
35 assert_response :service_unavailable
36 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
38 get :search_nodes, :name => "Test Node"
39 assert_response :service_unavailable
40 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
46 first_way = create(:way_with_nodes, :nodes_count => 2)
47 deleted_way = create(:way_with_nodes, :deleted, :nodes_count => 2)
48 third_way = create(:way_with_nodes, :nodes_count => 2)
50 [first_way, deleted_way, third_way].each do |way|
51 create(:way_tag, :way => way, :k => "test", :v => "yes")
53 create(:way_tag, :way => third_way, :k => "name", :v => "Test Way")
55 get :search_ways, :type => "test"
56 assert_response :service_unavailable
57 assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
59 get :search_ways, :type => "test", :value => "yes"
60 assert_response :success
61 assert_select "way", 3
63 get :search_ways, :name => "Test Way"
64 assert_response :success
65 assert_select "way", 1
69 # test searching relations
70 def test_search_relations
71 [:visible_relation, :invisible_relation, :used_relation].each do |relation|
72 create(:relation_tag, :relation => current_relations(relation), :k => "test", :v => "yes")
74 create(:relation_tag, :relation => current_relations(:used_relation), :k => "name", :v => "Test Relation")
76 get :search_relations, :type => "test"
77 assert_response :service_unavailable
78 assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
80 get :search_relations, :type => "test", :value => "yes"
81 assert_response :success
82 assert_select "relation", 3
84 get :search_relations, :name => "Test Relation"
85 assert_response :success
86 assert_select "relation", 1
90 # test searching nodes, ways and relations
92 get :search_all, :type => "test"
93 assert_response :service_unavailable
94 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
96 get :search_all, :type => "test", :value => "yes"
97 assert_response :service_unavailable
98 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
100 get :search_all, :name => "Test"
101 assert_response :service_unavailable
102 assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]