]> git.openstreetmap.org Git - rails.git/blob - test/controllers/search_controller_test.rb
Refactor deletion tests in way_controller_test to use factories.
[rails.git] / test / controllers / search_controller_test.rb
1 require "test_helper"
2
3 class SearchControllerTest < ActionController::TestCase
4   api_fixtures
5
6   ##
7   # test all routes which lead to this controller
8   def test_routes
9     assert_routing(
10       { :path => "/api/0.6/search", :method => :get },
11       { :controller => "search", :action => "search_all" }
12     )
13     assert_routing(
14       { :path => "/api/0.6/nodes/search", :method => :get },
15       { :controller => "search", :action => "search_nodes" }
16     )
17     assert_routing(
18       { :path => "/api/0.6/ways/search", :method => :get },
19       { :controller => "search", :action => "search_ways" }
20     )
21     assert_routing(
22       { :path => "/api/0.6/relations/search", :method => :get },
23       { :controller => "search", :action => "search_relations" }
24     )
25   end
26
27   ##
28   # test searching nodes
29   def test_search_nodes
30     get :search_nodes, :type => "test"
31     assert_response :service_unavailable
32     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
33
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"]
37
38     get :search_nodes, :name => "Test Node"
39     assert_response :service_unavailable
40     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
41   end
42
43   ##
44   # test searching ways
45   def test_search_ways
46     [:visible_way, :invisible_way, :used_way].each do |way|
47       create(:way_tag, :way => current_ways(way), :k => "test", :v => "yes")
48     end
49     create(:way_tag, :way => current_ways(:used_way), :k => "name", :v => "Test Way")
50
51     get :search_ways, :type => "test"
52     assert_response :service_unavailable
53     assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
54
55     get :search_ways, :type => "test", :value => "yes"
56     assert_response :success
57     assert_select "way", 3
58
59     get :search_ways, :name => "Test Way"
60     assert_response :success
61     assert_select "way", 1
62   end
63
64   ##
65   # test searching relations
66   def test_search_relations
67     [:visible_relation, :invisible_relation, :used_relation].each do |relation|
68       create(:relation_tag, :relation => current_relations(relation), :k => "test", :v => "yes")
69     end
70     create(:relation_tag, :relation => current_relations(:used_relation), :k => "name", :v => "Test Relation")
71
72     get :search_relations, :type => "test"
73     assert_response :service_unavailable
74     assert_equal "Searching for a key without value is currently unavailable", response.headers["Error"]
75
76     get :search_relations, :type => "test", :value => "yes"
77     assert_response :success
78     assert_select "relation", 3
79
80     get :search_relations, :name => "Test Relation"
81     assert_response :success
82     assert_select "relation", 1
83   end
84
85   ##
86   # test searching nodes, ways and relations
87   def test_search_all
88     get :search_all, :type => "test"
89     assert_response :service_unavailable
90     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
91
92     get :search_all, :type => "test", :value => "yes"
93     assert_response :service_unavailable
94     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
95
96     get :search_all, :name => "Test"
97     assert_response :service_unavailable
98     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
99   end
100 end