twitter-login 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/twitter/login.rb +11 -1
  2. data/spec/login_spec.rb +16 -19
  3. metadata +6 -6
@@ -101,7 +101,7 @@ class Twitter::Login
101
101
  response = access_token.get('/1/account/verify_credentials.json')
102
102
 
103
103
  # get and store authenticated user's info from Twitter
104
- request.session[:twitter_user] = Yajl::Parser.parse response.body
104
+ request.session[:twitter_user] = user_hash_from_response(response)
105
105
 
106
106
  # pass the request down to the main app
107
107
  response = begin
@@ -155,4 +155,14 @@ class Twitter::Login
155
155
  :authorize_path => '/oauth/authenticate'
156
156
  )
157
157
  end
158
+
159
+ def user_hash_from_response(api_response)
160
+ parse_response(api_response).reject { |key, _|
161
+ key == 'status' or key =~ /^profile_|_color$/
162
+ }
163
+ end
164
+
165
+ def parse_response(api_response)
166
+ Yajl::Parser.parse api_response.body
167
+ end
158
168
  end
@@ -44,38 +44,35 @@ describe Twitter::Login do
44
44
 
45
45
  it "should login with Twitter" do
46
46
  request_token = mock('Request Token', :authorize_url => 'http://disney.com/oauth', :token => 'abc', :secret => '123')
47
- oauth = mock_oauth('Twitter OAuth', :request_token => request_token)
48
- oauth.should_receive(:set_callback_url).with('http://example.org/login')
47
+ oauth = mock_oauth('Twitter OAuth')
48
+ oauth.should_receive(:get_request_token).with(:oauth_callback => 'http://example.org/login').and_return(request_token)
49
49
 
50
50
  get('/login', :lint => true)
51
51
  response.status.should == 302
52
52
  response['Location'].should == 'http://disney.com/oauth'
53
53
  response.body.should be_empty
54
- session[:request_token].should == ['abc', '123']
54
+ session[:twitter_request_token].should == ['abc', '123']
55
55
  end
56
56
 
57
57
  it "should authorize with Twitter" do
58
- consumer = mock('OAuth consumer')
58
+ oauth = mock_oauth('Twitter OAuth')
59
+ request_token = mock('Request Token')
60
+ OAuth::RequestToken.should_receive(:new).with(oauth, 'abc', '123').and_return(request_token)
59
61
  access_token = mock('Access Token', :token => 'access1', :secret => '42')
60
- oauth = mock_oauth('Twitter OAuth', :access_token => access_token, :consumer => consumer)
61
- oauth.should_receive(:authorize_from_request).with('abc', '123', 'allrighty')
62
+ request_token.should_receive(:get_access_token).with(:oauth_verifier => 'allrighty').and_return(access_token)
62
63
 
63
- twitter = mock('Twitter Base')
64
- Twitter::Base.should_receive(:new).with(oauth).and_return(twitter)
64
+ payload = { :screen_name => 'faker', :name => 'Fake Jr.', :followers_count => '13',
65
+ :profile_image_url => 'http://disney.com/mickey.png', :friends_count => '6', :statuses_count => '52' }
65
66
 
66
- twitter.should_receive(:verify_credentials).and_return {
67
- Hashie::Mash.new :screen_name => 'faker',
68
- :name => 'Fake Jr.', :profile_image_url => 'http://disney.com/mickey.png',
69
- :followers_count => '13', :friends_count => '6', :statuses_count => '52'
70
- }
67
+ http_response = mock('HTTP response', :body => Yajl::Encoder.encode(payload))
68
+ access_token.should_receive(:get).with('/1/account/verify_credentials.json').and_return(http_response)
71
69
 
72
- session_data = {:request_token => ['abc', '123']}
70
+ session_data = {:twitter_request_token => ['abc', '123']}
73
71
  get('/login?oauth_verifier=allrighty', build_session(session_data).update(:lint => true))
74
72
  response.status.should == 302
75
73
  response['Location'].should == 'http://example.org/'
76
- session[:request_token].should be_nil
77
- session[:access_token].should == ['access1', '42']
78
- session[:oauth_consumer].should be_nil
74
+ session[:twitter_request_token].should be_nil
75
+ session[:twitter_access_token].should == ['access1', '42']
79
76
 
80
77
  current_user = session[:twitter_user]
81
78
  current_user['screen_name'].should == 'faker'
@@ -86,7 +83,7 @@ describe Twitter::Login do
86
83
  get('/login?denied=OMG', build_session(session_data).update(:lint => true))
87
84
  response.status.should == 302
88
85
  response['Location'].should == 'http://example.org/'
89
- session[:request_token].should be_nil
86
+ session[:twitter_request_token].should be_nil
90
87
  end
91
88
 
92
89
  protected
@@ -124,7 +121,7 @@ describe Twitter::Login do
124
121
 
125
122
  def mock_oauth(*args)
126
123
  consumer = mock(*args)
127
- Twitter::OAuth.should_receive(:new).and_return(consumer)
124
+ OAuth::Consumer.should_receive(:new).and_return(consumer)
128
125
  consumer
129
126
  end
130
127
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-login
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mislav Marohni\xC4\x87"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-06 00:00:00 +02:00
18
+ date: 2011-02-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  requirements: []
141
141
 
142
142
  rubyforge_project:
143
- rubygems_version: 1.3.7
143
+ rubygems_version: 1.5.0
144
144
  signing_key:
145
145
  specification_version: 3
146
146
  summary: Rack middleware to provide login functionality through Twitter