Commit 2020d549dc9bad1221925e76f8fb20df3953da0d
1 parent
6cee467c
Exists in
staging
and in
6 other branches
Fix resend activation code for users
Showing
4 changed files
with
18 additions
and
2 deletions
Show diff stats
app/models/user.rb
@@ -425,7 +425,7 @@ class User < ActiveRecord::Base | @@ -425,7 +425,7 @@ class User < ActiveRecord::Base | ||
425 | 425 | ||
426 | def resend_activation_code | 426 | def resend_activation_code |
427 | return if self.activated? | 427 | return if self.activated? |
428 | - self.make_activation_code | 428 | + update_attribute(:activation_code, make_activation_code) |
429 | self.deliver_activation_code | 429 | self.deliver_activation_code |
430 | end | 430 | end |
431 | 431 |
lib/noosfero/api/session.rb
@@ -144,6 +144,7 @@ module Noosfero | @@ -144,6 +144,7 @@ module Noosfero | ||
144 | requestors.each do |requestor| | 144 | requestors.each do |requestor| |
145 | requestor.user.resend_activation_code | 145 | requestor.user.resend_activation_code |
146 | end | 146 | end |
147 | + present requestors.map(&:user), :with => Entities::UserLogin | ||
147 | end | 148 | end |
148 | 149 | ||
149 | params do | 150 | params do |
test/unit/api/session_test.rb
@@ -218,7 +218,22 @@ class SessionTest < ActiveSupport::TestCase | @@ -218,7 +218,22 @@ class SessionTest < ActiveSupport::TestCase | ||
218 | post "/api/v1/resend_activation_code?#{params.to_query}" | 218 | post "/api/v1/resend_activation_code?#{params.to_query}" |
219 | process_delayed_job_queue | 219 | process_delayed_job_queue |
220 | end | 220 | end |
221 | + json = JSON.parse(last_response.body) | ||
222 | + assert !json['users'].first['activated'] | ||
221 | assert_equal user.email, ActionMailer::Base.deliveries.last['to'].to_s | 223 | assert_equal user.email, ActionMailer::Base.deliveries.last['to'].to_s |
222 | end | 224 | end |
223 | 225 | ||
226 | + should 'not resend activation code for an active user' do | ||
227 | + user = create_user | ||
228 | + params = {:value => user.login} | ||
229 | + user.activate | ||
230 | + Delayed::Job.destroy_all | ||
231 | + assert_no_difference 'ActionMailer::Base.deliveries.size' do | ||
232 | + post "/api/v1/resend_activation_code?#{params.to_query}" | ||
233 | + process_delayed_job_queue | ||
234 | + end | ||
235 | + json = JSON.parse(last_response.body) | ||
236 | + assert json['users'].first['activated'] | ||
237 | + end | ||
238 | + | ||
224 | end | 239 | end |
test/unit/user_test.rb
@@ -764,7 +764,7 @@ class UserTest < ActiveSupport::TestCase | @@ -764,7 +764,7 @@ class UserTest < ActiveSupport::TestCase | ||
764 | user.resend_activation_code | 764 | user.resend_activation_code |
765 | process_delayed_job_queue | 765 | process_delayed_job_queue |
766 | end | 766 | end |
767 | - assert_not_equal activation_code, user.activation_code | 767 | + assert_not_equal activation_code, user.reload.activation_code |
768 | assert_equal 'pending@activation.com', ActionMailer::Base.deliveries.last['to'].to_s | 768 | assert_equal 'pending@activation.com', ActionMailer::Base.deliveries.last['to'].to_s |
769 | end | 769 | end |
770 | 770 |