octopi 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +2 -1
  2. data/.yardoc +0 -0
  3. data/README.rdoc +16 -41
  4. data/Rakefile +9 -0
  5. data/VERSION.yml +2 -2
  6. data/examples/overall.rb +1 -1
  7. data/lib/ext/hash_ext.rb +5 -0
  8. data/lib/ext/string_ext.rb +5 -0
  9. data/lib/octopi.rb +101 -202
  10. data/lib/octopi/api.rb +209 -0
  11. data/lib/octopi/base.rb +42 -38
  12. data/lib/octopi/blob.rb +12 -8
  13. data/lib/octopi/branch.rb +20 -7
  14. data/lib/octopi/branch_set.rb +11 -0
  15. data/lib/octopi/comment.rb +20 -0
  16. data/lib/octopi/commit.rb +39 -35
  17. data/lib/octopi/error.rb +17 -5
  18. data/lib/octopi/file_object.rb +6 -5
  19. data/lib/octopi/gist.rb +28 -0
  20. data/lib/octopi/issue.rb +49 -40
  21. data/lib/octopi/issue_comment.rb +7 -0
  22. data/lib/octopi/issue_set.rb +21 -0
  23. data/lib/octopi/key.rb +14 -7
  24. data/lib/octopi/key_set.rb +14 -0
  25. data/lib/octopi/plan.rb +5 -0
  26. data/lib/octopi/repository.rb +66 -45
  27. data/lib/octopi/repository_set.rb +9 -0
  28. data/lib/octopi/resource.rb +11 -16
  29. data/lib/octopi/self.rb +33 -0
  30. data/lib/octopi/tag.rb +12 -6
  31. data/lib/octopi/user.rb +62 -38
  32. data/octopi.gemspec +43 -12
  33. data/test/api_test.rb +58 -0
  34. data/test/authenticated_test.rb +39 -0
  35. data/test/blob_test.rb +23 -0
  36. data/test/branch_test.rb +20 -0
  37. data/test/commit_test.rb +82 -0
  38. data/test/file_object_test.rb +39 -0
  39. data/test/gist_test.rb +16 -0
  40. data/test/issue_comment.rb +19 -0
  41. data/test/issue_set_test.rb +33 -0
  42. data/test/issue_test.rb +120 -0
  43. data/test/key_set_test.rb +29 -0
  44. data/test/key_test.rb +35 -0
  45. data/test/repository_set_test.rb +23 -0
  46. data/test/repository_test.rb +141 -0
  47. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  48. data/test/tag_test.rb +20 -0
  49. data/test/test_helper.rb +236 -0
  50. data/test/user_test.rb +92 -0
  51. metadata +54 -12
  52. data/examples/github.yml.example +0 -14
  53. data/test/octopi_test.rb +0 -46
data/test/blob_test.rb ADDED
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class BlobTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ end
9
+
10
+ context Blob do
11
+ should "find a blob" do
12
+ blob = Blob.find(:user => "fcoury", :repo => "octopi", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
13
+ assert_not_nil blob
14
+ assert blob.is_a?(String)
15
+ end
16
+
17
+ # Can't grab real data for this yet, Github is throwing a 500 on this request.
18
+ # should "find a file for a blob" do
19
+ # assert_not_nil Blob.find(:user => "fcoury", :repo => "octopi", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae", :path => "lib/octopi.rb")
20
+ # end
21
+ end
22
+ end
23
+
@@ -0,0 +1,20 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class BranchTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ end
9
+
10
+ context Branch do
11
+ should "Find all branches for a repository" do
12
+ assert_not_nil Branch.all(:user => "fcoury", :name => "octopi")
13
+ end
14
+
15
+ should "Be able to find a specific branch" do
16
+ assert_not_nil Branch.all(:user => "fcoury", :name => "octopi").find("lazy")
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,82 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class CommitTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ @repo = @user.repository(:name => "octopi")
10
+ end
11
+
12
+ context Commit do
13
+ context "finding all commits" do
14
+ should "by strings" do
15
+ commits = Commit.find_all(:user => "fcoury", :repository => "octopi")
16
+ assert_not_nil commits
17
+ assert_equal 30, commits.size
18
+ assert_not_nil commits.first.repository
19
+ end
20
+
21
+ should "by objects" do
22
+ commits = Commit.find_all(:user => @user, :repository => @repo)
23
+ assert_not_nil commits
24
+ assert_equal 30, commits.size
25
+ end
26
+
27
+ should "be able to specify a branch" do
28
+ commits = Commit.find_all(:user => "fcoury", :repository => "octopi", :branch => "lazy")
29
+ assert_not_nil commits
30
+ assert_equal 30, commits.size
31
+ end
32
+
33
+ # Tests issue #28
34
+ should "be able to find commits in a private repository" do
35
+ auth do
36
+ commits = Commit.find_all(:user => "fcoury", :repository => "rboard")
37
+ end
38
+ assert_not_nil commits
39
+ assert_equal 22, commits.size
40
+ end
41
+
42
+ should "be able to find commits for a particular file" do
43
+ commits = Commit.find_all(:user => "fcoury", :repository => "octopi", :path => "lib/octopi.rb")
44
+ assert_not_nil commits
45
+ assert_equal 44, commits.size
46
+ end
47
+ end
48
+
49
+ context "finding a single commit" do
50
+ should "by strings" do
51
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
52
+ assert_not_nil commit
53
+ end
54
+
55
+ should "by objects" do
56
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
57
+ assert_not_nil commit
58
+ end
59
+
60
+ should "be able to specify a branch" do
61
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae", :branch => "lazy")
62
+ assert_not_nil commit
63
+ end
64
+
65
+ should "raise an error if not found" do
66
+ exception = assert_raise Octopi::NotFound do
67
+ Commit.find(:name => "octopi", :user => "fcoury", :sha => "nothere")
68
+ end
69
+
70
+ assert_equal "The Commit you were looking for could not be found, or is private.", exception.message
71
+ end
72
+ end
73
+
74
+ context "identifying a repository" do
75
+ should "be possible" do
76
+ commit = Commit.find(:name => "octopi", :user => "fcoury", :sha => "f6609209c3ac0badd004512d318bfaa508ea10ae")
77
+ assert_equal "fcoury/octopi/f6609209c3ac0badd004512d318bfaa508ea10ae", commit.repo_identifier
78
+ end
79
+ end
80
+ end
81
+ end
82
+
@@ -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
+
data/test/gist_test.rb ADDED
@@ -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
data/test/key_test.rb ADDED
@@ -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