From d782d6d3505324c20753afcd424aab24a934944a Mon Sep 17 00:00:00 2001 From: nov Date: Mon, 1 Sep 2014 18:49:48 +0900 Subject: [PATCH] App#banned?, App#ban! and App#unban!, and app specs --- lib/fb_graph2/edge/banned.rb | 17 ++++++++ spec/fb_graph2/edge/banned_spec.rb | 60 +++++++++++++++++++++++++++++ spec/fb_graph2/edge/blocked_spec.rb | 2 +- spec/fb_graph2/edge/roles_spec.rb | 20 ++++++++++ spec/fb_graph2/page_spec.rb | 14 +++---- spec/mock_json/app/banned.json | 12 ++++++ spec/mock_json/app/roles.json | 10 +++++ 7 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 spec/fb_graph2/edge/banned_spec.rb create mode 100644 spec/fb_graph2/edge/roles_spec.rb create mode 100644 spec/mock_json/app/banned.json create mode 100644 spec/mock_json/app/roles.json diff --git a/lib/fb_graph2/edge/banned.rb b/lib/fb_graph2/edge/banned.rb index d6620e2..d0df340 100644 --- a/lib/fb_graph2/edge/banned.rb +++ b/lib/fb_graph2/edge/banned.rb @@ -7,6 +7,23 @@ module FbGraph2 User.new(user[:id], user).authenticate self.access_token end end + + def banned?(user, params = {}) + users = self.edge :banned, params, edge_scope: user + users.present? + end + + def ban!(user, params = {}) + self.post params.merge( + uid: Util.as_identifier(user) + ), edge: :banned + end + + def unban!(user, params = {}) + self.delete params.merge( + uid: Util.as_identifier(user) + ), edge: :banned + end end end end \ No newline at end of file diff --git a/spec/fb_graph2/edge/banned_spec.rb b/spec/fb_graph2/edge/banned_spec.rb new file mode 100644 index 0000000..a384fe1 --- /dev/null +++ b/spec/fb_graph2/edge/banned_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Banned do + context 'included in App' do + let(:app) { FbGraph2::App.app('app_token') } + let(:user_id) { 'user_id' } + let(:user) { FbGraph2::User.new(user_id) } + + describe '#banned' do + it 'should return an Array of FbGraph2::User' do + users = mock_graph :get, 'app/banned', 'app/banned', access_token: 'app_token' do + app.banned + 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 + + describe '#banned?' do + context 'when String given' do + it do + mock_graph :get, "app/banned/#{user_id}", 'app/banned', access_token: 'app_token' do + app.banned? user_id + end.should be true + end + end + + context 'when FbGraph2::User given' do + it do + mock_graph :get, "app/banned/#{user_id}", 'app/banned', access_token: 'app_token' do + app.banned? user + end.should be true + end + end + end + + describe '#ban!' do + it do + mock_graph :post, 'app/banned', 'true', access_token: 'app_token', params: { + uid: user_id + } do + app.ban! user + end.should be true + end + end + + describe '#unban!' do + it do + mock_graph :delete, 'app/banned', 'true', access_token: 'app_token', params: { + uid: user_id + } do + app.unban! user + end.should be true + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/blocked_spec.rb b/spec/fb_graph2/edge/blocked_spec.rb index 060f634..a25779d 100644 --- a/spec/fb_graph2/edge/blocked_spec.rb +++ b/spec/fb_graph2/edge/blocked_spec.rb @@ -4,7 +4,7 @@ describe FbGraph2::Edge::Blocked do context 'included in Page' do let(:page) { FbGraph2::Page.new('page_id').authenticate('page_token') } let(:user_id) { 'user_id' } - let(:user) { FbGraph2::Page.new(user_id) } + let(:user) { FbGraph2::User.new(user_id) } describe '#blocked' do it 'should return an Array of FbGraph2::User' do diff --git a/spec/fb_graph2/edge/roles_spec.rb b/spec/fb_graph2/edge/roles_spec.rb new file mode 100644 index 0000000..2cd4dba --- /dev/null +++ b/spec/fb_graph2/edge/roles_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Roles do + context 'included in App' do + let(:app) { FbGraph2::App.app('app_token') } + + describe '#roles' do + it 'should return an Array of FbGraph2::Struct::Role' do + roles = mock_graph :get, 'app/roles', 'app/roles', access_token: 'app_token' do + app.roles + end + roles.should be_instance_of FbGraph2::Edge + roles.should_not be_blank + roles.each do |role| + role.should be_instance_of FbGraph2::Struct::Role + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/page_spec.rb b/spec/fb_graph2/page_spec.rb index 33ac439..277f677 100644 --- a/spec/fb_graph2/page_spec.rb +++ b/spec/fb_graph2/page_spec.rb @@ -24,37 +24,37 @@ describe FbGraph2::Page do describe '#parking' do subject { page.parking } [:street, :lot, :valet].each do |key| - its(key) { should == false } + its(key) { should be false } end end describe '#restaurant_services' do subject { page.restaurant_services } [:kids, :delivery, :catering, :waiter, :outdoor, :takeout].each do |key| - its(key) { should == false } + its(key) { should be false } end [:groups, :reserve, :walkins].each do |key| - its(key) { should == true } + its(key) { should be true } end end describe '#restaurant_specialties' do subject { page.restaurant_specialties } [:coffee, :drinks, :breakfast, :lunch].each do |key| - its(key) { should == false } + its(key) { should be false } end [:dinner].each do |key| - its(key) { should == true } + its(key) { should be true } end end describe '#payment_options' do subject { page.payment_options } [:cash_only, :discover].each do |key| - its(key) { should == false } + its(key) { should be false } end [:amex, :mastercard, :visa].each do |key| - its(key) { should == true } + its(key) { should be true } end end end diff --git a/spec/mock_json/app/banned.json b/spec/mock_json/app/banned.json new file mode 100644 index 0000000..7247a9b --- /dev/null +++ b/spec/mock_json/app/banned.json @@ -0,0 +1,12 @@ +{ + "data": [{ + "id": "100003934202581", + "name": "Open Graph Test User" + }], + "paging": { + "cursors": { + "before": "MTAwMDAzOTM0MjAyNTgx", + "after": "MTAwMDAzOTM0MjAyNTgx" + } + } +} diff --git a/spec/mock_json/app/roles.json b/spec/mock_json/app/roles.json new file mode 100644 index 0000000..c2cf38c --- /dev/null +++ b/spec/mock_json/app/roles.json @@ -0,0 +1,10 @@ +{ + "data": [{ + "app_id": "210798282372757", + "user": "579612276", + "role": "administrators" + }], + "paging": { + "next": "https://graph.facebook.com/v2.1/210798282372757/roles?limit=5000&offset=5000&__after_id=enc_AezKeljwOb-ajJmD2AAQnxKG4ppLUt__oG9ScW9Um9PcjIxWf1zs1-LbrM8skz4rDAVCAQxs3SO_-GeS6OnwPJNA" + } +}