models: remove belongs_to_creator macro.

The belongs_to_creator macro was used to initialize the creator_id field
to the CurrentUser. This made tests complicated because it meant you had
to create and set the current user every time you wanted to create an
object, when lead to the current user being set over and over again. It
also meant you had to constantly be aware of what the CurrentUser was in
many different contexts, which was often confusing. Setting creators
explicitly simplifies everything greatly.
This commit is contained in:
evazion
2020-01-18 15:52:01 -06:00
parent 77bf9ac7f3
commit b4ce2d83a6
86 changed files with 215 additions and 433 deletions

View File

@@ -8,6 +8,8 @@ class ApproverPrunerTest < ActiveSupport::TestCase
should "demote inactive approvers" do
assert_equal([@approver.id], ApproverPruner.inactive_approvers.map(&:id))
assert_nothing_raised { ApproverPruner.prune! }
assert_equal(false, @approver.reload.can_approve_posts)
end
should "not demote active approvers" do

View File

@@ -30,27 +30,27 @@ class ArtistTest < ActiveSupport::TestCase
end
should "parse inactive urls" do
@artist = Artist.create(name: "blah", url_string: "-http://monet.com")
@artist = create(:artist, name: "blah", url_string: "-http://monet.com")
assert_equal(["-http://monet.com"], @artist.urls.map(&:to_s))
refute(@artist.urls[0].is_active?)
end
should "not allow duplicate active+inactive urls" do
@artist = Artist.create(name: "blah", url_string: "-http://monet.com\nhttp://monet.com")
@artist = create(:artist, name: "blah", url_string: "-http://monet.com\nhttp://monet.com")
assert_equal(1, @artist.urls.count)
assert_equal(["-http://monet.com"], @artist.urls.map(&:to_s))
refute(@artist.urls[0].is_active?)
end
should "allow deactivating a url" do
@artist = Artist.create(name: "blah", url_string: "http://monet.com")
@artist = create(:artist, name: "blah", url_string: "http://monet.com")
@artist.update(url_string: "-http://monet.com")
assert_equal(1, @artist.urls.count)
refute(@artist.urls[0].is_active?)
end
should "allow activating a url" do
@artist = Artist.create(name: "blah", url_string: "-http://monet.com")
@artist = create(:artist, name: "blah", url_string: "-http://monet.com")
@artist.update(url_string: "http://monet.com")
assert_equal(1, @artist.urls.count)
assert(@artist.urls[0].is_active?)
@@ -69,7 +69,7 @@ class ArtistTest < ActiveSupport::TestCase
@post = FactoryBot.create(:post, :tag_string => "aaa")
@artist = FactoryBot.create(:artist, :name => "aaa")
@admin = FactoryBot.create(:admin_user)
CurrentUser.scoped(@admin) { @artist.ban! }
@artist.ban!(banner: @admin)
@post.reload
end
@@ -542,7 +542,7 @@ class ArtistTest < ActiveSupport::TestCase
context "#new_with_defaults" do
should "fetch the defaults from the given source" do
source = "https://i.pximg.net/img-original/img/2018/01/28/23/56/50/67014762_p0.jpg"
artist = Artist.new_with_defaults(source: source)
artist = Artist.new_with_defaults(source: source, creator: create(:user))
assert_equal("niceandcool", artist.name)
assert_equal("nice_and_cool", artist.other_names_string)

View File

@@ -37,7 +37,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "#update_notice" do
setup do
@forum_topic = FactoryBot.create(:forum_topic)
@forum_topic = create(:forum_topic, creator: @admin)
end
should "update the cache" do
@@ -70,7 +70,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
mass update aaa -> bbb
'
@bur = FactoryBot.create(:bulk_update_request, :script => @script)
@bur = create(:bulk_update_request, script: @script, user: @admin)
@bur.approve!(@admin)
assert_enqueued_jobs(3)
@@ -111,7 +111,7 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "that has an invalid alias" do
setup do
@alias1 = FactoryBot.create(:tag_alias)
@alias1 = create(:tag_alias, creator: @admin)
@req = FactoryBot.build(:bulk_update_request, :script => "create alias bbb -> aaa")
end
@@ -172,8 +172,8 @@ class BulkUpdateRequestTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@topic = FactoryBot.create(:forum_topic, :title => "[bulk] hoge")
@post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
@topic = create(:forum_topic, title: "[bulk] hoge", creator: @admin)
@post = create(:forum_post, topic: @topic, creator: @admin)
@req = FactoryBot.create(:bulk_update_request, :script => "create alias AAA -> BBB", :forum_topic_id => @topic.id, :forum_post_id => @post.id, :title => "[bulk] hoge")
end

