fix tests

This commit is contained in:
r888888888
2017-04-04 12:25:03 -07:00
parent 347ffb5989
commit 0b8d4105aa
19 changed files with 111 additions and 162 deletions

View File

@@ -74,6 +74,10 @@ module Sources
}
end
def to_json
to_h.to_json
end
def available?
strategy.present?
end

View File

@@ -11,6 +11,11 @@ module Moderator
@post = FactoryGirl.create(:post)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "confirm_delete action" do
should "render" do
get :confirm_delete, { id: @post.id }, { user_id: @admin.id }
@@ -49,7 +54,18 @@ module Moderator
end
context "move_favorites action" do
should "render" do
setup do
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "1234 render" do
parent = FactoryGirl.create(:post)
child = FactoryGirl.create(:post, parent: parent)
users = FactoryGirl.create_list(:user, 2)
@@ -57,6 +73,7 @@ module Moderator
put :move_favorites, { id: child.id, commit: "Submit" }, { user_id: @admin.id }
CurrentUser.user = @admin
assert_redirected_to(child)
assert_equal(users, parent.reload.favorited_users)
assert_equal([], child.reload.favorited_users)

View File

@@ -14,6 +14,7 @@ class PoolsControllerTest < ActionController::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post)
mock_pool_archive_service!
PoolArchive.sqs_service.stubs(:merge?).returns(false)
start_pool_archive_transaction
end

View File

@@ -1,18 +1,23 @@
require 'test_helper'
require 'helpers/post_archive_test_helper'
class PostVersionsControllerTest < ActionController::TestCase
include PostArchiveTestHelper
def setup
super
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "The post versions controller" do
setup do
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "index action" do
setup do
@post = FactoryGirl.create(:post)
@@ -21,13 +26,13 @@ class PostVersionsControllerTest < ActionController::TestCase
end
should "list all versions" do
get :index
get :index, {}, {:user_id => @user.id}
assert_response :success
assert_not_nil(assigns(:post_versions))
end
should "list all versions that match the search criteria" do
get :index, {:search => {:post_id => @post.id}}
get :index, {:search => {:post_id => @post.id}}, {:user_id => @user.id}
assert_response :success
assert_not_nil(assigns(:post_versions))
end

View File

@@ -1,7 +1,12 @@
require 'test_helper'
require 'helpers/post_archive_test_helper'
class ReportsControllerTest < ActionController::TestCase
setup do
include PostArchiveTestHelper
def setup
super
CurrentUser.user = FactoryGirl.create(:mod_user)
CurrentUser.ip_addr = "127.0.0.1"
session[:user_id] = CurrentUser.user.id
@@ -10,34 +15,15 @@ class ReportsControllerTest < ActionController::TestCase
@posts = @users.map { |u| FactoryGirl.create(:post, uploader: u) }
end
teardown do
def teardown
super
CurrentUser.user = nil
CurrentUser.ip_addr = nil
session[:user_id] = nil
end
context "The reports controller" do
context "user_promotions action" do
should "render" do
get :user_promotions
assert_response :success
end
end
context "janitor_trials action" do
should "render" do
get :janitor_trials
assert_response :success
end
end
context "contributors action" do
should "render" do
get :contributors
assert_response :success
end
end
context "uploads action" do
should "render" do
get :uploads
@@ -58,12 +44,5 @@ class ReportsControllerTest < ActionController::TestCase
assert_response :success
end
end
context "post_versions_create action" do
should "render" do
#post :post_versions_create, { tag: "touhou", type: "added" }
#assert_response :success
end
end
end
end

View File

@@ -5,12 +5,16 @@ module PoolArchiveTestHelper
_, json = msg.split(/\n/)
json = JSON.parse(json)
prev = PoolArchive.where(pool_id: json["pool_id"]).order("id desc").first
if prev && prev.updater_ip_addr.to_s == json["updater_ip_addr"]
if merge?(prev, json)
prev.update_columns(json)
else
PoolArchive.create(json)
end
end
def merge?(prev, json)
prev && (prev.updater_id == json["updater_id"]) && (prev.updated_at >= 1.hour.ago)
end
end
PoolArchive.stubs(:sqs_service).returns(mock_sqs_service.new)

View File

