gitlab 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +1 -0
  4. data/LICENSE.txt +1 -1
  5. data/README.md +28 -3
  6. data/bin/gitlab +7 -0
  7. data/gitlab.gemspec +3 -2
  8. data/lib/gitlab.rb +8 -0
  9. data/lib/gitlab/api.rb +1 -1
  10. data/lib/gitlab/cli.rb +57 -0
  11. data/lib/gitlab/cli_helpers.rb +141 -0
  12. data/lib/gitlab/client.rb +8 -6
  13. data/lib/gitlab/client/branches.rb +79 -0
  14. data/lib/gitlab/client/merge_requests.rb +15 -2
  15. data/lib/gitlab/client/projects.rb +25 -4
  16. data/lib/gitlab/client/repositories.rb +22 -23
  17. data/lib/gitlab/client/system_hooks.rb +58 -0
  18. data/lib/gitlab/client/users.rb +17 -0
  19. data/lib/gitlab/configuration.rb +3 -3
  20. data/lib/gitlab/objectified_hash.rb +8 -2
  21. data/lib/gitlab/request.rb +21 -5
  22. data/lib/gitlab/version.rb +1 -1
  23. data/spec/fixtures/branch.json +1 -0
  24. data/spec/fixtures/{project_branches.json → branches.json} +0 -0
  25. data/spec/fixtures/create_branch.json +1 -0
  26. data/spec/fixtures/merge_request_comments.json +1 -0
  27. data/spec/fixtures/project_commit.json +13 -0
  28. data/spec/fixtures/project_commit_diff.json +10 -0
  29. data/spec/fixtures/{project_branch.json → protect_branch.json} +1 -1
  30. data/spec/fixtures/system_hook.json +1 -0
  31. data/spec/fixtures/system_hook_test.json +1 -0
  32. data/spec/fixtures/system_hooks.json +1 -0
  33. data/spec/fixtures/unprotect_branch.json +1 -0
  34. data/spec/gitlab/cli_spec.rb +80 -0
  35. data/spec/gitlab/client/branches_spec.rb +103 -0
  36. data/spec/gitlab/client/groups_spec.rb +21 -21
  37. data/spec/gitlab/client/issues_spec.rb +26 -26
  38. data/spec/gitlab/client/merge_requests_spec.rb +45 -13
  39. data/spec/gitlab/client/milestones_spec.rb +11 -11
  40. data/spec/gitlab/client/notes_spec.rb +30 -30
  41. data/spec/gitlab/client/projects_spec.rb +93 -59
  42. data/spec/gitlab/client/repositories_spec.rb +28 -25
  43. data/spec/gitlab/client/snippets_spec.rb +16 -16
  44. data/spec/gitlab/client/system_hooks_spec.rb +69 -0
  45. data/spec/gitlab/client/users_spec.rb +60 -24
  46. data/spec/gitlab/objectified_hash_spec.rb +23 -0
  47. data/spec/gitlab/request_spec.rb +48 -0
  48. data/spec/gitlab_spec.rb +16 -7
  49. data/spec/spec_helper.rb +19 -8
  50. metadata +70 -22
@@ -9,9 +9,14 @@ class Gitlab::Client
9
9
  # @param [Hash] options A customizable set of options.
10
10
  # @option options [Integer] :page The page number.
11
11
  # @option options [Integer] :per_page The number of results per page.
12
+ # @option options [String] :scope Scope of projects. 'owned' for list of projects owned by the authenticated user, 'all' to get all projects (admin only)
12
13
  # @return [Array<Gitlab::ObjectifiedHash>]
13
14
  def projects(options={})
14
- get("/projects", :query => options)
15
+ if (options[:scope])
16
+ get("/projects/#{options[:scope]}", :query => options)
17
+ else
18
+ get("/projects", :query => options)
19
+ end
15
20
  end
16
21
 
17
22
  # Gets information about a project.
@@ -50,6 +55,17 @@ class Gitlab::Client
50
55
  post(url, :body => {:name => name}.merge(options))
