forked from e621ng/e621ng
[Tests] Always use CurrentUser as helper
This commit is contained in:
parent
20ef412b68
commit
c68fdfce2b
@ -10,7 +10,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
@post = create(:post)
|
||||
@comment = create(:comment, post: @post)
|
||||
CurrentUser.scoped(@mod) do
|
||||
as(@mod) do
|
||||
@mod_comment = create(:comment, post: @post)
|
||||
end
|
||||
end
|
||||
|
@ -79,12 +79,12 @@ module Moderator
|
||||
setup do
|
||||
@users = (0..5).map { create(:user) }
|
||||
|
||||
CurrentUser.as( create(:user) ) do
|
||||
as(create(:user)) do
|
||||
@comment = create(:comment)
|
||||
end
|
||||
|
||||
@users.each do |user|
|
||||
CurrentUser.as(user) do
|
||||
as(user) do
|
||||
VoteManager.comment_vote!(user: user, comment: @comment, score: -1)
|
||||
end
|
||||
end
|
||||
|
@ -13,11 +13,11 @@ class NoteVersionsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
@user_2 = create(:user)
|
||||
|
||||
CurrentUser.scoped(@user_2, "1.2.3.4") do
|
||||
as(@user_2, "1.2.3.4") do
|
||||
@note.update(:body => "1 2")
|
||||
end
|
||||
|
||||
CurrentUser.scoped(@user, "1.2.3.4") do
|
||||
as(@user, "1.2.3.4") do
|
||||
@note.update(:body => "1 2 3")
|
||||
end
|
||||
end
|
||||
|
@ -14,11 +14,11 @@ class PoolVersionsControllerTest < ActionDispatch::IntegrationTest
|
||||
@user_2 = create(:user)
|
||||
@user_3 = create(:user)
|
||||
|
||||
CurrentUser.scoped(@user_2, "1.2.3.4") do
|
||||
as(@user_2, "1.2.3.4") do
|
||||
@pool.update(:post_ids => "1 2")
|
||||
end
|
||||
|
||||
CurrentUser.scoped(@user_3, "5.6.7.8") do
|
||||
as(@user_3, "5.6.7.8") do
|
||||
@pool.update(:post_ids => "1 2 3 4")
|
||||
end
|
||||
|
||||
|
@ -89,7 +89,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
|
||||
@post_2 = create(:post)
|
||||
@pool = create(:pool, post_ids: [@post.id])
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.4") do
|
||||
as(@user, "1.2.3.4") do
|
||||
@pool.update(post_ids: [@post.id, @post_2.id])
|
||||
end
|
||||
end
|
||||
|
@ -52,8 +52,8 @@ class ActiveSupport::TestCase
|
||||
RequestStore.clear!
|
||||
end
|
||||
|
||||
def as(user, &)
|
||||
CurrentUser.as(user, &)
|
||||
def as(user, ip_addr = "127.0.0.1", &)
|
||||
CurrentUser.scoped(user, ip_addr, &)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -80,7 +80,7 @@ class BanTest < ActiveSupport::TestCase
|
||||
should "initialize the expiration date" do
|
||||
user = create(:user)
|
||||
admin = create(:admin_user)
|
||||
CurrentUser.scoped(admin) do
|
||||
as(admin) do
|
||||
ban = create(:ban, user: user, banner: admin)
|
||||
assert_not_nil(ban.expires_at)
|
||||
end
|
||||
@ -90,7 +90,7 @@ class BanTest < ActiveSupport::TestCase
|
||||
user = create(:user)
|
||||
admin = create(:admin_user)
|
||||
assert(user.feedback.empty?)
|
||||
CurrentUser.scoped(admin) do
|
||||
as(admin) do
|
||||
create(:ban, user: user, banner: admin)
|
||||
end
|
||||
assert(!user.feedback.empty?)
|
||||
|
@ -93,7 +93,7 @@ class CommentTest < ActiveSupport::TestCase
|
||||
post = create(:post)
|
||||
c1 = create(:comment, post: post)
|
||||
|
||||
CurrentUser.scoped(user2, "127.0.0.1") do
|
||||
as(user2) do
|
||||
VoteManager.comment_vote!(user: user2, comment: c1, score: -1)
|
||||
c1.reload
|
||||
assert_not_equal(user2.id, c1.updater_id)
|
||||
@ -107,7 +107,7 @@ class CommentTest < ActiveSupport::TestCase
|
||||
c1 = create(:comment, post: post)
|
||||
c2 = create(:comment, post: post)
|
||||
|
||||
CurrentUser.scoped(user2, "127.0.0.1") do
|
||||
as(user2) do
|
||||
assert_nothing_raised { VoteManager.comment_vote!(user: user2, comment: c1, score: -1) }
|
||||
assert_equal(:need_unvote, VoteManager.comment_vote!(user: user2, comment: c1, score: -1))
|
||||
assert_equal(1, CommentVote.count)
|
||||
@ -150,7 +150,7 @@ class CommentTest < ActiveSupport::TestCase
|
||||
user2 = create(:user)
|
||||
post = create(:post)
|
||||
comment = create(:comment, post: post)
|
||||
CurrentUser.scoped(user2, "127.0.0.1") do
|
||||
as(user2) do
|
||||
VoteManager.comment_vote!(user: user2, comment: comment, score: 1)
|
||||
comment.reload
|
||||
assert_equal(1, comment.score)
|
||||
|
@ -22,7 +22,7 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
user1 = create(:user)
|
||||
user2 = create(:user)
|
||||
CurrentUser.user = user1
|
||||
CurrentUser.scoped(user2, nil) do
|
||||
as(user2, nil) do
|
||||
assert_equal(user2.id, CurrentUser.user.id)
|
||||
end
|
||||
assert_equal(user1.id, CurrentUser.user.id)
|
||||
@ -33,7 +33,7 @@ class CurrentUserTest < ActiveSupport::TestCase
|
||||
user2 = create(:user)
|
||||
CurrentUser.user = user1
|
||||
assert_raises(RuntimeError) do
|
||||
CurrentUser.scoped(user2, nil) do
|
||||
as(user2, nil) do
|
||||
assert_equal(user2.id, CurrentUser.user.id)
|
||||
raise "ERROR"
|
||||
end
|
||||
|
@ -7,7 +7,7 @@ class DmailFilterTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
def create_dmail(body, title)
|
||||
CurrentUser.scoped(@sender, "127.0.0.1") do
|
||||
as(@sender) do
|
||||
Dmail.create_split(:to_id => @receiver.id, :body => body, :title => title)
|
||||
end
|
||||
end
|
||||
|
@ -34,7 +34,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "be ignored when sender is a moderator" do
|
||||
CurrentUser.scoped(create(:moderator_user), "127.0.0.1") do
|
||||
as(create(:moderator_user)) do
|
||||
@dmail = create(:dmail, owner: @recipient, body: "banned word here", to: @recipient)
|
||||
end
|
||||
|
||||
@ -149,7 +149,7 @@ class DmailTest < ActiveSupport::TestCase
|
||||
assert(recipient.has_mail?)
|
||||
assert_equal(1, recipient.unread_dmail_count)
|
||||
|
||||
CurrentUser.scoped(recipient) do
|
||||
as(recipient) do
|
||||
dmail.mark_as_read!
|
||||
end
|
||||
|
||||
|
@ -11,7 +11,7 @@ class MaintenanceTest < ActiveSupport::TestCase
|
||||
banner = create(:admin_user)
|
||||
user = create(:user)
|
||||
|
||||
CurrentUser.as(banner) { create(:ban, user: user, banner: banner, duration: 1) }
|
||||
as(banner) { create(:ban, user: user, banner: banner, duration: 1) }
|
||||
|
||||
assert_equal(true, user.reload.is_banned)
|
||||
travel_to(2.days.from_now) { Maintenance.daily }
|
||||
|
@ -148,7 +148,7 @@ class NoteTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@vandal = create(:user)
|
||||
@note = create(:note, x: 5, y: 5)
|
||||
CurrentUser.scoped(@vandal, "127.0.0.1") do
|
||||
as(@vandal) do
|
||||
@note.update(:x => 10, :y => 10)
|
||||
end
|
||||
end
|
||||
|
@ -63,23 +63,23 @@ class PoolTest < ActiveSupport::TestCase
|
||||
@p1 = create(:post)
|
||||
@p2 = create(:post)
|
||||
@p3 = create(:post)
|
||||
CurrentUser.scoped(@user, "1.2.3.4") do
|
||||
as(@user, "1.2.3.4") do
|
||||
@pool.add!(@p1)
|
||||
@pool.reload
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.5") do
|
||||
as(@user, "1.2.3.5") do
|
||||
@pool.add!(@p2)
|
||||
@pool.reload
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.6") do
|
||||
as(@user, "1.2.3.6") do
|
||||
@pool.add!(@p3)
|
||||
@pool.reload
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.7") do
|
||||
as(@user, "1.2.3.7") do
|
||||
@pool.remove!(@p1)
|
||||
@pool.reload
|
||||
end
|
||||
CurrentUser.scoped(@user, "1.2.3.8") do
|
||||
as(@user, "1.2.3.8") do
|
||||
version = @pool.versions[1]
|
||||
@pool.revert_to!(version)
|
||||
@pool.reload
|
||||
@ -236,7 +236,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
assert_equal(1, @pool.versions.size)
|
||||
user2 = create(:user, created_at: 1.month.ago)
|
||||
|
||||
CurrentUser.scoped(user2, "127.0.0.2") do
|
||||
as(user2, "127.0.0.2") do
|
||||
@pool.post_ids = [@p1.id]
|
||||
@pool.save
|
||||
end
|
||||
@ -246,7 +246,7 @@ class PoolTest < ActiveSupport::TestCase
|
||||
assert_equal(user2.id, @pool.versions.last.updater_id)
|
||||
assert_equal("127.0.0.2", @pool.versions.last.updater_ip_addr.to_s)
|
||||
|
||||
CurrentUser.scoped(user2, "127.0.0.3") do
|
||||
as(user2, "127.0.0.3") do
|
||||
@pool.post_ids = [@p1.id, @p2.id]
|
||||
@pool.save
|
||||
end
|
||||
|
@ -348,7 +348,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
p1 = create(:post)
|
||||
c1 = create(:post, parent_id: p1.id)
|
||||
c1.delete!("test")
|
||||
CurrentUser.scoped(new_user, "127.0.0.1") do
|
||||
as(new_user) do
|
||||
c1.undelete!
|
||||
end
|
||||
p1.reload
|
||||
@ -900,7 +900,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "by a janitor" do
|
||||
should "lock/unlock the notes" do
|
||||
CurrentUser.scoped(@janitor) do
|
||||
as(@janitor) do
|
||||
@post.update(:tag_string => "locked:notes")
|
||||
assert_equal(true, @post.is_note_locked)
|
||||
|
||||
@ -921,7 +921,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "by a janitor" do
|
||||
should "lock/unlock the rating" do
|
||||
CurrentUser.scoped(@janitor) do
|
||||
as(@janitor) do
|
||||
@post.update(:tag_string => "locked:rating")
|
||||
assert_equal(true, @post.is_rating_locked)
|
||||
|
||||
@ -942,7 +942,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
context "by an admin" do
|
||||
should "lock/unlock the status" do
|
||||
CurrentUser.scoped(create(:admin_user)) do
|
||||
as(create(:admin_user)) do
|
||||
@post.update(:tag_string => "locked:status")
|
||||
assert_equal(true, @post.is_status_locked)
|
||||
|
||||
@ -1569,7 +1569,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "return posts for the fav:<name> metatag" do
|
||||
users = create_list(:user, 2)
|
||||
posts = users.map do |u|
|
||||
CurrentUser.scoped(u) do
|
||||
as(u) do
|
||||
post = create(:post, tag_string: "abc")
|
||||
FavoriteManager.add!(user: u, post: post, isolation: false)
|
||||
post
|
||||
@ -1808,7 +1808,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
should "return posts for a upvote:<user>, downvote:<user> metatag" do
|
||||
old_user = create(:mod_user, created_at: 5.days.ago)
|
||||
CurrentUser.scoped(old_user) do
|
||||
as(old_user) do
|
||||
upvoted = create(:post, tag_string: "abc")
|
||||
downvoted = create(:post, tag_string: "abc")
|
||||
VoteManager.vote!(user: CurrentUser.user, post: upvoted, score: 1)
|
||||
@ -1886,7 +1886,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
post2 = create(:post)
|
||||
post3 = create(:post)
|
||||
|
||||
CurrentUser.scoped(create(:privileged_user), "127.0.0.1") do
|
||||
as(create(:privileged_user)) do
|
||||
create(:comment, post: post1)
|
||||
create(:comment, post: post2, do_not_bump_post: true)
|
||||
create(:comment, post: post3)
|
||||
@ -1980,7 +1980,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "not allow duplicate votes" do
|
||||
user = create(:privileged_user)
|
||||
post = create(:post)
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
as(user) do
|
||||
assert_nothing_raised { VoteManager.vote!(user: user, post: post, score: 1) }
|
||||
# Need unvote is returned upon duplicates that are accounted for.
|
||||
assert_equal(:need_unvote, VoteManager.vote!(user: user, post: post, score: 1) )
|
||||
@ -1996,7 +1996,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
# We deliberately don't call post.reload until the end to verify that
|
||||
# post.unvote! returns the correct score even when not forcibly reloaded.
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
as(user) do
|
||||
VoteManager.vote!(post: post, user: user, score: 1)
|
||||
assert_equal(1, post.score)
|
||||
|
||||
|
@ -160,7 +160,7 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
context "with an associated forum topic" do
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
CurrentUser.scoped(@admin) do
|
||||
as(@admin) do
|
||||
@topic = create(:forum_topic, title: TagAliasRequest.topic_title("aaa", "bbb"))
|
||||
@post = create(:forum_post, topic_id: @topic.id, body: TagAliasRequest.command_string("aaa", "bbb"))
|
||||
@alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", forum_topic: @topic, forum_post: @post, status: "pending")
|
||||
|
@ -59,7 +59,7 @@ class UserNameChangeRequestTest < ActiveSupport::TestCase
|
||||
|
||||
should "not convert the desired name to lower case" do
|
||||
uncr = create(:user_name_change_request, user: @requester, original_name: "provence.", desired_name: "Provence")
|
||||
CurrentUser.scoped(@admin) { uncr.approve! }
|
||||
as(@admin) { uncr.approve! }
|
||||
|
||||
assert_equal("Provence", @requester.name)
|
||||
end
|
||||
|
@ -6,12 +6,12 @@ class UserRevertTest < ActiveSupport::TestCase
|
||||
@creator = create(:user)
|
||||
@user = create(:user)
|
||||
|
||||
CurrentUser.scoped(@creator) do
|
||||
as(@creator) do
|
||||
@parent = create(:post)
|
||||
@post = create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||
end
|
||||
|
||||
CurrentUser.scoped(@user) do
|
||||
as(@user) do
|
||||
@post.update(:tag_string => "bbb ccc xxx", :source => "", :rating => "e")
|
||||
end
|
||||
end
|
||||
@ -26,7 +26,7 @@ class UserRevertTest < ActiveSupport::TestCase
|
||||
|
||||
context "when processed" do
|
||||
setup do
|
||||
CurrentUser.as(@user) do
|
||||
as(@user) do
|
||||
subject.process
|
||||
end
|
||||
@post.reload
|
||||
|
@ -34,7 +34,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
should "not validate if the originating ip address is banned" do
|
||||
assert_raises ActiveRecord::RecordInvalid do
|
||||
CurrentUser.scoped(User.anonymous, "1.2.3.4") do
|
||||
as(User.anonymous, "1.2.3.4") do
|
||||
create(:ip_ban, ip_addr: '1.2.3.4')
|
||||
create(:user, last_ip_addr: '1.2.3.4')
|
||||
end
|
||||
@ -69,14 +69,14 @@ class UserTest < ActiveSupport::TestCase
|
||||
user2.update_column(:created_at, 1.year.ago)
|
||||
|
||||
Danbooru.config.comment_vote_limit.times do
|
||||
CurrentUser.as(user2) do
|
||||
as(user2) do
|
||||
comment = create(:comment)
|
||||
end
|
||||
VoteManager.comment_vote!(comment: comment, user: @user, score: -1)
|
||||
end
|
||||
|
||||
assert_equal(@user.can_comment_vote_with_reason, :REJ_LIMITED)
|
||||
CurrentUser.as(user2) do
|
||||
as(user2) do
|
||||
comment = create(:comment)
|
||||
end
|
||||
assert_raises ActiveRecord::RecordInvalid do
|
||||
@ -270,7 +270,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
CurrentUser.scoped(nil, "127.0.0.2") do
|
||||
as(nil, "127.0.0.2") do
|
||||
@user = build(:user)
|
||||
@user.save
|
||||
assert_equal(["Last ip addr was used recently for another account and cannot be reused for another day"], @user.errors.full_messages)
|
||||
@ -284,7 +284,7 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
CurrentUser.scoped(nil, "127.0.0.2") do
|
||||
as(nil, "127.0.0.2") do
|
||||
@user = build(:user)
|
||||
@user.email = "what@mine.xyz"
|
||||
@user.save
|
||||
|
@ -92,7 +92,7 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
|
||||
should "differentiate between updater and creator" do
|
||||
another_user = create(:user)
|
||||
CurrentUser.scoped(another_user, "127.0.0.1") do
|
||||
as(another_user) do
|
||||
@wiki_page.title = "yyy"
|
||||
@wiki_page.save
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user