audc-gerry 0.1.6 → 0.1.8

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +62 -62
  3. data/Rakefile +7 -7
  4. data/lib/gerry/api/access.rb +17 -17
  5. data/lib/gerry/api/accounts.rb +38 -38
  6. data/lib/gerry/api/branches.rb +45 -45
  7. data/lib/gerry/api/changes.rb +38 -38
  8. data/lib/gerry/api/groups.rb +72 -72
  9. data/lib/gerry/api/projects.rb +73 -73
  10. data/lib/gerry/api/request.rb +86 -86
  11. data/lib/gerry/client.rb +58 -58
  12. data/lib/gerry/version.rb +5 -5
  13. data/lib/gerry.rb +11 -11
  14. data/spec/access_spec.rb +15 -15
  15. data/spec/accounts_spec.rb +35 -35
  16. data/spec/branches_spec.rb +36 -36
  17. data/spec/changes_spec.rb +55 -55
  18. data/spec/fixtures/README.md.json +2 -2
  19. data/spec/fixtures/access_rights.json +250 -250
  20. data/spec/fixtures/account_groups.json +32 -32
  21. data/spec/fixtures/branch_access.json +50 -50
  22. data/spec/fixtures/capabilities.json +7 -7
  23. data/spec/fixtures/changes.json +30 -30
  24. data/spec/fixtures/changes_batch_0.json +18 -18
  25. data/spec/fixtures/changes_batch_1.json +18 -18
  26. data/spec/fixtures/changes_batch_2.json +17 -17
  27. data/spec/fixtures/group_members.json +14 -14
  28. data/spec/fixtures/groups.json +68 -68
  29. data/spec/fixtures/open_changes.json +16 -16
  30. data/spec/fixtures/project_branch.json +6 -6
  31. data/spec/fixtures/project_branches.json +21 -21
  32. data/spec/fixtures/project_head.json +2 -2
  33. data/spec/fixtures/projects.json +9 -9
  34. data/spec/fixtures/query_capabilities.json +4 -4
  35. data/spec/groups_spec.rb +92 -92
  36. data/spec/projects_spec.rb +90 -90
  37. data/spec/request_spec.rb +46 -46
  38. data/spec/spec_helper.rb +49 -49
  39. metadata +52 -54
