Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'spec_helper'
- describe User do
- describe "creating a user" do
- it "changes the number of users by one" do
- lambda {Factory(:user)}.should change{User.count}.by(1)
- end
- end
- describe "creating a member" do
- it "changes the number of active user from 0 to 1" do
- lambda {Factory(:member)}.should change{User.count}.from(0).to(1)
- end
- end
- describe "authentication" do
- before do
- @login = 'dickdivers'
- @email = 'dick@divers.com'
- @password = 'nightingale'
- end
- context "of not active user" do
- before(:each) do
- @user = Factory(:user, :login => @login, :email => @email,
- :password => @password, :password_confirmation => @password)
- end
- it "return nil for correct login attempts using login column" do
- Tog::Config["plugins.tog_user.email_as_login"] = false
- User.authenticate(@login, @password).should be_nil
- end
- it "return nil for correct login attempts using email column" do
- Tog::Config["plugins.tog_user.email_as_login"] = true
- User.authenticate(@email, @password).should be_nil
- end
- end
- context "of a member" do
- before(:each) do
- @user = Factory(:member, :login => @login, :email => @email,
- :password => @password, :password_confirmation => @password)
- end
- it "return nil for incorrect login attempts" do
- Tog::Config["plugins.tog_user.email_as_login"] = false
- User.authenticate(@login, "bad_password").should be_nil
- User.authenticate("bad_login_email", "badpass").should be_nil
- User.authenticate("", "").should be_nil
- User.authenticate(nil, nil).should be_nil
- Tog::Config["plugins.tog_user.email_as_login"] = true
- User.authenticate(@email, "bad_password").should be_nil
- User.authenticate("bad_login_email", "badpass").should be_nil
- User.authenticate("", "").should be_nil
- User.authenticate(nil, nil).should be_nil
- end
- context "using email" do
- before(:each) do
- Tog::Config["plugins.tog_user.email_as_login"] = true
- end
- it "return the user object for a valid login using his email" do
- User.authenticate(@email, @password).should == @user
- User.authenticate(@email.upcase, @password).should == @user
- end
- end
- context "using login" do
- before(:each) do
- Tog::Config["plugins.tog_user.email_as_login"] = false
- end
- it "return the user object for a valid login using his login" do
- User.authenticate(@login, @password).should == @user
- User.authenticate(@login.upcase, @password).should == @user
- end
- end
- context "using login or email without check out email_as_login property" do
- before(:each) do
- Tog::Config.should_receive(:[]).never
- end
- it "return the user object for a valid login using his login" do
- User.authenticate(@login, @password).should == @user
- end
- it "return the user object for a valid login using his email" do
- User.authenticate(@email, @password).should == @user
- end
- end
- end
- end
- describe "register" do
- before(:each) do
- @user = Factory.build(:user)
- end
- it "should be in state pending" do
- @user.register!
- @user.state.should == "pending"
- end
- it "generate an activation code" do
- @user.register!
- @user.activation_code.should_not be_nil
- end
- it "receive an signup notification" do
- UserMailer.stub!(:deliver_signup_notification)
- UserMailer.should_receive(:deliver_signup_notification).with(@user)
- @user.register!
- end
- end
- describe "a registered user activates his account" do
- before(:each) do
- @user = Factory(:registered)
- end
- it "should be in state active" do
- @user.activate!
- @user.state.should == "active"
- end
- it "receive a welcome message (activation)" do
- UserMailer.stub!(:deliver_activation)
- UserMailer.should_receive(:deliver_activation).with(@user)
- @user.activate!
- end
- end
- describe "a member has forgotten his password" do
- before(:each) do
- @user = Factory(:member)
- end
- it "generate a password reset code" do
- @user.forgot_password
- @user.password_reset_code.should_not be_nil
- end
- it "receive an email to reset the password (reset notification)" do
- UserMailer.stub!(:deliver_reset_notification)
- UserMailer.should_receive(:deliver_reset_notification).with(@user)
- @user.forgot_password
- end
- end
- desrcibe "trying activate without register" do
- it "raise an invalid transition exception (AASM::InvalidTransition)" do
- lambda {
- Factory(:user).activate!
- }.should raise_exception(AASM::InvalidTransition)
- end
- end
- describe "validations" do
- context "authentication patches" do
- it "not be valid include @.- in the login"
- # it "not be valid include @.- in the login" do
- # pending "require authentication patches to use login in the profile url"
- # end
- #
- # it "not be valid include @.- in the login" do
- # pending "require authentication patches to use login in the profile url" do
- # %w(Holden@com Holde.com Holde-com).each do |login|
- # user = Factory.build(:user, :login => login)
- # user.should_not be_valid
- # user.errors.on(:login).should_not be_empty
- # end
- # end
- # end
- end
- end
- end
Add Comment
Please, Sign In to add comment