tests: eliminate as_user helper.

This commit is contained in:
evazion
2020-06-11 01:02:01 -05:00
parent 2d05004bef
commit 99a9149fc4
24 changed files with 84 additions and 130 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 }

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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