fb_graph 1.7.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +52 -0
- data/README.rdoc +1 -0
- data/Rakefile +8 -34
- data/VERSION +1 -1
- data/fb_graph.gemspec +15 -433
- data/lib/fb_graph/connections/family.rb +14 -0
- data/lib/fb_graph/connections/permissions.rb +12 -0
- data/lib/fb_graph/page/category_attributes.rb +1 -0
- data/lib/fb_graph/user.rb +4 -1
- data/lib/fb_graph.rb +0 -1
- data/spec/fb_graph/application_spec.rb +8 -14
- data/spec/fb_graph/auth_spec.rb +1 -1
- data/spec/fb_graph/checkin_spec.rb +15 -11
- data/spec/fb_graph/collection_spec.rb +8 -7
- data/spec/fb_graph/connection_spec.rb +36 -25
- data/spec/fb_graph/connections/accounts_spec.rb +30 -26
- data/spec/fb_graph/connections/activities_spec.rb +19 -18
- data/spec/fb_graph/connections/albums_spec.rb +40 -37
- data/spec/fb_graph/connections/app_requests_spec.rb +7 -7
- data/spec/fb_graph/connections/attending_spec.rb +12 -12
- data/spec/fb_graph/connections/books_spec.rb +18 -17
- data/spec/fb_graph/connections/checkins_spec.rb +91 -91
- data/spec/fb_graph/connections/comments_spec.rb +41 -48
- data/spec/fb_graph/connections/declined_spec.rb +13 -9
- data/spec/fb_graph/connections/events_spec.rb +31 -32
- data/spec/fb_graph/connections/family_spec.rb +34 -0
- data/spec/fb_graph/connections/feed_spec.rb +65 -70
- data/spec/fb_graph/connections/former_participants_spec.rb +8 -7
- data/spec/fb_graph/connections/friend_lists_spec.rb +7 -7
- data/spec/fb_graph/connections/friends_spec.rb +29 -24
- data/spec/fb_graph/connections/games_spec.rb +15 -15
- data/spec/fb_graph/connections/groups_spec.rb +17 -16
- data/spec/fb_graph/connections/home_spec.rb +40 -35
- data/spec/fb_graph/connections/insights_spec.rb +74 -70
- data/spec/fb_graph/connections/interests_spec.rb +7 -7
- data/spec/fb_graph/connections/invited_spec.rb +7 -7
- data/spec/fb_graph/connections/likes_spec.rb +23 -19
- data/spec/fb_graph/connections/links_spec.rb +17 -19
- data/spec/fb_graph/connections/maybe_spec.rb +10 -12
- data/spec/fb_graph/connections/members_spec.rb +7 -7
- data/spec/fb_graph/connections/messages_spec.rb +8 -7
- data/spec/fb_graph/connections/movies_spec.rb +7 -7
- data/spec/fb_graph/connections/music_spec.rb +7 -7
- data/spec/fb_graph/connections/noreply_spec.rb +7 -7
- data/spec/fb_graph/connections/notes_spec.rb +18 -16
- data/spec/fb_graph/connections/participants_spec.rb +8 -7
- data/spec/fb_graph/connections/permissions_spec.rb +18 -0
- data/spec/fb_graph/connections/photos_spec.rb +24 -24
- data/spec/fb_graph/connections/posts_spec.rb +23 -26
- data/spec/fb_graph/connections/senders_spec.rb +8 -7
- data/spec/fb_graph/connections/statuses_spec.rb +45 -43
- data/spec/fb_graph/connections/subscriptions_spec.rb +7 -7
- data/spec/fb_graph/connections/tagged_spec.rb +30 -33
- data/spec/fb_graph/connections/television_spec.rb +7 -7
- data/spec/fb_graph/connections/test_users_spec.rb +13 -9
- data/spec/fb_graph/connections/threads_spec.rb +7 -7
- data/spec/fb_graph/connections/videos_spec.rb +7 -7
- data/spec/fb_graph/page/local_business_spec.rb +4 -4
- data/spec/fb_graph/page/movie_spec.rb +4 -4
- data/spec/fb_graph/page/music_spec.rb +4 -4
- data/spec/fb_graph/page/person_spec.rb +4 -4
- data/spec/fb_graph/page/product_spec.rb +4 -4
- data/spec/fb_graph/page_spec.rb +8 -16
- data/spec/fb_graph/post_spec.rb +50 -46
- data/spec/fb_graph/query/core_spec.rb +39 -51
- data/spec/fb_graph/searchable_spec.rb +13 -9
- data/spec/fb_graph/test_user_spec.rb +5 -11
- data/spec/fb_graph/user_spec.rb +96 -91
- data/spec/helpers/webmock_helper.rb +71 -0
- data/spec/{fake_json → mock_json}/albums/photos/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/albums/photos/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/applications/feed/public.json +0 -0
- data/spec/{fake_json → mock_json}/applications/subscriptions/fb_graph_private.json +0 -0
- data/spec/{fake_json → mock_json}/applications/test_users/created.json +0 -0
- data/spec/{fake_json → mock_json}/applications/test_users/private.json +0 -0
- data/spec/{fake_json → mock_json}/checkins/search_private.json +0 -0
- data/spec/{fake_json → mock_json}/checkins/search_public.json +0 -0
- data/spec/{fake_json → mock_json}/events/attending/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/events/attending/smartday_private.json +0 -0
- data/spec/{fake_json → mock_json}/events/declined/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/events/declined/smartday_private.json +0 -0
- data/spec/{fake_json → mock_json}/events/invited/smartday_private.json +0 -0
- data/spec/{fake_json → mock_json}/events/maybe/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/events/maybe/smartday_private.json +0 -0
- data/spec/{fake_json → mock_json}/events/noreply/smartday_private.json +0 -0
- data/spec/{fake_json → mock_json}/groups/members/emacs_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/categories/local_business.json +0 -0
- data/spec/{fake_json → mock_json}/pages/categories/movie.json +0 -0
- data/spec/{fake_json → mock_json}/pages/categories/music.json +0 -0
- data/spec/{fake_json → mock_json}/pages/categories/person.json +0 -0
- data/spec/{fake_json → mock_json}/pages/categories/product.json +0 -0
- data/spec/{fake_json → mock_json}/pages/checkins/gowalla_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/checkins/gowalla_public.json +0 -0
- data/spec/{fake_json → mock_json}/pages/insights/FbGraph_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/insights/FbGraph_public.json +0 -0
- data/spec/{fake_json → mock_json}/pages/insights/page_like_adds/FbGraph_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/insights/page_like_adds/day/FbGraph_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/notes/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/pages/platform_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/platform_public.json +0 -0
- data/spec/{fake_json → mock_json}/pages/search_fb_graph.json +0 -0
- data/spec/{fake_json → mock_json}/pages/search_google.json +0 -0
- data/spec/{fake_json → mock_json}/pages/statuses/platform_private.json +0 -0
- data/spec/{fake_json → mock_json}/pages/statuses/platform_public.json +0 -0
- data/spec/{fake_json → mock_json}/posts/comments/post_with_invalid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/posts/comments/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/posts/comments/post_without_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/posts/likes/post_with_invalid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/posts/likes/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/posts/likes/post_without_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/posts/no_comments.json +0 -0
- data/spec/{fake_json → mock_json}/posts/platform_private.json +0 -0
- data/spec/{fake_json → mock_json}/posts/platform_public.json +0 -0
- data/spec/{fake_json → mock_json}/posts/to_application.json +0 -0
- data/spec/{fake_json → mock_json}/posts/to_event.json +0 -0
- data/spec/{fake_json → mock_json}/posts/to_group.json +0 -0
- data/spec/{fake_json → mock_json}/query/user/with_invalid_token.json +0 -0
- data/spec/{fake_json → mock_json}/query/user/with_valid_token.json +0 -0
- data/spec/{fake_json → mock_json}/query/user/without_token.json +0 -0
- data/spec/{fake_json → mock_json}/statuses/with_likes.json +0 -0
- data/spec/{fake_json → mock_json}/thread/former_participants/private.json +0 -0
- data/spec/{fake_json → mock_json}/thread/messages/private.json +0 -0
- data/spec/{fake_json → mock_json}/thread/participants/private.json +0 -0
- data/spec/{fake_json → mock_json}/thread/senders/private.json +0 -0
- data/spec/{fake_json → mock_json}/token_response.json +0 -0
- data/spec/{fake_json → mock_json}/true.json +0 -0
- data/spec/{fake_json → mock_json}/users/accounts/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/accounts/matake_private_with_manage_pages_permission.json +0 -0
- data/spec/{fake_json → mock_json}/users/accounts/matake_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/activities/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/activities/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/albums/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/albums/matake_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/albums/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/users/app_requests/me_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/books/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/books/matake_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/checkins/mattt_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/checkins/mattt_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/checkins/posted.json +0 -0
- data/spec/{fake_json → mock_json}/users/events/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/events/matake_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/events/post_with_valid_access_token.json +0 -0
- data/spec/mock_json/users/family/family_without_access_token.json +6 -0
- data/spec/mock_json/users/family/me_public.json +19 -0
- data/spec/{fake_json → mock_json}/users/feed/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/feed/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/feed/post_with_invalid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/users/feed/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/users/feed/post_without_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/users/friend_lists/matake.json +0 -0
- data/spec/{fake_json → mock_json}/users/friends/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/friends/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/friends/me_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/friends/me_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/games/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/groups/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/groups/matake_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/home/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/home/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/home/me_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/home/me_private_next.json +0 -0
- data/spec/{fake_json → mock_json}/users/home/me_private_previous.json +0 -0
- data/spec/{fake_json → mock_json}/users/home/me_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/interests/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/likes/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/likes/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/links/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/links/post_with_valid_access_token.json +0 -0
- data/spec/{fake_json → mock_json}/users/me_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/me_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/movies/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/music/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/notes/matake_private.json +0 -0
- data/spec/mock_json/users/permissions/me_private.json +70 -0
- data/spec/{fake_json → mock_json}/users/posts/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/posts/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/statuses/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/statuses/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/tagged/arjun_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/tagged/arjun_public.json +0 -0
- data/spec/{fake_json → mock_json}/users/television/matake_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/threads/me_private.json +0 -0
- data/spec/{fake_json → mock_json}/users/videos/kirk_private.json +0 -0
- data/spec/spec_helper.rb +2 -7
- metadata +267 -128
- data/.rspec-tm +0 -1
- data/spec/helpers/fake_json_helper.rb +0 -37
- data/spec/spec.opts +0 -3
data/spec/fb_graph/post_spec.rb
CHANGED
@@ -96,46 +96,44 @@ end
|
|
96
96
|
describe FbGraph::Post, '#fetch' do
|
97
97
|
|
98
98
|
context 'when no access_token given' do
|
99
|
-
before do
|
100
|
-
fake_json(:get, 'platform', 'posts/platform_public')
|
101
|
-
end
|
102
|
-
|
103
99
|
it 'should get all attributes except some comments' do
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
100
|
+
mock_graph :get, 'platform', 'posts/platform_public' do
|
101
|
+
post = FbGraph::Post.fetch('platform')
|
102
|
+
post.identifier.should == '19292868552_118464504835613'
|
103
|
+
post.from.should == FbGraph::Page.new(
|
104
|
+
"19292868552",
|
105
|
+
:name => "Facebook Platform",
|
106
|
+
:category => "Technology"
|
107
|
+
)
|
108
|
+
post.message.should == "We're getting ready for f8! Check out the latest on the f8 Page, including a video from the first event, when Platform launched :: http://bit.ly/ahHl7j"
|
109
|
+
post.likes.should == [
|
110
|
+
FbGraph::User.new("100000785546814", :name => "Anter Saied")
|
111
|
+
]
|
112
|
+
post.likes.collection.total_count.should == 270
|
113
|
+
post.created_time.should == Time.parse("2010-04-15T17:37:03+0000")
|
114
|
+
post.updated_time.should == Time.parse("2010-04-22T18:19:13+0000")
|
115
|
+
post.comments.size.should == 4
|
116
|
+
end
|
119
117
|
end
|
120
118
|
end
|
121
119
|
|
122
120
|
context 'when access_token given' do
|
123
|
-
before do
|
124
|
-
fake_json(:get, 'platform?access_token=access_token', 'posts/platform_private')
|
125
|
-
end
|
126
|
-
|
127
121
|
it 'shold get all attributes and comments' do
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
122
|
+
mock_graph :get, 'platform', 'posts/platform_private', :params => {
|
123
|
+
:access_token => 'access_token'
|
124
|
+
} do
|
125
|
+
post = FbGraph::Post.fetch('platform', :access_token => 'access_token')
|
126
|
+
post.identifier.should == '19292868552_118464504835613'
|
127
|
+
post.from.should == FbGraph::Page.new(
|
128
|
+
"19292868552",
|
129
|
+
:name => "Facebook Platform",
|
130
|
+
:category => "Technology"
|
131
|
+
)
|
132
|
+
post.message.should == "We're getting ready for f8! Check out the latest on the f8 Page, including a video from the first event, when Platform launched :: http://bit.ly/ahHl7j"
|
133
|
+
post.created_time.should == Time.parse("2010-04-15T17:37:03+0000")
|
134
|
+
post.updated_time.should == Time.parse("2010-04-22T18:19:13+0000")
|
135
|
+
post.comments.size.should == 9
|
136
|
+
end
|
139
137
|
end
|
140
138
|
end
|
141
139
|
|
@@ -145,36 +143,42 @@ describe FbGraph::Post, '#to' do
|
|
145
143
|
subject { post.to.first }
|
146
144
|
|
147
145
|
context 'when include Event' do
|
148
|
-
|
149
|
-
|
146
|
+
let :post do
|
147
|
+
mock_graph :get, 'to_event', 'posts/to_event' do
|
148
|
+
FbGraph::Post.fetch('to_event')
|
149
|
+
end
|
150
150
|
end
|
151
|
-
let(:post) { FbGraph::Post.fetch('to_event') }
|
152
151
|
it { should be_instance_of FbGraph::Event }
|
153
152
|
end
|
154
153
|
|
155
154
|
context 'when include Application' do
|
156
155
|
context 'when fetched as Application#feed' do
|
157
|
-
|
158
|
-
|
156
|
+
let :post do
|
157
|
+
mock_graph :get, 'app/feed', 'applications/feed/public' do
|
158
|
+
FbGraph::Application.new('app').feed.first
|
159
|
+
end
|
159
160
|
end
|
160
|
-
let(:post) { FbGraph::Application.new('app').feed.first }
|
161
161
|
it { should be_instance_of FbGraph::Application }
|
162
162
|
end
|
163
163
|
|
164
164
|
context 'otherwize' do # no way to detect this case..
|
165
|
-
|
166
|
-
|
165
|
+
let :post do
|
166
|
+
mock_graph :get, 'to_application', 'posts/to_application' do
|
167
|
+
FbGraph::Post.fetch('to_application')
|
168
|
+
end
|
167
169
|
end
|
168
|
-
let(:post) { FbGraph::Post.fetch('to_application') }
|
169
170
|
it { should be_instance_of FbGraph::User }
|
170
171
|
end
|
171
172
|
end
|
172
173
|
|
173
174
|
context 'when include Group' do
|
174
|
-
|
175
|
-
|
175
|
+
let :post do
|
176
|
+
mock_graph :get, 'to_group', 'posts/to_group', :params => {
|
177
|
+
:access_token => 'access_token'
|
178
|
+
} do
|
179
|
+
FbGraph::Post.fetch('to_group', :access_token => 'access_token')
|
180
|
+
end
|
176
181
|
end
|
177
|
-
let(:post) { FbGraph::Post.fetch('to_group', :access_token => 'access_token') }
|
178
182
|
it { should be_instance_of FbGraph::Group }
|
179
183
|
end
|
180
184
|
|
@@ -1,68 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe FbGraph::Query
|
3
|
+
describe FbGraph::Query do
|
4
|
+
let(:raw_query) { 'SELECT uid FROM user WHERE uid = me()' }
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
@query = FbGraph::Query.new(@raw_query, 'access_token')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should setup query and access_token' do
|
11
|
-
@query.query.should == @raw_query
|
12
|
-
@query.access_token.should == 'access_token'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should setup proper endpoint' do
|
16
|
-
endpoint = @query.send :build_endpoint
|
17
|
-
params = {
|
18
|
-
:query => @raw_query,
|
19
|
-
:format => :json,
|
20
|
-
:access_token => 'access_token'
|
21
|
-
}
|
22
|
-
endpoint.should == "#{FbGraph::Query::ENDPOINT}?#{params.to_query}"
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
6
|
+
describe '.new' do
|
7
|
+
let(:query) { FbGraph::Query.new(raw_query, 'access_token') }
|
26
8
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@raw_query = 'SELECT uid FROM user WHERE uid = me()'
|
31
|
-
@query = FbGraph::Query.new(@raw_query)
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when no access token given' do
|
35
|
-
before do
|
36
|
-
fake_fql_json @raw_query, 'query/user/without_token'
|
9
|
+
it 'should setup query and access_token' do
|
10
|
+
query.query.should == raw_query
|
11
|
+
query.access_token.should == 'access_token'
|
37
12
|
end
|
38
13
|
|
39
|
-
it 'should
|
40
|
-
|
41
|
-
|
14
|
+
it 'should setup proper endpoint' do
|
15
|
+
endpoint = query.send :build_endpoint
|
16
|
+
params = {
|
17
|
+
:query => raw_query,
|
18
|
+
:format => :json,
|
19
|
+
:access_token => 'access_token'
|
20
|
+
}
|
21
|
+
endpoint.should == "#{FbGraph::Query::ENDPOINT}?#{params.to_query}"
|
42
22
|
end
|
43
23
|
end
|
44
24
|
|
45
|
-
|
46
|
-
|
47
|
-
fake_fql_json @raw_query, 'query/user/with_invalid_token', :access_token => 'invalid'
|
48
|
-
end
|
25
|
+
describe '.fetch' do
|
26
|
+
let(:query) { FbGraph::Query.new(raw_query) }
|
49
27
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
28
|
+
context 'when no access token given' do
|
29
|
+
it 'should return blank Hash' do
|
30
|
+
mock_fql raw_query, 'query/user/without_token' do
|
31
|
+
response = query.fetch
|
32
|
+
response.should == {}
|
33
|
+
end
|
34
|
+
end
|
54
35
|
end
|
55
|
-
end
|
56
36
|
|
57
|
-
|
58
|
-
|
59
|
-
|
37
|
+
context 'when invalid access token given' do
|
38
|
+
it 'should raise exception' do
|
39
|
+
mock_fql raw_query, 'query/user/with_invalid_token', :access_token => 'invalid' do
|
40
|
+
lambda do
|
41
|
+
query.fetch('invalid')
|
42
|
+
end.should raise_error(FbGraph::Exception)
|
43
|
+
end
|
44
|
+
end
|
60
45
|
end
|
61
46
|
|
62
|
-
|
63
|
-
|
64
|
-
|
47
|
+
context 'when valid access token given' do
|
48
|
+
it 'should return an Array of Hash' do
|
49
|
+
mock_fql raw_query, 'query/user/with_valid_token', :access_token => 'valid' do
|
50
|
+
response = query.fetch('valid')
|
51
|
+
response.should == [{'uid' => 579612276}]
|
52
|
+
end
|
53
|
+
end
|
65
54
|
end
|
66
55
|
end
|
67
|
-
|
68
56
|
end
|
@@ -11,21 +11,25 @@ describe FbGraph::Searchable do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe FbGraph::Searchable::Result do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
let :fb_graph do
|
15
|
+
mock_graph :get, 'search?q=fbgraph&type=page', 'pages/search_fb_graph' do
|
16
|
+
FbGraph::Page.search('fbgraph')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
let :google_page2 do
|
20
|
+
mock_graph :get, 'search?limit=25&offset=25&q=google&type=page', 'pages/search_google' do
|
21
|
+
FbGraph::Page.search('google', :limit => 25, :offset => 25)
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
it 'should support pagination' do
|
22
|
-
|
23
|
-
|
26
|
+
fb_graph.next.should == []
|
27
|
+
fb_graph.previous.should == []
|
24
28
|
lambda do
|
25
|
-
|
29
|
+
google_page2.next
|
26
30
|
end.should request_to('search?limit=25&offset=50&q=google&type=page')
|
27
31
|
lambda do
|
28
|
-
|
32
|
+
google_page2.previous
|
29
33
|
end.should request_to('search?limit=25&offset=0&q=google&type=page')
|
30
34
|
end
|
31
35
|
end
|
@@ -24,17 +24,11 @@ describe FbGraph::TestUser, '.friend!' do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'should POST twice' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@u1.friend! @u2
|
33
|
-
end.should request_to('222/friends/111', :post)
|
34
|
-
fake_json(:post, '222/friends/111', 'true')
|
35
|
-
lambda do
|
36
|
-
@u1.friend! @u2
|
37
|
-
end.should_not raise_error(FakeWeb::NetConnectNotAllowedError)
|
27
|
+
mock_graph :post, '111/friends/222', 'true' do
|
28
|
+
mock_graph :post, '222/friends/111', 'true' do
|
29
|
+
@u1.friend! @u2
|
30
|
+
end
|
31
|
+
end
|
38
32
|
end
|
39
33
|
|
40
34
|
end
|
data/spec/fb_graph/user_spec.rb
CHANGED
@@ -32,34 +32,33 @@ describe FbGraph::User, '.me' do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe FbGraph::User, '.fetch' do
|
35
|
-
before do
|
36
|
-
fake_json(:get, 'me', 'users/me_public', :status => [401, 'Unauthorized'])
|
37
|
-
fake_json(:get, 'me?access_token=access_token', 'users/me_private')
|
38
|
-
fake_json(:get, 'arjun', 'users/arjun_public')
|
39
|
-
fake_json(:get, 'arjun?access_token=access_token', 'users/arjun_private')
|
40
|
-
end
|
41
|
-
|
42
35
|
context 'with me context' do
|
43
36
|
|
44
37
|
context 'when no access_token given' do
|
45
38
|
it 'should raise FbGraph::Unauthorized' do
|
46
|
-
|
47
|
-
|
48
|
-
|
39
|
+
mock_graph :get, 'me', 'users/me_public', :status => [401, 'Unauthorized'] do
|
40
|
+
lambda do
|
41
|
+
FbGraph::User.fetch('me')
|
42
|
+
end.should raise_exception(FbGraph::Unauthorized)
|
43
|
+
end
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
52
47
|
context 'when access_token given' do
|
53
48
|
it 'should get current user profile' do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
mock_graph :get, 'me', 'users/me_private', :params => {
|
50
|
+
:access_token => 'access_token'
|
51
|
+
} do
|
52
|
+
user = FbGraph::User.me('access_token').fetch
|
53
|
+
user.interested_in.should == ['female']
|
54
|
+
user.meeting_for.should == ['Friendship', 'Networking']
|
55
|
+
user.relationship_status.should == 'Married'
|
56
|
+
user.website.should == 'http://matake.jp'
|
57
|
+
user.religion.should be_nil
|
58
|
+
user.political.should be_nil
|
59
|
+
user.timezone.should == 9
|
60
|
+
user.verified.should be_true
|
61
|
+
end
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
@@ -67,85 +66,91 @@ describe FbGraph::User, '.fetch' do
|
|
67
66
|
|
68
67
|
context 'when no access_token given' do
|
69
68
|
it 'should get only public profile' do
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
mock_graph :get, 'arjun', 'users/arjun_public' do
|
70
|
+
user = FbGraph::User.fetch('arjun')
|
71
|
+
user.name.should == 'Arjun Banker'
|
72
|
+
user.first_name.should == 'Arjun'
|
73
|
+
user.last_name.should == 'Banker'
|
74
|
+
user.identifier.should == '7901103'
|
75
|
+
user.link.should == 'http://www.facebook.com/Arjun'
|
76
|
+
user.location.should == FbGraph::Page.new(114952118516947, :name => 'San Francisco, California')
|
77
|
+
user.gender.should == 'male'
|
78
|
+
end
|
78
79
|
end
|
79
80
|
end
|
80
81
|
|
81
82
|
context 'when access_token given' do
|
82
83
|
it 'should get public + private profile' do
|
83
|
-
|
84
|
+
mock_graph :get, 'arjun', 'users/arjun_private', :params => {
|
85
|
+
:access_token => 'access_token'
|
86
|
+
} do
|
87
|
+
user = FbGraph::User.fetch('arjun', :access_token => 'access_token')
|
84
88
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
# public
|
90
|
+
user.name.should == 'Arjun Banker'
|
91
|
+
user.first_name.should == 'Arjun'
|
92
|
+
user.last_name.should == 'Banker'
|
93
|
+
user.identifier.should == '7901103'
|
94
|
+
user.link.should == 'http://www.facebook.com/Arjun'
|
95
|
+
user.location.should == FbGraph::Page.new(114952118516947, :name => 'San Francisco, California')
|
96
|
+
user.gender.should == 'male'
|
93
97
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
98
|
+
# private
|
99
|
+
user.about.should == 'daydrea'
|
100
|
+
user.birthday.should == Date.strptime("04/15/1984", "%m/%d/%Y")
|
101
|
+
user.work.should == [
|
102
|
+
FbGraph::Work.new({
|
103
|
+
:employer => {:name => 'Facebook', :id => 20531316728},
|
104
|
+
:position => {:name => 'Software Engineer', :id => 107879555911138},
|
105
|
+
:location => {:name => 'Palo Alto, California', :id => 104022926303756},
|
106
|
+
:start_date => '2007-11'
|
107
|
+
}),
|
108
|
+
FbGraph::Work.new({
|
109
|
+
:employer => {:name => 'Zillow', :id => 113816405300191},
|
110
|
+
:position => {:name => 'Business Intelligence Analyst', :id => 105918922782444},
|
111
|
+
:start_date => '2006-03',
|
112
|
+
:end_date => '2007-10'
|
113
|
+
}),
|
114
|
+
FbGraph::Work.new({
|
115
|
+
:employer => {:name => 'Microsoft', :id => 20528438720},
|
116
|
+
:position => {:name => 'SDET', :id => 110006949022640},
|
117
|
+
:start_date => '2004-08',
|
118
|
+
:end_date => '2006-03'
|
119
|
+
}),
|
120
|
+
FbGraph::Work.new({
|
121
|
+
:employer => {:name => 'Dell', :id => 7706457055},
|
122
|
+
:position => {:name => 'Programmer Analyst', :id => 110344568993267},
|
123
|
+
:start_date => '2003-06',
|
124
|
+
:end_date => '2004-07'
|
125
|
+
})
|
126
|
+
]
|
127
|
+
user.education.should == [
|
128
|
+
FbGraph::Education.new({
|
129
|
+
:school => {:name => 'Texas Academy Of Math And Science', :id => 107922345906866},
|
130
|
+
:year => {:name => '2001', :id => 102241906483610}
|
131
|
+
}),
|
132
|
+
FbGraph::Education.new({
|
133
|
+
:school => {:name => 'The University of Texas at Austin', :id => 24147741537},
|
134
|
+
:year => {:name => '2003', :id => 108077232558120},
|
135
|
+
:concentration => [
|
136
|
+
{:name => 'Computer Science', :id => 116831821660155}
|
137
|
+
]
|
138
|
+
})
|
139
|
+
]
|
140
|
+
user.email.should == nil
|
141
|
+
user.website.should == nil
|
142
|
+
user.hometown.should == FbGraph::Page.new(109533479072558, :name => 'Minnetonka, Minnesota')
|
143
|
+
user.interested_in.should == ['female']
|
144
|
+
user.meeting_for.should == ['Friendship']
|
145
|
+
user.relationship_status.should == 'In a Relationship'
|
146
|
+
user.religion.should == 'zorp'
|
147
|
+
user.political.should == 'Liberal'
|
148
|
+
user.verified.should be_nil
|
149
|
+
# What's this?
|
150
|
+
# user.significant_other
|
151
|
+
user.timezone.should be_nil
|
152
|
+
user.updated_time.should == Time.parse('2010-05-29T04:29:23+0000')
|
153
|
+
end
|
149
154
|
end
|
150
155
|
end
|
151
156
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
|
3
|
+
module WebMockHelper
|
4
|
+
def mock_graph(method, path, response_file, options = {})
|
5
|
+
stub_request(method, endpoint_for(path)).with(
|
6
|
+
request_for(method, options)
|
7
|
+
).to_return(
|
8
|
+
response_for(response_file, options)
|
9
|
+
)
|
10
|
+
res = yield
|
11
|
+
a_request(method, endpoint_for(path)).with(
|
12
|
+
request_for(method, options)
|
13
|
+
).should have_been_made.once
|
14
|
+
res
|
15
|
+
end
|
16
|
+
|
17
|
+
def request_to(path, method = :get)
|
18
|
+
raise_error(WebMock::NetConnectNotAllowedError) { |e|
|
19
|
+
e.message.should include("Unregistered request: #{method.to_s.upcase}")
|
20
|
+
e.message.should include(endpoint_for path)
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def mock_fql(query, file_path, options = {})
|
25
|
+
params = {
|
26
|
+
:query => query,
|
27
|
+
:format => :json
|
28
|
+
}
|
29
|
+
params[:access_token] = options[:access_token] if options[:access_token]
|
30
|
+
stub_request(:get, FbGraph::Query::ENDPOINT).with(:query => params).to_return(
|
31
|
+
:body => File.read(File.join(File.dirname(__FILE__), '../mock_json', "#{file_path}.json"))
|
32
|
+
)
|
33
|
+
res = yield
|
34
|
+
a_request(:get, FbGraph::Query::ENDPOINT).with(:query => params).should have_been_made.once
|
35
|
+
res
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def endpoint_for(path)
|
41
|
+
File.join(FbGraph::ROOT_URL, path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def request_for(method, options = {})
|
45
|
+
request = {}
|
46
|
+
if options[:params]
|
47
|
+
case method
|
48
|
+
when :post, :put
|
49
|
+
request[:body] = options[:params]
|
50
|
+
else
|
51
|
+
request[:query] = options[:params]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
if options[:headers]
|
55
|
+
request[:headers] = options[:headers]
|
56
|
+
end
|
57
|
+
request
|
58
|
+
end
|
59
|
+
|
60
|
+
def response_for(response_file, options = {})
|
61
|
+
response = {}
|
62
|
+
response[:body] = File.new(File.join(File.dirname(__FILE__), '../mock_json', "#{response_file}.json"))
|
63
|
+
if options[:status]
|
64
|
+
response[:status] = options[:status]
|
65
|
+
end
|
66
|
+
response
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
include WebMockHelper
|
71
|
+
WebMock.disable_net_connect!
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|