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