diff --git a/fb_graph2.gemspec b/fb_graph2.gemspec index 5f03e4a..b94bdd8 100644 --- a/fb_graph2.gemspec +++ b/fb_graph2.gemspec @@ -20,5 +20,6 @@ Gem::Specification.new do |gem| gem.add_development_dependency 'rake' gem.add_development_dependency 'simplecov' gem.add_development_dependency 'webmock' - gem.add_development_dependency 'rspec', '>= 2' + gem.add_development_dependency 'rspec' + gem.add_development_dependency 'rspec-its' end diff --git a/lib/fb_graph2/collection.rb b/lib/fb_graph2/collection.rb index 14f7cd8..3ddfa43 100644 --- a/lib/fb_graph2/collection.rb +++ b/lib/fb_graph2/collection.rb @@ -2,7 +2,7 @@ module FbGraph2 class Collection < Array attr_reader :previous, :next, :total_count, :unread_count, :updated_time, :cursors - def initialize(collection = nil) + def initialize(collection) collection = case collection when Hash collection diff --git a/lib/fb_graph2/edge/albums.rb b/lib/fb_graph2/edge/albums.rb index a50c19a..ab5c4bd 100644 --- a/lib/fb_graph2/edge/albums.rb +++ b/lib/fb_graph2/edge/albums.rb @@ -7,6 +7,11 @@ module FbGraph2 Album.new(album[:id], album).authenticate self.access_token end end + + def album!(params = {}) + album = self.post params, edge: :albums + Album.new(album[:id], params.merge(album)).authenticate self.access_token + end end end end \ No newline at end of file diff --git a/lib/fb_graph2/edge/blocked.rb b/lib/fb_graph2/edge/blocked.rb index 21f816a..6cfebf8 100644 --- a/lib/fb_graph2/edge/blocked.rb +++ b/lib/fb_graph2/edge/blocked.rb @@ -8,15 +8,20 @@ module FbGraph2 end end + def blocked?(user, params = {}) + users = self.edge :blocked, params, edge_scope: user + users.present? + end + def block!(user, params = {}) self.post params.merge( - user_id: Util.as_identifier(user) + user: Util.as_identifier(user) ), edge: :blocked end def unblock!(user, params = {}) self.delete params.merge( - user_id: Util.as_identifier(user) + user: Util.as_identifier(user) ), edge: :blocked end end diff --git a/lib/fb_graph2/edge/comments.rb b/lib/fb_graph2/edge/comments.rb index 32eb3ad..45e1c24 100644 --- a/lib/fb_graph2/edge/comments.rb +++ b/lib/fb_graph2/edge/comments.rb @@ -21,7 +21,7 @@ module FbGraph2 def comment!(params = {}) comment = self.post params, edge: :comments - Comment.new(comment[:id], comment.merge(params)).authenticate self.access_token + Comment.new(comment[:id], params.merge(comment)).authenticate self.access_token end end end diff --git a/lib/fb_graph2/edge/feed.rb b/lib/fb_graph2/edge/feed.rb index 5fa6da0..4305092 100644 --- a/lib/fb_graph2/edge/feed.rb +++ b/lib/fb_graph2/edge/feed.rb @@ -9,7 +9,7 @@ module FbGraph2 end def feed!(params = {}) - post = post params, edge: :feed + post = self.post params, edge: :feed Post.new(post[:id], params.merge(post)).authenticate self.access_token end end diff --git a/lib/fb_graph2/edge/photos.rb b/lib/fb_graph2/edge/photos.rb index 150e902..f752038 100644 --- a/lib/fb_graph2/edge/photos.rb +++ b/lib/fb_graph2/edge/photos.rb @@ -10,7 +10,7 @@ module FbGraph2 end def photo!(params = {}) - photo = post params, edge: :photos + photo = self.post params, edge: :photos Photo.new(photo[:id], params.merge(photo)).authenticate self.access_token end end diff --git a/lib/fb_graph2/edge/videos.rb b/lib/fb_graph2/edge/videos.rb index e94d240..e32fec1 100644 --- a/lib/fb_graph2/edge/videos.rb +++ b/lib/fb_graph2/edge/videos.rb @@ -10,7 +10,7 @@ module FbGraph2 end def video!(params = {}) - video = post params, edge: :videos + video = self.post params, edge: :videos Video.new(video[:id], params.merge(video)).authenticate self.access_token end end diff --git a/lib/fb_graph2/user.rb b/lib/fb_graph2/user.rb index f8da854..d791883 100644 --- a/lib/fb_graph2/user.rb +++ b/lib/fb_graph2/user.rb @@ -11,6 +11,7 @@ module FbGraph2 include Edge::FriendLists include Edge::Friends include Edge::Games + include Edge::Groups include Edge::Home include Edge::Interests include Edge::InvitableFriends diff --git a/spec/fb_graph2/collection_spec.rb b/spec/fb_graph2/collection_spec.rb new file mode 100644 index 0000000..5c06fdb --- /dev/null +++ b/spec/fb_graph2/collection_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe FbGraph2::Collection do + context 'when non-collection object given' do + it do + expect do + FbGraph2::Collection.new 'scalar' + end.to raise_error ArgumentError + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/achievements_spec.rb b/spec/fb_graph2/edge/achievements_spec.rb index 8985254..3d1d8f5 100644 --- a/spec/fb_graph2/edge/achievements_spec.rb +++ b/spec/fb_graph2/edge/achievements_spec.rb @@ -4,7 +4,7 @@ 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 + it 'should return an Array of FbGraph2::Achievement' do pages = mock_graph :get, 'me/achievements', 'user/achievements', access_token: 'token' do me.achievements end diff --git a/spec/fb_graph2/edge/activities_spec.rb b/spec/fb_graph2/edge/activities_spec.rb new file mode 100644 index 0000000..4579466 --- /dev/null +++ b/spec/fb_graph2/edge/activities_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Activities do + context 'included in User' do + describe '#activities' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page' do + pages = mock_graph :get, 'me/activities', 'user/activities', access_token: 'token' do + me.activities + end + pages.should_not be_blank + pages.each do |page| + page.should be_instance_of FbGraph2::Page + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/admins_spec.rb b/spec/fb_graph2/edge/admins_spec.rb new file mode 100644 index 0000000..da71a7c --- /dev/null +++ b/spec/fb_graph2/edge/admins_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Admins do + context 'included in Page' do + let(:page) { FbGraph2::Page.new('page_id').authenticate('page_token') } + + describe '#admins' do + it 'should return an Array of FbGraph2::User' do + users = mock_graph :get, 'page_id/admins', 'page/admins', access_token: 'page_token' do + page.admins + end + users.should_not be_blank + users.each do |user| + user.should be_instance_of FbGraph2::User + end + end + end + + describe '#admin?' do + let(:user_id) { 'user_id' } + let(:user) { FbGraph2::Page.new(user_id) } + + context 'when String given' do + it do + mock_graph :get, "page_id/admins/#{user_id}", 'page/admins', access_token: 'page_token' do + page.admin? user_id + end.should be true + end + end + + context 'when FbGraph2::User given' do + it do + mock_graph :get, "page_id/admins/#{user_id}", 'page/admins', access_token: 'page_token' do + page.admin? user + end.should be true + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/albums_spec.rb b/spec/fb_graph2/edge/albums_spec.rb new file mode 100644 index 0000000..5603588 --- /dev/null +++ b/spec/fb_graph2/edge/albums_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Albums do + context 'included in User' do + let(:me) { FbGraph2::User.me('token') } + + describe '#albums' do + it 'should return an Array of FbGraph2::Video' do + albums = mock_graph :get, 'me/albums', 'user/albums', access_token: 'token' do + me.albums + end + albums.should_not be_blank + albums.each do |album| + album.should be_instance_of FbGraph2::Album + end + end + end + + describe '#album!' do + it do + album = mock_graph :post, 'me/albums', 'success_with_id', access_token: 'token', params: { + name: 'test' + } do + me.album! name: 'test' + end + album.should be_instance_of FbGraph2::Album + 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 new file mode 100644 index 0000000..44fd044 --- /dev/null +++ b/spec/fb_graph2/edge/blocked_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' + +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) } + + describe '#blocked' do + it 'should return an Array of FbGraph2::User' do + users = mock_graph :get, 'page_id/blocked', 'page/blocked', access_token: 'page_token' do + page.blocked + end + users.should_not be_blank + users.each do |user| + user.should be_instance_of FbGraph2::User + end + end + end + + describe '#blocked?' do + context 'when String given' do + it do + mock_graph :get, "page_id/blocked/#{user_id}", 'page/blocked', access_token: 'page_token' do + page.blocked? user_id + end.should be true + end + end + + context 'when FbGraph2::User given' do + it do + mock_graph :get, "page_id/blocked/#{user_id}", 'page/blocked', access_token: 'page_token' do + page.blocked? user + end.should be true + end + end + end + + describe '#block!' do + it do + result = mock_graph :post, 'page_id/blocked', 'page/block_succeeded', access_token: 'page_token', params: { + user: user_id + } do + page.block! user + end + result.should == {'user_id' => true} + end + end + + describe '#unblock!' do + it do + mock_graph :delete, 'page_id/blocked', 'true', access_token: 'page_token', params: { + user: user_id + } do + page.unblock! user + end.should be true + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/books_spec.rb b/spec/fb_graph2/edge/books_spec.rb index e858dab..9b4b7ac 100644 --- a/spec/fb_graph2/edge/books_spec.rb +++ b/spec/fb_graph2/edge/books_spec.rb @@ -4,7 +4,7 @@ describe FbGraph2::Edge::Books do context 'included in User' do describe '#books' do let(:me) { FbGraph2::User.me('token') } - it 'should return an Array of FbGraph2::Page with page token' do + it 'should return an Array of FbGraph2::Page' do pages = mock_graph :get, 'me/books', 'user/books', access_token: 'token' do me.books end diff --git a/spec/fb_graph2/edge/events_spec.rb b/spec/fb_graph2/edge/events_spec.rb new file mode 100644 index 0000000..597bce2 --- /dev/null +++ b/spec/fb_graph2/edge/events_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Events do + context 'included in User' do + describe '#events' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Event' do + events = mock_graph :get, 'me/events', 'user/events', access_token: 'token' do + me.events + end + events.should_not be_blank + events.each do |event| + event.should be_instance_of FbGraph2::Event + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/friend_lists_spec.rb b/spec/fb_graph2/edge/friend_lists_spec.rb index 6b305f5..e09a5d2 100644 --- a/spec/fb_graph2/edge/friend_lists_spec.rb +++ b/spec/fb_graph2/edge/friend_lists_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe FbGraph2::Edge::FriendLists do - context 'included in Post' do + context 'included in User' do describe '#friend_lists' do let(:me) { FbGraph2::User.me('token') } it 'should return an Array of FbGraph2::FriendList' do diff --git a/spec/fb_graph2/edge/friends_spec.rb b/spec/fb_graph2/edge/friends_spec.rb new file mode 100644 index 0000000..5a0f145 --- /dev/null +++ b/spec/fb_graph2/edge/friends_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Friends do + context 'included in User' do + describe '#friends' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::User' do + users = mock_graph :get, 'me/friends', 'user/friends', access_token: 'token' do + me.friends + end + users.should_not be_blank + users.each do |user| + user.should be_instance_of FbGraph2::User + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/groups_spec.rb b/spec/fb_graph2/edge/groups_spec.rb new file mode 100644 index 0000000..dfe77a9 --- /dev/null +++ b/spec/fb_graph2/edge/groups_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Groups do + context 'included in User' do + describe '#groups' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Page' do + groups = mock_graph :get, 'me/groups', 'user/groups', access_token: 'token' do + me.groups + end + groups.should_not be_blank + groups.each do |group| + group.should be_instance_of FbGraph2::Group + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/home_spec.rb b/spec/fb_graph2/edge/home_spec.rb new file mode 100644 index 0000000..316fb2f --- /dev/null +++ b/spec/fb_graph2/edge/home_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Feed do + context 'included in User' do + describe '#home' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Post' do + posts = mock_graph :get, 'me/home', 'user/home', access_token: 'token' do + me.home + end + posts.should_not be_blank + posts.each do |post| + post.should be_instance_of FbGraph2::Post + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/interests_spec.rb b/spec/fb_graph2/edge/interests_spec.rb index 1eefb48..fa1d51d 100644 --- a/spec/fb_graph2/edge/interests_spec.rb +++ b/spec/fb_graph2/edge/interests_spec.rb @@ -4,7 +4,7 @@ describe FbGraph2::Edge::Interests do context 'included in User' do describe '#interests' do let(:me) { FbGraph2::User.me('token') } - it 'should return an Array of FbGraph2::Page with page token' do + it 'should return an Array of FbGraph2::Page' do pages = mock_graph :get, 'me/interests', 'user/interests', access_token: 'token' do me.interests end diff --git a/spec/fb_graph2/edge/invitable_friends_spec.rb b/spec/fb_graph2/edge/invitable_friends_spec.rb new file mode 100644 index 0000000..972a1ce --- /dev/null +++ b/spec/fb_graph2/edge/invitable_friends_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::InvitableFriends do + context 'included in User' do + describe '#invitable_friends' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Struct::InvitableFriend' do + users = mock_graph :get, 'me/invitable_friends', 'user/invitable_friends', access_token: 'token' do + me.invitable_friends + end + users.should_not be_blank + users.each do |user| + user.should be_instance_of FbGraph2::Struct::InvitableFriend + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/likes_spec.rb b/spec/fb_graph2/edge/likes_spec.rb index 4fefe1f..e5b18af 100644 --- a/spec/fb_graph2/edge/likes_spec.rb +++ b/spec/fb_graph2/edge/likes_spec.rb @@ -21,7 +21,7 @@ describe FbGraph2::Edge::Likes do it do mock_graph :get, 'me/likes/page_id', 'user/likes', access_token: 'token' do me.liked? 'page_id' - end.should be_true + end.should be true end end @@ -29,7 +29,7 @@ describe FbGraph2::Edge::Likes do it do mock_graph :get, 'me/likes/page_id', 'blank_collection', access_token: 'token' do me.liked? 'page_id' - end.should be_false + end.should be false end end end @@ -80,7 +80,7 @@ describe FbGraph2::Edge::Likes do it 'should return true' do mock_graph :post, 'post_id/likes', 'true', access_token: 'token' do post.like! - end.should be_true + end.should be true end end @@ -88,7 +88,7 @@ describe FbGraph2::Edge::Likes do it 'should return true' do mock_graph :delete, 'post_id/likes', 'true', access_token: 'token' do post.unlike! - end.should be_true + end.should be true end end end diff --git a/spec/fb_graph2/edge/milestones_spec.rb b/spec/fb_graph2/edge/milestones_spec.rb new file mode 100644 index 0000000..c32c99d --- /dev/null +++ b/spec/fb_graph2/edge/milestones_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Milestones do + context 'included in Page' do + describe '#milestones' do + let(:page) { FbGraph2::Page.new('page_id').authenticate('token') } + it 'should return an Array of FbGraph2::Milestone' do + milestones = mock_graph :get, 'page_id/milestones', 'page/milestones', access_token: 'token' do + page.milestones + end + milestones.should_not be_blank + milestones.each do |milestone| + milestone.should be_instance_of FbGraph2::Milestone + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/movies_spec.rb b/spec/fb_graph2/edge/movies_spec.rb index 67658d9..2623226 100644 --- a/spec/fb_graph2/edge/movies_spec.rb +++ b/spec/fb_graph2/edge/movies_spec.rb @@ -4,7 +4,7 @@ describe FbGraph2::Edge::Movies do context 'included in User' do describe '#movies' do let(:me) { FbGraph2::User.me('token') } - it 'should return an Array of FbGraph2::Page with page token' do + it 'should return an Array of FbGraph2::Page' do pages = mock_graph :get, 'me/movies', 'user/movies', access_token: 'token' do me.movies end diff --git a/spec/fb_graph2/edge/music_spec.rb b/spec/fb_graph2/edge/music_spec.rb index 8e557df..97d8f28 100644 --- a/spec/fb_graph2/edge/music_spec.rb +++ b/spec/fb_graph2/edge/music_spec.rb @@ -4,7 +4,7 @@ describe FbGraph2::Edge::Music do context 'included in User' do describe '#music' do let(:me) { FbGraph2::User.me('token') } - it 'should return an Array of FbGraph2::Page with page token' do + it 'should return an Array of FbGraph2::Page' do pages = mock_graph :get, 'me/music', 'user/music', access_token: 'token' do me.music end diff --git a/spec/fb_graph2/edge/notifications_spec.rb b/spec/fb_graph2/edge/notifications_spec.rb index 3d9a262..ef9bbba 100644 --- a/spec/fb_graph2/edge/notifications_spec.rb +++ b/spec/fb_graph2/edge/notifications_spec.rb @@ -22,7 +22,7 @@ describe FbGraph2::Edge::Notifications do href: 'href', template: 'template' } do user.authenticate('app_token').notification! href: 'href', template: 'template' - end.should be_true + end.should be true end end end diff --git a/spec/fb_graph2/edge/permissions_spec.rb b/spec/fb_graph2/edge/permissions_spec.rb new file mode 100644 index 0000000..6c1fa93 --- /dev/null +++ b/spec/fb_graph2/edge/permissions_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Permissions do + context 'included in User' do + describe '#permissions' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Struct::Permission' do + permissions = mock_graph :get, 'me/permissions', 'user/permissions', access_token: 'token' do + me.permissions + end + permissions.should_not be_blank + permissions.each do |permission| + permission.should be_instance_of FbGraph2::Struct::Permission + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/picture_spec.rb b/spec/fb_graph2/edge/picture_spec.rb new file mode 100644 index 0000000..591bd7b --- /dev/null +++ b/spec/fb_graph2/edge/picture_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Picture do + context 'included in User' do + describe '#picture' do + let(:me) { FbGraph2::User.me('token') } + it do + mock_graph :get, 'me/picture', 'user/picture', access_token: 'token', params: { + redirect: false + } do + me.picture + end.should be_instance_of FbGraph2::Struct::Picture + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/promotable_posts_spec.rb b/spec/fb_graph2/edge/promotable_posts_spec.rb new file mode 100644 index 0000000..8680c12 --- /dev/null +++ b/spec/fb_graph2/edge/promotable_posts_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::PromotablePosts do + context 'included in Page' do + describe '#promotable_posts' do + let(:page) { FbGraph2::Page.new('page_id').authenticate('page_token') } + it 'should return an Array of FbGraph2::Post' do + posts = mock_graph :get, 'page_id/promotable_posts', 'page/promotable_posts', access_token: 'page_token' do + page.promotable_posts + end + posts.should_not be_blank + posts.each do |post| + post.should be_instance_of FbGraph2::Post + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/scores_spec.rb b/spec/fb_graph2/edge/scores_spec.rb new file mode 100644 index 0000000..a9bbe9f --- /dev/null +++ b/spec/fb_graph2/edge/scores_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Scores do + context 'included in User' do + describe '#scores' do + let(:me) { FbGraph2::User.me('token') } + it 'should return an Array of FbGraph2::Struct::Score' do + scores = mock_graph :get, 'me/scores', 'user/scores', access_token: 'token' do + me.scores + end + scores.should_not be_blank + scores.each do |score| + score.should be_instance_of FbGraph2::Struct::Score + end + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/edge/television_spec.rb b/spec/fb_graph2/edge/television_spec.rb index 39c6bad..c837ede 100644 --- a/spec/fb_graph2/edge/television_spec.rb +++ b/spec/fb_graph2/edge/television_spec.rb @@ -4,7 +4,7 @@ describe FbGraph2::Edge::Television do context 'included in User' do describe '#television' do let(:me) { FbGraph2::User.me('token') } - it 'should return an Array of FbGraph2::Page with page token' do + it 'should return an Array of FbGraph2::Page' do pages = mock_graph :get, 'me/television', 'user/television', access_token: 'token' do me.television end diff --git a/spec/fb_graph2/edge/videos_spec.rb b/spec/fb_graph2/edge/videos_spec.rb new file mode 100644 index 0000000..c11c6bc --- /dev/null +++ b/spec/fb_graph2/edge/videos_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe FbGraph2::Edge::Videos do + context 'included in User' do + let(:me) { FbGraph2::User.me('token') } + + describe '#videos' do + it 'should return an Array of FbGraph2::Video' do + videos = mock_graph :get, 'me/videos', 'user/videos', access_token: 'token' do + me.videos + end + videos.should_not be_blank + videos.each do |video| + video.should be_instance_of FbGraph2::Video + end + end + end + + describe '#video!' do + it do + video = mock_graph :post, 'me/videos', 'success_with_id', access_token: 'token' do + me.video! source: File.new(__FILE__), message: 'hello' + end + video.should be_instance_of FbGraph2::Video + end + end + end +end \ No newline at end of file diff --git a/spec/fb_graph2/request_filter/debugger_spec.rb b/spec/fb_graph2/request_filter/debugger_spec.rb index 0e04566..b4a1ac4 100644 --- a/spec/fb_graph2/request_filter/debugger_spec.rb +++ b/spec/fb_graph2/request_filter/debugger_spec.rb @@ -12,7 +12,7 @@ describe FbGraph2::RequestFilter::Debugger do "======= [FbGraph2] API REQUEST STARTED =======", request.dump ].each do |output| - FbGraph2.logger.should_receive(:info).with output + expect(FbGraph2.logger).to receive(:info).with output end request_filter.filter_request(request) end @@ -25,7 +25,7 @@ describe FbGraph2::RequestFilter::Debugger do response.dump, "======= [FbGraph2] API REQUEST FINISHED =======" ].each do |output| - FbGraph2.logger.should_receive(:info).with output + expect(FbGraph2.logger).to receive(:info).with output end request_filter.filter_response(request, response) end diff --git a/spec/mock_json/page/admins.json b/spec/mock_json/page/admins.json new file mode 100644 index 0000000..2bbd607 --- /dev/null +++ b/spec/mock_json/page/admins.json @@ -0,0 +1,11 @@ +{ + "data": [{ + "name": "Nov Matake", + "role": "MANAGER", + "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"], + "id": "10152411392127277" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/140478125968442/admins?limit=5000&offset=5000&__after_id=enc_AewHp5mZW0v4ZorlBTo4lsBccesXKfIJsKvOM-Qb268XDhHwKtZnhOhNwXWSun5KdHE" + } +} diff --git a/spec/mock_json/page/block_succeeded.json b/spec/mock_json/page/block_succeeded.json new file mode 100644 index 0000000..9dd7a28 --- /dev/null +++ b/spec/mock_json/page/block_succeeded.json @@ -0,0 +1,3 @@ +{ + "user_id": true +} \ No newline at end of file diff --git a/spec/mock_json/page/blocked.json b/spec/mock_json/page/blocked.json new file mode 100644 index 0000000..a875a08 --- /dev/null +++ b/spec/mock_json/page/blocked.json @@ -0,0 +1,11 @@ +{ + "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" + } +} \ No newline at end of file diff --git a/spec/mock_json/page/milestones.json b/spec/mock_json/page/milestones.json new file mode 100644 index 0000000..61b3e8a --- /dev/null +++ b/spec/mock_json/page/milestones.json @@ -0,0 +1,19 @@ +{ + "data": [{ + "id": "546071975451512", + "created_time": "2013-07-05T02:04:43+0000", + "description": "Big Guest from MIT-KIT", + "end_time": "2013-06-26T19:00:00+0000", + "from": { + "category": "Community", + "name": "Identity Conference #idcon", + "id": "367989543259757" + }, + "start_time": "2013-06-26T19:00:00+0000", + "title": "idcon satellite", + "updated_time": "2013-07-05T02:04:43+0000" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/367989543259757/milestones?limit=5000&offset=5000&__after_id=enc_Aex6DrtZcpP_AZjou_LFSynIQJzuO-LR4zoj2GU-WQO3StnFciL5I6GVJ2Nlj5-6C50JJSpZnn5O-zkuPXcU4DAC" + } +} diff --git a/spec/mock_json/page/promotable_posts.json b/spec/mock_json/page/promotable_posts.json new file mode 100644 index 0000000..f59891c --- /dev/null +++ b/spec/mock_json/page/promotable_posts.json @@ -0,0 +1,67 @@ +{ + "data": [{ + "id": "140478125968442_881790788503835", + "from": { + "category": "Community organization", + "name": "OAuth.jp", + "id": "140478125968442" + }, + "story": "OAuth.jp shared a link.", + "story_tags": { + "0": [{ + "id": "140478125968442", + "name": "OAuth.jp", + "offset": 0, + "length": 8, + "type": "page" + }] + }, + "link": "http://oauth.jp/blog/2014/05/09/what-happens-when-oauth2-code-leaked/", + "name": "OAuth 2.0 の code は漏れても大丈夫ってホント!? - OAuth.jp", + "caption": "oauth.jp", + "description": "昨日のCovert Redirect で Query 漏れるケースもある!?やOAuth 2.0 の脆弱性 (!?) “Covert Redirect” とはにあるように、OAuth 2.0 の code が漏れちゃうことも、ありえます。 漏れないためにやるべきことは、 …", + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif", + "actions": [{ + "name": "Comment", + "link": "https://www.facebook.com/140478125968442/posts/881790788503835" + }, { + "name": "Like", + "link": "https://www.facebook.com/140478125968442/posts/881790788503835" + }], + "privacy": { + "description": "Public", + "value": "EVERYONE", + "friends": "", + "networks": "", + "allow": "", + "deny": "" + }, + "type": "link", + "status_type": "shared_story", + "created_time": "2014-05-09T02:18:54+0000", + "updated_time": "2014-05-09T02:18:54+0000", + "is_published": true, + "likes": { + "data": [{ + "id": "799980330042786", + "name": "Nobuyuki Tetsuka" + }, { + "id": "671955032839764", + "name": "Naohiro Fujie" + }, { + "id": "514441882016076", + "name": "Shouji Ohara" + }], + "paging": { + "cursors": { + "after": "NTE0NDQxODgyMDE2MDc2", + "before": "Nzk5OTgwMzMwMDQyNzg2" + } + } + } + }], + "paging": { + "previous": "https://graph.facebook.com/v2.0/140478125968442/promotable_posts?limit=25&since=1399601934", + "next": "https://graph.facebook.com/v2.0/140478125968442/promotable_posts?limit=25&until=1340970652" + } +} diff --git a/spec/mock_json/user/activities.json b/spec/mock_json/user/activities.json new file mode 100644 index 0000000..1a991d6 --- /dev/null +++ b/spec/mock_json/user/activities.json @@ -0,0 +1,36 @@ +{ + "data": [{ + "category": "Interest", + "name": "Mobile Hack Tokyo", + "created_time": "2012-03-01T00:30:09+0000", + "id": "253431701402959" + }, { + "category": "Software", + "name": "Rack::OAuth2", + "created_time": "2011-06-23T10:32:47+0000", + "id": "141477809244105" + }, { + "category": "Non-profit organization", + "name": "OpenID Foundation Japan", + "created_time": "2011-06-23T04:53:40+0000", + "id": "157574337644417" + }, { + "category": "Internet/software", + "name": "SocialWeb Japan", + "created_time": "2011-04-26T04:54:13+0000", + "id": "150730961633" + }, { + "category": "Community organization", + "name": "OAuth.jp", + "created_time": "2011-01-05T00:27:02+0000", + "id": "140478125968442" + }, { + "category": "Software", + "name": "FbGraph", + "created_time": "2010-04-30T06:48:21+0000", + "id": "117513961602338" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/activities?limit=25&offset=25&__after_id=enc_AewISXs8Uhe2pwegtVsWC8GFmzAWEKKFzGcJoZ-UJa4MA_wFfCIRKFaQMJkS6U5WTdiSKw3G3EvlyDir1upNCBop" + } +} diff --git a/spec/mock_json/user/albums.json b/spec/mock_json/user/albums.json new file mode 100644 index 0000000..64b5727 --- /dev/null +++ b/spec/mock_json/user/albums.json @@ -0,0 +1,23 @@ +{ + "data": [{ + "id": "532912916729105", + "from": { + "category": "Software", + "name": "FbGraph", + "id": "117513961602338" + }, + "name": "Timeline Photos", + "link": "https://www.facebook.com/album.php?fbid=532912916729105&id=117513961602338&aid=116544", + "privacy": "everyone", + "type": "wall", + "created_time": "2013-02-16T13:23:10+0000", + "updated_time": "2013-02-16T13:23:10+0000", + "can_upload": false + }], + "paging": { + "cursors": { + "after": "MjEwNDcxNDkyMzA2NTg0", + "before": "NTMyOTEyOTE2NzI5MTA1" + } + } +} diff --git a/spec/mock_json/user/events.json b/spec/mock_json/user/events.json new file mode 100644 index 0000000..6bca602 --- /dev/null +++ b/spec/mock_json/user/events.json @@ -0,0 +1,16 @@ +{ + "data": [ + { + "name": "Test Event", + "start_time": "2014-06-13T19:00:00+0900", + "timezone": "Asia/Tokyo", + "location": "六本木", + "rsvp_status": "attending", + "id": "246996708819160" + } + ], + "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_" + } +} \ No newline at end of file diff --git a/spec/mock_json/user/friends.json b/spec/mock_json/user/friends.json new file mode 100644 index 0000000..8a00082 --- /dev/null +++ b/spec/mock_json/user/friends.json @@ -0,0 +1,18 @@ +{ + "data": [{ + "name": "Nat Sakimura", + "id": "1048138174" + }, { + "name": "Yusuke Kondo", + "id": "1229826130" + }, { + "name": "Yuya Ito", + "id": "1326792131" + }, { + "name": "Tatsuya Katsuhara", + "id": "1784765822" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/friends?limit=5000&offset=5000&__after_id=enc_AexFQ6mn3PA35psWD5WjFNzW7ovDp35_gkApd8tXqRmc5ygEBBAEs56d3YIetOc9NNk" + } +} diff --git a/spec/mock_json/user/groups.json b/spec/mock_json/user/groups.json new file mode 100644 index 0000000..0e642da --- /dev/null +++ b/spec/mock_json/user/groups.json @@ -0,0 +1,16 @@ +{ + "data": [{ + "name": "OpenID Connect Hackathon", + "administrator": true, + "bookmark_order": 14, + "id": "562322927125681" + }, { + "name": "OAuth.jp", + "administrator": true, + "bookmark_order": 12, + "id": "343659285716553" + }], + "paging": { + "next": "https://graph.facebook.com/v2.0/579612276/groups?icon_size=16&limit=5000&offset=5000&__after_id=enc_AeynOYwetNSbegZQTbjirpNPayS9oqujy9wnu0CnNjC7YMl4zxLq-JP--CRz3FX3KWg" + } +} diff --git a/spec/mock_json/user/home.json b/spec/mock_json/user/home.json new file mode 100644 index 0000000..e731c7e --- /dev/null +++ b/spec/mock_json/user/home.json @@ -0,0 +1,61 @@ +{ + "data": [{ + "id": "114870808553071_759907394049406", + "from": { + "category": "Computers/internet website", + "name": "TechCrunch Japan", + "id": "114870808553071" + }, + "story": "TechCrunch Japan shared a link.", + "story_tags": { + "0": [{ + "id": "114870808553071", + "name": "TechCrunch Japan", + "offset": 0, + "length": 16, + "type": "page" + }] + }, + "picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQCP3uH6kEoLnPsL&w=154&h=154&url=http%3A%2F%2Ftechcrunchjp.files.wordpress.com%2F2014%2F06%2F140603modiva1.jpg%3Fw%3D1024%26h%3D768", + "link": "http://dlvr.it/5sP8LX", + "name": "MOVIDA JAPANがデモデイを開催して13社が登壇‒‒個人的にはEigooo!に期待", + "caption": "jp.techcrunch.com", + "description": "MOVIDA JAPANは6月3日、同社のシードアクセラレーションプログラムの成果を発表する「MOVIDA JAPAN DemoDay 5th」を開催した。今回登壇したスタートアップは13社。まずは登壇したスタートアップとそのサービス概要を紹介していく。…", + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/y5/r/sXJx2UP7quc.png", + "actions": [{ + "name": "Comment", + "link": "https://www.facebook.com/114870808553071/posts/759907394049406" + }, { + "name": "Like", + "link": "https://www.facebook.com/114870808553071/posts/759907394049406" + }], + "privacy": { + "value": "" + }, + "type": "link", + "status_type": "shared_story", + "application": { + "name": "dlvr.it", + "namespace": "dlvr_it", + "id": "232775914688" + }, + "created_time": "2014-06-03T08:20:01+0000", + "updated_time": "2014-06-03T08:20:01+0000", + "likes": { + "data": [{ + "id": "10203763563950799", + "name": "Takuya Kawai" + }], + "paging": { + "cursors": { + "after": "MTAyMDM3NjM1NjM5NTA3OTk=", + "before": "MTAyMDM3NjM1NjM5NTA3OTk=" + } + } + } + }], + "paging": { + "previous": "https://graph.facebook.com/v2.0/579612276/home?limit=25&since=1401784697", + "next": "https://graph.facebook.com/v2.0/579612276/home?limit=25&until=1401773525" + } +} diff --git a/spec/mock_json/user/invitable_friends.json b/spec/mock_json/user/invitable_friends.json new file mode 100644 index 0000000..8796101 --- /dev/null +++ b/spec/mock_json/user/invitable_friends.json @@ -0,0 +1,27 @@ +{ + "data": [{ + "id": "AVm6afobc20T0wATmCYRk_CNymo_44MQW8yMBwpgDFAQ18iF9feZpDEDmwfmcjSBSSuYkFfD5fx77g_uJRF0fmQ7AR2kObX8biP4wzN7UMpbYQ", + "name": "Shingo Yamanaka", + "picture": { + "data": { + "is_silhouette": false, + "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/t1.0-1/c0.15.85.85/s50x50/1468668_10152037195781416_2050550170_s.jpg" + } + } + }, { + "id": "AVnJiIlmAtrWJ106ErRPlLZNy8_Hd4mfmuQBrbGm4tuFS_ENvyYdVxTwgesXE5Wp2ICtxcPHzkA4Y4BJAWwJqyUie2ZDKQeKn9mnjPCVAUr8Lg", + "name": "Hayashi Tatsuya", + "picture": { + "data": { + "is_silhouette": false, + "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xaf1/t1.0-1/c79.38.479.479/s50x50/388771_10150501378984825_523522119_n.jpg" + } + } + }], + "paging": { + "cursors": { + "before": "QVZra09GaExkNndsM1J5eVpuQ2dWS1hLV3FBb0dqRTh3dC1PVXJIZE8ya0JzbV9kUDZXcWZEdUtUZFNHejcxeGlWZ3JjZjZjdkIwMWdtSWtHZGpGVE8wTWZ5cUdNUm5NWWw3c2hSTEtPZ19ySmc=", + "after": "QVZrdlNsUHItNExPY1JIUVdlZ3BDZlFCTHFFMUl6YVhnVG5fRVlBLVV0QThUMFBmRnZNQkVQWVg2VkRBQWhRa3RyemVQUFhscWxBVERYZU15SExZbG50Z0RTQUtfVno5VjRjT3VUb2J5NGg1VFE=" + } + } +} diff --git a/spec/mock_json/user/permissions.json b/spec/mock_json/user/permissions.json new file mode 100644 index 0000000..6e359e5 --- /dev/null +++ b/spec/mock_json/user/permissions.json @@ -0,0 +1,114 @@ +{ + "data": [{ + "permission": "installed", + "status": "granted" + }, { + "permission": "public_profile", + "status": "granted" + }, { + "permission": "read_stream", + "status": "granted" + }, { + "permission": "read_mailbox", + "status": "granted" + }, { + "permission": "read_page_mailboxes", + "status": "granted" + }, { + "permission": "rsvp_event", + "status": "granted" + }, { + "permission": "email", + "status": "granted" + }, { + "permission": "read_insights", + "status": "granted" + }, { + "permission": "manage_notifications", + "status": "granted" + }, { + "permission": "read_friendlists", + "status": "granted" + }, { + "permission": "manage_pages", + "status": "granted" + }, { + "permission": "publish_actions", + "status": "granted" + }, { + "permission": "user_birthday", + "status": "granted" + }, { + "permission": "user_religion_politics", + "status": "granted" + }, { + "permission": "user_relationships", + "status": "granted" + }, { + "permission": "user_relationship_details", + "status": "granted" + }, { + "permission": "user_hometown", + "status": "granted" + }, { + "permission": "user_location", + "status": "granted" + }, { + "permission": "user_likes", + "status": "granted" + }, { + "permission": "user_activities", + "status": "granted" + }, { + "permission": "user_interests", + "status": "granted" + }, { + "permission": "user_education_history", + "status": "granted" + }, { + "permission": "user_work_history", + "status": "granted" + }, { + "permission": "user_website", + "status": "granted" + }, { + "permission": "user_groups", + "status": "granted" + }, { + "permission": "user_events", + "status": "granted" + }, { + "permission": "user_photos", + "status": "granted" + }, { + "permission": "user_videos", + "status": "granted" + }, { + "permission": "user_friends", + "status": "granted" + }, { + "permission": "user_about_me", + "status": "granted" + }, { + "permission": "user_status", + "status": "granted" + }, { + "permission": "user_games_activity", + "status": "granted" + }, { + "permission": "user_tagged_places", + "status": "granted" + }, { + "permission": "user_actions.books", + "status": "granted" + }, { + "permission": "user_actions.music", + "status": "granted" + }, { + "permission": "user_actions.video", + "status": "granted" + }, { + "permission": "user_actions.news", + "status": "granted" + }] +} diff --git a/spec/mock_json/user/picture.json b/spec/mock_json/user/picture.json new file mode 100644 index 0000000..653576f --- /dev/null +++ b/spec/mock_json/user/picture.json @@ -0,0 +1,6 @@ +{ + "data": { + "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfp1/t1.0-1/p50x50/1621886_836472406369007_1319645706_t.jpg", + "is_silhouette": false + } +} \ No newline at end of file diff --git a/spec/mock_json/user/scores.json b/spec/mock_json/user/scores.json new file mode 100644 index 0000000..7c9fbd6 --- /dev/null +++ b/spec/mock_json/user/scores.json @@ -0,0 +1,14 @@ +{ + "data": [{ + "user": { + "id": "10152411392127277", + "name": "Nov Matake" + }, + "score": 10, + "application": { + "name": "gem sample", + "namespace": "fbgraphsample", + "id": "134145643294322" + } + }] +} diff --git a/spec/mock_json/user/videos.json b/spec/mock_json/user/videos.json new file mode 100644 index 0000000..4f3349b --- /dev/null +++ b/spec/mock_json/user/videos.json @@ -0,0 +1,41 @@ +{ + "data": [{ + "id": "10150407695537277", + "from": { + "category": "Software", + "name": "FbGraph", + "id": "117513961602338" + }, + "name": "Testing Video Upload!", + "description": "Testing Video Upload!!!!", + "picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/t15.0-10/51203_10150407695802277_10150407695537277_13346_258_t.jpg", + "embed_html": "", + "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/DggDhA4z4tO.gif", + "source": "https://fbcdn-video-a.akamaihd.net/hvideo-ak-xap1/v/t43.1792-2/1205675_10151804645367277_61538_n.mp4?oh=d78d7d5854d1614376ca0358b15b9f54&oe=538F750B&__gda__=1401907382_f5c3b44cfea781601e4caed9eca55002", + "created_time": "2011-11-09T08:31:28+0000", + "updated_time": "2011-11-09T08:31:28+0000", + "format": [{ + "embed_html": "", + "width": 130, + "height": 98, + "filter": "130x130", + "picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/t15.0-10/s130x130/51203_10150407695802277_10150407695537277_13346_258_t.jpg" + }, { + "embed_html": "", + "width": 480, + "height": 360, + "filter": "480x480", + "picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/t15.0-10/s480x480/51203_10150407695802277_10150407695537277_13346_258_b.jpg" + }, { + "embed_html": "", + "width": 640, + "height": 480, + "filter": "native", + "picture": "https://fbcdn-vthumb-a.akamaihd.net/hvthumb-ak-xap1/t15.0-10/51203_10150407695802277_10150407695537277_13346_258_b.jpg" + }] + }], + "paging": { + "previous": "https://graph.facebook.com/v2.0/117513961602338/videos?limit=25&since=1320827488", + "next": "https://graph.facebook.com/v2.0/117513961602338/videos?limit=25&until=1308369661" + } +} diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6d05a19..9ae1cca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,8 +5,15 @@ SimpleCov.start do end require 'rspec' +require 'rspec/its' require 'fb_graph2' +RSpec.configure do |config| + config.expect_with :rspec do |c| + c.syntax = [:should, :expect] + end +end + Dir[File.join(__dir__, 'spec_helper/*.rb')].each do |file| require file end \ No newline at end of file diff --git a/spec/spec_helper/mock_graph.rb b/spec/spec_helper/mock_graph.rb index ed52c60..f48b967 100644 --- a/spec/spec_helper/mock_graph.rb +++ b/spec/spec_helper/mock_graph.rb @@ -50,7 +50,7 @@ module MockGraph end if options[:params] case method - when :post, :put + when :post, :put, :delete request[:body] = options[:params] else request[:query] = options[:params]