pundit: convert wiki pages to pundit.

This commit is contained in:
evazion
2020-03-17 04:36:05 -05:00
parent 5c6d26ea24
commit b3ff08fedf
7 changed files with 78 additions and 66 deletions

View File

@@ -33,6 +33,13 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
end
end
context "search action" do
should "work" do
get search_wiki_pages_path
assert_response :success
end
end
context "show action" do
setup do
as_user do
@@ -146,6 +153,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
should "create a wiki_page" do
assert_difference("WikiPage.count", 1) do
post_auth wiki_pages_path, @user, params: {:wiki_page => {:title => "abc", :body => "abc"}}
assert_redirected_to(wiki_page_path(WikiPage.last))
end
end
end
@@ -155,13 +163,45 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
as_user do
@tag = create(:tag, name: "foo", post_count: 42)
@wiki_page = create(:wiki_page, title: "foo")
@builder = create(:builder_user)
end
end
should "update a wiki_page" do
put_auth wiki_page_path(@wiki_page), @user, params: {:wiki_page => {:body => "xyz"}}
@wiki_page.reload
assert_equal("xyz", @wiki_page.body)
assert_redirected_to wiki_page_path(@wiki_page)
assert_equal("xyz", @wiki_page.reload.body)
end
should "not allow members to edit locked wiki pages" do
as(@user) { @wiki_page.update!(is_locked: true) }
put_auth wiki_page_path(@wiki_page), @user, params: { wiki_page: { body: "xyz" }}
assert_response 403
assert_not_equal("xyz", @wiki_page.reload.body)
end
should "allow builders to edit locked wiki pages" do
as(@builder) { @wiki_page.update!(is_locked: true) }
put_auth wiki_page_path(@wiki_page), @builder, params: { wiki_page: { body: "xyz" }}
assert_redirected_to wiki_page_path(@wiki_page)
assert_equal("xyz", @wiki_page.reload.body)
end
should "not allow members to edit the is_locked flag" do
put_auth wiki_page_path(@wiki_page), @user, params: { wiki_page: { is_locked: true }}
assert_response 403
assert_equal(false, @wiki_page.reload.is_locked)
end
should "allow builders to edit the is_locked flag" do
put_auth wiki_page_path(@wiki_page), @builder, params: { wiki_page: { is_locked: true }}
assert_redirected_to wiki_page_path(@wiki_page)
assert_equal(true, @wiki_page.reload.is_locked)
end
should "warn about renaming a wiki page with a non-empty tag" do

View File

@@ -11,38 +11,6 @@ class WikiPageTest < ActiveSupport::TestCase
end
context "A wiki page" do
context "that is locked" do
should "not be editable by a member" do
CurrentUser.user = FactoryBot.create(:moderator_user)
@wiki_page = FactoryBot.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryBot.create(:user)
@wiki_page.update(body: "hello")
assert_equal(["Is locked and cannot be updated"], @wiki_page.errors.full_messages)
end
should "be editable by a moderator" do
CurrentUser.user = FactoryBot.create(:moderator_user)
@wiki_page = FactoryBot.create(:wiki_page, :is_locked => true)
CurrentUser.user = FactoryBot.create(:moderator_user)
@wiki_page.update(body: "hello")
assert_equal([], @wiki_page.errors.full_messages)
end
end
context "updated by a moderator" do
setup do
@user = FactoryBot.create(:moderator_user)
CurrentUser.user = @user
@wiki_page = FactoryBot.create(:wiki_page)
end
should "allow the is_locked attribute to be updated" do
@wiki_page.update(is_locked: true)
@wiki_page.reload
assert_equal(true, @wiki_page.is_locked?)
end
end
context "updated by a regular user" do
setup do
@user = FactoryBot.create(:user)
@@ -50,13 +18,6 @@ class WikiPageTest < ActiveSupport::TestCase
@wiki_page = FactoryBot.create(:wiki_page, :title => "HOT POTATO", :other_names => "foo*bar baz")
end
should "not allow the is_locked attribute to be updated" do
@wiki_page.update(is_locked: true)
assert_equal(["Is locked and cannot be updated"], @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