From ccb8094da193106e387d3656c51c4eba87b8df42 Mon Sep 17 00:00:00 2001 From: joshua stein Date: Fri, 19 Jul 2013 22:05:00 -0500 Subject: [PATCH] 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 --- app/models/comment.rb | 7 +++++-- app/models/invitation.rb | 3 ++- app/models/message.rb | 3 ++- app/models/short_id.rb | 2 +- app/models/story.rb | 3 ++- app/models/user.rb | 5 ++++- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 8c3bc71..c93347a 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 4b7afe6..c953591 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -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| diff --git a/app/models/message.rb b/app/models/message.rb index 06865aa..543d114 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -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 diff --git a/app/models/short_id.rb b/app/models/short_id.rb index 164c9a3..b35f5a6 100644 --- a/app/models/short_id.rb +++ b/app/models/short_id.rb @@ -18,7 +18,7 @@ class ShortId CandidateId.new(klass) end - private +private class CandidateId attr_accessor :klass, :id diff --git a/app/models/story.rb b/app/models/story.rb index b501e22..b5d1c49 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 5cd3aac..e5f6011 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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",