2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-08-01 12:20:39 -04:00
|
|
|
require "test_helper"
|
2016-09-28 07:56:12 -04:00
|
|
|
|
|
|
|
class UserRevertTest < ActiveSupport::TestCase
|
|
|
|
context "Reverting a user's changes" do
|
|
|
|
setup do
|
2018-04-02 13:51:26 -04:00
|
|
|
@creator = create(:user)
|
|
|
|
@user = create(:user)
|
2016-09-28 07:56:12 -04:00
|
|
|
|
2022-11-26 09:20:15 -05:00
|
|
|
as(@creator) do
|
2018-04-02 13:51:26 -04:00
|
|
|
@parent = create(:post)
|
2023-08-01 12:20:39 -04:00
|
|
|
@post = create(:post, tag_string: "aaa bbb ccc", rating: "q", source: "xyz")
|
2016-09-28 07:56:12 -04:00
|
|
|
end
|
|
|
|
|
2022-11-26 09:20:15 -05:00
|
|
|
as(@user) do
|
2023-08-01 12:20:39 -04:00
|
|
|
@post.update(tag_string: "bbb ccc xxx", source: "", rating: "e")
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2016-09-28 07:56:12 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { UserRevert.new(@user.id) }
|
|
|
|
|
|
|
|
should "have the correct data" do
|
|
|
|
assert_equal("bbb ccc xxx", @post.tag_string)
|
|
|
|
assert_equal("", @post.source)
|
|
|
|
assert_equal("e", @post.rating)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when processed" do
|
2023-08-01 12:20:39 -04:00
|
|
|
should "revert the user's changes" do
|
2022-11-26 09:20:15 -05:00
|
|
|
as(@user) do
|
2018-04-02 13:51:26 -04:00
|
|
|
subject.process
|
|
|
|
end
|
2016-09-28 07:56:12 -04:00
|
|
|
@post.reload
|
|
|
|
|
|
|
|
assert_equal("aaa bbb ccc", @post.tag_string)
|
|
|
|
assert_equal("xyz", @post.source)
|
|
|
|
assert_equal("q", @post.rating)
|
|
|
|
end
|
|
|
|
|
2023-08-01 12:20:39 -04:00
|
|
|
context "when the user has an upload" do
|
|
|
|
setup do
|
|
|
|
as(@user) { create(:post, uploader: @user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
should "not raise" do
|
|
|
|
as(@user) do
|
|
|
|
assert_nothing_raised { subject.process }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-28 07:56:12 -04:00
|
|
|
end
|
|
|
|
end
|