View File

@@ -72,7 +72,7 @@ class CommentTest < ActiveSupport::TestCase
dmail = Dmail.last
assert_equal(<<-EOS.strip_heredoc, dmail.body)
@#{CurrentUser.name} mentioned you in a \"comment\":/posts/#{@comment.post_id}#comment-#{@comment.id} on post ##{@comment.post_id}:
@#{@comment.creator.name} mentioned you in a \"comment\":/posts/#{@comment.post_id}#comment-#{@comment.id} on post ##{@comment.post_id}:
[quote]
Hey @#{@user2.name} check this out!
@@ -195,7 +195,7 @@ class CommentTest < ActiveSupport::TestCase
should "not allow upvotes by the creator" do
user = FactoryBot.create(:user)
post = FactoryBot.create(:post)
c1 = FactoryBot.create(:comment, :post => post)
c1 = create(:comment, post: post, creator: CurrentUser.user)
exception = assert_raises(ActiveRecord::RecordInvalid) { c1.vote!("up") }
assert_equal("Validation failed: You cannot upvote your own comments", exception.message)

View File

@@ -2,15 +2,7 @@ require 'test_helper'
class FavoriteTest < ActiveSupport::TestCase
def setup
@user = create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@fav_group = create(:favorite_group, creator: @user, name: "blah")
end
def teardown
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@fav_group = create(:favorite_group)
end
context "searching by post id" do

View File

@@ -53,7 +53,7 @@ class ForumPostTest < ActiveSupport::TestCase
context "outside a quote block" do
setup do
@user2 = FactoryBot.create(:user)
@post = FactoryBot.build(:forum_post, :topic_id => @topic.id, :body => "Hey @#{@user2.name} check this out!")
@post = build(:forum_post, creator: @user, topic: @topic, body: "Hey @#{@user2.name} check this out!")
end
should "create a dmail" do
@@ -63,7 +63,7 @@ class ForumPostTest < ActiveSupport::TestCase
dmail = Dmail.last
assert_equal(<<-EOS.strip_heredoc, dmail.body)
@#{CurrentUser.name} mentioned you in topic ##{@topic.id} (\"#{@topic.title}\":[/forum_topics/#{@topic.id}?page=1]):
@#{@user.name} mentioned you in topic ##{@topic.id} (\"#{@topic.title}\":[/forum_topics/#{@topic.id}?page=1]):
[quote]
Hey @#{@user2.name} check this out!
@@ -169,7 +169,7 @@ class ForumPostTest < ActiveSupport::TestCase
end
should "initialize its creator" do
post = FactoryBot.create(:forum_post, :topic_id => @topic.id)
post = create(:forum_post, topic: @topic, creator: @user)
assert_equal(@user.id, post.creator_id)
end

View File

@@ -7,7 +7,7 @@ class ForumTopicTest < ActiveSupport::TestCase
@user = FactoryBot.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@topic = FactoryBot.create(:forum_topic, :title => "xxx")
@topic = create(:forum_topic, title: "xxx", creator: @user)
end
teardown do
@@ -113,7 +113,7 @@ class ForumTopicTest < ActiveSupport::TestCase
context "#merge" do
setup do
@topic2 = FactoryBot.create(:forum_topic, :title => "yyy")
@topic2 = create(:forum_topic, title: "yyy", creator: @user)
FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
FactoryBot.create(:forum_post, :topic_id => @topic2.id, :body => "xxx")
end
@@ -127,7 +127,7 @@ class ForumTopicTest < ActiveSupport::TestCase
context "constructed with nested attributes for its original post" do
should "create a matching forum post" do
assert_difference(["ForumTopic.count", "ForumPost.count"], 1) do
@topic = FactoryBot.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
@topic = create(:forum_topic, title: "abc", original_post_attributes: { body: "abc", creator: @user })
end
end
end

View File

@@ -1,16 +1,6 @@
require 'test_helper'
class IpBanTest < ActiveSupport::TestCase
setup do
CurrentUser.user = FactoryBot.create(:mod_user)
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "be able to ban a user" do
ip_ban = create(:ip_ban, ip_addr: "1.2.3.4")

