twitter-auth 0.1.8 → 0.1.9
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.
- data/README.markdown +4 -0
- data/VERSION.yml +1 -1
- data/app/controllers/sessions_controller.rb +2 -0
- data/app/models/twitter_auth/generic_user.rb +23 -2
- data/generators/twitter_auth/templates/twitter_auth.yml +12 -6
- data/lib/twitter_auth.rb +4 -0
- data/lib/twitter_auth/controller_extensions.rb +2 -1
- data/spec/controllers/controller_extensions_spec.rb +25 -9
- data/spec/controllers/sessions_controller_spec.rb +15 -0
- data/spec/debug.log +66281 -0
- data/spec/models/twitter_auth/generic_user_spec.rb +86 -1
- data/spec/schema.rb +4 -0
- data/spec/twitter_auth_spec.rb +13 -1
- metadata +1 -1
@@ -5,12 +5,17 @@ describe TwitterAuth::GenericUser do
|
|
5
5
|
should_validate_format_of :login, 'some_guy', 'awesome', 'cool_man'
|
6
6
|
should_not_validate_format_of :login, 'with-dashes', 'with.periods', 'with spaces'
|
7
7
|
should_validate_length_of :login, :in => 1..15
|
8
|
-
|
8
|
+
|
9
9
|
it 'should validate uniqueness of login' do
|
10
10
|
Factory.create(:twitter_oauth_user)
|
11
11
|
Factory.build(:twitter_oauth_user).should have_at_least(1).errors_on(:login)
|
12
12
|
end
|
13
13
|
|
14
|
+
it 'should validate uniqueness of remember_token' do
|
15
|
+
Factory.create(:twitter_oauth_user, :remember_token => 'abc')
|
16
|
+
Factory.build(:twitter_oauth_user, :remember_token => 'abc').should have_at_least(1).errors_on(:remember_token)
|
17
|
+
end
|
18
|
+
|
14
19
|
it 'should allow capital letters in the username' do
|
15
20
|
Factory.build(:twitter_oauth_user, :login => 'TwitterMan').should have(:no).errors_on(:login)
|
16
21
|
end
|
@@ -54,4 +59,84 @@ describe TwitterAuth::GenericUser do
|
|
54
59
|
lambda{user.update_twitter_attributes({'name' => 'Twitter Man', 'description' => 'Works.', 'whoopsy' => 'noworks.'})}.should_not raise_error
|
55
60
|
end
|
56
61
|
end
|
62
|
+
|
63
|
+
describe '#remember_me' do
|
64
|
+
before do
|
65
|
+
@user = Factory(:twitter_oauth_user)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'should check for the remember_token column' do
|
69
|
+
@user.should_receive(:respond_to?).with(:remember_token).and_return(false)
|
70
|
+
@user.remember_me
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should return nil if there is no remember_token column' do
|
74
|
+
@user.should_receive(:respond_to?).with(:remember_token).and_return(false)
|
75
|
+
@user.remember_me.should be_false
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ' with proper columns' do
|
79
|
+
it 'should generate a secure random token' do
|
80
|
+
ActiveSupport::SecureRandom.should_receive(:hex).with(10).and_return('abcdef')
|
81
|
+
@user.remember_me
|
82
|
+
@user.remember_token.should == 'abcdef'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should set the expiration to the current time plus the remember_for period' do
|
86
|
+
TwitterAuth.stub!(:remember_for).and_return(10)
|
87
|
+
time = Time.now
|
88
|
+
Time.stub!(:now).and_return(time)
|
89
|
+
|
90
|
+
@user.remember_me
|
91
|
+
|
92
|
+
@user.remember_token_expires_at.should == Time.now + 10.days
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should return a hash with a :value and :expires key' do
|
96
|
+
result = @user.remember_me
|
97
|
+
result.should be_a(Hash)
|
98
|
+
result.key?(:value).should be_true
|
99
|
+
result.key?(:expires).should be_true
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should return a hash with appropriate values' do
|
103
|
+
TwitterAuth.stub!(:remember_for).and_return(10)
|
104
|
+
time = Time.now
|
105
|
+
Time.stub!(:now).and_return(time)
|
106
|
+
ActiveSupport::SecureRandom.stub!(:hex).and_return('abcdef')
|
107
|
+
|
108
|
+
@user.remember_me.should == {:value => 'abcdef', :expires => (Time.now + 10.days)}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#forget_me' do
|
114
|
+
it 'should reset remember_token and remember_token_expires_at' do
|
115
|
+
@user = Factory(:twitter_oauth_user, :remember_token => "abcdef", :remember_token_expires_at => Time.now + 10.days)
|
116
|
+
@user.forget_me
|
117
|
+
@user.reload
|
118
|
+
@user.remember_token.should be_nil
|
119
|
+
@user.remember_token_expires_at.should be_nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '.from_remember_token' do
|
124
|
+
before do
|
125
|
+
@user = Factory(:twitter_oauth_user, :remember_token => 'abcdef', :remember_token_expires_at => (Time.now + 10.days))
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should find the user with the specified remember_token' do
|
129
|
+
User.from_remember_token('abcdef').should == @user
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should not find a user with an expired token' do
|
133
|
+
user2 = Factory(:twitter_oauth_user, :login => 'walker', :remember_token => 'ghijkl', :remember_token_expires_at => (Time.now - 10.days))
|
134
|
+
User.from_remember_token('ghijkl').should be_nil
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should not find a user with a nil token and an expiration' do
|
138
|
+
user = Factory(:twitter_oauth_user, :login => 'stranger', :remember_token => nil, :remember_token_expires_at => (Time.now + 10.days))
|
139
|
+
User.from_remember_token(nil).should be_nil
|
140
|
+
end
|
141
|
+
end
|
57
142
|
end
|
data/spec/schema.rb
CHANGED
@@ -10,6 +10,10 @@ ActiveRecord::Schema.define :version => 0 do
|
|
10
10
|
t.binary :crypted_password
|
11
11
|
t.string :salt
|
12
12
|
|
13
|
+
# Remember token fields
|
14
|
+
t.string :remember_token
|
15
|
+
t.datetime :remember_token_expires_at
|
16
|
+
|
13
17
|
# This information is automatically kept
|
14
18
|
# in-sync at each login of the user. You
|
15
19
|
# may remove any/all of these columns.
|
data/spec/twitter_auth_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe TwitterAuth do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
describe '
|
16
|
+
describe '.api_timeout' do
|
17
17
|
it 'should default to 10' do
|
18
18
|
TwitterAuth.stub!(:config).and_return({})
|
19
19
|
TwitterAuth.api_timeout.should == 10
|
@@ -25,6 +25,18 @@ describe TwitterAuth do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
describe '.remember_for' do
|
29
|
+
it 'should default to 14' do
|
30
|
+
TwitterAuth.stub!(:config).and_return({})
|
31
|
+
TwitterAuth.remember_for.should == 14
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should be settable via config' do
|
35
|
+
TwitterAuth.stub!(:config).and_return({'remember_for' => '7'})
|
36
|
+
TwitterAuth.remember_for.should == 7
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
28
40
|
describe '.net' do
|
29
41
|
before do
|
30
42
|
stub_basic!
|