Browse files

Users controller covered with tests

  • Loading branch information...
1 parent fed7071 commit 8d5d2e68392fbdc3e2cd3b6da5d5c535bb8585a7 @vessi committed Apr 21, 2012
Showing with 25 additions and 0 deletions.
  1. +25 −0 spec/controllers/users_controller_spec.rb
View
25 spec/controllers/users_controller_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe UsersController do
+ let(:user) { mock_model User }
+ it 'should create new user' do
+ User.should_receive(:new).and_return user
+ get :new
+ assigns(:user).should == user
+ end
+
+ it 'should render view new if user creation failed' do
+ User.should_receive(:new).and_return user
+ user.should_receive(:save).and_return false
+ post :create
+ response.should render_template :new
+ end
+
+ it 'should set session user_id and redirect to root_url if user creation passed' do
+ User.should_receive(:new).and_return user
+ user.should_receive(:save).and_return true
+ post :create
+ session[:user_id].should == user.id
+ response.should redirect_to root_url
+ end
+end

0 comments on commit 8d5d2e6

Please sign in to comment.