51
56
  end
52
57
 
58
+ # Deletes a project.
59
+ #
60
+ # @example
61
+ # Gitlab.delete_project(4)
62
+ #
63
+ # @param [Integer, String] id The ID or name of a project.
64
+ # @return [Gitlab::ObjectifiedHash] Information about deleted project.
65
+ def delete_project(id)
66
+ delete("/projects/#{id}")
67
+ end
68
+
53
69
  # Gets a list of project team members.
54
70
  #
55
71
  # @example
@@ -154,9 +170,14 @@ class Gitlab::Client
154
170
  #
155
171
  # @param [Integer, String] project The ID or name of a project.
156
172
  # @param [String] url The hook URL.
173
+ # @param [Hash] options Events list (`{push_events: true, merge_requests_events: false}`).
157
174
  # @return [Gitlab::ObjectifiedHash] Information about added hook.
158
- def add_project_hook(project, url)
159
- post("/projects/#{project}/hooks", :body => {:url => url})
175
+ def add_project_hook(project, url, options = {})
176
+ available_events = [:push_events, :merge_requests_events, :issues_events]
177
+ passed_events = available_events.select { |event| options[event] }
178
+ events = Hash[passed_events.map { |event| [event, options[event]] }]
179
+
180
+ post("/projects/#{project}/hooks", :body => {:url => url}.merge(events))
160
181
  end
161
182
 
162
183
  # Updates a project hook URL.
@@ -244,7 +265,7 @@ class Gitlab::Client
244
265
  # @param [String] key The content of a deploy key.
245
266
  # @return [Gitlab::ObjectifiedHash] Information about created deploy key.
246
267
  def create_deploy_key(project, title, key)
247
- post("/projects/#{project}/keys", title: title, key: key)
268
+ post("/projects/#{project}/keys", body: {title: title, key: key})
248
269
  end
249
270
 
250
271
  # Deletes a deploy key from project.
@@ -16,50 +16,49 @@ class Gitlab::Client
16
16
  end
17
17
  alias_method :repo_tags, :tags
18
18
 
19
- # Gets a list of project repositiory branches.
19
+ # Gets a list of project commits.
20
20
  #
21
21
  # @example
22
- # Gitlab.branches(42)
22
+ # Gitlab.commits('viking')
23
+ # Gitlab.repo_commits('gitlab', :ref_name => 'api')
23
24
  #
24
25
  # @param [Integer] project The ID of a project.
25
26
  # @param [Hash] options A customizable set of options.
27
+ # @option options [String] :ref_name The branch or tag name of a project repository.
26
28
  # @option options [Integer] :page The page number.
27
29
  # @option options [Integer] :per_page The number of results per page.
28
30
  # @return [Array<Gitlab::ObjectifiedHash>]
29
- def branches(project, options={})
30
- get("/projects/#{project}/repository/branches", :query => options)
31
+ def commits(project, options={})
32
+ get("/projects/#{project}/repository/commits", :query => options)
31
33
  end
32
- alias_method :repo_branches, :branches
34
+ alias_method :repo_commits, :commits
33
35
 
34
- # Gets information about a repository branch.
36
+ # Gets a specific commit identified by the commit hash or name of a branch or tag.
35
37
  #
36
38
  # @example
37
- # Gitlab.branch(3, 'api')
38
- # Gitlab.repo_branch(5, 'master')
39
+ # Gitlab.commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
40
+ # Gitlab.repo_commit(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
39
41
  #
40
42
  # @param [Integer] project The ID of a project.
41
- # @param [String] branch The name of the branch.
43
+ # @param [String] sha The commit hash or name of a repository branch or tag
42
44
  # @return [Gitlab::ObjectifiedHash]
43
- def branch(project, branch)
44
- get("/projects/#{project}/repository/branches/#{branch}")
45
+ def commit(project, sha)
46
+ get("/projects/#{project}/repository/commits/#{sha}")
45
47
  end
