5 class TracesControllerTest < ActionDispatch::IntegrationTest
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/user/gpx_files", :method => :get },
11 { :controller => "api/users/traces", :action => "index" }
14 { :path => "/api/0.6/user/gpx_files.json", :method => :get },
15 { :controller => "api/users/traces", :action => "index", :format => "json" }
21 trace1 = create(:trace, :user => user) do |trace|
22 create(:tracetag, :trace => trace, :tag => "London")
24 trace2 = create(:trace, :user => user) do |trace|
25 create(:tracetag, :trace => trace, :tag => "Birmingham")
28 # check that we get a response when logged in
29 auth_header = bearer_authorization_header user, :scopes => %w[read_gpx]
30 get api_user_traces_path, :headers => auth_header
31 assert_response :success
32 assert_equal "application/xml", response.media_type
34 # check the data that is returned
35 assert_select "gpx_file[id='#{trace1.id}']", 1 do
36 assert_select "tag", "London"
38 assert_select "gpx_file[id='#{trace2.id}']", 1 do
39 assert_select "tag", "Birmingham"
42 # check that we get a response when logged in with json
43 auth_header = bearer_authorization_header user, :scopes => %w[read_gpx]
44 get api_user_traces_path(:format => "json"), :headers => auth_header
45 assert_response :success
46 assert_equal "application/json", response.media_type
47 js = ActiveSupport::JSON.decode(@response.body)
49 assert_equal trace1.id, js["traces"][0]["id"]
50 assert_equal "London", js["traces"][0]["tags"][0]
51 assert_equal trace2.id, js["traces"][1]["id"]
52 assert_equal "Birmingham", js["traces"][1]["tags"][0]
55 def test_index_anonymous
56 get api_user_traces_path
57 assert_response :unauthorized
60 def test_index_no_scope
62 bad_auth = bearer_authorization_header user, :scopes => %w[]
64 get api_user_traces_path, :headers => bad_auth
65 assert_response :forbidden