Create user traces resource in api namespace
This commit is contained in:
parent
e6b23c133e
commit
880032ed85
7 changed files with 60 additions and 42 deletions
43
test/controllers/api/users/traces_controller_test.rb
Normal file
43
test/controllers/api/users/traces_controller_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
require "test_helper"
|
||||
|
||||
module Api
|
||||
module Users
|
||||
class TracesControllerTest < ActionDispatch::IntegrationTest
|
||||
##
|
||||
# test all routes which lead to this controller
|
||||
def test_routes
|
||||
assert_routing(
|
||||
{ :path => "/api/0.6/user/gpx_files", :method => :get },
|
||||
{ :controller => "api/users/traces", :action => "index" }
|
||||
)
|
||||
end
|
||||
|
||||
def test_index
|
||||
user = create(:user)
|
||||
trace1 = create(:trace, :user => user) do |trace|
|
||||
create(:tracetag, :trace => trace, :tag => "London")
|
||||
end
|
||||
trace2 = create(:trace, :user => user) do |trace|
|
||||
create(:tracetag, :trace => trace, :tag => "Birmingham")
|
||||
end
|
||||
# check that nothing is returned when not logged in
|
||||
get api_user_traces_path
|
||||
assert_response :unauthorized
|
||||
|
||||
# check that we get a response when logged in
|
||||
auth_header = bearer_authorization_header user
|
||||
get api_user_traces_path, :headers => auth_header
|
||||
assert_response :success
|
||||
assert_equal "application/xml", response.media_type
|
||||
|
||||
# check the data that is returned
|
||||
assert_select "gpx_file[id='#{trace1.id}']", 1 do
|
||||
assert_select "tag", "London"
|
||||
end
|
||||
assert_select "gpx_file[id='#{trace2.id}']", 1 do
|
||||
assert_select "tag", "Birmingham"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,10 +21,6 @@ module Api
|
|||
{ :path => "/api/0.6/user/details.json", :method => :get },
|
||||
{ :controller => "api/users", :action => "details", :format => "json" }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/api/0.6/user/gpx_files", :method => :get },
|
||||
{ :controller => "api/users", :action => "gpx_files" }
|
||||
)
|
||||
assert_routing(
|
||||
{ :path => "/api/0.6/users", :method => :get },
|
||||
{ :controller => "api/users", :action => "index" }
|
||||
|
@ -405,33 +401,6 @@ module Api
|
|||
assert_select "user", :count => 0
|
||||
end
|
||||
|
||||
def test_gpx_files
|
||||
user = create(:user)
|
||||
trace1 = create(:trace, :user => user) do |trace|
|
||||
create(:tracetag, :trace => trace, :tag => "London")
|
||||
end
|
||||
trace2 = create(:trace, :user => user) do |trace|
|
||||
create(:tracetag, :trace => trace, :tag => "Birmingham")
|
||||
end
|
||||
# check that nothing is returned when not logged in
|
||||
get user_gpx_files_path
|
||||
assert_response :unauthorized
|
||||
|
||||
# check that we get a response when logged in
|
||||
auth_header = bearer_authorization_header user
|
||||
get user_gpx_files_path, :headers => auth_header
|
||||
assert_response :success
|
||||
assert_equal "application/xml", response.media_type
|
||||
|
||||
# check the data that is returned
|
||||
assert_select "gpx_file[id='#{trace1.id}']", 1 do
|
||||
assert_select "tag", "London"
|
||||
end
|
||||
assert_select "gpx_file[id='#{trace2.id}']", 1 do
|
||||
assert_select "tag", "Birmingham"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_xml_details(user, include_private, include_email)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue