diff --git a/Gemfile b/Gemfile index 5733df03a5..4e5f2a24ae 100644 --- a/Gemfile +++ b/Gemfile @@ -68,3 +68,4 @@ gem 'jasmine-jquery-rails' gem 'geocoder' gem "i18n-js", ">= 3.0.0.rc11" gem 'http_accept_language' +gem 'friendly_id' diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 790aa1ae4f..ff227424f4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -158,4 +158,13 @@ def comments_node_and_path end end + def redirect_old_urls + # If an old id or a numeric id was used to find the record, then + # the request path will not match the notes path, and we should do + # a 301 redirect that uses the current friendly id. + if request.path != @node.path + return redirect_to @node.path, :status => :moved_permanently + end + end + end diff --git a/app/controllers/map_controller.rb b/app/controllers/map_controller.rb index cf1205a839..92f774fa27 100644 --- a/app/controllers/map_controller.rb +++ b/app/controllers/map_controller.rb @@ -16,7 +16,10 @@ def index end def show - @node = DrupalNode.find_map_by_slug(params[:name]+'/'+params[:date]) + @node = DrupalNode.find_map(params[:name], params[:name]) + + redirect_old_urls + @node.view @title = @node.title @tags = @node.tags diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 72b7ed30c7..e4cdfcf0b7 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -90,8 +90,9 @@ def raw def show if params[:author] && params[:date] - @node = DrupalNode.where(path: "/notes/#{params[:author]}/#{params[:date]}/#{params[:id]}").first + @node = DrupalNode.find_notes(params[:author], params[:date], params[:id]) @node = @node || DrupalNode.where(path: "/report/#{params[:id]}").first + redirect_old_urls else @node = DrupalNode.find params[:id] end diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 60010de2d8..d6acc56fa4 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -15,8 +15,11 @@ def index def show if params[:author] && params[:date] - @node = DrupalNode.where(path: "/notes/#{params[:author]}/#{params[:date]}/#{params[:id]}").first + @node = DrupalNode.find_notes(params[:author], params[:date], params[:id]) @node = @node || DrupalNode.where(path: "/report/#{params[:id]}").first + if request.path != @node.path(:question) + return redirect_to @node.path(:question), :status => :moved_permanently + end else @node = DrupalNode.find params[:id] end diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index ce88fcb90c..228eaa6579 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -20,10 +20,10 @@ def subdomain end def show - if params[:lang] - @node = DrupalNode.find_by_slug(params[:lang]+"/"+params[:id]) - else - @node = DrupalNode.find_by_slug(params[:id]) + @node = DrupalNode.find params[:id] + + if request.path != @node.path && request.path != '/wiki/' + @node.nid.to_s + return redirect_to @node.path, :status => :moved_permanently end return if check_and_redirect_node(@node) @@ -63,11 +63,7 @@ def raw end def edit - if params[:lang] - @node = DrupalNode.find_by_slug(params[:lang]+"/"+params[:id]) - else - @node = DrupalNode.find_by_slug(params[:id]) - end + @node = DrupalNode.find params[:id] if ((Time.now.to_i - @node.latest.timestamp) < 5.minutes.to_i) && @node.latest.author.uid != current_user.uid flash.now[:warning] = "Someone has clicked 'Edit' less than 5 minutes ago; be careful not to overwrite each others' edits!" end @@ -142,6 +138,7 @@ def update i.vid = @revision.vid i.save end + @node.title = @revision.title # save main image if params[:main_image] && params[:main_image] != "" begin diff --git a/app/models/drupal_node.rb b/app/models/drupal_node.rb index 390e3116fd..97dd921aeb 100644 --- a/app/models/drupal_node.rb +++ b/app/models/drupal_node.rb @@ -16,10 +16,28 @@ def validate(record) class DrupalNode < ActiveRecord::Base include NodeShared # common methods for node-like models - attr_accessible :title, :uid, :status, :type, :vid, :cached_likes, :comment, :path + attr_accessible :title, :uid, :status, :type, :vid, :cached_likes, :comment, :path, :slug self.table_name = 'node' self.primary_key = 'nid' + extend FriendlyId + friendly_id :friendly_id_string, use: [:slugged, :history] + + def should_generate_new_friendly_id? + slug.blank? || title_changed? + end + + def friendly_id_string + if self.type == 'note' + username = DrupalUsers.find_by_uid(self.uid).name + "#{username} #{Time.at(self.created).strftime("%m-%d-%Y")} #{self.title}" + elsif self.type == 'page' + "#{self.title}" + elsif self.type == 'map' + "#{self.title} #{Time.at(self.created).strftime("%m-%d-%Y")}" + end + end + has_many :drupal_node_revision, :foreign_key => 'nid', :dependent => :destroy # wasn't working to tie it to .vid, manually defining below # has_one :drupal_main_image, :foreign_key => 'vid', :dependent => :destroy @@ -43,7 +61,7 @@ class DrupalNode < ActiveRecord::Base validates :title, :presence => :true validates_with UniqueUrlValidator, :on => :create - validates :path, :uniqueness => { :scope => :nid, :message => "This title has already been taken" } + validates :path, :uniqueness => { :message => "This title has already been taken" } # making drupal and rails database conventions play nice; # 'changed' is a reserved word in rails @@ -64,6 +82,8 @@ def self.inheritance_column before_save :set_changed_and_created after_create :setup before_validation :set_path, on: :create + before_create :remove_slug + before_update :update_path # can switch to a "question-style" path if specified def path(type = :default) @@ -94,6 +114,24 @@ def set_path self.path = self.generate_path if self.path.blank? && !self.title.blank? end + def update_path + self.path = if self.type == 'note' + username = DrupalUsers.find_by_uid(self.uid).name + "/notes/#{username}/#{Time.at(self.created).strftime("%m-%d-%Y")}/#{self.title.parameterize}" + elsif self.type == 'page' + "/wiki/" + self.title.parameterize + elsif self.type == 'map' + "/map/#{self.title.parameterize}/#{Time.at(self.created).strftime("%m-%d-%Y")}" + end + end + + def remove_slug + if !FriendlyId::Slug.find_by_slug(self.title.parameterize).nil? && self.type == 'page' + slug = FriendlyId::Slug.find_by_slug(self.title.parameterize) + slug.delete + end + end + def set_changed_and_created self['changed'] = DateTime.now.to_i end @@ -384,14 +422,6 @@ def totalcount self.drupal_node_counter.totalcount end - # ============================================ - # URL-related methods: - - # is this used anymore? deprecate? - def slug - self.path.split('/').last - end - def edit_path if self.type == "page" || self.type == "tool" || self.type == "place" path = "/wiki/edit/" + self.path.split("/").last @@ -401,18 +431,10 @@ def edit_path path end - def self.find_by_slug(title) - DrupalNode.where(path: ["/#{title}", "/tool/#{title}", "/wiki/#{title}", "/place/#{title}"]).first - end - def self.find_root_by_slug(title) DrupalNode.where(path: ["/#{title}"]).first end - def self.find_map_by_slug(title) - DrupalNode.where(path: "/map/#{title}").first - end - def map # This fires off a query that orders by vid DESC # and is quicker than doing .order(vid: :DESC) for some reason. @@ -648,4 +670,13 @@ def mentioned_users User.find_all_by_username(usernames.map {|m| m[1] }).uniq end + def self.find_notes(author, date, title) + finder = "#{author} #{date} #{title}".parameterize + DrupalNode.find(finder) + end + + def self.find_map(name, date) + finder = "#{name} #{date}".parameterize + DrupalNode.find(finder) + end end diff --git a/db/migrate/20160715024414_rename_long_column_in_users.rb b/db/migrate/20160715024414_rename_long_column_in_users.rb index 5006e30c65..818898a9df 100644 --- a/db/migrate/20160715024414_rename_long_column_in_users.rb +++ b/db/migrate/20160715024414_rename_long_column_in_users.rb @@ -4,5 +4,6 @@ def up end def down + rename_column :location_tags, :lon, :long end end diff --git a/db/migrate/20160809215133_add_slug_to_nodes.rb b/db/migrate/20160809215133_add_slug_to_nodes.rb new file mode 100644 index 0000000000..0074c91248 --- /dev/null +++ b/db/migrate/20160809215133_add_slug_to_nodes.rb @@ -0,0 +1,11 @@ +class AddSlugToNodes < ActiveRecord::Migration + def up + add_column :node, :slug, :string + add_index :node, :slug + end + + def down + remove_index :node, :slug + remove_column :node, :slug + end +end diff --git a/db/migrate/20160809215356_create_friendly_id_slugs.rb b/db/migrate/20160809215356_create_friendly_id_slugs.rb new file mode 100644 index 0000000000..bb80e48d9e --- /dev/null +++ b/db/migrate/20160809215356_create_friendly_id_slugs.rb @@ -0,0 +1,18 @@ +class CreateFriendlyIdSlugs < ActiveRecord::Migration + + def self.up + create_table :friendly_id_slugs do |t| + t.string :slug, :null => false + t.integer :sluggable_id, :null => false + t.string :sluggable_type, :limit => 40 + t.datetime :created_at + end + add_index :friendly_id_slugs, :sluggable_id + add_index :friendly_id_slugs, [:slug, :sluggable_type], :unique => true + add_index :friendly_id_slugs, :sluggable_type + end + + def self.down + drop_table :friendly_id_slugs + end +end diff --git a/db/schema.rb.example b/db/schema.rb.example index d0581e74f3..a888fc7ade 100644 --- a/db/schema.rb.example +++ b/db/schema.rb.example @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160722022014) do +ActiveRecord::Schema.define(:version => 20160809215356) do create_table "answer_selections", :force => true do |t| t.integer "user_id" @@ -147,6 +147,17 @@ ActiveRecord::Schema.define(:version => 20160722022014) do add_index "files", ["timestamp"], :name => "index_files_timestamp" add_index "files", ["uid"], :name => "index_files_uid" + create_table "friendly_id_slugs", :force => true do |t| + t.string "slug", :null => false + t.integer "sluggable_id", :null => false + t.string "sluggable_type", :limit => 40 + t.datetime "created_at" + end + + add_index "friendly_id_slugs", ["slug", "sluggable_type"], :name => "index_friendly_id_slugs_on_slug_and_sluggable_type", :unique => true + add_index "friendly_id_slugs", ["sluggable_id"], :name => "index_friendly_id_slugs_on_sluggable_id" + add_index "friendly_id_slugs", ["sluggable_type"], :name => "index_friendly_id_slugs_on_sluggable_type" + create_table "images", :force => true do |t| t.string "title" t.integer "uid" @@ -194,12 +205,14 @@ ActiveRecord::Schema.define(:version => 20160722022014) do t.integer "drupal_node_revisions_count", :default => 0 t.string "path" t.integer "main_image_id" + t.string "slug" end add_index "node", ["changed"], :name => "node_changed" add_index "node", ["created"], :name => "node_created" add_index "node", ["moderate"], :name => "node_moderate" add_index "node", ["promote", "status"], :name => "node_promote_status" + add_index "node", ["slug"], :name => "index_node_on_slug" add_index "node", ["status", "type", "nid"], :name => "node_status_type" add_index "node", ["title", "type"], :name => "node_title_type" add_index "node", ["tnid"], :name => "index_node_tnid" diff --git a/test/fixtures/friendly_id_slugs.yml b/test/fixtures/friendly_id_slugs.yml new file mode 100644 index 0000000000..9e233e781b --- /dev/null +++ b/test/fixtures/friendly_id_slugs.yml @@ -0,0 +1,55 @@ +one: + id: 1 + slug: jeff-<%= Time.now.strftime("%m-%d-%Y") %>-canon-a1200-ir-conversion-at-plots-barnraising-at-lumcon + sluggable_id: 1 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +two: + id: 2 + slug: about + sluggable_id: 2 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +three: + id: 3 + slug: spammer-<%= Time.now.strftime("%m-%d-%Y") %>-hot-stuff-i-m-selling + sluggable_id: 3 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +four: + id: 4 + slug: important-work + sluggable_id: 4 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +five: + id: 5 + slug: organizers + sluggable_id: 5 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +six: + id: 6 + slug: newcomer-<%= Time.now.strftime("%m-%d-%Y") %>-my-very-first-post-to-public-lab + sluggable_id: 6 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +seven: + id: 7 + slug: chicago + sluggable_id: 7 + sluggable_type: DrupalNode + created_at: <%= Time.now %> + +eight: + id: 8 + slug: jeff-<%= Time.now.strftime("%m-%d-%Y") %>-how-to-use-a-spectrometer + sluggable_id: 8 + sluggable_type: DrupalNode + created_at: <%= Time.now %> diff --git a/test/fixtures/node.yml b/test/fixtures/node.yml index 989e96ddd2..4cb0f5f4f6 100644 --- a/test/fixtures/node.yml +++ b/test/fixtures/node.yml @@ -8,6 +8,7 @@ one: status: 1 type: "note" cached_likes: 0 + slug: jeff-<%= Time.now.strftime("%m-%d-%Y") %>-canon-a1200-ir-conversion-at-plots-barnraising-at-lumcon about: nid: 2 @@ -19,6 +20,7 @@ about: status: 1 type: "page" cached_likes: 0 + slug: about spam: nid: 3 @@ -30,17 +32,19 @@ spam: status: 0 type: "note" cached_likes: 0 + slug: spammer-<%= Time.now.strftime("%m-%d-%Y") %>-hot-stuff-i-m-selling spam_targeted_page: nid: 4 uid: 1 title: "Important work" - path: "/wiki/important" + path: "/wiki/important-work" created: <%= Time.now.to_i %> changed: <%= Time.now.to_i %> status: 1 type: "page" cached_likes: 0 + slug: important-work organizers: nid: 5 @@ -52,6 +56,7 @@ organizers: status: 1 type: "page" cached_likes: 0 + slug: organizers first_timer_note: nid: 6 @@ -63,6 +68,7 @@ first_timer_note: status: 4 type: "note" cached_likes: 0 + slug: newcomer-<%= Time.now.strftime("%m-%d-%Y") %>-my-very-first-post-to-public-lab place: nid: 7 @@ -72,8 +78,9 @@ place: created: <%= Time.now.to_i %> changed: <%= Time.now.to_i %> status: 1 - type: "wiki" + type: "page" cached_likes: 0 + slug: chicago question: nid: 8 @@ -85,3 +92,4 @@ question: status: 1 type: "note" cached_likes: 0 + slug: jeff-<%= Time.now.strftime("%m-%d-%Y") %>-how-to-use-a-spectrometer diff --git a/test/fixtures/node_counter.yml b/test/fixtures/node_counter.yml index b45ad3866e..95e286ce5d 100644 --- a/test/fixtures/node_counter.yml +++ b/test/fixtures/node_counter.yml @@ -16,5 +16,8 @@ five: six: nid: 6 +seven: + nid: 7 + eight: nid: 8 diff --git a/test/fixtures/node_revisions.yml b/test/fixtures/node_revisions.yml index 13619bac19..456f5546f7 100644 --- a/test/fixtures/node_revisions.yml +++ b/test/fixtures/node_revisions.yml @@ -135,3 +135,9 @@ question: uid: 2 title: How to use a Spectrometer body: Spectrometer Question + +place: + nid: 7 + uid: 1 + title: Chicago + body: Chicago chapter diff --git a/test/functional/notes_controller_test.rb b/test/functional/notes_controller_test.rb index 3cc20e4100..dce7b40f97 100644 --- a/test/functional/notes_controller_test.rb +++ b/test/functional/notes_controller_test.rb @@ -54,8 +54,8 @@ def setup test "don't show note by spam author" do note = node(:spam) # spam fixture - - get :show, + + get :show, author: note.author.name, date: Time.at(note.created).strftime("%m-%d-%Y"), id: note.title.parameterize @@ -235,45 +235,6 @@ def setup #end - test "edit note" do - UserSession.create(rusers(:bob)) - title = "My second post about balloon mapping" - - post :create, - title: title, - body: "This is a fascinating post about a balloon mapping event.", - tags: "balloon-mapping,event" - #, main_image: "/images/testimage.jpg" - - assert_redirected_to "/notes/"+rusers(:bob).username+"/"+Time.now.strftime("%m-%d-%Y")+"/"+title.parameterize - - node = DrupalNode.where(title: title).first - - # add a tag, and change the title and body - newtitle = title + " which I amended" - - post :update, - id: node.id, - title: newtitle, - body: "This is a fascinating post about a balloon mapping event. added content", - tags: "balloon-mapping,event,meetup" - - assert_redirected_to "/notes/" + rusers(:bob).username + "/" + Time.now.strftime("%m-%d-%Y") + "/" + title.parameterize + "?_=" + Time.now.to_i.to_s - - # approve the first-timer's note: - node.publish - - get :show, - author: rusers(:bob).username, - date: Time.now.strftime("%m-%d-%Y"), - id: title.parameterize - - assert_equal flash[:notice], "Edits saved." - assert_select "h1", newtitle - # assert_select "span#teststring", "added content" # this test does not work!! very frustrating. - # assert_select ".label", "meetup" # test for tag addition too, later - end - test "should load iframe url in comments" do comment = DrupalComment.new({ nid: node(:one).nid, @@ -313,7 +274,7 @@ def setup test "should redirect to questions show page after creating a new question" do user = UserSession.create(rusers(:bob)) - title = "How to use a Spectrometer" + title = "How to use Spectrometer" post :create, title: title, body: "Spectrometer question", diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 3113371372..f7b90757ba 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -80,13 +80,9 @@ def teardown title: newtitle, body: "Editing about Page" + wiki.reload assert_redirected_to wiki.path - - get :show, id: wiki.slug - - assert_response :success assert_equal flash[:notice], "Edits saved." - assert_select "h1", newtitle # title should change but not URL end test "update root-path (/about) wiki" do @@ -96,16 +92,12 @@ def teardown post :update, id: wiki.nid, uid: rusers(:bob).id, - title: "New Title", + title: newtitle, body: "Editing about Page" + wiki.reload assert_redirected_to wiki.path - - get :show, id: wiki.slug - - assert_response :success assert_equal flash[:notice], "Edits saved." - assert_select "h1", newtitle # title should change but not URL end test "update wiki uploading new image" do @@ -121,6 +113,7 @@ def teardown :photo => image } + node.reload assert_redirected_to node.path assert_equal flash[:notice], "Edits saved." end @@ -136,6 +129,7 @@ def teardown body: "Editing about Page", image_revision: image.path(:default) + node.reload assert_redirected_to node.path assert_equal flash[:notice], "Edits saved." end diff --git a/test/integration/I18n_test.rb b/test/integration/I18n_test.rb index b36ed543c7..1a01d449fc 100644 --- a/test/integration/I18n_test.rb +++ b/test/integration/I18n_test.rb @@ -326,7 +326,8 @@ class I18nTest < ActionDispatch::IntegrationTest } follow_redirect! - get '/wiki/edit' + wiki = node(:about) + get '/wiki/edit/' + wiki.title.parameterize assert_select 'a', I18n.t('wiki.edit.getting_started') end end diff --git a/test/integration/node_update_test.rb b/test/integration/node_update_test.rb new file mode 100644 index 0000000000..1b3eec72ea --- /dev/null +++ b/test/integration/node_update_test.rb @@ -0,0 +1,200 @@ +require 'test_helper' + +class NodeUpdateTest < ActionDispatch::IntegrationTest + + test "edit note after creating a new note" do + post '/user_sessions', user_session: { + username: rusers(:bob).username, + password: 'secret' + } + + title = "My second post about balloon mapping" + + post '/notes/create', + title: title, + body: "This is a fascinating post about a balloon mapping event.", + tags: "balloon-mapping,event" + + follow_redirect! + assert_equal "/notes/" + rusers(:bob).username + "/" + + Time.now.strftime("%m-%d-%Y") + "/" + title.parameterize, path + + node = DrupalNode.where(title: title).first + + # approve the first-timer's note: + node.publish + + # add a tag, and change the title and body + newtitle = title + " which I amended" + + post '/notes/update/' + node.id.to_s, + title: newtitle, + body: "This is a fascinating post about a balloon mapping event. added content", + tags: "balloon-mapping,event,meetup" + follow_redirect! + # path gets updated + assert_equal "/notes/" + rusers(:bob).username + "/" + + Time.now.strftime("%m-%d-%Y") + "/" + newtitle.parameterize, path + + assert_equal flash[:notice], "Edits saved." + + # visiting note with new path + get "/notes/" + rusers(:bob).username + "/" + + Time.now.strftime("%m-%d-%Y") + "/" + newtitle.parameterize + assert_response :success + assert_select "h1", newtitle + assert_select "span#teststring", "added content" + # assert_select ".label", "meetup" # test for tag addition too, later + end + + test "should redirect to new note path when visiting with old url" do + post '/user_sessions', user_session: { + username: rusers(:jeff).username, + password: 'secret' + } + + node = node(:one) + oldtitle = node.title + newtitle = oldtitle + " which I amended" + + post '/notes/update/' + node.id.to_s, + title: newtitle, + body: "Some test string" + + follow_redirect! + # path gets updated + assert_equal "/notes/" + rusers(:jeff).username + "/" + + node.created_at.strftime("%m-%d-%Y") + "/" + newtitle.parameterize, path + + assert_equal flash[:notice], "Edits saved." + + # visiting note with old path + get '/notes/' + rusers(:jeff).username + "/" + + node.created_at.strftime("%m-%d-%Y") + "/" + oldtitle.parameterize + + follow_redirect! + assert_equal '/notes/' + rusers(:jeff).username + "/" + + node.created_at.strftime("%m-%d-%Y") + "/" + + newtitle.parameterize, path + + end + + test "should redirect to new path for question when visiting with old url" do + post '/user_sessions', user_session: { + username: rusers(:jeff).username, + password: 'secret' + } + + node = node(:question) + oldtitle = node.title + newtitle = oldtitle + " which I amended" + + post '/notes/update/' + node.id.to_s, + title: newtitle, + body: "Some test string", + redirect: "question" + + follow_redirect! + # path gets updated + assert_equal "/questions/" + rusers(:jeff).username + "/" + + node.created_at.strftime("%m-%d-%Y") + "/" + newtitle.parameterize, path + + assert_equal flash[:notice], "Edits saved." + + # visiting note with old path + get '/questions/' + rusers(:jeff).username + "/" + + node.created_at.strftime("%m-%d-%Y") + "/" + oldtitle.parameterize + + follow_redirect! + assert_equal '/questions/' + rusers(:jeff).username + "/" + + node.created_at.strftime("%m-%d-%Y") + "/" + + newtitle.parameterize, path + + end + + test "should redirect to new wiki path when visiting with old url" do + post '/user_sessions', user_session: { + username: rusers(:bob).username, + password: 'secret' + } + + node = node(:about) + oldtitle = node.title + newtitle = oldtitle + " page amended" + + post '/wiki/update/' + node.id.to_s, + title: newtitle, + body: "Some test string" + + follow_redirect! + # path gets updated + assert_equal "/wiki/" + newtitle.parameterize, path + + assert_equal flash[:notice], "Edits saved." + + # visiting note with old path + get '/wiki/' + oldtitle.parameterize + + follow_redirect! + assert_equal '/wiki/' + newtitle.parameterize, path + + end + + test "should take the old url if the title is reverted to the old title" do + post '/user_sessions', user_session: { + username: rusers(:bob).username, + password: 'secret' + } + + node = node(:about) + oldtitle = node.title + newtitle = oldtitle + " page amended" + + post '/wiki/update/' + node.id.to_s, + title: newtitle, + body: "Some test string" + + follow_redirect! + # path gets updated + assert_equal "/wiki/" + newtitle.parameterize, path + assert_equal flash[:notice], "Edits saved." + + # reverting to the old title + post '/wiki/update/' + node.id.to_s, + title: oldtitle, + body: "Some test string" + + follow_redirect! + # path gets changed to the old url + assert_equal "/wiki/" + oldtitle.parameterize, path + assert_equal flash[:notice], "Edits saved." + end + + test "should reuse old slugs if a new wiki page is created with an old title of another wiki" do + post '/user_sessions', user_session: { + username: rusers(:bob).username, + password: 'secret' + } + + node = node(:about) + oldtitle = node.title + newtitle = oldtitle + " page amended" + + post '/wiki/update/' + node.id.to_s, + title: newtitle, + body: "Some test string" + + follow_redirect! + assert_equal "/wiki/" + newtitle.parameterize, path + assert_equal flash[:notice], "Edits saved." + + # create wiki page with oldtitle + post '/wiki/create/', + title: oldtitle, + body: "Test string" + + follow_redirect! + assert_equal "/wiki/" + oldtitle.parameterize, path + end + +end