koala 1.0.0.beta → 1.0.0

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 (52) hide show
  1. data/.gitignore +3 -0
  2. data/CHANGELOG +17 -3
  3. data/Gemfile +3 -0
  4. data/LICENSE +1 -1
  5. data/Manifest +5 -2
  6. data/Rakefile +13 -14
  7. data/koala.gemspec +35 -20
  8. data/lib/koala/graph_api.rb +183 -131
  9. data/lib/koala/http_services.rb +46 -55
  10. data/lib/koala/test_users.rb +21 -8
  11. data/lib/koala/uploadable_io.rb +115 -0
  12. data/lib/koala.rb +52 -84
  13. data/readme.md +19 -6
  14. data/spec/cases/api_base_spec.rb +101 -0
  15. data/spec/cases/graph_and_rest_api_spec.rb +31 -0
  16. data/spec/cases/graph_api_spec.rb +25 -0
  17. data/spec/cases/http_services/http_service_spec.rb +54 -0
  18. data/spec/cases/http_services/net_http_service_spec.rb +350 -0
  19. data/spec/cases/http_services/typhoeus_service_spec.rb +144 -0
  20. data/spec/cases/oauth_spec.rb +409 -0
  21. data/spec/cases/realtime_updates_spec.rb +184 -0
  22. data/spec/cases/rest_api_spec.rb +25 -0
  23. data/spec/{koala/test_users/test_users_tests.rb → cases/test_users_spec.rb} +46 -33
  24. data/spec/cases/uploadable_io_spec.rb +151 -0
  25. data/spec/{facebook_data.yml → fixtures/facebook_data.yml} +12 -14
  26. data/spec/{mock_facebook_responses.yml → fixtures/mock_facebook_responses.yml} +313 -306
  27. data/spec/spec_helper.rb +18 -0
  28. data/spec/support/graph_api_shared_examples.rb +424 -0
  29. data/spec/{koala → support}/live_testing_data_helper.rb +39 -42
  30. data/spec/{mock_http_service.rb → support/mock_http_service.rb} +94 -95
  31. data/spec/{koala/rest_api/rest_api_tests.rb → support/rest_api_shared_examples.rb} +43 -0
  32. data/spec/support/setup_mocks_or_live.rb +52 -0
  33. data/spec/support/uploadable_io_shared_examples.rb +76 -0
  34. metadata +107 -48
  35. data/init.rb +0 -2
  36. data/spec/koala/api_base_tests.rb +0 -102
  37. data/spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb +0 -14
  38. data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +0 -16
  39. data/spec/koala/graph_api/graph_api_no_access_token_tests.rb +0 -63
  40. data/spec/koala/graph_api/graph_api_tests.rb +0 -86
  41. data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +0 -154
  42. data/spec/koala/graph_api/graph_collection_tests.rb +0 -104
  43. data/spec/koala/net_http_service_tests.rb +0 -430
  44. data/spec/koala/oauth/oauth_tests.rb +0 -409
  45. data/spec/koala/realtime_updates/realtime_updates_tests.rb +0 -187
  46. data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +0 -25
  47. data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +0 -38
  48. data/spec/koala/typhoeus_service_tests.rb +0 -156
  49. data/spec/koala_spec.rb +0 -18
  50. data/spec/koala_spec_helper.rb +0 -70
  51. data/spec/koala_spec_without_mocks.rb +0 -19
  52. /data/spec/{koala/assets → fixtures}/beach.jpg +0 -0
