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:
@@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:artist) do
|
||||
creator
|
||||
name { rand(1_000_000).to_s }
|
||||
is_active { true }
|
||||
association :creator, factory: :user
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:bulk_update_request) do |f|
|
||||
user
|
||||
title {"xxx"}
|
||||
script {"create alias aaa -> bbb"}
|
||||
skip_secondary_validations {true}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
FactoryBot.define do
|
||||
factory(:comment) do |f|
|
||||
creator
|
||||
post
|
||||
creator_ip_addr { FFaker::Internet.ip_v4_address }
|
||||
body {FFaker::Lorem.sentences.join(" ")}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory :favorite_group do
|
||||
creator
|
||||
name { FFaker::Lorem.word }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:forum_post) do
|
||||
creator
|
||||
body {FFaker::Lorem.sentences.join(" ")}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:forum_topic) do
|
||||
creator
|
||||
title {FFaker::Lorem.words.join(" ")}
|
||||
is_sticky {false}
|
||||
is_locked {false}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:news_update) do
|
||||
creator
|
||||
message {"xxx"}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:note) do
|
||||
creator
|
||||
post
|
||||
x { 1 }
|
||||
y { 1 }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:pool) do
|
||||
creator
|
||||
name {"pool_" + rand(100..1000099).to_s}
|
||||
association :creator, :factory => :user
|
||||
description {FFaker::Lorem.sentences.join(" ")}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:post_appeal) do
|
||||
creator
|
||||
post
|
||||
reason {"xxx"}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory(:post_flag) do
|
||||
creator
|
||||
post
|
||||
reason {"xxx"}
|
||||
is_resolved {false}
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory :tag_alias do
|
||||
creator
|
||||
antecedent_name {"aaa"}
|
||||
consequent_name {"bbb"}
|
||||
status {"active"}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory :tag_implication do
|
||||
creator
|
||||
antecedent_name {"aaa"}
|
||||
consequent_name {"bbb"}
|
||||
status {"active"}
|
||||
|
||||
@@ -11,6 +11,7 @@ FactoryBot.define do
|
||||
last_logged_in_at {Time.now}
|
||||
favorite_count {0}
|
||||
bit_prefs {0}
|
||||
last_forum_read_at {nil}
|
||||
|
||||
factory(:banned_user) do
|
||||
transient { ban_duration {3} }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:user_feedback) do
|
||||
creator factory: :builder_user
|
||||
user
|
||||
category { "positive" }
|
||||
body { FFaker::Lorem.words.join(" ") }
|
||||
|
||||
@@ -5,6 +5,7 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = create(:user)
|
||||
@admin = create(:admin_user)
|
||||
@bulk_update_request = create(:bulk_update_request, user: @user)
|
||||
end
|
||||
|
||||
context "#new" do
|
||||
@@ -23,12 +24,6 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "#update" do
|
||||
setup do
|
||||
as_user do
|
||||
@bulk_update_request = create(:bulk_update_request)
|
||||
end
|
||||
end
|
||||
|
||||
should "still handle enabled secondary validations correctly" do
|
||||
put_auth bulk_update_request_path(@bulk_update_request.id), @user, params: {bulk_update_request: {script: "create alias zzz -> 222", skip_secondary_validations: "0"}}
|
||||
@bulk_update_request.reload
|
||||
@@ -43,12 +38,6 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "#index" do
|
||||
setup do
|
||||
as_user do
|
||||
@bulk_update_request = create(:bulk_update_request)
|
||||
end
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get bulk_update_requests_path
|
||||
assert_response :success
|
||||
@@ -56,12 +45,6 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "#destroy" do
|
||||
setup do
|
||||
as_user do
|
||||
@bulk_update_request = create(:bulk_update_request)
|
||||
end
|
||||
end
|
||||
|
||||
context "for the creator" do
|
||||
should "succeed" do
|
||||
delete_auth bulk_update_request_path(@bulk_update_request), @user
|
||||
@@ -92,12 +75,6 @@ class BulkUpdateRequestsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "#approve" do
|
||||
setup do
|
||||
as_user do
|
||||
@bulk_update_request = create(:bulk_update_request)
|
||||
end
|
||||
end
|
||||
|
||||
context "for a member" do
|
||||
should "fail" do
|
||||
post_auth approve_bulk_update_request_path(@bulk_update_request), @user
|
||||
|
||||
@@ -188,7 +188,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "create action" do
|
||||
should "create a comment" do
|
||||
assert_difference("Comment.count", 1) do
|
||||
post_auth comments_path, @user, params: {comment: FactoryBot.attributes_for(:comment, post_id: @post.id)}
|
||||
post_auth comments_path, @user, params: { comment: { post_id: @post.id, body: "blah" } }
|
||||
end
|
||||
comment = Comment.last
|
||||
assert_redirected_to post_path(comment.post)
|
||||
@@ -196,7 +196,7 @@ class CommentsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
should "not allow commenting on nonexistent posts" do
|
||||
assert_difference("Comment.count", 0) do
|
||||
post_auth comments_path, @user, params: {comment: FactoryBot.attributes_for(:comment, post_id: -1)}
|
||||
post_auth comments_path, @user, params: { comment: { post_id: -1, body: "blah" } }
|
||||
end
|
||||
assert_redirected_to comments_path
|
||||
end
|
||||
|
||||
@@ -4,9 +4,7 @@ class FavoriteGroupsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The favorite groups controller" do
|
||||
setup do
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
@favgroup = create(:favorite_group)
|
||||
end
|
||||
@favgroup = create(:favorite_group, creator: @user)
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
|
||||
@@ -6,10 +6,8 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
@user = create(:user)
|
||||
@other_user = create(:user)
|
||||
@mod = create(:moderator_user)
|
||||
as_user do
|
||||
@forum_topic = create(:forum_topic, :title => "my forum topic")
|
||||
@forum_post = create(:forum_post, :topic_id => @forum_topic.id, :body => "alias xxx -> yyy")
|
||||
end
|
||||
@forum_topic = as(@user) { create(:forum_topic, title: "my forum topic", creator: @user) }
|
||||
@forum_post = as(@user) { create(:forum_post, creator: @user, topic: @forum_topic, body: "alias xxx -> yyy") }
|
||||
end
|
||||
|
||||
context "with votes" do
|
||||
@@ -78,10 +76,8 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "with private topics" do
|
||||
setup do
|
||||
as(@mod) do
|
||||
@mod_topic = create(:mod_up_forum_topic)
|
||||
@mod_posts = 2.times.map do
|
||||
create(:forum_post, :topic_id => @mod_topic.id)
|
||||
end
|
||||
@mod_topic = create(:mod_up_forum_topic, creator: @mod)
|
||||
@mod_posts = create_list(:forum_post, 2, topic: @mod_topic, creator: @mod)
|
||||
end
|
||||
@mod_post_ids = ([@forum_post] + @mod_posts).map(&:id).reverse
|
||||
end
|
||||
|
||||
@@ -7,8 +7,9 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
@other_user = create(:user)
|
||||
@mod = create(:moderator_user)
|
||||
|
||||
as_user do
|
||||
@forum_topic = create(:forum_topic, :title => "my forum topic", :original_post_attributes => {:body => "xxx"})
|
||||
as(@user) do
|
||||
@forum_topic = create(:forum_topic, creator: @user, title: "my forum topic")
|
||||
@forum_post = create(:forum_post, creator: @user, topic: @forum_topic, body: "xxx")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,9 +29,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
@gold_user = create(:gold_user)
|
||||
|
||||
# An open topic should bump...
|
||||
as(@gold_user) do
|
||||
@open_topic = create(:forum_topic)
|
||||
end
|
||||
@open_topic = as(@gold_user) { create(:forum_topic, creator: @gold_user) }
|
||||
@gold_user.reload
|
||||
as(@gold_user) do
|
||||
assert(@gold_user.has_forum_been_updated?)
|
||||
@@ -47,9 +46,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
# Then adding an unread private topic should not bump.
|
||||
as(@mod) do
|
||||
create(:forum_post, :topic_id => @forum_topic.id)
|
||||
end
|
||||
as(@mod) { create(:forum_post, topic: @forum_topic, creator: @mod) }
|
||||
@gold_user.reload
|
||||
as(@gold_user) do
|
||||
assert_equal(false, @gold_user.has_forum_been_updated?)
|
||||
@@ -91,8 +88,10 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
@topic1 = create(:forum_topic, :is_sticky => true, :original_post_attributes => {:body => "xxx"})
|
||||
@topic2 = create(:forum_topic, :original_post_attributes => {:body => "xxx"})
|
||||
@topic1 = create(:forum_topic, is_sticky: true, creator: @user)
|
||||
@topic2 = create(:forum_topic, creator: @user)
|
||||
@post1 = create(:forum_post, topic: @topic1, creator: @user, body: "xxx")
|
||||
@post2 = create(:forum_post, topic: @topic2, creator: @user, body: "xxx")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -158,7 +157,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "create action" do
|
||||
should "create a new forum topic and post" do
|
||||
assert_difference(["ForumPost.count", "ForumTopic.count"], 1) do
|
||||
post_auth forum_topics_path, @user, params: {:forum_topic => {:title => "bababa", :original_post_attributes => {:body => "xaxaxa"}}}
|
||||
post_auth forum_topics_path, @user, params: { forum_topic: { title: "bababa", original_post_attributes: { body: "xaxaxa" }}}
|
||||
end
|
||||
|
||||
forum_topic = ForumTopic.last
|
||||
|
||||
@@ -7,13 +7,8 @@ module Moderator
|
||||
PoolArchive.delete_all
|
||||
PostArchive.delete_all
|
||||
|
||||
travel_to(1.month.ago) do
|
||||
@user = create(:moderator_user)
|
||||
end
|
||||
|
||||
as_user do
|
||||
create(:comment)
|
||||
end
|
||||
@user = create(:moderator_user, created_at: 1.month.ago)
|
||||
as(@user) { create(:comment, creator: @user) }
|
||||
end
|
||||
|
||||
should "find by ip addr" do
|
||||
|
||||
@@ -29,9 +29,7 @@ module Moderator
|
||||
end
|
||||
|
||||
should "work even if the deleter has flagged the post previously" do
|
||||
as_user do
|
||||
PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
||||
end
|
||||
create(:post_flag, post: @post, creator: @admin)
|
||||
post_auth delete_moderator_post_post_path(@post), @admin, params: {:reason => "xxx", :format => "js", :commit => "Delete"}
|
||||
assert(@post.reload.is_deleted?)
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ class NewsUpdatesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
as(@admin) do
|
||||
@news_update = create(:news_update)
|
||||
@news_update = create(:news_update, creator: @admin)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@ require 'test_helper'
|
||||
class PostFlagsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The post flags controller" do
|
||||
setup do
|
||||
travel_to(2.weeks.ago) do
|
||||
@user = create(:user)
|
||||
end
|
||||
@user = create(:user, created_at: 2.weeks.ago)
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
@@ -17,10 +15,7 @@ class PostFlagsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@user.as_current do
|
||||
@post = create(:post)
|
||||
@post_flag = create(:post_flag, :post => @post)
|
||||
end
|
||||
@post_flag = create(:post_flag, creator: @user)
|
||||
end
|
||||
|
||||
should "render" do
|
||||
|
||||
@@ -169,7 +169,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "with only deleted comments" do
|
||||
setup do
|
||||
as(@user) { create(:comment, post: @post, is_deleted: true) }
|
||||
as(@user) { create(:comment, creator: @user, post: @post, is_deleted: true) }
|
||||
end
|
||||
|
||||
should "not show deleted comments to regular members" do
|
||||
@@ -194,7 +194,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "with only downvoted comments" do
|
||||
should "not show thresholded comments" do
|
||||
comment = as(@user) { create(:comment, post: @post, score: -10) }
|
||||
comment = as(@user) { create(:comment, creator: @user, post: @post, score: -10) }
|
||||
get_auth post_path(@post), @user, params: { id: @post.id }
|
||||
|
||||
assert_response :success
|
||||
@@ -206,9 +206,9 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "with a mix of comments" do
|
||||
should "not show deleted or thresholded comments " do
|
||||
as(@user) { create(:comment, post: @post, do_not_bump_post: true, body: "good") }
|
||||
as(@user) { create(:comment, post: @post, do_not_bump_post: true, body: "bad", score: -10) }
|
||||
as(@user) { create(:comment, post: @post, do_not_bump_post: true, body: "ugly", is_deleted: true) }
|
||||
as(@user) { create(:comment, creator: @user, post: @post, do_not_bump_post: true, body: "good") }
|
||||
as(@user) { create(:comment, creator: @user, post: @post, do_not_bump_post: true, body: "bad", score: -10) }
|
||||
as(@user) { create(:comment, creator: @user, post: @post, do_not_bump_post: true, body: "ugly", is_deleted: true) }
|
||||
|
||||
get_auth post_path(@post), @user, params: { id: @post.id }
|
||||
|
||||
|
||||
@@ -4,15 +4,10 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The tag aliases controller" do
|
||||
setup do
|
||||
@user = create(:admin_user)
|
||||
@tag_alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
setup do
|
||||
as_admin do
|
||||
@tag_alias = create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get_auth edit_tag_alias_path(@tag_alias), @user
|
||||
assert_response :success
|
||||
@@ -20,12 +15,6 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
as_admin do
|
||||
@tag_alias = create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
end
|
||||
|
||||
context "for a pending alias" do
|
||||
setup do
|
||||
as_admin do
|
||||
@@ -63,12 +52,6 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as_admin do
|
||||
@tag_alias = create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
end
|
||||
|
||||
should "list all tag alias" do
|
||||
get_auth tag_aliases_path, @user
|
||||
assert_response :success
|
||||
@@ -81,12 +64,6 @@ class TagAliasesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
setup do
|
||||
as_admin do
|
||||
@tag_alias = create(:tag_alias)
|
||||
end
|
||||
end
|
||||
|
||||
should "mark the alias as deleted" do
|
||||
assert_difference("TagAlias.count", 0) do
|
||||
delete_auth tag_alias_path(@tag_alias), @user
|
||||
|
||||
@@ -4,15 +4,10 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The tag implications controller" do
|
||||
setup do
|
||||
@user = create(:admin_user)
|
||||
@tag_implication = create(:tag_implication, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
setup do
|
||||
as_admin do
|
||||
@tag_implication = create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get_auth tag_implication_path(@tag_implication), @user
|
||||
assert_response :success
|
||||
@@ -20,12 +15,6 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
as_admin do
|
||||
@tag_implication = create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
end
|
||||
|
||||
context "for a pending implication" do
|
||||
setup do
|
||||
as_admin do
|
||||
@@ -60,12 +49,6 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
@tag_implication = create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
end
|
||||
|
||||
should "list all tag implications" do
|
||||
get tag_implications_path
|
||||
assert_response :success
|
||||
@@ -78,12 +61,6 @@ class TagImplicationsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "destroy action" do
|
||||
setup do
|
||||
as_user do
|
||||
@tag_implication = create(:tag_implication)
|
||||
end
|
||||
end
|
||||
|
||||
should "mark the implication as deleted" do
|
||||
assert_difference("TagImplication.count", 0) do
|
||||
delete_auth tag_implication_path(@tag_implication), @user
|
||||
|
||||
@@ -6,7 +6,7 @@ class UserFeedbacksControllerTest < ActionDispatch::IntegrationTest
|
||||
@user = create(:user)
|
||||
@critic = create(:gold_user)
|
||||
@mod = create(:moderator_user)
|
||||
@user_feedback = as(@critic) { create(:user_feedback, user: @user) }
|
||||
@user_feedback = create(:user_feedback, user: @user, creator: @critic)
|
||||
end
|
||||
|
||||
context "new action" do
|
||||
|
||||
@@ -23,14 +23,8 @@ class TagRelationshipRetirementServiceTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
subject.stubs(:is_unused?).returns(true)
|
||||
|
||||
@user = FactoryBot.create(:user)
|
||||
as_user do
|
||||
@new_alias = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
|
||||
travel_to(3.years.ago) do
|
||||
@old_alias = FactoryBot.create(:tag_alias, antecedent_name: "ccc", consequent_name: "ddd")
|
||||
end
|
||||
end
|
||||
@new_alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
@old_alias = create(:tag_alias, antecedent_name: "ccc", consequent_name: "ddd", created_at: 3.years.ago)
|
||||
end
|
||||
|
||||
should "find old tag relationships" do
|
||||
@@ -50,17 +44,11 @@ class TagRelationshipRetirementServiceTest < ActiveSupport::TestCase
|
||||
subject { TagRelationshipRetirementService }
|
||||
|
||||
setup do
|
||||
@user = FactoryBot.create(:user)
|
||||
@new_alias = create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
@new_post = create(:post, tag_string: "bbb")
|
||||
|
||||
as_user do
|
||||
@new_alias = FactoryBot.create(:tag_alias, antecedent_name: "aaa", consequent_name: "bbb")
|
||||
@new_post = FactoryBot.create(:post, tag_string: "bbb")
|
||||
|
||||
travel_to(3.years.ago) do
|
||||
@old_alias = FactoryBot.create(:tag_alias, antecedent_name: "ccc", consequent_name: "ddd")
|
||||
@old_post = FactoryBot.create(:post, tag_string: "ddd")
|
||||
end
|
||||
end
|
||||
@old_alias = create(:tag_alias, antecedent_name: "ccc", consequent_name: "ddd", created_at: 3.years.ago)
|
||||
@old_post = create(:post, tag_string: "ddd", created_at: 3.years.ago)
|
||||
end
|
||||
|
||||
should "return true if no recent post exists" do
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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?)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user