FIX: When approving/rejecting a post it should delete the user action

This commit is contained in:
Robin Ward
2015-04-24 15:25:47 -04:00
parent 3a6efa25f0
commit 3660fe4f60
4 changed files with 22 additions and 10 deletions

View File

@@ -7,6 +7,14 @@ class QueuedPost < ActiveRecord::Base
belongs_to :approved_by, class_name: "User"
belongs_to :rejected_by, class_name: "User"
def create_pending_action
UserAction.log_action!(action_type: UserAction::PENDING,
user_id: user_id,
acting_user_id: user_id,
target_topic_id: topic_id,
queued_post_id: id)
end
def self.states
@states ||= Enum.new(:new, :approved, :rejected)
end
@@ -72,6 +80,10 @@ class QueuedPost < ActiveRecord::Base
row_count = QueuedPost.where('id = ? AND state <> ?', id, state_val).update_all(updates)
raise InvalidStateTransition.new if row_count == 0
if [:rejected, :approved].include?(state)
UserAction.where(queued_post_id: id).destroy_all
end
# Update the record in memory too, and clear the dirty flag
updates.each {|k, v| send("#{k}=", v) }
changes_applied