Commit b29e7d7853f1835dbce26bb60747e5343bc5d609
1 parent
37e45606
Exists in
theme-brasil-digital-from-staging
and in
7 other branches
Add method to resend activation code
Showing
2 changed files
with
28 additions
and
0 deletions
Show diff stats
app/models/user.rb
| @@ -423,6 +423,12 @@ class User < ActiveRecord::Base | @@ -423,6 +423,12 @@ class User < ActiveRecord::Base | ||
| 423 | @is_password_required = false | 423 | @is_password_required = false |
| 424 | end | 424 | end |
| 425 | 425 | ||
| 426 | + def resend_activation_code | ||
| 427 | + return if self.activated? | ||
| 428 | + self.make_activation_code | ||
| 429 | + self.deliver_activation_code | ||
| 430 | + end | ||
| 431 | + | ||
| 426 | protected | 432 | protected |
| 427 | 433 | ||
| 428 | def normalize_email | 434 | def normalize_email |
test/unit/user_test.rb
| @@ -756,6 +756,28 @@ class UserTest < ActiveSupport::TestCase | @@ -756,6 +756,28 @@ class UserTest < ActiveSupport::TestCase | ||
| 756 | assert_equal 'quire', user.person.name | 756 | assert_equal 'quire', user.person.name |
| 757 | end | 757 | end |
| 758 | 758 | ||
| 759 | + should 'deliver e-mail with activation code when resend was requested and user was not activated' do | ||
| 760 | + user = new_user :email => 'pending@activation.com' | ||
| 761 | + activation_code = user.activation_code | ||
| 762 | + Delayed::Job.destroy_all | ||
| 763 | + assert_difference 'ActionMailer::Base.deliveries.size', 1 do | ||
| 764 | + user.resend_activation_code | ||
| 765 | + process_delayed_job_queue | ||
| 766 | + end | ||
| 767 | + assert_not_equal activation_code, user.activation_code | ||
| 768 | + assert_equal 'pending@activation.com', ActionMailer::Base.deliveries.last['to'].to_s | ||
| 769 | + end | ||
| 770 | + | ||
| 771 | + should 'not deliver e-mail with activation code when resend was requested and user was activated' do | ||
| 772 | + user = new_user :email => 'pending@activation.com' | ||
| 773 | + user.activate | ||
| 774 | + Delayed::Job.destroy_all | ||
| 775 | + assert_no_difference 'ActionMailer::Base.deliveries.size' do | ||
| 776 | + user.resend_activation_code | ||
| 777 | + process_delayed_job_queue | ||
| 778 | + end | ||
| 779 | + end | ||
| 780 | + | ||
| 759 | protected | 781 | protected |
| 760 | def new_user(options = {}) | 782 | def new_user(options = {}) |
| 761 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) | 783 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) |