tpitale-octopi 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/.gitignore +5 -0
  2. data/.yardoc +0 -0
  3. data/CHANGELOG.md +9 -0
  4. data/LICENSE +20 -0
  5. data/README.markdown +137 -0
  6. data/Rakefile +91 -0
  7. data/VERSION.yml +4 -0
  8. data/contrib/backup.rb +100 -0
  9. data/examples/authenticated.rb +20 -0
  10. data/examples/issues.rb +18 -0
  11. data/examples/overall.rb +50 -0
  12. data/lib/ext/string_ext.rb +5 -0
  13. data/lib/octopi.rb +92 -0
  14. data/lib/octopi/api.rb +213 -0
  15. data/lib/octopi/base.rb +115 -0
  16. data/lib/octopi/blob.rb +25 -0
  17. data/lib/octopi/branch.rb +31 -0
  18. data/lib/octopi/branch_set.rb +11 -0
  19. data/lib/octopi/comment.rb +20 -0
  20. data/lib/octopi/commit.rb +69 -0
  21. data/lib/octopi/error.rb +35 -0
  22. data/lib/octopi/file_object.rb +16 -0
  23. data/lib/octopi/gist.rb +28 -0
  24. data/lib/octopi/issue.rb +111 -0
  25. data/lib/octopi/issue_comment.rb +7 -0
  26. data/lib/octopi/issue_set.rb +21 -0
  27. data/lib/octopi/key.rb +25 -0
  28. data/lib/octopi/key_set.rb +14 -0
  29. data/lib/octopi/plan.rb +5 -0
  30. data/lib/octopi/repository.rb +130 -0
  31. data/lib/octopi/repository_set.rb +9 -0
  32. data/lib/octopi/resource.rb +70 -0
  33. data/lib/octopi/self.rb +33 -0
  34. data/lib/octopi/tag.rb +23 -0
  35. data/lib/octopi/user.rb +131 -0
  36. data/test/api_test.rb +58 -0
  37. data/test/authenticated_test.rb +38 -0
  38. data/test/base_test.rb +20 -0
  39. data/test/blob_test.rb +23 -0
  40. data/test/branch_test.rb +20 -0
  41. data/test/commit_test.rb +82 -0
  42. data/test/file_object_test.rb +39 -0
  43. data/test/gist_test.rb +16 -0
  44. data/test/issue_comment.rb +19 -0
  45. data/test/issue_set_test.rb +33 -0
  46. data/test/issue_test.rb +120 -0
  47. data/test/key_set_test.rb +29 -0
  48. data/test/key_test.rb +35 -0
  49. data/test/repository_set_test.rb +23 -0
  50. data/test/repository_test.rb +151 -0
  51. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  52. data/test/tag_test.rb +20 -0
  53. data/test/test_helper.rb +246 -0
  54. data/test/user_test.rb +92 -0
  55. data/tpitale-octopi.gemspec +99 -0
  56. metadata +142 -0
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class FileObjectTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repositories.find("octopi")
10
+ end
11
+
12
+ context "finding" do
13
+ context "with strings" do
14
+ should "work" do
15
+ FileObject.find(:user => "fcoury", :repository => "octopi", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
16
+ end
17
+ end
18
+
19
+ context "with objects" do
20
+ should "work" do
21
+ FileObject.find(:user => @user, :repository => @repo, :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
22
+ end
23
+ end
24
+
25
+ context "invalid sha" do
26
+ should "not work" do
27
+ # sha below is "ryan"
28
+ exception = assert_raise NotFound do
29
+ FileObject.find(:user => @user, :repository => @repo, :sha => "ea3cd978650417470535f3a4725b6b5042a6ab59")
30
+ end
31
+
32
+ assert_equal "The FileObject you were looking for could not be found, or is private.", exception.message
33
+
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class GistTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ end
9
+
10
+ context Gist do
11
+ should "Find a single gist" do
12
+ assert_not_nil Gist.find(159579)
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class IssueTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository("octopi")
10
+ end
11
+
12
+ context IssueComment do
13
+ should "be valid" do
14
+ comment = IssueComment.new({ :comment => "This is a comment", :status => "saved"})
15
+ assert_not_nil comment.comment
16
+ assert_not_nil comment.status
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class IssueSetTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository("octopi")
10
+ end
11
+
12
+
13
+ context IssueSet do
14
+ should "be able to find a specific issue" do
15
+ assert_not_nil @repo.issues.find(28)
16
+ end
17
+
18
+ should "not be able to find an issue that doesn't exist" do
19
+ exception = assert_raise Octopi::NotFound do
20
+ @repo.issues.find("not-a-number")
21
+ end
22
+
23
+ assert_equal "The Issue you were looking for could not be found, or is private.", exception.message
24
+ end
25
+
26
+ should "be able to look for an issue" do
27
+ results = @repo.issues.search(:keyword => "test")
28
+ assert_not_nil results
29
+ assert_equal 1, results.size
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,120 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class IssueTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository("octopi")
10
+ @issue = Issue.find(:user => @user, :repo => @repo, :number => 28)
11
+ @closed = Issue.find(:user => @user, :repo => @repo, :number => 27)
12
+ end
13
+
14
+
15
+ context Issue do
16
+ context "finding all the issues" do
17
+ should "using objects" do
18
+ issues = Issue.find_all(:user => @user, :repo => @repo)
19
+ assert_not_nil issues
20
+ assert_equal 21, issues.size
21
+ end
22
+
23
+ should "using strings" do
24
+ issues = Issue.find_all(:user => "fcoury", :repo => "octopi")
25
+ assert_not_nil issues
26
+ assert_equal 21, issues.size
27
+ end
28
+
29
+ should "specifying a state" do
30
+ issues = Issue.find_all(:user => @user, :repo => @repo, :state => "closed")
31
+ assert_not_nil issues
32
+ assert_equal 9, issues.size
33
+ end
34
+ end
35
+
36
+ context "finding a single issue" do
37
+ should "work" do
38
+ issue = Issue.find(:user => @user, :repo => @repo, :number => 28)
39
+ assert_not_nil issue
40
+ assert_not_nil issue.body
41
+ end
42
+
43
+ should "not work, if issue doesn't exist" do
44
+ exception = assert_raise NotFound do
45
+ Issue.find(:user => @user, :repo => @repo, :number => "not-a-number")
46
+ end
47
+
48
+ assert_equal "The Issue you were looking for could not be found, or is private.", exception.message
49
+ end
50
+
51
+ should "be able to look for an issue" do
52
+ results = Issue.search(:user => @user, :repo => @repo, :keyword => "test")
53
+ assert_not_nil results
54
+ assert_equal 1, results.size
55
+ end
56
+ end
57
+
58
+ context "actions" do
59
+ should "opening an issue" do
60
+ issue = Issue.open(:user => @user, :repo => @repo, :params => { :title => "something's broken", :body => "something broke" })
61
+ assert_not_nil issue
62
+ assert_equal "open", issue.state
63
+ end
64
+
65
+ should "re-opening an issue" do
66
+ assert_equal "closed", @closed.state
67
+ @closed.reopen!
68
+ assert_equal "open", @closed.state
69
+ end
70
+
71
+ should "closing an issue" do
72
+ assert_equal "open", @issue.state
73
+ @issue.close!
74
+ assert_equal "closed", @issue.state
75
+ end
76
+
77
+ should "editing an issue" do
78
+ @issue.title = 'Testing'
79
+ @issue.save
80
+ assert_equal "Testing", @issue.title
81
+ end
82
+
83
+ should "adding a label" do
84
+ assert @issue.labels.empty?
85
+ @issue.add_label("one-point-oh")
86
+ assert !@issue.labels.empty?
87
+ end
88
+
89
+ should "adding multiple labels" do
90
+ assert @issue.labels.empty?
91
+ @issue.add_label("one-point-oh", "maybe-two-point-oh")
92
+ assert !@issue.labels.empty?
93
+ assert 2, @issue.labels.size
94
+ end
95
+
96
+ should "removing a label" do
97
+ assert @issue.labels.empty?
98
+ @issue.add_label("one-point-oh")
99
+ assert !@issue.labels.empty?
100
+ @issue.remove_label("one-point-oh")
101
+ assert @issue.labels.empty?
102
+ end
103
+
104
+ should "removing multiple labels" do
105
+ assert @issue.labels.empty?
106
+ @issue.add_label("one-point-oh", "maybe-two-point-oh")
107
+ assert !@issue.labels.empty?
108
+ assert_equal 2, @issue.labels.size
109
+ @issue.remove_label("one-point-oh", "maybe-two-point-oh")
110
+ assert_equal 0, @issue.labels.size
111
+
112
+ end
113
+
114
+ should "be able to comment" do
115
+ comment = @issue.comment("Yes, it is broken.")
116
+ assert comment.is_a?(IssueComment)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class KeySetTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ end
10
+
11
+
12
+ context KeySet do
13
+ should "be able to find a key" do
14
+ auth do
15
+ assert_not_nil Api.me.keys.find("macbook")
16
+ end
17
+ end
18
+
19
+ should "not be able to find a key without a valid title" do
20
+ exception = assert_raise NotFound do
21
+ auth do
22
+ assert_not_nil Api.me.keys.find("windows-box")
23
+ end
24
+ end
25
+
26
+ assert_equal "The Key you were looking for could not be found, or is private.", exception.message
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class KeyTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ auth do
10
+ @key = Api.me.keys.first
11
+ end
12
+ end
13
+
14
+ context Key do
15
+
16
+ should "be able to add a key" do
17
+ auth do
18
+ Key.add(:title => "other-computer", :key => "AAAAB3NzaC1yc2EAAAABIwAAAQEA0dyfPrSHHSVD0u3JQlJfLyUrEVeNDW+9imbMHwiuT/IStf8SOroRjWT+/S5cL9m6qmKQBIU4v3LUnMKLTHfiWlqICnTDVRHuSayrHGp193I9kTSGBdM7wFZ2E8hDv5OqXHvAKGmOJvl5RqK0d42mhoK/x3bLRMQXHxwSDmYIFLy9rXLMvbVbdFJbbcqXP6QjnP4fAeebvTnUs6bVzInL9nh8Tqb3qjB5qji2i0MiCz3IouuZonOlef/VEac3Zpm6NcI5rVthPsMY55G8BMu4rVEStbIUlAJPoSBzqOgEKEXQbmWLh3CZnOoqQlLwIIvrKlwnXx26M1b+oOFm8s712Q==")
19
+ end
20
+ end
21
+
22
+ should "be able to remove a key" do
23
+ auth do
24
+ assert_equal 2, Api.me.keys.size
25
+ @key.remove
26
+ # Just trust me on this one
27
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/user/keys" + auth_query, :response => stub_file(File.join("users", "key-removed")))
28
+ assert_equal 1, Api.me.keys.size
29
+ end
30
+ end
31
+
32
+
33
+
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class RepositorySetTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ end
10
+
11
+
12
+ context RepositorySet do
13
+
14
+ should "return a repository set" do
15
+ assert @user.repositories.is_a?(RepositorySet)
16
+ end
17
+
18
+ should "be able to find a repository" do
19
+ assert_not_nil @user.repositories.find("octopi")
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,151 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class RepositoryTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @private_repos = auth do
10
+ @private = @user.repositories.find("rboard")
11
+ @user.repositories
12
+ end
13
+ @repository = @user.repositories.find("octopi")
14
+ end
15
+
16
+
17
+ context Repository do
18
+
19
+ should "not retry for a repository you don't have access to" do
20
+ FakeWeb.register_uri(:get, "#{yaml_api}/repos/show/github/github", :status => 403)
21
+
22
+ exception = assert_raise APIError do
23
+ Repository.find(:user => "github", :name => "github")
24
+ end
25
+
26
+ assert_equal exception.message, "Github returned status 403, you may not have access to this resource."
27
+ end
28
+
29
+ should "return a repository for a user" do
30
+ assert_not_nil @user.repository(:name => "octopi")
31
+ assert @user.repository(:name => "octopi").is_a?(Repository)
32
+ end
33
+
34
+ should "return a repository for a login" do
35
+ assert_not_nil Repository.find(:user => "fcoury", :name => "octopi")
36
+ end
37
+
38
+ should "be able to look up the repository based on the user and name" do
39
+ assert_not_nil Repository.find(:user => @user, :name => "octopi")
40
+ end
41
+
42
+ should "have a User as the owner" do
43
+ assert @repository.owner.is_a?(User)
44
+ end
45
+
46
+ should "return repositories" do
47
+ assert_equal 45, @user.repositories.size
48
+ end
49
+
50
+ should "return more repositories if authed" do
51
+ assert_equal 44, @private_repos.size
52
+ end
53
+
54
+ should "not return a repository when asked for a private one" do
55
+ exception = assert_raise NotFound do
56
+ @user.repository(:name => "rboard")
57
+ end
58
+
59
+ assert_equal "The Repository you were looking for could not be found, or is private.", exception.message
60
+ end
61
+
62
+ should "return a private repository when authed" do
63
+ auth do
64
+ assert_not_nil @user.repository(:name => "rboard")
65
+ end
66
+ end
67
+
68
+ should "be able to search for similar repositories" do
69
+ repos = Repository.search("ruby", "testing")
70
+ assert_not_nil repos
71
+ assert repos.first.is_a?(Repository)
72
+ end
73
+
74
+ should "be able to find the latest 30 commits" do
75
+ commits = @repository.commits
76
+ assert_not_nil commits
77
+ assert_equal 30, commits.size
78
+ end
79
+
80
+
81
+ should "be able to find all open issues" do
82
+ issues = @repository.issues
83
+ assert_not_nil issues
84
+ assert_equal 21, issues.size
85
+ end
86
+
87
+ should "be able to find all issues" do
88
+ issues = @repository.all_issues
89
+ assert_not_nil issues
90
+ assert_equal 42, issues.size
91
+ end
92
+
93
+ should "be able to find an issue" do
94
+ assert_not_nil @repository.issue(28)
95
+ end
96
+
97
+ should "be able to find all collaborators" do
98
+ @collaborators = @repository.collaborators
99
+ assert_not_nil @collaborators
100
+ assert_equal 1, @collaborators.size
101
+ assert @collaborators.first.is_a?(User)
102
+ end
103
+
104
+ should "be able to create a repository" do
105
+ auth do
106
+ Repository.create(:name => "octopus")
107
+ end
108
+ end
109
+
110
+ should "be able to delete a repository" do
111
+ auth do
112
+ @repository.delete!
113
+ end
114
+ end
115
+
116
+ should "not be able to create a repository when not authed" do
117
+ assert_raise Octopi::AuthenticationRequired do
118
+ Repository.create(:name => "octopus")
119
+ end
120
+ end
121
+
122
+ should "be able to retrieve the branches" do
123
+ branches = @repository.branches
124
+ assert_not_nil branches
125
+ assert_equal 4, branches.size
126
+ end
127
+
128
+ should "be able to retrieve the tags" do
129
+ tags = @repository.tags
130
+ assert_not_nil tags
131
+ assert_equal 9, tags.size
132
+ end
133
+
134
+ should "be able to retrieve the comments" do
135
+ assert_not_nil @repository.comments
136
+ comment = @repository.comments.first
137
+ [:content, :author, :title, :updated, :link, :published, :id, :repository, :commit].each do |f|
138
+ assert_not_nil comment.send(f)
139
+ end
140
+ end
141
+
142
+ should "return the correct clone URL" do
143
+ assert_equal "git://github.com/fcoury/octopi.git", @repository.clone_url
144
+ auth do
145
+ assert_equal "git@github.com:fcoury/rboard.git", @private.clone_url
146
+ end
147
+ end
148
+
149
+
150
+ end
151
+ end