]> git.openstreetmap.org Git - rails.git/blob - test/controllers/search_controller_test.rb
Testing, testing, testing...
[rails.git] / test / controllers / search_controller_test.rb
1 require "test_helper"
2
3 class SearchControllerTest < ActionController::TestCase
4   ##
5   # test all routes which lead to this controller
6   def test_routes
7     assert_routing(
8       { :path => "/api/0.6/search", :method => :get },
9       { :controller => "search", :action => "search_all" }
10     )
11     assert_routing(
12       { :path => "/api/0.6/nodes/search", :method => :get },
13       { :controller => "search", :action => "search_nodes" }
14     )
15     assert_routing(
16       { :path => "/api/0.6/ways/search", :method => :get },
17       { :controller => "search", :action => "search_ways" }
18     )
19     assert_routing(
20       { :path => "/api/0.6/relations/search", :method => :get },
21       { :controller => "search", :action => "search_relations" }
22     )
23   end
24
25   ##
26   # test searching nodes
27   def test_search_nodes
28     get :search_nodes, :type => "test"
29     assert_response :service_unavailable
30     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
31
32     get :search_nodes, :type => "test", :value => "yes"
33     assert_response :service_unavailable
34     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
35
36     get :search_nodes, :name => "Test Node"
37     assert_response :service_unavailable
38     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
39   end
40
41   ##
42   # test searching ways
43   def test_search_ways
44     get :search_ways, :type => "test"
45     assert_response :service_unavailable
46     assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
47
48     get :search_ways, :type => "test", :value => "yes"
49     assert_response :success
50     assert_select "way", 3
51
52     get :search_ways, :name => "Test Way"
53     assert_response :success
54     assert_select "way", 1
55   end
56
57   ##
58   # test searching relations
59   def test_search_relations
60     get :search_relations, :type => "test"
61     assert_response :service_unavailable
62     assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
63
64     get :search_relations, :type => "test", :value => "yes"
65     assert_response :success
66     assert_select "relation", 3
67
68     get :search_relations, :name => "Test Relation"
69     assert_response :success
70     assert_select "relation", 1
71   end
72
73   ##
74   # test searching nodes, ways and relations
75   def test_search_all
76     get :search_all, :type => "test"
77     assert_response :service_unavailable
78     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
79
80     get :search_all, :type => "test", :value => "yes"
81     assert_response :service_unavailable
82     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
83
84     get :search_all, :name => "Test"
85     assert_response :service_unavailable
86     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
87   end
88 end