46
- alias_method :repo_branch, :branch
48
+ alias_method :repo_commit, :commit
47
49
 
48
- # Gets a list of project commits.
50
+ # Get the diff of a commit in a project.
49
51
  #
50
52
  # @example
51
- # Gitlab.commits('viking')
52
- # Gitlab.repo_commits('gitlab', :ref_name => 'api')
53
+ # Gitlab.commit_diff(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
54
+ # Gitlab.repo_commit_diff(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
53
55
  #
54
56
  # @param [Integer] project The ID of a project.
55
- # @param [Hash] options A customizable set of options.
56
- # @option options [String] :ref_name The branch or tag name of a project repository.
57
- # @option options [Integer] :page The page number.
58
- # @option options [Integer] :per_page The number of results per page.
59
- # @return [Array<Gitlab::ObjectifiedHash>]
60
- def commits(project, options={})
61
- get("/projects/#{project}/repository/commits", :query => options)
57
+ # @param [String] sha The name of a repository branch or tag or if not given the default branch.
58
+ # @return [Gitlab::ObjectifiedHash]
59
+ def commit_diff(project, sha)
60
+ get("/projects/#{project}/repository/commits/#{sha}/diff")
62
61
  end
63
- alias_method :repo_commits, :commits
62
+ alias_method :repo_commit_diff, :commit_diff
64
63
  end
65
64
  end
@@ -0,0 +1,58 @@
1
+ class Gitlab::Client
2
+ # Defines methods related to system hooks.
3
+ module SystemHooks
4
+ # Gets a list of system hooks.
5
+ #
6
+ # @example
7
+ # Gitlab.hooks
8
+ # Gitlab.system_hooks
9
+ #
10
+ # @param [Hash] options A customizable set of options.
11
+ # @option options [Integer] :page The page number.
12
+ # @option options [Integer] :per_page The number of results per page.
13
+ # @return [Array<Gitlab::ObjectifiedHash>]
14
+ def hooks(options={})
15
+ get("/hooks", query: options)
16
+ end
17
+ alias_method :system_hooks, :hooks
18
+
19
+ # Adds a new system hook.
20
+ #
21
+ # @example
22
+ # Gitlab.add_hook('http://example.com/hook')
23
+ # Gitlab.add_system_hook('https://api.example.net/v1/hook')
24
+ #
25
+ # @param [String] url The hook URL.
26
+ # @return [Gitlab::ObjectifiedHash]
27
+ def add_hook(url)
28
+ post("/hooks", :body => {:url => url})
29
+ end
30
+ alias_method :add_system_hook, :add_hook
31
+
32
+ # Tests a system hook.
33
+ #
34
+ # @example
35
+ # Gitlab.hook(3)
36
+ # Gitlab.system_hook(12)
37
+ #
38
+ # @param [Integer] id The ID of a system hook.
39
+ # @return [Array<Gitlab::ObjectifiedHash>]
40
+ def hook(id)
41
+ get("/hooks/#{id}")
42
+ end
43
+ alias_method :system_hook, :hook
44
+
45
+ # Deletes a new system hook.
46
+ #
47
+ # @example
48
+ # Gitlab.delete_hook(3)
49
+ # Gitlab.delete_system_hook(12)
50
+ #
51
+ # @param [Integer] id The ID of a system hook.
52
+ # @return [Gitlab::ObjectifiedHash]
53
+ def delete_hook(id)
54
+ delete("/hooks/#{id}")
55
+ end
56
+ alias_method :delete_system_hook, :delete_hook
57
+ end
58
+ end
@@ -44,6 +44,22 @@ class Gitlab::Client
44
44
  post("/users", :body => body)
45
45
  end
46
46
 
