koala 1.0.0.beta2.1 → 1.0.0.rc

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. data/.gitignore +3 -0
  2. data/CHANGELOG +6 -1
  3. data/Gemfile +3 -0
  4. data/Rakefile +13 -14
  5. data/koala.gemspec +35 -20
  6. data/lib/koala.rb +8 -17
  7. data/lib/koala/graph_api.rb +2 -2
  8. data/lib/koala/http_services.rb +32 -27
  9. data/lib/koala/test_users.rb +4 -4
  10. data/lib/koala/uploadable_io.rb +1 -1
  11. data/spec/cases/api_base_spec.rb +101 -0
  12. data/spec/cases/graph_and_rest_api_spec.rb +31 -0
  13. data/spec/cases/graph_api_spec.rb +25 -0
  14. data/spec/{koala/http_services/http_service_tests.rb → cases/http_services/http_service_spec.rb} +8 -5
  15. data/spec/cases/http_services/net_http_service_spec.rb +350 -0
  16. data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
  17. data/spec/cases/oauth_spec.rb +374 -0
  18. data/spec/cases/realtime_updates_spec.rb +184 -0
  19. data/spec/cases/rest_api_spec.rb +25 -0
  20. data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +34 -29
  21. data/spec/cases/uploadable_io_spec.rb +151 -0
  22. data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
  23. data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +5 -5
  24. data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +311 -311
  25. data/spec/spec_helper.rb +18 -0
  26. data/spec/support/graph_api_shared_examples.rb +424 -0
  27. data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
  28. data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -94
  29. data/spec/{koala/rest_api/rest_api_tests.rb → support/rest_api_shared_examples.rb} +43 -0
  30. data/spec/support/setup_mocks_or_live.rb +52 -0
  31. data/spec/support/uploadable_io_shared_examples.rb +76 -0
  32. metadata +109 -53
  33. data/init.rb +0 -2
  34. data/spec/koala/api_base_tests.rb +0 -102
  35. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -14
  36. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
  37. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -65
  38. data/spec/koala/graph_api/graph_api_tests.rb +0 -85
  39. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -194
  40. data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
  41. data/spec/koala/http_services/net_http_service_tests.rb +0 -339
  42. data/spec/koala/http_services/typhoeus_service_tests.rb +0 -162
  43. data/spec/koala/oauth/oauth_tests.rb +0 -372
  44. data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
  45. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
  46. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
  47. data/spec/koala/uploadable_io/uploadable_io_tests.rb +0 -246
  48. data/spec/koala_spec.rb +0 -18
  49. data/spec/koala_spec_helper.rb +0 -74
  50. data/spec/koala_spec_without_mocks.rb +0 -19
