Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup docs and twitter_fake

  • Loading branch information...
commit 31578b03cc38f6787a22ad5c556f9515007abd4b 1 parent e815df5
@jasonm jasonm authored
View
7 README
@@ -4,7 +4,14 @@ To install:
script/plugin install git@github.com:thoughtbot/clearance-twitter.git
script/generate clearance_twitter
+
+If you want cucumber features:
+
script/generate clearance_twitter_features
See generators/clearance_twitter/templates/README (displayed when you
generate) for more information.
+
+The cucumber features use WebMock to fake twitter.com OAuth responses.
+If you'd like to use another tool for this, see
+
View
1  TODO
@@ -1,3 +1,4 @@
* 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
+* Make ClearanceTwitter::LinkedUser::TWITTER_ATTRIBUTES (set of attrs copied from profile to User upon connect) easier to change / document it
View
1  app/models/clearance_twitter/linked_user.rb
@@ -2,6 +2,7 @@ module ClearanceTwitter
class Unauthorized < Exception; end
module LinkedUser
+ # Attrs to copy from the twitter user hash onto the User model upon connect
TWITTER_ATTRIBUTES = [
:name
]
View
2  generators/clearance_twitter/clearance_twitter_generator.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
+require File.expand_path(File.dirname(__FILE__) + "/../lib/insert_commands.rb")
class ClearanceTwitterGenerator < Rails::Generator::Base
def manifest
View
7 generators/clearance_twitter_features/clearance_twitter_features_generator.rb
@@ -1,5 +1,6 @@
-class ClearanceTwitterFeaturesGenerator < Rails::Generator::Base
+require File.expand_path(File.dirname(__FILE__) + "/../lib/insert_commands.rb")
+class ClearanceTwitterFeaturesGenerator < Rails::Generator::Base
def manifest
record do |m|
m.directory File.join("features", "step_definitions")
@@ -9,7 +10,9 @@ def manifest
"features/twitter_sign_up.feature"].each do |file|
m.file file, file
end
+
+ m.insert_into 'features/support/env.rb', 'World(WebMockTwitterFake)'
+ m.insert_into 'features/support/env.rb', 'World(TwitterFake)'
end
end
-
end
View
16 generators/clearance_twitter_features/templates/features/step_definitions/clearance_twitter_steps.rb
@@ -1,11 +1,7 @@
-require 'clearance_twitter/fake_twitter'
+require 'clearance_twitter/twitter_fake'
Before do
- # 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
+ disable_remote_http
end
Given 'there are no users' do
@@ -42,17 +38,17 @@
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)
+ stub_twitter_successful_access_token
+ stub_twitter_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
When 'I deny access to the Twitter application' do
- FakeTwitter.stub_twitter_denied_access_token
+ stub_twitter_denied_access_token
visit oauth_callback_twitter_users_url(:denied => 'denied_token')
end
Given /^the Twitter OAuth request is successful$/ do
- FakeTwitter.stub_twitter_request_token
+ stub_twitter_request_token
end
View
8 generators/clearance_twitter_features/templates/features/support/clearance_twitter_support.rb
@@ -0,0 +1,8 @@
+# If you want to use something other than WebMock to fake remote HTTP resources
+# replace WebMockTwitterFake with your own module
+
+require 'clearance_twitter/web_mock_twitter_fake'
+require 'clearance_twitter/twitter_fake'
+
+World(WebMockTwitterFake)
+World(TwitterFake)
View
0  generators/clearance_twitter/lib/insert_commands.rb → generators/lib/insert_commands.rb
File renamed without changes
View
68 lib/clearance_twitter/fake_twitter.rb
@@ -1,68 +0,0 @@
-# TODO: Add World(FakeTwitter::WebMockHelpers) to features/support/env.rb in generator
-# thereby allowing user to change this easily without the method_missing crap.
-
-class FakeTwitter
-
- class << self
- attr_accessor :backend
- end
-
- # 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
-
- 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_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 => response_json
- })
- end
-
- def stub_twitter_request_token
- stub_request(:any, "#{ClearanceTwitter.base_url}/oauth/request_token", {
- :status => 200,
- :body => "oauth_token=this_need_not_be_real&oauth_token_secret=same_for_this"
- })
- end
-
- def stub_twitter_successful_access_token
- stub_request(:any, "#{ClearanceTwitter.base_url}/oauth/access_token", {
- :status => 200,
- :body => "oauth_token=this_need_not_be_real&oauth_token_secret=same_for_this"
- })
- end
-
- def stub_twitter_denied_access_token
- stub_request(:any, "#{ClearanceTwitter.base_url}/oauth/access_token", {
- :status => 401,
- :body => ''
- })
- end
- end
-end
-
View
43 lib/clearance_twitter/twitter_fake.rb
@@ -0,0 +1,43 @@
+# See web_mock_twitter_fake.rb which supplies the following methods:
+#
+# stub_http_request_for_fake_twitter
+#
+module TwitterFake
+ def stub_twitter_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_http_request_for_fake_twitter(:get, verify_credentials_url, {
+ :status => 200,
+ :body => response_json
+ })
+ end
+
+ def stub_twitter_request_token
+ stub_http_request_for_fake_twitter(:any, "#{ClearanceTwitter.base_url}/oauth/request_token", {
+ :status => 200,
+ :body => "oauth_token=this_need_not_be_real&oauth_token_secret=same_for_this"
+ })
+ end
+
+ def stub_twitter_successful_access_token
+ stub_http_request_for_fake_twitter(:any, "#{ClearanceTwitter.base_url}/oauth/access_token", {
+ :status => 200,
+ :body => "oauth_token=this_need_not_be_real&oauth_token_secret=same_for_this"
+ })
+ end
+
+ def stub_twitter_denied_access_token
+ stub_http_request_for_fake_twitter(:any, "#{ClearanceTwitter.base_url}/oauth/access_token", {
+ :status => 401,
+ :body => ''
+ })
+ end
+end
View
11 lib/clearance_twitter/web_mock_twitter_fake.rb
@@ -0,0 +1,11 @@
+require 'webmock'
+
+module WebMockTwitterFake
+ def disable_remote_http
+ WebMock.disable_net_connect!
+ end
+
+ def stub_http_request_for_fake_twitter(method, url, response_options)
+ WebMock.stub_request(method, url).to_return(response_options)
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.