notes: drop unused undo_changes_by_user method.
This commit is contained in:
@@ -137,20 +137,6 @@ class Note < ApplicationRecord
|
|||||||
new_note.save
|
new_note.save
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.undo_changes_by_user(vandal_id)
|
|
||||||
transaction do
|
|
||||||
note_ids = NoteVersion.where(:updater_id => vandal_id).select("note_id").distinct.map(&:note_id)
|
|
||||||
NoteVersion.where(["updater_id = ?", vandal_id]).delete_all
|
|
||||||
note_ids.each do |note_id|
|
|
||||||
note = Note.find(note_id)
|
|
||||||
most_recent = note.versions.last
|
|
||||||
if most_recent
|
|
||||||
note.revert_to!(most_recent)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available_includes
|
def self.available_includes
|
||||||
[:post]
|
[:post]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -163,32 +163,6 @@ class NoteTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when notes have been vandalized by one user" do
|
|
||||||
setup do
|
|
||||||
@vandal = FactoryBot.create(:user)
|
|
||||||
@note = FactoryBot.create(:note, :x => 5, :y => 5)
|
|
||||||
CurrentUser.scoped(@vandal, "127.0.0.1") do
|
|
||||||
@note.update(x: 10, y: 10)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "the act of undoing all changes by that user" do
|
|
||||||
should "revert any affected notes" do
|
|
||||||
assert_equal(2, NoteVersion.count)
|
|
||||||
assert_equal([1, 2], @note.versions.map(&:version))
|
|
||||||
assert_equal([@user.id, @vandal.id], @note.versions.map(&:updater_id))
|
|
||||||
travel(1.day) do
|
|
||||||
Note.undo_changes_by_user(@vandal.id)
|
|
||||||
end
|
|
||||||
@note.reload
|
|
||||||
assert_equal([1, 3], @note.versions.map(&:version))
|
|
||||||
assert_equal([@user.id, @user.id], @note.versions.map(&:updater_id))
|
|
||||||
assert_equal(5, @note.x)
|
|
||||||
assert_equal(5, @note.y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "searching for a note" do
|
context "searching for a note" do
|
||||||
setup do
|
setup do
|
||||||
@note = FactoryBot.create(:note, :body => "aaa")
|
@note = FactoryBot.create(:note, :body => "aaa")
|
||||||
|
|||||||
Reference in New Issue
Block a user