koala 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/Manifest +0 -14
- data/Rakefile +2 -1
- data/koala.gemspec +6 -3
- data/spec/facebook_data.yml +5 -5
- data/spec/koala/api_base_tests.rb +1 -0
- data/spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb +1 -1
- data/spec/koala/graph_api/graph_api_with_access_token_tests.rb +1 -1
- data/spec/koala/graph_api/graph_collection_tests.rb +2 -2
- data/spec/koala/live_testing_data_helper.rb +20 -12
- data/spec/koala/net_http_service_tests.rb +164 -159
- data/spec/koala/oauth/oauth_tests.rb +4 -11
- data/spec/koala/rest_api/rest_api_no_access_token_tests.rb +5 -5
- data/spec/koala/rest_api/rest_api_with_access_token_tests.rb +1 -1
- data/spec/koala_spec_helper.rb +18 -4
- metadata +16 -19
- data/examples/oauth_playground/Capfile +0 -2
- data/examples/oauth_playground/LICENSE +0 -22
- data/examples/oauth_playground/Rakefile +0 -4
- data/examples/oauth_playground/config.ru +0 -27
- data/examples/oauth_playground/config/deploy.rb +0 -39
- data/examples/oauth_playground/config/facebook.yml +0 -13
- data/examples/oauth_playground/lib/load_facebook.rb +0 -3
- data/examples/oauth_playground/lib/oauth_playground.rb +0 -187
- data/examples/oauth_playground/readme.md +0 -8
- data/examples/oauth_playground/spec/oauth_playground_spec.rb +0 -35
- data/examples/oauth_playground/spec/spec_helper.rb +0 -36
- data/examples/oauth_playground/tmp/restart.txt +0 -0
- data/examples/oauth_playground/views/index.erb +0 -206
- data/examples/oauth_playground/views/layout.erb +0 -39
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.9.1
|
2
|
+
-- Tests are now compatible with Ruby 1.9.2
|
3
|
+
-- Added JSON to runtime dependencies
|
4
|
+
-- Removed examples directory (referenced from github instead)
|
5
|
+
|
1
6
|
v0.9.0
|
2
7
|
-- Added parse_signed_request to handle Facebook's new authentication scheme
|
3
8
|
-- note: creates dependency on OpenSSL (OpenSSL::HMAC) for decryption
|
data/Manifest
CHANGED
@@ -2,20 +2,6 @@ CHANGELOG
|
|
2
2
|
LICENSE
|
3
3
|
Manifest
|
4
4
|
Rakefile
|
5
|
-
examples/oauth_playground/Capfile
|
6
|
-
examples/oauth_playground/LICENSE
|
7
|
-
examples/oauth_playground/Rakefile
|
8
|
-
examples/oauth_playground/config.ru
|
9
|
-
examples/oauth_playground/config/deploy.rb
|
10
|
-
examples/oauth_playground/config/facebook.yml
|
11
|
-
examples/oauth_playground/lib/load_facebook.rb
|
12
|
-
examples/oauth_playground/lib/oauth_playground.rb
|
13
|
-
examples/oauth_playground/readme.md
|
14
|
-
examples/oauth_playground/spec/oauth_playground_spec.rb
|
15
|
-
examples/oauth_playground/spec/spec_helper.rb
|
16
|
-
examples/oauth_playground/tmp/restart.txt
|
17
|
-
examples/oauth_playground/views/index.erb
|
18
|
-
examples/oauth_playground/views/layout.erb
|
19
5
|
init.rb
|
20
6
|
koala.gemspec
|
21
7
|
lib/koala.rb
|
data/Rakefile
CHANGED
@@ -4,13 +4,14 @@ require 'rake'
|
|
4
4
|
require 'echoe'
|
5
5
|
|
6
6
|
# gem management
|
7
|
-
Echoe.new('koala', '0.9.
|
7
|
+
Echoe.new('koala', '0.9.1') do |p|
|
8
8
|
p.summary = "A lightweight, flexible library for Facebook with support for the Graph API, the old REST API, realtime updates, and OAuth validation."
|
9
9
|
p.description = "Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services."
|
10
10
|
p.url = "http://github.com/arsduo/koala"
|
11
11
|
p.author = ["Alex Koppel", "Chris Baclig", "Rafi Jacoby", "Context Optional"]
|
12
12
|
p.email = "alex@alexkoppel.com"
|
13
13
|
p.ignore_pattern = ["tmp/*", "script/*", "pkg/*"]
|
14
|
+
p.runtime_dependencies = ["json"]
|
14
15
|
p.development_dependencies = []
|
15
16
|
p.retain_gemspec = true
|
16
17
|
end
|
data/koala.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{koala}
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Alex Koppel, Chris Baclig, Rafi Jacoby, Context Optional"]
|
9
|
-
s.date = %q{2010-
|
9
|
+
s.date = %q{2010-10-13}
|
10
10
|
s.description = %q{Koala is a lightweight, flexible Ruby SDK for Facebook. It allows read/write access to the social graph via the Graph API and the older REST API, as well as support for realtime updates and OAuth and Facebook Connect authentication. Koala is fully tested and supports Net::HTTP and Typhoeus connections out of the box and can accept custom modules for other services.}
|
11
11
|
s.email = %q{alex@alexkoppel.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb"]
|
13
|
-
s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "Rakefile", "init.rb", "koala.gemspec", "lib/koala.rb", "lib/koala/graph_api.rb", "lib/koala/http_services.rb", "lib/koala/realtime_updates.rb", "lib/koala/rest_api.rb", "readme.md", "spec/facebook_data.yml", "spec/koala/api_base_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_no_token_tests.rb", "spec/koala/graph_and_rest_api/graph_and_rest_api_with_token_tests.rb", "spec/koala/graph_api/graph_api_no_access_token_tests.rb", "spec/koala/graph_api/graph_api_with_access_token_tests.rb", "spec/koala/graph_api/graph_collection_tests.rb", "spec/koala/live_testing_data_helper.rb", "spec/koala/net_http_service_tests.rb", "spec/koala/oauth/oauth_tests.rb", "spec/koala/realtime_updates/realtime_updates_tests.rb", "spec/koala/rest_api/rest_api_no_access_token_tests.rb", "spec/koala/rest_api/rest_api_with_access_token_tests.rb", "spec/koala_spec.rb", "spec/koala_spec_helper.rb", "spec/koala_spec_without_mocks.rb", "spec/mock_facebook_responses.yml", "spec/mock_http_service.rb"]
|
14
14
|
s.homepage = %q{http://github.com/arsduo/koala}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koala", "--main", "readme.md"]
|
16
16
|
s.require_paths = ["lib"]
|
@@ -23,8 +23,11 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
26
27
|
else
|
28
|
+
s.add_dependency(%q<json>, [">= 0"])
|
27
29
|
end
|
28
30
|
else
|
31
|
+
s.add_dependency(%q<json>, [">= 0"])
|
29
32
|
end
|
30
33
|
end
|
data/spec/facebook_data.yml
CHANGED
@@ -5,18 +5,18 @@
|
|
5
5
|
|
6
6
|
# You must supply this value yourself to test the GraphAPI class.
|
7
7
|
# Your OAuth token should have publish_stream and read_stream permissions.
|
8
|
-
oauth_token: 119908831367602|2.
|
8
|
+
oauth_token: 119908831367602|2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623|24AaBQnKkMvvMlNNKdJn4GxRWWQ
|
9
9
|
|
10
10
|
# for testing the OAuth class
|
11
11
|
# baseline app
|
12
12
|
oauth_test_data:
|
13
13
|
# You must supply this value yourself, since they will expire.
|
14
|
-
code: 2.
|
14
|
+
code: 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623|Hae8o6zcuXr9E_UXm0LdoCN4ML8
|
15
15
|
# easiest way to get session keys: use multiple test accounts with the Javascript login at http://oauth.twoalex.com
|
16
|
-
session_key: 2.
|
16
|
+
session_key: 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623
|
17
17
|
multiple_session_keys:
|
18
|
-
- 2.
|
19
|
-
- 2.
|
18
|
+
- 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623
|
19
|
+
- 2.5GL0_XdFnxzqsiXeHxJ_FQ__.3600.1286535600-2905623
|
20
20
|
|
21
21
|
# These values will work out of the box
|
22
22
|
app_id: 119908831367602
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class GraphAndRestAPIWithTokenTests < Test::Unit::TestCase
|
2
2
|
describe "Koala GraphAndRestAPI without an access token" do
|
3
|
-
|
3
|
+
include LiveTestingDataHelper
|
4
4
|
it_should_behave_like "Koala RestAPI with an access token"
|
5
5
|
it_should_behave_like "Koala GraphAPI with an access token"
|
6
6
|
|
@@ -140,7 +140,7 @@ end
|
|
140
140
|
|
141
141
|
class FacebookWithAccessTokenTests < Test::Unit::TestCase
|
142
142
|
describe "Koala GraphAPI with an access token" do
|
143
|
-
|
143
|
+
include LiveTestingDataHelper
|
144
144
|
it_should_behave_like "Koala GraphAPI with an access token"
|
145
145
|
|
146
146
|
before :each do
|
@@ -65,7 +65,7 @@ shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
65
65
|
@api.should_receive(:graph_call).with(@base, @args).and_return(@second_page)
|
66
66
|
Koala::Facebook::GraphCollection.should_receive(:new).with(@second_page, @api).and_return(@page_of_results)
|
67
67
|
|
68
|
-
@result.previous_page
|
68
|
+
@result.previous_page.should == @page_of_results
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should return the next page of results" do
|
@@ -79,7 +79,7 @@ shared_examples_for "Koala GraphAPI with GraphCollection" do
|
|
79
79
|
it "should return nil it there are no other pages" do
|
80
80
|
%w{next previous}.each do |this|
|
81
81
|
@result.should_receive("#{this}_page_params".to_sym).and_return(nil)
|
82
|
-
@result.send("#{this}_page"
|
82
|
+
@result.send("#{this}_page").should == nil
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -1,15 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module LiveTestingDataHelper
|
2
|
+
# in RSpec 2, included example groups no longer share any hooks or state with outside examples
|
3
|
+
# even if in the same block
|
4
|
+
# so we have to use a module to provide setup and teardown hooks for live testing
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.class_eval do
|
8
|
+
before :each do
|
9
|
+
@token = $testing_data["oauth_token"]
|
10
|
+
raise Exception, "Must supply access token to run FacebookWithAccessTokenTests!" unless @token
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
# clean up any temporary objects
|
15
|
+
if @temporary_object_id
|
16
|
+
puts "\nCleaning up temporary object #{@temporary_object_id.to_s}"
|
17
|
+
result = @api.delete_object(@temporary_object_id)
|
18
|
+
raise "Unable to clean up temporary Graph object #{@temporary_object_id}!" unless result
|
19
|
+
end
|
13
20
|
end
|
14
21
|
end
|
22
|
+
end
|
15
23
|
end
|
@@ -1,180 +1,185 @@
|
|
1
1
|
require 'koala/http_services'
|
2
|
-
|
3
2
|
class NetHTTPServiceTests < Test::Unit::TestCase
|
4
3
|
module Bear
|
5
4
|
include Koala::NetHTTPService
|
6
5
|
end
|
7
|
-
|
8
|
-
it "should define a make_request static module method" do
|
9
|
-
Bear.respond_to?(:make_request).should be_true
|
10
|
-
end
|
11
6
|
|
12
|
-
describe "
|
13
|
-
|
14
|
-
|
15
|
-
@mock_http_response = stub('Net::HTTPResponse', :code => 1)
|
16
|
-
@mock_body = stub('Net::HTTPResponse body')
|
17
|
-
@http_request_result = [@mock_http_response, @mock_body]
|
18
|
-
|
19
|
-
@http_yield_mock = mock('Net::HTTP start yielded object')
|
20
|
-
|
21
|
-
@http_yield_mock.stub(:post).and_return(@http_request_result)
|
22
|
-
@http_yield_mock.stub(:get).and_return(@http_request_result)
|
23
|
-
|
24
|
-
@http_mock = stub('Net::HTTP object', 'use_ssl=' => true, 'verify_mode=' => true)
|
25
|
-
@http_mock.stub(:start).and_yield(@http_yield_mock)
|
26
|
-
|
27
|
-
Net::HTTP.stub(:new).and_return(@http_mock)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should use POST if verb is not GET" do
|
31
|
-
@http_yield_mock.should_receive(:post).and_return(@mock_http_response)
|
32
|
-
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
33
|
-
|
34
|
-
Bear.make_request('anything', {}, 'anything')
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should use port 443" do
|
38
|
-
Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
|
39
|
-
|
40
|
-
Bear.make_request('anything', {}, 'anything')
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should use SSL" do
|
44
|
-
@http_mock.should_receive('use_ssl=').with(true)
|
45
|
-
|
46
|
-
Bear.make_request('anything', {}, 'anything')
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should use the graph server by default" do
|
50
|
-
Net::HTTP.should_receive(:new).with(Koala::Facebook::GRAPH_SERVER, anything).and_return(@http_mock)
|
51
|
-
Bear.make_request('anything', {}, 'anything')
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should use the REST server if the :rest_api option is true" do
|
55
|
-
Net::HTTP.should_receive(:new).with(Koala::Facebook::REST_SERVER, anything).and_return(@http_mock)
|
56
|
-
Bear.make_request('anything', {}, 'anything', :rest_api => true)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should turn off vertificate validaiton warnings" do
|
60
|
-
@http_mock.should_receive('verify_mode=').with(OpenSSL::SSL::VERIFY_NONE)
|
61
|
-
|
62
|
-
Bear.make_request('anything', {}, 'anything')
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should start an HTTP connection" do
|
66
|
-
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
67
|
-
Bear.make_request('anything', {}, 'anything')
|
7
|
+
describe "NetHTTPService module holder class Bear" do
|
8
|
+
it "should define a make_request static module method" do
|
9
|
+
Bear.respond_to?(:make_request).should be_true
|
68
10
|
end
|
69
|
-
|
70
|
-
describe "
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
11
|
+
|
12
|
+
describe "when making a request" do
|
13
|
+
before(:each) do
|
14
|
+
# Setup stubs for make_request to execute without exceptions
|
15
|
+
@mock_http_response = stub('Net::HTTPResponse', :code => 1)
|
16
|
+
@mock_body = stub('Net::HTTPResponse body')
|
17
|
+
@http_request_result = [@mock_http_response, @mock_body]
|
18
|
+
|
19
|
+
# to_ary is called in Ruby 1.9 to provide backwards compatibility
|
20
|
+
# with the response, body = http.get() syntax we use
|
21
|
+
@mock_http_response.stub!(:to_ary).and_return(@http_request_result)
|
22
|
+
|
23
|
+
@http_yield_mock = mock('Net::HTTP start yielded object')
|
24
|
+
|
25
|
+
@http_yield_mock.stub(:post).and_return(@http_request_result)
|
26
|
+
@http_yield_mock.stub(:get).and_return(@http_request_result)
|
27
|
+
|
28
|
+
@http_mock = stub('Net::HTTP object', 'use_ssl=' => true, 'verify_mode=' => true)
|
29
|
+
@http_mock.stub(:start).and_yield(@http_yield_mock)
|
30
|
+
|
31
|
+
Net::HTTP.stub(:new).and_return(@http_mock)
|
75
32
|
end
|
76
|
-
|
77
|
-
it "should
|
78
|
-
|
79
|
-
@
|
80
|
-
|
81
|
-
Bear.make_request(
|
33
|
+
|
34
|
+
it "should use POST if verb is not GET" do
|
35
|
+
@http_yield_mock.should_receive(:post).and_return(@mock_http_response)
|
36
|
+
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
37
|
+
|
38
|
+
Bear.make_request('anything', {}, 'anything')
|
82
39
|
end
|
83
|
-
|
84
|
-
it "should use
|
85
|
-
|
86
|
-
|
87
|
-
Bear.
|
88
|
-
|
89
|
-
@http_yield_mock.should_receive(:post).with(anything, params).and_return(@http_request_result)
|
90
|
-
|
91
|
-
Bear.make_request('anything', args, 'post')
|
40
|
+
|
41
|
+
it "should use port 443" do
|
42
|
+
Net::HTTP.should_receive(:new).with(anything, 443).and_return(@http_mock)
|
43
|
+
|
44
|
+
Bear.make_request('anything', {}, 'anything')
|
92
45
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
Bear.make_request('anything', {}, 'get')
|
46
|
+
|
47
|
+
it "should use SSL" do
|
48
|
+
@http_mock.should_receive('use_ssl=').with(true)
|
49
|
+
|
50
|
+
Bear.make_request('anything', {}, 'anything')
|
100
51
|
end
|
101
|
-
|
102
|
-
it "should use the
|
103
|
-
|
104
|
-
|
105
|
-
args = {}
|
106
|
-
|
107
|
-
Bear.should_receive(:encode_params).with(args).and_return(params)
|
108
|
-
@http_yield_mock.should_receive(:get).with("#{path}?#{params}").and_return(@http_request_result)
|
109
|
-
|
110
|
-
Bear.make_request(path, args, 'get')
|
52
|
+
|
53
|
+
it "should use the graph server by default" do
|
54
|
+
Net::HTTP.should_receive(:new).with(Koala::Facebook::GRAPH_SERVER, anything).and_return(@http_mock)
|
55
|
+
Bear.make_request('anything', {}, 'anything')
|
111
56
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
57
|
+
|
58
|
+
it "should use the REST server if the :rest_api option is true" do
|
59
|
+
Net::HTTP.should_receive(:new).with(Koala::Facebook::REST_SERVER, anything).and_return(@http_mock)
|
60
|
+
Bear.make_request('anything', {}, 'anything', :rest_api => true)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should turn off vertificate validaiton warnings" do
|
64
|
+
@http_mock.should_receive('verify_mode=').with(OpenSSL::SSL::VERIFY_NONE)
|
65
|
+
|
66
|
+
Bear.make_request('anything', {}, 'anything')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should start an HTTP connection" do
|
70
|
+
@http_mock.should_receive(:start).and_yield(@http_yield_mock)
|
71
|
+
Bear.make_request('anything', {}, 'anything')
|
117
72
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
73
|
+
|
74
|
+
describe "via POST" do
|
75
|
+
it "should use Net::HTTP to make a POST request" do
|
76
|
+
@http_yield_mock.should_receive(:post).and_return(@http_request_result)
|
77
|
+
|
78
|
+
Bear.make_request('anything', {}, 'post')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should go to the specified path adding a / if it doesn't exist" do
|
82
|
+
path = mock('Path')
|
83
|
+
@http_yield_mock.should_receive(:post).with(path, anything).and_return(@http_request_result)
|
84
|
+
|
85
|
+
Bear.make_request(path, {}, 'post')
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should use encoded parameters" do
|
89
|
+
args = {}
|
90
|
+
params = mock('Encoded parameters')
|
91
|
+
Bear.should_receive(:encode_params).with(args).and_return(params)
|
92
|
+
|
93
|
+
@http_yield_mock.should_receive(:post).with(anything, params).and_return(@http_request_result)
|
94
|
+
|
95
|
+
Bear.make_request('anything', args, 'post')
|
96
|
+
end
|
121
97
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
98
|
+
|
99
|
+
describe "via GET" do
|
100
|
+
it "should use Net::HTTP to make a GET request" do
|
101
|
+
@http_yield_mock.should_receive(:get).and_return(@http_request_result)
|
102
|
+
|
103
|
+
Bear.make_request('anything', {}, 'get')
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should use the correct path, including arguments" do
|
107
|
+
path = mock('Path')
|
108
|
+
params = mock('Encoded parameters')
|
109
|
+
args = {}
|
110
|
+
|
111
|
+
Bear.should_receive(:encode_params).with(args).and_return(params)
|
112
|
+
@http_yield_mock.should_receive(:get).with("#{path}?#{params}").and_return(@http_request_result)
|
113
|
+
|
114
|
+
Bear.make_request(path, args, 'get')
|
115
|
+
end
|
125
116
|
end
|
126
|
-
|
127
|
-
|
128
|
-
|
117
|
+
|
118
|
+
describe "the returned value" do
|
119
|
+
before(:each) do
|
120
|
+
@response = Bear.make_request('anything', {}, 'anything')
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return a Koala::Response object" do
|
124
|
+
@response.class.should == Koala::Response
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should return a Koala::Response with the right status" do
|
128
|
+
@response.status.should == @mock_http_response.code
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should reutrn a Koala::Response with the right body" do
|
132
|
+
@response.body.should == @mock_body
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return a Koala::Response with the Net::HTTPResponse object as headers" do
|
136
|
+
@response.headers.should == @mock_http_response
|
137
|
+
end
|
138
|
+
end # describe return value
|
139
|
+
end # describe when making a request
|
140
|
+
|
141
|
+
describe "when encoding parameters" do
|
142
|
+
it "should return an empty string if param_hash evaluates to false" do
|
143
|
+
Bear.encode_params(nil).should == ''
|
129
144
|
end
|
130
|
-
|
131
|
-
it "should
|
132
|
-
|
145
|
+
|
146
|
+
it "should convert values to JSON if the value is not a String" do
|
147
|
+
val = 'json_value'
|
148
|
+
not_a_string = 'not_a_string'
|
149
|
+
not_a_string.stub(:class).and_return('NotAString')
|
150
|
+
not_a_string.should_receive(:to_json).and_return(val)
|
151
|
+
|
152
|
+
string = "hi"
|
153
|
+
|
154
|
+
args = {
|
155
|
+
not_a_string => not_a_string,
|
156
|
+
string => string
|
157
|
+
}
|
158
|
+
|
159
|
+
result = Bear.encode_params(args)
|
160
|
+
result.split('&').find do |key_and_val|
|
161
|
+
key_and_val.match("#{not_a_string}=#{val}")
|
162
|
+
end.should be_true
|
133
163
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
val = 'json_value'
|
144
|
-
not_a_string = 'not_a_string'
|
145
|
-
not_a_string.stub(:class).and_return('NotAString')
|
146
|
-
not_a_string.should_receive(:to_json).and_return(val)
|
147
|
-
|
148
|
-
string = "hi"
|
149
|
-
|
150
|
-
args = {
|
151
|
-
not_a_string => not_a_string,
|
152
|
-
string => string
|
153
|
-
}
|
154
|
-
|
155
|
-
result = Bear.encode_params(args)
|
156
|
-
result.split('&').find do |key_and_val|
|
157
|
-
key_and_val.match("#{not_a_string}=#{val}")
|
158
|
-
end.should be_true
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should escape all values" do
|
162
|
-
args = Hash[*(1..4).map {|i| [i.to_s, "Value #{i}($"]}.flatten]
|
163
|
-
|
164
|
-
result = Bear.encode_params(args)
|
165
|
-
result.split('&').each do |key_val|
|
166
|
-
key, val = key_val.split('=')
|
167
|
-
val.should == CGI.escape(args[key])
|
164
|
+
|
165
|
+
it "should escape all values" do
|
166
|
+
args = Hash[*(1..4).map {|i| [i.to_s, "Value #{i}($"]}.flatten]
|
167
|
+
|
168
|
+
result = Bear.encode_params(args)
|
169
|
+
result.split('&').each do |key_val|
|
170
|
+
key, val = key_val.split('=')
|
171
|
+
val.should == CGI.escape(args[key])
|
172
|
+
end
|
168
173
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
174
|
+
|
175
|
+
it "should convert all keys to Strings" do
|
176
|
+
args = Hash[*(1..4).map {|i| [i, "val#{i}"]}.flatten]
|
177
|
+
|
178
|
+
result = Bear.encode_params(args)
|
179
|
+
result.split('&').each do |key_val|
|
180
|
+
key, val = key_val.split('=')
|
181
|
+
key.should == args.find{|key_val_arr| key_val_arr.last == val}.first.to_s
|
182
|
+
end
|
178
183
|
end
|
179
184
|
end
|
180
185
|
end
|