47
+ # Updates a user.
48
+ #
49
+ # @param [Integer] id The ID of a user.
50
+ # @param [Hash] options A customizable set of options.
51
+ # @option options [String] email The email of a user.
52
+ # @option options [String] password The password of a user.
53
+ # @option options [String] :name The name of a user. Defaults to email.
54
+ # @option options [String] :skype The skype of a user.
55
+ # @option options [String] :linkedin The linkedin of a user.
56
+ # @option options [String] :twitter The twitter of a user.
57
+ # @option options [Integer] :projects_limit The limit of projects for a user.
58
+ # @return [Gitlab::ObjectifiedHash] Information about created user.
59
+ def edit_user(user_id, options={})
60
+ put("/users/#{user_id}", :body => options)
61
+ end
62
+
47
63
  # Creates a new user session.
48
64
  #
49
65
  # @example
@@ -52,6 +68,7 @@ class Gitlab::Client
52
68
  # @param [String] email The email of a user.
53
69
  # @param [String] password The password of a user.
54
70
  # @return [Gitlab::ObjectifiedHash]
71
+ # @note This method doesn't require private_token to be set.
55
72
  def session(email, password)
56
73
  post("/session", :body => {:email => email, :password => password})
57
74
  end
@@ -8,7 +8,7 @@ module Gitlab
8
8
  DEFAULT_USER_AGENT = "Gitlab Ruby Gem #{Gitlab::VERSION}".freeze
9
9
 
10
10
  # @private
11
- attr_accessor *VALID_OPTIONS_KEYS
11
+ attr_accessor(*VALID_OPTIONS_KEYS)
12
12
 
13
13
  # Sets all configuration options to their default values
14
14
  # when this module is extended.
@@ -30,8 +30,8 @@ module Gitlab
30
30
 
31
31
  # Resets all configuration options to the defaults.
32
32
  def reset
33
- self.endpoint = nil
34
- self.private_token = nil
33
+ self.endpoint = ENV['GITLAB_API_ENDPOINT']
34
+ self.private_token = ENV['GITLAB_API_PRIVATE_TOKEN']
35
35
  self.sudo = nil
36
36
  self.user_agent = DEFAULT_USER_AGENT
37
37
  end
@@ -1,8 +1,9 @@
1
1
  module Gitlab
2
2
  # Converts hashes to the objects.
3
3
  class ObjectifiedHash
4
- # Creates a new ObjectifiedHash.
4
+ # Creates a new ObjectifiedHash object.
5
5
  def initialize(hash)
6
+ @hash = hash
6
7
  @data = hash.inject({}) do |data, (key,value)|
7
8
  value = ObjectifiedHash.new(value) if value.is_a? Hash
8
9
  data[key.to_s] = value
@@ -10,7 +11,12 @@ module Gitlab
10
11
  end
11
12
  end
12
13
 
13
- # Delegate to ObjectifiedHash
14
+ def to_hash
15
+ @hash
16
+ end
17
+ alias_method :to_h, :to_hash
18
+
19
+ # Delegate to ObjectifiedHash.
14
20
  def method_missing(key)
15
21
  @data.key?(key.to_s) ? @data[key.to_s] : nil
16
22
  end
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'json'
2
3
 
3
4
  module Gitlab
4
5
  # @private
@@ -8,6 +9,8 @@ module Gitlab
8
9
  headers 'Accept' => 'application/json'
9
10
  parser Proc.new { |body, _| parse(body) }
10
11
 
12
+ attr_accessor :private_token
13
+
11
14
  # Converts the response body to an ObjectifiedHash.
12
15
  def self.parse(body)
13
16
  body = decode(body)
@@ -31,19 +34,23 @@ module Gitlab
31
34
  end
32
35
 
33
36
  def get(path, options={})
37
+ set_private_token_header(options)
34
38
  validate self.class.get(path, options)
35
39
  end
36
40
 
37
41
  def post(path, options={})
42
+ set_private_token_header(options, path)
38
43
  validate self.class.post(path, options)
39
44
  end
40
45
 
41
46
  def put(path, options={})
47
+ set_private_token_header(options)
42
48
  validate self.class.put(path, options)
43
49
  end
44
50
 
45
- def delete(path)
46
- validate self.class.delete(path)
51
+ def delete(path, options={})
52
+ set_private_token_header(options)
53
+ validate self.class.delete(path, options)
47
54
  end
