dmails: replace hard deletions with soft deletions.

Turn deletions into soft deletions (set the is_deleted flag) instead of
hard deletions (remove from database). The is_deleted flag actually
already existed, but it was never used before.
This commit is contained in:
evazion
2020-01-30 21:49:55 -06:00
parent 5df8d08aae
commit f8db577c25
7 changed files with 26 additions and 24 deletions

View File

@@ -94,18 +94,19 @@ class DmailsControllerTest < ActionDispatch::IntegrationTest
end
end
context "destroy action" do
context "update action" do
should "allow deletion if the dmail is owned by the current user" do
assert_difference("Dmail.count", -1) do
delete_auth dmail_path(@dmail), @user
assert_redirected_to dmails_path
end
put_auth dmail_path(@dmail), @user, params: { dmail: { is_deleted: true } }
assert_redirected_to dmail_path(@dmail)
assert_equal(true, @dmail.reload.is_deleted)
end
should "not allow deletion if the dmail is not owned by the current user" do
assert_difference("Dmail.count", 0) do
delete_auth dmail_path(@dmail), @unrelated_user
end
put_auth dmail_path(@dmail), @unrelated_user, params: { dmail: { is_deleted: true } }
assert_response 403
assert_equal(false, @dmail.reload.is_deleted)
end
end
end