From b949c0400dabc6774419025e7b131d0a18447c3a Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 17 Dec 2013 10:00:35 -0500 Subject: [PATCH] Don't suppress `Twitter::Error::Forbidden` in #follow and #follow! Closes #502. --- lib/twitter/error.rb | 1 + lib/twitter/rest/api/friends_and_followers.rb | 8 +------- spec/fixtures/forbidden.json | 1 + spec/helper.rb | 2 +- spec/twitter/rest/api/friends_and_followers_spec.rb | 8 ++++++++ 5 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 spec/fixtures/forbidden.json diff --git a/lib/twitter/error.rb b/lib/twitter/error.rb index 0f5a398d8..36005bd4d 100644 --- a/lib/twitter/error.rb +++ b/lib/twitter/error.rb @@ -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 diff --git a/lib/twitter/rest/api/friends_and_followers.rb b/lib/twitter/rest/api/friends_and_followers.rb index bee9effc7..90f560484 100644 --- a/lib/twitter/rest/api/friends_and_followers.rb +++ b/lib/twitter/rest/api/friends_and_followers.rb @@ -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! diff --git a/spec/fixtures/forbidden.json b/spec/fixtures/forbidden.json new file mode 100644 index 000000000..6fed130f3 --- /dev/null +++ b/spec/fixtures/forbidden.json @@ -0,0 +1 @@ +{"errors":[{"code":160,"message":"You've already requested to follow %s."}]} \ No newline at end of file diff --git a/spec/helper.rb b/spec/helper.rb index ec459b338..63e75e962 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -8,7 +8,7 @@ SimpleCov.start do add_filter '/spec/' - minimum_coverage(99.07) + minimum_coverage(99.13) end require 'twitter' diff --git a/spec/twitter/rest/api/friends_and_followers_spec.rb b/spec/twitter/rest/api/friends_and_followers_spec.rb index 05d19972c..66feaf2b6 100644 --- a/spec/twitter/rest/api/friends_and_followers_spec.rb +++ b/spec/twitter/rest/api/friends_and_followers_spec.rb @@ -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