-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5433 from AntonKhorev/user-routes-api-namespace
Resourceful routes for users api
- Loading branch information
Showing
7 changed files
with
83 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Api | ||
module Users | ||
class TracesController < ApiController | ||
before_action :authorize | ||
|
||
authorize_resource :trace | ||
|
||
def index | ||
@traces = current_user.traces.reload | ||
render :content_type => "application/xml" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 we get a response when logged in | ||
auth_header = bearer_authorization_header user, :scopes => %w[read_gpx] | ||
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 | ||
|
||
def test_index_anonymous | ||
get api_user_traces_path | ||
assert_response :unauthorized | ||
end | ||
|
||
def test_index_no_scope | ||
user = create(:user) | ||
bad_auth = bearer_authorization_header user, :scopes => %w[] | ||
|
||
get api_user_traces_path, :headers => bad_auth | ||
assert_response :forbidden | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters