mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
page spec
This commit is contained in:
parent
113d51bdfc
commit
4befaaee82
4 changed files with 110 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
module FbGraph2
|
||||
class Collection < Array
|
||||
attr_accessor :before, :after, :next, :previous, :order, :total_count
|
||||
attr_accessor :before, :after, :next, :previous, :order, :total_count, :summary
|
||||
|
||||
def initialize(collection = [])
|
||||
collection = normalize collection
|
||||
|
@ -34,6 +34,7 @@ module FbGraph2
|
|||
end
|
||||
|
||||
def summarize(summary)
|
||||
self.summary = summary
|
||||
self.order = summary.try(:[], :order)
|
||||
self.total_count = summary.try(:[], :total_count)
|
||||
end
|
||||
|
|
61
spec/fb_graph2/page_spec.rb
Normal file
61
spec/fb_graph2/page_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe FbGraph2::Page do
|
||||
context 'with optional fields' do
|
||||
subject { page }
|
||||
let(:page) do
|
||||
attributes = mock_json 'page/with_optional_fields'
|
||||
FbGraph2::Page.new attributes[:id], attributes
|
||||
end
|
||||
|
||||
describe '#context' do
|
||||
subject { page.context }
|
||||
it { should be_instance_of FbGraph2::Struct::Context::PageContext }
|
||||
|
||||
describe 'friends_who_like' do
|
||||
subject { page.context.friends_who_like }
|
||||
it { should be_instance_of FbGraph2::Collection }
|
||||
it { should be_blank }
|
||||
its(:total_count) { should == 14 }
|
||||
its(:summary) { should include :social_sentence }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#parking' do
|
||||
subject { page.parking }
|
||||
[:street, :lot, :valet].each do |key|
|
||||
its(key) { should == false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#restaurant_services' do
|
||||
subject { page.restaurant_services }
|
||||
[:kids, :delivery, :catering, :waiter, :outdoor, :takeout].each do |key|
|
||||
its(key) { should == false }
|
||||
end
|
||||
[:groups, :reserve, :walkins].each do |key|
|
||||
its(key) { should == true }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#restaurant_specialties' do
|
||||
subject { page.restaurant_specialties }
|
||||
[:coffee, :drinks, :breakfast, :lunch].each do |key|
|
||||
its(key) { should == false }
|
||||
end
|
||||
[:dinner].each do |key|
|
||||
its(key) { should == true }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#payment_options' do
|
||||
subject { page.payment_options }
|
||||
[:cash_only, :discover].each do |key|
|
||||
its(key) { should == false }
|
||||
end
|
||||
[:amex, :mastercard, :visa].each do |key|
|
||||
its(key) { should == true }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,11 +1,9 @@
|
|||
{
|
||||
"data": [
|
||||
{
|
||||
"name": "Jr Nov",
|
||||
"id": "1575327134"
|
||||
}
|
||||
],
|
||||
"data": [{
|
||||
"name": "Jr Nov",
|
||||
"id": "1575327134"
|
||||
}],
|
||||
"paging": {
|
||||
"next": "https://graph.facebook.com/v2.0/117513961602338/blocked?limit=5000&offset=5000&__after_id=enc_AewU3hSo5zqbS5KA0i0lJYmPrLn57SMSo645aYB7BTPg1PSawPvlM9mRI_3Y_dcpeDI"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
42
spec/mock_json/page/with_optional_fields.json
Normal file
42
spec/mock_json/page/with_optional_fields.json
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"context": {
|
||||
"friends_who_like": {
|
||||
"data": [],
|
||||
"summary": {
|
||||
"social_sentence": "14 of your friends like this.",
|
||||
"total_count": 14
|
||||
}
|
||||
}
|
||||
},
|
||||
"parking": {
|
||||
"lot": 0,
|
||||
"street": 0,
|
||||
"valet": 0
|
||||
},
|
||||
"restaurant_services": {
|
||||
"delivery": 0,
|
||||
"catering": 0,
|
||||
"groups": 1,
|
||||
"kids": 0,
|
||||
"outdoor": 0,
|
||||
"reserve": 1,
|
||||
"takeout": 0,
|
||||
"waiter": 0,
|
||||
"walkins": 1
|
||||
},
|
||||
"restaurant_specialties": {
|
||||
"breakfast": 0,
|
||||
"coffee": 0,
|
||||
"dinner": 1,
|
||||
"drinks": 0,
|
||||
"lunch": 0
|
||||
},
|
||||
"payment_options": {
|
||||
"amex": 1,
|
||||
"cash_only": 0,
|
||||
"discover": 0,
|
||||
"mastercard": 1,
|
||||
"visa": 1
|
||||
},
|
||||
"id": "139296106095829"
|
||||
}
|
Loading…
Add table
Reference in a new issue