@@ -146,19 +146,19 @@ class BanTest < ActiveSupport::TestCase
should "initialize the expiration date" do
user = FactoryGirl.create(:user)
admin = FactoryGirl.create(:admin_user)
CurrentUser.user = admin
ban = FactoryGirl.create(:ban, :user => user, :banner => admin)
CurrentUser.user = nil
assert_not_nil(ban.expires_at)
CurrentUser.scoped(admin) do
ban = FactoryGirl.create(:ban, :user => user, :banner => admin)
assert_not_nil(ban.expires_at)
end
end
should "update the user's feedback" do
user = FactoryGirl.create(:user)
admin = FactoryGirl.create(:admin_user)
assert(user.feedback.empty?)
CurrentUser.user = admin
ban = FactoryGirl.create(:ban, :user => user, :banner => admin)
CurrentUser.user = nil
CurrentUser.scoped(admin) do
FactoryGirl.create(:ban, :user => user, :banner => admin)
end
assert(!user.feedback.empty?)
assert_equal("negative", user.feedback.last.category)
end

View File

@@ -91,7 +91,7 @@ class CommentTest < ActiveSupport::TestCase
setup do
@post = FactoryGirl.create(:post)
@comment = FactoryGirl.create(:comment, :post_id => @post.id)
@comment.destroy
@comment.update({is_deleted: true}, as: :member)
@post.reload
end

View File

