octopi 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/.gitignore +5 -0
  2. data/Rakefile +2 -84
  3. data/examples/authenticated.rb +20 -0
  4. data/examples/github.yml.example +14 -0
  5. data/examples/issues.rb +18 -0
  6. data/examples/overall.rb +50 -0
  7. data/lib/octopi/version.rb +3 -0
  8. data/octopi.gemspec +20 -93
  9. data/real_world_test/commit_test.rb +20 -0
  10. data/real_world_test/repository_test.rb +19 -0
  11. data/real_world_test/test_helper.rb +11 -0
  12. data/test/.gitconfig +3 -0
  13. data/test/api_test.rb +58 -0
  14. data/test/authenticated_test.rb +39 -0
  15. data/test/base_test.rb +20 -0
  16. data/test/blob_test.rb +23 -0
  17. data/test/branch_test.rb +20 -0
  18. data/test/commit_test.rb +89 -0
  19. data/test/file_object_test.rb +39 -0
  20. data/test/gist_test.rb +16 -0
  21. data/test/issue_comment.rb +19 -0
  22. data/test/issue_set_test.rb +33 -0
  23. data/test/issue_test.rb +136 -0
  24. data/test/key_set_test.rb +29 -0
  25. data/test/key_test.rb +35 -0
  26. data/test/repository_set_test.rb +23 -0
  27. data/test/repository_test.rb +164 -0
  28. data/test/stubs/account +691 -0
  29. data/test/stubs/blob/fcoury/octopi/plain/f6609209c3ac0badd004512d318bfaa508ea10ae +20 -0
  30. data/test/stubs/comments/fcoury/octopi/comments +30 -0
  31. data/test/stubs/comments/fcoury/octopi/comments.atom +48 -0
  32. data/test/stubs/commits/fcoury/octopi/f6609209c3ac0badd004512d318bfaa508ea10ae +94 -0
  33. data/test/stubs/commits/fcoury/octopi/lazy +491 -0
  34. data/test/stubs/commits/fcoury/octopi/master +477 -0
  35. data/test/stubs/commits/fcoury/octopi/octopi.rb +818 -0
  36. data/test/stubs/commits/fcoury/rboard/master +437 -0
  37. data/test/stubs/dashboard +231 -0
  38. data/test/stubs/errors/repository/not_found +16 -0
  39. data/test/stubs/gists/159579 +18 -0
  40. data/test/stubs/issues/fcoury/octopi/27 +42 -0
  41. data/test/stubs/issues/fcoury/octopi/27-reopened +27 -0
  42. data/test/stubs/issues/fcoury/octopi/28 +27 -0
  43. data/test/stubs/issues/fcoury/octopi/28-closed +27 -0
  44. data/test/stubs/issues/fcoury/octopi/28-edited +27 -0
  45. data/test/stubs/issues/fcoury/octopi/closed +175 -0
  46. data/test/stubs/issues/fcoury/octopi/comment/28-comment +15 -0
  47. data/test/stubs/issues/fcoury/octopi/labels/28-maybe-two-point-oh +16 -0
  48. data/test/stubs/issues/fcoury/octopi/labels/28-one-point-oh +16 -0
  49. data/test/stubs/issues/fcoury/octopi/labels/28-remove-maybe-two-point-oh +14 -0
  50. data/test/stubs/issues/fcoury/octopi/labels/28-remove-one-point-oh +15 -0
  51. data/test/stubs/issues/fcoury/octopi/new +27 -0
  52. data/test/stubs/issues/fcoury/octopi/open +329 -0
  53. data/test/stubs/issues/fcoury/octopi/search +139 -0
  54. data/test/stubs/login +157 -0
  55. data/test/stubs/repos/fcoury/octopi/branches +18 -0
  56. data/test/stubs/repos/fcoury/octopi/collaborators +16 -0
  57. data/test/stubs/repos/fcoury/octopi/delete-token +13 -0
  58. data/test/stubs/repos/fcoury/octopi/languages +16 -0
  59. data/test/stubs/repos/fcoury/octopi/main +12 -0
  60. data/test/stubs/repos/fcoury/octopi/master +24 -0
  61. data/test/stubs/repos/fcoury/octopi/tags +23 -0
  62. data/test/stubs/repos/fcoury/octopus/main +24 -0
  63. data/test/stubs/repos/fcoury/rboard/main +12 -0
  64. data/test/stubs/repos/fcoury/rboard/master +24 -0
  65. data/test/stubs/repos/search +238 -0
  66. data/test/stubs/repos/show/fcoury +463 -0
  67. data/test/stubs/repos/show/fcoury-private +454 -0
  68. data/test/stubs/tree/fcoury/octopi/f6609209c3ac0badd004512d318bfaa508ea10ae +54 -0
  69. data/test/stubs/users/Caged +26 -0
  70. data/test/stubs/users/FooBarWidget +26 -0
  71. data/test/stubs/users/aslakhellesoy +26 -0
  72. data/test/stubs/users/augustl +26 -0
  73. data/test/stubs/users/bcalloway +26 -0
  74. data/test/stubs/users/benaskins +26 -0
  75. data/test/stubs/users/benhoskings +26 -0
  76. data/test/stubs/users/bjeanes +27 -0
  77. data/test/stubs/users/cldwalker +26 -0
  78. data/test/stubs/users/danlucraft +26 -0
  79. data/test/stubs/users/dchelimsky +26 -0
  80. data/test/stubs/users/dcrec1 +26 -0
  81. data/test/stubs/users/defunkt +26 -0
  82. data/test/stubs/users/derencius +26 -0
  83. data/test/stubs/users/diy +21 -0
  84. data/test/stubs/users/documentcloud +26 -0
  85. data/test/stubs/users/drnic +26 -0
  86. data/test/stubs/users/dustin +26 -0
  87. data/test/stubs/users/eladmeidar +26 -0
  88. data/test/stubs/users/elliottcable +26 -0
  89. data/test/stubs/users/entp +26 -0
  90. data/test/stubs/users/fcoury +26 -0
  91. data/test/stubs/users/fcoury-private +36 -0
  92. data/test/stubs/users/follow +15 -0
  93. data/test/stubs/users/follow-rails +15 -0
  94. data/test/stubs/users/followers +24 -0
  95. data/test/stubs/users/following +28 -0
  96. data/test/stubs/users/giraffesoft +26 -0
  97. data/test/stubs/users/gwoliveira +26 -0
  98. data/test/stubs/users/hashrocket +26 -0
  99. data/test/stubs/users/hcatlin +26 -0
  100. data/test/stubs/users/jamis +26 -0
  101. data/test/stubs/users/jnicklas +26 -0
  102. data/test/stubs/users/jnunemaker +26 -0
  103. data/test/stubs/users/jruby +21 -0
  104. data/test/stubs/users/kballard +26 -0
  105. data/test/stubs/users/kchris +26 -0
  106. data/test/stubs/users/key-added +20 -0
  107. data/test/stubs/users/key-removed +17 -0
  108. data/test/stubs/users/keys +21 -0
  109. data/test/stubs/users/knewter +26 -0
  110. data/test/stubs/users/lachie +26 -0
  111. data/test/stubs/users/lachlanhardy +26 -0
  112. data/test/stubs/users/lenary +26 -0
  113. data/test/stubs/users/lifo +26 -0
  114. data/test/stubs/users/maccman +26 -0
  115. data/test/stubs/users/markgandolfo +26 -0
  116. data/test/stubs/users/mbleigh +26 -0
  117. data/test/stubs/users/mhodgson +26 -0
  118. data/test/stubs/users/mocra +26 -0
  119. data/test/stubs/users/mojombo +26 -0
  120. data/test/stubs/users/newbamboo +26 -0
  121. data/test/stubs/users/notahat +26 -0
  122. data/test/stubs/users/opscode +26 -0
  123. data/test/stubs/users/paulorv +26 -0
  124. data/test/stubs/users/pvande +21 -0
  125. data/test/stubs/users/rack +26 -0
  126. data/test/stubs/users/radar +26 -0
  127. data/test/stubs/users/rails +26 -0
  128. data/test/stubs/users/railscampau +21 -0
  129. data/test/stubs/users/redinger +26 -0
  130. data/test/stubs/users/remi +26 -0
  131. data/test/stubs/users/search-radar +27 -0
  132. data/test/stubs/users/shanesveller +26 -0
  133. data/test/stubs/users/shuber +26 -0
  134. data/test/stubs/users/softprops +26 -0
  135. data/test/stubs/users/superfeedr +26 -0
  136. data/test/stubs/users/svenfuchs +26 -0
  137. data/test/stubs/users/taylorrf +26 -0
  138. data/test/stubs/users/technoweenie +26 -0
  139. data/test/stubs/users/tgraham +26 -0
  140. data/test/stubs/users/thoughtbot +26 -0
  141. data/test/stubs/users/tmm1 +26 -0
  142. data/test/stubs/users/tobi +26 -0
  143. data/test/stubs/users/tpope +26 -0
  144. data/test/stubs/users/unfollow-rails +14 -0
  145. data/test/stubs/users/watched-repos +1668 -0
  146. data/test/stubs/users/webbynode +26 -0
  147. data/test/stubs/users/wvanbergen +26 -0
  148. data/test/stubs/users/wycats +26 -0
  149. data/test/tag_test.rb +20 -0
  150. data/test/test_helper.rb +251 -0
  151. data/test/user_test.rb +97 -0
  152. data/test_auth.rb +5 -0
  153. metadata +359 -73
