summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2012-08-25 13:31:50 -0400
committerRobert Speicher <rspeicher@gmail.com>2012-08-25 14:19:15 -0400
commitb2a5344a2d68922d5c6cb8de228fb9b41ce3efc4 (patch)
treee2f9927b723c8e0561ac33fc18a700f4092c2412 /spec/support
parentfba174e9bc4e4ef5c0c4d6a4282f37e5265b87e2 (diff)
downloadgitlab-ce-b2a5344a2d68922d5c6cb8de228fb9b41ce3efc4.tar.gz
Add a simple `api` method to ApiHelpers, replacing api_prefix
See docs for usage
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/api_helpers.rb29
1 files changed, 27 insertions, 2 deletions
diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb
index e35d5735ec3..7d9011971dd 100644
--- a/spec/support/api_helpers.rb
+++ b/spec/support/api_helpers.rb
@@ -1,6 +1,31 @@
module ApiHelpers
- def api_prefix
- "/api/#{Gitlab::API::VERSION}"
+ # Public: Prepend a request path with the path to the API
+ #
+ # path - Path to append
+ # user - User object - If provided, automatically appends private_token query
+ # string for authenticated requests
+ #
+ # Examples
+ #
+ # >> api('/issues')
+ # => "/api/v2/issues"
+ #
+ # >> api('/issues', User.last)
+ # => "/api/v2/issues?private_token=..."
+ #
+ # >> api('/issues?foo=bar', User.last)
+ # => "/api/v2/issues?foo=bar&private_token=..."
+ #
+ # Returns the relative path to the requested API resource
+ def api(path, user = nil)
+ "/api/#{Gitlab::API::VERSION}#{path}" +
+
+ # Normalize query string
+ (path.index('?') ? '' : '?') +
+
+ # Append private_token if given a User object
+ (user.respond_to?(:private_token) ?
+ "&private_token=#{user.private_token}" : "")
end
def json_response