summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-05 15:06:02 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-05 15:06:02 +0300
commit162dd6cb2b9b93ef188ecacc285f476660fcb90c (patch)
treef37375ccd518cd7e9c74a89331af52a01cadfbb9 /spec/support
parent4b74c55b1572da19d78fa6982edf54916d09eec3 (diff)
downloadgitlab-ci-162dd6cb2b9b93ef188ecacc285f476660fcb90c.tar.gz
Api rspec
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/api_helpers.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb
new file mode 100644
index 0000000..ec9a326
--- /dev/null
+++ b/spec/support/api_helpers.rb
@@ -0,0 +1,34 @@
+module ApiHelpers
+ # 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/#{API::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
+ JSON.parse(response.body)
+ end
+end