|
| 1 | +require File.dirname(__FILE__) + '/../spec_helper' |
| 2 | + |
| 3 | +describe User do |
| 4 | + before :each do |
| 5 | + @site = Site.make |
| 6 | + end |
| 7 | + |
| 8 | + def make_admin_with_token token |
| 9 | + user = User.make(:token_expires_at => 1.day.from_now, :admin => true) |
| 10 | + user.token = token # May be nil, so we can't pass to User.make. |
| 11 | + user.save! |
| 12 | + end |
| 13 | + |
| 14 | + it "should not find users with nil token" do |
| 15 | + # This test always passed, before we did anything specific to fix it. |
| 16 | + make_admin_with_token nil |
| 17 | + User.find_by_token(@site, nil).should be_nil |
| 18 | + end |
| 19 | + |
| 20 | + it "should not find users with empty token" do |
| 21 | + make_admin_with_token '' |
| 22 | + User.find_by_token(@site, '').should be_nil |
| 23 | + end |
| 24 | + |
| 25 | + def make_admin_with_login_and_password login, password |
| 26 | + User.make(:login => login, :password => password, :admin => true) |
| 27 | + end |
| 28 | + |
| 29 | + it "should not find users with empty login" do |
| 30 | + begin |
| 31 | + make_admin_with_login_and_password '', 'foo' |
| 32 | + User.authenticate_for(@site, '', 'foo').should be_nil |
| 33 | + rescue ActiveRecord::RecordInvalid # This is OK, too. |
| 34 | + end |
| 35 | + end |
| 36 | + |
| 37 | + it "should not find users with empty password" do |
| 38 | + begin |
| 39 | + make_admin_with_login_and_password 'joe', '' |
| 40 | + User.authenticate_for(@site, 'joe', '').should be_nil |
| 41 | + rescue ActiveRecord::RecordInvalid # This is OK, too. |
| 42 | + end |
| 43 | + end |
| 44 | +end |
| 45 | + |
0 commit comments