mbleigh-twitter-auth 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe TwitterAuth::Dispatcher::Basic do
4
+ before do
5
+ stub_basic!
6
+ @user = Factory.create(:twitter_basic_user, :login => 'twitterman', :password => 'test')
7
+ end
8
+
9
+ it 'should require a user as the initialization argument' do
10
+ lambda{TwitterAuth::Dispatcher::Basic.new(nil)}.should raise_error(TwitterAuth::Error, 'Dispatcher must be initialized with a User.')
11
+ end
12
+
13
+ it 'should store the user in an attr_accessor' do
14
+ TwitterAuth::Dispatcher::Basic.new(@user).user.should == @user
15
+ end
16
+
17
+ describe '#request' do
18
+ before do
19
+ @dispatcher = TwitterAuth::Dispatcher::Basic.new(@user)
20
+ FakeWeb.register_uri('https://twitter.com:443/fake.json', :string => {'fake' => true}.to_json)
21
+ FakeWeb.register_uri('https://twitter.com:443/fake.xml', :string => '<fake>true</fake>')
22
+ end
23
+
24
+ it 'should automatically parse JSON if valid' do
25
+ @dispatcher.request(:get, '/fake.json').should == {'fake' => true}
26
+ end
27
+
28
+ it 'should return XML as a string' do
29
+ @dispatcher.request(:get, '/fake.xml').should == "<fake>true</fake>"
30
+ end
31
+
32
+ it 'should append .json to the path if no extension is provided' do
33
+ @dispatcher.request(:get, '/fake.json').should == @dispatcher.request(:get, '/fake')
34
+ end
35
+
36
+ %w(get post put delete).each do |method|
37
+ it "should build a #{method} class based on a :#{method} http_method" do
38
+ @req = "Net::HTTP::#{method.capitalize}".constantize.new('/fake.json')
39
+ "Net::HTTP::#{method.capitalize}".constantize.should_receive(:new).and_return(@req)
40
+ @dispatcher.request(method.to_sym, '/fake')
41
+ end
42
+ end
43
+
44
+ it 'should start the HTTP session' do
45
+ @net = TwitterAuth.net
46
+ TwitterAuth.stub!(:net).and_return(@net)
47
+ @net.should_receive(:start)
48
+ lambda{@dispatcher.request(:get, '/fake')}.should raise_error(NoMethodError)
49
+ end
50
+ end
51
+
52
+ %w(get post delete put).each do |method|
53
+ it "should have a ##{method} method that calls request(:#{method})" do
54
+ dispatcher = TwitterAuth::Dispatcher::Basic.new(@user)
55
+ if %w(get delete).include?(method)
56
+ dispatcher.should_receive(:request).with(method.to_sym, '/fake.json')
57
+ else
58
+ dispatcher.should_receive(:request).with(method.to_sym, '/fake.json', '')
59
+ end
60
+ dispatcher.send(method, '/fake.json')
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe TwitterAuth::Dispatcher::Oauth do
4
+ before do
5
+ stub_oauth!
6
+ @user = Factory.create(:twitter_oauth_user, :access_token => 'token', :access_secret => 'secret')
7
+ end
8
+
9
+ it 'should be a child class of OAuth::AccessToken' do
10
+ TwitterAuth::Dispatcher::Oauth.new(@user).should be_a(OAuth::AccessToken)
11
+ end
12
+
13
+ it 'should require initialization of an OauthUser' do
14
+ lambda{TwitterAuth::Dispatcher::Oauth.new(nil)}.should raise_error(TwitterAuth::Error, 'Dispatcher must be initialized with a User.')
15
+ end
16
+
17
+ it 'should store the user in an attr_accessor' do
18
+ TwitterAuth::Dispatcher::Oauth.new(@user).user.should == @user
19
+ end
20
+
21
+ it "should initialize with the user's token and secret" do
22
+ d = TwitterAuth::Dispatcher::Oauth.new(@user)
23
+ d.token.should == 'token'
24
+ d.secret.should == 'secret'
25
+ end
26
+
27
+ describe '#request' do
28
+ before do
29
+ @dispatcher = TwitterAuth::Dispatcher::Oauth.new(@user)
30
+ FakeWeb.register_uri(:get, 'https://twitter.com:443/fake.json', :string => {'fake' => true}.to_json)
31
+ FakeWeb.register_uri(:get, 'https://twitter.com:443/fake.xml', :string => "<fake>true</fake>")
32
+ end
33
+
34
+ it 'should automatically parse json' do
35
+ result = @dispatcher.request(:get, '/fake.json')
36
+ result.should be_a(Hash)
37
+ result['fake'].should be_true
38
+ end
39
+
40
+ it 'should return xml as a string' do
41
+ @dispatcher.request(:get, '/fake.xml').should == '<fake>true</fake>'
42
+ end
43
+
44
+ it 'should append .json to the path if no extension is provided' do
45
+ @dispatcher.request(:get, '/fake').should == @dispatcher.request(:get, '/fake.json')
46
+ end
47
+
48
+ it 'should work with verb methods' do
49
+ @dispatcher.get('/fake').should == @dispatcher.request(:get, '/fake')
50
+ end
51
+ end
52
+ end
@@ -1 +1,130 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe TwitterAuth do
4
+ describe '#base_url' do
5
+ it 'should have default to https://twitter.com' do
6
+ TwitterAuth.stub!(:config).and_return({})
7
+ TwitterAuth.base_url.should == 'https://twitter.com'
8
+ end
9
+
10
+ it 'should otherwise load from the config[base_url]' do
11
+ TwitterAuth.stub!(:config).and_return({'base_url' => 'https://example.com'})
12
+ TwitterAuth.base_url.should == 'https://example.com'
13
+ end
14
+ end
15
+
16
+ describe '#api_timeout' do
17
+ it 'should default to 10' do
18
+ TwitterAuth.stub!(:config).and_return({})
19
+ TwitterAuth.api_timeout.should == 10
20
+ end
21
+
22
+ it 'should be settable via config' do
23
+ TwitterAuth.stub!(:config).and_return({'api_timeout' => 15})
24
+ TwitterAuth.api_timeout.should == 15
25
+ end
26
+ end
27
+
28
+ describe '.net' do
29
+ before do
30
+ stub_basic!
31
+ end
32
+
33
+ it 'should return a Net::HTTP object' do
34
+ TwitterAuth.net.should be_a(Net::HTTP)
35
+ end
36
+
37
+ it 'should be SSL if the base_url is' do
38
+ TwitterAuth.stub!(:config).and_return({'base_url' => 'http://twitter.com'})
39
+ TwitterAuth.net.use_ssl?.should be_false
40
+ TwitterAuth.stub!(:config).and_return({'base_url' => 'https://twitter.com'})
41
+ TwitterAuth.net.use_ssl?.should be_true
42
+ end
43
+
44
+ it 'should work from the base_url' do
45
+ @net = Net::HTTP.new('example.com',80)
46
+ Net::HTTP.should_receive(:new).with('example.com',80).and_return(@net)
47
+ TwitterAuth.stub!(:config).and_return({'base_url' => 'http://example.com'})
48
+ TwitterAuth.net
49
+ end
50
+ end
51
+
52
+ describe '#config' do
53
+ before do
54
+ TwitterAuth.send(:instance_variable_set, :@config, nil)
55
+ @config_file = File.open(File.dirname(__FILE__) + '/fixtures/config/twitter_auth.yml')
56
+ File.should_receive(:open).any_number_of_times.and_return(@config_file)
57
+ end
58
+
59
+ it 'should load a hash from RAILS_ROOT/config/twitter.yml' do
60
+ TwitterAuth.config.should be_a(Hash)
61
+ end
62
+
63
+ it 'should be able to override the RAILS_ENV' do
64
+ TwitterAuth.config('development')['oauth_consumer_key'].should == 'devkey'
65
+ end
66
+ end
67
+
68
+ describe '#consumer' do
69
+ before do
70
+ stub_oauth!
71
+ end
72
+
73
+ it 'should be an OAuth Consumer' do
74
+ TwitterAuth.consumer.should be_a(OAuth::Consumer)
75
+ end
76
+
77
+ it 'should use the credentials from #config' do
78
+ TwitterAuth.consumer.key.should == 'testkey'
79
+ TwitterAuth.consumer.secret.should == 'testsecret'
80
+ end
81
+
82
+ it 'should use the TwitterAuth base_url' do
83
+ TwitterAuth.stub!(:base_url).and_return('https://example.com')
84
+ TwitterAuth.consumer.site.should == TwitterAuth.base_url
85
+ TwitterAuth.consumer.site.should == 'https://example.com'
86
+ end
87
+ end
88
+
89
+ describe '#strategy' do
90
+ it 'should pull and symbolize from the config' do
91
+ TwitterAuth.stub!(:config).and_return({'strategy' => 'oauth'})
92
+ TwitterAuth.strategy.should == TwitterAuth.config['strategy'].to_sym
93
+ end
94
+
95
+ it 'should raise an argument error if not oauth or basic' do
96
+ TwitterAuth.stub!(:config).and_return({'strategy' => 'oauth'})
97
+ lambda{TwitterAuth.strategy}.should_not raise_error(ArgumentError)
98
+
99
+ TwitterAuth.stub!(:config).and_return({'strategy' => 'basic'})
100
+ lambda{TwitterAuth.strategy}.should_not raise_error(ArgumentError)
101
+
102
+ TwitterAuth.stub!(:config).and_return({'strategy' => 'invalid_strategy'})
103
+ lambda{TwitterAuth.strategy}.should raise_error(ArgumentError)
104
+ end
105
+ end
106
+
107
+ it '#oauth? should be true if strategy is :oauth' do
108
+ TwitterAuth.stub!(:config).and_return({'strategy' => 'oauth'})
109
+ TwitterAuth.oauth?.should be_true
110
+ TwitterAuth.basic?.should be_false
111
+ end
112
+
113
+ it '#basic? should be true if strategy is :basic' do
114
+ TwitterAuth.stub!(:config).and_return({'strategy' => 'basic'})
115
+ TwitterAuth.oauth?.should be_false
116
+ TwitterAuth.basic?.should be_true
117
+ end
118
+
119
+ describe '#encryption_key' do
120
+ it 'should raise a Cryptify error if none is found' do
121
+ TwitterAuth.stub!(:config).and_return({})
122
+ lambda{TwitterAuth.encryption_key}.should raise_error(TwitterAuth::Cryptify::Error, "You must specify an encryption_key in config/twitter_auth.yml")
123
+ end
124
+
125
+ it 'should return the config[encryption_key] value' do
126
+ TwitterAuth.stub!(:config).and_return({'encryption_key' => 'mickeymouse'})
127
+ TwitterAuth.encryption_key.should == 'mickeymouse'
128
+ end
129
+ end
130
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbleigh-twitter-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,31 +9,80 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-07 00:00:00 -08:00
12
+ date: 2009-03-20 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
16
- description: TODO
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oauth
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.3.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: ezcrypto
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.2
34
+ version:
35
+ description: TwitterAuth is a Rails plugin gem that provides Single Sign-On capabilities for Rails applications via Twitter. Both OAuth and HTTP Basic are supported.
17
36
  email: michael@intridea.com