data/spec/groups_spec.rb CHANGED
@@ -1,92 +1,92 @@
1
- require 'spec_helper'
2
-
3
- describe '.list_groups' do
4
- it 'fetchs all groups' do
5
- stub = stub_get('/groups/', 'groups.json')
6
-
7
- client = MockGerry.new
8
- groups = client.groups
9
- expect(stub).to have_been_requested
10
-
11
- expect(groups.size).to eq(6)
12
- expect(groups).to include('Project Owners')
13
- end
14
- end
15
-
16
- describe '.group_members' do
17
- it "fetchs all members of the specified group" do
18
- stub = stub_get('/groups/834ec36dd5e0ed21a2ff5d7e2255da082d63bbd7/members/', 'group_members.json')
19
-
20
- client = MockGerry.new
21
- group_members = client.group_members('834ec36dd5e0ed21a2ff5d7e2255da082d63bbd7')
22
- expect(stub).to have_been_requested
23
-
24
- expect(group_members.size).to eq(2)
25
- expect(group_members[1]['email']).to eq('john.doe@example.com')
26
- end
27
- end
28
-
29
- describe '.create_group' do
30
- let(:name) { "my_new_group_name" }
31
- let(:description) { "group description" }
32
- let(:visible) { true }
33
- let(:owner_id) { nil }
34
-
35
- it "creates a group" do
36
- input = {
37
- description: description,
38
- visible_to_all: visible
39
- }
40
-
41
- response = %Q<)]}'
42
- {
43
- "kind": "gerritcodereview#group",
44
- "id": "9999c971bb4ab872aab759d8c49833ee6b9ff320",
45
- "name": "#{name}",
46
- "url": "#/admin/groups/uuid-9999c971bb4ab872aab759d8c49833ee6b9ff320",
47
- "options": {
48
- "visible_to_all": true
49
- },
50
- "description":"#{description}",
51
- "group_id": 551,
52
- "owner": "#{name}",
53
- "owner_id": "9999c971bb4ab872aab759d8c49833ee6b9ff320"
54
- }
55
- >
56
- stub = stub_put('/groups/my_new_group_name', input.to_json, response)
57
-
58
- client = MockGerry.new
59
- new_group = client.create_group(name, description, visible, owner_id)
60
- expect(stub).to have_been_requested
61
- end
62
- end
63
-
64
- describe '.add_to_group' do
65
- it "adds users to a group" do
66
- users = %w(jane.roe@example.com john.doe@example.com)
67
- group_id = "9999c971bb4ab872aab759d8c49833ee6b9ff320"
68
- input = {
69
- members: users
70
- }
71
- stub = stub_post("/groups/#{group_id}/members", input.to_json, get_fixture('group_members.json'))
72
-
73
- client = MockGerry.new
74
- new_group = client.add_to_group(group_id, users)
75
- expect(stub).to have_been_requested
76
- end
77
- end
78
-
79
- describe '.remove_from_group' do
80
- it "removes users from a group" do
81
- users = %w(jane.roe@example.com john.doe@example.com)
82
- group_id = "9999c971bb4ab872aab759d8c49833ee6b9ff320"
83
- input = {
84
- members: users
85
- }
86
- stub = stub_post("/groups/#{group_id}/members.delete", input.to_json, "")
87
-
88
- client = MockGerry.new
89
- new_group = client.remove_from_group(group_id, users)
90
- expect(stub).to have_been_requested
91
- end
92
- end
1
+ require 'spec_helper'
2
+
3
+ describe '.list_groups' do
4
+ it 'fetchs all groups' do
5
+ stub = stub_get('/groups/', 'groups.json')
6
+
7
+ client = MockGerry.new
8
+ groups = client.groups
9
+ expect(stub).to have_been_requested
10
+
11
+ expect(groups.size).to eq(6)
12
+ expect(groups).to include('Project Owners')
13
+ end
14
+ end
15
+
16
+ describe '.group_members' do
17
+ it "fetchs all members of the specified group" do
18
+ stub = stub_get('/groups/834ec36dd5e0ed21a2ff5d7e2255da082d63bbd7/members/', 'group_members.json')
19
+
20
+ client = MockGerry.new
21
+ group_members = client.group_members('834ec36dd5e0ed21a2ff5d7e2255da082d63bbd7')
22
+ expect(stub).to have_been_requested
23
+
24
+ expect(group_members.size).to eq(2)
25
+ expect(group_members[1]['email']).to eq('john.doe@example.com')
26
+ end
27
+ end
28
+
29
+ describe '.create_group' do
30
+ let(:name) { "my_new_group_name" }
31
+ let(:description) { "group description" }
32
+ let(:visible) { true }
33
+ let(:owner_id) { nil }
34
+
35
+ it "creates a group" do
36
+ input = {
37
+ description: description,
38
+ visible_to_all: visible
39
+ }
40
+
41
+ response = %Q<)]}'
42
+ {
43
+ "kind": "gerritcodereview#group",
44
+ "id": "9999c971bb4ab872aab759d8c49833ee6b9ff320",
45
+ "name": "#{name}",
46
+ "url": "#/admin/groups/uuid-9999c971bb4ab872aab759d8c49833ee6b9ff320",
47
+ "options": {
48
+ "visible_to_all": true
49
+ },
50
+ "description":"#{description}",
51
+ "group_id": 551,
52
+ "owner": "#{name}",
53
+ "owner_id": "9999c971bb4ab872aab759d8c49833ee6b9ff320"
54
+ }
55
+ >
56
+ stub = stub_put('/groups/my_new_group_name', input.to_json, response)
57
+
58
+ client = MockGerry.new
59
+ new_group = client.create_group(name, description, visible, owner_id)
60
+ expect(stub).to have_been_requested
61
+ end
62
+ end
63
+
64
+ describe '.add_to_group' do
65
+ it "adds users to a group" do
66
+ users = %w(jane.roe@example.com john.doe@example.com)
67
+ group_id = "9999c971bb4ab872aab759d8c49833ee6b9ff320"
68
+ input = {
69
+ members: users
70
+ }
71
+ stub = stub_post("/groups/#{group_id}/members", input.to_json, get_fixture('group_members.json'))
72
+
73
+ client = MockGerry.new
74
+ new_group = client.add_to_group(group_id, users)
75
+ expect(stub).to have_been_requested
76
+ end
77
+ end
78
+
79
+ describe '.remove_from_group' do
80
+ it "removes users from a group" do
81
+ users = %w(jane.roe@example.com john.doe@example.com)
82
+ group_id = "9999c971bb4ab872aab759d8c49833ee6b9ff320"
83
+ input = {
84
+ members: users
85
+ }
86
+ stub = stub_post("/groups/#{group_id}/members.delete", input.to_json, "")
87
+
88
+ client = MockGerry.new
89
+ new_group = client.remove_from_group(group_id, users)
90
+ expect(stub).to have_been_requested
91
+ end
92
+ end
@@ -1,90 +1,90 @@
1
- require 'spec_helper'
2
- require 'pry'
3
-
4
- describe '.projects' do
5
- before(:all) do
6
- @client = MockGerry.new
7
- end
8
-
9
- it 'should fetch all projects' do
10
- stub = stub_get('/projects/', 'projects.json')
11
-
12
- projects = @client.projects
13
-
14
- expect(stub).to have_been_requested
15
-
16
- expect(projects['awesome']['description']).to eq('Awesome project')
17
- expect(projects['clean']['description']).to eq('Clean code!')
18
- end
19
-
20
- it 'should fetch a project' do
21
- stub = stub_get('/projects/awesome', 'projects.json')
22
-
23
- projects = @client.find_project('awesome')
24
-
25
- expect(stub).to have_been_requested
26
-
27
- expect(projects['awesome']['description']).to eq('Awesome project')
28
- end
29
-
30
- it 'should fetch file content' do
31
- stub = stub_get('/projects/awesome/commits/djfkslj/files/README.md/content','README.md.json')
32
-
33
- file = @client.project_file('awesome','djfkslj','README.md')
34
-
35
- expect(stub).to have_been_requested
36
- expect(file).to eq('Hello World!')
37
- end
38
-
39
- it 'should resolve the symbolic HEAD ref of a project' do
40
- project = 'awesome'
41
- stub = stub_get("/projects/#{project}/HEAD", 'project_head.json')
42
-
43
- branch = @client.get_head(project)
44
-
45
- expect(stub).to have_been_requested
46
-
47
- expect(branch).to eq('refs/heads/stable')
48
- end
49
-
50
- it 'should define the symbolic HEAD ref of a project' do
51
- project = 'awesome'
52
- branch = 'stable'
53
- input = {
54
- ref: 'refs/heads/' + branch
55
- }
56
- stub = stub_put("/projects/#{project}/HEAD", input.to_json, get_fixture('project_head.json'))
57
-
58
- new_branch = @client.set_head(project, branch)
59
-
60
- expect(stub).to have_been_requested
61
-
62
- expect(new_branch).to eq('refs/heads/' + branch)
63
- end
64
-
65
- it 'list access rights' do
66
- stub = stub_get('/projects/foo/access', 'branch_access.json')
67
-
68
- accesses = @client.project_access('foo')
69
- expect(stub).to have_been_requested
70
- end
71
-
72
- it 'create project access rights' do
73
- access_rights = {
74
- 'refs/heads/*' => {
75
- 'permissions' => {
76
- 'read' => {
77
- 'rules' => {
78
- 'user:kobe' => {
79
- 'action' => 'ALLOW'
80
- }
81
- }
82
- }
83
- }
84
- }
85
- }
86
- stub = stub_post('/projects/foo/access', 'add' => access_rights)
87
- @client.create_project_access('foo', access_rights)
88
- expect(stub).to have_been_requested
89
- end
90
- end
1
+ require 'spec_helper'
2
+ require 'pry'
3
+
4
+ describe '.projects' do
5
+ before(:all) do
6
+ @client = MockGerry.new
7
+ end
8
+
9
+ it 'should fetch all projects' do
10
+ stub = stub_get('/projects/', 'projects.json')
11
+
12
+ projects = @client.projects
13
+
14
+ expect(stub).to have_been_requested
15
+
16
+ expect(projects['awesome']['description']).to eq('Awesome project')
17
+ expect(projects['clean']['description']).to eq('Clean code!')
18
+ end
19
+
20
+ it 'should fetch a project' do
21
+ stub = stub_get('/projects/awesome', 'projects.json')
22
+
23
+ projects = @client.find_project('awesome')
24
+
25
+ expect(stub).to have_been_requested
26
+
27
+ expect(projects['awesome']['description']).to eq('Awesome project')
28
+ end
29
+
30
+ it 'should fetch file content' do
31
+ stub = stub_get('/projects/awesome/commits/djfkslj/files/README.md/content','README.md.json')
32
+
33
+ file = @client.project_file('awesome','djfkslj','README.md')
34
+
35
+ expect(stub).to have_been_requested
36
+ expect(file).to eq('Hello World!')
37
+ end
38
+
39
+ it 'should resolve the symbolic HEAD ref of a project' do
40
+ project = 'awesome'
41
+ stub = stub_get("/projects/#{project}/HEAD", 'project_head.json')
42
+
43
+ branch = @client.get_head(project)
44
+
45
+ expect(stub).to have_been_requested
46
+
47
+ expect(branch).to eq('refs/heads/stable')
48
+ end
49
+
50
+ it 'should define the symbolic HEAD ref of a project' do
51
+ project = 'awesome'
52
+ branch = 'stable'
53
+ input = {
54
+ ref: 'refs/heads/' + branch
55
+ }
56
+ stub = stub_put("/projects/#{project}/HEAD", input.to_json, get_fixture('project_head.json'))
57
+
58
+ new_branch = @client.set_head(project, branch)
59
+
60
+ expect(stub).to have_been_requested
61
+
62
+ expect(new_branch).to eq('refs/heads/' + branch)
63
+ end
64
+
65
+ it 'list access rights' do
66
+ stub = stub_get('/projects/foo/access', 'branch_access.json')
67
+
68
+ accesses = @client.project_access('foo')
69
+ expect(stub).to have_been_requested
70
+ end
71
+
72
+ it 'create project access rights' do
73
+ access_rights = {
74
+ 'refs/heads/*' => {
75
+ 'permissions' => {
76
+ 'read' => {
77
+ 'rules' => {
78
+ 'user:kobe' => {
79
+ 'action' => 'ALLOW'
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ stub = stub_post('/projects/foo/access', 'add' => access_rights)
87
+ @client.create_project_access('foo', access_rights)
88
+ expect(stub).to have_been_requested
89
+ end
90
+ end
data/spec/request_spec.rb CHANGED
@@ -1,46 +1,46 @@
1
- require 'spec_helper'
2
-
3
- describe '.map_options' do
4
- it 'should map the query options' do
5
-
6
- client = MockGerry.new
7
- options = client.map_options(['q=createAccount', 'q=createGroup'])
8
-
9
- expect(options).to eq('q=createAccount&q=createGroup')
10
- end
11
- end
12
-
13
- describe '.get' do
14
- it 'should request projects as anoymous' do
15
- stub = stub_get('/projects/', 'projects.json')
16
-
17
- client = MockGerry.new
18
- client.projects
19
-
20
- expect(stub).to have_been_requested
21
- end
22
-
23
- it 'should request projects as user with basic auth' do
24
- username = 'gerry'
25
- password = 'whoop'
26
-
27
- body = get_fixture('projects.json')
28
-
29
- stub = stub_request(:get, 'http://localhost/a/projects/').
30
- with(
31
- headers:
32
- {
33
- 'Accept' => 'application/json',
34
- 'Authorization' => 'Basic Z2Vycnk6d2hvb3A='
35
- }
36
- ).to_return(:status => 200, :body => body, :headers => {})
37
-
38
- client = Gerry.new(MockGerry::URL, 'gerry', 'whoop')
39
- projects = client.projects
40
-
41
- expect(stub).to have_been_requested
42
-
43
- expect(projects['awesome']['description']).to eq('Awesome project')
44
- expect(projects['clean']['description']).to eq('Clean code!')
45
- end
46
- end
1
+ require 'spec_helper'
2
+
3
+ describe '.map_options' do
4
+ it 'should map the query options' do
5
+
6
+ client = MockGerry.new
7
+ options = client.map_options(['q=createAccount', 'q=createGroup'])
8
+
9
+ expect(options).to eq('q=createAccount&q=createGroup')
10
+ end
11
+ end
12
+
13
+ describe '.get' do
14
+ it 'should request projects as anoymous' do
15
+ stub = stub_get('/projects/', 'projects.json')
16
+
17
+ client = MockGerry.new
18
+ client.projects
19
+
20
+ expect(stub).to have_been_requested
21
+ end
22
+
23
+ it 'should request projects as user with basic auth' do
24
+ username = 'gerry'
25
+ password = 'whoop'
26
+
27
+ body = get_fixture('projects.json')
28
+
29
+ stub = stub_request(:get, 'http://localhost/a/projects/').
30
+ with(
31
+ headers:
32
+ {
33
+ 'Accept' => 'application/json',
34
+ 'Authorization' => 'Basic Z2Vycnk6d2hvb3A='
35
+ }
36
+ ).to_return(:status => 200, :body => body, :headers => {})
37
+
38
+ client = Gerry.new(MockGerry::URL, 'gerry', 'whoop')
39
+ projects = client.projects
40
+
41
+ expect(stub).to have_been_requested
42
+
43
+ expect(projects['awesome']['description']).to eq('Awesome project')
44
+ expect(projects['clean']['description']).to eq('Clean code!')
45
+ end
46
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,50 +1,50 @@
1
- require "rspec/expectations"
2
- require 'webmock/rspec'
3
-
4
- require_relative '../lib/gerry'
5
-
6
- class MockGerry < Gerry::Client
7
- URL = 'http://localhost'
8
-
9
- def initialize
10
- super(URL)
11
- end
12
- end
13
-
14
- def get_fixture(filename)
15
- return '' if filename.empty?
16
- file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
17
- File.read(file_path)
18
- end
19
-
20
- def stub_get(url, filename)
21
- body = get_fixture(filename)
22
- stub_request(:get, "#{MockGerry::URL}#{url}").
23
- to_return(:status => 200, :body => "#{body}", :headers => {'Content-Type' => 'application/json'})
24
- end
25
-
26
- def stub_put(url, body, response_body=nil)
27
- response = {
28
- status: 200,
29
- headers: {
30
- 'Content-Type' => 'application/json'
31
- },
32
- body: response_body
33
- }
34
- stub_request(:put, "#{MockGerry::URL}#{url}").
35
- with(:body => body, :headers => { 'Content-Type' => 'application/json' }).
36
- to_return(response)
37
- end
38
-
39
- def stub_post(url, body, response_body=nil)
40
- response = {
41
- status: 200,
42
- headers: {
43
- 'Content-Type' => 'application/json'
44
- },
45
- body: response_body
46
- }
47
- stub_request(:post, "#{MockGerry::URL}#{url}").
48
- with(:body => body, :headers => { 'Content-Type' => 'application/json' }).
49
- to_return(response)
1
+ require "rspec/expectations"
2
+ require 'webmock/rspec'
3
+
4
+ require_relative '../lib/gerry'
5
+
6
+ class MockGerry < Gerry::Client
7
+ URL = 'http://localhost'
8
+
9
+ def initialize
10
+ super(URL)
11
+ end
12
+ end
13
+
14
+ def get_fixture(filename)
15
+ return '' if filename.empty?
16
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
17
+ File.read(file_path)
18
+ end
19
+
20
+ def stub_get(url, filename)
21
+ body = get_fixture(filename)
22
+ stub_request(:get, "#{MockGerry::URL}#{url}").
23
+ to_return(:status => 200, :body => "#{body}", :headers => {'Content-Type' => 'application/json'})
24
+ end
25
+
26
+ def stub_put(url, body, response_body=nil)
27
+ response = {
28
+ status: 200,
29
+ headers: {
30
+ 'Content-Type' => 'application/json'
31
+ },
32
+ body: response_body
33
+ }
34
+ stub_request(:put, "#{MockGerry::URL}#{url}").
35
+ with(:body => body, :headers => { 'Content-Type' => 'application/json' }).
36
+ to_return(response)
37
+ end
38
+
39
+ def stub_post(url, body, response_body=nil)
40
+ response = {
41
+ status: 200,
42
+ headers: {
43
+ 'Content-Type' => 'application/json'
44
+ },
45
+ body: response_body
46
+ }
47
+ stub_request(:post, "#{MockGerry::URL}#{url}").
48
+ with(:body => body, :headers => { 'Content-Type' => 'application/json' }).
49
+ to_return(response)
50
50
  end