Permalink
Browse files

cleaning up features

  • Loading branch information...
1 parent 0480461 commit da11748feb05c7bb5510a6402b23fa198ecff42f @jasonm jasonm committed Mar 14, 2010
View
54 ...clearance_twitter_features/templates/features/step_definitions/clearance_twitter_steps.rb
@@ -1,53 +1,51 @@
require 'clearance_twitter/fake_twitter'
Before do
- FakeTwitterUser.clear_remote_profiles
- FakeTwitterSession.logout
+ # You can override the HTTP faking implementation like this, if you prefer:
+ # FakeTwitter.implemenation = FakeTwitter::SomeOtherBackend.new
+ #
+ # The default uses WebMock via FakeTwitter::WebMockBackend
+ FakeTwitter.disable_remote_http
end
-Given /^there are no users$/ do
+Given 'there are no users' do
User.delete_all
end
-Given /^remote Twitter user exists with an username of "([^"]+)"$/ do |twitter_username|
- FakeTwitterUser.add_remote_profile({:username => twitter_username})
+When 'I click the Sign in with Twitter button' do
+ click_link 'Sign in using Twitter'
end
-Given 'remote Twitter user exists with an username of "$username" and a name of "$name" and an email of "$email"' do |twitter_username, twitter_user_name, twitter_user_email|
- FakeTwitterUser.add_remote_profile({:id => twitter_username, :name => twitter_user_name, :email => twitter_user_email})
+Then /^there should be (\d+) users? in the system$/ do |count|
+ assert_equal count.to_i, User.count, User.all.inspect
end
-Given 'I am signed into Twitter account "$username"' do |twitter_username|
- twitter_user = FakeTwitterUser.get_remote_profile(twitter_username)
- FakeTwitterSession.login(twitter_user)
+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}"
+ assert_equal user, @controller.current_user, "Not signed in as the correct Twitter user"
end
-When 'I click the Twitter button' do
- click_link 'Sign in using Twitter'
+When 'I grant access to the Twitter application for Twitter user "$twitter_username"' do |twitter_username|
+ pending # express the regexp above with the code you wish you had
end
-Then /^there should be (\d+) users? in the system$/ do |count|
- assert_equal count.to_i, User.count, User.all.inspect
+When 'I deny access to the Twitter application' do
end
-Given 'an user exists that is connected to Twitter account "$username"' do |twitter_username|
- Factory(:user, :twitter_username => twitter_username)
+Given /^remote Twitter user exists with an username of "([^\"]*)"$/ do |arg1|
+ pending # express the regexp above with the code you wish you had
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}"
- assert_equal user, @controller.current_user, "Not signed in as the correct Twitter user"
+Given /^a user exists that is connected to Twitter account "([^\"]*)"$/ do |arg1|
+ pending # express the regexp above with the code you wish you had
end
-And /^I sign out of Twitter$/ do
- FakeTwitterSession.logout
- visit url_for(
- :controller => 'clearance/sessions',
- :action => 'destroy',
- :method => :delete
- ), :delete
+When /^I am signed into Twitter account "([^\"]*)"$/ do |arg1|
+ pending # express the regexp above with the code you wish you had
end
-Then /^I should be signed out of Twitter$/ do
- assert !@controller.local_twitter_session?
+When /^I click the Twitter button$/ do
+ pending # express the regexp above with the code you wish you had
end
+
+
View
32 generators/clearance_twitter_features/templates/features/twitter_sign_in.feature
@@ -3,34 +3,12 @@ Feature: Sign in with Twitter OAuth
An existing user
Should be able to sign in with Twitter OAuth
- @wip
Scenario: User has already signed up with Twitter OAuth
- Given remote Twitter user exists with an username of "jerkcity"
- And an user exists that is connected to Twitter account "jerkcity"
+ Given there are no users
+ And remote Twitter user exists with an username of "jerkcity"
+ And a user exists that is connected to Twitter account "jerkcity"
When I go to the sign in page
- And I am signed into Twitter account "jerkcity"
- And I click the Twitter button
+ 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 signed in as Twitter user "jerkcity"
And there should be 1 user in the system
-
- @wip
- Scenario: User has already signed up, but their account is not linked to Twitter
- Given remote Twitter user exists with an username of "jerkcity" and a name of "Alice Appleton" and an email of "user@example.com"
- And an email confirmed user exists with an email of "user@example.com"
- When I go to the sign in page
- And I am signed into Twitter account "jerkcity"
- And I click the Twitter button
- Then I should be signed in as Twitter user "jerkcity"
- And there should be 1 user in the system
-
- Scenario: A user with a Twitter account signs out
- Given remote Twitter user exists with an username of "jerkcity"
- And an user exists that is connected to Twitter account "jerkcity"
- When I go to the sign in page
- And I am signed into Twitter account "jerkcity"
- And I click the Twitter button
- Then I should be signed in as Twitter user "jerkcity"
- When I go to the homepage
- And I sign out of Twitter
- Then I should be signed out
- And I should be signed out of Twitter
View
33 generators/clearance_twitter_features/templates/features/twitter_sign_up.feature
@@ -4,22 +4,27 @@ Feature: Sign up with Twitter OAuth
Should be able to sign up with Twitter OAuth
@wip
- Scenario: User signs up with Twitter OAuth
+ Scenario: User successfully signs up with Twitter OAuth
Given there are no users
- And remote Twitter user exists with an username of "jerkcity"
- When I am signed into Twitter account "jerkcity"
And I go to the sign up page
- And I click the Twitter button
+ 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 signed in as Twitter user "jerkcity"
And there should be 1 user in the system
- @wip
- Scenario: User has already signed up with Twitter OAuth
- Given there are no users
- And remote Twitter user exists with an username of "jerkcity"
- And an user exists that is connected to Twitter account "jerkcity"
- When I go to the sign up page
- And I am signed into Twitter account "jerkcity"
- And I click the Twitter button
- Then I should be signed in as Twitter user "jerkcity"
- And there should be 1 user in the system
+ # Deny access
+ # http://beerfire.heroku.com/oauth_callback?denied=gDvIISsUyVIKEsMZSmMCWPUOy3VwMU5xcRfc52GzMqk
+
+ # Allow access
+ # http://beerfire.heroku.com/oauth_callback?oauth_token=HGvvHmjk94vmNM5sz8ny2wYIYQCpOewvxAmXaCs9Y8U&oauth_verifier=R8vGQeATOFW5BZXH65FCzMdj1uvpadFy4ENEuZvS1fs
+
+# Given /^I am signed in as "@(.*)"$/ do |twitter_username|
+# @twitter_username = twitter_username
+# stub_post('https://twitter.com/oauth/request_token', 'access_token')
+# stub_post('https://twitter.com/oauth/access_token', 'access_token')
+# stub_get('https://twitter.com/account/verify_credentials.json', 'verify_credentials.json')
+# visit path_to('the login page')
+# visit path_to('the oauth callback page')
+# end
+
+ Scenario: User goes to sign up with Twitter but denies access
View
105 lib/clearance_twitter/fake_twitter.rb
@@ -1,18 +1,107 @@
-class FakeTwitterUser
- def self.clear_remote_profiles
+class FakeTwitter
+
+ class << self
+ attr_accessor :backend
end
- def self.add_remote_profile(profile_hash)
+ # Delegate class methods to an instance of the backend of choice
+ def self.method_missing(args)
+ self.backend ||= FakeTwitter::WebMockBackend.new
+ self.backend.send(*args)
end
- def self.get_remote_profile(username)
+ class FakeOAuthRequestToken
+ attr_accessor :authorize_url, :token, :secret
+ def initialize(attributes)
+ attributes.each { |key, value| send(:"#{key}=", value) }
+ end
end
-end
-class FakeTwitterSession
- def self.logout
+ class FakeOAuthConsumer
+ attr_accessor :get_request_token
+ def initialize(attributes)
+ attributes.each { |key, value| send(:"#{key}=", value) }
+ end
end
- def self.login(twitter_user)
+ gem 'webmock'
+ require 'webmock'
+
+ class WebMockBackend
+ def disable_remote_http
+ WebMock.disable_net_connect!
+ end
+
+ def stub_request(method, url, response_options)
+ # method :get, :post, :any
+ # response_options = { :status => '...', :body => '...' }
+ WebMock.stub_request(method, url).to_return(response_options)
+ end
+
+ def stub_oauth
+ FakeTwitter.oauth_paths_to_stub.each do |path|
+ stub_request(:any, ClearanceFacebook.configuration['base_url'] + path, :body => '')
+ end
+
+ ClearanceFacebook.oauth_consumer = fake_oauth_consumer
+ end
+
+ def add_user(twitter_username)
+ end
+
+ private
+
+ def fake_oauth_consumer
+ FakeOAuthConsumer.new({
+ :get_request_token => fake_request_token
+ })
+ end
+
+ def fake_request_token
+ authorize_url = ClearanceFacebook.config['base_url'] +
+ ClearanceFacebook.config['authorize_path']
+
+ FakeOAuthRequestToken.new({
+ :authorize_url => authorize_url,
+ :token => 'token',
+ :secret => 'secret'
+ })
+ end
+
+ def oauth_paths_to_stub
+ [ClearanceFacebook.configuration['authorize_path'],
+ '/oauth/request_token',
+ '/oauth/authorize',
+ '/oauth/access_token']
+ end
+
+
+ end
+end
+
+Given /^Twitter OAuth is faked$/ do
+ [TwitterAuth.config['authorize_path'], '/oauth/request_token', '/oauth/authorize', '/oauth/access_token'].each do |path|
+ FakeWeb.register_uri(:any, TwitterAuth.config['base_url'] + path, :body => '')
end
+
+ request_token = stub('request_token',
+ :authorize_url => TwitterAuth.config['base_url'] + TwitterAuth.config['authorize_path'],
+ :token => 'token',
+ :secret => 'secret')
+ consumer = stub('consumer', :get_request_token => request_token)
+ TwitterAuth.stubs(:consumer).returns(consumer)
end
+
+Then /^I should be directed to Twitter OAuth$/ do
+ assert_redirected_to(TwitterAuth.config['base_url'] + TwitterAuth.config['authorize_path'] + '&oauth_callback=' + CGI.escape(TwitterAuth.config['oauth_callback']))
+end
+
+When /^I return from Twitter OAuth with a valid OAuth verifier for "@([^\"]*)"$/ do |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)
+ visit oauth_callback_url(:oauth_token => 'token', :oauth_verifier => 'verifier')
+end
+

0 comments on commit da11748

Please sign in to comment.