Skip to content
Browse files

store twitter_id

  • Loading branch information...
1 parent 2041d10 commit 575f106df3495287f2e3ad4ad985f205ff572cfb @jasonm jasonm committed
View
2 app/models/clearance_twitter/linked_user.rb
@@ -141,7 +141,7 @@ def new_from_twitter_hash(hash)
user = User.new
# TODO Add test to motivate #twitter_id
- # user.twitter_id = hash['id'].to_s
+ user.twitter_id = hash['id'].to_s
user.twitter_username = hash['screen_name']
user.assign_twitter_attributes(hash)
View
26 ...clearance_twitter_features/templates/features/step_definitions/clearance_twitter_steps.rb
@@ -16,28 +16,24 @@
click_link 'Sign in using Twitter'
end
+# Then 'I should be directed to sign in with Twitter' do
+# assert_redirected_to 'foo.com'
+# end
+
Then /^there should be (\d+) users? in the system$/ do |count|
assert_equal count.to_i, User.count, User.all.inspect
end
-Then 'I should be signed in as Twitter user "$username"' do |twitter_username|
- assert user = User.find_by_twitter_username(twitter_username), "No user exists for Twitter username #{twitter_username.inspect}. Users:\n#{User.all.inspect}"
+Then 'I should be signed in as Twitter user "$username" with ID $twitter_id' 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
-When 'I grant access to the Twitter application for Twitter user "$twitter_username"' do |twitter_username|
- # user = stub('user', :id => '1', :remember_me => '2', :login => 'boys', :geocoded_location => FakeGeocoder.geocode() )
- # request_token = stub('request_token', :get_access_token => 'access_token')
- # User.stubs(:identify_or_create_from_access_token).returns(user)
- # CrushesController.any_instance.stubs(:current_user).returns(user)
- # OAuth::RequestToken.stubs(:new).returns(request_token)
- #
-# {:session_id=>"4f7fe62bf1ed8509899b954469b12e16", :request_token_secret=>"same_for_this", :request_token=>"this_need_not_be_real"}
-# ---Params---
-# {"action"=>"oauth_callback", "oauth_verifier"=>"verifier", "oauth_token"=>"token", "controller"=>"clearance_twitter/twitter_users"}
-# And I grant access to the Twitter application for Twitter user "jerk
-
- FakeTwitter.stub_verify_credentials_for(twitter_username)
+When 'I grant access to the Twitter application for Twitter user "$twitter_username" with ID $twitter_id' do |twitter_username, twitter_id|
+ FakeTwitter.stub_verify_credentials_for(:twitter_username => twitter_username, :twitter_id => twitter_id)
visit oauth_callback_twitter_users_url(:oauth_token => 'this_need_not_be_real', :oauth_verifier => 'verifier')
end
View
9 generators/clearance_twitter_features/templates/features/twitter_sign_in.feature
@@ -6,12 +6,15 @@ Feature: Sign in with Twitter OAuth
Scenario: User signs in with Twitter
Given there are no users
And Twitter OAuth is faked
- And a user exists with a twitter username of "jerkcity"
+ And the following user exists:
+ | twitter_username | twitter_id |
+ | jerkcity | 999 |
When I go to the sign in page
And I click the Sign in with Twitter button
- And I grant access to the Twitter application for Twitter user "jerkcity"
+ # 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"
+ And I should be signed in as Twitter user "jerkcity" with ID 999
Scenario: Signed in user connects their Twitter account
View
5 generators/clearance_twitter_features/templates/features/twitter_sign_up.feature
@@ -8,10 +8,11 @@ Feature: Sign up with Twitter OAuth
And Twitter OAuth is faked
And I go to the sign up page
And I click the Sign in with Twitter button
- And I grant access to the Twitter application for Twitter user "jerkcity"
+ # 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"
+ And I should be signed in as Twitter user "jerkcity" with ID 999
# Deny access
# http://beerfire.heroku.com/oauth_callback?denied=gDvIISsUyVIKEsMZSmMCWPUOy3VwMU5xcRfc52GzMqk
View
13 lib/clearance_twitter/fake_twitter.rb
@@ -26,11 +26,20 @@ def stub_request(method, url, response_options)
WebMock.stub_request(method, url).to_return(response_options)
end
- def stub_verify_credentials_for(twitter_username)
+ def stub_verify_credentials_for(options)
+ twitter_username = options.delete(:twitter_username)
+ twitter_id = options.delete(:twitter_id)
+ response_json = <<-JSON
+ {
+ "screen_name":"#{twitter_username}",
+ "id":"#{twitter_id}"
+ }
+ JSON
+
verify_credentials_url = ClearanceTwitter.base_url + '/account/verify_credentials.json'
stub_request(:get, verify_credentials_url, {
:status => 200,
- :body => %|{"screen_name":"#{twitter_username}"}|
+ :body => response_json
})
end

0 comments on commit 575f106

Please sign in to comment.
Something went wrong with that request. Please try again.