]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/versions_controller_test.rb
Merge remote-tracking branch 'upstream/pull/4762'
[rails.git] / test / controllers / api / versions_controller_test.rb
1 require "test_helper"
2
3 module Api
4   class VersionsControllerTest < ActionDispatch::IntegrationTest
5     ##
6     # test all routes which lead to this controller
7     def test_routes
8       assert_routing(
9         { :path => "/api/versions", :method => :get },
10         { :controller => "api/versions", :action => "show" }
11       )
12       assert_routing(
13         { :path => "/api/versions.json", :method => :get },
14         { :controller => "api/versions", :action => "show", :format => "json" }
15       )
16       assert_recognizes(
17         { :controller => "api/versions", :action => "show" },
18         { :path => "/api/versions", :method => :get }
19       )
20       assert_recognizes(
21         { :controller => "api/versions", :action => "show", :format => "json" },
22         { :path => "/api/versions.json", :method => :get }
23       )
24     end
25
26     def test_versions
27       get api_versions_path
28       assert_response :success
29       assert_select "osm[generator='#{Settings.generator}']", :count => 1 do
30         assert_select "api", :count => 1 do
31           assert_select "version", Settings.api_version
32         end
33       end
34     end
35
36     def test_versions_json
37       get api_versions_path, :params => { :format => "json" }
38       assert_response :success
39       js = ActiveSupport::JSON.decode(@response.body)
40       assert_not_nil js
41       assert_equal [Settings.api_version], js["api"]["versions"]
42     end
43
44     def test_no_version_in_root_element
45       get api_versions_path
46       assert_response :success
47       assert_select "osm[version]", :count => 0
48     end
49   end
50 end