mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
likes & comments test
This commit is contained in:
parent
ffae61e531
commit
a8502fbb8f
9 changed files with 158 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
|||
module FbGraph2
|
||||
class Edge
|
||||
module Comments
|
||||
def initialize(id, attributes)
|
||||
def assign(attributes)
|
||||
super
|
||||
if attributes.include?(:comments)
|
||||
@_cached_comments = Collection.new attributes[:comments]
|
||||
|
|
|
@ -16,7 +16,7 @@ module FbGraph2
|
|||
end
|
||||
|
||||
module LikeeContext
|
||||
def initialize(id, attributes)
|
||||
def assign(attributes)
|
||||
super
|
||||
if attributes.include?(:likes)
|
||||
@_cached_likes = Collection.new attributes[:likes]
|
||||
|
|
|
@ -28,6 +28,29 @@ describe FbGraph2::Edge::Comments do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'otherwise' do
|
||||
it 'should return an Array of FbGraph2::Post' do
|
||||
comments = mock_graph :get, 'post_id/comments', 'post/comments', access_token: 'token' do
|
||||
post.comments
|
||||
end
|
||||
comments.should_not be_blank
|
||||
comments.each do |comment|
|
||||
comment.should be_instance_of FbGraph2::Comment
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#comment!' do
|
||||
it 'should return FbGraph2::Post with posted params' do
|
||||
comment = mock_graph :post, 'post_id/comments', 'success_with_id', access_token: 'token' do
|
||||
post.comment! message: 'hello'
|
||||
end
|
||||
comment.should be_instance_of FbGraph2::Comment
|
||||
comment.id.should == 'created_object_id'
|
||||
comment.message.should == 'hello'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,7 +16,7 @@ describe FbGraph2::Edge::Feed do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'feed!' do
|
||||
describe '#feed!' do
|
||||
it 'should return FbGraph2::Post with posted params' do
|
||||
post = mock_graph :post, 'me/feed', 'success_with_id', access_token: 'token' do
|
||||
me.feed! message: 'hello'
|
||||
|
|
|
@ -1,10 +1,44 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FbGraph2::Edge::Likes do
|
||||
context 'included in User' do
|
||||
let(:me) { FbGraph2::User.me('token') }
|
||||
|
||||
describe '#likes' do
|
||||
it 'should return an Array of FbGraph2::Page' do
|
||||
likes = mock_graph :get, 'me/likes', 'user/likes', access_token: 'token' do
|
||||
me.likes
|
||||
end
|
||||
likes.should_not be_blank
|
||||
likes.each do |like|
|
||||
like.should be_instance_of FbGraph2::Page
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#liked?' do
|
||||
context 'liked' do
|
||||
it do
|
||||
mock_graph :get, 'me/likes/page_id', 'user/likes', access_token: 'token' do
|
||||
me.liked? 'page_id'
|
||||
end.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context 'otherwise' do
|
||||
it do
|
||||
mock_graph :get, 'me/likes/page_id', 'blank_collection', access_token: 'token' do
|
||||
me.liked? 'page_id'
|
||||
end.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'included in Post' do
|
||||
let(:post) { FbGraph2::Post.new('post_id').authenticate('token') }
|
||||
|
||||
describe '#comments' do
|
||||
describe '#likes' do
|
||||
context 'when cached' do
|
||||
let(:fetched) do
|
||||
mock_graph :get, 'post_id', 'post/liked_and_commented', access_token: 'token' do
|
||||
|
@ -28,6 +62,34 @@ describe FbGraph2::Edge::Likes do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'otherwise' do
|
||||
it 'should return an Array of FbGraph2::User' do
|
||||
likes = mock_graph :get, 'post_id/likes', 'post/likes', access_token: 'token' do
|
||||
post.likes
|
||||
end
|
||||
likes.should_not be_blank
|
||||
likes.each do |like|
|
||||
like.should be_instance_of FbGraph2::User
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#like!' do
|
||||
it 'should return true' do
|
||||
mock_graph :post, 'post_id/likes', 'true', access_token: 'token' do
|
||||
post.like!
|
||||
end.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unlike!' do
|
||||
it 'should return true' do
|
||||
mock_graph :delete, 'post_id/likes', 'true', access_token: 'token' do
|
||||
post.unlike!
|
||||
end.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1
spec/mock_json/blank_collection.json
Normal file
1
spec/mock_json/blank_collection.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"data":[]}
|
20
spec/mock_json/post/comments.json
Normal file
20
spec/mock_json/post/comments.json
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"data": [{
|
||||
"id": "10152461220962277_10152461646087277",
|
||||
"from": {
|
||||
"id": "789665437731725",
|
||||
"name": "Toyoaki Ohgochi"
|
||||
},
|
||||
"message": "....ポイントも付きますよ....",
|
||||
"can_remove": true,
|
||||
"created_time": "2014-05-24T15:05:57+0000",
|
||||
"like_count": 0,
|
||||
"user_likes": false
|
||||
}],
|
||||
"paging": {
|
||||
"cursors": {
|
||||
"after": "MQ==",
|
||||
"before": "MQ=="
|
||||
}
|
||||
}
|
||||
}
|
15
spec/mock_json/post/likes.json
Normal file
15
spec/mock_json/post/likes.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"data": [{
|
||||
"id": "689134294485152",
|
||||
"name": "Shunya Iriki"
|
||||
}, {
|
||||
"id": "1486426304903512",
|
||||
"name": "Masato Nagai"
|
||||
}],
|
||||
"paging": {
|
||||
"cursors": {
|
||||
"after": "MTQ4NjQyNjMwNDkwMzUxMg==",
|
||||
"before": "Njg5MTM0Mjk0NDg1MTUy"
|
||||
}
|
||||
}
|
||||
}
|
33
spec/mock_json/user/likes.json
Normal file
33
spec/mock_json/user/likes.json
Normal file
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"data": [{
|
||||
"category": "Business/economy website",
|
||||
"name": "デザイナーズSOHOオフィスなら【SOHO東京】",
|
||||
"created_time": "2014-04-27T07:42:29+0000",
|
||||
"id": "140108926038346"
|
||||
}, {
|
||||
"category": "Real estate",
|
||||
"category_list": [{
|
||||
"id": "198327773511962",
|
||||
"name": "Real Estate"
|
||||
}],
|
||||
"name": "ジョイライフスタイル",
|
||||
"created_time": "2014-04-05T15:26:28+0000",
|
||||
"id": "117500321741291"
|
||||
}, {
|
||||
"category": "Internet/software",
|
||||
"category_list": [{
|
||||
"id": "2256",
|
||||
"name": "Internet/Software"
|
||||
}],
|
||||
"name": "Engineerrise",
|
||||
"created_time": "2014-03-28T14:32:31+0000",
|
||||
"id": "565244630160593"
|
||||
}],
|
||||
"paging": {
|
||||
"cursors": {
|
||||
"after": "MzY3OTg5NTQzMjU5NzU3",
|
||||
"before": "MTQwMTA4OTI2MDM4MzQ2"
|
||||
},
|
||||
"next": "https://graph.facebook.com/v2.0/579612276/likes?limit=25&after=MzY3OTg5NTQzMjU5NzU3"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue