Permalink
Browse files

Renamed method typo.

  • Loading branch information...
Michael Bleigh
Michael Bleigh committed Mar 19, 2009
1 parent 7a88811 commit 3e96e8189df6834e9b819dbe49d1640559e918fa
Showing with 6 additions and 13 deletions.
  1. +2 −9 app/models/twitter_auth/basic_user.rb
  2. +4 −4 spec/models/twitter_auth/basic_user_spec.rb
@@ -11,14 +11,6 @@ def self.included(base)
end
module ClassMethods
def authenticate(login, password)
Twitter::Base.new(login, password).verify_credentials
user = find_by_login(login)
rescue Twitter::CantConnect
nil
end
def verify_credentials(login, password)
uri = URI.parse(TwitterAuth.base_url)
net = Net::HTTP.new(uri.host, uri.port)
@@ -28,14 +20,15 @@ def verify_credentials(login, password)
request.basic_auth login, password
http.request(request)
}
if response.code == '200'
JSON.parse(response.body)
else
false
end
end
def authorize(login, password)
def authenticate(login, password)
if twitter_hash = verify_credentials(login, password)
user = identify_or_create_from_twitter_hash_and_password(twitter_hash, password)
user
@@ -56,24 +56,24 @@
end
end
describe '.authorize' do
describe '.authenticate' do
before do
@user = Factory.create(:twitter_basic_user)
end
it 'should make a call to verify_credentials' do
User.should_receive(:verify_credentials).with('twitterman','test')
User.authorize('twitterman','test')
User.authenticate('twitterman','test')
end
it 'should return nil if verify_credentials returns false' do
User.stub!(:verify_credentials).and_return(false)
User.authorize('twitterman','test').should be_nil
User.authenticate('twitterman','test').should be_nil
end
it 'should return the user if verify_credentials succeeds' do
User.stub!(:verify_credentials).and_return(JSON.parse("{\"profile_image_url\":\"http:\\/\\/static.twitter.com\\/images\\/default_profile_normal.png\",\"description\":\"Saving the world for all Twitter kind.\",\"utc_offset\":null,\"favourites_count\":0,\"profile_sidebar_fill_color\":\"e0ff92\",\"screen_name\":\"twitterman\",\"statuses_count\":0,\"profile_background_tile\":false,\"profile_sidebar_border_color\":\"87bc44\",\"friends_count\":2,\"url\":null,\"name\":\"Twitter Man\",\"time_zone\":null,\"protected\":false,\"profile_background_image_url\":\"http:\\/\\/static.twitter.com\\/images\\/themes\\/theme1\\/bg.gif\",\"profile_background_color\":\"9ae4e8\",\"created_at\":\"Fri Feb 06 18:10:32 +0000 2009\",\"profile_text_color\":\"000000\",\"followers_count\":2,\"location\":null,\"id\":20256865,\"profile_link_color\":\"0000ff\"}"))
User.authorize('twitterman','test').should == @user
User.authenticate('twitterman','test').should == @user
end
end

0 comments on commit 3e96e81

Please sign in to comment.