@@ -28,7 +28,7 @@ module Downloads
context "An ugoira site for pixiv" do
setup do
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654", @tempfile.path)
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364", @tempfile.path)
@download.download!
end
@@ -37,8 +37,8 @@ module Downloads
end
should "capture the data" do
assert_equal("http://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @download.source)
assert_equal([{"file"=>"000000.jpg", "delay"=>200}, {"file"=>"000001.jpg", "delay"=>200}, {"file"=>"000002.jpg", "delay"=>200}, {"file"=>"000003.jpg", "delay"=>200}, {"file"=>"000004.jpg", "delay"=>250}], @download.data[:ugoira_frame_data])
assert_equal("https://i1.pixiv.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @download.source)
assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @download.data[:ugoira_frame_data])
end
end
@@ -73,13 +73,10 @@ module Downloads
# don't work for images uploaded after this date.
context "downloading a new PNG illustration" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015"
@big_page = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=46337015"
@medium_thumbnail = "http://i2.pixiv.net/c/600x600/img-master/img/2014/10/04/03/59/52/46337015_p0_master1200.jpg"
@full_size_image = "http://i4.pixiv.net/img-original/img/2014/10/04/03/59/52/46337015_p0.png"
@file_size = 5_141
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
@medium_thumbnail = "https://i.pximg.net/c/600x600/img-master/img/2017/04/04/08/54/15/62247350_p0_master1200.jpg"
@full_size_image = "http://i3.pixiv.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png"
@file_size = 16275
end
should "download the full size image" do
@@ -89,9 +86,7 @@ module Downloads
should "download the full size image instead of the HTML page" do
assert_rewritten(@full_size_image, @medium_page)
assert_rewritten(@full_size_image, @big_page)
assert_downloaded(@file_size, @medium_page)
assert_downloaded(@file_size, @big_page)
end
should "download the full size image instead of the thumbnail" do
@@ -144,10 +139,9 @@ module Downloads
context "downloading a ugoira" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46323924"
@small_thumbnail = "http://i1.pixiv.net/img-inf/img/2014/10/03/17/29/16/46323924_s.jpg"
@zip_file = "http://i1.pixiv.net/img-zip-ugoira/img/2014/10/03/17/29/16/46323924_ugoira1920x1080.zip"
@file_size = 41_171
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
@zip_file = "https://i1.pixiv.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip"
@file_size = 2804
end
should "download the zip file instead of the HTML page" do
@@ -155,11 +149,6 @@ module Downloads
assert_downloaded(@file_size, @medium_page)
end
should "download the zip file instead of the thumbnail" do
assert_rewritten(@zip_file, @small_thumbnail)
assert_downloaded(@file_size, @small_thumbnail)
end
should "download the zip file" do
assert_not_rewritten(@zip_file)
assert_downloaded(@file_size, @zip_file)
@@ -167,14 +156,6 @@ module Downloads
end
context "downloading a profile image" do
should "download old profile images" do
@file_url = "http://img12.pixiv.net/profile/rapattu/119950.jpg"
@file_size = 16238
assert_not_rewritten(@file_url)
assert_downloaded(@file_size, @file_url)
end
should "download new profile images" do
@file_url = "http://i2.pixiv.net/img130/profile/minono_aki/8733472.jpg"
@file_size = 23266
@@ -196,14 +177,6 @@ module Downloads
end
context "downloading a novel image" do
should "download old novel images" do
@file_url = "http://i2.pixiv.net/img20/img/a-park/novel/3607898.jpg"
@file_size = 125_635
assert_not_rewritten(@file_url)
assert_downloaded(@file_size, @file_url)
end
should "download new novel images" do
@file_url = "http://i1.pixiv.net/novel-cover-original/img/2016/11/03/20/10/58/7436075_f75af69f3eacd1656d3733c72aa959cf.jpg"
@file_size = 316_133

View File

@@ -17,7 +17,7 @@ class JanitorTrialTest < ActiveSupport::TestCase
context "upon creation" do
should "create a dmail when testing a new janitor" do
assert_difference("Dmail.count", 4) do
assert_difference("Dmail.count", 2) do
JanitorTrial.create(:user_id => @user.id)
end
end

View File

@@ -16,6 +16,7 @@ class PoolTest < ActiveSupport::TestCase
MEMCACHE.flush_all
mock_pool_archive_service!
PoolArchive.sqs_service.stubs(:merge?).returns(false)
start_pool_archive_transaction
end
@@ -229,20 +230,13 @@ class PoolTest < ActiveSupport::TestCase
@pool.reload
assert_equal(2, @pool.versions.size)
CurrentUser.scoped(user2, "127.0.0.2") do
CurrentUser.scoped(user2, "127.0.0.3") do
@pool.post_ids = "#{@p1.id} #{@p2.id}"
@pool.save
end
@pool.reload
assert_equal(2, @pool.versions.size)
end
should "not create a version if updating the pool fails" do
@pool.stubs(:synchronize!).raises(NotImplementedError)
assert_raise(NotImplementedError) { @pool.update(name: "blah") }
assert_equal(1, @pool.versions.size)
assert_equal(3, @pool.versions.size)
end
should "should create a version if the name changes" do

View File

@@ -24,7 +24,7 @@ class PostArchiveTest < ActiveSupport::TestCase
@post.update_attributes(:tag_string => "2 3")
end
subject { @post.versions[1] }
subject { @post.versions.sort_by(&:id)[1] }
should "undo the changes" do
subject.undo!
@@ -61,7 +61,7 @@ class PostArchiveTest < ActiveSupport::TestCase
should "also create a version" do
assert_equal(1, @post.versions.size)
@version = @post.versions.last
@version = @post.versions.sort_by(&:id).last
assert_equal("aaa bbb ccc", @version.tags)
assert_equal(@post.rating, @version.rating)
assert_equal(@post.parent_id, @version.parent_id)
@@ -93,7 +93,7 @@ class PostArchiveTest < ActiveSupport::TestCase
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
assert_equal(2, @post.versions.size)
@version = @post.versions.last
@version = @post.versions.sort_by(&:id).last
assert_equal("bbb ccc xxx", @version.tags)
assert_equal("q", @version.rating)
assert_equal("", @version.source)
@@ -110,14 +110,14 @@ class PostArchiveTest < ActiveSupport::TestCase
should "should create a version if the rating changes" do
assert_difference("@post.versions.size", 1) do
@post.update(rating: "s")
assert_equal("s", @post.versions.last.rating)
assert_equal("s", @post.versions.sort_by(&:id).last.rating)
end
end
should "should create a version if the source changes" do
assert_difference("@post.versions.size", 1) do
@post.update(source: "blah")
assert_equal("blah", @post.versions.last.source)
assert_equal("blah", @post.versions.sort_by(&:id).last.source)
end
end
@@ -125,14 +125,14 @@ class PostArchiveTest < ActiveSupport::TestCase
assert_difference("@post.versions.size", 1) do
@parent = FactoryGirl.create(:post)
@post.update(parent_id: @parent.id)
assert_equal(@parent.id, @post.versions.last.parent_id)
assert_equal(@parent.id, @post.versions.sort_by(&:id).last.parent_id)
end
end
should "should create a version if the tags change" do
assert_difference("@post.versions.size", 1) do
@post.update(tag_string: "blah")
assert_equal("blah", @post.versions.last.tags)
assert_equal("blah", @post.versions.sort_by(&:id).last.tags)
end
end
end

View File

@@ -24,8 +24,8 @@ class PostEventTest < ActiveSupport::TestCase
should "work" do
results = PostEvent.find_for_post(@post.id)
assert_equal(2, results.size)
assert(results[0].flag?)
assert(results[1].appeal?)
assert_equal("appeal", results[0].type_name)
assert_equal("flag", results[1].type_name)
end
end
end

View File

@@ -69,7 +69,9 @@ class PostVersionTest < ActiveSupport::TestCase
context "that has been updated" do
setup do
PostArchive.sqs_service.stubs(:merge?).returns(false)
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
Timecop.travel(1.minute.ago) do
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
end
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
end

View File

@@ -38,10 +38,10 @@ module Sources
should "convert a page into a json representation" do
assert_nothing_raised do
@site_1.to_json
@site_1.to_h
end
assert_nothing_raised do
@site_2.to_json
@site_2.to_h
end
end
end

View File

@@ -46,22 +46,22 @@ module Sources
context "An ugoira source site for pixiv" do
setup do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654")
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
@site.get
end
should "get the file url" do
assert_equal("http://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @site.file_url)
assert_equal("https://i1.pixiv.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @site.file_url)
end
should "capture the frame data" do
assert_equal([{"file"=>"000000.jpg", "delay"=>200}, {"file"=>"000001.jpg", "delay"=>200}, {"file"=>"000002.jpg", "delay"=>200}, {"file"=>"000003.jpg", "delay"=>200}, {"file"=>"000004.jpg", "delay"=>250}], @site.ugoira_frame_data)
assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @site.ugoira_frame_data)
end
end
context "fetching source data for a new manga image" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46324488")
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46304614")
end
should "get the profile" do
@@ -73,7 +73,7 @@ module Sources
end
should "get the full size image url" do
assert_equal("http://i1.pixiv.net/img-original/img/2014/10/03/18/10/20/46324488_p0.png", @site.image_url)
assert_equal("http://i3.pixiv.net/img-original/img/2014/10/02/14/21/39/46304614_p0.gif", @site.image_url)
end
should "get the page count" do
@@ -84,7 +84,7 @@ module Sources
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
assert_equal(%w(R-18G derp tag1 tag2 オリジナル), pixiv_tags)
assert_equal(["漫画", "foo", "bar", "tag1", "tag2", "derp", "オリジナル"], pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
end
@@ -100,23 +100,9 @@ module Sources
end
end
context "fetching source data for an old manga image" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45792845")
end
should "get the page count" do
assert_equal(3, @site.page_count)
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img-original/img/2014/09/05/05/53/53/45792845_p0.jpg", @site.image_url)
end
end
context "fetching source data for a new illustration" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015")
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46785915")
end
should "get the page count" do
@@ -124,29 +110,7 @@ module Sources
end
should "get the full size image url" do
assert_equal("http://i4.pixiv.net/img-original/img/2014/10/04/03/59/52/46337015_p0.png", @site.image_url)
end
end
context "fetching source data for an old illustration" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720")
end
should "get the page count" do
assert_equal(1, @site.page_count)
end
should "get the full size image url" do
assert_equal("http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png", @site.image_url)
end
should "get the tags" do
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
assert_equal(%w(derp), pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
assert_equal("http://i4.pixiv.net/img-original/img/2014/10/29/09/27/19/46785915_p0.jpg", @site.image_url)
end
end
end

View File

@@ -119,7 +119,7 @@ class UploadTest < ActiveSupport::TestCase
end
end
context "that is an ugoira" do
context "that is a pixiv ugoira" do
setup do
@url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654"
@upload = FactoryGirl.create(:source_upload, :source => @url, :tag_string => "ugoira")
@@ -263,7 +263,7 @@ class UploadTest < ActiveSupport::TestCase
end
end
should "process completely for an ugoira" do
should "process completely for a pixiv ugoira" do
@upload = FactoryGirl.create(:source_upload,
:source => "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654",
:rating => "s",
@@ -279,7 +279,7 @@ class UploadTest < ActiveSupport::TestCase
assert_equal("0d94800c4b520bf3d8adda08f95d31e2", post.md5)
assert_equal(60, post.image_width)
assert_equal(60, post.image_height)
assert_equal("http://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", post.source)
assert_equal("https://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", post.source)
assert_operator(File.size(post.large_file_path), :>, 0)
assert_operator(File.size(post.preview_file_path), :>, 0)
end

View File

@@ -18,7 +18,7 @@ class UserFeedbackTest < ActiveSupport::TestCase
member = FactoryGirl.create(:user)
CurrentUser.user = gold
assert_difference("Dmail.count", 2) do
assert_difference("Dmail.count", 1) do
FactoryGirl.create(:user_feedback, :user => user)
end
end

View File

@@ -6,6 +6,12 @@ class UserNameChangeRequestTest < ActiveSupport::TestCase
@admin = FactoryGirl.create(:admin_user)
@requester = FactoryGirl.create(:user)
CurrentUser.user = @requester
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "approving a request" do
@@ -20,7 +26,7 @@ class UserNameChangeRequestTest < ActiveSupport::TestCase
end
should "create a dmail" do
assert_difference("Dmail.count", 4) do
assert_difference("Dmail.count", 2) do
@change_request.approve!
end
end
@@ -61,7 +67,7 @@ class UserNameChangeRequestTest < ActiveSupport::TestCase
end
should "create a dmail" do
assert_difference("Dmail.count", 2) do
assert_difference("Dmail.count", 1) do
@change_request.reject!("msg")
end
end