diff options
author | Francis Irving <francis@mysociety.org> | 2010-03-10 03:15:25 +0000 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-03-10 03:15:25 +0000 |
commit | 2734ede2a66553bf29294d64f9c1ed9782324686 (patch) | |
tree | 8097fc7c7bec5552d9de9dbb04e3a270a4a0fccc /spec/controllers/user_controller_spec.rb | |
parent | 5e752e09c4d5afe4150bf20cc5ef332b1d8cda1a (diff) |
Form for changing your email address
Diffstat (limited to 'spec/controllers/user_controller_spec.rb')
-rw-r--r-- | spec/controllers/user_controller_spec.rb | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb index 29658f085..81333843a 100644 --- a/spec/controllers/user_controller_spec.rb +++ b/spec/controllers/user_controller_spec.rb @@ -290,6 +290,76 @@ describe UserController, "when changing password" do end +describe UserController, "when changing email address" do + integrate_views + fixtures :users + + it "should require login" do + get :signchangeemail + + post_redirect = PostRedirect.get_last_post_redirect + response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token) + end + + it "should show form for changing email if logged in" do + session[:user_id] = users(:silly_name_user).id + get :signchangeemail + + response.should render_template('signchangeemail') + end + + it "should be an error if the password is wrong, everything else right" do + @user = users(:silly_name_user) + session[:user_id] = @user.id + + post :signchangeemail, { :signchangeemail => { :old_email => 'silly@localhost', + :password => 'donotknowpassword', :new_email => 'newsilly@localhost' }, + :submitted_signchangeemail_do => 1 + } + + @user.reload + @user.email.should == 'silly@localhost' + response.should render_template('signchangeemail') + assigns[:signchangeemail].errors[:password].should_not be_nil + end + + it "should be an error if old email is wrong, everything else right" do + @user = users(:silly_name_user) + session[:user_id] = @user.id + + post :signchangeemail, { :signchangeemail => { :old_email => 'silly@moo', + :password => 'jonespassword', :new_email => 'newsilly@localhost' }, + :submitted_signchangeemail_do => 1 + } + + @user.reload + @user.email.should == 'silly@localhost' + response.should render_template('signchangeemail') + assigns[:signchangeemail].errors[:old_email].should_not be_nil + end + + it "should change your email if you get all the details right, and require confirmation" do + @user = users(:silly_name_user) + session[:user_id] = @user.id + + post :signchangeemail, { :signchangeemail => { :old_email => 'silly@localhost', + :password => 'jonespassword', :new_email => 'newsilly@localhost' }, + :submitted_signchangeemail_do => 1 + } + + @user.reload + @user.email.should == 'newsilly@localhost' + @user.email_confirmed.should == false + + response.flash[:notice].should include('Your email has been changed') + response.should render_template('confirm') + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + deliveries[0].body.should include("not reveal your email") + end + + +end |