View File

@@ -8,7 +8,7 @@ module Moderator
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
@comment = FactoryBot.create(:comment)
@comment = create(:comment, creator: @user, creator_ip_addr: "127.0.0.1")
PoolArchive.stubs(:enabled?).returns(false)
PostArchive.stubs(:enabled?).returns(false)
@user.reload

View File

@@ -3,14 +3,7 @@ require 'test_helper'
class PostAppealTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = FactoryBot.create(:user)
CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@alice = create(:user)
end
context "a user" do
@@ -19,37 +12,27 @@ class PostAppealTest < ActiveSupport::TestCase
end
should "not be able to appeal a post more than twice" do
assert_difference("PostAppeal.count", 1) do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
end
assert_difference("PostAppeal.count", 0) do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
end
@post_appeal = create(:post_appeal, post: @post, creator: @alice)
@post_appeal = build(:post_appeal, post: @post, creator: @alice)
assert_equal(false, @post_appeal.valid?)
assert_includes(@post_appeal.errors.full_messages, "You have already appealed this post")
end
should "not be able to appeal more than 1 post in 24 hours" do
@post_appeal = PostAppeal.new(:post => @post, :reason => "aaa")
@post_appeal.expects(:appeal_count_for_creator).returns(1)
assert_difference("PostAppeal.count", 0) do
@post_appeal.save
end
@post_appeal = create(:post_appeal, post: @post, creator: @alice)
@post_appeal = build(:post_appeal, post: create(:post, is_deleted: true), creator: @alice)
assert_equal(false, @post_appeal.valid?)
assert_equal(["You can appeal at most 1 post a day"], @post_appeal.errors.full_messages)
end
should "not be able to appeal an active post" do
@post.update_attribute(:is_deleted, false)
assert_difference("PostAppeal.count", 0) do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
end
assert_equal(["Post is active"], @post_appeal.errors.full_messages)
end
@post_appeal = build(:post_appeal, post: @post, creator: @alice)
should "initialize its creator" do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
assert_equal(@alice.id, @post_appeal.creator_id)
assert_equal(false, @post_appeal.valid?)
assert_equal(["Post is active"], @post_appeal.errors.full_messages)
end
end
end

View File

@@ -35,8 +35,8 @@ class PostApprovalTest < ActiveSupport::TestCase
context "that is then flagged" do
setup do
@user2 = FactoryBot.create(:user)
@user3 = FactoryBot.create(:user)
@user2 = create(:user, created_at: 2.weeks.ago)
@user3 = create(:user, created_at: 2.weeks.ago)
@approver2 = FactoryBot.create(:user)
@approver2.can_approve_posts = true
@approver2.save

View File

@@ -2,22 +2,10 @@ require 'test_helper'
class PostEventTest < ActiveSupport::TestCase
def setup
super
travel_to(2.weeks.ago) do
CurrentUser.user = FactoryBot.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
end
@post = FactoryBot.create(:post)
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
end
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@user = create(:user, created_at: 2.weeks.ago)
@post = create(:post)
@post_flag = create(:post_flag, creator: @user, post: @post)
@post_appeal = create(:post_appeal, creator: @user, post: @post)
end
context "PostEvent.find_for_post" do

View File