18
37
  executables: []
19
38
 
20
39
  extensions: []
21
40
 
22
- extra_rdoc_files: []
23
-
41
+ extra_rdoc_files:
42
+ - README.markdown
24
43
  files:
25
44
  - README.markdown
26
45
  - VERSION.yml
27
46
  - generators/twitter_auth
28
47
  - generators/twitter_auth/templates
29
48
  - generators/twitter_auth/templates/migration.rb
49
+ - generators/twitter_auth/templates/twitter_auth.yml
30
50
  - generators/twitter_auth/templates/user.rb
31
51
  - generators/twitter_auth/twitter_auth_generator.rb
52
+ - generators/twitter_auth/USAGE
32
53
  - lib/twitter_auth
33
54
  - lib/twitter_auth/controller_extensions.rb
34
55
  - lib/twitter_auth/cryptify.rb
56
+ - lib/twitter_auth/dispatcher
57
+ - lib/twitter_auth/dispatcher/basic.rb
58
+ - lib/twitter_auth/dispatcher/oauth.rb
35
59
  - lib/twitter_auth.rb
60
+ - lib/twitteresque
61
+ - spec/controllers
62
+ - spec/controllers/controller_extensions_spec.rb
63
+ - spec/controllers/sessions_controller_spec.rb
64
+ - spec/debug.log
65
+ - spec/fixtures
66
+ - spec/fixtures/config
67
+ - spec/fixtures/config/twitter_auth.yml
68
+ - spec/fixtures/factories.rb
69
+ - spec/fixtures/fakeweb.rb
70
+ - spec/fixtures/twitter
71
+ - spec/fixtures/twitter/account
72
+ - spec/fixtures/twitter.rb
73
+ - spec/models
74
+ - spec/models/twitter_auth
75
+ - spec/models/twitter_auth/basic_user_spec.rb
76
+ - spec/models/twitter_auth/generic_user_spec.rb
77
+ - spec/models/twitter_auth/oauth_user_spec.rb
78
+ - spec/schema.rb
79
+ - spec/spec.opts
36
80
  - spec/spec_helper.rb
81
+ - spec/twitter_auth
82
+ - spec/twitter_auth/cryptify_spec.rb
83
+ - spec/twitter_auth/dispatcher
84
+ - spec/twitter_auth/dispatcher/basic_spec.rb
85
+ - spec/twitter_auth/dispatcher/oauth_spec.rb
37
86
  - spec/twitter_auth_spec.rb
38
87
  has_rdoc: true
39
88
  homepage: http://github.com/mbleigh/twitter-auth
@@ -61,6 +110,6 @@ rubyforge_project:
61
110
  rubygems_version: 1.2.0
62
111
  signing_key:
63
112
  specification_version: 2
64
- summary: Standard authentication stack for Rails using Twitter to log in.
113
+ summary: TwitterAuth is a Rails plugin gem that provides Single Sign-On capabilities for Rails applications via Twitter.
65
114
  test_files: []
66
115