add tests for note locks

fix naming scheme for mod actions
This commit is contained in:
Lily
2021-07-31 21:53:54 -03:00
parent 9fb8093052
commit 66b02b5037
2 changed files with 52 additions and 6 deletions

View File

@@ -1496,25 +1496,25 @@ class Post < ApplicationRecord
def create_mod_action_for_lock_change
if is_note_locked != is_note_locked_was
if is_note_locked
ModAction.log("locked notes for post ##{id}", :post_note_lock)
ModAction.log("locked notes for post ##{id}", :post_note_lock_create)
else
ModAction.log("unlocked notes for post ##{id}", :post_note_unlock)
ModAction.log("unlocked notes for post ##{id}", :post_note_lock_delete)
end
end
if is_rating_locked != is_rating_locked_was
if is_rating_locked
ModAction.log("locked rating for post ##{id}", :post_rating_lock)
ModAction.log("locked rating for post ##{id}", :post_rating_lock_create)
else
ModAction.log("unlocked rating for post ##{id}", :post_rating_unlock)
ModAction.log("unlocked rating for post ##{id}", :post_rating_lock_delete)
end
end
if is_status_locked != is_status_locked_was
if is_status_locked
ModAction.log("locked status for post ##{id}", :post_status_lock)
ModAction.log("locked status for post ##{id}", :post_status_lock_create)
else
ModAction.log("unlocked status for post ##{id}", :post_status_unlock)
ModAction.log("unlocked status for post ##{id}", :post_status_lock_delete)
end
end
end

View File

@@ -534,6 +534,52 @@ class PostTest < ActiveSupport::TestCase
assert_includes(approval.errors.full_messages, "Post is locked and cannot be approved")
end
end
context "Locking post fields" do
should "create ModAction entries" do
@post = create(:post)
assert_difference("ModAction.post_note_lock_create.count", 1) do
@post.is_note_locked = true
@post.save!
end
assert_difference("ModAction.post_note_lock_delete.count", 1) do
@post.is_note_locked = false
@post.save!
end
assert_difference("ModAction.post_rating_lock_create.count", 1) do
@post.is_rating_locked = true
@post.save!
end
assert_difference("ModAction.post_rating_lock_delete.count", 1) do
@post.is_rating_locked = false
@post.save!
end
assert_difference("ModAction.post_status_lock_create.count", 1) do
@post.is_status_locked = true
@post.save!
end
assert_difference("ModAction.post_status_lock_delete.count", 1) do
@post.is_status_locked = false
@post.save!
end
assert_difference("ModAction.post_status_lock_create.count", 1) do
assert_difference("ModAction.post_rating_lock_create.count", 1) do
assert_difference("ModAction.post_note_lock_create.count", 1) do
@post.is_status_locked = true
@post.is_rating_locked = true
@post.is_note_locked = true
@post.save!
end
end
end
end
end
end
context "Tagging:" do