diff --git a/app/models/person.rb b/app/models/person.rb index 2df291f..54297df 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -328,7 +328,7 @@ class Person < Profile end after_update do |person| - person.user.save! + person.user.save! unless person.user.changes.blank? end def is_admin?(environment = nil) diff --git a/app/models/profile.rb b/app/models/profile.rb index 764236b..469ad4c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -692,15 +692,15 @@ private :generate_url, :url_options after_create :insert_default_article_set def insert_default_article_set if template - copy_articles_from template + self.save! if copy_articles_from template else default_set_of_articles.each do |article| article.profile = self article.advertise = false article.save! end + self.save! end - self.save! end # Override this method in subclasses of Profile to create a default article @@ -721,10 +721,12 @@ private :generate_url, :url_options end def copy_articles_from other + return false if other.top_level_articles.empty? other.top_level_articles.each do |a| copy_article_tree a end self.articles.reload + true end def copy_article_tree(article, parent=nil) diff --git a/app/models/user.rb b/app/models/user.rb index 7df23f2..8be2ba9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -445,7 +445,7 @@ class User < ActiveRecord::Base def deliver_activation_code return if person.is_template? - UserMailer.activation_code(self).deliver unless self.activation_code.blank? + Delayed::Job.enqueue(UserMailer::Job.new(self, :activation_code)) unless self.activation_code.blank? end def delay_activation_check diff --git a/features/signup.feature b/features/signup.feature index 1fc81c1..fa575f2 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -16,6 +16,7 @@ Feature: signup | Full name | José da Silva | And wait for the captcha signup time And I press "Create my account" + And there are no pending jobs Then I should receive an e-mail on josesilva@example.com When I go to login page And I fill in "Username" with "josesilva" diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index a8f91e4..d2e06b2 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -27,6 +27,7 @@ class SearchControllerTest < ActionController::TestCase # By pass user validation on person creation user = mock() user.stubs(:id).returns(1) + user.stubs(:changes).returns(nil) user.stubs(:valid?).returns(true) user.stubs(:email).returns('some@test.com') user.stubs(:save!).returns(true) diff --git a/test/integration/signup_test.rb b/test/integration/signup_test.rb index e4ee1e5..3b45e69 100644 --- a/test/integration/signup_test.rb +++ b/test/integration/signup_test.rb @@ -45,7 +45,7 @@ class SignupTest < ActionDispatch::IntegrationTest assert_redirected_to controller: 'home', action: 'welcome' assert_equal count + 1, User.count - assert_equal mail_count + 1, ActionMailer::Base.deliveries.count + assert_includes Delayed::Job.all.map{|d|d.name}, 'UserMailer::Job' end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index f8ebf8a..4a5e045 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1937,11 +1937,18 @@ class PersonTest < ActiveSupport::TestCase should 'a person follows many articles' do person = create_user('article_follower').person - + 1.upto(10).map do |n| person.following_articles << fast_create(Article, :profile_id => fast_create(Person)) end assert_equal 10, person.following_articles.count end + should 'not save user after an update on person and user is not touched' do + user = create_user('testuser') + person = user.person + person.user.expects(:save!).never + person.save! + end + end -- libgit2 0.21.2