/
facebook_data_test.rb
84 lines (73 loc) · 2.92 KB
/
facebook_data_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require File.dirname(__FILE__) + '/test_helper.rb'
class FacebookDataTest < Test::Unit::TestCase
def setup
@session = Facebooker::Session.create('apikey', 'secretkey')
end
def test_can_ask_facebook_to_set_a_cookies
expect_http_posts_with_responses(example_set_cookie_xml)
assert(@session.data.set_cookie(12345, 'name', 'value'))
end
def test_can_ask_facebook_to_get_cookies
expect_http_posts_with_responses(example_get_cookies_xml)
assert(@session.data.get_cookies(12345))
end
def test_can_get_cookies_for_user
mock_http = establish_session
mock_http.should_receive(:post_form).and_return(example_get_cookies_xml).once.ordered(:posts)
cookies = @session.data.get_cookies(508508326)
assert_equal 'Foo', cookies.first.name
assert_equal 'Bar', cookies.first.value
end
def test_can_ask_facebook_to_set_a_preference
expect_http_posts_with_responses(example_set_preference_xml)
assert(@session.data.set_preference(0, 'hello'))
end
def test_can_ask_facebook_to_get_preference
expect_http_posts_with_responses(example_get_preference_xml)
assert(@session.data.get_preference(0))
end
def test_can_get_preference
mock_http = establish_session
mock_http.should_receive(:post_form).and_return(example_get_preference_xml).once.ordered(:posts)
assert_equal 'hello', @session.data.get_preference(0)
end
private
def example_set_cookie_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<data_setCookie_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_setCookie_response>
XML
end
def example_get_cookies_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<data_getCookie_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
<cookies>
<uid>508508326</uid>
<name>Foo</name>
<value>Bar</value>
<expires>0</expires>
<path>/tmp/</path>
</cookies>
</data_getCookie_response>
XML
end
def example_set_preference_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<data_setUserPreference_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd"/>
XML
end
def example_get_preference_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<data_getUserPreference_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
hello
</data_getUserPreference_response>
XML
end
end