mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:42:16 +08:00
Use after_commit
since after_save
runs within the transaction as well.
This commit is contained in:
parent
299b92b4d7
commit
9f299b6842
2
Gemfile
2
Gemfile
|
@ -120,6 +120,8 @@ group :test do
|
|||
gem 'fakeweb', '~> 1.3.0', require: false
|
||||
gem 'minitest', require: false
|
||||
gem 'timecop'
|
||||
# TODO: Remove once we upgrade to Rails 5.
|
||||
gem 'test_after_commit'
|
||||
end
|
||||
|
||||
group :test, :development do
|
||||
|
|
|
@ -359,6 +359,8 @@ GEM
|
|||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
stackprof (0.2.10)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tilt (2.0.5)
|
||||
|
@ -470,6 +472,7 @@ DEPENDENCIES
|
|||
sinatra
|
||||
spork-rails
|
||||
stackprof
|
||||
test_after_commit
|
||||
thor
|
||||
timecop
|
||||
uglifier
|
||||
|
|
|
@ -96,7 +96,6 @@ class User < ActiveRecord::Base
|
|||
|
||||
before_save :update_username_lower
|
||||
before_save :ensure_password_is_hashed
|
||||
before_save :setup_trigger_user_created_event
|
||||
|
||||
after_save :expire_tokens_if_password_changed
|
||||
after_save :automatic_group_membership
|
||||
|
@ -105,7 +104,7 @@ class User < ActiveRecord::Base
|
|||
after_save :badge_grant
|
||||
after_save :expire_old_email_tokens
|
||||
after_save :index_search
|
||||
after_save :trigger_user_created_event
|
||||
after_commit :trigger_user_created_event, on: :create
|
||||
|
||||
before_destroy do
|
||||
# These tables don't have primary keys, so destroying them with activerecord is tricky:
|
||||
|
@ -1078,13 +1077,8 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def setup_trigger_user_created_event
|
||||
@trigger_user_created_event = self.new_record?
|
||||
true
|
||||
end
|
||||
|
||||
def trigger_user_created_event
|
||||
DiscourseEvent.trigger(:user_created, self) if @trigger_user_created_event
|
||||
DiscourseEvent.trigger(:user_created, self)
|
||||
true
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user