UsersController: Fix test for sending mail on user activation

pull/240/head
Michael Frister 11 years ago committed by Michael Frister
parent 0f1be97449
commit 71d98a1413
  1. 35
      spec/controllers/users_controller_spec.rb
  2. 19
      test/functional/users_controller_test.rb

@ -189,6 +189,41 @@ describe UsersController do
end
end
describe :change_status do
describe 'WHEN activating a registered user' do
let!(:registered_user) do
FactoryGirl.create(:user, :status => User::STATUSES[:registered],
:language => 'fr')
end
before do
ActionMailer::Base.deliveries.clear
with_settings(:available_languages => [:en, :fr],
:bcc_recipients => '1') do
as_logged_in_user admin do
post :change_status, :id => registered_user.id,
:user => {:status => User::STATUSES[:active]},
:activate => '1'
end
end
end
it 'should activate the user' do
assert registered_user.reload.active?
end
it 'should send an email to the correct user in the correct language' do
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal [registered_user.mail], mail.to
mail.parts.each do |part|
assert part.body.encoded.include?(I18n.t(:notice_account_activated,
:locale => 'fr'))
end
end
end
end
describe "index" do
describe "with session lifetime" do
# TODO move this section to a proper place because we test a

@ -227,25 +227,6 @@ class UsersControllerTest < ActionController::TestCase
assert_equal [10], user.group_ids
end
def test_update_with_activation_should_send_a_notification
Setting.available_languages = [:en, :fr]
u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
u.login = 'foo'
u.status = User::STATUSES[:registered]
u.save!
ActionMailer::Base.deliveries.clear
Setting.bcc_recipients = '1'
put :update, :id => u.id, :user => {:status => User::STATUSES[:active]}
assert u.reload.active?
mail = ActionMailer::Base.deliveries.last
assert_not_nil mail
assert_equal ['foo.bar@somenet.foo'], mail.to
mail.parts.each do |part|
assert part.body.encoded.include?(ll('fr', :notice_account_activated))
end
end
def test_update_with_password_change_should_send_a_notification
ActionMailer::Base.deliveries.clear
Setting.bcc_recipients = '1'

Loading…
Cancel
Save