From ccbb11e060b6c1972054f29377ac435375a3ddf5 Mon Sep 17 00:00:00 2001 From: francis Date: Fri, 9 Nov 2007 01:48:36 +0000 Subject: Get user controller to 100% test coverage. --- spec/controllers/user_controller_spec.rb | 35 ++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'spec/controllers/user_controller_spec.rb') diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index fa8cea3b5..cf73e5d13 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -79,6 +79,7 @@ describe UserController, "when signing in" do } session[:user].should == users(:bob_smith_user).id response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) + response.should_not send_email end it "should ask you to confirm your email if it isn't confirmed, after log in" do @@ -89,10 +90,28 @@ describe UserController, "when signing in" do :token => post_redirect.token } response.should render_template('confirm') - # XXX check email sent + response.should send_email end - it "should confirm your email, log you in and redirect you to where you were after you click an email link" + it "should confirm your email, log you in and redirect you to where you were after you click an email link" do + get :signin, :r => "/list" + post_redirect = get_last_postredirect + + post :signin, { :user => { :email => 'silly@localhost', :password => 'jonespassword' }, + :token => post_redirect.token + } + response.should send_email + + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body =~ /(http:\/\/.*\/c\/(.*))/ + mail_url = $1 + mail_token = $2 + + get :confirm, :email_token => post_redirect.email_token + response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) + end end @@ -114,13 +133,13 @@ describe UserController, "when signing up" do assigns[:user].errors[:email].should_not be_nil end -# it "should ask you to confirm your email if you fill in the form right" do -# post :signup, { :user => { :email => 'new@localhost', :name => 'New Person', -# :password => 'sillypassword', :password_confirmation => 'sillypassword' } -# } -# response.should render_template('confirm') + it "should ask you to confirm your email if you fill in the form right" do + post :signup, { :user => { :email => 'new@localhost', :name => 'New Person', + :password => 'sillypassword', :password_confirmation => 'sillypassword' } + } + response.should render_template('confirm') # XXX if you go straight into signup form without token it doesn't make one -# end + end end describe UserController, "when signing out" do -- cgit v1.2.3