@@ -12,54 +12,37 @@ class PostFlagTest < ActiveSupport::TestCase
end
context "a basic user" do
setup do
travel_to(2.weeks.ago) do
@bob = create(:user)
end
end
should "not be able to flag more than 1 post in 24 hours" do
@post_flag = PostFlag.new(post: @post, reason: "aaa", is_resolved: false)
@bob = create(:user, created_at: 2.weeks.ago)
@post_flag = build(:post_flag, creator: @bob)
@post_flag.expects(:flag_count_for_creator).returns(1)
assert_difference("PostFlag.count", 0) do
as(@bob) { @post_flag.save }
end
assert_equal(false, @post_flag.valid?)
assert_equal(["You can flag 1 post a day"], @post_flag.errors.full_messages)
end
end
context "a gold user" do
setup do
travel_to(2.weeks.ago) do
@bob = create(:gold_user)
end
@bob = create(:gold_user, created_at: 1.month.ago)
end
should "not be able to flag a post more than twice" do
assert_difference(-> { PostFlag.count }, 1) do
as(@bob) do
@post_flag = PostFlag.create(post: @post, reason: "aaa", is_resolved: false)
end
end
assert_difference(-> { PostFlag.count }, 0) do
as(@bob) do
@post_flag = PostFlag.create(post: @post, reason: "aaa", is_resolved: false)
end
end
@post_flag = create(:post_flag, post: @post, creator: @bob)
@post_flag = build(:post_flag, post: @post, creator: @bob)
assert_equal(false, @post_flag.valid?)
assert_equal(["have already flagged this post"], @post_flag.errors[:creator_id])
end
should "not be able to flag more than 10 posts in 24 hours" do
as(@bob) do
@post_flag = PostFlag.new(post: @post, reason: "aaa", is_resolved: false)
@post_flag.expects(:flag_count_for_creator).returns(10)
@post_flag = build(:post_flag, post: @post, creator: @bob)
@post_flag.expects(:flag_count_for_creator).returns(10)
assert_difference(-> { PostFlag.count }, 0) do
@post_flag.save
end
assert_difference(-> { PostFlag.count }, 0) do
@post_flag.save
end
assert_equal(["You can flag 10 posts a day"], @post_flag.errors.full_messages)
end
@@ -68,11 +51,8 @@ class PostFlagTest < ActiveSupport::TestCase
@post.update(is_deleted: true)
end
assert_difference(-> { PostFlag.count }, 0) do
as(@bob) do
@post_flag = PostFlag.create(post: @post, reason: "aaa", is_resolved: false)
end
end
@post_flag = build(:post_flag, post: @post, creator: @bob)
@post_flag.save
assert_equal(["Post is deleted"], @post_flag.errors.full_messages)
end
@@ -80,9 +60,7 @@ class PostFlagTest < ActiveSupport::TestCase
as(@alice) do
@post.update(is_pending: true)
end
as(@bob) do
@flag = @post.flags.create(reason: "test")
end
@flag = @post.flags.create(reason: "test", creator: @bob)
assert_equal(["Post is pending and cannot be flagged"], @flag.errors.full_messages)
end
@@ -94,49 +72,35 @@ class PostFlagTest < ActiveSupport::TestCase
@users = FactoryBot.create_list(:user, 2)
end
as(@users.first) do
@flag1 = PostFlag.create(post: @post, reason: "something")
end
@flag1 = create(:post_flag, post: @post, reason: "something", creator: @users.first)
as(@mod) do
@post.approve!
end
travel_to(PostFlag::COOLDOWN_PERIOD.from_now - 1.minute) do
as(@users.second) do
@flag2 = PostFlag.create(post: @post, reason: "something")
end
@flag2 = build(:post_flag, post: @post, reason: "something", creator: @users.second)
assert_equal(false, @flag2.valid?)
assert_match(/cannot be flagged more than once/, @flag2.errors[:post].join)
end
travel_to(PostFlag::COOLDOWN_PERIOD.from_now + 1.minute) do
as(@users.second) do
@flag3 = PostFlag.create(post: @post, reason: "something")
end
@flag3 = create(:post_flag, post: @post, reason: "something", creator: @users.second)
assert(@flag3.errors.empty?)
end
end
should "initialize its creator" do
@post_flag = as(@alice) do
PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
end
@post_flag = create(:post_flag, creator: @alice)
assert_equal(@alice.id, @post_flag.creator_id)
end
end
context "a moderator user" do
setup do
travel_to(2.weeks.ago) do
@dave = create(:moderator_user)
end
end
should "not be able to view flags on their own uploads" do
@dave = create(:moderator_user, created_at: 1.month.ago)
@modpost = create(:post, :tag_string => "mmm", :uploader => @dave)
as(@alice) do
@flag1 = PostFlag.create(:post => @modpost, :reason => "aaa", :is_resolved => false)
end
@flag1 = create(:post_flag, post: @modpost, creator: @alice)
assert_equal(false, @dave.can_view_flagger_on_post?(@flag1))

View File

