tests: eliminate as_user helper.
This commit is contained in:
@@ -5,7 +5,7 @@ class ArtistCommentariesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = create(:user)
|
||||
|
||||
as_user do
|
||||
as(@user) do
|
||||
@commentary1 = create(:artist_commentary)
|
||||
@commentary2 = create(:artist_commentary)
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
as(@user) do
|
||||
@artist = create(:artist)
|
||||
@masao = create(:artist, name: "masao", url_string: "http://www.pixiv.net/member.php?id=32777")
|
||||
@artgerm = create(:artist, name: "artgerm", url_string: "http://artgerm.deviantart.com/")
|
||||
@@ -179,7 +179,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "revert action" do
|
||||
should "work" do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@artist.update(name: "xyz")
|
||||
@artist.update(name: "abc")
|
||||
end
|
||||
@@ -188,9 +188,7 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another artist" do
|
||||
as_user do
|
||||
@artist2 = create(:artist)
|
||||
end
|
||||
@artist2 = as(@user) { create(:artist) }
|
||||
put_auth artist_path(@artist.id), @user, params: {version_id: @artist2.versions.first.id}
|
||||
assert_redirected_to(artist_path(@artist.id))
|
||||
assert_not_equal(@artist.reload.name, @artist2.name)
|
||||
|
||||
@@ -5,9 +5,7 @@ class DmailsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = create(:user, unread_dmail_count: 1)
|
||||
@unrelated_user = create(:user)
|
||||
as_user do
|
||||
@dmail = create(:dmail, :owner => @user)
|
||||
end
|
||||
@dmail = create(:dmail, owner: @user)
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
||||
@@ -12,7 +12,7 @@ class ForumPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "with votes" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@bulk_update_request = create(:bulk_update_request, forum_post: @forum_post)
|
||||
@vote = create(:forum_post_vote, forum_post: @forum_post, score: 1)
|
||||
@forum_post.reload
|
||||
|
||||
@@ -87,7 +87,7 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@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")
|
||||
@@ -267,8 +267,8 @@ class ForumTopicsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "destroy action" do
|
||||
setup do
|
||||
as_user do
|
||||
@post = create(:forum_post, :topic_id => @forum_topic.id)
|
||||
as(@user) do
|
||||
@post = create(:forum_post, topic: @forum_topic)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,9 +5,7 @@ class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
Danbooru.config.stubs(:iqdbs_server).returns("https://karasuma.donmai.us")
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
@posts = FactoryBot.create_list(:post, 2)
|
||||
end
|
||||
@posts = as(@user) { create_list(:post, 2) }
|
||||
end
|
||||
|
||||
context "show action" do
|
||||
|
||||
@@ -10,7 +10,7 @@ module Moderator
|
||||
@user = create(:gold_user)
|
||||
end
|
||||
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = create(:post)
|
||||
end
|
||||
end
|
||||
@@ -48,7 +48,7 @@ module Moderator
|
||||
end
|
||||
|
||||
should "render" do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@parent = create(:post)
|
||||
@child = create(:post, parent: @parent)
|
||||
end
|
||||
|
||||
@@ -5,9 +5,7 @@ class ModqueueControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
@post = create(:post, :is_pending => true)
|
||||
end
|
||||
@post = as(@user) { create(:post, is_pending: true) }
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
|
||||
@@ -71,7 +71,7 @@ class NotesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
travel(1.day) do
|
||||
@note.update(:body => "111")
|
||||
end
|
||||
@@ -88,7 +88,7 @@ class NotesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another note" do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@note2 = create(:note, :body => "note 2")
|
||||
end
|
||||
put_auth revert_note_path(@note), @user, params: { :version_id => @note2.versions.first.id }
|
||||
|
||||
@@ -5,7 +5,7 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user = travel_to(1.month.ago) {create(:user)}
|
||||
@mod = create(:moderator_user)
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = create(:post)
|
||||
@pool = create(:pool, :name => "abc")
|
||||
end
|
||||
@@ -19,7 +19,7 @@ class PoolElementsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "add a post to a pool once and only once" do
|
||||
as_user { @pool.add!(@post) }
|
||||
as(@user) { @pool.add!(@post) }
|
||||
post_auth pool_element_path, @user, params: {:pool_id => @pool.id, :post_id => @post.id, :format => "json"}
|
||||
assert_response :success
|
||||
assert_equal([@post.id], @pool.reload.post_ids)
|
||||
|
||||
@@ -7,7 +7,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
|
||||
@user = create(:user)
|
||||
@mod = create(:moderator_user)
|
||||
end
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = create(:post)
|
||||
@pool = create(:pool)
|
||||
end
|
||||
@@ -112,9 +112,7 @@ class PoolsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another pool" do
|
||||
as_user do
|
||||
@pool2 = create(:pool)
|
||||
end
|
||||
@pool2 = as(@user) { create(:pool) }
|
||||
put_auth revert_pool_path(@pool), @user, params: {:version_id => @pool2.versions.first.id }
|
||||
@pool.reload
|
||||
assert_not_equal(@pool.name, @pool2.name)
|
||||
|
||||
@@ -23,7 +23,7 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = create(:post, :is_deleted => true)
|
||||
@post_appeal = create(:post_appeal, :post => @post)
|
||||
end
|
||||
@@ -49,9 +49,7 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "create action" do
|
||||
setup do
|
||||
as_user do
|
||||
@post = create(:post, :is_deleted => true)
|
||||
end
|
||||
@post = as(@user) { create(:post, is_deleted: true) }
|
||||
end
|
||||
|
||||
should "create a new appeal" do
|
||||
|
||||
@@ -7,7 +7,7 @@ class PostEventsControllerTest < ActionDispatch::IntegrationTest
|
||||
@mod = create(:mod_user)
|
||||
end
|
||||
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = create(:post)
|
||||
@post.flag!("aaa")
|
||||
create(:post_appeal, post: @post)
|
||||
|
||||
@@ -6,9 +6,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
PopularSearchService.stubs(:enabled?).returns(false)
|
||||
|
||||
@user = travel_to(1.month.ago) {create(:user)}
|
||||
as_user do
|
||||
@post = create(:post, :tag_string => "aaaa")
|
||||
end
|
||||
@post = as(@user) { create(:post, tag_string: "aaaa") }
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
@@ -45,7 +43,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
assert_select "#show-excerpt-link", count: 1, text: "Wiki"
|
||||
|
||||
as_user { create(:wiki_page, title: "bkub") }
|
||||
as(@user) { create(:wiki_page, title: "bkub") }
|
||||
get posts_path, params: { tags: "bkub" }
|
||||
assert_response :success
|
||||
assert_select "#show-excerpt-link", count: 1, text: "Wiki"
|
||||
@@ -57,12 +55,12 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
assert_select "#show-excerpt-link", count: 1, text: "Wiki"
|
||||
|
||||
as_user { @wiki = create(:wiki_page, title: "fumimi") }
|
||||
@wiki = as(@user) { create(:wiki_page, title: "fumimi") }
|
||||
get posts_path, params: { tags: "fumimi" }
|
||||
assert_response :success
|
||||
assert_select "#show-excerpt-link", count: 1, text: "Wiki"
|
||||
|
||||
as_user { @wiki.update(is_deleted: true) }
|
||||
as(@user) { @wiki.update(is_deleted: true) }
|
||||
get posts_path, params: { tags: "bkub" }
|
||||
assert_response :success
|
||||
assert_select "#show-excerpt-link", count: 0
|
||||
@@ -520,9 +518,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "revert action" do
|
||||
setup do
|
||||
PostVersion.sqs_service.stubs(:merge?).returns(false)
|
||||
as_user do
|
||||
@post.update(tag_string: "zzz")
|
||||
end
|
||||
as(@user) { @post.update(tag_string: "zzz") }
|
||||
end
|
||||
|
||||
should "work" do
|
||||
@@ -535,9 +531,7 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another post" do
|
||||
as_user do
|
||||
@post2 = create(:post, :uploader_id => @user.id, :tag_string => "herp")
|
||||
end
|
||||
@post2 = as(@user) { create(:post, uploader_id: @user.id, tag_string: "herp") }
|
||||
|
||||
put_auth revert_post_path(@post), @user, params: { :version_id => @post2.versions.first.id }
|
||||
@post.reload
|
||||
|
||||
@@ -4,9 +4,7 @@ class RecommendedPostsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The recommended posts controller" do
|
||||
setup do
|
||||
@user = travel_to(1.month.ago) {create(:user)}
|
||||
as_user do
|
||||
@post = create(:post, :tag_string => "aaaa")
|
||||
end
|
||||
@post = as(@user) { create(:post, tag_string: "aaaa") }
|
||||
RecommenderService.stubs(:enabled?).returns(true)
|
||||
end
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The tags controller" do
|
||||
setup do
|
||||
@user = create(:builder_user)
|
||||
as_user do
|
||||
@tag = create(:tag, name: "touhou", category: Tag.categories.copyright, post_count: 1)
|
||||
end
|
||||
@tag = create(:tag, name: "touhou", category: Tag.categories.copyright, post_count: 1)
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
@@ -92,9 +90,7 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "for a tag with >50 posts" do
|
||||
setup do
|
||||
as_user do
|
||||
@tag.update(post_count: 100)
|
||||
end
|
||||
@tag.update(post_count: 100)
|
||||
end
|
||||
|
||||
should "not update the category for a member" do
|
||||
@@ -114,9 +110,7 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not change category when the tag is too large to be changed by a builder" do
|
||||
as_user do
|
||||
@tag.update(category: Tag.categories.general, post_count: 1001)
|
||||
end
|
||||
@tag.update(category: Tag.categories.general, post_count: 1001)
|
||||
put_auth tag_path(@tag), @user, params: {:tag => {:category => Tag.categories.artist}}
|
||||
|
||||
assert_response :forbidden
|
||||
|
||||
@@ -131,9 +131,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "for a post that has already been uploaded" do
|
||||
setup do
|
||||
as_user do
|
||||
@post = create(:post, :source => "http://google.com/aaa")
|
||||
end
|
||||
@post = as(@user) { create(:post, source: "http://google.com/aaa") }
|
||||
end
|
||||
|
||||
should "initialize the post" do
|
||||
@@ -147,7 +145,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@upload = create(:source_upload, tag_string: "foo bar")
|
||||
@upload2 = create(:source_upload, tag_string: "tagme", rating: "e")
|
||||
end
|
||||
@@ -180,9 +178,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
as_user do
|
||||
@upload = create(:jpg_upload)
|
||||
end
|
||||
@upload = as(@user) { create(:jpg_upload) }
|
||||
end
|
||||
|
||||
should "render" do
|
||||
@@ -195,7 +191,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "when a preprocessed upload already exists" do
|
||||
context "for twitter" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@ref = "https://twitter.com/onsen_musume_jp/status/865534101918330881"
|
||||
@source = "https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"
|
||||
@upload = create(:upload, status: "preprocessed", source: @source, referer_url: @ref, image_width: 0, image_height: 0, file_size: 0, md5: "something", file_ext: "jpg")
|
||||
@@ -217,9 +213,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@ref = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482"
|
||||
@source = "https://i.pximg.net/img-original/img/2015/03/14/17/53/32/49270482_p0.jpg"
|
||||
as_user do
|
||||
@upload = create(:upload, status: "preprocessed", source: @source, referer_url: @ref, image_width: 0, image_height: 0, file_size: 0, md5: "something", file_ext: "jpg")
|
||||
end
|
||||
@upload = as(@user) { create(:upload, status: "preprocessed", source: @source, referer_url: @ref, image_width: 0, image_height: 0, file_size: 0, md5: "something", file_ext: "jpg") }
|
||||
end
|
||||
|
||||
should "update the predecessor" do
|
||||
|
||||
@@ -45,7 +45,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
# flesh out profile to get more test coverage of user presenter.
|
||||
@user = create(:banned_user, can_approve_posts: true, created_at: 2.weeks.ago)
|
||||
as_user do
|
||||
as(@user) do
|
||||
create(:saved_search, user: @user)
|
||||
create(:post, uploader: @user, tag_string: "fav:#{@user.name}")
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ class WikiPageVersionsControllerTest < ActionDispatch::IntegrationTest
|
||||
context "The wiki page versions controller" do
|
||||
setup do
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
as(@user) do
|
||||
@wiki_page = create(:wiki_page)
|
||||
@wiki_page.update(:body => "1 2")
|
||||
@wiki_page.update(:body => "2 3")
|
||||
|
||||
@@ -9,7 +9,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@wiki_page_abc = create(:wiki_page, :title => "abc")
|
||||
@wiki_page_def = create(:wiki_page, :title => "def")
|
||||
end
|
||||
@@ -47,9 +47,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "show action" do
|
||||
setup do
|
||||
as_user do
|
||||
@wiki_page = create(:wiki_page)
|
||||
end
|
||||
@wiki_page = as(@user) { create(:wiki_page) }
|
||||
end
|
||||
|
||||
should "redirect to the title for an id" do
|
||||
@@ -91,9 +89,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "render for a negated tag" do
|
||||
as_user do
|
||||
@wiki_page.update(title: "-aaa")
|
||||
end
|
||||
as(@user) { @wiki_page.update(title: "-aaa") }
|
||||
|
||||
get wiki_page_path(@wiki_page.id)
|
||||
assert_redirected_to wiki_page_path(@wiki_page.title)
|
||||
@@ -115,9 +111,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "show_or_new action" do
|
||||
setup do
|
||||
as_user do
|
||||
@wiki_page = create(:wiki_page)
|
||||
end
|
||||
@wiki_page = as(@user) { create(:wiki_page) }
|
||||
end
|
||||
|
||||
should "redirect when given a title" do
|
||||
@@ -167,7 +161,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@tag = create(:tag, name: "foo", post_count: 42)
|
||||
@wiki_page = create(:wiki_page, title: "foo")
|
||||
@builder = create(:builder_user)
|
||||
@@ -219,9 +213,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "destroy action" do
|
||||
setup do
|
||||
as_user do
|
||||
@wiki_page = create(:wiki_page)
|
||||
end
|
||||
@wiki_page = as(@user) { create(:wiki_page) }
|
||||
@mod = create(:mod_user)
|
||||
end
|
||||
|
||||
@@ -234,7 +226,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
context "revert action" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@wiki_page = create(:wiki_page, body: "1")
|
||||
travel(1.day)
|
||||
@wiki_page.update(body: "1 2")
|
||||
@@ -252,9 +244,7 @@ class WikiPagesControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "not allow reverting to a previous version of another wiki page" do
|
||||
as_user do
|
||||
@wiki_page_2 = create(:wiki_page)
|
||||
end
|
||||
@wiki_page_2 = as(@user) { create(:wiki_page) }
|
||||
|
||||
put_auth revert_wiki_page_path(@wiki_page), @user, params: { :version_id => @wiki_page_2.versions.first.id }
|
||||
@wiki_page.reload
|
||||
|
||||
@@ -31,10 +31,6 @@ module TestHelpers
|
||||
def as(user, &block)
|
||||
CurrentUser.as(user, &block)
|
||||
end
|
||||
|
||||
def as_user(&block)
|
||||
CurrentUser.as(@user, &block)
|
||||
end
|
||||
end
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
|
||||
@@ -1828,7 +1828,7 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "not allow members to vote" do
|
||||
@user = FactoryBot.create(:user)
|
||||
@post = FactoryBot.create(:post)
|
||||
as_user do
|
||||
as(@user) do
|
||||
assert_raises(PostVote::Error) { @post.vote!("up") }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -98,7 +98,7 @@ class TagAutocompleteTest < ActiveSupport::TestCase
|
||||
create(:tag, name: "abcdef", post_count: 1),
|
||||
create(:tag, name: "zzzzzz", post_count: 1)
|
||||
]
|
||||
as_user do
|
||||
as(@user) do
|
||||
@aliases = [
|
||||
create(:tag_alias, antecedent_name: "/abc", consequent_name: "abcdef", status: "active")
|
||||
]
|
||||
|
||||
@@ -257,7 +257,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
travel_to(1.month.ago) do
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = FactoryBot.create(:post, md5: Digest::MD5.hexdigest(@old_file.read))
|
||||
@old_md5 = @post.md5
|
||||
@post.stubs(:queue_delete_files)
|
||||
@@ -270,32 +270,32 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "#process!" do
|
||||
should "create a new upload" do
|
||||
assert_difference(-> { Upload.count }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "create a comment" do
|
||||
assert_difference(-> { @post.comments.count }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "not create a new post" do
|
||||
assert_difference(-> { Post.count }, 0) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post's MD5" do
|
||||
assert_changes(-> { @post.md5 }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "preserve the old values" do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
assert_equal(1500, @replacement.image_width_was)
|
||||
assert_equal(1000, @replacement.image_height_was)
|
||||
assert_equal(2000, @replacement.file_size_was)
|
||||
@@ -304,7 +304,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "record the new values" do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
assert_equal(500, @replacement.image_width)
|
||||
assert_equal(335, @replacement.image_height)
|
||||
assert_equal(28086, @replacement.file_size)
|
||||
@@ -313,7 +313,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "correctly update the attributes" do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
assert_equal(500, @post.image_width)
|
||||
assert_equal(335, @post.image_height)
|
||||
assert_equal(28086, @post.file_size)
|
||||
@@ -327,7 +327,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
should "not raise a duplicate error" do
|
||||
upload_file("test/files/test.png") do |file|
|
||||
assert_nothing_raised do
|
||||
as_user { @post.replace!(replacement_file: file, replacement_url: "") }
|
||||
as(@user) { @post.replace!(replacement_file: file, replacement_url: "") }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -335,7 +335,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
should "not queue a deletion or log a comment" do
|
||||
upload_file("test/files/test.png") do |file|
|
||||
assert_no_difference(-> { @post.comments.count }) do
|
||||
as_user { @post.replace!(replacement_file: file, replacement_url: "") }
|
||||
as(@user) { @post.replace!(replacement_file: file, replacement_url: "") }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
@@ -351,7 +351,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = FactoryBot.create(:post, source: "http://blah", file_ext: "jpg", md5: "something", uploader_ip_addr: "127.0.0.2")
|
||||
@post.stubs(:queue_delete_files)
|
||||
@replacement = FactoryBot.create(:post_replacement, post: @post, replacement_url: @new_url)
|
||||
@@ -361,7 +361,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
subject { UploadService::Replacer.new(post: @post, replacement: @replacement) }
|
||||
|
||||
should "replace the post" do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
|
||||
@post.reload
|
||||
|
||||
@@ -376,7 +376,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
travel_to(1.month.ago) do
|
||||
@user = FactoryBot.create(:user)
|
||||
end
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post_md5 = "710fd9cba4ef37260f9152ffa9d154d8"
|
||||
@post = FactoryBot.create(:post, source: "https://cdn.donmai.us/original/71/0f/#{@post_md5}.png", file_ext: "png", md5: @post_md5, uploader_ip_addr: "127.0.0.2")
|
||||
@post.stubs(:queue_delete_files)
|
||||
@@ -388,7 +388,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
|
||||
context "when replacing with its own source" do
|
||||
should "work" do
|
||||
as_user { @post.replace!(replacement_url: @post.source) }
|
||||
as(@user) { @post.replace!(replacement_url: @post.source) }
|
||||
assert_equal(@post_md5, @post.md5)
|
||||
assert_match(/#{@post_md5}/, @post.file_path)
|
||||
end
|
||||
@@ -397,7 +397,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "when an upload with the same MD5 already exists" do
|
||||
setup do
|
||||
@post.update(md5: @new_md5)
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post2 = FactoryBot.create(:post)
|
||||
@post2.stubs(:queue_delete_files)
|
||||
end
|
||||
@@ -405,7 +405,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
|
||||
should "throw an error" do
|
||||
assert_raises(UploadService::Replacer::Error) do
|
||||
as_user { @post2.replace!(replacement_url: @new_url) }
|
||||
as(@user) { @post2.replace!(replacement_url: @new_url) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -415,7 +415,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
replacement_url = "https://cdn.donmai.us/original/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg"
|
||||
final_source = "https://cdn.donmai.us/original/71/0f/710fd9cba4ef37260f9152ffa9d154d8.png"
|
||||
|
||||
as_user { @post.replace!(replacement_url: replacement_url, final_source: final_source) }
|
||||
as(@user) { @post.replace!(replacement_url: replacement_url, final_source: final_source) }
|
||||
|
||||
assert_equal(final_source, @post.source)
|
||||
end
|
||||
@@ -426,7 +426,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
skip "Twitter key not set" unless Danbooru.config.twitter_api_key
|
||||
replacement_url = "https://twitter.com/nounproject/status/540944400767922176"
|
||||
image_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||
as_user { @post.replace!(replacement_url: replacement_url) }
|
||||
as(@user) { @post.replace!(replacement_url: replacement_url) }
|
||||
|
||||
assert_equal(replacement_url, @post.replacements.last.replacement_url)
|
||||
end
|
||||
@@ -435,7 +435,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "#undo!" do
|
||||
setup do
|
||||
@user = travel_to(1.month.ago) { FactoryBot.create(:user) }
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post = FactoryBot.create(:post, source: "https://cdn.donmai.us/original/d3/4e/d34e4cf0a437a5d65f8e82b7bcd02606.jpg")
|
||||
@post.stubs(:queue_delete_files)
|
||||
@post.replace!(replacement_url: "https://cdn.donmai.us/original/fd/b4/fdb47f79fb8da82e66eeb1d84a1cae8d.jpg", tags: "-tag1 tag2")
|
||||
@@ -445,7 +445,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "update the attributes" do
|
||||
as_user do
|
||||
as(@user) do
|
||||
subject.undo!
|
||||
end
|
||||
|
||||
@@ -463,46 +463,46 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "#process!" do
|
||||
should "create a new upload" do
|
||||
assert_difference(-> { Upload.count }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "create a comment" do
|
||||
assert_difference(-> { @post.comments.count }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "not create a new post" do
|
||||
assert_difference(-> { Post.count }, 0) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post's MD5" do
|
||||
assert_changes(-> { @post.md5 }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "update the post's source" do
|
||||
assert_changes(-> { @post.source }, nil, from: @post.source, to: @new_url) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "not change the post status or uploader" do
|
||||
assert_no_changes(-> { {ip_addr: @post.uploader_ip_addr.to_s, uploader: @post.uploader_id, pending: @post.is_pending?} }) do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
@post.reload
|
||||
end
|
||||
end
|
||||
|
||||
should "leave a system comment" do
|
||||
as_user { subject.process! }
|
||||
as(@user) { subject.process! }
|
||||
comment = @post.comments.last
|
||||
assert_not_nil(comment)
|
||||
assert_equal(User.system.id, comment.creator_id)
|
||||
@@ -513,7 +513,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
context "a post with a pixiv html source" do
|
||||
should "replace with the full size image" do
|
||||
begin
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
end
|
||||
|
||||
@@ -535,7 +535,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
@post.unstub(:queue_delete_files)
|
||||
FileUtils.expects(:rm_f).times(3)
|
||||
|
||||
as_user { @post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350") }
|
||||
as(@user) { @post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350") }
|
||||
|
||||
travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
|
||||
perform_enqueued_jobs
|
||||
@@ -550,7 +550,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
should "save the frame data" do
|
||||
skip unless MediaFile::Ugoira.videos_enabled?
|
||||
begin
|
||||
as_user { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") }
|
||||
as(@user) { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") }
|
||||
@post.reload
|
||||
|
||||
assert_equal(80, @post.image_width)
|
||||
@@ -575,7 +575,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
# this is called thrice to delete the file for 62247364
|
||||
FileUtils.expects(:rm_f).times(3)
|
||||
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@post.reload
|
||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||
@@ -601,7 +601,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
|
||||
context "two posts that have had their files swapped" do
|
||||
setup do
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post1 = FactoryBot.create(:post)
|
||||
@post2 = FactoryBot.create(:post)
|
||||
end
|
||||
@@ -610,7 +610,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
should "not delete the still active files" do
|
||||
# swap the images between @post1 and @post2.
|
||||
begin
|
||||
as_user do
|
||||
as(@user) do
|
||||
skip unless MediaFile::Ugoira.videos_enabled?
|
||||
|
||||
@post1.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||
@@ -649,7 +649,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
Note.any_instance.stubs(:merge_version?).returns(false)
|
||||
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post.update(image_width: 160, image_height: 164)
|
||||
@note = @post.notes.create(x: 80, y: 82, width: 80, height: 82, body: "test")
|
||||
@note.reload
|
||||
@@ -662,7 +662,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
||||
begin
|
||||
assert_difference(-> { @note.versions.count }) do
|
||||
# replacement image is 80x82, so we're downscaling by 50% (160x164 -> 80x82).
|
||||
as_user do
|
||||
as(@user) do
|
||||
@post.replace!(
|
||||
replacement_url: "https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png",
|
||||
final_source: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
|
||||
|
||||
Reference in New Issue
Block a user