1
require File.dirname(__FILE__) + '/../spec_helper'
3
# Be sure to include AuthenticatedTestHelper in spec/spec_helper.rb instead
4
# Then, you can remove it from this and the units test.
5
include AuthenticatedTestHelper
6
include AuthenticatedSystem
9
describe SessionsController do
13
# FIXME -- sessions controller not testing xml logins
14
stub!(:authenticate_with_http_basic).and_return nil
16
describe "logout_killing_session!" do
21
it 'resets the session' do should_receive(:reset_session); logout_killing_session! end
22
it 'kills my auth_token cookie' do should_receive(:kill_remember_cookie!); logout_killing_session! end
23
it 'nils the current associate' do logout_killing_session!; current_associate.should be_nil end
24
it 'kills :associate_id session' do
26
session.should_receive(:[]=).with(:associate_id, nil).at_least(:once)
27
logout_killing_session!
30
current_associate.remember_me
31
current_associate.remember_token.should_not be_nil; current_associate.remember_token_expires_at.should_not be_nil
32
Associate.find(1).remember_token.should_not be_nil; Associate.find(1).remember_token_expires_at.should_not be_nil
33
logout_killing_session!
34
Associate.find(1).remember_token.should be_nil; Associate.find(1).remember_token_expires_at.should be_nil
38
describe "logout_keeping_session!" do
43
it 'does not reset the session' do should_not_receive(:reset_session); logout_keeping_session! end
44
it 'kills my auth_token cookie' do should_receive(:kill_remember_cookie!); logout_keeping_session! end
45
it 'nils the current associate' do logout_keeping_session!; current_associate.should be_nil end
46
it 'kills :associate_id session' do
48
session.should_receive(:[]=).with(:associate_id, nil).at_least(:once)
49
logout_keeping_session!
52
current_associate.remember_me
53
current_associate.remember_token.should_not be_nil; current_associate.remember_token_expires_at.should_not be_nil
54
Associate.find(1).remember_token.should_not be_nil; Associate.find(1).remember_token_expires_at.should_not be_nil
55
logout_keeping_session!
56
Associate.find(1).remember_token.should be_nil; Associate.find(1).remember_token_expires_at.should be_nil
60
describe 'When logged out' do
61
it "should not be authorized?" do
62
authorized?().should be_false
69
describe "Logging in by cookie" do
70
def set_remember_token token, time
71
@associate[:remember_token] = token;
72
@associate[:remember_token_expires_at] = time
76
@associate = Associate.find(:first);
77
set_remember_token 'hello!', 5.minutes.from_now
79
it 'logs in with cookie' do
80
stub!(:cookies).and_return({ :auth_token => 'hello!' })
81
logged_in?.should be_true
84
it 'fails cookie login with bad cookie' do
85
should_receive(:cookies).at_least(:once).and_return({ :auth_token => 'i_haxxor_joo' })
86
logged_in?.should_not be_true
89
it 'fails cookie login with no cookie' do
90
set_remember_token nil, nil
91
should_receive(:cookies).at_least(:once).and_return({ })
92
logged_in?.should_not be_true
95
it 'fails expired cookie login' do
96
set_remember_token 'hello!', 5.minutes.ago
97
stub!(:cookies).and_return({ :auth_token => 'hello!' })
98
logged_in?.should_not be_true