@@ -1,156 +0,0 @@
1
- require 'koala/http_services'
2
- class TyphoeusServiceTests < Test::Unit::TestCase
3
- module Bear
4
- include Koala::TyphoeusService
5
- end
6
-
7
- describe "TyphoeusService module holder class Bear" do
8
- before :each do
9
- # reset the always_use_ssl parameter
10
- Bear.always_use_ssl = nil
11
- end
12
-
13
- it "should define a make_request static module method" do
14
- Bear.respond_to?(:make_request).should be_true
15
- end
16
-
17
- it "should include the Koala::HTTPService module defining common features" do
18
- Bear.included_modules.include?(Koala::HTTPService).should be_true
19
- end
20
-
21
- describe "when making a request" do
22
- before(:each) do
23
- # Setup stubs for make_request to execute without exceptions
24
- @mock_body = stub('Typhoeus response body')
25
- @mock_headers_hash = stub({:value => "headers hash"})
26
- @mock_http_response = stub(Typhoeus::Response, :code => 1, :headers_hash => @mock_headers_hash, :body => @mock_body)
27
-
28
- # Typhoeus is an included module, so we stub methods on Bear itself
29
- Bear.stub(:post).and_return(@mock_http_response)
30
- Bear.stub(:get).and_return(@mock_http_response)
31
- end
32
-
33
- it "should use POST if verb is not GET" do
34
- Bear.should_receive(:post).and_return(@mock_http_response)
35
- Bear.make_request('anything', {}, 'anything')
36
- end
37
-
38
- it "should use GET if that verb is specified" do
39
- Bear.should_receive(:get).and_return(@mock_http_response)
40
- Bear.make_request('anything', {}, 'get')
41
- end
42
-
43
- describe "the connection" do
44
- it "should use SSL if the request has an access token" do
45
- Bear.should_receive(:post).with(/https\:/, anything)
46
-
47
- Bear.make_request('anything', {"access_token" => "123"}, 'anything')
48
- end
49
-
50
- it "should use SSL if always_use_ssl is true, even if there's no token" do
51
- Bear.should_receive(:post).with(/https\:/, anything)
52
-
53
- Bear.always_use_ssl = true
54
- Bear.make_request('anything', {}, 'anything')
55
- end
56
-
57
- it "should use SSL if the :use_ssl option is provided, even if there's no token" do
58
- Bear.should_receive(:post).with(/https\:/, anything)
59
-
60
- Bear.always_use_ssl = true
61
- Bear.make_request('anything', {}, 'anything', :use_ssl => true)
62
- end
63
-
64
- it "should not use SSL if always_use_ssl is false and there's no token" do
65
- Bear.should_receive(:post).with(/http\:/, anything)
66
-
67
- Bear.make_request('anything', {}, 'anything')
68
- end
69
-
70
- it "should use the graph server by default" do
71
- Bear.should_receive(:post).with(Regexp.new(Koala::Facebook::GRAPH_SERVER), anything)
72
-
73
- Bear.make_request('anything', {}, 'anything')
74
- end
75
-
76
- it "should use the REST server if the :rest_api option is true" do
77
- Bear.should_receive(:post).with(Regexp.new(Koala::Facebook::REST_SERVER), anything)
78
-
79
- Bear.make_request('anything', {}, 'anything', :rest_api => true)
80
- end
81
- end
82
-
83
- it "should pass the arguments to Typhoeus under the :params key" do
84
- args = {:a => 2}
85
- Bear.should_receive(:post).with(anything, hash_including(:params => args))
86
-
87
- Bear.make_request('anything', args, "post")
88
- end
89
-
90
- it "should add the method to the arguments if the method isn't get or post" do
91
- method = "telekenesis"
92
- Bear.should_receive(:post).with(anything, hash_including(:params => {:method => method}))
93
-
94
- Bear.make_request('anything', {}, method)
95
- end
96
-
97
- it "should pass :typhoeus_options to Typhoeus if provided" do
98
- t_options = {:a => :b}
99
- Bear.should_receive(:post).with(anything, hash_including(t_options))
100
-
101
- Bear.make_request("anything", {}, "post", :typhoeus_options => t_options)
102
- end
103
-
104
- it "should include the path in the request" do
105
- path = "/a/b/c/1"
106
- Bear.should_receive(:post).with(Regexp.new(path), anything)
107
-
108
- Bear.make_request(path, {}, "post")
109
- end
110
-
111
- describe "the returned value" do
112
- before(:each) do
113
- @response = Bear.make_request('anything', {}, 'anything')
114
- end
115
-
116
- it "should return a Koala::Response object" do
117
- @response.class.should == Koala::Response
118
- end
119
-
120
- it "should return a Koala::Response with the right status" do
121
- @response.status.should == @mock_http_response.code
122
- end
123
-
124
- it "should reutrn a Koala::Response with the right body" do
125
- @response.body.should == @mock_body
126
- end
127
-
128
- it "should return a Koala::Response with the Net::HTTPResponse object as headers" do
129
- @response.headers.should == @mock_headers_hash
130
- end
131
- end # describe return value
132
- end
133
-
134
- describe "with file upload" do
135
- it "should include an interface to NetHTTPService called NetHTTPInterface" do
136
- # we should be able to access it
137
- lambda { Koala::TyphoeusService::NetHTTPInterface }.should_not raise_exception(Exception)
138
- Koala::TyphoeusService::NetHTTPInterface.included_modules.include?(Koala::NetHTTPService).should be_true
139
- end
140
-
141
- it "should call the NetHTTPInterface if multipart is required" do
142
- method = "any_method"
143
- args = {}
144
- verb = "get"
145
- options = {}
146
-
147
- Bear.stub(:params_require_multipart?).and_return(true)
148
- Koala::TyphoeusService::NetHTTPInterface.should_receive(:make_request).with(method, args, verb, options)
149
-
150
- Bear.make_request(method, args, verb, options)
151
- end
152
-
153
- # for live tests, run the Graph API tests with Typhoues, which will run file uploads
154
- end
155
- end
156
- end
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,70 +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
-
14
- require 'spec/test/unit'
15
- end
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
- # Services tests
48
- require 'koala/net_http_service_tests'
49
- begin
50
- require 'koala/typhoeus_service_tests'
51
- rescue LoadError
52
- puts "Typhoeus tests will not be run because Typhoeus is not installed."
53
- end
54
-
55
- module KoalaTest
56
- def self.validate_user_info(token)
57
- print "Validating permissions for live testing..."
58
- # make sure we have the necessary permissions
59
- api = Koala::Facebook::GraphAndRestAPI.new(token)
60
- uid = api.get_object("me")["id"]
61
- perms = api.fql_query("select read_stream, publish_stream, user_photos from permissions where uid = #{uid}")[0]
62
- perms.each_pair do |perm, value|
63
- unless value == 1
64
- puts "failed!\n" # put a new line after the print above
65
- raise ArgumentError, "Your access token must have the read_stream, publish_stream, and user_photos permissions. You have: #{perms.inspect}"
66
- end
67
- end
68
- puts "done!"
69
- end
70
- 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"]
File without changes