Skip to content

Commit

Permalink
Don't suppress Twitter::Error::Forbidden in #follow and #follow!
Browse files Browse the repository at this point in the history
Closes #502.
  • Loading branch information
sferik committed Dec 17, 2013
1 parent 6a47e71 commit b949c04
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/twitter/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Codes
OVER_CAPACITY = 130
INTERNAL_ERROR = 131
OAUTH_TIMESTAMP_OUT_OF_RANGE = 135
FOLLOW_ALREADY_REQUESTED = 160
FOLLOW_LIMIT_EXCEEDED = 161
PROTECTED_STATUS = 179
OVER_UPDATE_LIMIT = 185
Expand Down
8 changes: 1 addition & 7 deletions lib/twitter/rest/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,7 @@ def follow(*args)
def follow!(*args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.threaded_map do |user|
begin
object_from_response(Twitter::User, :post, '/1.1/friendships/create.json', merge_user(arguments.options, user))
rescue Twitter::Error::Forbidden
# This error will be raised if the user doesn't have permission to
# follow list_member, for whatever reason.
next
end
object_from_response(Twitter::User, :post, '/1.1/friendships/create.json', merge_user(arguments.options, user))
end.compact
end
alias_method :create_friendship!, :follow!
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/forbidden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"errors":[{"code":160,"message":"You've already requested to follow %s."}]}
2 changes: 1 addition & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

SimpleCov.start do
add_filter '/spec/'
minimum_coverage(99.07)
minimum_coverage(99.13)
end

require 'twitter'
Expand Down
8 changes: 8 additions & 0 deletions spec/twitter/rest/api/friends_and_followers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,14 @@
expect(a_post('/1.1/friendships/create.json').with(:body => {:screen_name => 'sferik'})).to have_been_made
end
end
context 'with a forbidden error' do
before do
stub_post('/1.1/friendships/create.json').with(:body => {:screen_name => 'sferik'}).to_return(:status => 403, :body => fixture('forbidden.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
end
it 'raises an exception' do
expect { @client.follow!('sferik') }.to raise_error(Twitter::Error::Forbidden)
end
end

describe '#unfollow' do
before do
Expand Down

0 comments on commit b949c04

Please sign in to comment.