@@ -1,25 +0,0 @@
1
- shared_examples_for "Koala RestAPI without an access token" do
2
- # FQL_QUERY
3
- describe "when making a FQL request" do
4
- it "should be able to access public information via FQL" do
5
- @result = @api.fql_query("select first_name from user where uid = 216743")
6
- @result.size.should == 1
7
- @result.first["first_name"].should == "Chris"
8
- end
9
-
10
- it "should not be able to access protected information via FQL" do
11
- lambda { @api.fql_query("select read_stream from permissions where uid = 216743") }.should raise_error(Koala::Facebook::APIError)
12
- end
13
- end
14
- end
15
-
16
- class FacebookRestAPINoAccessTokenTest < Test::Unit::TestCase
17
- describe "Koala RestAPI without an access token" do
18
- before :each do
19
- @api = Koala::Facebook::RestAPI.new
20
- end
21
-
22
- it_should_behave_like "Koala RestAPI"
23
- it_should_behave_like "Koala RestAPI without an access token"
24
- end
25
- end
@@ -1,38 +0,0 @@
1
- shared_examples_for "Koala RestAPI with an access token" do
2
- # FQL
3
- it "should be able to access public information via FQL" do
4
- result = @api.fql_query('select first_name from user where uid = 216743')
5
- result.size.should == 1
6
- result.first['first_name'].should == 'Chris'
7
- end
8
-
9
- it "should be able to access protected information via FQL" do
10
- # Tests agains the permissions fql table
11
-
12
- # get the current user's ID
13
- # we're sneakily using the Graph API, which should be okay since it has its own tests
14
- g = Koala::Facebook::GraphAPI.new(@token)
15
- id = g.get_object("me", :fields => "id")["id"]
16
-
17
- # now send a query about your permissions
18
- result = @api.fql_query("select read_stream from permissions where uid = #{id}")
19
-
20
- result.size.should == 1
21
- # we assume that you have read_stream permissions, so we can test against that
22
- # (should we keep this?)
23
- result.first["read_stream"].should == 1
24
- end
25
- end
26
-
27
- class FacebookRestAPIWithAccessTokenTests < Test::Unit::TestCase
28
- describe "Koala RestAPI with an access token" do
29
- include LiveTestingDataHelper
30
-
31
- before :each do
32
- @api = Koala::Facebook::RestAPI.new(@token)
33
- end
34
-
35
- it_should_behave_like "Koala RestAPI"
36
- it_should_behave_like "Koala RestAPI with an access token"
37
- end
38
- end
@@ -1,246 +0,0 @@
1
- # fake MIME::Types
2
- module Koala::MIME
3
- module Types
4
- def self.type_for(type)
5
- # this should be faked out in tests
6
- nil
7
- end
8
- end
9
- end
10
-
11
- class UploadableIOTests < Test::Unit::TestCase
12
- include Koala
13
-
14
- VALID_PATH = File.join(File.dirname(__FILE__), "..", "assets", "beach.jpg")
15
-
16
- describe UploadableIO do
17
- shared_examples_for "MIME::Types can't return results" do
18
- {
19
- "jpg" => "image/jpeg",
20
- "jpeg" => "image/jpeg",
21
- "png" => "image/png",
22
- "gif" => "image/gif"
23
- }.each_pair do |extension, mime_type|
24
- it "should properly get content types for #{extension} using basic analysis" do
25
- path = "filename.#{extension}"
26
- if @koala_io_params[0].is_a?(File)
27
- @koala_io_params[0].stub!(:path).and_return(path)
28
- else
29
- @koala_io_params[0] = path
30
- end
31
- UploadableIO.new(*@koala_io_params).content_type.should == mime_type
32
- end
33
-
34
- it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
35
- path = "file.name.#{extension}"
36
- if @koala_io_params[0].is_a?(File)
37
- @koala_io_params[0].stub!(:path).and_return(path)
38
- else
39
- @koala_io_params[0] = path
40
- end
41
- UploadableIO.new(*@koala_io_params).content_type.should == mime_type
42
- end
43
- end
44
-
45
- describe "if the MIME type can't be determined" do
46
- before :each do
47
- path = "badfile.badextension"
48
- if @koala_io_params[0].is_a?(File)
49
- @koala_io_params[0].stub!(:path).and_return(path)
50
- else
51
- @koala_io_params[0] = path
52
- end
53
- end
54
-
55
- it "should throw an exception if the MIME type can't be determined and the HTTP service requires content type" do
56
- Koala.stub!(:multipart_requires_content_type?).and_return(true)
57
- lambda { UploadableIO.new(*@koala_io_params) }.should raise_exception(KoalaError)
58
- end
59
-
60
- it "should just have @content_type == nil if the HTTP service doesn't require content type" do
61
- Koala.stub!(:multipart_requires_content_type?).and_return(false)
62
- UploadableIO.new(*@koala_io_params).content_type.should be_nil
63
- end
64
- end
65
- end
66
-
67
- shared_examples_for "determining a mime type" do
68
- describe "if MIME::Types is available" do
69
- it "should return an UploadIO with MIME::Types-determined type if the type exists" do
70
- type_result = ["type"]
71
- Koala::MIME::Types.stub(:type_for).and_return(type_result)
72
- UploadableIO.new(*@koala_io_params).content_type.should == type_result.first
73
- end
74
- end
75
-
76
- describe "if MIME::Types is unavailable" do
77
- before :each do
78
- # fake that MIME::Types doesn't exist
79
- Koala::MIME::Types.stub(:type_for).and_raise(NameError)
80
- end
81
- it_should_behave_like "MIME::Types can't return results"
82
- end
83
-
84
- describe "if MIME::Types can't find the result" do
85
- before :each do
86
- # fake that MIME::Types doesn't exist
87
- Koala::MIME::Types.stub(:type_for).and_return([])
88
- end
89
-
90
- it_should_behave_like "MIME::Types can't return results"
91
- end
92
- end
93
-
94
- describe "the constructor" do
95
- describe "when given a file path" do
96
- before(:each) do
97
- @koala_io_params = [
98
- File.open(VALID_PATH)
99
- ]
100
- end
101
-
102
- describe "and a content type" do
103
- before :each do
104
- @koala_io_params.concat([stub("image/jpg")])
105
- end
106
-
107
- it "should return an UploadIO with the same file path" do
108
- stub_path = @koala_io_params[0] = "/stub/path/to/file"
109
- UploadableIO.new(*@koala_io_params).io_or_path.should == stub_path
110
- end
111
-
112
- it "should return an UploadIO with the same content type" do
113
- stub_type = @koala_io_params[1] = stub('Content Type')
114
- UploadableIO.new(*@koala_io_params).content_type.should == stub_type
115
- end
116
- end
117
-
118
- describe "and no content type" do
119
- it_should_behave_like "determining a mime type"
120
- end
121
- end
122
-
123
- describe "when given a File object" do
124
- before(:each) do
125
- @koala_io_params = [
126
- File.open(VALID_PATH)
127
- ]
128
- end
129
-
130
- describe "and a content type" do
131
- before :each do
132
- @koala_io_params.concat(["image/jpg"])
133
- end
134
-
135
- it "should return an UploadIO with the same io" do
136
- UploadableIO.new(*@koala_io_params).io_or_path.should == @koala_io_params[0]
137
- end
138
-
139
- it "should return an UplaodIO with the same content_type" do
140
- content_stub = @koala_io_params[1] = stub('Content Type')
141
- UploadableIO.new(*@koala_io_params).content_type.should == content_stub
142
- end
143
- end
144
-
145
- describe "and no content type" do
146
- it_should_behave_like "determining a mime type"
147
- end
148
- end
149
-
150
- describe "when given a Rails 3 ActionDispatch::Http::UploadedFile" do
151
- before(:each) do
152
- @tempfile = stub('Tempfile', :path => true)
153
- @uploaded_file = stub('ActionDispatch::Http::UploadedFile',
154
- :content_type => true,
155
- :tempfile => @tempfile
156
- )
157
-
158
- @uploaded_file.stub!(:respond_to?).with(:path).and_return(true)
159
- @uploaded_file.stub!(:respond_to?).with(:content_type).and_return(true)
160
- @uploaded_file.stub!(:respond_to?).with(:tempfile).and_return(@tempfile)
161
- @tempfile.stub!(:respond_to?).with(:path).and_return(true)
162
- end
163
-
164
- it "should get the content type via the content_type method" do
165
- expected_content_type = stub('Content Type')
166
- @uploaded_file.should_receive(:content_type).and_return(expected_content_type)
167
- UploadableIO.new(@uploaded_file).content_type.should == expected_content_type
168
- end
169
-
170
- it "should get the path from the tempfile associated with the UploadedFile" do
171
- expected_path = stub('Tempfile')
172
- @tempfile.should_receive(:path).and_return(expected_path)
173
- UploadableIO.new(@uploaded_file).io_or_path.should == expected_path
174
- end
175
- end
176
-
177
- describe "when given a Sinatra file parameter hash" do
178
- before(:each) do
179
- @file_hash = {
180
- :type => "type",
181
- :tempfile => "Tempfile"
182
- }
183
- end
184
-
185
- it "should get the content type from the :type key" do
186
- expected_content_type = stub('Content Type')
187
- @file_hash[:type] = expected_content_type
188
-
189
- uploadable = UploadableIO.new(@file_hash)
190
- uploadable.content_type.should == expected_content_type
191
- end
192
-
193
- it "should get the io_or_path from the :tempfile key" do
194
- expected_file = stub('File')
195
- @file_hash[:tempfile] = expected_file
196
-
197
- uploadable = UploadableIO.new(@file_hash)
198
- uploadable.io_or_path.should == expected_file
199
- end
200
- end
201
-
202
- describe "for files with with recognizable MIME types" do
203
- # what that means is tested below
204
- it "should accept a file object alone" do
205
- params = [
206
- VALID_PATH
207
- ]
208
- lambda { UploadableIO.new(*params) }.should_not raise_exception(KoalaError)
209
- end
210
-
211
- it "should accept a file path alone" do
212
- params = [
213
- VALID_PATH
214
- ]
215
- lambda { UploadableIO.new(*params) }.should_not raise_exception(KoalaError)
216
- end
217
- end
218
- end
219
-
220
- describe "getting an UploadableIO" do
221
- before(:each) do
222
- @upload_io = stub("UploadIO")
223
- UploadIO.stub!(:new).with(anything, anything, anything).and_return(@upload_io)
224
- end
225
-
226
- it "should call the constructor with the content type, file name, and a dummy file name" do
227
- UploadIO.should_receive(:new).with(VALID_PATH, "content/type", anything).and_return(@upload_io)
228
- UploadableIO.new(VALID_PATH, "content/type").to_upload_io.should == @upload_io
229
- end
230
- end
231
-
232
- describe "getting a file" do
233
- it "should return the File if initialized with a file" do
234
- f = File.new(VALID_PATH)
235
- UploadableIO.new(f).to_file.should == f
236
- end
237
-
238
- it "should open up and return a file corresponding to the path if io_or_path is a path" do
239
- path = VALID_PATH
240
- result = stub("File")
241
- File.should_receive(:open).with(path).and_return(result)
242
- UploadableIO.new(path).to_file.should == result
243
- end
244
- end
245
- end # describe UploadableIO
246
- end # class
data/spec/koala_spec.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'koala_spec_helper'
2
- require 'mock_http_service'
3
-
4
- # Runs Koala specs using stubs for HTTP requests
5
- #
6
- # Valid OAuth token and code are not necessary to run these
7
- # specs. Because of this, specs do not fail due to Facebook
8
- # imposed rate-limits or server timeouts.
9
- #
10
- # However as a result they are more brittle since
11
- # we are not testing the latest responses from the Facebook servers.
12
- # Therefore, to be certain all specs pass with the current
13
- # Facebook services, run koala_spec_without_mocks.rb.
14
-
15
-
16
- Koala.http_service = Koala::MockHTTPService
17
-
18
- $testing_data = Koala::MockHTTPService::TEST_DATA
@@ -1,74 +0,0 @@
1
- if defined?(RUBY_VERSION) && RUBY_VERSION =~ /1\.9/
2
- require 'test/unit'
3
- require 'rspec'
4
-
5
- Rspec.configure do |c|
6
- c.mock_with :rspec
7
- end
8
-
9
- else
10
- # Ruby 1.8.x
11
- require 'test/unit'
12
- require 'rubygems'
13
- end
14
-
15
- require 'yaml'
16
-
17
- # load the libraries
18
- require 'koala'
19
-
20
- # load testing data libraries
21
- require 'koala/live_testing_data_helper'
22
-
23
- # API tests
24
- require 'koala/api_base_tests'
25
-
26
- require 'koala/graph_api/graph_api_tests'
27
- require 'koala/graph_api/graph_collection_tests'
28
- require 'koala/graph_api/graph_api_no_access_token_tests'
29
- require 'koala/graph_api/graph_api_with_access_token_tests'
30
-
31
- require 'koala/rest_api/rest_api_tests'
32
- require 'koala/rest_api/rest_api_no_access_token_tests'
33
- require 'koala/rest_api/rest_api_with_access_token_tests'
34
-
35
- require 'koala/graph_and_rest_api/graph_and_rest_api_no_token_tests'
36
- require 'koala/graph_and_rest_api/graph_and_rest_api_with_token_tests'
37
-
38
- # OAuth tests
39
- require 'koala/oauth/oauth_tests'
40
-
41
- # Subscriptions tests
42
- require 'koala/realtime_updates/realtime_updates_tests'
43
-
44
- # Test users tests
45
- require 'koala/test_users/test_users_tests'
46
-
47
- # KoalaIO tests
48
- require 'koala/uploadable_io/uploadable_io_tests'
49
-
50
- # Services tests
51
- require 'koala/http_services/http_service_tests'
52
- require 'koala/http_services/net_http_service_tests'
53
- begin
54
- require 'koala/http_services/typhoeus_service_tests'
55
- rescue LoadError
56
- puts "Typhoeus tests will not be run because Typhoeus is not installed."
57
- end
58
-
59
- module KoalaTest
60
- def self.validate_user_info(token)
61
- print "Validating permissions for live testing..."
62
- # make sure we have the necessary permissions
63
- api = Koala::Facebook::GraphAndRestAPI.new(token)
64
- uid = api.get_object("me")["id"]
65
- perms = api.fql_query("select read_stream, publish_stream, user_photos from permissions where uid = #{uid}")[0]
66
- perms.each_pair do |perm, value|
67
- unless value == 1
68
- puts "failed!\n" # put a new line after the print above
69
- raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions. You have: #{perms.inspect}"
70
- end
71
- end
72
- puts "done!"
73
- end
74
- end
@@ -1,19 +0,0 @@
1
- require 'koala_spec_helper'
2
-
3
- # Runs Koala specs through the Facebook servers
4
- #
5
- # Note that you need a valid OAuth token and code for these
6
- # specs to run. See facebook_data.yml for more information.
7
-
8
- # load testing data (see note in readme.md)
9
- $testing_data = YAML.load_file(File.join(File.dirname(__FILE__), 'facebook_data.yml')) rescue {}
10
-
11
- unless $testing_data["oauth_token"]
12
- puts "Access token tests will fail until you store a valid token in facebook_data.yml"
13
- end
14
-
15
- unless $testing_data["oauth_test_data"] && $testing_data["oauth_test_data"]["code"] && $testing_data["oauth_test_data"]["secret"]
16
- puts "OAuth code tests will fail until you store valid data for the user's OAuth code and the app secret in facebook_data.yml"
17
- end
18
-
19
- KoalaTest.validate_user_info $testing_data["oauth_token"]