Fixed some major bugs with implications, cleaning up the cache
expiration process and adding some additional tests. Cleaned up the unit tests. They should all run cleanly with rake test:units now.
This commit is contained in:
@@ -48,7 +48,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
should "parse urls" do
|
||||
artist = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg http://aaa.com")
|
||||
artist.reload
|
||||
assert_equal(["http://aaa.com", "http://rembrandt.com/test.jpg"], artist.artist_urls.map(&:to_s).sort)
|
||||
assert_equal(["http://aaa.com", "http://rembrandt.com/test.jpg"], artist.urls.map(&:to_s).sort)
|
||||
end
|
||||
|
||||
should "make sure old urls are deleted" do
|
||||
@@ -56,7 +56,7 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
artist.url_string = "http://not.rembrandt.com/test.jpg"
|
||||
artist.save
|
||||
artist.reload
|
||||
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.artist_urls.map(&:to_s).sort)
|
||||
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.urls.map(&:to_s).sort)
|
||||
end
|
||||
|
||||
should "find matches by url" do
|
||||
|
||||
@@ -521,11 +521,15 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the <uploader> metatag" do
|
||||
user = Factory.create(:user)
|
||||
post1 = Factory.create(:post, :uploader => user)
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
relation = Post.find_by_tags("uploader:#{user.name}")
|
||||
second_user = Factory.create(:user)
|
||||
post1 = Factory.create(:post)
|
||||
|
||||
CurrentUser.scoped(second_user, "127.0.0.2") do
|
||||
post2 = Factory.create(:post)
|
||||
post3 = Factory.create(:post)
|
||||
end
|
||||
|
||||
relation = Post.find_by_tags("uploader:#{CurrentUser.user.name}")
|
||||
assert_equal(1, relation.count)
|
||||
assert_equal(post1.id, relation.first.id)
|
||||
end
|
||||
|
||||
@@ -14,6 +14,11 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
should "populate the creator information" do
|
||||
ta = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal(CurrentUser.user.id, ta.creator_id)
|
||||
end
|
||||
|
||||
should "convert a tag to its normalized version" do
|
||||
tag1 = Factory.create(:tag, :name => "aaa")
|
||||
tag2 = Factory.create(:tag, :name => "bbb")
|
||||
@@ -53,5 +58,17 @@ class TagAliasTest < ActiveSupport::TestCase
|
||||
assert_equal("Tag alias can not create a transitive relation with another tag alias", ta3.errors.full_messages.join)
|
||||
end
|
||||
end
|
||||
|
||||
should "record the alias's creator in the tag history" do
|
||||
user = Factory.create(:user)
|
||||
p1 = nil
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
p1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
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_equal(ta1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,11 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
should "populate the creator information" do
|
||||
ti = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
assert_equal(CurrentUser.user.id, ti.creator_id)
|
||||
end
|
||||
|
||||
should "not validate when a circular relation is created" do
|
||||
ti1 = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
ti2 = Factory.build(:tag_implication, :antecedent_name => "bbb", :consequent_name => "aaa")
|
||||
@@ -38,7 +43,7 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
ti1.update_attributes(
|
||||
:consequent_name => "ccc"
|
||||
)
|
||||
assert_nil(MEMCACHE.get("ti:aaa"))
|
||||
assert_equal(["ccc"], MEMCACHE.get("ti:aaa"))
|
||||
end
|
||||
|
||||
should "clear the cache upon destruction" do
|
||||
@@ -99,5 +104,17 @@ class TagImplicationTest < ActiveSupport::TestCase
|
||||
p1.reload
|
||||
assert_equal("aaa yyy xxx bbb ccc", p1.tag_string)
|
||||
end
|
||||
|
||||
should "record the implication's creator in the tag history" do
|
||||
user = Factory.create(:user)
|
||||
p1 = nil
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
p1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
|
||||
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_equal(ti1.creator_id, p1.versions.last.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,6 +11,8 @@ class UploadTest < ActiveSupport::TestCase
|
||||
teardown do
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
|
||||
@upload.delete_temp_file if @upload
|
||||
end
|
||||
|
||||
context "An upload" do
|
||||
@@ -165,4 +167,15 @@ class UploadTest < ActiveSupport::TestCase
|
||||
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
|
||||
|
||||
@@ -28,8 +28,6 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
|
||||
should "create versions" do
|
||||
wp = nil
|
||||
user = Factory.create(:user)
|
||||
reverter = Factory.create(:user)
|
||||
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
wp = Factory.create(:wiki_page, :title => "xxx")
|
||||
@@ -37,15 +35,29 @@ class WikiPageTest < ActiveSupport::TestCase
|
||||
|
||||
assert_difference("WikiPageVersion.count") do
|
||||
wp.title = "yyy"
|
||||
wp.updater_id = user.id
|
||||
wp.updater_ip_addr = "127.0.0.1"
|
||||
wp.save
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
should "revert to a prior version" do
|
||||
wp = Factory.create(:wiki_page, :title => "xxx")
|
||||
wp.title = "yyy"
|
||||
wp.save
|
||||
version = WikiPageVersion.first
|
||||
wp.revert_to!(version, reverter.id, "127.0.0.1")
|
||||
|
||||
wp.revert_to!(version)
|
||||
wp.reload
|
||||
assert_equal("xxx", wp.title)
|
||||
end
|
||||
|
||||
should "differentiate between updater and creator" do
|
||||
user = Factory.create(:user)
|
||||
wp = Factory.create(:wiki_page, :title => "xxx")
|
||||
CurrentUser.scoped(user, "127.0.0.1") do
|
||||
wp.title = "yyy"
|
||||
wp.save
|
||||
end
|
||||
version = WikiPageVersion.first
|
||||
assert_not_equal(wp.creator_id, version.updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user