@@ -2,34 +2,17 @@ require 'test_helper'
class PostPrunerTest < ActiveSupport::TestCase
def setup
super
@user = FactoryBot.create(:admin_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
travel_to(2.weeks.ago) do
@flagger = FactoryBot.create(:gold_user)
end
@old_post = FactoryBot.create(:post, :created_at => 5.days.ago, :is_pending => true)
@unresolved_flagged_post = FactoryBot.create(:post, :is_flagged => true)
@resolved_flagged_post = FactoryBot.create(:post, :is_flagged => true)
CurrentUser.scoped(@flagger, "127.0.0.2") do
@unresolved_post_flag = FactoryBot.create(:post_flag, :created_at => 5.days.ago, :is_resolved => false, :post_id => @unresolved_flagged_post.id)
@resolved_post_flag = FactoryBot.create(:post_flag, :created_at => 5.days.ago, :is_resolved => true, :post_id => @resolved_flagged_post.id)
end
@flagger = create(:gold_user, created_at: 2.weeks.ago)
@unresolved_post_flag = create(:post_flag, creator: @flagger, created_at: 5.days.ago, is_resolved: false, post: @unresolved_flagged_post)
@resolved_post_flag = create(:post_flag, creator: @flagger, created_at: 5.days.ago, is_resolved: true, post: @resolved_flagged_post)
PostPruner.new.prune!
end
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "prune old pending posts" do
@old_post.reload
assert(@old_post.is_deleted?)

View File

@@ -2030,7 +2030,7 @@ class PostTest < ActiveSupport::TestCase
should "return posts for the commenter:<name> metatag" do
users = FactoryBot.create_list(:user, 2, created_at: 2.weeks.ago)
posts = FactoryBot.create_list(:post, 2)
comms = users.zip(posts).map { |u, p| as(u) { FactoryBot.create(:comment, post: p) } }
comms = users.zip(posts).map { |u, p| as(u) { FactoryBot.create(:comment, creator: u, post: p) } }
assert_tag_match([posts[0]], "commenter:#{users[0].name}")
assert_tag_match([posts[1]], "commenter:#{users[1].name}")
@@ -2038,8 +2038,8 @@ class PostTest < ActiveSupport::TestCase
should "return posts for the commenter:<any|none> metatag" do
posts = FactoryBot.create_list(:post, 2)
FactoryBot.create(:comment, post: posts[0], is_deleted: false)
FactoryBot.create(:comment, post: posts[1], is_deleted: true)
create(:comment, creator: create(:user, created_at: 2.weeks.ago), post: posts[0], is_deleted: false)
create(:comment, creator: create(:user, created_at: 2.weeks.ago), post: posts[1], is_deleted: true)
assert_tag_match([posts[0]], "commenter:any")
assert_tag_match([posts[1]], "commenter:none")
@@ -2143,7 +2143,7 @@ class PostTest < ActiveSupport::TestCase
pending = FactoryBot.create(:post, is_pending: true)
disapproved = FactoryBot.create(:post, is_pending: true)
FactoryBot.create(:post_flag, post: flagged)
create(:post_flag, post: flagged, creator: create(:user, created_at: 2.weeks.ago))
FactoryBot.create(:post_disapproval, post: disapproved, reason: "disinterest")
assert_tag_match([pending, flagged], "status:unmoderated")
@@ -2352,9 +2352,10 @@ class PostTest < ActiveSupport::TestCase
tag_string: tags[n - 1]
)
FactoryBot.create(:artist_commentary, post: p)
FactoryBot.create(:comment, post: p, do_not_bump_post: false)
FactoryBot.create(:note, post: p)
u = create(:user, created_at: 2.weeks.ago)
create(:artist_commentary, post: p)
create(:comment, post: p, creator: u, do_not_bump_post: false)
create(:note, post: p, creator: u)
p
end
@@ -2406,11 +2407,12 @@ class PostTest < ActiveSupport::TestCase
post1 = FactoryBot.create(:post)
post2 = FactoryBot.create(:post)
post3 = FactoryBot.create(:post)
user = create(:gold_user)
CurrentUser.scoped(FactoryBot.create(:gold_user), "127.0.0.1") do
comment1 = FactoryBot.create(:comment, :post => post1)
comment2 = FactoryBot.create(:comment, :post => post2, :do_not_bump_post => true)
comment3 = FactoryBot.create(:comment, :post => post3)
as(user) do
comment1 = create(:comment, creator: user, post: post1)
comment2 = create(:comment, creator: user, post: post2, do_not_bump_post: true)
comment3 = create(:comment, creator: user, post: post3)
end
assert_tag_match([post3, post1, post2], "order:comment_bumped")
@@ -2749,11 +2751,10 @@ class PostTest < ActiveSupport::TestCase
@src = FactoryBot.create(:post, image_width: 100, image_height: 100, tag_string: "translated partially_translated", has_embedded_notes: true)
@dst = FactoryBot.create(:post, image_width: 200, image_height: 200, tag_string: "translation_request")
@src.notes.create(x: 10, y: 10, width: 10, height: 10, body: "test")
@src.notes.create(x: 10, y: 10, width: 10, height: 10, body: "deleted", is_active: false)
@src.reload
create(:note, post: @src, x: 10, y: 10, width: 10, height: 10, body: "test")
create(:note, post: @src, x: 10, y: 10, width: 10, height: 10, body: "deleted", is_active: false)
@src.copy_notes_to(@dst)
@src.reload.copy_notes_to(@dst)
end
should "copy notes and tags" do

