Fix in find_for_authentication
This commit is contained in:
parent
9da69a4b01
commit
61e40debb5
2 changed files with 9 additions and 2 deletions
|
|
@ -76,6 +76,7 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_for_authentication(conditions={})
|
def self.find_for_authentication(conditions={})
|
||||||
|
conditions[:username] = conditions[:username].downcase
|
||||||
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
||||||
conditions[:email] = conditions.delete(:username)
|
conditions[:email] = conditions.delete(:username)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -242,9 +242,15 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".find_for_authentication" do
|
describe ".find_for_authentication" do
|
||||||
it "preserves case" do
|
before do
|
||||||
|
user
|
||||||
|
user2
|
||||||
|
end
|
||||||
|
it 'finds a user' do
|
||||||
User.find_for_authentication(:username => user.username).should == user
|
User.find_for_authentication(:username => user.username).should == user
|
||||||
User.find_for_authentication(:username => user.username.upcase).should be_nil
|
end
|
||||||
|
it "does not preserve case" do
|
||||||
|
User.find_for_authentication(:username => user.username.upcase).should == user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue