]> git.openstreetmap.org Git - rails.git/blob - test/controllers/api/users/traces_controller_test.rb
9fdd4927149c11e59c31e788da186a742df1d11d
[rails.git] / test / controllers / api / users / traces_controller_test.rb
1 require "test_helper"
2
3 module Api
4   module Users
5     class TracesControllerTest < ActionDispatch::IntegrationTest
6       ##
7       # test all routes which lead to this controller
8       def test_routes
9         assert_routing(
10           { :path => "/api/0.6/user/gpx_files", :method => :get },
11           { :controller => "api/users/traces", :action => "index" }
12         )
13       end
14
15       def test_index
16         user = create(:user)
17         trace1 = create(:trace, :user => user) do |trace|
18           create(:tracetag, :trace => trace, :tag => "London")
19         end
20         trace2 = create(:trace, :user => user) do |trace|
21           create(:tracetag, :trace => trace, :tag => "Birmingham")
22         end
23         # check that nothing is returned when not logged in
24         get api_user_traces_path
25         assert_response :unauthorized
26
27         # check that we get a response when logged in
28         auth_header = bearer_authorization_header user
29         get api_user_traces_path, :headers => auth_header
30         assert_response :success
31         assert_equal "application/xml", response.media_type
32
33         # check the data that is returned
34         assert_select "gpx_file[id='#{trace1.id}']", 1 do
35           assert_select "tag", "London"
36         end
37         assert_select "gpx_file[id='#{trace2.id}']", 1 do
38           assert_select "tag", "Birmingham"
39         end
40       end
41     end
42   end
43 end