48
55
 
49
56
  # Checks the response code for common errors.
@@ -65,18 +72,27 @@ module Gitlab
65
72
  end
66
73
 
67
74
  # Sets a base_uri and default_params for requests.
68
- # @raise [Error::MissingCredentials] if endpoint or private_token not set.
75
+ # @raise [Error::MissingCredentials] if endpoint not set.
69
76
  def set_request_defaults(endpoint, private_token, sudo=nil)
70
77
  raise Error::MissingCredentials.new("Please set an endpoint to API") unless endpoint
71
- raise Error::MissingCredentials.new("Please set a private_token for user") unless private_token
78
+ @private_token = private_token
72
79
 
73
80
  self.class.base_uri endpoint
74
- self.class.default_params :private_token => private_token, :sudo => sudo
81
+ self.class.default_params :sudo => sudo
75
82
  self.class.default_params.delete(:sudo) if sudo.nil?
76
83
  end
77
84
 
78
85
  private
79
86
 
87
+ # Sets a PRIVATE-TOKEN header for requests.
88
+ # @raise [Error::MissingCredentials] if private_token not set.
89
+ def set_private_token_header(options, path=nil)
90
+ unless path == '/session'
91
+ raise Error::MissingCredentials.new("Please set a private_token for user") unless @private_token
92
+ options[:headers] = {'PRIVATE-TOKEN' => @private_token}
93
+ end
94
+ end
95
+
80
96
  def error_message(response)
81
97
  "Server responded with code #{response.code}, message: #{response.parsed_response.message}. " \
82
98
  "Request URI: #{response.request.base_uri}#{response.request.path}"