View File

@@ -108,7 +108,7 @@ class TagAliasTest < ActiveSupport::TestCase
end
should "populate the creator information" do
ta = FactoryBot.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
ta = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb", creator: CurrentUser.user)
assert_equal(CurrentUser.user.id, ta.creator_id)
end

View File

@@ -6,7 +6,6 @@ class TagImplicationTest < ActiveSupport::TestCase
user = FactoryBot.create(:admin_user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
@user = FactoryBot.create(:user)
end
teardown do
@@ -104,7 +103,7 @@ class TagImplicationTest < ActiveSupport::TestCase
end
should "populate the creator information" do
ti = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti = create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb", creator: CurrentUser.user)
assert_equal(CurrentUser.user.id, ti.creator_id)
end
@@ -263,7 +262,6 @@ class TagImplicationTest < ActiveSupport::TestCase
context "with an associated forum topic" do
setup do
@admin = FactoryBot.create(:admin_user)
@topic = FactoryBot.create(:forum_topic, :title => "Tag implication: aaa -> bbb")
@post = FactoryBot.create(:forum_post, topic_id: @topic.id, :body => TagImplicationRequest.command_string("aaa", "bbb"))
@implication = FactoryBot.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :forum_topic => @topic, :forum_post => @post, :status => "pending")

View File

@@ -2,37 +2,25 @@ require 'test_helper'
class UserFeedbackTest < ActiveSupport::TestCase
context "A user's feedback" do
setup do
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "create a dmail" do
user = FactoryBot.create(:user)
gold = FactoryBot.create(:gold_user)
member = FactoryBot.create(:user)
dmail = <<~EOS.chomp
@#{gold.name} created a "positive record":/user_feedbacks?search[user_id]=#{user.id} for your account:
good job!
EOS
CurrentUser.user = gold
assert_difference("Dmail.count", 1) do
FactoryBot.create(:user_feedback, :user => user, :body => "good job!")
create(:user_feedback, creator: gold, user: user, body: "good job!")
assert_equal(dmail, user.dmails.last.body)
end
end
should "not validate if the creator is the user" do
gold_user = FactoryBot.create(:gold_user)
CurrentUser.user = gold_user
feedback = FactoryBot.build(:user_feedback, :user => gold_user)
user = FactoryBot.create(:gold_user)
feedback = build(:user_feedback, creator: user, user: user)
feedback.save
assert_equal(["You cannot submit feedback for yourself"], feedback.errors.full_messages)
end
@@ -42,12 +30,10 @@ class UserFeedbackTest < ActiveSupport::TestCase
gold = FactoryBot.create(:gold_user)
member = FactoryBot.create(:user)
CurrentUser.user = gold
feedback = FactoryBot.create(:user_feedback, :user => user)
feedback = FactoryBot.create(:user_feedback, creator: gold, user: user)
assert(feedback.errors.empty?)
CurrentUser.user = member
feedback = FactoryBot.build(:user_feedback, :user => user)
feedback = build(:user_feedback, creator: member, user: user)
feedback.save
assert_equal(["You must be gold"], feedback.errors.full_messages)
end

View File

@@ -88,9 +88,7 @@ class UserTest < ActiveSupport::TestCase
@user.update_column(:created_at, 1.year.ago)
assert(@user.can_comment?)
assert(!@user.is_comment_limited?)
Danbooru.config.member_comment_limit.times do
FactoryBot.create(:comment)
end
create_list(:comment, Danbooru.config.member_comment_limit, creator: @user)
assert(@user.is_comment_limited?)
end