Show More
Commit Description:
more work on registration...
Commit Description:
more work on registration
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@296 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
spec/models/user_spec.rb
| 63 lines
| 1.5 KiB
| text/x-ruby
| RubyLexer
|
|
r155 | |||
require File.dirname(__FILE__) + '/../spec_helper' | ||||
describe User do | ||||
before(:each) do | ||||
@password = "hello" | ||||
@salt = "123" | ||||
@john = stub_model(User, :salt => @salt, | ||||
:hashed_password => User.encrypt(@password,@salt)) | ||||
end | ||||
|
r157 | it "should be authenticated if activated" do | ||
|
r155 | @john.should_receive(:activated).and_return(true) | ||
@john.authenticated?(@password).should == true | ||||
end | ||||
|
r157 | it "should not be authenticated if inactivated" do | ||
|
r155 | @john.should_receive(:activated).and_return(false) | ||
@john.authenticated?(@password).should == false | ||||
end | ||||
|
r157 | it "should not be authenticated if incorrect password is provided" do | ||
|
r155 | @john.should_receive(:activated).and_return(true) | ||
@john.should_receive(:hashed_password).and_return("byebye") | ||||
@john.authenticated?(@password).should == false | ||||
end | ||||
|
r157 | |||
|
r155 | end | ||
describe User, "during registration" do | ||||
|
r157 | |||
|
r155 | class User | ||
public :encrypt_new_password | ||||
end | ||||
before(:each) do | ||||
@john = User.new(:login => 'john', :password => 'hello') | ||||
@john.encrypt_new_password | ||||
end | ||||
|
r157 | |||
|
r155 | it "should produce and accept activation key" do | ||
activation_key = @john.activation_key | ||||
@john.verify_activation_key(activation_key).should == true | ||||
end | ||||
|
r157 | |||
|
r155 | it "should not accept invalid activation key" do | ||
@john.verify_activation_key("12345").should == false | ||||
end | ||||
|
r157 | |||
end | ||||
|
r155 | |||
|
r157 | describe User, "as a class" do | ||
|
r155 | |||
|
r157 | it "should be able to generate random password" do | ||
password1 = User.random_password | ||||
password2 = User.random_password | ||||
password1.should_not == password2 | ||||
end | ||||
|
r155 | end | ||