Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add specs for when a user ID is passed
  • Loading branch information
sferik committed Dec 20, 2012
1 parent c8cc26d commit 32837be
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 261 deletions.
104 changes: 44 additions & 60 deletions spec/twitter/api/friends_and_followers_spec.rb
Expand Up @@ -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"})
Expand Down Expand Up @@ -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"})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -425,56 +455,33 @@
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
@client.followers("sferik")
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
Expand All @@ -497,56 +504,33 @@
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
@client.friends("sferik")
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
Expand Down

0 comments on commit 32837be

Please sign in to comment.