@@ -1,3 +1,3 @@
1
1
  module Gitlab
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -0,0 +1 @@
1
+ {"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"},"protected": true}
@@ -0,0 +1 @@
1
+ {"name":"api","commit":{ "id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","message":"API: expose issues project id","parent_ids":["949b1df930bedace1dbd755aaa4a82e8c451a616"],"authored_date":"2012-07-25T04:22:21-07:00","author_name":"Nihad Abbasov","author_email":"narkoz.2008@gmail.com","committed_date":"2012-07-25T04:22:21-07:00","committer_name":"Nihad Abbasov","committer_email":"narkoz.2008@gmail.com"},"protected": false}
@@ -0,0 +1 @@
1
+ [{"note":"this is the 1st comment on the 2merge merge request","author":{"id":11,"username":"admin","email":"admin@example.com","name":"A User","state":"active","created_at":"2014-03-06T08:17:35.000Z"}},{"note":"another discussion point on the 2merge request","author":{"id":12,"username":"admin","email":"admin@example.com","name":"A User","state":"active","created_at":"2014-03-06T08:17:35.000Z"}}]
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
3
+ "short_id": "6104942438c",
4
+ "title": "Sanitize for network graph",
5
+ "author_name": "randx",
6
+ "author_email": "dmitriy.zaporozhets@gmail.com",
7
+ "created_at": "2012-09-20T09:06:12+03:00",
8
+ "committed_date": "2012-09-20T09:06:12+03:00",
9
+ "authored_date": "2012-09-20T09:06:12+03:00",
10
+ "parent_ids": [
11
+ "ae1d9fb46aa2b07ee9836d49862ec4e2c46fbbba"
12
+ ]
13
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "diff": "--- a/doc/update/5.4-to-6.0.md\n+++ b/doc/update/5.4-to-6.0.md\n@@ -71,6 +71,8 @@\n sudo -u git -H bundle exec rake migrate_keys RAILS_ENV=production\n sudo -u git -H bundle exec rake migrate_inline_notes RAILS_ENV=production\n \n+sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production\n+\n ```\n \n ### 6. Update config files",
3
+ "new_path": "doc/update/5.4-to-6.0.md",
4
+ "old_path": "doc/update/5.4-to-6.0.md",
5
+ "a_mode": null,
6
+ "b_mode": "100644",
7
+ "new_file": false,
8
+ "renamed_file": false,
9
+ "deleted_file": false
10
+ }
@@ -1 +1 @@
1
- {"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"}}
1
+ {"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"},"protected":true}
@@ -0,0 +1 @@
1
+ {"id": 3, "url": "http://example.com/hook", "created_at": "2013-10-02T10:15:31Z"}
@@ -0,0 +1 @@
1
+ { "event_name": "project_create", "name": "Ruby", "path": "ruby", "project_id": 1, "owner_name": "Someone", "owner_email": "example@gitlabhq.com" }
@@ -0,0 +1 @@
1
+ [{"id": 3, "url": "http://example.com/hook", "created_at": "2013-10-02T10:15:31Z"}]
@@ -0,0 +1 @@
1
+ {"name":"api","commit":{"id":"f7dd067490fe57505f7226c3b54d3127d2f7fd46","parents":[{"id":"949b1df930bedace1dbd755aaa4a82e8c451a616"}],"tree":"f8c4b21c036339f92fcc5482aa28a41250553b27","message":"API: expose issues project id","author":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"committer":{"name":"Nihad Abbasov","email":"narkoz.2008@gmail.com"},"authored_date":"2012-07-25T04:22:21-07:00","committed_date":"2012-07-25T04:22:21-07:00"},"protected":false}
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gitlab::CLI do
4
+ describe ".run" do
5
+ context "when command is version" do
6
+ it "should show gem version" do
7
+ output = capture_output { Gitlab::CLI.run('-v') }
8
+ expect(output).to eq("Gitlab Ruby Gem #{Gitlab::VERSION}\n")
9
+ end
10
+ end
11
+
12
+ context "when command is info" do
13
+ it "should show environment info" do
14
+ output = capture_output { Gitlab::CLI.run('info') }
15
+ expect(output).to include("Gitlab endpoint is")
16
+ expect(output).to include("Gitlab private token is")
17
+ expect(output).to include("Ruby Version is")
18
+ expect(output).to include("Gitlab Ruby Gem")
19
+ end
20
+ end
21
+
22
+ context "when command is help" do
23
+ it "should show available actions" do
24
+ output = capture_output { Gitlab::CLI.run('help') }
25
+ expect(output).to include('Available commands')
26
+ expect(output).to include('MergeRequests')
27
+ expect(output).to include('team_members')
28
+ end
29
+ end
30
+
31
+ context "when command is user" do
32
+ before do
33
+ stub_get("/user", "user")
34
+ @output = capture_output { Gitlab::CLI.run('user') }
35
+ end
36
+
37
+ it "should show executed command" do
38
+ expect(@output).to include('Gitlab.user')
39
+ end
40
+
41
+ it "should show user data" do
42
+ expect(@output).to include('name')
43
+ expect(@output).to include('John Smith')
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ".start" do
49
+ context "when command with excluded fields" do
50
+ before do
51
+ stub_get("/user", "user")
52
+ args = ['user', '--except=id,email,name']
53
+ @output = capture_output { Gitlab::CLI.start(args) }
54
+ end
55
+
56
+ it "should show user data with excluded fields" do
57
+ expect(@output).to_not include('John Smith')
58
+ expect(@output).to include('bio')
59
+ expect(@output).to include('created_at')
60
+ end
61
+ end
62
+
63
+ context "when command with required fields" do
64
+ before do
65
+ stub_get("/user", "user")
66
+ args = ['user', '--only=id,email,name']
67
+ @output = capture_output { Gitlab::CLI.start(args) }
68
+ end
69
+
70
+ it "should show user data with required fields" do
71
+ expect(@output).to include('id')
72
+ expect(@output).to include('name')
73
+ expect(@output).to include('email')
74
+ expect(@output).to include('John Smith')
75
+ expect(@output).to_not include('bio')
76
+ expect(@output).to_not include('created_at')
77
+ end
78
+ end
79
+ end
80
+ end