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

more spec

This commit is contained in:
nov 2014-06-03 15:53:28 +09:00
parent 805ea39ca6
commit 47d008c23a
9 changed files with 153 additions and 3 deletions

View file

@ -13,7 +13,9 @@ module FbGraph2
def initialize(id, attributes = {})
super
# TODO: handle custom attributes.
if attributes.include? :data
self.data = attributes[:data]
end
end
end
end

View file

@ -40,7 +40,7 @@ module FbGraph2
def initialize(id, attributes = {})
super
if attributes.include? :category_list
attributes[:category_list].collect do |page_category|
self.category_list = attributes[:category_list].collect do |page_category|
PageCategory.new page_category[:id], page_category
end
end

View file

@ -0,0 +1,23 @@
require 'spec_helper'
describe FbGraph2::User do
describe '.app' do
let(:klass) { FbGraph2::Application }
it 'should not call API' do
expect do
app = klass.app 'token'
app.should be_instance_of klass
end.not_to request_to 'app'
end
context 'when fetched' do
it 'should call API' do
app = mock_graph :get, 'app', 'application/app' do
klass.app('token').fetch
end
app.should be_instance_of klass
end
end
end
end

View file

@ -0,0 +1,18 @@
require 'spec_helper'
describe FbGraph2::Edge::Achievements do
context 'included in User' do
describe '#achievements' do
let(:me) { FbGraph2::User.me('token') }
it 'should return an Array of FbGraph2::Achievement with page token' do
pages = mock_graph :get, 'me/achievements', 'user/achievements', access_token: 'token' do
me.achievements
end
pages.should_not be_blank
pages.each do |page|
page.should be_instance_of FbGraph2::Achievement
end
end
end
end
end

View file

@ -0,0 +1,33 @@
require 'spec_helper'
describe FbGraph2::RequestFilter::Debugger do
let(:resource_endpoint) { 'https://graph.facebook.com/matake' }
let(:request) { HTTP::Message.new_request(:get, URI.parse(resource_endpoint)) }
let(:response) { HTTP::Message.new_response({:hello => 'world'}.to_json) }
let(:request_filter) { FbGraph2::RequestFilter::Debugger.new }
describe '#filter_request' do
it 'should log request' do
[
"======= [FbGraph2] API REQUEST STARTED =======",
request.dump
].each do |output|
FbGraph2.logger.should_receive(:info).with output
end
request_filter.filter_request(request)
end
end
describe '#filter_response' do
it 'should log response' do
[
"--------------------------------------------------",
response.dump,
"======= [FbGraph2] API REQUEST FINISHED ======="
].each do |output|
FbGraph2.logger.should_receive(:info).with output
end
request_filter.filter_response(request, response)
end
end
end

View file

@ -14,7 +14,7 @@ describe FbGraph2::User do
context 'when fetched' do
it 'should call API' do
me = mock_graph :get, 'me', 'user/me' do
FbGraph2::User.me('token').fetch
klass.me('token').fetch
end
me.should be_instance_of klass
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe FbGraph2::Util do
describe '.as_identifier' do
context 'when FbGraph2::Node given' do
it do
FbGraph2::Util.as_identifier(
FbGraph2::Node.new 'object_id'
).should == 'object_id'
end
end
context 'when String given' do
it do
FbGraph2::Util.as_identifier('object_id').should == 'object_id'
end
end
end
end

View file

@ -0,0 +1,15 @@
{
"category": "Business",
"daily_active_users": "10000",
"daily_active_users_rank": 1215,
"description": "A tool to help browse objects within the Facebook Graph API, manage permissions, obtain access tokens and learn how it all works.",
"icon_url": "https://fbcdn-photos-a-a.akamaihd.net/hphotos-ak-xpa1/t39.2081-0/851576_646264348772288_612357246_n.png",
"link": "https://www.facebook.com/apps/application.php?id=145634995501895",
"logo_url": "https://fbcdn-photos-a-a.akamaihd.net/hphotos-ak-xpa1/t39.2081-0/p75x75/851563_646263475439042_787584105_n.png",
"monthly_active_users": "500000",
"monthly_active_users_rank": 432,
"name": "Graph API Explorer",
"subcategory": "General",
"weekly_active_users": "100000",
"id": "145634995501895"
}

View file

@ -0,0 +1,40 @@
{
"data": [{
"id": "10150407675002277",
"from": {
"id": "579612276",
"name": "Nov Matake"
},
"start_time": "2011-11-09T08:04:58+0000",
"end_time": "2011-11-09T08:04:58+0000",
"publish_time": "2011-11-09T08:04:58+0000",
"application": {
"name": "gem sample",
"namespace": "fbgraphsample",
"id": "134145643294322"
},
"data": {
"achievement": {
"id": "10150310611431721",
"url": "http://fbgraphsample.heroku.com/achievements/1",
"type": "game.achievement",
"title": "1st Achievement"
}
},
"type": "games.achieves",
"no_feed_story": false,
"likes": {
"count": 0,
"can_like": true,
"user_likes": false
},
"comments": {
"count": 0,
"can_comment": true,
"comment_order": "chronological"
}
}],
"paging": {
"next": "https://graph.facebook.com/v2.0/579612276/achievements?limit=25&offset=25&__after_id=enc_AeyhCSdwSdwIMz2Kbpibnp2MZgYC1gasXThstsCJgxJdxwL9V_ss1OPBDnrxUgpTqAe1QOHjq-un-45-IJXJFrLv"
}
}