Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored OauthUser and BasicUser into modules (how they should have…
… been from the beginning) and started spec'ing out BasicUser.
- Loading branch information
Michael Bleigh
committed
Mar 19, 2009
1 parent
46d4329
commit 52bb18e
Showing
11 changed files
with
104 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
module TwitterAuth | ||
class BasicUser < TwitterAuth::GenericUser | ||
attr_protected :cryped_password, :salt | ||
module BasicUser | ||
def self.included(base) | ||
base.class_eval do | ||
attr_protected :crypted_password, :salt | ||
end | ||
end | ||
|
||
def password=(new_password) | ||
encrypted = TwitterAuth::Cryptify.encrypt(new_password) | ||
self.crypted_password = encrypted[:encrypted_data] | ||
self.salt = encrypted[:salt] | ||
end | ||
|
||
def password | ||
TwitterAuth::Cryptify.decrypt(self.crypted_password, self.salt) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
|
||
describe TwitterAuth::BasicUser do | ||
before do | ||
stub_basic! | ||
end | ||
|
||
describe '#password=' do | ||
before do | ||
@user = Factory.build(:twitter_basic_user) | ||
end | ||
|
||
it 'should change the value of crypted_password' do | ||
lambda{@user.password = 'newpass'}.should change(@user, :crypted_password) | ||
end | ||
|
||
it 'should change the value of salt' do | ||
lambda{@user.password = 'newpass'}.should change(@user, :salt) | ||
end | ||
|
||
it 'should not store the plaintext password' do | ||
@user.password = 'newpass' | ||
@user.crypted_password.should_not == 'newpass' | ||
end | ||
end | ||
|
||
describe '#password' do | ||
before do | ||
@user = Factory.build(:twitter_basic_user, :password => 'monkey') | ||
end | ||
|
||
it 'should return the password' do | ||
@user.password.should == 'monkey' | ||
end | ||
|
||
it 'should not be a database attribute' do | ||
@user['password'].should_not == 'monkey' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters