require File.dirname(__FILE__) + '/../spec_helper' describe UnstaticSession do it "should include Errorable module" do UnstaticSession.ancestors.include?(Errorable).should == true end it "should provide an attribute accessor for password" do unstatic_session = UnstaticSession.new unstatic_session.password = "password" unstatic_session.password.should =="password" end end describe UnstaticSession, "#new" do it "should accept an attribute hash" do lambda { UnstaticSession.new({ :name => "value" }) }.should_not raise_error end it "should assign password from attribute hash" do unstatic_session = UnstaticSession.new({ :password => "password" }) unstatic_session.password.should == "password" end end describe UnstaticSession, "#authorized?" do before(:each) do @unstatic_session = UnstaticSession.new(:password => "password") end it "should return true if password is valid" do UnstaticPassword.should_receive(:authorized?).with("password").and_return(true) @unstatic_session.authorized?.should == true end it "should return false if password is not valid" do UnstaticPassword.should_receive(:authorized?).with("password").and_return(false) @unstatic_session.authorized?.should == false end it "should set error on password attribute if password is not valid" do UnstaticPassword.should_receive(:authorized?).with("password").and_return(false) @unstatic_session.authorized? @unstatic_session.errors.on(:password).should_not be_nil end end