Permalink
Browse files

handling signin failure

  • Loading branch information...
1 parent d3e5185 commit 9a7fbe9fb36025baf9377c04be779adbf1eaa1f8 @jefflam committed Oct 7, 2011
@@ -5,7 +5,16 @@ 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
View
@@ -5,12 +5,13 @@
root :to => 'pages#home'
match '/contact' => 'pages#contact'
- match '/about' => 'pages#about'
- match '/help' => 'pages#help'
+ match '/about' => 'pages#about'
+ match '/help' => 'pages#help'
match '/contact' => 'pages#contact'
- match '/signup' => 'users#new'
- match '/signin' => 'sessions#new'
+ match '/signup' => 'users#new'
+ match '/signin' => 'sessions#new'
match '/signout' => 'sessions#destroy'
+
# get "pages/home"
@@ -49,13 +49,13 @@
end
end
- describe "GET 'signin'" do
- it "should be successful" do
- get 'signin'
- response.should be_success
- response.should have_selector("title", :content => "#{@base_title} | Sign In")
- end
- end
+ # describe "GET 'signin'" do
+ # it "should be successful" do
+ # get 'signin'
+ # response.should be_success
+ # response.should have_selector("title", :content => "#{@base_title} | Sign In")
+ # end
+ # end
@@ -15,5 +15,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 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 9a7fbe9

Please sign in to comment.