stubbed in view code from old danbooru; only janitors can lock a wiki page
This commit is contained in:
@@ -2,9 +2,6 @@ require_relative '../test_helper'
|
||||
|
||||
class WikiPageTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = Factory.create(:user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
@@ -14,50 +11,75 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
context "A wiki page" do
|
||||
should "normalize its title" do
|
||||
wp = Factory.create(:wiki_page, :title => "HOT POTATO")
|
||||
assert_equal("hot_potato", wp.title)
|
||||
context "updated by a janitor" do
|
||||
setup do
|
||||
@user = Factory.create(:janitor_user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@wiki_page = Factory.create(:wiki_page)
|
||||
end
|
||||
|
||||
should "allow the is_locked attribute to be updated" do
|
||||
@wiki_page.update_attributes(:is_locked => true)
|
||||
@wiki_page.reload
|
||||
assert_equal(true, @wiki_page.is_locked?)
|
||||
end
|
||||
end
|
||||
|
||||
should "search by title" do
|
||||
Factory.create(:wiki_page, :title => "HOT POTATO")
|
||||
matches = WikiPage.titled("hot potato")
|
||||
assert_equal(1, matches.count)
|
||||
assert_equal("hot_potato", matches.first.title)
|
||||
end
|
||||
|
||||
should "create versions" do
|
||||
wp = nil
|
||||
context "updated by a regular user" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
@wiki_page = Factory.create(:wiki_page, :title => "HOT POTATO")
|
||||
end
|
||||
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
wp = Factory.create(:wiki_page, :title => "xxx")
|
||||
should "not allow the is_locked attribute to be updated" do
|
||||
@wiki_page.update_attributes(:is_locked => true)
|
||||
assert_equal(["Is locked can be modified by janitors only"], @wiki_page.errors.full_messages)
|
||||
@wiki_page.reload
|
||||
assert_equal(false, @wiki_page.is_locked?)
|
||||
end
|
||||
|
||||
should "normalize its title" do
|
||||
assert_equal("hot_potato", @wiki_page.title)
|
||||
end
|
||||
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
wp.title = "yyy"
|
||||
wp.save
|
||||
should "search by title" do
|
||||
matches = WikiPage.titled("hot potato")
|
||||
assert_equal(1, matches.count)
|
||||
assert_equal("hot_potato", matches.first.title)
|
||||
end
|
||||
end
|
||||
|
||||
should "revert to a prior version" do
|
||||
wp = Factory.create(:wiki_page, :title => "xxx")
|
||||
wp.title = "yyy"
|
||||
wp.save
|
||||
version = WikiPageVersion.first
|
||||
wp.revert_to!(version)
|
||||
wp.reload
|
||||
assert_equal("xxx", wp.title)
|
||||
end
|
||||
|
||||
should "differentiate between updater and creator" do
|
||||
user = Factory.create(:user)
|
||||
wp = Factory.create(:wiki_page, :title => "xxx")
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
wp.title = "yyy"
|
||||
wp.save
|
||||
|
||||
should "create versions" do
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
@wiki_page = Factory.create(:wiki_page, :title => "xxx")
|
||||
end
|
||||
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
@wiki_page.title = "yyy"
|
||||
@wiki_page.save
|
||||
end
|
||||
end
|
||||
|
||||
should "revert to a prior version" do
|
||||
@wiki_page.title = "yyy"
|
||||
@wiki_page.save
|
||||
version = WikiPageVersion.first
|
||||
@wiki_page.revert_to!(version)
|
||||
@wiki_page.reload
|
||||
assert_equal("hot_potato", @wiki_page.title)
|
||||
end
|
||||
|
||||
should "differentiate between updater and creator" do
|
||||
another_user = Factory.create(:user)
|
||||
CurrentUser.scoped(another_user, "127.0.0.1") do
|
||||
@wiki_page.title = "yyy"
|
||||
@wiki_page.save
|
||||
end
|
||||
version = WikiPageVersion.first
|
||||
assert_not_equal(@wiki_page.creator_id, version.updater_id)
|
||||
end
|
||||
version = WikiPageVersion.first
|
||||
assert_not_equal(wp.creator_id, version.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user