Created
January 27, 2011 19:16
-
-
Save pentikos/799026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe SessionController do | |
it "should show the login page at new action" do | |
get :new | |
response.should be_success | |
end | |
context "authentication failure" do | |
before do | |
User.should_receive(:authenticate).with('[email protected]', 'incorrect').and_return(nil) | |
post :create, :login => { :email => "[email protected]", :password => 'incorrect' } | |
end | |
it "should render the login template" do | |
response.should render_template("session/new") | |
end | |
it "should assign an alert message" do | |
flash[:alert].should == "authentication.failure" | |
end | |
end | |
context "authentication success" do | |
before do | |
@user = user = mock_model(User) | |
User.should_receive(:authenticate).with("[email protected]", "foobar").and_return(@user) | |
post :create, :login => { :email => "[email protected]", :password => "foobar" } | |
end | |
it "should redirect to the homepage after an successfull login" do | |
response.should redirect_to(root_path) | |
flash[:notice].should == "authentication.success" | |
end | |
it "should assign the user id to session[:user_id]" do | |
session[:user_id].should == @user.id | |
end | |
it "should assign a flash message" do | |
flash[:notice].should == "authentication.success" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment