]> git.openstreetmap.org Git - rails.git/blob - test/controllers/search_controller_test.rb
Fix rubocop warnings
[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, :params => { :type => "test" }
29     assert_response :service_unavailable
30     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
31
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"]
35
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"]
39   end
40
41   ##
42   # test searching ways
43   def test_search_ways
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)
47
48     [first_way, deleted_way, third_way].each do |way|
49       create(:way_tag, :way => way, :k => "test", :v => "yes")
50     end
51     create(:way_tag, :way => third_way, :k => "name", :v => "Test Way")
52
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"]
56
57     get :search_ways, :params => { :type => "test", :value => "yes" }
58     assert_response :success
59     assert_select "way", 3
60
61     get :search_ways, :params => { :name => "Test Way" }
62     assert_response :success
63     assert_select "way", 1
64   end
65
66   ##
67   # test searching relations
68   def test_search_relations
69     first_relation = create(:relation)
70     deleted_relation = create(:relation)
71     third_relation = create(:relation)
72
73     [first_relation, deleted_relation, third_relation].each do |relation|
74       create(:relation_tag, :relation => relation, :k => "test", :v => "yes")
75     end
76     create(:relation_tag, :relation => third_relation, :k => "name", :v => "Test Relation")
77
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"]
81
82     get :search_relations, :params => { :type => "test", :value => "yes" }
83     assert_response :success
84     assert_select "relation", 3
85
86     get :search_relations, :params => { :name => "Test Relation" }
87     assert_response :success
88     assert_select "relation", 1
89   end
90
91   ##
92   # test searching nodes, ways and relations
93   def test_search_all
94     get :search_all, :params => { :type => "test" }
95     assert_response :service_unavailable
96     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
97
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"]
101
102     get :search_all, :params => { :name => "Test" }
103     assert_response :service_unavailable
104     assert_equal "Searching of nodes is currently unavailable", response.headers["Error"]
105   end
106 end