fixing tests
This commit is contained in:
@@ -2,7 +2,7 @@ require 'fileutils'
|
||||
|
||||
Factory.define(:upload) do |f|
|
||||
f.rating "s"
|
||||
f.uploader {|x| x.association(:user, :is_contributor => true)}
|
||||
f.uploader {|x| x.association(:user, :level => 200)}
|
||||
f.uploader_ip_addr "127.0.0.1"
|
||||
f.tag_string "special"
|
||||
f.status "pending"
|
||||
|
||||
@@ -13,21 +13,21 @@ Factory.define(:banned_user, :parent => :user) do |f|
|
||||
end
|
||||
|
||||
Factory.define(:privileged_user, :parent => :user) do |f|
|
||||
f.is_privileged true
|
||||
f.level 100
|
||||
end
|
||||
|
||||
Factory.define(:contributor_user, :parent => :user) do |f|
|
||||
f.is_contributor true
|
||||
f.level 200
|
||||
end
|
||||
|
||||
Factory.define(:janitor_user, :parent => :user) do |f|
|
||||
f.is_janitor true
|
||||
f.level 300
|
||||
end
|
||||
|
||||
Factory.define(:moderator_user, :parent => :user) do |f|
|
||||
f.is_moderator true
|
||||
f.level 400
|
||||
end
|
||||
|
||||
Factory.define(:admin_user, :parent => :user) do |f|
|
||||
f.is_admin true
|
||||
f.level 500
|
||||
end
|
||||
|
||||
@@ -25,16 +25,11 @@ module PostSets
|
||||
context "a favorite set for before the most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.model_for(@user.id).where(:user_id => @user.id, :post_id => @post_3.id).first.id
|
||||
@set = PostSets::Base.new(:id => @user.id, :before_id => id)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set.extend(PostSets::Favorite)
|
||||
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, "b#{id}")
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Sequential)
|
||||
end
|
||||
|
||||
should "return the second most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
@@ -45,35 +40,25 @@ module PostSets
|
||||
context "a favorite set for after the second most recent post" do
|
||||
setup do
|
||||
id = ::Favorite.model_for(@user.id).where(:user_id => @user.id, :post_id => @post_2.id).first.id
|
||||
@set = PostSets::Base.new(:id => @user.id, :after_id => id)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set.extend(PostSets::Favorite)
|
||||
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, "a#{id}")
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Sequential)
|
||||
end
|
||||
|
||||
should "return the most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a favorite set for page 2" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:id => @user.id, :page => 2)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set.extend(PostSets::Favorite)
|
||||
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id, 2)
|
||||
end
|
||||
|
||||
context "a numbered paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Numbered)
|
||||
end
|
||||
|
||||
should "return the second most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
@@ -83,32 +68,13 @@ module PostSets
|
||||
|
||||
context "a favorite set with no page specified" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:id => @user.id)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set.extend(PostSets::Favorite)
|
||||
::Favorite.model_for(@user.id).stubs(:records_per_page).returns(1)
|
||||
@set = PostSets::Favorite.new(@user.id)
|
||||
end
|
||||
|
||||
context "a numbered paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Numbered)
|
||||
end
|
||||
|
||||
should "return the most recent element" do
|
||||
assert_equal(3, @set.count)
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "a sequential paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Sequential)
|
||||
end
|
||||
|
||||
should "return the most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
should "return the most recent element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,40 +25,33 @@ module PostSets
|
||||
|
||||
context "a post pool set for page 2" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:id => @pool.id, :page => 2)
|
||||
@set = PostSets::Pool.new(@pool, 2)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set.extend(PostSets::Pool)
|
||||
end
|
||||
|
||||
context "a numbered paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Numbered)
|
||||
end
|
||||
|
||||
should "return the second element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
should "return the second element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_1.id, @set.posts.first.id)
|
||||
end
|
||||
|
||||
should "know the total number of pages" do
|
||||
assert_equal(3, @set.total_pages)
|
||||
end
|
||||
|
||||
should "know the current page" do
|
||||
assert_equal(2, @set.current_page)
|
||||
end
|
||||
end
|
||||
|
||||
context "a post pool set with no page specified" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:id => @pool.id)
|
||||
@set = PostSets::Pool.new(@pool)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set.extend(PostSets::Pool)
|
||||
end
|
||||
|
||||
context "a numbered paginator" do
|
||||
setup do
|
||||
@set.extend(PostSets::Numbered)
|
||||
end
|
||||
|
||||
should "return the first element" do
|
||||
assert_equal(3, @set.count)
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_2.id, @set.posts.first.id)
|
||||
end
|
||||
should "return the first element" do
|
||||
assert_equal(1, @set.posts.size)
|
||||
assert_equal(@post_2.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require_relative '../../test_helper'
|
||||
require "danbooru/paginator/pagination_error"
|
||||
|
||||
module PostSets
|
||||
class PostTest < ActiveSupport::TestCase
|
||||
@@ -19,12 +20,10 @@ module PostSets
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "a numbered set for page 2" do
|
||||
context "a set for page 2" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:page => 2)
|
||||
@set.extend(PostSets::Sequential)
|
||||
@set.extend(PostSets::Post)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set = PostSets::Post.new("", 2)
|
||||
::Post.stubs(:records_per_page).returns(1)
|
||||
end
|
||||
|
||||
should "return the second element" do
|
||||
@@ -32,18 +31,16 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
context "a sequential set for the 'a' tag query" do
|
||||
context "a set for the 'a' tag query" do
|
||||
setup do
|
||||
@post_4 = Factory.create(:post, :tag_string => "a")
|
||||
@post_5 = Factory.create(:post, :tag_string => "a")
|
||||
end
|
||||
|
||||
context "with no before_id parameter" do
|
||||
context "with no page" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "a")
|
||||
@set.extend(PostSets::Sequential)
|
||||
@set.extend(PostSets::Post)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set = PostSets::Post.new("a")
|
||||
::Post.stubs(:records_per_page).returns(1)
|
||||
end
|
||||
|
||||
should "return the first element" do
|
||||
@@ -51,12 +48,10 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
context "with a before_id parameter for the first element" do
|
||||
context "for before the first element" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "a", :before_id => @post_5.id)
|
||||
@set.extend(PostSets::Sequential)
|
||||
@set.extend(PostSets::Post)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set = PostSets::Post.new("a", "b#{@post_5.id}")
|
||||
::Post.stubs(:records_per_page).returns(1)
|
||||
end
|
||||
|
||||
should "return the second element" do
|
||||
@@ -64,12 +59,10 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
context "with an after_id parameter for the second element" do
|
||||
context "for after the second element" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "a", :after_id => @post_4.id)
|
||||
@set.extend(PostSets::Sequential)
|
||||
@set.extend(PostSets::Post)
|
||||
@set.stubs(:limit).returns(1)
|
||||
@set = PostSets::Post.new("a", "a#{@post_4.id}")
|
||||
@set.stubs(:records_per_page).returns(1)
|
||||
end
|
||||
|
||||
should "return the first element" do
|
||||
@@ -78,11 +71,9 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
context "a new numbered set for the 'a b' tag query" do
|
||||
context "a set for the 'a b' tag query" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "a b")
|
||||
@set.extend(PostSets::Numbered)
|
||||
@set.extend(PostSets::Post)
|
||||
@set = PostSets::Post.new("a b")
|
||||
end
|
||||
|
||||
should "know it isn't a single tag" do
|
||||
@@ -90,31 +81,27 @@ module PostSets
|
||||
end
|
||||
end
|
||||
|
||||
context "a new numbered set going to the 1,001st page" do
|
||||
context "a set going to the 1,001st page" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "a", :page => 1_001)
|
||||
@set.extend(PostSets::Numbered)
|
||||
@set.extend(PostSets::Post)
|
||||
@set = PostSets::Post.new("a", 1_001)
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
assert_raises(PostSets::Error) do
|
||||
@set.validate
|
||||
should "fail" do
|
||||
assert_raises(Danbooru::Paginator::PaginationError) do
|
||||
@set.posts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a new numbered set for the 'a b c' tag query" do
|
||||
context "a set for the 'a b c' tag query" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "a b c")
|
||||
@set.extend(PostSets::Numbered)
|
||||
@set.extend(PostSets::Post)
|
||||
@set = PostSets::Post.new("a b c")
|
||||
end
|
||||
|
||||
context "for a non-privileged user" do
|
||||
should "not validate" do
|
||||
assert_raises(PostSets::Error) do
|
||||
@set.validate
|
||||
should "fail" do
|
||||
assert_raises(PostSets::SearchError) do
|
||||
@set.posts
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -124,25 +111,17 @@ module PostSets
|
||||
CurrentUser.user = Factory.create(:privileged_user)
|
||||
end
|
||||
|
||||
should "not validate" do
|
||||
should "pass" do
|
||||
assert_nothing_raised do
|
||||
@set.validate
|
||||
@set.posts
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a new numbered set for the 'a' tag query" do
|
||||
context "a set for the 'a' tag query" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:tags => "A")
|
||||
@set.extend(PostSets::Numbered)
|
||||
@set.extend(PostSets::Post)
|
||||
end
|
||||
|
||||
should "validate" do
|
||||
assert_nothing_raised do
|
||||
@set.validate
|
||||
end
|
||||
@set = PostSets::Post.new("a")
|
||||
end
|
||||
|
||||
should "know it is a single tag" do
|
||||
@@ -153,8 +132,8 @@ module PostSets
|
||||
assert_equal("a", @set.tag_string)
|
||||
end
|
||||
|
||||
should "find the count" do
|
||||
assert_equal(1, @set.count)
|
||||
should "know the count" do
|
||||
assert_equal(1, @set.posts.total_count)
|
||||
end
|
||||
|
||||
should "find the posts" do
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
require 'test_helper'
|
||||
|
||||
module PostSets
|
||||
class WikiPageTest < ActiveSupport::TestCase
|
||||
context "In all cases" do
|
||||
setup do
|
||||
@user = Factory.create(:user)
|
||||
CurrentUser.user = @user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
|
||||
@wiki_page = Factory.create(:wiki_page, :title => "a")
|
||||
@post_1 = Factory.create(:post, :tag_string => "a")
|
||||
@post_2 = Factory.create(:post, :tag_string => "a")
|
||||
@post_3 = Factory.create(:post, :tag_string => "a")
|
||||
end
|
||||
|
||||
context "a numbered wiki page set" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:page => 2, :id => @wiki_page.id)
|
||||
@set.extend(PostSets::Numbered)
|
||||
@set.extend(PostSets::WikiPage)
|
||||
@set.stubs(:limit).returns(1)
|
||||
end
|
||||
|
||||
should "return the count" do
|
||||
assert_equal(3, @set.count)
|
||||
end
|
||||
end
|
||||
|
||||
context "a sequential wiki page set" do
|
||||
context "with a before_id for the first element" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:id => @wiki_page.id, :before_id => @post_3.id)
|
||||
@set.extend(PostSets::Sequential)
|
||||
@set.extend(PostSets::WikiPage)
|
||||
@set.stubs(:limit).returns(1)
|
||||
end
|
||||
|
||||
should "return the second element" do
|
||||
assert_equal(@post_2.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
context "with an after_id for the second element" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:after_id => @post_2.id, :id => @wiki_page.id)
|
||||
@set.extend(PostSets::Sequential)
|
||||
@set.extend(PostSets::WikiPage)
|
||||
@set.stubs(:limit).returns(1)
|
||||
end
|
||||
|
||||
should "return the first element" do
|
||||
assert_equal(@post_3.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "a numbered wiki page set for page 2" do
|
||||
setup do
|
||||
@set = PostSets::Base.new(:page => 2, :id => @wiki_page.id)
|
||||
@set.extend(PostSets::Numbered)
|
||||
@set.extend(PostSets::WikiPage)
|
||||
@set.stubs(:limit).returns(1)
|
||||
end
|
||||
|
||||
should "return the second element" do
|
||||
assert_equal(@post_2.id, @set.posts.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -178,13 +178,13 @@ class PostTest < ActiveSupport::TestCase
|
||||
should "preserve the approver's identity when approved" do
|
||||
post = Factory.create(:post, :is_pending => true)
|
||||
post.approve!
|
||||
assert_equal("approver:#{CurrentUser.name}", post.approver_string)
|
||||
assert_equal(post.approver_id, CurrentUser.id)
|
||||
end
|
||||
|
||||
context "that was previously approved by person X" do
|
||||
should "not allow person X to reapprove that post" do
|
||||
user = Factory.create(:janitor_user, :name => "xxx")
|
||||
post = Factory.create(:post, :approver_string => "approver:xxx")
|
||||
post = Factory.create(:post, :approver_id => user.id)
|
||||
post.flag!("bad")
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
assert_raises(Post::ApprovalError) do
|
||||
@@ -396,10 +396,10 @@ class PostTest < ActiveSupport::TestCase
|
||||
user3 = Factory.create(:user)
|
||||
|
||||
post.uploader = user1
|
||||
assert_equal("uploader:#{user1.id}", post.uploader_string)
|
||||
assert_equal(user1.id, post.uploader_id)
|
||||
|
||||
post.uploader_id = user2.id
|
||||
assert_equal("uploader:#{user2.id}", post.uploader_string)
|
||||
assert_equal(user2.id, post.uploader_id)
|
||||
assert_equal(user2.id, post.uploader_id)
|
||||
assert_equal(user2.name, post.uploader_name)
|
||||
end
|
||||
@@ -493,13 +493,15 @@ class PostTest < ActiveSupport::TestCase
|
||||
|
||||
should "return posts for the <uploader> metatag" do
|
||||
second_user = Factory.create(:user)
|
||||
post1 = Factory.create(:post)
|
||||
post1 = Factory.create(:post, :uploader => CurrentUser.user)
|
||||
|
||||
assert_equal(CurrentUser.id, post1.uploader_id)
|
||||
|
||||
CurrentUser.scoped(second_user, "127.0.0.2") do
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
end
|
||||
|
||||
|
||||
relation = Post.tag_match("uploader:#{CurrentUser.user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
|
||||
@@ -67,7 +67,7 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
end
|
||||
ta1 = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
p1.reload
|
||||
assert_not_equal("uploader:#{ta1.creator_id}", p1.uploader_string)
|
||||
assert_not_equal(ta1.creator_id, p1.uploader_id)
|
||||
assert_equal(ta1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -113,7 +113,7 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
end
|
||||
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
|
||||
p1.reload
|
||||
assert_not_equal("uploader:#{ti1.creator_id}", p1.uploader_string)
|
||||
assert_not_equal(ti1.creator_id, p1.uploader_id)
|
||||
assert_equal(ti1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,181 +1,183 @@
|
||||
require_relative '../test_helper'
|
||||
|
||||
class UploadTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
user = Factory.create(:contributor_user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
|
||||
@upload.delete_temp_file if @upload
|
||||
end
|
||||
|
||||
context "An upload" do
|
||||
context "In all cases" do
|
||||
setup do
|
||||
user = Factory.create(:contributor_user)
|
||||
CurrentUser.user = user
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
end
|
||||
|
||||
teardown do
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*"))
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
|
||||
@upload.delete_temp_file if @upload
|
||||
end
|
||||
|
||||
context "image size calculator" do
|
||||
should "discover the dimensions for a JPG" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
|
||||
assert_equal(500, @upload.image_width)
|
||||
assert_equal(335, @upload.image_height)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a PNG" do
|
||||
@upload = Factory.create(:png_upload)
|
||||
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
|
||||
assert_equal(768, @upload.image_width)
|
||||
assert_equal(1024, @upload.image_height)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a GIF" do
|
||||
@upload = Factory.create(:gif_upload)
|
||||
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
|
||||
assert_equal(400, @upload.image_width)
|
||||
assert_equal(400, @upload.image_height)
|
||||
end
|
||||
end
|
||||
|
||||
context "content type calculator" do
|
||||
should "know how to parse jpeg, png, gif, and swf file extensions" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
assert_equal("image/jpeg", @upload.file_ext_to_content_type("test.jpeg"))
|
||||
assert_equal("image/gif", @upload.file_ext_to_content_type("test.gif"))
|
||||
assert_equal("image/png", @upload.file_ext_to_content_type("test.png"))
|
||||
assert_equal("application/x-shockwave-flash", @upload.file_ext_to_content_type("test.swf"))
|
||||
assert_equal("application/octet-stream", @upload.file_ext_to_content_type(""))
|
||||
end
|
||||
|
||||
should "know how to parse jpeg, png, gif, and swf content types" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
assert_equal("jpg", @upload.content_type_to_file_ext("image/jpeg"))
|
||||
assert_equal("gif", @upload.content_type_to_file_ext("image/gif"))
|
||||
assert_equal("png", @upload.content_type_to_file_ext("image/png"))
|
||||
assert_equal("swf", @upload.content_type_to_file_ext("application/x-shockwave-flash"))
|
||||
assert_equal("bin", @upload.content_type_to_file_ext(""))
|
||||
end
|
||||
end
|
||||
|
||||
context "downloader" do
|
||||
should "initialize the final path and content type after downloading a file" do
|
||||
@upload = Factory.create(:source_upload)
|
||||
path = "#{Rails.root}/tmp/test.download.jpg"
|
||||
assert_nothing_raised {@upload.download_from_source(path)}
|
||||
assert(File.exists?(path))
|
||||
assert_equal(8558, File.size(path))
|
||||
assert_equal("image/gif", @upload.content_type)
|
||||
assert_equal(path, @upload.file_path)
|
||||
assert_equal("gif", @upload.file_ext)
|
||||
end
|
||||
end
|
||||
|
||||
context "file processor" do
|
||||
should "parse and process a cgi file representation" do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
||||
@upload = Upload.new(:file => upload_jpeg("#{Rails.root}/tmp/test.jpg"))
|
||||
assert_nothing_raised {@upload.convert_cgi_file}
|
||||
assert_equal("image/jpeg", @upload.content_type)
|
||||
assert(File.exists?(@upload.file_path))
|
||||
assert_equal(28086, File.size(@upload.file_path))
|
||||
assert_equal("jpg", @upload.file_ext)
|
||||
end
|
||||
end
|
||||
|
||||
context "hash calculator" do
|
||||
should "caculate the hash" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @upload.md5)
|
||||
end
|
||||
end
|
||||
|
||||
context "resizer" do
|
||||
context "An upload" do
|
||||
teardown do
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/thumb/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/medium/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/large/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/original/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*"))
|
||||
end
|
||||
|
||||
should "generate several resized versions of the image" do
|
||||
@upload = Factory.create(:large_jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
@upload.calculate_dimensions(@upload.file_path)
|
||||
assert_nothing_raised {@upload.generate_resizes(@upload.file_path)}
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert_equal(6556, File.size(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert_equal(39411, File.size(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
assert_equal(179324, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
|
||||
context "image size calculator" do
|
||||
should "discover the dimensions for a JPG" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
|
||||
assert_equal(500, @upload.image_width)
|
||||
assert_equal(335, @upload.image_height)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a PNG" do
|
||||
@upload = Factory.create(:png_upload)
|
||||
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
|
||||
assert_equal(768, @upload.image_width)
|
||||
assert_equal(1024, @upload.image_height)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a GIF" do
|
||||
@upload = Factory.create(:gif_upload)
|
||||
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
|
||||
assert_equal(400, @upload.image_width)
|
||||
assert_equal(400, @upload.image_height)
|
||||
end
|
||||
end
|
||||
|
||||
context "content type calculator" do
|
||||
should "know how to parse jpeg, png, gif, and swf file extensions" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
assert_equal("image/jpeg", @upload.file_ext_to_content_type("test.jpeg"))
|
||||
assert_equal("image/gif", @upload.file_ext_to_content_type("test.gif"))
|
||||
assert_equal("image/png", @upload.file_ext_to_content_type("test.png"))
|
||||
assert_equal("application/x-shockwave-flash", @upload.file_ext_to_content_type("test.swf"))
|
||||
assert_equal("application/octet-stream", @upload.file_ext_to_content_type(""))
|
||||
end
|
||||
|
||||
should "know how to parse jpeg, png, gif, and swf content types" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
assert_equal("jpg", @upload.content_type_to_file_ext("image/jpeg"))
|
||||
assert_equal("gif", @upload.content_type_to_file_ext("image/gif"))
|
||||
assert_equal("png", @upload.content_type_to_file_ext("image/png"))
|
||||
assert_equal("swf", @upload.content_type_to_file_ext("application/x-shockwave-flash"))
|
||||
assert_equal("bin", @upload.content_type_to_file_ext(""))
|
||||
end
|
||||
end
|
||||
|
||||
context "downloader" do
|
||||
should "initialize the final path and content type after downloading a file" do
|
||||
@upload = Factory.create(:source_upload)
|
||||
path = "#{Rails.root}/tmp/test.download.jpg"
|
||||
assert_nothing_raised {@upload.download_from_source(path)}
|
||||
assert(File.exists?(path))
|
||||
assert_equal(8558, File.size(path))
|
||||
assert_equal("image/gif", @upload.content_type)
|
||||
assert_equal(path, @upload.file_path)
|
||||
assert_equal("gif", @upload.file_ext)
|
||||
end
|
||||
end
|
||||
|
||||
context "file processor" do
|
||||
should "parse and process a cgi file representation" do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
||||
@upload = Upload.new(:file => upload_jpeg("#{Rails.root}/tmp/test.jpg"))
|
||||
assert_nothing_raised {@upload.convert_cgi_file}
|
||||
assert_equal("image/jpeg", @upload.content_type)
|
||||
assert(File.exists?(@upload.file_path))
|
||||
assert_equal(28086, File.size(@upload.file_path))
|
||||
assert_equal("jpg", @upload.file_ext)
|
||||
end
|
||||
end
|
||||
|
||||
context "hash calculator" do
|
||||
should "caculate the hash" do
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @upload.md5)
|
||||
end
|
||||
end
|
||||
|
||||
context "resizer" do
|
||||
teardown do
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/thumb/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/medium/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/large/test.*.jpg"))
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/data/original/test.*.jpg"))
|
||||
end
|
||||
|
||||
should "generate several resized versions of the image" do
|
||||
@upload = Factory.create(:large_jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
@upload.calculate_dimensions(@upload.file_path)
|
||||
assert_nothing_raised {@upload.generate_resizes(@upload.file_path)}
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert_equal(6556, File.size(@upload.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert_equal(39411, File.size(@upload.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert(File.exists?(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
assert_equal(179324, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for a downloaded image" do
|
||||
@upload = Factory.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised {@upload.process!}
|
||||
end
|
||||
|
||||
post = Post.last
|
||||
assert_equal("hoge foo", post.tag_string)
|
||||
assert_equal("s", post.rating)
|
||||
assert_equal(@upload.uploader_id, post.uploader_id)
|
||||
assert_equal("127.0.0.1", post.uploader_ip_addr)
|
||||
assert_equal(@upload.md5, post.md5)
|
||||
assert_equal("gif", post.file_ext)
|
||||
assert_equal(276, post.image_width)
|
||||
assert_equal(110, post.image_height)
|
||||
assert_equal(8558, post.file_size)
|
||||
assert_equal(post.id, @upload.post_id)
|
||||
assert_equal("completed", @upload.status)
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for a downloaded image" do
|
||||
@upload = Factory.create(:source_upload,
|
||||
|
||||
should "process completely for an uploaded image" do
|
||||
@upload = Factory.create(:jpg_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
@upload.file = upload_jpeg("#{Rails.root}/test/files/test.jpg")
|
||||
@upload.convert_cgi_file
|
||||
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised {@upload.process!}
|
||||
end
|
||||
|
||||
post = Post.last
|
||||
assert_equal("hoge foo", post.tag_string)
|
||||
assert_equal("s", post.rating)
|
||||
assert_equal(@upload.uploader_id, post.uploader_id)
|
||||
assert_equal("127.0.0.1", post.uploader_ip_addr)
|
||||
assert_equal(@upload.md5, post.md5)
|
||||
assert_equal("gif", post.file_ext)
|
||||
assert_equal(276, post.image_width)
|
||||
assert_equal(110, post.image_height)
|
||||
assert_equal(8558, post.file_size)
|
||||
assert_equal("jpg", post.file_ext)
|
||||
assert(File.exists?(post.file_path))
|
||||
assert_equal(28086, File.size(post.file_path))
|
||||
assert_equal(post.id, @upload.post_id)
|
||||
assert_equal("completed", @upload.status)
|
||||
assert_equal("completed", @upload.status)
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for an uploaded image" do
|
||||
@upload = Factory.create(:jpg_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
@upload.file = upload_jpeg("#{Rails.root}/test/files/test.jpg")
|
||||
@upload.convert_cgi_file
|
||||
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised {@upload.process!}
|
||||
should "delete the temporary file upon completion" do
|
||||
@upload = Factory.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
|
||||
@upload.process!
|
||||
assert(!File.exists?(@upload.temp_file_path))
|
||||
end
|
||||
post = Post.last
|
||||
assert_equal("hoge foo", post.tag_string)
|
||||
assert_equal("s", post.rating)
|
||||
assert_equal(@upload.uploader_id, post.uploader_id)
|
||||
assert_equal("127.0.0.1", post.uploader_ip_addr)
|
||||
assert_equal(@upload.md5, post.md5)
|
||||
assert_equal("jpg", post.file_ext)
|
||||
assert(File.exists?(post.file_path))
|
||||
assert_equal(28086, File.size(post.file_path))
|
||||
assert_equal(post.id, @upload.post_id)
|
||||
assert_equal("completed", @upload.status)
|
||||
end
|
||||
|
||||
should "delete the temporary file upon completion" do
|
||||
@upload = Factory.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
|
||||
@upload.process!
|
||||
assert(!File.exists?(@upload.temp_file_path))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,9 +24,9 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
should "limit post uploads" do
|
||||
assert(!@user.can_upload?)
|
||||
@user.update_attribute(:is_contributor, true)
|
||||
@user.update_column(:level, User::Levels::CONTRIBUTOR)
|
||||
assert(@user.can_upload?)
|
||||
@user.update_attribute(:is_contributor, false)
|
||||
@user.update_column(:level, User::Levels::MEMBER)
|
||||
|
||||
40.times do
|
||||
Factory.create(:post, :uploader => @user, :is_deleted => true)
|
||||
@@ -49,10 +49,10 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
should "limit comments" do
|
||||
assert(!@user.can_comment?)
|
||||
@user.update_attribute(:is_privileged, true)
|
||||
@user.update_column(:level, User::Levels::PRIVILEGED)
|
||||
assert(@user.can_comment?)
|
||||
@user.update_attribute(:is_privileged, false)
|
||||
@user.update_attribute(:created_at, 1.year.ago)
|
||||
@user.update_column(:level, User::Levels::MEMBER)
|
||||
@user.update_column(:created_at, 1.year.ago)
|
||||
assert(@user.can_comment?)
|
||||
(Danbooru.config.member_comment_limit).times do
|
||||
Factory.create(:comment)
|
||||
@@ -79,34 +79,34 @@ class UserTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "normalize its level" do
|
||||
user = Factory.create(:user, :is_admin => true)
|
||||
user = Factory.create(:user, :level => User::Levels::ADMIN)
|
||||
assert(user.is_moderator?)
|
||||
assert(user.is_janitor?)
|
||||
assert(user.is_contributor?)
|
||||
assert(user.is_privileged?)
|
||||
|
||||
user = Factory.create(:user, :is_moderator => true)
|
||||
user = Factory.create(:user, :level => User::Levels::MODERATOR)
|
||||
assert(!user.is_admin?)
|
||||
assert(user.is_moderator?)
|
||||
assert(user.is_janitor?)
|
||||
assert(!user.is_contributor?)
|
||||
assert(user.is_contributor?)
|
||||
assert(user.is_privileged?)
|
||||
|
||||
user = Factory.create(:user, :is_janitor => true)
|
||||
user = Factory.create(:user, :level => User::Levels::JANITOR)
|
||||
assert(!user.is_admin?)
|
||||
assert(!user.is_moderator?)
|
||||
assert(user.is_janitor?)
|
||||
assert(!user.is_contributor?)
|
||||
assert(user.is_privileged?)
|
||||
|
||||
user = Factory.create(:user, :is_contributor => true)
|
||||
user = Factory.create(:user, :level => User::Levels::CONTRIBUTOR)
|
||||
assert(!user.is_admin?)
|
||||
assert(!user.is_moderator?)
|
||||
assert(!user.is_janitor?)
|
||||
assert(user.is_contributor?)
|
||||
assert(user.is_privileged?)
|
||||
|
||||
user = Factory.create(:user, :is_privileged => true)
|
||||
user = Factory.create(:user, :level => User::LEvels::PRIVILEGED)
|
||||
assert(!user.is_admin?)
|
||||
assert(!user.is_moderator?)
|
||||
assert(!user.is_janitor?)
|
||||
@@ -133,8 +133,8 @@ class UserTest < ActiveSupport::TestCase
|
||||
|
||||
should "be updated" do
|
||||
@user = Factory.create(:user)
|
||||
@user.update_attribute(:name, "danzig")
|
||||
assert_equal("danzig", User.id_to_name(@user.id))
|
||||
@user.update_column(:name, "danzig")
|
||||
assert_equal(@user.name, User.id_to_name(@user.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user