koala 1.7.0rc1 → 1.8.0rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4f55beaaa005d6ac4b23f447fa6b024feb6380c
4
+ data.tar.gz: 323bc58cb6614e800eb394f06647cdc989c432a6
5
+ SHA512:
6
+ metadata.gz: d047fbf1bd2d466b9abafb2d4e28e2b8bf748744c36d9f84a491faf8c8c91e35071ade91583d57ee1ec9a86324d7a336de33f2ba151dec5f7e8867e27e9dfdc6
7
+ data.tar.gz: 2fd83e7103a13f39b98f4f09586b373e8b38059cab57edaba0067600bd9e380c4a1f8db4f748330d6be0be74a4f38d30be1b2e584d929b55df715e96e039440b
data/.travis.yml CHANGED
@@ -1,10 +1,11 @@
1
1
  rvm:
2
- - 1.8.7
3
- - 1.9.2
2
+ # MRI
4
3
  - 1.9.3
5
4
  - 2.0.0
6
- - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
5
+ - ruby-head
6
+ # rbx
9
7
  - rbx-19mode
10
- - ree
8
+ - rbx-2.1.1
9
+ # jruby
10
+ - jruby-19mode
11
+ - jruby-head
data/changelog.md CHANGED
@@ -1,3 +1,35 @@
1
+ v1.8.0rc1
2
+ =========
3
+
4
+ NOTE: Due to updates to underlying gems, new versions of Koala no longer work
5
+ with Ruby 1.8.x, rbx/jruby in 1.8 mode, and Ruby 1.9.2. Earlier versions will,
6
+ of course, continue to work, since the underlying Facebook API remains the
7
+ same.
8
+
9
+ If you, tragically, find yourself stuck using these old versions, you may be
10
+ able to get Koala to work by adding proper constraints to your Gemfile. Good
11
+ luck.
12
+
13
+ New methods:
14
+ * OAuth#generate_client_code lets you get long-lived user tokens for client apps (thanks, binarygeek!)
15
+
16
+ Updated methods:
17
+ * API#new now takes an optional access_token, which will be used to generate
18
+ the appsecret_proof parameters ([thanks,
19
+ nchelluri!](https://github.com/arsduo/koala/pull/323))
20
+ * GraphCollection#next_page and #previous_page can now take additional
21
+ parameters ([thanks, gacha!](https://github.com/arsduo/koala/pull/330))
22
+
23
+ Internal Improvements:
24
+ * FIXED: TestUser#delete_all will avoid infinite loops if the user hashes
25
+ change ([thanks, chunkerchunker!](https://github.com/arsduo/koala/pull/331))
26
+ * CHANGED: Koala now properly uploads Tempfiles like Files, detecting mime type (thanks, ys!)
27
+ * CHANGED: Koala now only passes valid Faraday options, improving compatibility with 0.9 (thanks, lsimoneau!)
28
+ * FIXED: RealtimeUpdates#validate_update now raise a proper error if secret is missing (thanks, theosp!)
29
+
30
+ Testing improvements:
31
+ * Fixed RSpec deprecations (thanks, sanemat!)
32
+
1
33
  v1.7
2
34
  ====
3
35
 
@@ -41,18 +41,26 @@ module Koala
41
41
 
42
42
  # Retrieve the next page of results.
43
43
  #
44
+ # @param [Hash] extra_params Some optional extra parameters for paging. For supported parameters see https://developers.facebook.com/docs/reference/api/pagination/
45
+ #
46
+ # @example With optional extra params
47
+ # wall = api.get_connections("me", "feed", since: 1379593891)
48
+ # wall.next_page(since: 1379593891)
49
+ #
44
50
  # @return a GraphCollection array of additional results (an empty array if there are no more results)
45
- def next_page
51
+ def next_page(extra_params = {})
46
52
  base, args = next_page_params
47
- base ? @api.get_page([base, args]) : nil
53
+ base ? @api.get_page([base, args.merge(extra_params)]) : nil
48
54
  end
49
55
 
50
56
  # Retrieve the previous page of results.
51
57
  #
58
+ # @param [Hash] extra_params Some optional extra parameters for paging. For supported parameters see https://developers.facebook.com/docs/reference/api/pagination/
59
+ #
52
60
  # @return a GraphCollection array of additional results (an empty array if there are no earlier results)
53
- def previous_page
61
+ def previous_page(extra_params = {})
54
62
  base, args = previous_page_params
55
- base ? @api.get_page([base, args]) : nil
63
+ base ? @api.get_page([base, args.merge(extra_params)]) : nil
56
64
  end
57
65
 
58
66
  # Arguments that can be sent to {Koala::Facebook::API#graph_call} to retrieve the next page of results.
data/lib/koala/errors.rb CHANGED
@@ -7,6 +7,9 @@ module Koala
7
7
  # The OAuth signature is incomplete, invalid, or using an unsupported algorithm
8
8
  class OAuthSignatureError < ::Koala::KoalaError; end
9
9
 
10
+ # Required for realtime updates validation
11
+ class AppSecretNotDefinedError < ::Koala::KoalaError; end
12
+
10
13
  # Facebook responded with an error to an API request. If the exception contains a nil
11
14
  # http_status, then the error was detected before making a call to Facebook. (e.g. missing access token)
12
15
  class APIError < ::Koala::KoalaError
@@ -90,7 +90,7 @@ module Koala
90
90
 
91
91
  # set up our Faraday connection
92
92
  # we have to manually assign params to the URL or the
93
- conn = Faraday.new(server(request_options), request_options, &(faraday_middleware || DEFAULT_MIDDLEWARE))
93
+ conn = Faraday.new(server(request_options), faraday_options(request_options), &(faraday_middleware || DEFAULT_MIDDLEWARE))
94
94
 
95
95
  response = conn.send(verb, path, (verb == "post" ? params : {}))
96
96
 
@@ -216,6 +216,11 @@ module Koala
216
216
 
217
217
  options
218
218
  end
219
+
220
+ def self.faraday_options(options)
221
+ valid_options = [:request, :proxy, :ssl, :builder, :url, :parallel_manager, :params, :headers, :builder_class]
222
+ Hash[ options.select { |key,value| valid_options.include?(key) } ]
223
+ end
219
224
  end
220
225
 
221
226
  # @private
@@ -1,4 +1,5 @@
1
1
  require "net/http/post/multipart"
2
+ require "tempfile"
2
3
 
3
4
  module Koala
4
5
  module HTTPService
@@ -80,7 +81,7 @@ module Koala
80
81
 
81
82
  # takes a file object
82
83
  def self.file_param?(file)
83
- file.kind_of?(File)
84
+ file.kind_of?(File) || file.kind_of?(Tempfile)
84
85
  end
85
86
 
86
87
  def parse_file_object(file, content_type = nil)
@@ -180,7 +181,7 @@ module Koala
180
181
  end
181
182
  end
182
183
  end
183
-
184
+
184
185
  # @private
185
186
  # legacy support for when UploadableIO lived directly under Koala
186
187
  UploadableIO = HTTPService::UploadableIO
data/lib/koala/oauth.rb CHANGED
@@ -132,6 +132,34 @@ module Koala
132
132
  build_url("http://#{Koala.config.dialog_host}/dialog/#{dialog_type}", true, url_options)
133
133
  end
134
134
 
135
+ # Generates a 'client code' from a server side long-lived access token. With the generated
136
+ # code, it can be sent to a client application which can then use it to get a long-lived
137
+ # access token from Facebook. After which the clients can use that access token to make
138
+ # requests to Facebook without having to use the server token, yet the server access token
139
+ # remains valid.
140
+ # See https://developers.facebook.com/docs/facebook-login/access-tokens/#long-via-code
141
+ #
142
+ # @param access_token a user's long lived (server) access token
143
+ #
144
+ # @raise Koala::Facebook::ServerError if Facebook returns a server error (status >= 500)
145
+ # @raise Koala::Facebook::OAuthTokenRequestError if Facebook returns an error response (status >= 400)
146
+ # @raise Koala::Facebook::BadFacebookResponse if Facebook returns a blank response
147
+ # @raise Koala::KoalaError if response does not contain 'code' hash key
148
+ #
149
+ # @return a string of the generated 'code'
150
+ def generate_client_code(access_token)
151
+ response = fetch_token_string({:redirect_uri => @oauth_callback_url, :access_token => access_token}, false, 'client_code')
152
+
153
+ # Facebook returns an empty body in certain error conditions
154
+ if response == ''
155
+ raise BadFacebookResponse.new(200, '', 'generate_client_code received an error: empty response body')
156
+ else
157
+ result = MultiJson.load(response)
158
+ end
159
+
160
+ result.has_key?('code') ? result['code'] : raise(Koala::KoalaError.new("Facebook returned a valid response without the expected 'code' in the body (response = #{response})"))
161
+ end
162
+
135
163
  # access tokens
136
164
 
137
165
  # Fetches an access token, token expiration, and other info from Facebook.
@@ -125,6 +125,10 @@ module Koala
125
125
  # end
126
126
  # end
127
127
  def validate_update(body, headers)
128
+ unless @secret
129
+ raise AppSecretNotDefinedError, "You must init RealtimeUpdates with your app secret in order to validate updates"
130
+ end
131
+
128
132
  if request_signature = headers['X-Hub-Signature'] || headers['HTTP_X_HUB_SIGNATURE'] and
129
133
  signature_parts = request_signature.split("sha1=")
130
134
  request_signature = signature_parts[1]
@@ -2,11 +2,11 @@ require 'koala'
2
2
 
3
3
  module Koala
4
4
  module Facebook
5
-
6
- # Create and manage test users for your application.
7
- # A test user is a user account associated with an app created for the purpose
8
- # of testing the functionality of that app.
9
- # You can use test users for manual or automated testing --
5
+
6
+ # Create and manage test users for your application.
7
+ # A test user is a user account associated with an app created for the purpose
8
+ # of testing the functionality of that app.
9
+ # You can use test users for manual or automated testing --
10
10
  # Koala's live test suite uses test users to verify the library works with Facebook.
11
11
  #
12
12
  # @note the test user API is fairly slow compared to other interfaces
@@ -15,19 +15,19 @@ module Koala
15
15
  # See http://developers.facebook.com/docs/test_users/.
16
16
  class TestUsers
17
17
 
18
- # The application API interface used to communicate with Facebook.
19
- # @return [Koala::Facebook::API]
18
+ # The application API interface used to communicate with Facebook.
19
+ # @return [Koala::Facebook::API]
20
20
  attr_reader :api
21
21
  attr_reader :app_id, :app_access_token, :secret
22
-
23
- # Create a new TestUsers instance.
24
- # If you don't have your app's access token, provide the app's secret and
22
+
23
+ # Create a new TestUsers instance.
24
+ # If you don't have your app's access token, provide the app's secret and
25
25
  # Koala will make a request to Facebook for the appropriate token.
26
- #
26
+ #
27
27
  # @param options initialization options.
28
28
  # @option options :app_id the application's ID.
29
29
  # @option options :app_access_token an application access token, if known.
30
- # @option options :secret the application's secret.
30
+ # @option options :secret the application's secret.
31
31
  #
32
32
  # @raise ArgumentError if the application ID and one of the app access token or the secret are not provided.
33
33
  def initialize(options = {})
@@ -43,11 +43,11 @@ module Koala
43
43
  oauth = Koala::Facebook::OAuth.new(@app_id, @secret)
44
44
  @app_access_token = oauth.get_app_access_token
45
45
  end
46
-
46
+
47
47
  @api = API.new(@app_access_token)
48
48
  end
49
49
 
50
- # Create a new test user.
50
+ # Create a new test user.
51
51
  #
52
52
  # @param installed whether the user has installed your app
53
53
  # @param permissions a comma-separated string or array of permissions the user has granted (if installed)
@@ -83,11 +83,11 @@ module Koala
83
83
  end
84
84
 
85
85
  # Deletes all test users in batches of 50.
86
- #
86
+ #
87
87
  # @note if you have a lot of test users (> 20), this operation can take a long time.
88
88
  #
89
89
  # @param options (see Koala::Facebook::API#api)
90
- #
90
+ #
91
91
  # @return a list of the test users that have been deleted
92
92
  def delete_all(options = {})
93
93
  # ideally we'd save a call by checking next_page_params, but at the time of writing
@@ -96,19 +96,23 @@ module Koala
96
96
  while (test_user_list = list(options)).length > 0
97
97
  # avoid infinite loops if Facebook returns buggy users you can't delete
98
98
  # see http://developers.facebook.com/bugs/223629371047398
99
- break if test_user_list == previous_list
99
+ # since the hashes may change across calls, even if the IDs don't,
100
+ # we just compare the IDs.
101
+ test_user_ids = test_user_list.map {|u| u['id']}
102
+ previous_user_ids = (previous_list || []).map {|u| u['id']}
103
+ break if (test_user_ids - previous_user_ids).empty?
100
104
 
101
- test_user_list.each_slice(50) do |users|
105
+ test_user_list.each_slice(50) do |users|
102
106
  self.api.batch(options) {|batch_api| users.each {|u| batch_api.delete_object(u["id"]) }}
103
107
  end
104
-
108
+
105
109
  previous_list = test_user_list
106
110
  end
107
111
  end
108
112
 
109
113
  # Updates a test user's attributes.
110
114
  #
111
- # @note currently, only name and password can be changed;
115
+ # @note currently, only name and password can be changed;
112
116
  # see {http://developers.facebook.com/docs/test_users/ the Facebook documentation}.
113
117
  #
114
118
  # @param test_user the user to update; can be either a Facebook ID or the hash returned by {#create}
@@ -151,7 +155,7 @@ module Koala
151
155
 
152
156
  # Create a network of test users, all of whom are friends and have the same permissions.
153
157
  #
154
- # @note this call slows down dramatically the more users you create
158
+ # @note this call slows down dramatically the more users you create
155
159
  # (test user calls are slow, and more users => more 1-on-1 connections to be made).
156
160
  # Use carefully.
157
161
  #
@@ -174,11 +178,11 @@ module Koala
174
178
  end
175
179
  return users
176
180
  end
177
-
181
+
178
182
  # The Facebook test users management URL for your application.
179
183
  def test_user_accounts_path
180
184
  @test_user_accounts_path ||= "/#{@app_id}/accounts/test-users"
181
- end
185
+ end
182
186
 
183
187
  # @private
184
188
  # Legacy accessor for before GraphAPI was unified into API
data/lib/koala/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Koala
2
- VERSION = "1.7.0rc1"
2
+ VERSION = "1.8.0rc1"
3
3
  end
data/readme.md CHANGED
@@ -11,20 +11,20 @@ Koala
11
11
 
12
12
  * Lightweight: Koala should be as light and simple as Facebook’s own libraries, providing API accessors and returning simple JSON.
13
13
  * Fast: Koala should, out of the box, be quick. Out of the box, we use Facebook's faster read-only servers when possible and if available, the Typhoeus gem to make snappy Facebook requests. Of course, that brings us to our next topic:
14
- * Flexible: Koala should be useful to everyone, regardless of their current configuration. We support JRuby, Rubinius, and REE as well as vanilla Ruby (1.8.7, 1.9.2, and 1.9.3), and use the Faraday library to provide complete flexibility over how HTTP requests are made.
14
+ * Flexible: Koala should be useful to everyone, regardless of their current configuration. We support JRuby, Rubinius, and REE as well as vanilla Ruby (1.8.7, 1.9.2, 1.9.3, and 2.0.0), and use the Faraday library to provide complete flexibility over how HTTP requests are made.
15
15
  * Tested: Koala should have complete test coverage, so you can rely on it. Our test coverage is complete and can be run against either mocked responses or the live Facebook servers; we're also on [Travis CI](http://travis-ci.org/arsduo/koala/).
16
16
 
17
17
  Installation
18
18
  ---
19
19
 
20
- Easy:
21
- ```bash
22
- [sudo|rvm] gem install koala
20
+ In Bundler:
21
+ ```ruby
22
+ gem "koala", "~> 1.8.0rc1"
23
23
  ```
24
24
 
25
- Or in Bundler:
26
- ```ruby
27
- gem "koala"
25
+ Otherwise:
26
+ ```bash
27
+ [sudo|rvm] gem install koala --pre
28
28
  ```
29
29
 
30
30
  Graph API
@@ -108,8 +108,6 @@ Fortunately, Koala supports the REST API using the very same interface; to use t
108
108
 
109
109
  Of course, you can use the Graph API methods on the same object -- the power of two APIs right in the palm of your hand.
110
110
  ```ruby
111
- @api = Koala::Facebook::API.new(oauth_access_token)
112
-
113
111
  @api = Koala::Facebook::API.new(oauth_access_token)
114
112
  fql = @api.fql_query(my_fql_query)
115
113
  @api.put_wall_post(process_result(fql))
@@ -227,7 +225,7 @@ See examples, ask questions
227
225
  -----
228
226
  Some resources to help you as you play with Koala and the Graph API:
229
227
 
230
- * Complete Koala documentation <a href="http://wiki.github.com/arsduo/koala/">on the wiki</a>
228
+ * Complete Koala documentation <a href="https://github.com/arsduo/koala/wiki">on the wiki</a>
231
229
  * The <a href="http://groups.google.com/group/koala-users">Koala users group</a> on Google Groups, the place for your Koala and API questions
232
230
  * Facebook's <a href="http://developers.facebook.com/tools/explorer/">Graph API Explorer</a>, where you can play with the Graph API in your browser
233
231
  * The Koala-powered <a href="http://oauth.twoalex.com" target="_blank">OAuth Playground</a>, where you can easily generate OAuth access tokens and any other data needed to test out the APIs or OAuth
@@ -39,8 +39,8 @@ describe "Koala::Facebook::API" do
39
39
  it "gets the attribute of a Koala::HTTPService::Response given by the http_component parameter" do
40
40
  http_component = :method_name
41
41
 
42
- response = mock('Mock KoalaResponse', :body => '', :status => 200)
43
- result = stub("result")
42
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
43
+ result = double("result")
44
44
  response.stub(http_component).and_return(result)
45
45
  Koala.stub(:make_request).and_return(response)
46
46
 
@@ -49,7 +49,7 @@ describe "Koala::Facebook::API" do
49
49
 
50
50
  it "returns the entire response if http_component => :response" do
51
51
  http_component = :response
52
- response = mock('Mock KoalaResponse', :body => '', :status => 200)
52
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
53
53
  Koala.stub(:make_request).and_return(response)
54
54
  @service.api('anything', {}, 'get', :http_component => http_component).should == response
55
55
  end
@@ -57,7 +57,7 @@ describe "Koala::Facebook::API" do
57
57
  it "turns arrays of non-enumerables into comma-separated arguments" do
58
58
  args = [12345, {:foo => [1, 2, "3", :four]}]
59
59
  expected = ["/12345", {:foo => "1,2,3,four"}, "get", {}]
60
- response = mock('Mock KoalaResponse', :body => '', :status => 200)
60
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
61
61
  Koala.should_receive(:make_request).with(*expected).and_return(response)
62
62
  @service.api(*args)
63
63
  end
@@ -69,16 +69,16 @@ describe "Koala::Facebook::API" do
69
69
  # (if appropriate behavior is defined)
70
70
  # or raise an exception
71
71
  expected = ["/12345", params, "get", {}]
72
- response = mock('Mock KoalaResponse', :body => '', :status => 200)
72
+ response = double('Mock KoalaResponse', :body => '', :status => 200)
73
73
  Koala.should_receive(:make_request).with(*expected).and_return(response)
74
74
  @service.api(*args)
75
75
  end
76
76
 
77
77
  it "returns the body of the request as JSON if no http_component is given" do
78
- response = stub('response', :body => 'body', :status => 200)
78
+ response = double('response', :body => 'body', :status => 200)
79
79
  Koala.stub(:make_request).and_return(response)
80
80
 
81
- json_body = mock('JSON body')
81
+ json_body = double('JSON body')
82
82
  MultiJson.stub(:load).and_return([json_body])
83
83
 
84
84
  @service.api('anything').should == json_body
@@ -88,7 +88,7 @@ describe "Koala::Facebook::API" do
88
88
  response = Koala::HTTPService::Response.new(200, '{}', {})
89
89
  Koala.stub(:make_request).and_return(response)
90
90
 
91
- yield_test = mock('Yield Tester')
91
+ yield_test = double('Yield Tester')
92
92
  yield_test.should_receive(:pass)
93
93
 
94
94
  @service.api('anything', {}, "get") do |arg|
@@ -52,8 +52,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
52
52
 
53
53
  describe "when supplied binary files" do
54
54
  before :each do
55
- @binary = stub("Binary file")
56
- @uploadable_io = stub("UploadableIO 1")
55
+ @binary = double("Binary file")
56
+ @uploadable_io = double("UploadableIO 1")
57
57
 
58
58
  @batch_queue = []
59
59
  Koala::Facebook::GraphAPI.stub(:batch_calls).and_return(@batch_queue)
@@ -237,10 +237,10 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
237
237
 
238
238
  describe "with binary files" do
239
239
  before :each do
240
- @binary = stub("Binary file")
240
+ @binary = double("Binary file")
241
241
  Koala::UploadableIO.stub(:binary_content?).and_return(false)
242
242
  Koala::UploadableIO.stub(:binary_content?).with(@binary).and_return(true)
243
- @uploadable_io = stub("UploadableIO")
243
+ @uploadable_io = double("UploadableIO")
244
244
  Koala::UploadableIO.stub(:new).with(@binary).and_return(@uploadable_io)
245
245
  @uploadable_io.stub(:is_a?).with(Koala::UploadableIO).and_return(true)
246
246
 
@@ -317,8 +317,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
317
317
  # we test above to ensure that files are properly assimilated into the BatchOperation instance
318
318
  # right now, we want to make sure that batch_api handles them properly
319
319
  @key = "file0_0"
320
- @uploadable_io = stub("UploadableIO")
321
- batch_op = stub("Koala Batch Operation", :files => {@key => @uploadable_io}, :to_batch_params => {}, :access_token => "foo")
320
+ @uploadable_io = double("UploadableIO")
321
+ batch_op = double("Koala Batch Operation", :files => {@key => @uploadable_io}, :to_batch_params => {}, :access_token => "foo")
322
322
  Koala::Facebook::GraphBatchAPI::BatchOperation.stub(:new).and_return(batch_op)
323
323
 
324
324
  Koala.should_receive(:make_request).with(anything, hash_including(@key => @uploadable_io), anything, anything).and_return(@fake_response)
@@ -531,7 +531,7 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
531
531
 
532
532
  # The alternate token is returned with the next page parameters
533
533
  # The GraphCollection should receive a request for the next_page_params during paging
534
- insights.should_receive(:next_page_params).and_return([stub("base"), @other_access_token_args.dup])
534
+ insights.should_receive(:next_page_params).and_return([double("base"), @other_access_token_args.dup])
535
535
 
536
536
  # The alternate access token should pass through to making the request
537
537
  # Koala should receive a request during paging using the alternate token
@@ -576,8 +576,8 @@ describe "Koala::Facebook::GraphAPI in batch mode" do
576
576
  end
577
577
 
578
578
  describe 'with post-processing callback' do
579
- let(:me_result) { stub("me result") }
580
- let(:friends_result) { [stub("friends result")] }
579
+ let(:me_result) { double("me result") }
580
+ let(:friends_result) { [double("friends result")] }
581
581
 
582
582
  let(:me_callback) { lambda {|arg| {"result" => me_result, "args" => arg} } }
583
583
  let(:friends_callback) { lambda {|arg| {"result" => friends_result, "args" => arg} } }
@@ -10,21 +10,21 @@ describe 'Koala::Facebook::GraphAPIMethods' do
10
10
  end
11
11
 
12
12
  describe 'post-processing for' do
13
- let(:result) { stub("result") }
13
+ let(:result) { double("result") }
14
14
  let(:post_processing) { lambda {|arg| {"result" => result, "args" => arg} } }
15
15
 
16
16
  # Most API methods have the same signature, we test get_object representatively
17
17
  # and the other methods which do some post-processing locally
18
18
  context '#get_object' do
19
19
  it 'returns result of block' do
20
- @api.stub(:api).and_return(stub("other results"))
20
+ @api.stub(:api).and_return(double("other results"))
21
21
  @api.get_object('koppel', &post_processing)["result"].should == result
22
22
  end
23
23
  end
24
24
 
25
25
  context '#get_picture' do
26
26
  it 'returns result of block' do
27
- @api.stub(:api).and_return("Location" => stub("other result"))
27
+ @api.stub(:api).and_return("Location" => double("other result"))
28
28
  @api.get_picture('lukeshepard', &post_processing)["result"].should == result
29
29
  end
30
30
  end
@@ -1,10 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Koala::Facebook::GraphCollection do
4
+ let(:paging){ {:paging => true} }
5
+
4
6
  before(:each) do
5
7
  @result = {
6
8
  "data" => [1, 2, :three],
7
- "paging" => {:paging => true}
9
+ "paging" => paging
8
10
  }
9
11
  @api = Koala::Facebook::API.new("123")
10
12
  @collection = Koala::Facebook::GraphCollection.new(@result, @api)
@@ -45,9 +47,9 @@ describe Koala::Facebook::GraphCollection do
45
47
  "data" => [:second, :page, :data],
46
48
  "paging" => {}
47
49
  }
48
- @base = stub("base")
49
- @args = stub("args")
50
- @page_of_results = stub("page of results")
50
+ @base = double("base")
51
+ @args = {"a" => 1}
52
+ @page_of_results = double("page of results")
51
53
  end
52
54
 
53
55
  it "should return the previous page of results" do
@@ -76,15 +78,15 @@ describe Koala::Facebook::GraphCollection do
76
78
  describe "when parsing page paramters" do
77
79
  describe "#parse_page_url" do
78
80
  it "should pass the url to the class method" do
79
- url = stub("url")
81
+ url = double("url")
80
82
  Koala::Facebook::GraphCollection.should_receive(:parse_page_url).with(url)
81
83
  @collection.parse_page_url(url)
82
84
  end
83
85
 
84
86
  it "should return the result of the class method" do
85
- parsed_content = stub("parsed_content")
87
+ parsed_content = double("parsed_content")
86
88
  Koala::Facebook::GraphCollection.stub(:parse_page_url).and_return(parsed_content)
87
- @collection.parse_page_url(stub("url")).should == parsed_content
89
+ @collection.parse_page_url(double("url")).should == parsed_content
88
90
  end
89
91
  end
90
92
 
@@ -141,4 +143,32 @@ describe Koala::Facebook::GraphCollection do
141
143
  Koala::Facebook::GraphCollection.evaluate(result, @api).should == expected
142
144
  end
143
145
  end
146
+
147
+ describe "#next_page" do
148
+ let(:paging){ {"next" => "http://example.com/?a=2&b=3"} }
149
+
150
+ it "should get next page" do
151
+ @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
152
+ @collection.next_page
153
+ end
154
+
155
+ it "should get next page with extra parameters" do
156
+ @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
157
+ @collection.next_page("c" => "4")
158
+ end
159
+ end
160
+
161
+ describe "#previous_page" do
162
+ let(:paging){ {"previous" => "http://example.com/?a=2&b=3"} }
163
+
164
+ it "should get previous page" do
165
+ @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3"}])
166
+ @collection.previous_page
167
+ end
168
+
169
+ it "should get previous page with extra parameters" do
170
+ @api.should_receive(:get_page).with(["", {"a" => "2", "b" => "3", "c" => "4"}])
171
+ @collection.previous_page("c" => "4")
172
+ end
173
+ end
144
174
  end
@@ -17,7 +17,7 @@ describe Koala::HTTPService do
17
17
 
18
18
  describe "DEFAULT_MIDDLEWARE" do
19
19
  before :each do
20
- @builder = stub("Faraday connection builder")
20
+ @builder = double("Faraday connection builder")
21
21
  @builder.stub(:request)
22
22
  @builder.stub(:adapter)
23
23
  @builder.stub(:use)
@@ -173,11 +173,11 @@ describe Koala::HTTPService do
173
173
  describe ".make_request" do
174
174
  before :each do
175
175
  # Setup stubs for make_request to execute without exceptions
176
- @mock_body = stub('Typhoeus response body')
177
- @mock_headers_hash = stub({:value => "headers hash"})
178
- @mock_http_response = stub("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
176
+ @mock_body = double('Typhoeus response body')
177
+ @mock_headers_hash = double({:value => "headers hash"})
178
+ @mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
179
179
 
180
- @mock_connection = stub("Faraday connection")
180
+ @mock_connection = double("Faraday connection")
181
181
  @mock_connection.stub(:get).and_return(@mock_http_response)
182
182
  @mock_connection.stub(:post).and_return(@mock_http_response)
183
183
  Faraday.stub(:new).and_return(@mock_connection)
@@ -192,21 +192,28 @@ describe Koala::HTTPService do
192
192
  end
193
193
 
194
194
  it "merges Koala::HTTPService.http_options into the request params" do
195
- http_options = {:a => 2, :c => "3"}
195
+ http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
196
196
  Koala::HTTPService.http_options = http_options
197
197
  Faraday.should_receive(:new).with(anything, hash_including(http_options)).and_return(@mock_connection)
198
198
  Koala::HTTPService.make_request("anything", {}, "get")
199
199
  end
200
200
 
201
+ it "does not merge invalid Faraday options from Koala::HTTPService.http_options into the request params" do
202
+ http_options = {:invalid => "fake param"}
203
+ Koala::HTTPService.http_options = http_options
204
+ Faraday.should_receive(:new).with(anything, hash_not_including(http_options)).and_return(@mock_connection)
205
+ Koala::HTTPService.make_request("anything", {}, "get")
206
+ end
207
+
201
208
  it "merges any provided options into the request params" do
202
- options = {:a => 2, :c => "3"}
209
+ options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
203
210
  Faraday.should_receive(:new).with(anything, hash_including(options)).and_return(@mock_connection)
204
211
  Koala::HTTPService.make_request("anything", {}, "get", options)
205
212
  end
206
213
 
207
214
  it "overrides Koala::HTTPService.http_options with any provided options for the request params" do
208
- options = {:a => 2, :c => "3"}
209
- http_options = {:a => :a}
215
+ options = {:proxy => "http://user:password@proxy.org/", :request => { :timeout => 10 }}
216
+ http_options = {:proxy => "http://user:password@example.org/", :request => { :timeout => 3 }}
210
217
  Koala::HTTPService.stub(:http_options).and_return(http_options)
211
218
 
212
219
  Faraday.should_receive(:new).with(anything, hash_including(http_options.merge(options))).and_return(@mock_connection)
@@ -216,7 +223,7 @@ describe Koala::HTTPService do
216
223
  it "forces use_ssl to true if an access token is present" do
217
224
  options = {:use_ssl => false}
218
225
  Koala::HTTPService.stub(:http_options).and_return(:use_ssl => false)
219
- Faraday.should_receive(:new).with(anything, hash_including(:use_ssl => true, :ssl => {:verify => true})).and_return(@mock_connection)
226
+ Faraday.should_receive(:new).with(anything, hash_including(:ssl => {:verify => true})).and_return(@mock_connection)
220
227
  Koala::HTTPService.make_request("anything", {"access_token" => "foo"}, "get", options)
221
228
  end
222
229
 
@@ -312,7 +319,7 @@ describe Koala::HTTPService do
312
319
 
313
320
  it "turns any UploadableIOs to UploadIOs" do
314
321
  # technically this is done for all requests, but you don't send GET requests with files
315
- upload_io = stub("UploadIO")
322
+ upload_io = double("UploadIO")
316
323
  u = Koala::UploadableIO.new("/path/to/stuff", "img/jpg")
317
324
  u.stub(:to_upload_io).and_return(upload_io)
318
325
  @mock_connection.should_receive(:post).with(anything, hash_including("source" => upload_io)).and_return(@mock_http_response)
@@ -433,11 +440,11 @@ describe Koala::HTTPService do
433
440
  describe "per-request options" do
434
441
  before :each do
435
442
  # Setup stubs for make_request to execute without exceptions
436
- @mock_body = stub('Typhoeus response body')
437
- @mock_headers_hash = stub({:value => "headers hash"})
438
- @mock_http_response = stub("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
443
+ @mock_body = double('Typhoeus response body')
444
+ @mock_headers_hash = double({:value => "headers hash"})
445
+ @mock_http_response = double("Faraday Response", :status => 200, :headers => @mock_headers_hash, :body => @mock_body)
439
446
 
440
- @mock_connection = stub("Faraday connection")
447
+ @mock_connection = double("Faraday connection")
441
448
  @mock_connection.stub(:get).and_return(@mock_http_response)
442
449
  @mock_connection.stub(:post).and_return(@mock_http_response)
443
450
  Faraday.stub(:new).and_return(@mock_connection)
@@ -445,13 +452,13 @@ describe Koala::HTTPService do
445
452
 
446
453
  describe ":typhoeus_options" do
447
454
  it "merges any typhoeus_options into options" do
448
- typhoeus_options = {:a => 2}
455
+ typhoeus_options = {:proxy => "http://user:password@example.org/" }
449
456
  Faraday.should_receive(:new).with(anything, hash_including(typhoeus_options)).and_return(@mock_connection)
450
457
  Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
451
458
  end
452
459
 
453
460
  it "deletes the typhoeus_options key" do
454
- typhoeus_options = {:a => 2}
461
+ typhoeus_options = {:proxy => "http://user:password@example.org/" }
455
462
  Faraday.should_receive(:new).with(anything, hash_not_including(:typhoeus_options => typhoeus_options)).and_return(@mock_connection)
456
463
  Koala::HTTPService.make_request("anything", {}, "get", :typhoeus_options => typhoeus_options)
457
464
  end
@@ -22,20 +22,20 @@ describe Koala do
22
22
  end
23
23
 
24
24
  it "invokes deprecated_interface if present" do
25
- mock_service = stub("http service")
25
+ mock_service = double("http service")
26
26
  mock_service.should_receive(:deprecated_interface)
27
27
  Koala.http_service = mock_service
28
28
  end
29
29
 
30
30
  it "does not set the service if it's deprecated" do
31
- mock_service = stub("http service")
31
+ mock_service = double("http service")
32
32
  mock_service.stub(:deprecated_interface)
33
33
  Koala.http_service = mock_service
34
34
  Koala.http_service.should == @service
35
35
  end
36
36
 
37
37
  it "sets the service if it's not deprecated" do
38
- mock_service = stub("http service")
38
+ mock_service = double("http service")
39
39
  Koala.http_service = mock_service
40
40
  Koala.http_service.should == mock_service
41
41
  end
@@ -28,8 +28,8 @@ describe "Koala::Facebook::OAuth" do
28
28
 
29
29
  before :each do
30
30
  @time = Time.now
31
- Time.stub!(:now).and_return(@time)
32
- @time.stub!(:to_i).and_return(1273363199)
31
+ Time.stub(:now).and_return(@time)
32
+ @time.stub(:to_i).and_return(1273363199)
33
33
  end
34
34
 
35
35
  describe ".new" do
@@ -373,6 +373,46 @@ describe "Koala::Facebook::OAuth" do
373
373
  end
374
374
  end
375
375
 
376
+ describe 'for generating a client code' do
377
+ describe '#generate_client_code' do
378
+ if KoalaTest.mock_interface? || KoalaTest.oauth_token
379
+ it 'makes a request using the correct endpoint' do
380
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
381
+ @oauth.generate_client_code(KoalaTest.oauth_token)
382
+ end
383
+
384
+ it 'gets a valid client code returned' do
385
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"code": "fake_client_code"}', {}))
386
+ result = @oauth.generate_client_code(KoalaTest.oauth_token)
387
+ result.should be_a(String)
388
+ result.should eq('fake_client_code')
389
+ end
390
+
391
+ it 'raises a BadFacebookResponse error when empty response body is returned' do
392
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '', {}))
393
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::BadFacebookResponse)
394
+ end
395
+
396
+ it 'raises an OAuthTokenRequestError when empty response body is returned' do
397
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(400, '', {}))
398
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::OAuthTokenRequestError)
399
+ end
400
+
401
+ it 'raises a ServerError when empty response body is returned' do
402
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(500, '', {}))
403
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::Facebook::ServerError)
404
+ end
405
+
406
+ it 'raises a KoalaError when empty response body is returned' do
407
+ Koala.should_receive(:make_request).with('/oauth/client_code', anything, 'get', anything).and_return(Koala::HTTPService::Response.new(200, '{"client_code":"should_not_be_returned"}', {}))
408
+ lambda { @oauth.generate_client_code(KoalaTest.oauth_token) }.should raise_error(Koala::KoalaError)
409
+ end
410
+ else
411
+ pending "Some OAuth token exchange tests will not be run since the access token field in facebook_data.yml is blank."
412
+ end
413
+ end
414
+ end
415
+
376
416
  describe "for fetching access tokens" do
377
417
  describe "#get_access_token_info" do
378
418
  it "uses options[:redirect_uri] if provided" do
@@ -670,7 +710,7 @@ describe "Koala::Facebook::OAuth" do
670
710
  end
671
711
 
672
712
  it "throws an error if the signature is invalid" do
673
- OpenSSL::HMAC.stub!(:hexdigest).and_return("i'm an invalid signature")
713
+ OpenSSL::HMAC.stub(:hexdigest).and_return("i'm an invalid signature")
674
714
  lambda { @oauth.parse_signed_request(@signed_request) }.should raise_error
675
715
  end
676
716
 
@@ -213,7 +213,14 @@ describe "Koala::Facebook::RealtimeUpdates" do
213
213
  end
214
214
  end
215
215
 
216
- describe ".validate_update" do
216
+ describe "#validate_update" do
217
+ it "raises an error if no secret is defined" do
218
+ updates = Koala::Facebook::RealtimeUpdates.new(:app_id => @app_id, :app_access_token => "foo")
219
+ expect {
220
+ updates.validate_update("", {})
221
+ }.to raise_exception(Koala::Facebook::AppSecretNotDefinedError)
222
+ end
223
+
217
224
  it "returns false if there is no X-Hub-Signature header" do
218
225
  @updates.validate_update("", {}).should be_false
219
226
  end
@@ -189,8 +189,8 @@ describe "Koala::Facebook::TestUsers" do
189
189
  it "deletes the batch API to deleten all users found by the list commnand" do
190
190
  array = 200.times.collect { {"id" => rand}}
191
191
  @test_users.should_receive(:list).and_return(array, [])
192
- batch_api = stub("batch API")
193
- @test_users.api.should_receive(:batch).and_yield(batch_api).any_number_of_times
192
+ batch_api = double("batch API")
193
+ allow(@test_users.api).to receive(:batch).and_yield(batch_api)
194
194
  array.each {|item| batch_api.should_receive(:delete_object).with(item["id"]) }
195
195
  @test_users.delete_all
196
196
  end
@@ -204,7 +204,15 @@ describe "Koala::Facebook::TestUsers" do
204
204
 
205
205
  it "breaks if Facebook sends back the same list twice" do
206
206
  list = [{"id" => rand}]
207
- @test_users.should_receive(:list).any_number_of_times.and_return(list)
207
+ allow(@test_users).to receive(:list).and_return(list)
208
+ @test_users.api.should_receive(:batch).once
209
+ @test_users.delete_all
210
+ end
211
+
212
+ it "breaks if the same list comes back, even if the hashes differ" do
213
+ list1 = [{"id" => 123}]
214
+ list2 = [{"id" => 123, "name" => "foo"}]
215
+ allow(@test_users).to receive(:list).twice.and_return(list1, list2)
208
216
  @test_users.api.should_receive(:batch).once
209
217
  @test_users.delete_all
210
218
  end
@@ -291,12 +299,12 @@ describe "Koala::Facebook::TestUsers" do
291
299
 
292
300
  if KoalaTest.mock_interface?
293
301
  id_counter = 999999900
294
- @test_users.stub!(:create).and_return do
302
+ @test_users.stub(:create).and_return do
295
303
  id_counter += 1
296
304
  {"id" => id_counter, "access_token" => @token, "login_url" => "https://www.facebook.com/platform/test_account.."}
297
305
  end
298
- @test_users.stub!(:befriend).and_return(true)
299
- @test_users.stub!(:delete).and_return(true)
306
+ @test_users.stub(:befriend).and_return(true)
307
+ @test_users.stub(:delete).and_return(true)
300
308
  end
301
309
  end
302
310
 
@@ -312,7 +320,7 @@ describe "Koala::Facebook::TestUsers" do
312
320
  it "has no built-in network size limit" do
313
321
  times = 100
314
322
  @test_users.should_receive(:create).exactly(times).times
315
- @test_users.stub!(:befriend)
323
+ @test_users.stub(:befriend)
316
324
  @test_users.create_network(times)
317
325
  end
318
326
 
@@ -321,7 +329,7 @@ describe "Koala::Facebook::TestUsers" do
321
329
  installed = false
322
330
  count = 25
323
331
  @test_users.should_receive(:create).exactly(count).times.with(installed, perms, anything)
324
- @test_users.stub!(:befriend)
332
+ @test_users.stub(:befriend)
325
333
  @test_users.create_network(count, installed, perms)
326
334
  end
327
335
 
@@ -10,13 +10,13 @@ end
10
10
 
11
11
  describe "Koala::UploadableIO" do
12
12
  def rails_3_mocks
13
- tempfile = stub('Tempfile', :path => "foo")
14
- uploaded_file = stub('ActionDispatch::Http::UploadedFile',
13
+ tempfile = double('Tempfile', :path => "foo")
14
+ uploaded_file = double('ActionDispatch::Http::UploadedFile',
15
15
  :content_type => true,
16
16
  :tempfile => tempfile,
17
17
  :original_filename => "bar"
18
18
  )
19
- tempfile.stub!(:respond_to?).with(:path).and_return(true)
19
+ tempfile.stub(:respond_to?).with(:path).and_return(true)
20
20
 
21
21
  [tempfile, uploaded_file]
22
22
  end
@@ -34,7 +34,7 @@ describe "Koala::UploadableIO" do
34
34
 
35
35
  describe "and a content type" do
36
36
  before :each do
37
- @stub_type = stub("image/jpg")
37
+ @stub_type = double("image/jpg")
38
38
  @koala_io_params.concat([@stub_type])
39
39
  end
40
40
 
@@ -72,7 +72,39 @@ describe "Koala::UploadableIO" do
72
72
  end
73
73
 
74
74
  it "returns an UploadableIO with the same content_type" do
75
- content_stub = @koala_io_params[1] = stub('Content Type')
75
+ content_stub = @koala_io_params[1] = double('Content Type')
76
+ Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
77
+ end
78
+
79
+ it "returns an UploadableIO with the right filename" do
80
+ Koala::UploadableIO.new(*@koala_io_params).filename.should == File.basename(@file.path)
81
+ end
82
+ end
83
+
84
+ describe "and no content type" do
85
+ it_should_behave_like "determining a mime type"
86
+ end
87
+ end
88
+
89
+
90
+ describe "when given a Tempfile object" do
91
+ before(:each) do
92
+ @file = Tempfile.new('coucou')
93
+ @koala_io_params = [@file]
94
+ end
95
+
96
+ describe "and a content type" do
97
+ before :each do
98
+ @koala_io_params.concat(["image/jpg"])
99
+ end
100
+
101
+ it "returns an UploadIO with the same io" do
102
+ #Problem comparing Tempfile in Ruby 1.8, REE and Rubinius mode 1.8
103
+ Koala::UploadableIO.new(*@koala_io_params).io_or_path.path.should == @koala_io_params[0].path
104
+ end
105
+
106
+ it "returns an UploadableIO with the same content_type" do
107
+ content_stub = @koala_io_params[1] = double('Content Type')
76
108
  Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
77
109
  end
78
110
 
@@ -102,7 +134,7 @@ describe "Koala::UploadableIO" do
102
134
  end
103
135
 
104
136
  it "returns an UploadableIO with the same content_type" do
105
- content_stub = @koala_io_params[1] = stub('Content Type')
137
+ content_stub = @koala_io_params[1] = double('Content Type')
106
138
  Koala::UploadableIO.new(*@koala_io_params).content_type.should == content_stub
107
139
  end
108
140
  end
@@ -120,13 +152,13 @@ describe "Koala::UploadableIO" do
120
152
  end
121
153
 
122
154
  it "gets the path from the tempfile associated with the UploadedFile" do
123
- expected_path = stub('Tempfile')
155
+ expected_path = double('Tempfile')
124
156
  @tempfile.should_receive(:path).and_return(expected_path)
125
157
  Koala::UploadableIO.new(@uploaded_file).io_or_path.should == expected_path
126
158
  end
127
159
 
128
160
  it "gets the content type via the content_type method" do
129
- expected_content_type = stub('Content Type')
161
+ expected_content_type = double('Content Type')
130
162
  @uploaded_file.should_receive(:content_type).and_return(expected_content_type)
131
163
  Koala::UploadableIO.new(@uploaded_file).content_type.should == expected_content_type
132
164
  end
@@ -142,7 +174,7 @@ describe "Koala::UploadableIO" do
142
174
  end
143
175
 
144
176
  it "gets the io_or_path from the :tempfile key" do
145
- expected_file = stub('File')
177
+ expected_file = double('File')
146
178
  @file_hash[:tempfile] = expected_file
147
179
 
148
180
  uploadable = Koala::UploadableIO.new(@file_hash)
@@ -150,7 +182,7 @@ describe "Koala::UploadableIO" do
150
182
  end
151
183
 
152
184
  it "gets the content type from the :type key" do
153
- expected_content_type = stub('Content Type')
185
+ expected_content_type = double('Content Type')
154
186
  @file_hash[:type] = expected_content_type
155
187
 
156
188
  uploadable = Koala::UploadableIO.new(@file_hash)
@@ -167,20 +199,20 @@ describe "Koala::UploadableIO" do
167
199
  # what that means is tested below
168
200
  it "should accept a file object alone" do
169
201
  params = [BEACH_BALL_PATH]
170
- lambda { Koala::UploadableIO.new(*params) }.should_not raise_exception(Koala::KoalaError)
202
+ lambda { Koala::UploadableIO.new(*params) }.should_not raise_exception
171
203
  end
172
204
 
173
205
  it "should accept a file path alone" do
174
206
  params = [BEACH_BALL_PATH]
175
- lambda { Koala::UploadableIO.new(*params) }.should_not raise_exception(Koala::KoalaError)
207
+ lambda { Koala::UploadableIO.new(*params) }.should_not raise_exception
176
208
  end
177
209
  end
178
210
  end
179
211
 
180
212
  describe "getting an UploadableIO" do
181
213
  before(:each) do
182
- @upload_io = stub("UploadIO")
183
- UploadIO.stub!(:new).with(anything, anything, anything).and_return(@upload_io)
214
+ @upload_io = double("UploadIO")
215
+ UploadIO.stub(:new).with(anything, anything, anything).and_return(@upload_io)
184
216
  end
185
217
 
186
218
  context "if no filename was provided" do
@@ -206,7 +238,7 @@ describe "Koala::UploadableIO" do
206
238
  end
207
239
 
208
240
  it "should open up and return a file corresponding to the path if io_or_path is a path" do
209
- result = stub("File")
241
+ result = double("File")
210
242
  File.should_receive(:open).with(BEACH_BALL_PATH).and_return(result)
211
243
  Koala::UploadableIO.new(BEACH_BALL_PATH).to_file.should == result
212
244
  end
@@ -140,11 +140,11 @@ shared_examples_for "Koala GraphAPI" do
140
140
  describe "#fql_query" do
141
141
  it "makes a request to /fql" do
142
142
  @api.should_receive(:get_object).with("fql", anything, anything)
143
- @api.fql_query stub('query string')
143
+ @api.fql_query double('query string')
144
144
  end
145
145
 
146
146
  it "passes a query argument" do
147
- query = stub('query string')
147
+ query = double('query string')
148
148
  @api.should_receive(:get_object).with(anything, hash_including(:q => query), anything)
149
149
  @api.fql_query(query)
150
150
  end
@@ -163,7 +163,7 @@ shared_examples_for "Koala GraphAPI" do
163
163
  end
164
164
 
165
165
  it "passes a queries argument" do
166
- queries = stub('query string')
166
+ queries = double('query string')
167
167
  queries_json = "some JSON"
168
168
  MultiJson.stub(:dump).with(queries).and_return(queries_json)
169
169
 
@@ -338,7 +338,7 @@ shared_examples_for "Koala GraphAPI with an access token" do
338
338
  end
339
339
 
340
340
  it "sets options[:video] to true" do
341
- source = stub("UploadIO")
341
+ source = double("UploadIO")
342
342
  Koala::UploadableIO.stub(:new).and_return(source)
343
343
  source.stub(:requires_base_http_service).and_return(false)
344
344
  Koala.should_receive(:make_request).with(anything, anything, anything, hash_including(:video => true)).and_return(Koala::HTTPService::Response.new(200, "[]", {}))
@@ -2,7 +2,7 @@ shared_examples_for "Koala RestAPI" do
2
2
  # REST_CALL
3
3
  describe "when making a rest request" do
4
4
  it "uses the proper path" do
5
- method = stub('methodName')
5
+ method = double('methodName')
6
6
  @api.should_receive(:api).with(
7
7
  "method/#{method}",
8
8
  anything,
@@ -146,7 +146,7 @@ shared_examples_for "Koala RestAPI with an access token" do
146
146
  @api.should_receive(:rest_call).with(anything, anything, opts, anything)
147
147
  @api.set_app_properties({}, {}, opts)
148
148
  end
149
-
149
+
150
150
  it "makes a POST" do
151
151
  @api.should_receive(:rest_call).with(anything, anything, anything, "post")
152
152
  @api.set_app_properties({})
@@ -8,7 +8,7 @@ shared_examples_for "MIME::Types can't return results" do
8
8
  it "should properly get content types for #{extension} using basic analysis" do
9
9
  path = "filename.#{extension}"
10
10
  if @koala_io_params[0].is_a?(File)
11
- @koala_io_params[0].stub!(:path).and_return(path)
11
+ @koala_io_params[0].stub(:path).and_return(path)
12
12
  else
13
13
  @koala_io_params[0] = path
14
14
  end
@@ -18,7 +18,7 @@ shared_examples_for "MIME::Types can't return results" do
18
18
  it "should get content types for #{extension} using basic analysis with file names with more than one dot" do
19
19
  path = "file.name.#{extension}"
20
20
  if @koala_io_params[0].is_a?(File)
21
- @koala_io_params[0].stub!(:path).and_return(path)
21
+ @koala_io_params[0].stub(:path).and_return(path)
22
22
  else
23
23
  @koala_io_params[0] = path
24
24
  end
@@ -30,7 +30,7 @@ shared_examples_for "MIME::Types can't return results" do
30
30
  before :each do
31
31
  path = "badfile.badextension"
32
32
  if @koala_io_params[0].is_a?(File)
33
- @koala_io_params[0].stub!(:path).and_return(path)
33
+ @koala_io_params[0].stub(:path).and_return(path)
34
34
  else
35
35
  @koala_io_params[0] = path
36
36
  end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koala
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0rc1
5
- prerelease: 5
4
+ version: 1.8.0rc1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Koppel
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-19 00:00:00.000000000 Z
11
+ date: 2013-10-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: multi_json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: faraday
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: addressable
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write
@@ -164,6 +153,7 @@ files:
164
153
  - spec/support/uploadable_io_shared_examples.rb
165
154
  homepage: http://github.com/arsduo/koala
166
155
  licenses: []
156
+ metadata: {}
167
157
  post_install_message:
168
158
  rdoc_options:
169
159
  - --line-numbers
@@ -173,25 +163,20 @@ rdoc_options:
173
163
  require_paths:
174
164
  - lib
175
165
  required_ruby_version: !ruby/object:Gem::Requirement
176
- none: false
177
166
  requirements:
178
- - - ! '>='
167
+ - - '>='
179
168
  - !ruby/object:Gem::Version
180
169
  version: '0'
181
- segments:
182
- - 0
183
- hash: 3438610920641769302
184
170
  required_rubygems_version: !ruby/object:Gem::Requirement
185
- none: false
186
171
  requirements:
187
- - - ! '>'
172
+ - - '>'
188
173
  - !ruby/object:Gem::Version
189
174
  version: 1.3.1
190
175
  requirements: []
191
176
  rubyforge_project:
192
- rubygems_version: 1.8.23
177
+ rubygems_version: 2.0.6
193
178
  signing_key:
194
- specification_version: 3
179
+ specification_version: 4
195
180
  summary: A lightweight, flexible library for Facebook with support for the Graph API,
196
181
  the REST API, realtime updates, and OAuth authentication.
197
182
  test_files: