major bug fix with cache.rb, work on implication tests
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
require 'fileutils'
|
||||
|
||||
Factory.define(:pending_post) do |f|
|
||||
f.rating "s"
|
||||
f.uploader {|x| x.association(:user)}
|
||||
f.uploader_ip_addr "127.0.0.1"
|
||||
f.tag_string "special"
|
||||
f.status "pending"
|
||||
end
|
||||
|
||||
Factory.define(:downloadable_pending_post, :parent => :pending_post) do |f|
|
||||
f.source "http://www.google.com/intl/en_ALL/images/logo.gif"
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_jpg_pending_post, :parent => :pending_post) do |f|
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.jpg"
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_large_jpg_pending_post, :parent => :pending_post) do |f|
|
||||
f.file_ext "jpg"
|
||||
f.content_type "image/jpeg"
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test-large.jpg", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test-large.jpg"
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_png_pending_post, :parent => :pending_post) do |f|
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.png", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.png"
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_gif_pending_post, :parent => :pending_post) do |f|
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.gif", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.gif"
|
||||
end
|
||||
end
|
||||
5
test/factories/tag_implication.rb
Normal file
5
test/factories/tag_implication.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
Factory.define(:tag_implication) do |f|
|
||||
f.creator {|x| x.association(:user)}
|
||||
f.updater_id {|x| x.creator_id}
|
||||
f.updater_ip_addr "127.0.0.1"
|
||||
end
|
||||
@@ -8,18 +8,18 @@ Factory.define(:upload) do |f|
|
||||
f.status "pending"
|
||||
end
|
||||
|
||||
Factory.define(:downloadable_upload, :parent => :upload) do |f|
|
||||
Factory.define(:source_upload, :parent => :upload) do |f|
|
||||
f.source "http://www.google.com/intl/en_ALL/images/logo.gif"
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_jpg_upload, :parent => :upload) do |f|
|
||||
Factory.define(:jpg_upload, :parent => :upload) do |f|
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.jpg"
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_large_jpg_upload, :parent => :upload) do |f|
|
||||
Factory.define(:large_jpg_upload, :parent => :upload) do |f|
|
||||
f.file_ext "jpg"
|
||||
f.content_type "image/jpeg"
|
||||
f.file_path do
|
||||
@@ -28,14 +28,14 @@ Factory.define(:uploaded_large_jpg_upload, :parent => :upload) do |f|
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_png_upload, :parent => :upload) do |f|
|
||||
Factory.define(:png_upload, :parent => :upload) do |f|
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.png", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.png"
|
||||
end
|
||||
end
|
||||
|
||||
Factory.define(:uploaded_gif_upload, :parent => :upload) do |f|
|
||||
Factory.define(:gif_upload, :parent => :upload) do |f|
|
||||
f.file_path do
|
||||
FileUtils.cp("#{Rails.root}/test/files/test.gif", "#{Rails.root}/tmp")
|
||||
"#{Rails.root}/tmp/test.gif"
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class PendingPostTest < ActiveSupport::TestCase
|
||||
context "A pending post" do
|
||||
teardown do
|
||||
FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*"))
|
||||
end
|
||||
|
||||
context "image size calculator" do
|
||||
should "discover the dimensions for a JPG" do
|
||||
@pending_post = Factory.create(:uploaded_jpg_pending_post)
|
||||
assert_nothing_raised {@pending_post.calculate_dimensions(@pending_post.file_path)}
|
||||
assert_equal(500, @pending_post.image_width)
|
||||
assert_equal(335, @pending_post.image_height)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a PNG" do
|
||||
@pending_post = Factory.create(:uploaded_png_pending_post)
|
||||
assert_nothing_raised {@pending_post.calculate_dimensions(@pending_post.file_path)}
|
||||
assert_equal(768, @pending_post.image_width)
|
||||
assert_equal(1024, @pending_post.image_height)
|
||||
end
|
||||
|
||||
should "discover the dimensions for a GIF" do
|
||||
@pending_post = Factory.create(:uploaded_gif_pending_post)
|
||||
assert_nothing_raised {@pending_post.calculate_dimensions(@pending_post.file_path)}
|
||||
assert_equal(400, @pending_post.image_width)
|
||||
assert_equal(400, @pending_post.image_height)
|
||||
end
|
||||
end
|
||||
|
||||
context "content type calculator" do
|
||||
should "know how to parse jpeg, png, gif, and swf file extensions" do
|
||||
@pending_post = Factory.create(:uploaded_jpg_pending_post)
|
||||
assert_equal("image/jpeg", @pending_post.file_ext_to_content_type("test.jpeg"))
|
||||
assert_equal("image/gif", @pending_post.file_ext_to_content_type("test.gif"))
|
||||
assert_equal("image/png", @pending_post.file_ext_to_content_type("test.png"))
|
||||
assert_equal("application/x-shockwave-flash", @pending_post.file_ext_to_content_type("test.swf"))
|
||||
assert_equal("application/octet-stream", @pending_post.file_ext_to_content_type(""))
|
||||
end
|
||||
|
||||
should "know how to parse jpeg, png, gif, and swf content types" do
|
||||
@pending_post = Factory.create(:uploaded_jpg_pending_post)
|
||||
assert_equal("jpg", @pending_post.content_type_to_file_ext("image/jpeg"))
|
||||
assert_equal("gif", @pending_post.content_type_to_file_ext("image/gif"))
|
||||
assert_equal("png", @pending_post.content_type_to_file_ext("image/png"))
|
||||
assert_equal("swf", @pending_post.content_type_to_file_ext("application/x-shockwave-flash"))
|
||||
assert_equal("bin", @pending_post.content_type_to_file_ext(""))
|
||||
end
|
||||
end
|
||||
|
||||
context "downloader" do
|
||||
should "initialize the final path and content type after downloading a file" do
|
||||
@pending_post = Factory.create(:downloadable_pending_post)
|
||||
path = "#{Rails.root}/tmp/test.download.jpg"
|
||||
assert_nothing_raised {@pending_post.download_from_source(path)}
|
||||
assert(File.exists?(path))
|
||||
assert_equal(8558, File.size(path))
|
||||
assert_equal("image/gif", @pending_post.content_type)
|
||||
assert_equal(path, @pending_post.file_path)
|
||||
assert_equal("gif", @pending_post.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")
|
||||
@pending_post = PendingPost.new(:file => upload_jpeg("#{Rails.root}/tmp/test.jpg"))
|
||||
assert_nothing_raised {@pending_post.convert_cgi_file}
|
||||
assert_equal("image/jpeg", @pending_post.content_type)
|
||||
assert(File.exists?(@pending_post.file_path))
|
||||
assert_equal(28086, File.size(@pending_post.file_path))
|
||||
assert_equal("jpg", @pending_post.file_ext)
|
||||
end
|
||||
end
|
||||
|
||||
context "hash calculator" do
|
||||
should "caculate the hash" do
|
||||
@pending_post = Factory.create(:uploaded_jpg_pending_post)
|
||||
@pending_post.calculate_hash(@pending_post.file_path)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @pending_post.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
|
||||
@pending_post = Factory.create(:uploaded_large_jpg_pending_post)
|
||||
@pending_post.calculate_hash(@pending_post.file_path)
|
||||
@pending_post.calculate_dimensions(@pending_post.file_path)
|
||||
assert_nothing_raised {@pending_post.generate_resizes(@pending_post.file_path)}
|
||||
assert(File.exists?(@pending_post.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert_equal(6556, File.size(@pending_post.resized_file_path_for(Danbooru.config.small_image_width)))
|
||||
assert(File.exists?(@pending_post.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert_equal(39411, File.size(@pending_post.resized_file_path_for(Danbooru.config.medium_image_width)))
|
||||
assert(File.exists?(@pending_post.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
assert_equal(179324, File.size(@pending_post.resized_file_path_for(Danbooru.config.large_image_width)))
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for a downloaded image" do
|
||||
@pending_post = Factory.create(:downloadable_pending_post,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised {@pending_post.process!}
|
||||
end
|
||||
|
||||
post = Post.last
|
||||
assert_equal("hoge foo", post.tag_string)
|
||||
assert_equal("s", post.rating)
|
||||
assert_equal(@pending_post.uploader_id, post.uploader_id)
|
||||
assert_equal("127.0.0.1", post.uploader_ip_addr)
|
||||
assert_equal(@pending_post.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, @pending_post.post_id)
|
||||
assert_equal("finished", @pending_post.status)
|
||||
end
|
||||
end
|
||||
|
||||
should "process completely for an uploaded image" do
|
||||
@pending_post = Factory.create(:uploaded_jpg_pending_post,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
)
|
||||
@pending_post.file = upload_jpeg("#{Rails.root}/test/files/test.jpg")
|
||||
@pending_post.convert_cgi_file
|
||||
|
||||
assert_difference("Post.count") do
|
||||
assert_nothing_raised {@pending_post.process!}
|
||||
end
|
||||
post = Post.last
|
||||
assert_equal("hoge foo", post.tag_string)
|
||||
assert_equal("s", post.rating)
|
||||
assert_equal(@pending_post.uploader_id, post.uploader_id)
|
||||
assert_equal("127.0.0.1", post.uploader_ip_addr)
|
||||
assert_equal(@pending_post.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, @pending_post.post_id)
|
||||
assert_equal("finished", @pending_post.status)
|
||||
end
|
||||
end
|
||||
@@ -19,6 +19,8 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
tag2 = Factory.create(:tag, :name => "bbb")
|
||||
ta = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal("bbb", MEMCACHE.get("ta:aaa"))
|
||||
ta.destroy
|
||||
assert_nil(MEMCACHE.get("ta:aaa"))
|
||||
end
|
||||
|
||||
should "update any affected posts when saved" do
|
||||
@@ -33,5 +35,14 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
assert_equal("ccc bbb", post1.tag_string)
|
||||
assert_equal("ccc ddd", post2.tag_string)
|
||||
end
|
||||
|
||||
should "not validate for transitive relations" do
|
||||
ta1 = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_difference("TagAlias.count", 0) do
|
||||
ta3 = TagAlias.create(:antecedent_name => "bbb", :consequent_name => "ddd", :updater_id => ta1.creator_id, :updater_ip_addr => "127.0.0.1")
|
||||
assert(ta3.errors.any?, "Tag alias should be invalid")
|
||||
assert_equal("Tag alias can not create a transitive relation with another tag alias", ta3.errors.full_messages.join)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,45 @@
|
||||
require 'test_helper'
|
||||
require File.dirname(__FILE__) + '/../test_helper'
|
||||
|
||||
class TagImplicationTest < ActiveSupport::TestCase
|
||||
# Replace this with your real tests.
|
||||
test "the truth" do
|
||||
assert true
|
||||
context "A tag implication" do
|
||||
setup do
|
||||
MEMCACHE.flush_all
|
||||
@user = Factory.create(:user)
|
||||
end
|
||||
|
||||
should "clear the cache upon saving" do
|
||||
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal(["bbb"], ti1.descendant_names_array)
|
||||
assert_equal(["bbb"], MEMCACHE.get("ti:aaa"))
|
||||
ti1.update_attributes(
|
||||
:consequent_name => "ccc",
|
||||
:updater_id => @user.id,
|
||||
:updater_ip_addr => "127.0.0.1"
|
||||
)
|
||||
assert_nil(MEMCACHE.get("ti:aaa"))
|
||||
end
|
||||
|
||||
# should "clear the cache upon destruction" do
|
||||
# ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
# assert_equal("bbb", ti1.descendant_names)
|
||||
# assert_equal(["bbb"], ti1.descendant_names_array)
|
||||
# assert_equal(["bbb"], MEMCACHE.get("ti:aaa"))
|
||||
# ti1.destroy
|
||||
# assert_nil(MEMCACHE.get("ti:aaa"))
|
||||
# end
|
||||
#
|
||||
# should "calculate all its descendants" do
|
||||
# ti1 = Factory.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
|
||||
# assert_equal(["ccc"], ti1.descendant_names_array)
|
||||
# ti2 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
# assert_equal(["bbb", "ccc"], ti2.descendant_names_array)
|
||||
# ti1.reload
|
||||
# assert_equal(["ccc"], ti1.descendant_names_array)
|
||||
# end
|
||||
|
||||
should "cache its descendants"
|
||||
should "update its descendants on save"
|
||||
should "update the decendants for its parent on save"
|
||||
should "update any affected post upon save"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,21 +8,21 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "image size calculator" do
|
||||
should "discover the dimensions for a JPG" do
|
||||
@upload = Factory.create(:uploaded_jpg_upload)
|
||||
@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(:uploaded_png_upload)
|
||||
@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(:uploaded_gif_upload)
|
||||
@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)
|
||||
@@ -31,7 +31,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "content type calculator" do
|
||||
should "know how to parse jpeg, png, gif, and swf file extensions" do
|
||||
@upload = Factory.create(:uploaded_jpg_upload)
|
||||
@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"))
|
||||
@@ -40,7 +40,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "know how to parse jpeg, png, gif, and swf content types" do
|
||||
@upload = Factory.create(:uploaded_jpg_upload)
|
||||
@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"))
|
||||
@@ -51,7 +51,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "downloader" do
|
||||
should "initialize the final path and content type after downloading a file" do
|
||||
@upload = Factory.create(:downloadable_upload)
|
||||
@upload = Factory.create(:source_upload)
|
||||
path = "#{Rails.root}/tmp/test.download.jpg"
|
||||
assert_nothing_raised {@upload.download_from_source(path)}
|
||||
assert(File.exists?(path))
|
||||
@@ -76,7 +76,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
|
||||
context "hash calculator" do
|
||||
should "caculate the hash" do
|
||||
@upload = Factory.create(:uploaded_jpg_upload)
|
||||
@upload = Factory.create(:jpg_upload)
|
||||
@upload.calculate_hash(@upload.file_path)
|
||||
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @upload.md5)
|
||||
end
|
||||
@@ -91,7 +91,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "generate several resized versions of the image" do
|
||||
@upload = Factory.create(:uploaded_large_jpg_upload)
|
||||
@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)}
|
||||
@@ -105,7 +105,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for a downloaded image" do
|
||||
@upload = Factory.create(:downloadable_upload,
|
||||
@upload = Factory.create(:source_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
@@ -130,7 +130,7 @@ class UploadTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "process completely for an uploaded image" do
|
||||
@upload = Factory.create(:uploaded_jpg_upload,
|
||||
@upload = Factory.create(:jpg_upload,
|
||||
:rating => "s",
|
||||
:uploader_ip_addr => "127.0.0.1",
|
||||
:tag_string => "hoge foo"
|
||||
|
||||
Reference in New Issue
Block a user