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