diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index c55c5eacb..4dbaf1b29 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -33,7 +33,8 @@ class WikiPagesController < ApplicationController @wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id]) if request.format.html? && @wiki_page.blank? && found_by == :title - redirect_to show_or_new_wiki_pages_path(title: params[:id]) + @wiki_page = WikiPage.new(title: params[:id]) + respond_with @wiki_page, status: 404 elsif request.format.html? && @wiki_page.present? && found_by == :id redirect_to @wiki_page elsif @wiki_page.blank? @@ -69,15 +70,10 @@ class WikiPagesController < ApplicationController end def show_or_new - @wiki_page = WikiPage.find_by_title(params[:title]) - if params[:title].blank? redirect_to new_wiki_page_path(wiki_page_params(:create)) - elsif @wiki_page.present? - redirect_to wiki_page_path(@wiki_page) else - @wiki_page = WikiPage.new(:title => params[:title]) - respond_with(@wiki_page) + redirect_to wiki_page_path(params[:title]) end end diff --git a/app/views/wiki_pages/show.html.erb b/app/views/wiki_pages/show.html.erb index 593bc8964..654f7680b 100644 --- a/app/views/wiki_pages/show.html.erb +++ b/app/views/wiki_pages/show.html.erb @@ -19,7 +19,11 @@
<%= wiki_page_other_names_list(@wiki_page) %>
<% end %> - <%= format_text(@wiki_page.body) %> + <% if @wiki_page.new_record? %> +This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(wiki_page: { title: @wiki_page.title }) %>.
+ <% else %> + <%= format_text(@wiki_page.body) %> + <% end %> <% if @wiki_page.artist %><%= link_to "View artist", @wiki_page.artist %>
diff --git a/app/views/wiki_pages/show_or_new.html.erb b/app/views/wiki_pages/show_or_new.html.erb deleted file mode 100644 index 904fd7195..000000000 --- a/app/views/wiki_pages/show_or_new.html.erb +++ /dev/null @@ -1,24 +0,0 @@ -<%= render "sidebar" %> - -<% content_for(:content) do %> -This wiki page does not exist. <%= link_to "Create new wiki page", new_wiki_page_path(:wiki_page => {:title => params[:title]}) %>.
-<%= link_to "View artist", @wiki_page.artist %>
- <% end %> - - <%= wiki_page_alias_and_implication_list(@wiki_page)%> - - <%= wiki_page_post_previews(@wiki_page) %> -<% end %> - -<%= render "secondary_links" %> - -<% content_for(:page_title) do %> - Wiki - <%= params[:title] %> - <%= Danbooru.config.app_name %> -<% end %> diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index 0160c2db3..9e7803f42 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -66,9 +66,11 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest assert_response :success end - should "redirect html requests for a nonexistent title" do + should "show the 'does not exist' page for a nonexistent title" do get wiki_page_path("what") - assert_redirected_to(show_or_new_wiki_pages_path(title: "what")) + + assert_response 404 + assert_select "#wiki-page-body", text: /This wiki page does not exist/ end should "return 404 to api requests for a nonexistent title" do @@ -98,9 +100,9 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest assert_redirected_to(@wiki_page) end - should "render when given a nonexistent title" do + should "redirect when given a nonexistent title" do get show_or_new_wiki_pages_path, params: { title: "what" } - assert_response :success + assert_redirected_to wiki_page_path("what") end end