Story: don't allow a story to be merged into itself
This commit is contained in:
parent
336882a8fd
commit
b204775e8f
|
@ -25,6 +25,12 @@ class Story < ActiveRecord::Base
|
|||
validates_length_of :url, :maximum => 250, :allow_nil => true
|
||||
validates_presence_of :user_id
|
||||
|
||||
validates_each :merged_story_id do |record,attr,value|
|
||||
if value.to_i == record.id
|
||||
record.errors.add(:merge_story_short_id, "id cannot be itself.")
|
||||
end
|
||||
end
|
||||
|
||||
DOWNVOTABLE_DAYS = 14
|
||||
|
||||
# after this many minutes old, a story cannot be edited
|
||||
|
@ -442,11 +448,6 @@ class Story < ActiveRecord::Base
|
|||
Keystore.increment_value_for("user:#{self.user_id}:stories_submitted")
|
||||
end
|
||||
|
||||
def merge_into_story!(story)
|
||||
self.merged_story_id = story.id
|
||||
self.save!
|
||||
end
|
||||
|
||||
def merged_comments
|
||||
# TODO: make this a normal has_many?
|
||||
Comment.where(:story_id => Story.select(:id).
|
||||
|
|
Loading…
Reference in a new issue