This commit is contained in:
albert
2013-03-10 16:31:39 -04:00
parent 1946fab809
commit e53d60d99b
22 changed files with 384 additions and 17 deletions

View File

@@ -0,0 +1,39 @@
class TagAliasRequest
class ValidationError < Exception ; end
attr_reader :antecedent_name, :consequent_name, :reason, :tag_alias, :forum_topic
def initialize(antecedent_name, consequent_name, reason)
@antecedent_name = antecedent_name
@consequent_name = consequent_name
@reason = reason
end
def create
TagAlias.transaction do
create_alias
create_forum_topic
end
end
def create_alias
@tag_alias = TagAlias.create(:antecedent_name => antecedent_name, :consequent_name => consequent_name, :status => "pending")
if @tag_alias.errors.any?
raise ValidationError.new(@tag_alias.errors.full_messages.join("; "))
end
end
def create_forum_topic
@forum_topic = ForumTopic.create(
:title => "Tag alias: #{antecedent_name} -> #{consequent_name}",
:original_post_attributes => {
:body => reason + "\n\n\"Link to alias\":/tag_aliases?search[id]=#{tag_alias.id}"
}
)
if @forum_topic.errors.any?
raise ValidationError.new(@forum_topic.errors.full_messages.join("; "))
end
tag_alias.update_attribute(:forum_topic_id, @forum_topic.id)
end
end

View File

@@ -0,0 +1,39 @@
class TagImplicationRequest
class ValidationError < Exception ; end
attr_reader :antecedent_name, :consequent_name, :reason, :tag_implication, :forum_topic
def initialize(antecedent_name, consequent_name, reason)
@antecedent_name = antecedent_name
@consequent_name = consequent_name
@reason = reason
end
def create
TagImplication.transaction do
create_implication
create_forum_topic
end
end
def create_implication
@tag_implication = TagImplication.create(:antecedent_name => antecedent_name, :consequent_name => consequent_name, :status => "pending")
if @tag_implication.errors.any?
raise ValidationError.new(@tag_implication.errors.full_messages.join("; "))
end
end
def create_forum_topic
@forum_topic = ForumTopic.create(
:title => "Tag implication: #{antecedent_name} -> #{consequent_name}",
:original_post_attributes => {
:body => reason + "\n\n\"Link to implication\":/tag_implications?search[id]=#{tag_implication.id}"
}
)
if @forum_topic.errors.any?
raise ValidationError.new(@forum_topic.errors.full_messages.join("; "))
end
tag_implication.update_attribute(:forum_topic_id, @forum_topic.id)
end
end