From 32837be77e0370aa9b78e31f2345824f3ad21143 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Thu, 20 Dec 2012 08:44:07 -0800 Subject: [PATCH] Add specs for when a user ID is passed --- .../twitter/api/friends_and_followers_spec.rb | 104 +++--- spec/twitter/api/lists_spec.rb | 314 +++++++++++------- spec/twitter/api/search_spec.rb | 8 +- spec/twitter/api/suggested_users_spec.rb | 35 -- spec/twitter/api/undocumented_spec.rb | 15 + spec/twitter/api/users_spec.rb | 97 +++--- 6 files changed, 312 insertions(+), 261 deletions(-) diff --git a/spec/twitter/api/friends_and_followers_spec.rb b/spec/twitter/api/friends_and_followers_spec.rb index e9533c27b..a04e12b58 100644 --- a/spec/twitter/api/friends_and_followers_spec.rb +++ b/spec/twitter/api/friends_and_followers_spec.rb @@ -22,6 +22,21 @@ expect(friend_ids.ids.first).to eq 14100886 end end + context "with a user ID passed" do + before do + stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :user_id => "7505382"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.friend_ids(7505382) + expect(a_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made + end + it "returns an array of numeric IDs for every user the specified user is following" do + friend_ids = @client.friend_ids(7505382) + expect(friend_ids).to be_a Twitter::Cursor + expect(friend_ids.ids).to be_an Array + expect(friend_ids.ids.first).to eq 14100886 + end + end context "without arguments passed" do before do stub_get("/1.1/friends/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) @@ -55,6 +70,21 @@ expect(follower_ids.ids.first).to eq 14100886 end end + context "with a user ID passed" do + before do + stub_get("/1.1/followers/ids.json").with(:query => {:cursor => "-1", :user_id => "7505382"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.follower_ids(7505382) + expect(a_get("/1.1/followers/ids.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made + end + it "returns an array of numeric IDs for every user following the specified user" do + follower_ids = @client.follower_ids(7505382) + expect(follower_ids).to be_a Twitter::Cursor + expect(follower_ids.ids).to be_an Array + expect(follower_ids.ids.first).to eq 14100886 + end + end context "without arguments passed" do before do stub_get("/1.1/followers/ids.json").with(:query => {:cursor => "-1"}).to_return(:body => fixture("ids_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) @@ -373,8 +403,8 @@ stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new(:id => '7505382') - user2 = Twitter::User.new(:id => '14100886') + user1 = Twitter::User.new(:id => "7505382") + user2 = Twitter::User.new(:id => "14100886") @client.friendship(user1, user2) expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made end @@ -414,8 +444,8 @@ stub_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"}).to_return(:body => fixture("following.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new(:id => '7505382') - user2 = Twitter::User.new(:id => '14100886') + user1 = Twitter::User.new(:id => "7505382") + user2 = Twitter::User.new(:id => "14100886") @client.friendship?(user1, user2) expect(a_get("/1.1/friendships/show.json").with(:query => {:source_id => "7505382", :target_id => "14100886"})).to have_been_made end @@ -425,7 +455,6 @@ describe "#followers" do context "with a screen_name passed" do before do - stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) stub_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("followers_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @@ -433,48 +462,26 @@ expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made end it "returns a cursor of followers with details for every user the specified user is followed by" do - followers = @client.followers + followers = @client.followers("sferik") expect(followers).to be_a Twitter::Cursor expect(followers.users).to be_an Array expect(followers.users.first).to be_a Twitter::User end - context "when authenticated as someone else" do - before do - stub_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("followers_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/followers/list.json").with(:query => {:cursor => "1419103567112105362", :screen_name => "sferik"}).to_return(:body => fixture("followers_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resources" do - @client.followers("sferik").each{} - expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made - expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "1419103567112105362", :screen_name => "sferik"})).to have_been_made - end - end end context "with a user ID passed" do before do - stub_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"}).to_return(:body => fixture("followers_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :user_id => "7505382"}).to_return(:body => fixture("followers_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.followers(14100886) - expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"})).to have_been_made + @client.followers(7505382) + expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made end it "returns a cursor of followers with details for every user the specified user is followed by" do - followers = @client.followers(14100886) + followers = @client.followers(7505382) expect(followers).to be_a Twitter::Cursor expect(followers.users).to be_an Array expect(followers.users.first).to be_a Twitter::User end - context "when authenticated as someone else" do - before do - stub_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"}).to_return(:body => fixture("followers_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/followers/list.json").with(:query => {:cursor => "1419103567112105362", :user_id => "14100886"}).to_return(:body => fixture("followers_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resources" do - @client.followers(14100886).each{} - expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"})).to have_been_made - expect(a_get("/1.1/followers/list.json").with(:query => {:cursor => "1419103567112105362", :user_id => "14100886"})).to have_been_made - end - end end context "without arguments passed" do before do @@ -497,7 +504,6 @@ describe "#friends" do context "with a screen_name passed" do before do - stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @@ -505,48 +511,26 @@ expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made end it "returns a cursor of followers with details for every user the specified user is following" do - friends = @client.friends + friends = @client.friends("sferik") expect(friends).to be_a Twitter::Cursor expect(friends.users).to be_an Array expect(friends.users.first).to be_a Twitter::User end - context "when authenticated as someone else" do - before do - stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/friends/list.json").with(:query => {:cursor => "1418947360875712729", :screen_name => "sferik"}).to_return(:body => fixture("friends_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resources" do - @client.friends("sferik").each{} - expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made - expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "1418947360875712729", :screen_name => "sferik"})).to have_been_made - end - end end context "with a user ID passed" do before do - stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :user_id => "7505382"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.friends(14100886) - expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"})).to have_been_made + @client.friends(7505382) + expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made end it "returns a cursor of followers with details for every user the specified user is following" do - friends = @client.friends(14100886) + friends = @client.friends(7505382) expect(friends).to be_a Twitter::Cursor expect(friends.users).to be_an Array expect(friends.users.first).to be_a Twitter::User end - context "when authenticated as someone else" do - before do - stub_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"}).to_return(:body => fixture("friends_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/friends/list.json").with(:query => {:cursor => "1418947360875712729", :user_id => "14100886"}).to_return(:body => fixture("friends_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resources" do - @client.friends(14100886).each{} - expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "-1", :user_id => "14100886"})).to have_been_made - expect(a_get("/1.1/friends/list.json").with(:query => {:cursor => "1418947360875712729", :user_id => "14100886"})).to have_been_made - end - end end context "without arguments passed" do before do diff --git a/spec/twitter/api/lists_spec.rb b/spec/twitter/api/lists_spec.rb index 486be4ae7..f0a783949 100644 --- a/spec/twitter/api/lists_spec.rb +++ b/spec/twitter/api/lists_spec.rb @@ -25,11 +25,11 @@ describe "#list_timeline" do context "with a screen name passed" do before do - stub_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_timeline("sferik", "presidents") - expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end it "returns the timeline for members of the specified list" do tweets = @client.list_timeline("sferik", "presidents") @@ -41,11 +41,11 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_timeline("presidents") - expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_get("/1.1/lists/statuses.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end end @@ -53,11 +53,11 @@ describe "#list_remove_member" do context "with a screen name passed" do before do - stub_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_remove_member("sferik", "presidents", 813286) - expect(a_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"})).to have_been_made + expect(a_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end it "returns the list" do list = @client.list_remove_member("sferik", "presidents", 813286) @@ -68,11 +68,11 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_remove_member("presidents", 813286) - expect(a_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"})).to have_been_made + expect(a_post("/1.1/lists/members/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end end end @@ -80,14 +80,30 @@ describe "#memberships" do context "with a screen name passed" do before do - stub_get("/1.1/lists/memberships.json").with(:query => {:screen_name => 'pengwynn', :cursor => "-1"}).to_return(:body => fixture("memberships.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/memberships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"}).to_return(:body => fixture("memberships.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.memberships("pengwynn") - expect(a_get("/1.1/lists/memberships.json").with(:query => {:screen_name => 'pengwynn', :cursor => "-1"})).to have_been_made + @client.memberships("sferik") + expect(a_get("/1.1/lists/memberships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"})).to have_been_made end it "returns the lists the specified user has been added to" do - memberships = @client.memberships("pengwynn") + memberships = @client.memberships("sferik") + expect(memberships).to be_a Twitter::Cursor + expect(memberships.lists).to be_an Array + expect(memberships.lists.first).to be_a Twitter::List + expect(memberships.lists.first.name).to eq "developer" + end + end + context "with a user ID passed" do + before do + stub_get("/1.1/lists/memberships.json").with(:query => {:user_id => "7505382", :cursor => "-1"}).to_return(:body => fixture("memberships.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.memberships(7505382) + expect(a_get("/1.1/lists/memberships.json").with(:query => {:user_id => "7505382", :cursor => "-1"})).to have_been_made + end + it "returns the lists the specified user has been added to" do + memberships = @client.memberships(7505382) expect(memberships).to be_a Twitter::Cursor expect(memberships.lists).to be_an Array expect(memberships.lists.first).to be_a Twitter::List @@ -109,11 +125,11 @@ describe "#list_subscribers" do context "with a screen name passed" do before do - stub_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscribers("sferik", "presidents") - expect(a_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"})).to have_been_made + expect(a_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"})).to have_been_made end it "returns the subscribers of the specified list" do list_subscribers = @client.list_subscribers("sferik", "presidents") @@ -123,14 +139,30 @@ expect(list_subscribers.users.first.id).to eq 7505382 end end + context "with a user ID passed" do + before do + stub_get("/1.1/lists/subscribers.json").with(:query => {:owner_id => "7505382", :slug => "presidents", :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.list_subscribers(7505382, "presidents") + expect(a_get("/1.1/lists/subscribers.json").with(:query => {:owner_id => "7505382", :slug => "presidents", :cursor => "-1"})).to have_been_made + end + it "returns the subscribers of the specified list" do + list_subscribers = @client.list_subscribers(7505382, "presidents") + expect(list_subscribers).to be_a Twitter::Cursor + expect(list_subscribers.users).to be_an Array + expect(list_subscribers.users.first).to be_a Twitter::User + expect(list_subscribers.users.first.id).to eq 7505382 + end + end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscribers("presidents") - expect(a_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"})).to have_been_made + expect(a_get("/1.1/lists/subscribers.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"})).to have_been_made end end end @@ -138,11 +170,11 @@ describe "#list_subscribe" do context "with a screen name passed" do before do - stub_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscribe("sferik", "presidents") - expect(a_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end it "returns the specified list" do list = @client.list_subscribe("sferik", "presidents") @@ -153,11 +185,11 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscribe("presidents") - expect(a_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_post("/1.1/lists/subscribers/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end end @@ -165,13 +197,13 @@ describe "#list_subscriber?" do context "with a screen name passed" do before do - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '18755393'}).to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '12345678'}).to_return(:body => fixture("not_found.json"), :status => 403, :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "18755393"}).to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "12345678"}).to_return(:body => fixture("not_found.json"), :status => 403, :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscriber?("sferik", "presidents", 813286) - expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end it "returns true if the specified user subscribes to the specified list" do list_subscriber = @client.list_subscriber?("sferik", "presidents", 813286) @@ -188,49 +220,49 @@ end context "with a owner ID passed" do before do - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscriber?(12345678, "presidents", 813286) - expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents", :user_id => "813286"})).to have_been_made end end context "with a list ID passed" do before do - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :list_id => "12345678", :user_id => "813286"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.list_subscriber?('sferik', 12345678, 813286) - expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'})).to have_been_made + @client.list_subscriber?("sferik", 12345678, 813286) + expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :list_id => "12345678", :user_id => "813286"})).to have_been_made end end context "with a list object passed" do before do - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => "7505382", :list_id => "12345678", :user_id => "813286"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new(:id => 12345678, :user => {:id => 7505382, :screen_name => 'sferik'}) + list = Twitter::List.new(:id => 12345678, :user => {:id => 7505382, :screen_name => "sferik"}) @client.list_subscriber?(list, 813286) - expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_id => "7505382", :list_id => "12345678", :user_id => "813286"})).to have_been_made end end context "with a screen name passed for user_to_check" do before do - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :screen_name => "erebor"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.list_subscriber?("sferik", "presidents", 'erebor') - expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'})).to have_been_made + @client.list_subscriber?("sferik", "presidents", "erebor") + expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :screen_name => "erebor"})).to have_been_made end end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_subscriber?("presidents", 813286) - expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/subscribers/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end end end @@ -238,11 +270,11 @@ describe "#list_unsubscribe" do context "with a screen name passed" do before do - stub_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_unsubscribe("sferik", "presidents") - expect(a_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end it "returns the specified list" do list = @client.list_unsubscribe("sferik", "presidents") @@ -253,11 +285,11 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_unsubscribe("presidents") - expect(a_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_post("/1.1/lists/subscribers/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end end @@ -265,11 +297,11 @@ describe "#list_add_members" do context "with a screen name passed" do before do - stub_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_add_members("sferik", "presidents", [813286, 18755393]) - expect(a_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"})).to have_been_made + expect(a_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"})).to have_been_made end it "returns the list" do list = @client.list_add_members("sferik", "presidents", [813286, 18755393]) @@ -279,21 +311,21 @@ end context "with a combination of member IDs and member screen names to add" do before do - stub_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.list_add_members('sferik', 'presidents', [813286, 'pengwynn', 18755393, 'erebor']) - expect(a_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"})).to have_been_made + @client.list_add_members("sferik", "presidents", [813286, "pengwynn", 18755393, "erebor"]) + expect(a_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"})).to have_been_made end end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_add_members("presidents", [813286, 18755393]) - expect(a_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"})).to have_been_made + expect(a_post("/1.1/lists/members/create_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"})).to have_been_made end end end @@ -301,13 +333,13 @@ describe "#list_member?" do context "with a screen name passed" do before do - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '65493023'}).to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '12345678'}).to_return(:body => fixture("not_found.json"), :status => 403, :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "65493023"}).to_return(:body => fixture("not_found.json"), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "12345678"}).to_return(:body => fixture("not_found.json"), :status => 403, :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_member?("sferik", "presidents", 813286) - expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end it "returns true if user is a list member" do list_member = @client.list_member?("sferik", "presidents", 813286) @@ -324,49 +356,49 @@ end context "with an owner ID passed" do before do - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_member?(12345678, "presidents", 813286) - expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents", :user_id => "813286"})).to have_been_made end end context "with a list ID passed" do before do - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :list_id => "12345678", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.list_member?('sferik', 12345678, 813286) - expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => '813286'})).to have_been_made + @client.list_member?("sferik", 12345678, 813286) + expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :list_id => "12345678", :user_id => "813286"})).to have_been_made end end context "with a list object passed" do before do - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_id => "7505382", :list_id => "12345678", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new(:id => 12345678, :user => {:id => 7505382, :screen_name => 'sferik'}) + list = Twitter::List.new(:id => 12345678, :user => {:id => 7505382, :screen_name => "sferik"}) @client.list_member?(list, 813286) - expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_id => '7505382', :list_id => '12345678', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_id => "7505382", :list_id => "12345678", :user_id => "813286"})).to have_been_made end end context "with a screen name passed for user_to_check" do before do - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :screen_name => "erebor"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"}) end it "requests the correct resource" do - @client.list_member?("sferik", "presidents", 'erebor') - expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :screen_name => 'erebor'})).to have_been_made + @client.list_member?("sferik", "presidents", "erebor") + expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :screen_name => "erebor"})).to have_been_made end end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"}) + stub_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"}) end it "requests the correct resource" do @client.list_member?("presidents", 813286) - expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'})).to have_been_made + expect(a_get("/1.1/lists/members/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end end end @@ -374,11 +406,11 @@ describe "#list_members" do context "with a screen name passed" do before do - stub_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_members("sferik", "presidents") - expect(a_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"})).to have_been_made + expect(a_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"})).to have_been_made end it "returns the members of the specified list" do list_members = @client.list_members("sferik", "presidents") @@ -388,14 +420,30 @@ expect(list_members.users.first.id).to eq 7505382 end end + context "with a user ID passed" do + before do + stub_get("/1.1/lists/members.json").with(:query => {:owner_id => "7505382", :slug => "presidents", :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.list_members(7505382, "presidents") + expect(a_get("/1.1/lists/members.json").with(:query => {:owner_id => "7505382", :slug => "presidents", :cursor => "-1"})).to have_been_made + end + it "returns the members of the specified list" do + list_members = @client.list_members(7505382, "presidents") + expect(list_members).to be_a Twitter::Cursor + expect(list_members.users).to be_an Array + expect(list_members.users.first).to be_a Twitter::User + expect(list_members.users.first.id).to eq 7505382 + end + end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_members("presidents") - expect(a_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"})).to have_been_made + expect(a_get("/1.1/lists/members.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents", :cursor => "-1"})).to have_been_made end end end @@ -403,11 +451,11 @@ describe "#list_add_member" do context "with a screen name passed" do before do - stub_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_add_member("sferik", "presidents", 813286) - expect(a_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"})).to have_been_made + expect(a_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end it "returns the list" do list = @client.list_add_member("sferik", "presidents", 813286) @@ -418,11 +466,11 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_add_member("presidents", 813286) - expect(a_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"})).to have_been_made + expect(a_post("/1.1/lists/members/create.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286"})).to have_been_made end end end @@ -430,11 +478,11 @@ describe "#list_destroy" do context "with a screen name passed" do before do - stub_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_destroy("sferik", "presidents") - expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end it "returns the deleted list" do list = @client.list_destroy("sferik", "presidents") @@ -445,30 +493,30 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_destroy("presidents") - expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end context "with a list ID passed" do before do - stub_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => "sferik", :list_id => "12345678"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_destroy("sferik", 12345678) - expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678'})).to have_been_made + expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_screen_name => "sferik", :list_id => "12345678"})).to have_been_made end end context "with a list object passed" do before do - stub_post("/1.1/lists/destroy.json").with(:body => {:owner_id => '7505382', :list_id => '12345678'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/destroy.json").with(:body => {:owner_id => "7505382", :list_id => "12345678"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new(:id => '12345678', :user => {:id => 7505382, :screen_name => 'sferik'}) + list = Twitter::List.new(:id => "12345678", :user => {:id => 7505382, :screen_name => "sferik"}) @client.list_destroy(list) - expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_id => '7505382', :list_id => '12345678'})).to have_been_made + expect(a_post("/1.1/lists/destroy.json").with(:body => {:owner_id => "7505382", :list_id => "12345678"})).to have_been_made end end end @@ -476,11 +524,11 @@ describe "#list_update" do context "with a screen name passed" do before do - stub_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => 'sferik', :slug => "presidents", :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_update("sferik", "presidents", :description => "Presidents of the United States of America") - expect(a_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => 'sferik', :slug => "presidents", :description => "Presidents of the United States of America"})).to have_been_made + expect(a_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :description => "Presidents of the United States of America"})).to have_been_made end it "returns the updated list" do list = @client.list_update("sferik", "presidents", :description => "Presidents of the United States of America") @@ -491,30 +539,30 @@ context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_update("presidents", :description => "Presidents of the United States of America") - expect(a_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :description => "Presidents of the United States of America"})).to have_been_made + expect(a_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :description => "Presidents of the United States of America"})).to have_been_made end end context "with a list ID passed" do before do - stub_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => "sferik", :list_id => "12345678", :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_update("sferik", 12345678, :description => "Presidents of the United States of America") - expect(a_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :description => "Presidents of the United States of America"})).to have_been_made + expect(a_post("/1.1/lists/update.json").with(:body => {:owner_screen_name => "sferik", :list_id => "12345678", :description => "Presidents of the United States of America"})).to have_been_made end end context "with a list object passed" do before do - stub_post("/1.1/lists/update.json").with(:body => {:owner_id => '7505382', :list_id => '12345678', :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/update.json").with(:body => {:owner_id => "7505382", :list_id => "12345678", :description => "Presidents of the United States of America"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new(:id => '12345678', :user => {:id => 7505382, :screen_name => 'sferik'}) + list = Twitter::List.new(:id => "12345678", :user => {:id => 7505382, :screen_name => "sferik"}) @client.list_update(list, :description => "Presidents of the United States of America") - expect(a_post("/1.1/lists/update.json").with(:body => {:owner_id => '7505382', :list_id => '12345678', :description => "Presidents of the United States of America"})).to have_been_made + expect(a_post("/1.1/lists/update.json").with(:body => {:owner_id => "7505382", :list_id => "12345678", :description => "Presidents of the United States of America"})).to have_been_made end end end @@ -537,11 +585,11 @@ describe "#list" do context "with a screen name passed" do before do - stub_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list("sferik", "presidents") - expect(a_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end it "returns the updated list" do list = @client.list("sferik", "presidents") @@ -551,50 +599,50 @@ end context "with a user ID passed" do before do - stub_get("/1.1/lists/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.list(12345678, 'presidents') - expect(a_get("/1.1/lists/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents'})).to have_been_made + @client.list(12345678, "presidents") + expect(a_get("/1.1/lists/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents"})).to have_been_made end end context "with a user object passed" do before do - stub_get("/1.1/lists/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user = Twitter::User.new(:id => '12345678') - @client.list(user, 'presidents') - expect(a_get("/1.1/lists/show.json").with(:query => {:owner_id => '12345678', :slug => 'presidents'})).to have_been_made + user = Twitter::User.new(:id => "12345678") + @client.list(user, "presidents") + expect(a_get("/1.1/lists/show.json").with(:query => {:owner_id => "12345678", :slug => "presidents"})).to have_been_made end end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list("presidents") - expect(a_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'})).to have_been_made + expect(a_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => "sferik", :slug => "presidents"})).to have_been_made end end context "with a list ID passed" do before do - stub_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => "sferik", :list_id => "12345678"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list("sferik", 12345678) - expect(a_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => 'sferik', :list_id => '12345678'})).to have_been_made + expect(a_get("/1.1/lists/show.json").with(:query => {:owner_screen_name => "sferik", :list_id => "12345678"})).to have_been_made end end context "with a list object passed" do before do - stub_get("/1.1/lists/show.json").with(:query => {:owner_id => '7505382', :list_id => '12345678'}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/show.json").with(:query => {:owner_id => "7505382", :list_id => "12345678"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - list = Twitter::List.new(:id => '12345678', :user => {:id => 7505382, :screen_name => 'sferik'}) + list = Twitter::List.new(:id => "12345678", :user => {:id => 7505382, :screen_name => "sferik"}) @client.list(list) - expect(a_get("/1.1/lists/show.json").with(:query => {:owner_id => '7505382', :list_id => '12345678'})).to have_been_made + expect(a_get("/1.1/lists/show.json").with(:query => {:owner_id => "7505382", :list_id => "12345678"})).to have_been_made end end end @@ -602,14 +650,30 @@ describe "#subscriptions" do context "with a screen name passed" do before do - stub_get("/1.1/lists/subscriptions.json").with(:query => {:screen_name => 'pengwynn', :cursor => "-1"}).to_return(:body => fixture("subscriptions.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/lists/subscriptions.json").with(:query => {:screen_name => "sferik", :cursor => "-1"}).to_return(:body => fixture("subscriptions.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.subscriptions("pengwynn") - expect(a_get("/1.1/lists/subscriptions.json").with(:query => {:screen_name => 'pengwynn', :cursor => "-1"})).to have_been_made + @client.subscriptions("sferik") + expect(a_get("/1.1/lists/subscriptions.json").with(:query => {:screen_name => "sferik", :cursor => "-1"})).to have_been_made end it "returns the lists the specified user follows" do - subscriptions = @client.subscriptions("pengwynn") + subscriptions = @client.subscriptions("sferik") + expect(subscriptions).to be_a Twitter::Cursor + expect(subscriptions.lists).to be_an Array + expect(subscriptions.lists.first).to be_a Twitter::List + expect(subscriptions.lists.first.name).to eq "Rubyists" + end + end + context "with a user ID passed" do + before do + stub_get("/1.1/lists/subscriptions.json").with(:query => {:user_id => "7505382", :cursor => "-1"}).to_return(:body => fixture("subscriptions.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.subscriptions(7505382) + expect(a_get("/1.1/lists/subscriptions.json").with(:query => {:user_id => "7505382", :cursor => "-1"})).to have_been_made + end + it "returns the lists the specified user follows" do + subscriptions = @client.subscriptions(7505382) expect(subscriptions).to be_a Twitter::Cursor expect(subscriptions.lists).to be_an Array expect(subscriptions.lists.first).to be_a Twitter::List @@ -631,11 +695,11 @@ describe "#list_remove_members" do context "with a screen name passed" do before do - stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_remove_members("sferik", "presidents", [813286, 18755393]) - expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"})).to have_been_made + expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"})).to have_been_made end it "returns the list" do list = @client.list_remove_members("sferik", "presidents", [813286, 18755393]) @@ -643,23 +707,37 @@ expect(list.name).to eq "presidents" end end + context "with a user ID passed" do + before do + stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_id => "7505382", :slug => "presidents", :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.list_remove_members(7505382, "presidents", [813286, 18755393]) + expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_id => "7505382", :slug => "presidents", :user_id => "813286,18755393"})).to have_been_made + end + it "returns the list" do + list = @client.list_remove_members(7505382, "presidents", [813286, 18755393]) + expect(list).to be_a Twitter::List + expect(list.name).to eq "presidents" + end + end context "with a combination of member IDs and member screen names to add" do before do - stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.list_remove_members('sferik', 'presidents', [813286, 'pengwynn', 18755393, 'erebor']) - expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"})).to have_been_made + @client.list_remove_members("sferik", "presidents", [813286, "pengwynn", 18755393, "erebor"]) + expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"})).to have_been_made end end context "without a screen name passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"}).to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @client.list_remove_members("presidents", [813286, 18755393]) - expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"})).to have_been_made + expect(a_post("/1.1/lists/members/destroy_all.json").with(:body => {:owner_screen_name => "sferik", :slug => "presidents", :user_id => "813286,18755393"})).to have_been_made end end end diff --git a/spec/twitter/api/search_spec.rb b/spec/twitter/api/search_spec.rb index f34eb7649..2fa6e21b6 100644 --- a/spec/twitter/api/search_spec.rb +++ b/spec/twitter/api/search_spec.rb @@ -11,18 +11,18 @@ stub_get("/1.1/search/tweets.json").with(:query => {:q => "twitter"}).to_return(:body => fixture("search.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.search('twitter') + @client.search("twitter") expect(a_get("/1.1/search/tweets.json").with(:query => {:q => "twitter"})).to have_been_made end it "returns recent Tweets related to a query with images and videos embedded" do - search = @client.search('twitter') + search = @client.search("twitter") expect(search).to be_a Twitter::SearchResults expect(search.results).to be_an Array expect(search.results.first).to be_a Twitter::Tweet expect(search.results.first.text).to eq "Bubble Mailer #freebandnames" end it "returns the max_id value for a search result" do - search = @client.search('twitter') + search = @client.search("twitter") expect(search.max_id).to eq 250126199840518145 end @@ -32,7 +32,7 @@ end it "returns an empty array" do - search = @client.search('twitter') + search = @client.search("twitter") expect(search.results).to be_an Array expect(search.results).to be_empty end diff --git a/spec/twitter/api/suggested_users_spec.rb b/spec/twitter/api/suggested_users_spec.rb index 26ac3beb6..694d08a69 100644 --- a/spec/twitter/api/suggested_users_spec.rb +++ b/spec/twitter/api/suggested_users_spec.rb @@ -56,39 +56,4 @@ end end - describe "#following_followers_of" do - context "with a screen_name passed" do - before do - stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resource" do - @client.following_followers_of("sferik") - expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made - end - it "returns an array of numeric IDs for every user following the specified user" do - following_followers_of = @client.following_followers_of("sferik") - expect(following_followers_of).to be_a Twitter::Cursor - expect(following_followers_of.users).to be_an Array - expect(following_followers_of.users.first).to be_a Twitter::User - end - end - context "without arguments passed" do - before do - stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resource" do - @client.following_followers_of - expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made - expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made - end - it "returns an array of numeric IDs for every user following the specified user" do - following_followers_of = @client.following_followers_of - expect(following_followers_of).to be_a Twitter::Cursor - expect(following_followers_of.users).to be_an Array - expect(following_followers_of.users.first).to be_a Twitter::User - end - end - end - end diff --git a/spec/twitter/api/undocumented_spec.rb b/spec/twitter/api/undocumented_spec.rb index 222c2b17f..b73c11b4b 100644 --- a/spec/twitter/api/undocumented_spec.rb +++ b/spec/twitter/api/undocumented_spec.rb @@ -50,6 +50,21 @@ expect(following_followers_of.users.first).to be_a Twitter::User end end + context "with a user ID passed" do + before do + stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :user_id => "7505382"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.following_followers_of(7505382) + expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :user_id => "7505382"})).to have_been_made + end + it "returns an array of numeric IDs for every user following the specified user" do + following_followers_of = @client.following_followers_of(7505382) + expect(following_followers_of).to be_a Twitter::Cursor + expect(following_followers_of.users).to be_an Array + expect(following_followers_of.users.first).to be_a Twitter::User + end + end context "without arguments passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) diff --git a/spec/twitter/api/users_spec.rb b/spec/twitter/api/users_spec.rb index df54377cb..855e5c3f8 100644 --- a/spec/twitter/api/users_spec.rb +++ b/spec/twitter/api/users_spec.rb @@ -18,7 +18,7 @@ it "returns settings" do settings = @client.settings expect(settings).to be_a Twitter::Settings - expect(settings.language).to eq 'en' + expect(settings.language).to eq "en" end it "requests the correct resource on POST" do @client.settings(:trend_location_woeid => "23424803") @@ -27,7 +27,7 @@ it "returns settings" do settings = @client.settings(:trend_location_woeid => "23424803") expect(settings).to be_a Twitter::Settings - expect(settings.language).to eq 'en' + expect(settings.language).to eq "en" end end @@ -244,7 +244,7 @@ stub_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"}).to_return(:body => fixture("ids_list2.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resources" do - user = Twitter::User.new(:id => '7505382') + user = Twitter::User.new(:id => "7505382") @client.block?(user) expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "-1"})).to have_been_made expect(a_get("/1.1/blocks/ids.json").with(:query => {:cursor => "1305102810874389703"})).to have_been_made @@ -333,8 +333,8 @@ stub_post("/1.1/users/lookup.json").with(:body => {:user_id => "7505382,14100886"}).to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new(:id => '7505382') - user2 = Twitter::User.new(:id => '14100886') + user1 = Twitter::User.new(:id => "7505382") + user2 = Twitter::User.new(:id => "14100886") @client.users(user1, user2) expect(a_post("/1.1/users/lookup.json").with(:body => {:user_id => "7505382,14100886"})).to have_been_made end @@ -389,8 +389,8 @@ stub_get("/1.1/users/lookup.json").with(:query => {:user_id => "7505382,14100886"}).to_return(:body => fixture("users.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - user1 = Twitter::User.new(:id => '7505382') - user2 = Twitter::User.new(:id => '14100886') + user1 = Twitter::User.new(:id => "7505382") + user2 = Twitter::User.new(:id => "14100886") @client.users(user1, user2, :method => :get) expect(a_get("/1.1/users/lookup.json").with(:query => {:user_id => "7505382,14100886"})).to have_been_made end @@ -523,6 +523,21 @@ expect(contributees.first.name).to eq "Twitter API" end end + context "with a user ID passed" do + before do + stub_get("/1.1/users/contributees.json").with(:query => {:user_id => "7505382"}).to_return(:body => fixture("contributees.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.contributees(7505382) + expect(a_get("/1.1/users/contributees.json").with(:query => {:user_id => "7505382"})).to have_been_made + end + it "returns a user's contributees" do + contributees = @client.contributees(7505382) + expect(contributees).to be_an Array + expect(contributees.first).to be_a Twitter::User + expect(contributees.first.name).to eq "Twitter API" + end + end context "without arguments passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) @@ -544,7 +559,6 @@ describe "#contributors" do context "with a screen name passed" do before do - stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) stub_get("/1.1/users/contributors.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do @@ -558,55 +572,35 @@ expect(contributors.first.name).to eq "Biz Stone" end end - context "without arguments passed" do + context "with a user ID passed" do before do - stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/1.1/users/contributors.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/users/contributors.json").with(:query => {:user_id => "7505382"}).to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.contributors - expect(a_get("/1.1/users/contributors.json").with(:query => {:screen_name => "sferik"})).to have_been_made + @client.contributors(7505382) + expect(a_get("/1.1/users/contributors.json").with(:query => {:user_id => "7505382"})).to have_been_made end it "returns a user's contributors" do - contributors = @client.contributors + contributors = @client.contributors(7505382) expect(contributors).to be_an Array expect(contributors.first).to be_a Twitter::User expect(contributors.first.name).to eq "Biz Stone" end end - end - - describe "#following_followers_of" do - context "with a screen_name passed" do - before do - stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - end - it "requests the correct resource" do - @client.following_followers_of("sferik") - expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made - end - it "returns an array of numeric IDs for every user following the specified user" do - following_followers_of = @client.following_followers_of("sferik") - expect(following_followers_of).to be_a Twitter::Cursor - expect(following_followers_of.users).to be_an Array - expect(following_followers_of.users.first).to be_a Twitter::User - end - end context "without arguments passed" do before do stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"}) - stub_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"}).to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + stub_get("/1.1/users/contributors.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.following_followers_of - expect(a_get("/1.1/account/verify_credentials.json")).to have_been_made - expect(a_get("/users/following_followers_of.json").with(:query => {:cursor => "-1", :screen_name => "sferik"})).to have_been_made + @client.contributors + expect(a_get("/1.1/users/contributors.json").with(:query => {:screen_name => "sferik"})).to have_been_made end - it "returns an array of numeric IDs for every user following the specified user" do - following_followers_of = @client.following_followers_of - expect(following_followers_of).to be_a Twitter::Cursor - expect(following_followers_of.users).to be_an Array - expect(following_followers_of.users.first).to be_a Twitter::User + it "returns a user's contributors" do + contributors = @client.contributors + expect(contributors).to be_an Array + expect(contributors.first).to be_a Twitter::User + expect(contributors.first.name).to eq "Biz Stone" end end end @@ -639,17 +633,32 @@ end end - describe '#profile_banner' do + describe "#profile_banner" do context "with a screen_name passed" do before do stub_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"}).to_return(:body => fixture("profile_banner.json"), :headers => {:content_type => "application/json; charset=utf-8"}) end it "requests the correct resource" do - @client.profile_banner('sferik') + @client.profile_banner("sferik") expect(a_get("/1.1/users/profile_banner.json").with(:query => {:screen_name => "sferik"})).to have_been_made end it "returns a user's profile banner" do - banner = @client.profile_banner('sferik') + banner = @client.profile_banner("sferik") + expect(banner).to be_a Twitter::ProfileBanner + expect(banner.sizes).to be_a Hash + expect(banner.sizes[:mobile].height).to eq 160 + end + end + context "with a user ID passed" do + before do + stub_get("/1.1/users/profile_banner.json").with(:query => {:user_id => "7505382"}).to_return(:body => fixture("profile_banner.json"), :headers => {:content_type => "application/json; charset=utf-8"}) + end + it "requests the correct resource" do + @client.profile_banner(7505382) + expect(a_get("/1.1/users/profile_banner.json").with(:query => {:user_id => "7505382"})).to have_been_made + end + it "returns a user's profile banner" do + banner = @client.profile_banner(7505382) expect(banner).to be_a Twitter::ProfileBanner expect(banner.sizes).to be_a Hash expect(banner.sizes[:mobile].height).to eq 160