aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/user_controller_spec.rb
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2010-03-10 03:54:40 +0000
committerFrancis Irving <francis@mysociety.org>2010-03-10 03:54:40 +0000
commit5ec31603058d5c4108d08ed5cfa62707aaeced7d (patch)
treec1c06794a338cfe3e30bc50f6c1364f1b0e1ab0a /spec/controllers/user_controller_spec.rb
parent96ff1f26d610393b0e6cfc177d98039820fcf0da (diff)
Use bob instead of silly as test user. Make it behave better if existing
email changed to.
Diffstat (limited to 'spec/controllers/user_controller_spec.rb')
-rw-r--r--spec/controllers/user_controller_spec.rb62
1 files changed, 47 insertions, 15 deletions
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index c552c8d41..d85706b2d 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -302,63 +302,95 @@ describe UserController, "when changing email address" do
end
it "should show form for changing email if logged in" do
- session[:user_id] = users(:silly_name_user).id
+ @user = users(:bob_smith_user)
+ session[:user_id] = @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)
+ @user = users(:bob_smith_user)
session[:user_id] = @user.id
- post :signchangeemail, { :signchangeemail => { :old_email => 'silly@localhost',
- :password => 'donotknowpassword', :new_email => 'newsilly@localhost' },
+ post :signchangeemail, { :signchangeemail => { :old_email => 'bob@localhost',
+ :password => 'donotknowpassword', :new_email => 'newbob@localhost' },
:submitted_signchangeemail_do => 1
}
@user.reload
- @user.email.should == 'silly@localhost'
+ @user.email.should == 'bob@localhost'
response.should render_template('signchangeemail')
assigns[:signchangeemail].errors[:password].should_not be_nil
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
end
it "should be an error if old email is wrong, everything else right" do
- @user = users(:silly_name_user)
+ @user = users(:bob_smith_user)
session[:user_id] = @user.id
- post :signchangeemail, { :signchangeemail => { :old_email => 'silly@moo',
- :password => 'jonespassword', :new_email => 'newsilly@localhost' },
+ post :signchangeemail, { :signchangeemail => { :old_email => 'bob@moo',
+ :password => 'jonespassword', :new_email => 'newbob@localhost' },
:submitted_signchangeemail_do => 1
}
@user.reload
- @user.email.should == 'silly@localhost'
+ @user.email.should == 'bob@localhost'
response.should render_template('signchangeemail')
assigns[:signchangeemail].errors[:old_email].should_not be_nil
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 0
end
it "should change your email if you get all the details right, and send confirmation email" do
- @user = users(:silly_name_user)
+ @user = users(:bob_smith_user)
session[:user_id] = @user.id
- post :signchangeemail, { :signchangeemail => { :old_email => 'silly@localhost',
- :password => 'jonespassword', :new_email => 'newsilly@localhost' },
+ post :signchangeemail, { :signchangeemail => { :old_email => 'bob@localhost',
+ :password => 'jonespassword', :new_email => 'newbob@localhost' },
:submitted_signchangeemail_do => 1
}
@user.reload
- @user.email.should == 'newsilly@localhost'
+ @user.email.should == 'newbob@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")
+ mail = deliveries[0]
+
+ mail.body.should include("not reveal your email")
+ mail.to.should == [ 'newbob@localhost' ]
end
+ it "should send special 'already signed up' mail if you try to change your email to one already used" do
+ @user = users(:bob_smith_user)
+ session[:user_id] = @user.id
+
+ post :signchangeemail, { :signchangeemail => { :old_email => 'bob@localhost',
+ :password => 'jonespassword', :new_email => 'bob@localhost' },
+ :submitted_signchangeemail_do => 1
+ }
+
+ @user.reload
+ @user.email.should == 'bob@localhost'
+ @user.email_confirmed.should == true
+
+ response.should render_template('confirm')
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+
+ mail.body.should include("have an account")
+ mail.to.should == [ 'bob@localhost' ]
+ end
end