Skip to content

Commit

Permalink
Handling invalid signin
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartl committed Aug 26, 2010
1 parent deadb71 commit b04e0e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ def new
end

def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
@title = "Sign in"
render 'new'
else
# Handle successful signin.
end
end

def destroy
Expand Down
25 changes: 25 additions & 0 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,29 @@
response.should have_selector('title', :content => "Sign in")
end
end

describe "POST 'create'" do

describe "failure" do

before(:each) do
@attr = { :email => "", :password => "" }
end

it "should re-render the new page" do
post :create, :session => @attr
response.should render_template('new')
end

it "should have the right title" do
post :create, :session => @attr
response.should have_selector('title', :content => "Sign in")
end

it "should have an error message" do
post :create, :session => @attr
flash.now[:error].should =~ /invalid/i
end
end
end
end

0 comments on commit b04e0e7

Please sign in to comment.