1
0
Fork 0
mirror of https://github.com/nov/fb_graph2 synced 2023-03-27 23:22:15 -04:00

spec spec spec

This commit is contained in:
nov 2014-09-02 13:45:04 +09:00
parent d782d6d350
commit 1c58cb060e
17 changed files with 211 additions and 13 deletions

View file

@ -1,6 +1,6 @@
module FbGraph2
class Collection < Array
attr_accessor :before, :after, :next, :previous, :order, :total_count, :summary
attr_accessor :before, :after, :next, :previous, :total_count, :summary
def initialize(collection = [])
collection = normalize collection
@ -35,8 +35,10 @@ module FbGraph2
def summarize(summary)
self.summary = summary
self.order = summary.try(:[], :order)
self.total_count = summary.try(:[], :total_count)
if summary.try(:[], :updated_time)
self.summary[:updated_time] = Time.parse summary[:updated_time]
end
end
def params_in(url)

View file

@ -1,7 +1,7 @@
module FbGraph2
class Edge < Collection
attr_accessor :owner, :edge, :params, :options, :collection
delegate :order, :total_count, to: :collection
delegate :summary, :total_count, to: :collection
def initialize(owner, edge, params = {}, options = {})
self.owner = owner

View file

@ -1,7 +1,5 @@
module FbGraph2
class FriendList < Node
include Edge::Members
register_attributes(
raw: [:name, :list_type]
)

View file

@ -47,6 +47,8 @@ module FbGraph2
:relationship,
# NOTE: in page admin context
:perms, :role,
# NOTE: in group context
:administrator,
# NOTE: in photo tags context
:x, :y
],

View file

@ -49,7 +49,7 @@ describe FbGraph2::Edge::Comments do
} do
post.comments(summary: true)
end
comments.order.should == 'chronological'
comments.summary.should include order: 'chronological', total_count: 4
comments.total_count.should == 4
end
end

View file

@ -0,0 +1,20 @@
require 'spec_helper'
describe FbGraph2::Edge::Inbox do
context 'included in User' do
describe '#inbox' do
let(:me) { FbGraph2::User.me('token') }
it 'should return an Array of FbGraph2::Thread' do
threads = mock_graph :get, 'me/inbox', 'user/inbox', access_token: 'token' do
me.inbox
end
threads.should be_instance_of FbGraph2::Edge
threads.should_not be_blank
threads.each do |thread|
thread.should be_instance_of FbGraph2::Thread
end
threads.summary.should include unseen_count: 0, unread_count: 0, updated_time: Time.parse('2014-09-02T03:51:40+0000')
end
end
end
end

View file

@ -0,0 +1,21 @@
require 'spec_helper'
describe FbGraph2::Edge::Members do
context 'included in Group' do
let(:group) { FbGraph2::Group.new('group_id').authenticate('token') }
describe '#invited' do
it 'should return an Array of FbGraph2::User' do
users = mock_graph :get, 'group_id/members', 'group/members', access_token: 'token' do
group.members
end
users.should be_instance_of FbGraph2::Edge
users.should_not be_blank
users.each do |user|
user.should be_instance_of FbGraph2::User
end
users.last.administrator.should be true
end
end
end
end

View file

@ -0,0 +1,20 @@
require 'spec_helper'
describe FbGraph2::Edge::Noreply do
context 'included in Event' do
let(:event) { FbGraph2::Event.new('event_id').authenticate('token') }
describe '#noreply' do
it 'should return an Array of FbGraph2::User' do
users = mock_graph :get, 'event_id/noreply', 'event/noreply', access_token: 'token' do
event.noreply
end
users.should be_instance_of FbGraph2::Edge
users.should_not be_blank
users.each do |user|
user.should be_instance_of FbGraph2::User
end
end
end
end
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe FbGraph2::Edge::Outbox do
context 'included in User' do
describe '#outbox' do
let(:me) { FbGraph2::User.me('token') }
it 'should return an Array of FbGraph2::Thread' do
threads = mock_graph :get, 'me/outbox', 'user/outbox', access_token: 'token' do
me.outbox
end
threads.should be_instance_of FbGraph2::Edge
threads.should_not be_blank
threads.each do |thread|
thread.should be_instance_of FbGraph2::Thread
end
end
end
end
end

View file

@ -16,7 +16,7 @@ describe FbGraph2::Edge do
describe 'summary' do
subject { comments }
its(:order) { should == 'chronological' }
its(:summary) { should include order: 'chronological', total_count: 4 }
its(:total_count) { should == 4 }
end

View file

@ -0,0 +1,17 @@
{
"data": [{
"name": "Akira Otaishi",
"rsvp_status": "attending",
"id": "553375548107883"
}, {
"name": "Shin-ichiro Kagaya",
"rsvp_status": "attending",
"id": "241546062702044"
}],
"paging": {
"cursors": {
"after": "TVRBd01EQXdNRFl6TWpjME1qSTBPakUwTVRBMU1UQTJNREE2TVRZMU1EZzBPRGsyT0RRNE5UZ3g=",
"before": "TVRBd01EQXpNRFl6TWpjM01qTXhPakUwTVRBMU1UQTJNREE2TVRjMk9UQTRNVE0xTmpnM09UWXg="
}
}
}

View file

@ -0,0 +1,22 @@
{
"data": [
{
"name": "Hayashi Tatsuya",
"administrator": false,
"id": "10152167763779825"
},
{
"name": "Ryo Ito",
"administrator": false,
"id": "10203204372262716"
},
{
"name": "Nov Matake",
"administrator": true,
"id": "579612276"
}
],
"paging": {
"next": "https://graph.facebook.com/v2.1/343659285716553/members?limit=5000&offset=5000&__after_id=***"
}
}

View file

@ -10,7 +10,7 @@
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.0/579612276/events?limit=25&since=1402653600&__paging_token=enc_AezFmlDRX4GTGnTULSAcMS7GEDiK296BwTlhQLHgty6ocPG7F6tHzNZgysABJrSyXW0Xxv4A9f87zl1ii9B02tZ7",
"next": "https://graph.facebook.com/v2.0/579612276/events?limit=25&until=1402653600&__paging_token=enc_AexwobcxwDuR9BhmbM29GnNdQn7phvKIQGLtI-NeCFjlSP3uU6NeNGi10PTwl64OrNADgtn8PBNbJDsRwXGV1dg_"
"previous": "https://graph.facebook.com/v2.0/579612276/events?limit=25&since=1402653600&__paging_token=***",
"next": "https://graph.facebook.com/v2.0/579612276/events?limit=25&until=1402653600&__paging_token=***"
}
}

View file

@ -0,0 +1,41 @@
{
"data": [{
"id": "741737742539677",
"to": {
"data": [{
"id": "579612276",
"name": "Nov Matake"
}, {
"id": "10152167763779825",
"name": "Hayashi Tatsuya"
}]
},
"updated_time": "2014-09-02T03:51:40+0000",
"unread": 0,
"unseen": 0,
"comments": {
"data": [{
"id": "741737742539677_1409625688",
"from": {
"id": "579612276",
"name": "Nov Matake"
},
"message": "ヒゲキョクチョ",
"created_time": "2014-09-02T02:41:28+0000"
}],
"paging": {
"previous": "https://graph.facebook.com/v2.1/741737742539677/comments?limit=25&since=1409629900&__paging_token=***",
"next": "https://graph.facebook.com/v2.1/741737742539677/comments?limit=25&until=1409625439&__paging_token=***"
}
}
}],
"paging": {
"previous": "https://graph.facebook.com/v2.1/579612276/inbox?limit=25&since=1409629900&__paging_token=***",
"next": "https://graph.facebook.com/v2.1/579612276/inbox?limit=25&until=1403524175&__paging_token=***"
},
"summary": {
"unseen_count": 0,
"unread_count": 0,
"updated_time": "2014-09-02T03:51:40+0000"
}
}

View file

@ -39,7 +39,7 @@
"unread": 1
}],
"paging": {
"previous": "https://graph.facebook.com/v2.1/579612276/notifications?limit=5000&since=1409272999&__paging_token=enc_Aewp7NBZ5fIN12MTyeJziuFNDceCydTGsvVqg-hwrjPZBCnWi-W_fjsS1bNaXkZ9K-tS8wFhFQw4pOajivn20h3c",
"next": "https://graph.facebook.com/v2.1/579612276/notifications?limit=5000&until=1408919679&__paging_token=enc_Aey6fAeKsVGCSCKsplC0g1FGjchGgmGajndTVwb-tzE0q7A8nT6C_1iVdwBRzXWdt3zKHh3yOjq6caxNtsTrD58s"
"previous": "https://graph.facebook.com/v2.1/579612276/notifications?limit=5000&since=1409272999&__paging_token=***",
"next": "https://graph.facebook.com/v2.1/579612276/notifications?limit=5000&until=1408919679&__paging_token=***"
}
}

View file

@ -0,0 +1,36 @@
{
"data": [{
"id": "741737742539677",
"to": {
"data": [{
"id": "579612276",
"name": "Nov Matake"
}, {
"id": "10152167763779825",
"name": "Hayashi Tatsuya"
}]
},
"updated_time": "2014-09-02T03:51:40+0000",
"unread": 0,
"unseen": 0,
"comments": {
"data": [{
"id": "741737742539677_1409625688",
"from": {
"id": "579612276",
"name": "Nov Matake"
},
"message": "ヒゲキョクチョ",
"created_time": "2014-09-02T02:41:28+0000"
}],
"paging": {
"previous": "https://graph.facebook.com/v2.1/741737742539677/comments?limit=25&since=1409629900&__paging_token=***",
"next": "https://graph.facebook.com/v2.1/741737742539677/comments?limit=25&until=1409625439&__paging_token=***"
}
}
}],
"paging": {
"previous": "https://graph.facebook.com/v2.1/579612276/outbox?limit=25&since=1409629900&__paging_token=***",
"next": "https://graph.facebook.com/v2.1/579612276/outbox?limit=25&until=1403014440&__paging_token=***"
}
}

View file

@ -9,7 +9,7 @@
"updated_time": "2014-06-03T06:27:20+0000"
}],
"paging": {
"previous": "https://graph.facebook.com/v2.0/579612276/statuses?limit=25&since=1401776840&__paging_token=enc_Aex8IwVNSggYJw8M6QIUUCJvf2TcGZpItipsxeT2NUupXAxD-01jC8oRxhDe9gGnJD-vMkN1tDEUjTuE83vcaIpq",
"next": "https://graph.facebook.com/v2.0/579612276/statuses?limit=25&until=1384770778&__paging_token=enc_AewaF0Qo-zXVeD8fMKMQBs0GKoqDw6LXxOZhyn2z9HqW7_NBd1IvqlGOXrrL7DPpJNvx1A8-0G0_pf_OauViIb3I"
"previous": "https://graph.facebook.com/v2.0/579612276/statuses?limit=25&since=1401776840&__paging_token=***",
"next": "https://graph.facebook.com/v2.0/579612276/statuses?limit=25&until=1384770778&__paging_token=***"
}
}