@@ -0,0 +1,26 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/0.7.61
3
+ Date: Thu, 05 Nov 2009 21:06:51 GMT
4
+ Content-Type: application/x-yaml; charset=utf-8
5
+ Connection: keep-alive
6
+ Status: 200 OK
7
+ ETag: "2769fb4793a2763c7a6da914a0070cc4"
8
+ X-Runtime: 13ms
9
+ Content-Length: 233
10
+ Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
11
+ Cache-Control: private, max-age=0, must-revalidate
12
+
13
+ ---
14
+ user:
15
+ name: ""
16
+ company:
17
+ location:
18
+ created_at: 2009-03-28 00:29:46 -07:00
19
+ public_gist_count: 5
20
+ public_repo_count: 10
21
+ blog: ""
22
+ following_count: 2
23
+ id: 68083
24
+ followers_count: 11
25
+ login: webbynode
26
+ email: ""
@@ -0,0 +1,26 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/0.7.61
3
+ Date: Thu, 05 Nov 2009 21:06:52 GMT
4
+ Content-Type: application/x-yaml; charset=utf-8
5
+ Connection: keep-alive
6
+ Status: 200 OK
7
+ ETag: "39ad0c7d44e7b2b85f6a879f606ced73"
8
+ X-Runtime: 13ms
9
+ Content-Length: 342
10
+ Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
11
+ Cache-Control: private, max-age=0, must-revalidate
12
+
13
+ ---
14
+ user:
15
+ name: Willem van Bergen
16
+ company: Floorplanner.com
17
+ location: Rotterdam, The Netherlands
18
+ created_at: 2008-07-02 21:28:50 -07:00
19
+ public_gist_count: 3
20
+ public_repo_count: 9
21
+ blog: http://techblog.floorplanner.com
22
+ following_count: 10
23
+ id: 15870
24
+ followers_count: 15
25
+ login: wvanbergen
26
+ email: willem@railsdoctors.com
@@ -0,0 +1,26 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/0.7.61
3
+ Date: Thu, 05 Nov 2009 21:06:52 GMT
4
+ Content-Type: application/x-yaml; charset=utf-8
5
+ Connection: keep-alive
6
+ Status: 200 OK
7
+ ETag: "f97a1ff2f8799ad0284f5b1417d8dc1e"
8
+ X-Runtime: 39ms
9
+ Content-Length: 299
10
+ Set-Cookie: _github_ses=BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7AA%3D%3D--884981fc5aa85daf318eeff084d98e2cff92578f; path=/; expires=Wed, 01 Jan 2020 08:00:00 GMT; HttpOnly
11
+ Cache-Control: private, max-age=0, must-revalidate
12
+
13
+ ---
14
+ user:
15
+ name: Yehuda Katz
16
+ company: Engine Yard
17
+ location: San Francisco
18
+ created_at: 2008-01-11 21:38:33 -08:00
19
+ public_gist_count: 351
20
+ public_repo_count: 46
21
+ blog: http://www.yehudakatz.com
22
+ following_count: 3
23
+ id: 4
24
+ followers_count: 581
25
+ login: wycats
26
+ email: wycats@gmail.com
data/test/tag_test.rb ADDED
@@ -0,0 +1,20 @@
1
+ # Tests for octopi core functionality go here.
2
+ require File.join(File.dirname(__FILE__), 'test_helper')
3
+
4
+ class TagTest < Test::Unit::TestCase
5
+ include Octopi
6
+
7
+ def setup
8
+ fake_everything
9
+ end
10
+
11
+ context Tag do
12
+ should "be able to find all tags" do
13
+ tags = Tag.all(:user => "fcoury", :repository => "octopi")
14
+ assert_not_nil tags
15
+ assert_equal 9, tags.size
16
+ assert tags.first.is_a?(Tag)
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,251 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'octopi'
9
+
10
+ ENV['HOME'] = File.dirname(__FILE__)
11
+ FakeWeb.allow_net_connect = false
12
+
13
+ @the_repo = ["fcoury", "octopi"]
14
+
15
+ def stub_file(*path)
16
+ File.join(File.dirname(__FILE__), "stubs", path)
17
+ end
18
+
19
+ def commits(*args)
20
+ File.join("commits", "fcoury", "octopi", args)
21
+ end
22
+
23
+ def issues(*args)
24
+ File.join("issues", "fcoury", "octopi", args)
25
+ end
26
+
27
+ def repos(*args)
28
+ File.join("repos", "fcoury", "octopi", args)
29
+ end
30
+
31
+ def users(*args)
32
+ File.join("users", args)
33
+ end
34
+
35
+ def auth(&block)
36
+ authenticated_with(:login => "fcoury", :token => "8f700e0d7747826f3e56ee13651414bd") do
37
+ yield
38
+ end
39
+ end
40
+
41
+ # Methodized so it can be used in tests, an instance would do also.
42
+ def yaml_api
43
+ "github.com/api/v2/yaml"
44
+ end
45
+
46
+ def fake_everything
47
+ FakeWeb.clean_registry
48
+ # helper variables to make things shorter.
49
+ sha = "f6609209c3ac0badd004512d318bfaa508ea10ae"
50
+ fake_sha = "ea3cd978650417470535f3a4725b6b5042a6ab59"
51
+
52
+ plain_api = "github.com/api/v2/plain"
53
+
54
+ # Public stuff
55
+ fakes = {
56
+ "blob/show/fcoury/octopi/#{sha}" => File.join("blob", "fcoury", "octopi", "plain", sha),
57
+
58
+ "commits/list/fcoury/octopi/master" => commits("master"),
59
+ "commits/list/fcoury/octopi/master/lib/octopi.rb" => commits("octopi.rb"),
60
+ "commits/list/fcoury/octopi/lazy" => commits("lazy"),
61
+ "commits/show/fcoury/octopi/#{sha}" => commits(sha),
62
+
63
+ "issues/list/fcoury/octopi/open" => issues("open"),
64
+ "issues/list/fcoury/octopi/closed" => issues("closed"),
65
+
66
+ "issues/search/fcoury/octopi/open/test" => issues("search"),
67
+
68
+ #comments for an issue
69
+ "issues/comments/fcoury/octopi/28" => File.join("comments", "fcoury", "octopi", "comments"),
70
+
71
+ # Closed issue
72
+ "issues/show/fcoury/octopi/27" => issues("27"),
73
+ # Open issue
74
+ "issues/show/fcoury/octopi/28" => issues("28"),
75
+
76
+ "repos/show/fcoury/octopi/collaborators" => File.join("repos", "fcoury", "octopi", "collaborators"),
77
+ "repos/show/fcoury/octopi/languages" => File.join("repos", "fcoury", "octopi", "languages"),
78
+ "repos/show/fcoury" => File.join("repos", "show", "fcoury"),
79
+ "repos/search/ruby+testing" => File.join("repos", "search"),
80
+ "repos/show/fcoury/octopi" => repos("master"),
81
+ "repos/show/fcoury/octopi/branches" => repos("branches"),
82
+ "repos/show/fcoury/octopi/tags" => repos("tags"),
83
+ "repos/watched/radar" => File.join("users", "watched-repos"),
84
+
85
+ "tree/show/fcoury/octopi/#{sha}" => File.join("tree", "fcoury", "octopi", sha),
86
+
87
+ "user/show/fcoury" => users("fcoury"),
88
+
89
+ "user/show/fcoury/followers" => File.join("users", "followers"),
90
+ "user/show/fcoury/following" => File.join("users", "following"),
91
+ "user/search/radar" => File.join("users", "search-radar"),
92
+ "user/email/test@example.com" => users("fcoury")
93
+
94
+
95
+ }
96
+
97
+ # I follow the following people:
98
+ ["Caged",
99
+ "FooBarWidget",
100
+ "aslakhellesoy",
101
+ "augustl",
102
+ "benaskins",
103
+ "benhoskings",
104
+ "bjeanes",
105
+ "cldwalker",
106
+ "dchelimsky",
107
+ "defunkt",
108
+ "diy",
109
+ "documentcloud",
110
+ "drnic",
111
+ "eladmeidar",
112
+ "entp",
113
+ "fcoury",
114
+ "giraffesoft",
115
+ "hashrocket",
116
+ "hcatlin",
117
+ "jamis",
118
+ "jnicklas",
119
+ "jnunemaker",
120
+ "kballard",
121
+ "knewter",
122
+ "lachie",
123
+ "lachlanhardy",
124
+ "lenary",
125
+ "lifo",
126
+ "maccman",
127
+ "markgandolfo",
128
+ "mbleigh",
129
+ "mhodgson",
130
+ "mocra",
131
+ "mojombo",
132
+ "newbamboo",
133
+ "notahat",
134
+ "opscode",
135
+ "pvande",
136
+ "rack",
137
+ "radar",
138
+ "rails",
139
+ "railscampau",
140
+ "redinger",
141
+ "shuber",
142
+ "softprops",
143
+ "svenfuchs",
144
+ "technoweenie",
145
+ "thoughtbot",
146
+ "tobi",
147
+ "webbynode",
148
+ "wvanbergen",
149
+ "wycats"].each do |name|
150
+ fakes["user/show/#{name}"] = users(name);
151
+ end
152
+
153
+ fakes.each do |key, value|
154
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/" + key, :response => stub_file(value))
155
+ end
156
+
157
+ gist_fakes = {
158
+ "159579" => File.join("gists", "159579")
159
+ }
160
+
161
+
162
+ gist_fakes.each do |key, value|
163
+ FakeWeb.register_uri(:get, "https://gist.github.com/api/v1/yaml/#{key}", :response => stub_file(value))
164
+ end
165
+ ["augustl", "bcalloway", "danlucraft", "dcrec1", "derencius", "dustin", "elliottcable", "gwoliveira", "hashrocket", "jruby", "kchris", "paulorv", "radar", "remi", "shanesveller", "superfeedr", "taylorrf", "tgraham", "tmm1", "tpope", "webbynode"].each do |followee|
166
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/user/show/#{followee}", :response => stub_file("users/#{followee}") )
167
+ end
168
+
169
+
170
+ fake_posts = {
171
+ "issues/label/add/fcoury/octopi/one-point-oh/28" => issues("labels", "28-one-point-oh"),
172
+ "issues/label/add/fcoury/octopi/maybe-two-point-oh/28" => issues("labels", "28-maybe-two-point-oh"),
173
+ "issues/label/remove/fcoury/octopi/one-point-oh/28" => issues("labels", "28-remove-one-point-oh"),
174
+ "issues/label/remove/fcoury/octopi/maybe-two-point-oh/28" => issues("labels", "28-remove-maybe-two-point-oh"),
175
+ "issues/reopen/fcoury/octopi/27" => issues("27-reopened"),
176
+ "issues/open/fcoury/octopi" => issues("new"),
177
+ "issues/close/fcoury/octopi/28" => issues("28-closed"),
178
+ "issues/edit/fcoury/octopi/28" => issues("28-edited"),
179
+ "issues/reopen/fcoury/octopi/27" => issues("27-reopened"),
180
+ "issues/comment/fcoury/octopi/28" => issues("comment", "28-comment")
181
+ }.each do |key, value|
182
+ FakeWeb.register_uri(:post, "https://#{yaml_api}/" + key, :response => stub_file(value))
183
+ end
184
+
185
+ # # rboard is a private repository
186
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/repos/show/fcoury/rboard", :response => stub_file("errors", "repository", "not_found"))
187
+
188
+ # nothere is obviously an invalid sha
189
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/commits/show/fcoury/octopi/nothere", :status => ["404", "Not Found"])
190
+ # not-a-number is obviously not a *number*
191
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/issues/show/fcoury/octopi/not-a-number", :status => ["404", "Not Found"])
192
+ # is an invalid hash
193
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/tree/show/fcoury/octopi/#{fake_sha}", :status => ["404", "Not Found"])
194
+ # is not a user
195
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/user/show/i-am-most-probably-a-user-that-does-not-exist", :status => ["404", "Not Found"])
196
+
197
+
198
+ FakeWeb.register_uri(:get, "https://github.com/login", :response => stub_file("login"))
199
+ FakeWeb.register_uri(:post, "https://github.com/session", :response => stub_file("dashboard"))
200
+ FakeWeb.register_uri(:get, "https://github.com/account", :response => stub_file("account"))
201
+
202
+ # Personal & Private stuff
203
+
204
+ # To authenticate with the API
205
+ # Methodized as it is used also in key_tests
206
+ def auth_query
207
+ "?login=fcoury&token=8f700e0d7747826f3e56ee13651414bd"
208
+ end
209
+
210
+ secure_fakes = {
211
+
212
+ "commits/list/fcoury/rboard/master" => File.join("commits", "fcoury", "rboard", "master"),
213
+
214
+ "repos/show/fcoury" => File.join("repos", "show", "fcoury-private"),
215
+ "repos/show/fcoury/octopi" => File.join("repos", "fcoury", "octopi", "master"),
216
+ "repos/show/fcoury/rboard" => File.join("repos", "fcoury", "rboard", "master"),
217
+
218
+ "user/keys" => File.join("users", "keys"),
219
+ "user/show/fcoury" => File.join("users", "fcoury-private")
220
+ }
221
+
222
+ secure_fakes.each do |key, value|
223
+ FakeWeb.register_uri(:get, "https://#{yaml_api}/" + key + auth_query, :response => stub_file(value))
224
+ end
225
+
226
+ secure_post_fakes = {
227
+ "user/key/add" => File.join("users", "key-added"),
228
+ "user/key/remove" => File.join("users", "key-removed"),
229
+ "user/follow/rails" => File.join("users", "follow-rails"),
230
+ "user/unfollow/rails" => File.join("users", "unfollow-rails"),
231
+ "repos/create" => File.join("repos", "fcoury", "octopus", "main"),
232
+ "repos/delete/octopi" => File.join("repos", "fcoury", "octopi", "delete-token")
233
+ }
234
+
235
+ secure_post_fakes.each do |key, value|
236
+ FakeWeb.register_uri(:post, "https://#{yaml_api}/" + key + auth_query, :response => stub_file(value))
237
+ end
238
+
239
+
240
+ # And the plain fakes
241
+ FakeWeb.register_uri(:get, "https://#{plain_api}/blob/show/fcoury/octopi/#{sha}",
242
+ :response => stub_file(File.join("blob", "fcoury", "octopi", "plain", sha)))
243
+
244
+
245
+ FakeWeb.register_uri(:get, "https://github.com/fcoury/octopi/comments.atom", :response => stub_file("comments", "fcoury", "octopi", "comments.atom"))
246
+ end
247
+
248
+
249
+ class Test::Unit::TestCase
250
+
251
+ end
data/test/user_test.rb ADDED
@@ -0,0 +1,97 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class UserTest < Test::Unit::TestCase
4
+ include Octopi
5
+
6
+ def setup
7
+ fake_everything
8
+ @user = User.find("fcoury")
9
+ end
10
+
11
+ should "be able to find a user" do
12
+ assert_not_nil User.find("fcoury")
13
+ end
14
+
15
+ should "not be able to find a user that doesn't exist" do
16
+ exception = assert_raise NotFound do
17
+ User.find("i-am-most-probably-a-user-that-does-not-exist")
18
+ end
19
+
20
+ assert_equal "The User you were looking for could not be found, or is private.", exception.message
21
+ end
22
+
23
+ should "be able to look for a user, using find_all" do
24
+ users = User.find_all("radar")
25
+ assert_not_nil users
26
+ end
27
+
28
+ should "be able to search for a user" do
29
+ users = User.search("radar")
30
+ assert_not_nil users
31
+ end
32
+
33
+ should "be able to find a user by email" do
34
+ user = User.find_by_email("test@example.com")
35
+ assert_not_nil user
36
+ end
37
+
38
+ context "authenticated" do
39
+ should "return all user information" do
40
+ authenticated do
41
+ user = Api.api.user
42
+ assert_not_nil user
43
+ fields = [:company, :name, :following_count, :blog, :public_repo_count,
44
+ :public_gist_count, :id, :login, :followers_count, :created_at,
45
+ :email, :location, :disk_usage, :private_gist_count, :plan,
46
+ :owned_private_repo_count, :total_private_repo_count]
47
+ fields.each do |f|
48
+ assert_not_nil user.send(f)
49
+ end
50
+
51
+ plan_fields = [:name, :collaborators, :space, :private_repos]
52
+ plan_fields.each do |f|
53
+ assert_not_nil user.plan.send(f)
54
+ end
55
+ end
56
+ end
57
+
58
+ context "return a list of followers" do
59
+
60
+ should "in string format" do
61
+ users = @user.followers
62
+ assert_not_nil users
63
+ assert users.first.is_a?(String)
64
+ end
65
+
66
+ should "in object format" do
67
+ users = @user.followers!
68
+ assert_not_nil users
69
+ assert users.first.is_a?(User)
70
+ end
71
+ end
72
+
73
+ context "return a list of people who they are following" do
74
+ should "in string format" do
75
+ users = @user.following
76
+ assert_not_nil users
77
+ assert users.first.is_a?(String)
78
+ end
79
+
80
+ should "in object format" do
81
+ users = @user.following!
82
+ assert_not_nil users
83
+ assert users.first.is_a?(User)
84
+ end
85
+ end
86
+
87
+ context "return a list of watched repositories" do
88
+ should "in an array" do
89
+ @user = User.find("radar")
90
+ repos = @user.watching
91
+ assert_not_nil repos
92
+ assert repos.first.is_a?(Repository)
93
+ end
94
+ end
95
+
96
+ end
97
+ end