change some before_create's to before_validation, :on => :create

random tokens need to be filled in before validation, otherwise the
validation is just checking a blank value
This commit is contained in:
joshua stein 2013-07-19 22:05:00 -05:00
parent 4f8c302edb
commit ccb8094da1
6 changed files with 16 additions and 7 deletions

View file

@ -13,8 +13,11 @@ class Comment < ActiveRecord::Base
attr_accessor :parent_comment_short_id, :current_vote, :previewing,
:indent_level, :highlighted
before_create :assign_short_id_and_upvote, :assign_initial_confidence,
:assign_thread_id
before_validation :on => :create do
self.assign_short_id_and_upvote
self.assign_initial_confidence
self.assign_thread_id
end
after_create :assign_votes, :mark_submitter, :deliver_reply_notifications,
:deliver_mention_notifications, :log_to_countinual
after_destroy :unassign_votes

View file

@ -9,7 +9,8 @@ class Invitation < ActiveRecord::Base
end
end
before_create :create_code
before_validation :create_code,
:on => :create
def create_code
(1...10).each do |tries|

View file

@ -16,7 +16,8 @@ class Message < ActiveRecord::Base
validates_length_of :subject, :in => 1..150
validates_length_of :body, :maximum => (64 * 1024)
before_create :assign_short_id
before_validation :assign_short_id,
:on => :create
after_create :deliver_reply_notifications
after_save :update_unread_counts
after_save :check_for_both_deleted

View file

@ -18,7 +18,7 @@ class ShortId
CandidateId.new(klass)
end
private
private
class CandidateId
attr_accessor :klass, :id

View file

@ -19,7 +19,8 @@ class Story < ActiveRecord::Base
attr_accessible :title, :description, :tags_a, :moderation_reason
before_create :assign_short_id
before_validation :assign_short_id,
:on => :create
before_save :log_moderation
after_create :mark_submitter

View file

@ -34,7 +34,10 @@ class User < ActiveRecord::Base
:pushover_mentions, :mailing_list_enabled
before_save :check_session_token
before_create :create_rss_token, :create_mailing_list_token
before_validation :on => :create do
self.create_rss_token
self.create_mailing_list_token
end
after_create :create_default_tag_filters
BANNED_USERNAMES = [ "admin", "administrator", "hostmaster", "mailer-daemon",