mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
App#banned?, App#ban! and App#unban!, and app specs
This commit is contained in:
parent
d5d740fa5c
commit
d782d6d350
7 changed files with 127 additions and 8 deletions
|
@ -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
|
60
spec/fb_graph2/edge/banned_spec.rb
Normal file
60
spec/fb_graph2/edge/banned_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
20
spec/fb_graph2/edge/roles_spec.rb
Normal file
20
spec/fb_graph2/edge/roles_spec.rb
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
12
spec/mock_json/app/banned.json
Normal file
12
spec/mock_json/app/banned.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"data": [{
|
||||
"id": "100003934202581",
|
||||
"name": "Open Graph Test User"
|
||||
}],
|
||||
"paging": {
|
||||
"cursors": {
|
||||
"before": "MTAwMDAzOTM0MjAyNTgx",
|
||||
"after": "MTAwMDAzOTM0MjAyNTgx"
|
||||
}
|
||||
}
|
||||
}
|
10
spec/mock_json/app/roles.json
Normal file
10
spec/mock_json/app/roles.json
Normal file
|
@ -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"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue