Permalink
Browse files

Signed in user connects their Twitter account

  • Loading branch information...
1 parent 96ba8e4 commit 0a006917575a48e52bc42d1311913ec197c3e571 @jasonm jasonm committed Mar 14, 2010
View
1 TODO
@@ -1,4 +1,3 @@
* Right now, send_confirmation_email sends even for twitter users; it's okay since they don't have an email, but we still shouldn't send one.
* Make it easy to not use WebMock
* Clean up TODOs
-* Scenario: Signed in user connects their Twitter account
View
8 app/controllers/clearance_twitter/twitter_users_controller.rb
@@ -26,8 +26,12 @@ def oauth_callback
session[:request_token] = nil
session[:request_token_secret] = nil
- @user = User.identify_or_create_from_access_token(@access_token)
- sign_in(@user)
+ if current_user
+ current_user.update_from_twitter_access_token(@access_token)
+ else
+ @user = User.identify_or_create_from_access_token(@access_token)
+ sign_in(@user)
+ end
# TODO: What to do here?
# cookies[:remember_token] = @user.remember_me
View
10 app/models/clearance_twitter/linked_user.rb
@@ -32,18 +32,18 @@ def twitter_user?
end
def update_from_twitter_access_token(access_token)
- hash = self.twitter_hash_from_access_token(access_token)
- self.update_from_twitter_hash_and_access_token(hash, access_token)
+ hash = self.class.twitter_hash_from_access_token(access_token)
+ update_from_twitter_hash_and_access_token(hash, access_token)
end
def update_from_twitter_hash_and_access_token(hash, access_token)
- self.populate_from_twitter_hash_and_access_token(hash, access_token)
- self.save
+ populate_from_twitter_hash_and_access_token(hash, access_token)
+ save
self
end
def populate_from_twitter_hash_and_access_token(hash, access_token)
- self.assign_twitter_attributes(hash)
+ assign_twitter_attributes(hash)
self.twitter_id = hash['id'].to_s
self.twitter_username = hash['screen_name']
self.twitter_access_token = access_token.token
View
10 ...clearance_twitter_features/templates/features/step_definitions/clearance_twitter_steps.rb
@@ -25,14 +25,22 @@
assert_equal count.to_i, User.count, User.all.inspect
end
-Then 'I should be signed in as Twitter user "$username" with ID $twitter_id' do |twitter_username, twitter_id|
+Then /^I should be signed in as Twitter user "(.*)" with ID (\d+)$/ do |twitter_username, twitter_id|
assert user = User.find_by_twitter_username_and_twitter_id(twitter_username, twitter_id),
"No user exists for Twitter username #{twitter_username.inspect} and Twitter ID #{twitter_id}.
All users:\n#{User.all.inspect}"
assert_equal user, @controller.current_user, "Not signed in as the correct Twitter user"
end
+Then /^I should be signed in as Twitter user "(.*)" with ID (\d+) and email address "(.*)"$/ do |twitter_username, twitter_id, email|
+ assert user = User.find_by_twitter_username_and_twitter_id(twitter_username, twitter_id),
+ "No user exists for Twitter username #{twitter_username.inspect} and Twitter ID #{twitter_id} and email address #{email}.
+ All users:\n#{User.all.inspect}"
+
+ assert_equal user, @controller.current_user, "Not signed in as the correct Twitter user"
+end
+
When 'I grant access to the Twitter application for Twitter user "$twitter_username" with ID $twitter_id' do |twitter_username, twitter_id|
FakeTwitter.stub_twitter_successful_access_token
FakeTwitter.stub_verify_credentials_for(:twitter_username => twitter_username, :twitter_id => twitter_id)
View
20 generators/clearance_twitter_features/templates/features/twitter_sign_in.feature
@@ -18,13 +18,13 @@ Feature: Sign in with Twitter OAuth
And I should be signed in as Twitter user "jerkcity" with ID 999
Scenario: Signed in user connects their Twitter account
- # Given the Twitter OAuth request is successful
- # And I am signed up and confirmed as "email@example.com/password"
- # When I sign in as "email@example.com/password"
- # And I am on the sign in page
- # And I click the Sign in with Twitter button
- # Then I should be directed to sign in with Twitter
- # When I grant access to the Twitter application for Twitter user "jerkcity" with ID 999
- # Then I should see "Successfully signed in with Twitter."
- # And there should be 1 user in the system
- # And I should be signed in as Twitter user "jerkcity" with ID 999 and email address "email@example.com"
+ Given the Twitter OAuth request is successful
+ And I am signed up and confirmed as "email@example.com/password"
+ When I sign in as "email@example.com/password"
+ And I am on the sign in page
+ And I click the Sign in with Twitter button
+ Then I should be directed to sign in with Twitter
+ When I grant access to the Twitter application for Twitter user "jerkcity" with ID 999
+ Then I should see "Successfully signed in with Twitter."
+ And there should be 1 user in the system
+ And I should be signed in as Twitter user "jerkcity" with ID 999 and email address "email@example.com"

0 comments on commit 0a00691

Please sign in to comment.