-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1946fab
commit e53d60d
Showing
22 changed files
with
384 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class TagAliasRequestsController < ApplicationController | ||
before_filter :member_only | ||
rescue_from TagAliasRequest::ValidationError, :with => :rescue_exception | ||
|
||
def new | ||
end | ||
|
||
def create | ||
@tag_alias_request = TagAliasRequest.new( | ||
params[:tag_alias_request][:antecedent_name], | ||
params[:tag_alias_request][:consequent_name], | ||
params[:tag_alias_request][:reason] | ||
) | ||
@tag_alias_request.create | ||
redirect_to(forum_topic_path(@tag_alias_request.forum_topic)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class TagImplicationRequestsController < ApplicationController | ||
before_filter :member_only | ||
rescue_from TagImplicationRequest::ValidationError, :with => :rescue_exception | ||
|
||
def new | ||
end | ||
|
||
def create | ||
@tag_implication_request = TagImplicationRequest.new( | ||
params[:tag_implication_request][:antecedent_name], | ||
params[:tag_implication_request][:consequent_name], | ||
params[:tag_implication_request][:reason] | ||
) | ||
@tag_implication_request.create | ||
redirect_to(forum_topic_path(@tag_implication_request.forum_topic)) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div id="c-tag-aliases"> | ||
<div id="a-request-new"> | ||
<h1>Tag Alias Request</h1> | ||
|
||
<p>You can request a new tag alias be created. This will create a corresponding forum topic for community review.</p> | ||
|
||
<%= form_tag(tag_alias_request_path, :class => "simple_form") do %> | ||
<div class="input"> | ||
<label>Antecedent</label> | ||
<%= text_field "tag_alias_request", "antecedent_name" %> | ||
</div> | ||
|
||
<div class="input"> | ||
<label>Consequent</label> | ||
<%= text_field "tag_alias_request", "consequent_name" %> | ||
</div> | ||
|
||
<div class="input"> | ||
<label>Reason</label> | ||
<%= text_area "tag_alias_request", "reason" %> | ||
</div> | ||
|
||
<div class="input"> | ||
<%= submit_tag "Submit" %> | ||
</div> | ||
<% end %> | ||
<%= render "tag_aliases/secondary_links" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<% content_for(:secondary_links) do %> | ||
<menu> | ||
<li><%= link_to "Listing", tag_aliases_path %></li> | ||
<li><%= link_to "New", new_tag_alias_path %></li> | ||
<% if CurrentUser.is_admin? %> | ||
<li><%= link_to "New", new_tag_alias_path %></li> | ||
<% else %> | ||
<li><%= link_to "Request", new_tag_alias_request_path %></li> | ||
<% end %> | ||
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_aliases") %></li> | ||
</menu> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<div id="c-tag-implications"> | ||
<div id="a-request-new"> | ||
<h1>Tag Implication Request</h1> | ||
|
||
<p>You can request a new tag implication be created. This will create a corresponding forum topic for community review.</p> | ||
|
||
<%= form_tag(tag_implication_request_path, :class => "simple_form") do %> | ||
<div class="input"> | ||
<label>Antecedent</label> | ||
<%= text_field "tag_implication_request", "antecedent_name" %> | ||
</div> | ||
|
||
<div class="input"> | ||
<label>Consequent</label> | ||
<%= text_field "tag_implication_request", "consequent_name" %> | ||
</div> | ||
|
||
<div class="input"> | ||
<label>Reason</label> | ||
<%= text_area "tag_implication_request", "reason" %> | ||
</div> | ||
|
||
<div class="input"> | ||
<%= submit_tag "Submit" %> | ||
</div> | ||
<% end %> | ||
<%= render "tag_implications/secondary_links" %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<% content_for(:secondary_links) do %> | ||
<menu> | ||
<li><%= link_to "Listing", tag_implications_path %></li> | ||
<li><%= link_to "New", new_tag_implication_path %></li> | ||
<% if CurrentUser.is_admin? %> | ||
<li><%= link_to "New", new_tag_implication_path %></li> | ||
<% else %> | ||
<li><%= link_to "Request", new_tag_implication_request_path %></li> | ||
<% end %> | ||
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_implications") %></li> | ||
</menu> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'test_helper' | ||
|
||
class TagAliasCorrectionsControllerTest < ActionController::TestCase | ||
context "The tag alias correction controller" do | ||
setup do | ||
@admin = FactoryGirl.create(:admin_user) | ||
CurrentUser.user = @admin | ||
CurrentUser.ip_addr = "127.0.0.1" | ||
MEMCACHE.flush_all | ||
Delayed::Worker.delay_jobs = false | ||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb") | ||
end | ||
|
||
teardown do | ||
CurrentUser.user = nil | ||
CurrentUser.ip_addr = nil | ||
end | ||
|
||
context "show action" do | ||
should "render" do | ||
get :show, {:tag_alias_id => @tag_alias.id}, {:user => @admin.id} | ||
assert_response :success | ||
end | ||
end | ||
|
||
context "create action" do | ||
should "render" do | ||
post :create, {:tag_alias_id => @tag_alias.id, :commit => "Fix"}, {:user => @admin.id} | ||
assert_redirected_to(tag_alias_correction_path(:tag_alias_id => @tag_alias.id)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'test_helper' | ||
|
||
class TagAliasRequestsControllerTest < ActionController::TestCase | ||
context "The tag alias request controller" do | ||
setup do | ||
@user = FactoryGirl.create(:user) | ||
CurrentUser.user = @user | ||
CurrentUser.ip_addr = "127.0.0.1" | ||
MEMCACHE.flush_all | ||
Delayed::Worker.delay_jobs = false | ||
end | ||
|
||
teardown do | ||
CurrentUser.user = nil | ||
CurrentUser.ip_addr = nil | ||
end | ||
|
||
context "new action" do | ||
should "render" do | ||
get :new, {}, {:user => @user.id} | ||
assert_response :success | ||
end | ||
end | ||
|
||
context "create action" do | ||
should "render" do | ||
assert_difference("ForumTopic.count", 1) do | ||
post :create, {:tag_alias_request => {:antecedent_name => "aaa", :consequent_name => "bbb", :reason => "ccc"}}, {:user => @user.id} | ||
end | ||
assert_redirected_to(forum_topic_path(ForumTopic.last)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'test_helper' | ||
|
||
class TagImplicationRequestsControllerTest < ActionController::TestCase | ||
context "The tag implication request controller" do | ||
setup do | ||
@user = FactoryGirl.create(:user) | ||
CurrentUser.user = @user | ||
CurrentUser.ip_addr = "127.0.0.1" | ||
MEMCACHE.flush_all | ||
Delayed::Worker.delay_jobs = false | ||
end | ||
|
||
teardown do | ||
CurrentUser.user = nil | ||
CurrentUser.ip_addr = nil | ||
end | ||
|
||
context "new action" do | ||
should "render" do | ||
get :new, {}, {:user => @user.id} | ||
assert_response :success | ||
end | ||
end | ||
|
||
context "create action" do | ||
should "render" do | ||
assert_difference("ForumTopic.count", 1) do | ||
post :create, {:tag_implication_request => {:antecedent_name => "aaa", :consequent_name => "bbb", :reason => "ccc"}}, {:user => @user.id} | ||
end | ||
assert_redirected_to(forum_topic_path(ForumTopic.last)) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.