Browse files

Fix elusive post-processing issue

  • Loading branch information...
1 parent e3d57b7 commit d86845f5175ae6c882fd69aaca77be1c1941a481 @arsduo committed Jan 14, 2013
Showing with 25 additions and 36 deletions.
  1. +10 −14 spec/cases/graph_api_batch_spec.rb
  2. +13 −20 spec/cases/graph_api_spec.rb
  3. +2 −2 spec/support/mock_http_service.rb
View
24 spec/cases/graph_api_batch_spec.rb
@@ -551,36 +551,32 @@
describe 'with post-processing callback' do
let(:me_result) { stub("me result") }
let(:friends_result) { stub("friends result") }
-
- let(:me_callback) { lambda {|data| me_result } }
- let(:friends_callback) { lambda {|data| friends_result } }
+
+ let(:me_callback) { lambda {|arg| {"result" => me_result, "args" => arg} } }
+ let(:friends_callback) { lambda {|arg| {"result" => friends_result, "args" => arg} } }
it 'calls the callback with the appropriate data' do
- me_callback.should_receive(:call).with(hash_including(
- 'id' => KoalaTest.user1
- ))
- friends_callback.should_receive(:call).with([
- hash_including('id' => KoalaTest.user2)
- ])
- @api.batch do |batch_api|
+ me, friends = @api.batch do |batch_api|
batch_api.get_object('me', &me_callback)
batch_api.get_connections('me', 'friends', &friends_callback)
end
+ me["args"].should include("id" => KoalaTest.user1)
+ friends["args"].should include("id" => KoalaTest.user2)
end
it 'passes GraphCollections, not raw data' do
- friends_callback.should_receive(:call).with(kind_of(Koala::Facebook::API::GraphCollection))
- @api.batch do |batch_api|
+ me, friends = @api.batch do |batch_api|
batch_api.get_object('me')
batch_api.get_connections('me', 'friends', &friends_callback)
end
+ friends["args"].should be_a(Koala::Facebook::API::GraphCollection)
end
it "returns the result of the callback" do
@api.batch do |batch_api|
batch_api.get_object('me', &me_callback)
batch_api.get_connections('me', 'friends', &friends_callback)
- end.should == [me_result, friends_result]
+ end.map {|r| r["result"]}.should == [me_result, friends_result]
end
end
@@ -662,4 +658,4 @@
end
end
end
-end
+end
View
33 spec/cases/graph_api_spec.rb
@@ -10,27 +10,22 @@
end
describe 'post-processing for' do
- let(:post_processing) { lambda {} }
+ let(:result) { stub("result") }
+ let(:post_processing) { lambda {|arg| {"result" => result, "args" => arg} } }
# Most API methods have the same signature, we test get_object representatively
# and the other methods which do some post-processing locally
context '#get_object' do
it 'returns result of block' do
- result = {"id" => 1, "name" => 1, "updated_time" => 1}
- @api.stub(:api).and_return(result)
- post_processing.should_receive(:call).
- with(result).and_return('new result')
- @api.get_object('koppel', &post_processing).should == 'new result'
+ @api.stub(:api).and_return(stub("other results"))
+ @api.get_object('koppel', &post_processing)["result"].should == result
end
end
context '#get_picture' do
it 'returns result of block' do
- result = "http://facebook.com/"
- @api.stub(:api).and_return("Location" => result)
- post_processing.should_receive(:call).
- with(result).and_return('new result')
- @api.get_picture('lukeshepard', &post_processing).should == 'new result'
+ @api.stub(:api).and_return("Location" => stub("other result"))
+ @api.get_picture('lukeshepard', &post_processing)["result"].should == result
end
end
@@ -45,23 +40,21 @@
it 'is called with resolved response' do
resolved_result = {
'query1' => [{'id' => 123}],
- 'query2' => [{'id'=>456}]
+ 'query2' => [{'id' => 456}]
}
- post_processing.should_receive(:call).
- with(resolved_result).and_return('id'=>'123', 'id'=>'456')
- @api.fql_multiquery({}, &post_processing).should ==
- {'id'=>'123', 'id'=>'456'}
+ response = @api.fql_multiquery({}, &post_processing)
+ response["args"].should == resolved_result
+ response["result"].should == result
end
end
context '#get_page_access_token' do
it 'returns result of block' do
token = Koala::MockHTTPService::APP_ACCESS_TOKEN
@api.stub(:api).and_return("access_token" => token)
- post_processing.should_receive(:call).
- with(token).and_return('base64-encoded access token')
- @api.get_page_access_token('facebook', &post_processing).should ==
- 'base64-encoded access token'
+ response = @api.get_page_access_token('facebook', &post_processing)
+ response["args"].should == token
+ response["result"].should == result
end
end
end
View
4 spec/support/mock_http_service.rb
@@ -137,7 +137,7 @@ def self.decode_query(string)
# all the time -- different Rubies may create a strings with equivalent
# content but different order. We want to compare the objects.
def self.should_json_decode?(v)
- ["[", "{"].include?(v[0])
+ v.match(/^[\[\{]/)
end
end
-end
+end

0 comments on commit d86845f

Please sign in to comment.