Kill trailing whitespace in ruby files

This commit is contained in:
小太
2013-03-19 23:10:10 +11:00
parent c107f96cec
commit cba839ba76
319 changed files with 2710 additions and 2710 deletions

View File

@@ -6,11 +6,11 @@ class AdvertisementTest < ActiveSupport::TestCase
Danbooru.config.stubs(:advertisement_path).returns("/tmp")
@ad = FactoryGirl.create(:advertisement, :file => upload_jpeg("#{Rails.root}/test/files/test.jpg"))
end
teardown do
FileUtils.rm_f(Dir.glob("#{Rails.root}/public/images/advertisements/*.jpg"))
end
should "create new hit records" do
assert_difference("AdvertisementHit.count") do
@ad.hit!("0.0.0.0")
@@ -20,7 +20,7 @@ class AdvertisementTest < ActiveSupport::TestCase
assert_equal(1, @ad.hit_sum(1.day.ago, 1.day.from_now))
assert_equal(0, @ad.hit_sum(2.days.ago, 1.day.ago))
end
should "know its preview height and preview width" do
assert_equal(100, @ad.preview_width)
assert_equal(67, @ad.preview_height)

View File

@@ -7,44 +7,44 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "given a valid list" do
setup do
@list = "create alias abc -> def\ncreate implication aaa -> bbb\n"
@importer = AliasAndImplicationImporter.new(@list, nil)
end
should "process it" do
assert_difference("Delayed::Job.count", 4) do
@importer.process!
end
end
end
context "given a list with an invalid command" do
setup do
@list = "zzzz abc -> def\n"
@importer = AliasAndImplicationImporter.new(@list, nil)
end
should "throw an exception" do
assert_raises(RuntimeError) do
@importer.process!
end
end
end
context "given a list with a logic error" do
setup do
@list = "remove alias zzz -> yyy\n"
@importer = AliasAndImplicationImporter.new(@list, nil)
end
should "throw an exception" do
assert_raises(RuntimeError) do
@importer.process!

View File

@@ -13,22 +13,22 @@ class ArtistTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "with a matching tag alias" do
setup do
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
@artist = FactoryGirl.create(:artist, :name => "aaa")
end
should "know it has an alias" do
assert_equal(true, @artist.has_tag_alias?)
end
should "know its alias" do
assert_equal("bbb", @artist.tag_alias_name)
end
end
context "that has been banned" do
setup do
@post = FactoryGirl.create(:post, :tag_string => "aaa")
@@ -36,16 +36,16 @@ class ArtistTest < ActiveSupport::TestCase
@artist.ban!
@post.reload
end
should "delete the post" do
assert(@post.is_deleted?)
end
should "create a new tag implication" do
assert_equal(1, TagImplication.where(:antecedent_name => "aaa", :consequent_name => "banned_artist").count)
end
end
should "create a new wiki page to store any note information" do
artist = nil
assert_difference("WikiPage.count") do
@@ -55,7 +55,7 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal("testing", artist.wiki_page.body)
assert_equal(artist.name, artist.wiki_page.title)
end
should "update the wiki page when notes are assigned" do
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
artist.update_attribute(:notes, "kokoko")
@@ -63,12 +63,12 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal("kokoko", artist.notes)
assert_equal("kokoko", artist.wiki_page.body)
end
should "normalize its name" do
artist = FactoryGirl.create(:artist, :name => " AAA BBB ")
assert_equal("aaa_bbb", artist.name)
end
should "resolve ambiguous urls" do
bobross = FactoryGirl.create(:artist, :name => "bob_ross", :url_string => "http://artists.com/bobross/image.jpg")
bob = FactoryGirl.create(:artist, :name => "bob", :url_string => "http://artists.com/bob/image.jpg")
@@ -76,13 +76,13 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(1, matches.size)
assert_equal("bob", matches.first.name)
end
should "parse urls" do
artist = FactoryGirl.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.urls.map(&:to_s).sort)
end
should "make sure old urls are deleted" do
artist = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
artist.url_string = "http://not.rembrandt.com/test.jpg"
@@ -97,32 +97,32 @@ class ArtistTest < ActiveSupport::TestCase
a3 = FactoryGirl.create(:artist, :name => "minko", :url_string => "https://minko.com/x/test.jpg")
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/x/test.jpg").map(&:name))
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/x/another.jpg").map(&:name))
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/x/another.jpg").map(&:name))
assert_equal([], Artist.find_all_by_url("http://nonexistent.com/test.jpg").map(&:name))
assert_equal(["minko"], Artist.find_all_by_url("https://minko.com/x/test.jpg").map(&:name))
assert_equal(["minko"], Artist.find_all_by_url("http://minko.com/x/test.jpg").map(&:name))
end
should "not allow duplicates" do
FactoryGirl.create(:artist, :name => "warhol", :url_string => "http://warhol.com/x/a/image.jpg\nhttp://warhol.com/x/b/image.jpg")
assert_equal(["warhol"], Artist.find_all_by_url("http://warhol.com/x/test.jpg").map(&:name))
end
should "hide deleted artists" do
FactoryGirl.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg", :is_active => false)
assert_equal([], Artist.find_all_by_url("http://warhol.com/a/image.jpg").map(&:name))
end
should "normalize its other names" do
artist = FactoryGirl.create(:artist, :name => "a1", :other_names_comma => "aaa, bbb, ccc ddd")
assert_equal("aaa, bbb, ccc_ddd", artist.other_names_comma)
end
should "search on its name should return results" do
artist = FactoryGirl.create(:artist, :name => "artist")
assert_not_nil(Artist.search(:name => "artist").first)
end
should "search on other names should return matches" do
artist = FactoryGirl.create(:artist, :name => "artist", :other_names_comma => "aaa, ccc ddd")
assert_nil(Artist.other_names_match("artist").first)
@@ -131,7 +131,7 @@ class ArtistTest < ActiveSupport::TestCase
assert_not_nil(Artist.search(:name => "other:aaa").first)
assert_not_nil(Artist.search(:name => "aaa").first)
end
should "search on group name and return matches" do
cat_or_fish = FactoryGirl.create(:artist, :name => "cat_or_fish")
yuu = FactoryGirl.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
@@ -139,19 +139,19 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal("yuu", cat_or_fish.member_names)
assert_not_nil(Artist.search(:name => "group:cat_or_fish").first)
end
should "have an associated wiki" do
user = FactoryGirl.create(:user)
CurrentUser.user = user
artist = FactoryGirl.create(:artist, :name => "max", :wiki_page_attributes => {:title => "xxx", :body => "this is max"})
assert_not_nil(artist.wiki_page)
assert_equal("this is max", artist.wiki_page.body)
artist.update_attributes({:wiki_page_attributes => {:id => artist.wiki_page.id, :body => "this is hoge mark ii"}})
assert_equal("this is hoge mark ii", artist.wiki_page(true).body)
CurrentUser.user = nil
end
should "revert to prior versions" do
user = FactoryGirl.create(:user)
reverter = FactoryGirl.create(:user)
@@ -159,12 +159,12 @@ class ArtistTest < ActiveSupport::TestCase
assert_difference("ArtistVersion.count") do
artist = FactoryGirl.create(:artist, :other_names => "yyy")
end
assert_difference("ArtistVersion.count") do
artist.other_names = "xxx"
artist.save
end
first_version = ArtistVersion.first
assert_equal("yyy", first_version.other_names)
artist.revert_to!(first_version)

View File

@@ -7,7 +7,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@@ -22,7 +22,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
assert_equal("http://monet.com/", url.url)
assert_equal("http://monet.com/", url.normalized_url)
end
should "normalise https" do
url = FactoryGirl.create(:artist_url, :url => "https://google.com")
assert_equal("https://google.com", url.url)
@@ -38,7 +38,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
assert_equal("http://blog-imgs-55.fc2.com/monet", url.url)
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
end
should "normalize pixiv urls" do
url = FactoryGirl.create(:artist_url, :url => "http://img55.pixiv.net/monet")
assert_equal("http://img55.pixiv.net/monet", url.url)

View File

@@ -8,20 +8,20 @@ class BanTest < ActiveSupport::TestCase
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
@banner = nil
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "not be valid against another admin" do
user = FactoryGirl.create(:admin_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
end
should "be valid against anyone who is not an admin" do
user = FactoryGirl.create(:moderator_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
@@ -44,20 +44,20 @@ class BanTest < ActiveSupport::TestCase
assert(ban.errors.empty?)
end
end
context "created by a moderator" do
setup do
@banner = FactoryGirl.create(:moderator_user)
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
@banner = nil
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "not be valid against an admin or moderator" do
user = FactoryGirl.create(:admin_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
@@ -69,7 +69,7 @@ class BanTest < ActiveSupport::TestCase
ban.save
assert(ban.errors.any?)
end
should "be valid against anyone who is not an admin or a moderator" do
user = FactoryGirl.create(:janitor_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
@@ -88,20 +88,20 @@ class BanTest < ActiveSupport::TestCase
assert(ban.errors.empty?)
end
end
context "created by a janitor" do
setup do
@banner = FactoryGirl.create(:janitor_user)
@banner = FactoryGirl.create(:janitor_user)
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
teardown do
@banner = nil
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "always be invalid" do
user = FactoryGirl.create(:admin_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
@@ -143,7 +143,7 @@ class BanTest < ActiveSupport::TestCase
CurrentUser.user = nil
assert_not_nil(ban.expires_at)
end
should "update the user's feedback" do
user = FactoryGirl.create(:user)
admin = FactoryGirl.create(:admin_user)
@@ -164,31 +164,31 @@ class BanTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@user = FactoryGirl.create(:user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "when only expired bans exist" do
setup do
@ban = FactoryGirl.create(:ban, :user => @user, :banner => @admin, :duration => -1)
end
should "not return expired bans" do
assert(!Ban.is_banned?(@user))
end
end
context "when active bans still exist" do
setup do
@ban = FactoryGirl.create(:ban, :user => @user, :banner => @admin, :duration => 1)
end
should "return active bans" do
assert(Ban.is_banned?(@user))
end
end
end
end
end
end

View File

@@ -8,31 +8,31 @@ class CommentTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "created by a limited user" do
setup do
Danbooru.config.stubs(:member_comment_limit).returns(5)
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.ago)
end
should "fail creation" do
comment = FactoryGirl.build(:comment)
comment.save
assert_equal(["Creator can not post comments within 1 week of sign up, and can only post 5 comments per hour after that"], comment.errors.full_messages)
end
end
context "created by an unlimited user" do
setup do
Danbooru.config.stubs(:member_comment_limit).returns(100)
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
end
context "that is then deleted" do
setup do
@post = FactoryGirl.create(:post)
@@ -40,7 +40,7 @@ class CommentTest < ActiveSupport::TestCase
@comment.destroy
@post.reload
end
should "nullify the last_commented_at field" do
assert_nil(@post.last_commented_at)
end

View File

@@ -5,37 +5,37 @@ class ArtistTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "The current user" do
should "be set only within the scope of the block" do
user = FactoryGirl.create(:user)
assert_nil(CurrentUser.user)
assert_nil(CurrentUser.ip_addr)
CurrentUser.user = user
CurrentUser.ip_addr = "1.2.3.4"
assert_not_nil(CurrentUser.user)
assert_equal(user.id, CurrentUser.user.id)
assert_equal("1.2.3.4", CurrentUser.ip_addr)
end
end
context "A scoped current user" do
should "reset the current user after the block has exited" do
user1 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
CurrentUser.user = user1
CurrentUser.scoped(user2, nil) do
assert_equal(user2.id, CurrentUser.user.id)
end
assert_equal(user1.id, CurrentUser.user.id)
end
should "reset the current user even if an exception is thrown" do
user1 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
CurrentUser.user = user1
assert_raises(RuntimeError) do
CurrentUser.scoped(user2, nil) do

View File

@@ -11,16 +11,16 @@ class DmailTest < ActiveSupport::TestCase
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
end
teardown do
CurrentUser.user = nil
end
context "from a banned user" do
setup do
@user.update_attribute(:is_banned, true)
end
should "not validate" do
dmail = FactoryGirl.build(:dmail, :title => "xxx", :owner => @user)
dmail.save
@@ -28,7 +28,7 @@ class DmailTest < ActiveSupport::TestCase
assert_equal(["Sender is banned and cannot send messages"], dmail.errors.full_messages)
end
end
context "search" do
should "return results based on title contents" do
dmail = FactoryGirl.create(:dmail, :title => "xxx", :owner => @user)
@@ -37,7 +37,7 @@ class DmailTest < ActiveSupport::TestCase
matches = Dmail.search_message("aaa")
assert(matches.empty?)
end
should "return results based on body contents" do
dmail = FactoryGirl.create(:dmail, :body => "xxx", :owner => @user)
matches = Dmail.search_message("xxx")
@@ -46,14 +46,14 @@ class DmailTest < ActiveSupport::TestCase
assert(matches.empty?)
end
end
should "should parse user names" do
dmail = FactoryGirl.build(:dmail, :owner => @user)
dmail.to_id = nil
dmail.to_name = @user.name
assert(dmail.to_id == @user.id)
end
should "construct a response" do
dmail = FactoryGirl.create(:dmail, :owner => @user)
response = dmail.build_response
@@ -61,7 +61,7 @@ class DmailTest < ActiveSupport::TestCase
assert_equal(dmail.from_id, response.to_id)
assert_equal(dmail.to_id, response.from_id)
end
should "create a copy for each user" do
@new_user = FactoryGirl.create(:user)
assert_difference("Dmail.count", 2) do
@@ -82,14 +82,14 @@ class DmailTest < ActiveSupport::TestCase
Dmail.create_split(:to_id => user.id, :title => "foo", :body => "foo")
end
end
should "be marked as read after the user reads it" do
dmail = FactoryGirl.create(:dmail, :owner => @user)
assert(!dmail.is_read?)
dmail.mark_as_read!
assert(dmail.is_read?)
end
should "notify the recipient he has mail" do
dmail = FactoryGirl.create(:dmail, :owner => @user)
assert(dmail.to(true).has_mail?)

View File

@@ -8,32 +8,32 @@ module Downloads
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
end
teardown do
@tempfile.close
end
should "stream a file from an HTTP source" do
@download.http_get_streaming do |resp|
assert_equal("200", resp.code)
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
end
end
should "throw an exception when the file is larger than the maximum" do
assert_raise(Downloads::File::Error) do
@download.http_get_streaming(:max_size => 1) do |resp|
end
end
end
should "store the file in the tempfile path" do
@download.download!
assert_equal(@source, @download.source)
assert(::File.exists?(@tempfile.path), "temp file should exist")
assert(::File.size(@tempfile.path) > 0, "should have data")
end
should "initialize the content type" do
@download.download!
assert_match(/image\/gif/, @download.content_type)

View File

@@ -8,7 +8,7 @@ module Downloads
# @tempfile = Tempfile.new("danbooru-test")
# @download = Downloads::File.new(@source, @tempfile.path)
end
should "work" do
# @download.download!
# assert_equal(201248, ::File.size(@tempfile.path))

View File

@@ -1,5 +1,5 @@
# require 'test_helper'
#
#
# module Downloads
# class PixaTest < ActiveSupport::TestCase
# context "a download for a pixa image" do
@@ -8,7 +8,7 @@
# @tempfile = Tempfile.new("danbooru-test")
# @download = Downloads::File.new(@source, @tempfile.path)
# end
#
#
# should "work" do
# @download.download!
# assert_equal(104627, ::File.size(@tempfile.path))

View File

@@ -9,12 +9,12 @@ module Downloads
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
end
should "instead download the big version" do
assert_equal("http://img65.pixiv.net/img/kiyoringo/21755794_big_p2.png", @download.source)
end
end
context "a download for a html page" do
setup do
@source = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=23828655"
@@ -23,12 +23,12 @@ module Downloads
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
end
should "work" do
assert_equal(185778, ::File.size(@tempfile.path))
end
end
context "a download for a small image" do
setup do
@source = "http://img02.pixiv.net/img/wanwandoh/4348318_m.jpg"
@@ -36,11 +36,11 @@ module Downloads
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
end
should "instead download the original version" do
assert_equal("http://img02.pixiv.net/img/wanwandoh/4348318.jpg", @download.source)
end
should "work" do
assert_equal(185778, ::File.size(@tempfile.path))
end

View File

@@ -1,5 +1,5 @@
# require 'test_helper'
#
#
# module Downloads
# class TinamiTest < ActiveSupport::TestCase
# context "a download for a pixa image" do
@@ -8,7 +8,7 @@
# @tempfile = Tempfile.new("danbooru-test")
# @download = Downloads::File.new(@source, @tempfile.path)
# end
#
#
# should "work" do
# @download.download!
# assert_equal(201248, ::File.size(@tempfile.path))

View File

@@ -4,18 +4,18 @@ class DTextTest < ActiveSupport::TestCase
def p(s)
DText.parse(s)
end
def test_sanitize
assert_equal('<p>&lt;</p>', p("<"))
assert_equal('<p>&gt;</p>', p(">"))
assert_equal('<p>&amp;</p>', p("&"))
end
def test_wiki_links
assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=b\">b</a> c</p>", p("a [[b]] c"))
assert_equal("<p>a <a href=\"/wiki_pages/show_or_new?title=spoiler\">spoiler</a> c</p>", p("a [[spoiler]] c"))
end
def test_spoilers
assert_equal("<p>this is</p><div class=\"spoiler\"><p>an inline spoiler</p></div><p>.</p>", p("this is [spoiler]an inline spoiler[/spoiler]."))
assert_equal("<p>this is</p><div class=\"spoiler\"><p>a block spoiler</p></div><p>.</p>", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler]."))
@@ -23,24 +23,24 @@ class DTextTest < ActiveSupport::TestCase
assert_equal("<div class=\"spoiler\"><p>this is a spoiler with no closing tag<br>new text</p></div>", p("[spoiler]this is a spoiler with no closing tag\nnew text"))
assert_equal("<div class=\"spoiler\">\n<p>this is</p>\n<div class=\"spoiler\"><p>a nested</p></div>\n<p>spoiler</p>\n</div>", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]"))
end
def test_paragraphs
assert_equal("<p>a</p>", p("a"))
assert_equal("<p>abc</p>", p("abc"))
assert_equal("<p>a<br>b<br>c</p>", p("a\nb\nc"))
assert_equal("<p>a</p><p>b</p>", p("a\n\nb"))
end
def test_headers
assert_equal("<h1>header</h1>", p("h1. header"))
assert_equal("<h1>header</h1><p>paragraph</p>", p("h1.header\n\nparagraph"))
end
def test_quote_blocks
assert_equal('<blockquote><p>test</p></blockquote>', p("[quote]\ntest\n[/quote]"))
assert_equal("<blockquote>\n<p>a</p>\n<blockquote><p>b</p></blockquote>\n<p>c</p>\n</blockquote>", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]"))
end
def test_urls
assert_equal('<p>a <a href="http://test.com">http://test.com</a> b</p>', p('a http://test.com b'))
assert_equal('<p><a href="http://test.com">http://test.com</a><br>b</p>', p("http://test.com\nb"))
@@ -49,7 +49,7 @@ class DTextTest < ActiveSupport::TestCase
assert_equal('<p>a <a href="http://test.com">http://test.com</a>. b</p>', p('a http://test.com. b'))
assert_equal('<p>a (<a href="http://test.com">http://test.com</a>) b</p>', p('a (http://test.com) b'))
end
# def test_links
# assert_equal('<p><a href="http://test.com">test</a></p>', p('[url=http://test.com]test[/url]'))
# assert_equal('<p>"1" <a href="http://two.com">2</a></p>', p('"1" [url=http://two.com]2[/url]'))
@@ -61,29 +61,29 @@ class DTextTest < ActiveSupport::TestCase
assert_equal('<p>"1" <a href="http://two.com">2</a></p>', p('"1" "2":http://two.com'))
assert_equal('<p>"1" <a href="http://three.com">2 &amp; 3</a></p>', p('"1" "2 & 3":http://three.com'))
end
# def test_aliased_urls
# assert_equal('<p>a <a href="http://test.com">bob</a>. b</p>', p('a [url=http://test.com]bob[/url]. b'))
# assert_equal('<p><em><a href="http://test.com">bob</a></em></p>', p('[i][url=http://test.com]bob[/url][/i]'))
# end
def test_lists
assert_equal('<ul><li>a</li></ul>', p('* a'))
assert_equal('<ul><li>a</li><li>b</li></ul>', p("* a\n* b").gsub(/\n/, ""))
assert_equal('<ul><li>a</li><ul><li>b</li></ul></ul>', p("* a\n** b").gsub(/\n/, ""))
assert_equal('<ul><li><a href="/posts/1">post #1</a></li></ul>', p("* post #1").gsub(/\n/, ""))
end
def test_inline
assert_equal('<p><a href="/posts?tags=tag">tag</a></p>', p("{{tag}}"))
assert_equal('<p><a href="/posts?tags=tag1+tag2">tag1 tag2</a></p>', p("{{tag1 tag2}}"))
assert_equal('<p><a href="/posts?tags=%3C3">&lt;3</a></p>', p("{{<3}}"))
end
def test_extra_newlines
assert_equal('<p>a</p><p>b</p>', p("a\n\n\n\n\n\n\nb\n\n\n\n"))
end
def test_complex_links
assert_equal("<p><a href=\"/wiki_pages/show_or_new?title=1\">2 3</a> | <a href=\"/wiki_pages/show_or_new?title=4\">5 6</a></p>", p("[[1|2 3]] | [[4|5 6]]"))
assert_equal("<p>Tags <strong>(<a href=\"/wiki_pages/show_or_new?title=howto%3Atag\">Tagging Guidelines</a> | <a href=\"/wiki_pages/show_or_new?title=howto%3Atag_checklist\">Tag Checklist</a> | <a href=\"/wiki_pages/show_or_new?title=tag_groups\">Tag Groups</a>)</strong></p>", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]"))

View File

@@ -8,7 +8,7 @@ class FavoriteTest < ActiveSupport::TestCase
MEMCACHE.flush_all
Favorite # need to force loading the favorite model
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@@ -18,41 +18,41 @@ class FavoriteTest < ActiveSupport::TestCase
should "delete from all tables" do
user1 = FactoryGirl.create(:user)
p1 = FactoryGirl.create(:post)
user1.add_favorite!(p1)
assert_equal(1, Favorite.count)
Favorite.destroy_all(:user_id => user1.id, :post_id => p1.id)
assert_equal(0, Favorite.count)
end
should "know which table it belongs to" do
user1 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
p1 = FactoryGirl.create(:post)
p2 = FactoryGirl.create(:post)
user1.add_favorite!(p1)
user1.add_favorite!(p2)
user2.add_favorite!(p1)
favorites = user1.favorites.order("id desc")
assert_equal(2, favorites.count)
assert_equal(p2.id, favorites[0].post_id)
assert_equal(p1.id, favorites[1].post_id)
favorites = user2.favorites.order("id desc")
assert_equal(1, favorites.count)
assert_equal(p1.id, favorites[0].post_id)
end
should "not allow duplicates" do
user1 = FactoryGirl.create(:user)
p1 = FactoryGirl.create(:post)
p2 = FactoryGirl.create(:post)
user1.add_favorite!(p1)
user1.add_favorite!(p1)
assert_equal(1, user1.favorites.count)
end
end

View File

@@ -8,12 +8,12 @@ class ForumPostTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@topic = FactoryGirl.create(:forum_topic)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "that belongs to a topic with several pages of posts" do
setup do
Danbooru.config.stubs(:posts_per_page).returns(3)
@@ -22,7 +22,7 @@ class ForumPostTest < ActiveSupport::TestCase
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
end
should "know which page it's on" do
assert_equal(2, @posts[3].forum_topic_page)
assert_equal(2, @posts[4].forum_topic_page)
@@ -30,26 +30,26 @@ class ForumPostTest < ActiveSupport::TestCase
assert_equal(3, @posts[6].forum_topic_page)
end
end
context "belonging to a locked topic" do
setup do
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
@topic.update_attribute(:is_locked, true)
@post.reload
end
should "not be updateable" do
@post.update_attributes(:body => "xxx")
@post.reload
assert_equal("zzz", @post.body)
end
should "not be deletable" do
@post.destroy
assert_equal(1, ForumPost.count)
end
end
should "update its parent when saved" do
sleep 1
original_topic_updated_at = @topic.updated_at
@@ -57,37 +57,37 @@ class ForumPostTest < ActiveSupport::TestCase
@topic.reload
assert_not_equal(original_topic_updated_at, @topic.updated_at)
end
should "be searchable by body content" do
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
assert_equal(1, ForumPost.body_matches("xxx").count)
assert_equal(0, ForumPost.body_matches("aaa").count)
end
should "initialize its creator" do
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
assert_equal(@user.id, post.creator_id)
end
context "that is deleted" do
setup do
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@post.update_attribute(:is_deleted, true)
@topic.reload
end
should "also delete the topic" do
assert(@topic.is_deleted)
end
end
context "updated by a second user" do
setup do
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@second_user = FactoryGirl.create(:user)
CurrentUser.user = @second_user
end
should "record its updater" do
@post.update_attributes(:body => "abc")
assert_equal(@second_user.id, @post.updater_id)

View File

@@ -8,48 +8,48 @@ class ForumTopicTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@topic = FactoryGirl.create(:forum_topic, :title => "xxx")
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "constructed with nested attributes for its original post" do
should "create a matching forum post" do
assert_difference(["ForumTopic.count", "ForumPost.count"], 1) do
@topic = FactoryGirl.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
end
end
end
end
should "be searchable by title" do
assert_equal(1, ForumTopic.title_matches("xxx").count)
assert_equal(0, ForumTopic.title_matches("aaa").count)
end
should "initialize its creator" do
assert_equal(@user.id, @topic.creator_id)
end
context "updated by a second user" do
setup do
@second_user = FactoryGirl.create(:user)
CurrentUser.user = @second_user
end
should "record its updater" do
@topic.update_attributes(:title => "abc")
assert_equal(@second_user.id, @topic.updater_id)
end
end
context "with multiple posts that has been deleted" do
setup do
5.times do
FactoryGirl.create(:forum_post, :topic_id => @topic.id)
end
end
should "delete any associated posts" do
assert_difference("ForumPost.count", -5) do
@topic.destroy

View File

@@ -8,7 +8,7 @@ class IpBanTest < ActiveSupport::TestCase
MEMCACHE.flush_all
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@@ -19,7 +19,7 @@ class IpBanTest < ActiveSupport::TestCase
counts = IpBan.count_by_ip_addr("comments", [comment.creator_id], "creator_id", "ip_addr")
assert_equal([{"ip_addr" => "127.0.0.1", "count" => "1"}], counts)
end
should "be able to count any updates from a user, groupiny by IP address" do
CurrentUser.scoped(@user, "1.2.3.4") do
comment = FactoryGirl.create(:comment, :body => "aaa")

View File

@@ -9,19 +9,19 @@ class JanitorTrialTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "upon creation" do
should "create a dmail when testing a new janitor" do
assert_difference("Dmail.count", 2) do
JanitorTrial.create(:user_id => @user.id)
end
end
should "toggle the janitor flag on the user" do
janitor_trial = JanitorTrial.create(:user_id => @user.id)
@user.reload
@@ -33,19 +33,19 @@ class JanitorTrialTest < ActiveSupport::TestCase
setup do
@janitor_trial = FactoryGirl.create(:janitor_trial, :user_id => @user.id)
end
should "create a negative feedback record" do
assert_difference("UserFeedback.count", 1) do
@janitor_trial.demote!
end
end
end
context "upon promotion" do
setup do
@janitor_trial = FactoryGirl.create(:janitor_trial, :user_id => @user.id)
end
should "destroy the trial object" do
assert_difference("JanitorTrial.count", -1) do
@janitor_trial.promote!

View File

@@ -7,7 +7,7 @@ module Maintenance
setup do
@user = FactoryGirl.create(:user)
end
should "send the notie" do
LoginReminderMailer.notice(@user).deliver
assert !ActionMailer::Base.deliveries.empty?

View File

@@ -11,17 +11,17 @@ module Moderator
FactoryGirl.create(:comment)
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "find by ip addr" do
@search = IpAddrSearch.new(:ip_addr => "127.0.0.1")
assert_equal({@user.id.to_s => 2}, @search.execute)
end
should "find by user id" do
@search = IpAddrSearch.new(:user_id => @user.id.to_s)
assert_equal({"127.0.0.1" => 2}, @search.execute)

View File

@@ -9,7 +9,7 @@ module Moderator
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post, :tag_string => "aaa")
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@@ -21,7 +21,7 @@ module Moderator
@post.reload
assert_equal("bbb", @post.tag_string)
end
should "raise an error if there is no predicate" do
tag_batch_change = TagBatchChange.new("", "bbb", @user, "127.0.0.1")
assert_raises(TagBatchChange::Error) do

View File

@@ -8,35 +8,35 @@ class NoteTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "for a post that already has a note" do
setup do
@post = FactoryGirl.create(:post)
@note = FactoryGirl.create(:note, :post => @post)
end
context "when the note is deleted the post" do
setup do
@note.toggle!(:is_active)
end
should "null out its last_noted_at_field" do
@post.reload
assert_nil(@post.last_noted_at)
end
end
end
context "creating a note" do
setup do
@post = FactoryGirl.create(:post)
end
should "create a version" do
assert_difference("NoteVersion.count", 1) do
@note = FactoryGirl.create(:note, :post => @post)
@@ -45,7 +45,7 @@ class NoteTest < ActiveSupport::TestCase
assert_equal(1, @note.versions.count)
assert_equal(@note.body, @note.versions.first.body)
end
should "update the post's last_noted_at field" do
assert_nil(@post.last_noted_at)
@note = FactoryGirl.create(:note, :post => @post)
@@ -64,29 +64,29 @@ class NoteTest < ActiveSupport::TestCase
@note.save
end
assert_equal(["Post is note locked"], @note.errors.full_messages)
end
end
end
end
context "updating a note" do
setup do
@post = FactoryGirl.create(:post)
@note = FactoryGirl.create(:note, :post => @post)
end
should "increment the updater's note_update_count" do
assert_difference("CurrentUser.note_update_count", 1) do
@note.update_attributes(:body => "zzz")
end
end
should "update the post's last_noted_at field" do
assert_nil(@post.last_noted_at)
@note.update_attributes(:x => 1000)
@post.reload
assert_equal(@post.last_noted_at.to_i, @note.updated_at.to_i)
end
should "create a version" do
assert_difference("NoteVersion.count", 1) do
@note.update_attributes(:body => "fafafa")
@@ -94,19 +94,19 @@ class NoteTest < ActiveSupport::TestCase
assert_equal(2, @note.versions.count)
assert_equal("fafafa", @note.versions.last.body)
end
context "for a note-locked post" do
setup do
@post.update_attribute(:is_note_locked, true)
end
should "fail" do
@note.update_attributes(:x => 1000)
assert_equal(["Post is note locked"], @note.errors.full_messages)
end
end
end
context "when notes have been vandalized by one user" do
setup do
@vandal = FactoryGirl.create(:user)
@@ -115,7 +115,7 @@ class NoteTest < ActiveSupport::TestCase
@note.update_attributes(:x => 2000, :y => 2000)
end
end
context "the act of undoing all changes by that user" do
should "revert any affected notes" do
Note.undo_changes_by_user(@vandal.id)
@@ -130,13 +130,13 @@ class NoteTest < ActiveSupport::TestCase
setup do
@note = FactoryGirl.create(:note, :body => "aaa")
end
context "where the body contains the string 'aaa'" do
should "return a hit" do
assert_equal(1, Note.body_matches("aaa").count)
end
end
context "where the body contains the string 'bbb'" do
should "return no hits" do
assert_equal(0, Note.body_matches("bbb").count)

View File

@@ -7,36 +7,36 @@ class PoolTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "A name" do
setup do
@pool = FactoryGirl.create(:pool, :name => "xxx")
end
should "be mapped to a pool id" do
assert_equal(@pool.id, Pool.name_to_id("xxx"))
end
end
context "An id number" do
setup do
@pool = FactoryGirl.create(:pool)
end
should "be mapped to a pool id" do
assert_equal(@pool.id, Pool.name_to_id(@pool.id.to_s))
end
should "be mapped to its name" do
assert_equal(@pool.name, Pool.id_to_name(@pool.id))
end
end
context "Reverting a pool" do
setup do
@pool = FactoryGirl.create(:pool)
@@ -54,7 +54,7 @@ class PoolTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "1.2.3.8"
@pool.revert_to!(@pool.versions.all[1])
end
should "have the correct versions" do
assert_equal(6, @pool.versions.size)
assert_equal("", @pool.versions.all[0].post_ids)
@@ -63,51 +63,51 @@ class PoolTest < ActiveSupport::TestCase
assert_equal("#{@p1.id} #{@p2.id} #{@p3.id}", @pool.versions.all[3].post_ids)
assert_equal("#{@p2.id} #{@p3.id}", @pool.versions.all[4].post_ids)
end
should "update its post_ids" do
assert_equal("#{@p1.id}", @pool.post_ids)
end
should "update any old posts that were removed" do
@p2.reload
assert_equal("", @p2.pool_string)
end
should "update any new posts that were added" do
@p1.reload
assert_equal("pool:#{@pool.id}", @p1.pool_string)
end
end
context "Updating a pool" do
setup do
@pool = FactoryGirl.create(:pool)
@p1 = FactoryGirl.create(:post)
@p2 = FactoryGirl.create(:post)
end
context "by adding a new post" do
setup do
@pool.add!(@p1)
end
should "add the post to the pool" do
assert_equal("#{@p1.id}", @pool.post_ids)
end
should "add the pool to the post" do
assert_equal("pool:#{@pool.id}", @p1.pool_string)
end
should "increment the post count" do
assert_equal(1, @pool.post_count)
end
context "to a pool that already has the post" do
setup do
@pool.add!(@p1)
end
should "not double add the post to the pool" do
assert_equal("#{@p1.id}", @pool.post_ids)
end
@@ -121,12 +121,12 @@ class PoolTest < ActiveSupport::TestCase
end
end
end
context "by removing a post" do
setup do
@pool.add!(@p1)
end
context "that is in the pool" do
setup do
@pool.remove!(@p1)
@@ -144,26 +144,26 @@ class PoolTest < ActiveSupport::TestCase
assert_equal(0, @pool.post_count)
end
end
context "that is not in the pool" do
setup do
@pool.remove!(@p2)
end
should "not affect the pool" do
assert_equal("#{@p1.id}", @pool.post_ids)
end
should "not affect the post" do
assert_equal("pool:#{@pool.id}", @p1.pool_string)
end
should "not affect the post count" do
assert_equal(1, @pool.post_count)
end
end
end
should "create new versions for each distinct user" do
assert_equal(1, @pool.versions(true).size)
@pool.post_ids = "#{@p1.id}"
@@ -174,24 +174,24 @@ class PoolTest < ActiveSupport::TestCase
@pool.save
assert_equal(2, @pool.versions(true).size)
end
should "know what its post ids were previously" do
@pool.post_ids = "#{@p1.id}"
assert_equal("", @pool.post_ids_was)
assert_equal([], @pool.post_id_array_was)
end
should "normalize its name" do
@pool.update_attributes(:name => "A B")
assert_equal("A_B", @pool.name)
end
should "normalize its post ids" do
@pool.update_attributes(:post_ids => " 1 2 ")
assert_equal("1 2", @pool.post_ids)
end
end
context "An existing pool" do
setup do
@pool = FactoryGirl.create(:pool)
@@ -207,20 +207,20 @@ class PoolTest < ActiveSupport::TestCase
@pool.reload # clear cached neighbors
@p3_neighbors = @pool.neighbors(@p3)
end
context "that is synchronized" do
setup do
@pool.reload
@pool.post_ids = "#{@p2.id}"
@pool.synchronize!
end
should "update the pool" do
@pool.reload
assert_equal(1, @pool.post_count)
assert_equal("#{@p2.id}", @pool.post_ids)
end
should "update the posts" do
@p1.reload
@p2.reload
@@ -230,17 +230,17 @@ class PoolTest < ActiveSupport::TestCase
assert_equal("", @p3.pool_string)
end
end
should "find the neighbors for the first post" do
assert_nil(@p1_neighbors.previous)
assert_equal(@p2.id, @p1_neighbors.next)
end
should "find the neighbors for the middle post" do
assert_equal(@p1.id, @p2_neighbors.previous)
assert_equal(@p3.id, @p2_neighbors.next)
end
should "find the neighbors for the last post" do
assert_equal(@p2.id, @p3_neighbors.previous)
assert_nil(@p3_neighbors.next)
@@ -252,7 +252,7 @@ class PoolTest < ActiveSupport::TestCase
user = FactoryGirl.create(:user)
CurrentUser.user = user
end
should "have a name starting with anon" do
pool = Pool.create_anonymous
assert_match(/^anon:\d+$/, pool.name)

View File

@@ -14,24 +14,24 @@ class PostAppealTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a user" do
setup do
@post = FactoryGirl.create(:post, :tag_string => "aaa", :is_deleted => true)
end
should "not be able to appeal a post more than twice" do
assert_difference("PostAppeal.count", 1) do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
end
assert_difference("PostAppeal.count", 0) do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
end
assert_equal(["You have already appealed this post"], @post_appeal.errors.full_messages)
end
should "not be able to appeal more than 5 posts in 24 hours" do
@post_appeal = PostAppeal.new(:post => @post, :reason => "aaa")
@post_appeal.expects(:appeal_count_for_creator).returns(5)
@@ -40,7 +40,7 @@ class PostAppealTest < ActiveSupport::TestCase
end
assert_equal(["You can appeal at most 5 post a day"], @post_appeal.errors.full_messages)
end
should "not be able to appeal an active post" do
@post.update_attribute(:is_deleted, false)
assert_difference("PostAppeal.count", 0) do
@@ -48,7 +48,7 @@ class PostAppealTest < ActiveSupport::TestCase
end
assert_equal(["Post is active"], @post_appeal.errors.full_messages)
end
should "initialize its creator" do
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
assert_equal(@alice.id, @post_appeal.creator_id)

View File

@@ -13,13 +13,13 @@ class PostDisapprovalTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "A post disapproval" do
setup do
@post_1 = FactoryGirl.create(:post, :is_pending => true)
@post_2 = FactoryGirl.create(:post, :is_pending => true)
end
context "made by alice" do
setup do
@disapproval = PostDisapproval.create(:user => @alice, :post => @post_1)
@@ -29,7 +29,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
setup do
CurrentUser.user = @alice
end
should "remove the associated post from alice's moderation queue" do
assert(!Post.available_for_moderation(false).map(&:id).include?(@post_1.id))
assert(Post.available_for_moderation(false).map(&:id).include?(@post_2.id))
@@ -41,7 +41,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
@brittony = FactoryGirl.create(:moderator_user)
CurrentUser.user = @brittony
end
should "not remove the associated post from brittony's moderation queue" do
assert(Post.available_for_moderation(false).map(&:id).include?(@post_1.id))
assert(Post.available_for_moderation(false).map(&:id).include?(@post_2.id))
@@ -55,7 +55,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user)
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
end
should "be pruned" do
assert_difference("PostDisapproval.count", -1) do
PostDisapproval.prune!

View File

@@ -13,24 +13,24 @@ class PostFlagTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a user" do
setup do
@post = FactoryGirl.create(:post, :tag_string => "aaa")
end
should "not be able to flag a post more than twice" do
assert_difference("PostFlag.count", 1) do
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
end
assert_difference("PostFlag.count", 0) do
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
end
assert_equal(["You have already flagged this post"], @post_flag.errors.full_messages)
end
should "not be able to flag more than 10 posts in 24 hours" do
@post_flag = PostFlag.new(:post => @post, :reason => "aaa", :is_resolved => false)
@post_flag.expects(:flag_count_for_creator).returns(10)
@@ -39,7 +39,7 @@ class PostFlagTest < ActiveSupport::TestCase
end
assert_equal(["You can flag 10 posts a day"], @post_flag.errors.full_messages)
end
should "not be able to flag a deleted post" do
@post.update_attribute(:is_deleted, true)
assert_difference("PostFlag.count", 0) do
@@ -47,7 +47,7 @@ class PostFlagTest < ActiveSupport::TestCase
end
assert_equal(["Post is deleted"], @post_flag.errors.full_messages)
end
should "initialize its creator" do
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
assert_equal(@alice.id, @post_flag.creator_id)

View File

@@ -6,7 +6,7 @@ class PostPrunerTest < ActiveSupport::TestCase
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@flagger = FactoryGirl.create(:user)
@old_post = FactoryGirl.create(:post, :created_at => 5.days.ago, :is_pending => true)
@unresolved_flagged_post = FactoryGirl.create(:post, :is_flagged => true)
@@ -16,25 +16,25 @@ class PostPrunerTest < ActiveSupport::TestCase
@unresolved_post_flag = FactoryGirl.create(:post_flag, :created_at => 5.days.ago, :is_resolved => false, :post_id => @unresolved_flagged_post.id)
@resolved_post_flag = FactoryGirl.create(:post_flag, :created_at => 5.days.ago, :is_resolved => true, :post_id => @resolved_flagged_post.id)
end
PostPruner.new.prune!
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "prune old pending posts" do
@old_post.reload
assert(@old_post.is_deleted?)
end
should "prune old flagged posts that are still unresolved" do
@unresolved_flagged_post.reload
assert(@unresolved_flagged_post.is_deleted?)
end
should "not prune old flagged posts that are resolved" do
@resolved_flagged_post.reload
assert(!@resolved_flagged_post.is_deleted?)

View File

@@ -16,12 +16,12 @@ module PostSets
@post_1.add_favorite!(@user)
@post_3.add_favorite!(@user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a favorite set for before the most recent post" do
setup do
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_3.id).first.id
@@ -36,7 +36,7 @@ module PostSets
end
end
end
context "a favorite set for after the second most recent post" do
setup do
id = ::Favorite.where(:user_id => @user.id, :post_id => @post_2.id).first.id
@@ -51,7 +51,7 @@ module PostSets
end
end
end
context "a favorite set for page 2" do
setup do
::Favorite.stubs(:records_per_page).returns(1)
@@ -65,7 +65,7 @@ module PostSets
end
end
end
context "a favorite set with no page specified" do
setup do
::Favorite.stubs(:records_per_page).returns(1)

View File

@@ -17,12 +17,12 @@ module PostSets
@pool.add!(@post_1)
@pool.add!(@post_3)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a post pool set for page 2" do
setup do
@set = PostSets::Pool.new(@pool, 2)
@@ -33,16 +33,16 @@ module PostSets
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::Pool.new(@pool)

View File

@@ -14,46 +14,46 @@ module PostSets
@post_2 = FactoryGirl.create(:post, :tag_string => "b")
@post_3 = FactoryGirl.create(:post, :tag_string => "c")
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "a set for page 2" do
setup do
@set = PostSets::Post.new("", 2)
::Post.stubs(:records_per_page).returns(1)
end
should "return the second element" do
assert_equal(@post_2.id, @set.posts.first.id)
end
end
context "a set for the 'a' tag query" do
setup do
@post_4 = FactoryGirl.create(:post, :tag_string => "a")
@post_5 = FactoryGirl.create(:post, :tag_string => "a")
end
context "with no page" do
setup do
@set = PostSets::Post.new("a")
::Post.stubs(:records_per_page).returns(1)
end
should "return the first element" do
assert_equal(@post_5.id, @set.posts.first.id)
end
end
context "for before the first element" do
setup do
@set = PostSets::Post.new("a", "b#{@post_5.id}")
::Post.stubs(:records_per_page).returns(1)
end
should "return the second element" do
assert_equal(@post_4.id, @set.posts.first.id)
end
@@ -64,40 +64,40 @@ module PostSets
@set = PostSets::Post.new("a", "a#{@post_4.id}")
@set.stubs(:records_per_page).returns(1)
end
should "return the first element" do
assert_equal(@post_5.id, @set.posts.first.id)
end
end
end
context "a set for the 'a b' tag query" do
setup do
@set = PostSets::Post.new("a b")
end
should "know it isn't a single tag" do
assert(!@set.is_single_tag?)
end
end
context "a set going to the 1,001st page" do
setup do
@set = PostSets::Post.new("a", 1_001)
end
should "fail" do
assert_raises(Danbooru::Paginator::PaginationError) do
@set.posts
end
end
end
context "a set for the 'a b c' tag query" do
setup do
@set = PostSets::Post.new("a b c")
end
context "for a non-privileged user" do
should "fail" do
assert_raises(PostSets::SearchError) do
@@ -105,12 +105,12 @@ module PostSets
end
end
end
context "for a privileged user" do
setup do
CurrentUser.user = FactoryGirl.create(:privileged_user)
end
should "pass" do
assert_nothing_raised do
@set.posts
@@ -118,44 +118,44 @@ module PostSets
end
end
end
context "a set for the 'a' tag query" do
setup do
@set = PostSets::Post.new("a")
end
should "know it is a single tag" do
assert(@set.is_single_tag?)
end
should "normalize its tag query" do
assert_equal("a", @set.tag_string)
end
should "know the count" do
assert_equal(1, @set.posts.total_count)
end
should "find the posts" do
assert_equal(@post_1.id, @set.posts.first.id)
end
context "that has a matching wiki page" do
setup do
@wiki_page = FactoryGirl.create(:wiki_page, :title => "a")
end
should "find the wiki page" do
assert_not_nil(@set.wiki_page)
assert_equal(@wiki_page.id, @set.wiki_page.id)
end
end
context "that has a matching artist" do
setup do
@artist = FactoryGirl.create(:artist, :name => "a")
end
should "find the artist" do
assert_not_nil(@set.artist)
assert_equal(@artist.id, @set.artist.id)

View File

@@ -8,54 +8,54 @@ class PostTest < ActiveSupport::TestCase
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "Deletion:" do
context "Annihilating a post" do
setup do
@post = FactoryGirl.create(:post)
end
context "that is status locked" do
setup do
@post.update_attributes({:is_status_locked => true}, :as => :admin)
end
should "not destroy the record" do
@post.annihilate!
assert_equal(1, Post.where("id = ?", @post.id).count)
end
end
should "destroy the record" do
@post.annihilate!
assert_equal([], @post.errors.full_messages)
assert_equal(0, Post.where("id = ?", @post.id).count)
end
end
context "Deleting a post" do
setup do
Danbooru.config.stubs(:blank_tag_search_fast_count).returns(nil)
end
context "that is status locked" do
setup do
@post = FactoryGirl.create(:post)
@post.update_attributes({:is_status_locked => true}, :as => :admin)
end
should "fail" do
@post.delete!
assert_equal(["Is status locked ; cannot delete post"], @post.errors.full_messages)
assert_equal(1, Post.where("id = ?", @post.id).count)
end
end
should "update the fast count" do
post = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal(1, Post.fast_count)
@@ -64,14 +64,14 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, Post.fast_count)
assert_equal(1, Post.fast_count("aaa"))
end
should "toggle the is_deleted flag" do
post = FactoryGirl.create(:post)
assert_equal(false, post.is_deleted?)
post.delete!
assert_equal(true, post.is_deleted?)
end
should "not decrement the tag counts" do
post = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal(1, Tag.find_by_name("aaa").post_count)
@@ -80,7 +80,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Parenting:" do
context "Assignining a parent to a post" do
should "update the has_children flag on the parent" do
@@ -90,7 +90,7 @@ class PostTest < ActiveSupport::TestCase
p1.reload
assert(p1.has_children?, "Parent not updated after child was added")
end
should "update the has_children flag on the old parent" do
p1 = FactoryGirl.create(:post)
p2 = FactoryGirl.create(:post)
@@ -108,7 +108,7 @@ class PostTest < ActiveSupport::TestCase
post.save
assert(post.errors[:parent].any?, "Parent should be invalid")
end
# should "fail if the parent has a parent" do
# p1 = FactoryGirl.create(:post)
# c1 = FactoryGirl.create(:post, :parent_id => p1.id)
@@ -117,7 +117,7 @@ class PostTest < ActiveSupport::TestCase
# assert(c2.errors[:parent].any?, "Parent should be invalid")
# end
end
context "Destroying a post with" do
context "a parent" do
should "reset the has_children flag of the parent" do
@@ -127,7 +127,7 @@ class PostTest < ActiveSupport::TestCase
p1.reload
assert_equal(false, p1.has_children?)
end
should "reassign favorites to the parent" do
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
@@ -148,7 +148,7 @@ class PostTest < ActiveSupport::TestCase
assert(!p1.has_children?, "Parent should not have children")
end
end
context "one child" do
should "remove the has_children flag" do
p1 = FactoryGirl.create(:post)
@@ -156,7 +156,7 @@ class PostTest < ActiveSupport::TestCase
p1.delete!
assert_equal(false, p1.has_children?)
end
should "remove the parent of that child" do
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
@@ -165,7 +165,7 @@ class PostTest < ActiveSupport::TestCase
assert_nil(c1.parent)
end
end
context "two or more children" do
should "reparent all children to the first child" do
p1 = FactoryGirl.create(:post)
@@ -182,7 +182,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Undestroying a post with a parent" do
should "create a new approver" do
new_user = FactoryGirl.create(:moderator_user)
@@ -195,7 +195,7 @@ class PostTest < ActiveSupport::TestCase
p1.reload
assert_equal(new_user.id, c1.approver_id)
end
should "not preserve the parent's has_children flag" do
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
@@ -213,25 +213,25 @@ class PostTest < ActiveSupport::TestCase
setup do
@post = FactoryGirl.create(:post, :is_deleted => true)
end
context "that is status locked" do
setup do
@post.update_attributes({:is_status_locked => true}, :as => :admin)
end
should "not allow undeletion" do
@post.undelete!
assert_equal(["Is status locked ; cannot undelete post"], @post.errors.full_messages)
assert_equal(true, @post.is_deleted?)
end
end
should "be undeleted" do
@post.undelete!
@post.reload
assert_equal(false, @post.is_deleted?)
end
should "be appealed" do
assert_difference("PostAppeal.count", 1) do
@post.appeal!("xxx")
@@ -240,7 +240,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, @post.appeals.count)
end
end
context "An approved post" do
should "be flagged" do
post = FactoryGirl.create(:post)
@@ -250,7 +250,7 @@ class PostTest < ActiveSupport::TestCase
assert(post.is_flagged?, "Post should be flagged.")
assert_equal(1, post.flags.count)
end
should "not be flagged if no reason is given" do
post = FactoryGirl.create(:post)
assert_difference("PostFlag.count", 0) do
@@ -260,20 +260,20 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "An unapproved post" do
context "An unapproved post" do
should "preserve the approver's identity when approved" do
post = FactoryGirl.create(:post, :is_pending => true)
post.approve!
assert_equal(post.approver_id, CurrentUser.id)
end
context "that was uploaded by person X" do
setup do
@post = FactoryGirl.create(:post)
@post.flag!("reason")
end
should "not allow person X to approve that post" do
assert_raises(Post::ApprovalError) do
CurrentUser.scoped(@post.uploader, "127.0.0.1") do
@@ -284,7 +284,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(["You cannot approve a post you uploaded"], @post.errors.full_messages)
end
end
context "that was previously approved by person X" do
setup do
@user = FactoryGirl.create(:janitor_user, :name => "xxx")
@@ -292,7 +292,7 @@ class PostTest < ActiveSupport::TestCase
@post = FactoryGirl.create(:post, :approver_id => @user.id)
@post.flag!("bad")
end
should "not allow person X to reapprove that post" do
CurrentUser.scoped(@user, "127.0.0.1") do
assert_raises(Post::ApprovalError) do
@@ -300,7 +300,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
should "allow person Y to approve the post" do
CurrentUser.scoped(@user2, "127.0.0.1") do
assert_nothing_raised do
@@ -309,7 +309,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "that has been reapproved" do
should "no longer be flagged or pending" do
post = FactoryGirl.create(:post)
@@ -328,19 +328,19 @@ class PostTest < ActiveSupport::TestCase
@post = FactoryGirl.create(:post)
@post.update_attributes({:is_status_locked => true}, :as => :admin)
end
should "not allow new flags" do
assert_raises(PostFlag::Error) do
@post.flag!("wrong")
end
end
should "not allow new appeals" do
assert_raises(PostAppeal::Error) do
@post.appeal!("wrong")
end
end
should "not allow approval" do
assert_raises(Post::ApprovalError) do
@post.approve!
@@ -354,7 +354,7 @@ class PostTest < ActiveSupport::TestCase
setup do
@post = FactoryGirl.create(:post)
end
context "with an artist tag that is then changed to copyright" do
setup do
Delayed::Worker.delay_jobs = false
@@ -364,32 +364,32 @@ class PostTest < ActiveSupport::TestCase
@post.update_attribute(:tag_string, "copy:abc")
@post.reload
end
teardown do
Delayed::Worker.delay_jobs = true
end
should "update the category of the tag" do
assert_equal(Tag.categories.copyright, Tag.find_by_name("abc").category)
end
should "update the category cache of the tag" do
assert_equal(Tag.categories.copyright, Cache.get("tc:abc"))
end
should "update the tag counts of the posts" do
assert_equal(0, @post.tag_count_artist)
assert_equal(1, @post.tag_count_copyright)
assert_equal(0, @post.tag_count_general)
end
end
context "tagged with a metatag" do
context "for a parent" do
setup do
@parent = FactoryGirl.create(:post)
end
should "update the parent relationships for both posts" do
@post.update_attributes(:tag_string => "aaa parent:#{@parent.id}")
@post.reload
@@ -398,14 +398,14 @@ class PostTest < ActiveSupport::TestCase
assert(@parent.has_children?)
end
end
context "for a pool" do
context "on creation" do
setup do
@pool = FactoryGirl.create(:pool)
@post = FactoryGirl.create(:post, :tag_string => "aaa pool:#{@pool.id}")
end
should "add the post to the pool" do
@post.reload
@pool.reload
@@ -413,13 +413,13 @@ class PostTest < ActiveSupport::TestCase
assert_equal("pool:#{@pool.id}", @post.pool_string)
end
end
context "id" do
setup do
@pool = FactoryGirl.create(:pool)
@post.update_attributes(:tag_string => "aaa pool:#{@pool.id}")
end
should "add the post to the pool" do
@post.reload
@pool.reload
@@ -427,7 +427,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal("pool:#{@pool.id}", @post.pool_string)
end
end
context "name" do
context "that exists" do
setup do
@@ -442,7 +442,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal("pool:#{@pool.id}", @post.pool_string)
end
end
context "that doesn't exist" do
should "create a new pool and add the post to that pool" do
@post.update_attributes(:tag_string => "aaa pool:abc")
@@ -455,7 +455,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "for a rating" do
context "that is valid" do
should "update the rating" do
@@ -464,7 +464,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal("e", @post.rating)
end
end
context "that is invalid" do
should "not update the rating" do
@post.update_attributes(:tag_string => "aaa rating:z")
@@ -473,7 +473,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "for a fav" do
should "add the current user to the post's favorite listing" do
@post.update_attributes(:tag_string => "aaa fav:self")
@@ -482,24 +482,24 @@ class PostTest < ActiveSupport::TestCase
end
end
end
should "have an array representation of its tags" do
post = FactoryGirl.create(:post)
post.set_tag_string("aaa bbb")
assert_equal(%w(aaa bbb), post.tag_array)
assert_equal(%w(tag1 tag2), post.tag_array_was)
end
context "that has been updated" do
should "increment the updater's post_update_count" do
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
assert_difference("CurrentUser.post_update_count", 1) do
post.update_attributes(:tag_string => "zzz")
CurrentUser.reload
end
end
should "reset its tag array cache" do
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
user = FactoryGirl.create(:user)
@@ -516,7 +516,7 @@ class PostTest < ActiveSupport::TestCase
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
end
should "update the post counts of relevant tag records" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
post2 = FactoryGirl.create(:post, :tag_string => "bbb ccc ddd")
@@ -528,12 +528,12 @@ class PostTest < ActiveSupport::TestCase
post3.save
assert_equal(1, Tag.find_by_name("aaa").post_count)
assert_equal(2, Tag.find_by_name("bbb").post_count)
assert_equal(2, Tag.find_by_name("ccc").post_count)
assert_equal(1, Tag.find_by_name("ddd").post_count)
assert_equal(2, Tag.find_by_name("ccc").post_count)
assert_equal(1, Tag.find_by_name("ddd").post_count)
assert_equal(0, Tag.find_by_name("eee").post_count)
assert_equal(1, Tag.find_by_name("xxx").post_count)
end
should "update its tag counts" do
artist_tag = FactoryGirl.create(:artist_tag)
copyright_tag = FactoryGirl.create(:copyright_tag)
@@ -553,7 +553,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(0, new_post.tag_count_character)
assert_equal(1, new_post.tag_count)
end
should "merge any changes that were made after loading the initial set of tags part 1" do
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
@@ -570,10 +570,10 @@ class PostTest < ActiveSupport::TestCase
post_edited_by_user_b.save
# final should be <aaa>, <bbb>, <ddd>, <eee>
final_post = Post.find(post.id)
final_post = Post.find(post.id)
assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(final_post.tag_string).sort)
end
should "merge any changes that were made after loading the initial set of tags part 2" do
# This is the same as part 1, only the order of operations is reversed.
# The results should be the same.
@@ -593,7 +593,7 @@ class PostTest < ActiveSupport::TestCase
post_edited_by_user_b.save
# final should be <aaa>, <bbb>, <ddd>, <eee>
final_post = Post.find(post.id)
final_post = Post.find(post.id)
assert_equal(%w(aaa bbb ddd eee), Tag.scan_tags(final_post.tag_string).sort)
end
end
@@ -608,7 +608,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Favorites:" do
context "Removing a post from a user's favorites" do
setup do
@@ -618,19 +618,19 @@ class PostTest < ActiveSupport::TestCase
@post = FactoryGirl.create(:post)
@post.add_favorite!(@user)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "decrement the user's favorite_count" do
assert_difference("CurrentUser.favorite_count", -1) do
@post.remove_favorite!(@user)
CurrentUser.reload
end
end
should "decrement the post's score for privileged users" do
@post.remove_favorite!(@user)
@post.reload
@@ -645,7 +645,7 @@ class PostTest < ActiveSupport::TestCase
@post.reload
assert_equal(1, @post.score)
end
should "not decrement the user's favorite_count if the user did not favorite the post" do
@post2 = FactoryGirl.create(:post)
assert_difference("CurrentUser.favorite_count", 0) do
@@ -654,7 +654,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Adding a post to a user's favorites" do
setup do
@user = FactoryGirl.create(:contributor_user)
@@ -662,25 +662,25 @@ class PostTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "increment the user's favorite_count" do
assert_difference("CurrentUser.favorite_count", 1) do
@post.add_favorite!(@user)
CurrentUser.reload
end
end
should "increment the post's score for privileged users" do
@post.add_favorite!(@user)
@post.reload
assert_equal(1, @post.score)
end
should "not increment the post's score for basic users" do
@member = FactoryGirl.create(:user)
CurrentUser.scoped(@member, "127.0.0.1") do
@@ -689,7 +689,7 @@ class PostTest < ActiveSupport::TestCase
@post.reload
assert_equal(0, @post.score)
end
should "update the fav strings ont he post" do
@post.add_favorite!(@user)
@post.reload
@@ -705,7 +705,7 @@ class PostTest < ActiveSupport::TestCase
@post.reload
assert_equal("", @post.fav_string)
assert(!Favorite.exists?(:user_id => @user.id, :post_id => @post.id))
@post.remove_favorite!(@user)
@post.reload
assert_equal("", @post.fav_string)
@@ -713,7 +713,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Pools:" do
context "Removing a post from a pool" do
should "update the post's pool string" do
@@ -728,7 +728,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal("", post.pool_string)
end
end
context "Adding a post to a pool" do
should "update the post's pool string" do
post = FactoryGirl.create(:post)
@@ -745,7 +745,7 @@ class PostTest < ActiveSupport::TestCase
end
end
end
context "Uploading:" do
context "Uploading a post" do
should "capture who uploaded the post" do
@@ -772,28 +772,28 @@ class PostTest < ActiveSupport::TestCase
count = Post.tag_match("'").count
assert_equal(1, count)
end
should "return posts for the \\ tag" do
post1 = FactoryGirl.create(:post, :tag_string => "\\")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("\\").count
assert_equal(1, count)
end
should "return posts for the ( tag" do
post1 = FactoryGirl.create(:post, :tag_string => "(")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("(").count
assert_equal(1, count)
end
should "return posts for the ? tag" do
post1 = FactoryGirl.create(:post, :tag_string => "?")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
count = Post.tag_match("?").count
assert_equal(1, count)
end
should "return posts for 1 tag" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@@ -812,7 +812,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
end
should "return posts for 1 tag with exclusion" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@@ -821,7 +821,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for 1 tag with a pattern" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
@@ -829,9 +829,9 @@ class PostTest < ActiveSupport::TestCase
relation = Post.tag_match("a*")
assert_equal(2, relation.count)
assert_equal(post2.id, relation.all[0].id)
assert_equal(post1.id, relation.all[1].id)
assert_equal(post1.id, relation.all[1].id)
end
should "return posts for 2 tags, one with a pattern" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
@@ -840,7 +840,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
end
should "return posts for the <id> metatag" do
post1 = FactoryGirl.create(:post)
post2 = FactoryGirl.create(:post)
@@ -855,7 +855,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for the <fav> metatag" do
post1 = FactoryGirl.create(:post)
post2 = FactoryGirl.create(:post)
@@ -866,7 +866,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for the <pool> metatag" do
post1 = FactoryGirl.create(:post)
post2 = FactoryGirl.create(:post)
@@ -877,13 +877,13 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for the <user> metatag" do
second_user = FactoryGirl.create(:user)
post1 = FactoryGirl.create(:post, :uploader => CurrentUser.user)
assert_equal(CurrentUser.id, post1.uploader_id)
CurrentUser.scoped(second_user, "127.0.0.2") do
post2 = FactoryGirl.create(:post)
post3 = FactoryGirl.create(:post)
@@ -893,13 +893,13 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for the <pixiv> metatag" do
post = FactoryGirl.create(:post, :source => "http://i1.pixiv.net/img123/img/artist-name/789.png")
assert_equal(1, Post.tag_match("pixiv:789").count)
assert_equal(0, Post.tag_match("pixiv:790").count)
end
should "return posts for a list of md5 hashes" do
post1 = FactoryGirl.create(:post, :md5 => "abcd")
post2 = FactoryGirl.create(:post)
@@ -908,7 +908,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for a source search" do
post1 = FactoryGirl.create(:post, :source => "abcd")
post2 = FactoryGirl.create(:post, :source => "abcdefg")
@@ -917,14 +917,14 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
end
should "return posts for a case sensitive source search" do
post1 = FactoryGirl.create(:post, :source => "ABCD")
post2 = FactoryGirl.create(:post, :source => "1234")
relation = Post.tag_match("source:ABCD")
assert_equal(1, relation.count)
end
should "return posts for a pixiv source search" do
post = FactoryGirl.create(:post, :source => "http://i1.pixiv.net/img123/img/artist-name/789.png")
assert_equal(1, Post.tag_match("source:pixiv/artist-name/*").count)
@@ -932,7 +932,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, Post.tag_match("source:*.pixiv.net/img*/artist-name/*").count)
assert_equal(0, Post.tag_match("source:*.pixiv.net/img*/artist-fake/*").count)
end
should "return posts for a tag subscription search" do
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
@@ -940,7 +940,7 @@ class PostTest < ActiveSupport::TestCase
relation = Post.tag_match("sub:#{CurrentUser.name}")
assert_equal(1, relation.count)
end
should "return posts for a particular rating" do
post1 = FactoryGirl.create(:post, :rating => "s")
post2 = FactoryGirl.create(:post, :rating => "q")
@@ -949,7 +949,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post3.id, relation.first.id)
end
should "return posts for a particular negated rating" do
post1 = FactoryGirl.create(:post, :rating => "s")
post2 = FactoryGirl.create(:post, :rating => "s")
@@ -958,7 +958,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, relation.count)
assert_equal(post3.id, relation.first.id)
end
should "return posts ordered by a particular attribute" do
post1 = FactoryGirl.create(:post, :rating => "s")
post2 = FactoryGirl.create(:post, :rating => "s")
@@ -968,9 +968,9 @@ class PostTest < ActiveSupport::TestCase
relation = Post.tag_match("order:mpixels")
assert_equal(post3.id, relation.first.id)
relation = Post.tag_match("order:landscape")
assert_equal(post3.id, relation.first.id)
assert_equal(post3.id, relation.first.id)
end
should "fail for more than 6 tags" do
post1 = FactoryGirl.create(:post, :rating => "s")
@@ -978,14 +978,14 @@ class PostTest < ActiveSupport::TestCase
Post.tag_match("a b c rating:s width:10 height:10 user:bob")
end
end
should "succeed for exclusive tag searches with no other tag" do
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
assert_nothing_raised do
relation = Post.tag_match("-aaa")
end
end
should "succeed for exclusive tag searches combined with a metatag" do
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
assert_nothing_raised do
@@ -1023,7 +1023,7 @@ class PostTest < ActiveSupport::TestCase
FactoryGirl.create(:tag_alias, :antecedent_name => "alias", :consequent_name => "aaa")
FactoryGirl.create(:post, :tag_string => "aaa")
end
should "be counted correctly in fast_count" do
assert_equal(1, Post.count)
assert_equal(Danbooru.config.blank_tag_search_fast_count, Post.fast_count(""))
@@ -1032,7 +1032,7 @@ class PostTest < ActiveSupport::TestCase
assert_equal(0, Post.fast_count("bbb"))
end
end
should "increment the post count" do
assert_equal(0, Post.fast_count(""))
post = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@@ -1040,10 +1040,10 @@ class PostTest < ActiveSupport::TestCase
assert_equal(1, Post.fast_count("aaa"))
assert_equal(1, Post.fast_count("bbb"))
assert_equal(0, Post.fast_count("ccc"))
post.tag_string = "ccc"
post.save
assert_equal(1, Post.fast_count(""))
assert_equal(0, Post.fast_count("aaa"))
assert_equal(0, Post.fast_count("bbb"))
@@ -1060,24 +1060,24 @@ class PostTest < ActiveSupport::TestCase
@post.update_attributes(:tag_string => "bbb xxx yyy", :source => "xyz")
@post.update_attributes(:tag_string => "bbb mmm yyy", :source => "abc")
end
context "and then reverted to an early version" do
setup do
@post.revert_to(@post.versions[1])
end
should "correctly revert all fields" do
assert_equal("aaa bbb ccc ddd", @post.tag_string)
assert_equal(nil, @post.source)
assert_equal("q", @post.rating)
end
end
context "and then reverted to a later version" do
setup do
@post.revert_to(@post.versions[-2])
end
should "correctly revert all fields" do
assert_equal("bbb xxx yyy", @post.tag_string)
assert_equal("xyz", @post.source)

View File

@@ -8,29 +8,29 @@ class PostVersionTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "that has multiple versions: " do
setup do
@post = FactoryGirl.create(:post, :tag_string => "1")
@post.update_attributes(:tag_string => "1 2")
@post.update_attributes(:tag_string => "2 3")
end
context "a version record" do
setup do
@version = PostVersion.last
end
should "know its previous version" do
assert_not_nil(@version.previous)
assert_equal("1 2", @version.previous.tags)
end
should "know the seuqence of all versions for the post" do
assert_equal(2, @version.sequence_for_post.size)
assert_equal(%w(3), @version.sequence_for_post[0][:added_tags])
@@ -38,13 +38,13 @@ class PostVersionTest < ActiveSupport::TestCase
end
end
end
context "that has been created" do
setup do
@parent = FactoryGirl.create(:post)
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
end
should "also create a version" do
assert_equal(1, @post.versions.size)
@version = @post.versions.last
@@ -54,14 +54,14 @@ class PostVersionTest < ActiveSupport::TestCase
assert_equal(@post.source, @version.source)
end
end
context "that has been updated" do
setup do
@parent = FactoryGirl.create(:post)
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
end
should "also create a version" do
assert_equal(2, @post.versions.size)
@version = @post.versions.last

View File

@@ -6,21 +6,21 @@ class PostVoteTest < ActiveSupport::TestCase
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post = FactoryGirl.create(:post)
end
context "Voting for a post" do
should "interpret up as +1 score" do
vote = PostVote.create(:post_id => @post.id, :score => "up")
assert_equal(1, vote.score)
end
should "interpret down as -1 score" do
vote = PostVote.create(:post_id => @post.id, :score => "down")
assert_equal(-1, vote.score)
end
should "not accept any other scores" do
vote = PostVote.create(:post_id => @post.id, :score => "xxx")
assert(vote.errors.any?)

View File

@@ -7,28 +7,28 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "A related tag calculator" do
should "calculate related tags for a tag" do
posts = []
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb")
assert_equal({"aaa" => 3, "bbb" => 3, "ccc" => 2, "ddd" => 1}, RelatedTagCalculator.calculate_from_sample("aaa", 10))
end
should "calculate related tags for multiple tag" do
posts = []
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
posts << FactoryGirl.create(:post, :tag_string => "aaa eee fff")
assert_equal({"aaa"=>2, "bbb"=>2, "ddd"=>1, "ccc"=>2}, RelatedTagCalculator.calculate_from_sample("aaa bbb", 10))
end
@@ -37,17 +37,17 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb art:ccc copy:ddd")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb art:ccc")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb")
assert_equal({"ccc" => 2}, RelatedTagCalculator.calculate_from_sample("aaa", 10, Tag.categories.artist))
assert_equal({"ddd" => 1}, RelatedTagCalculator.calculate_from_sample("aaa", 10, Tag.categories.copyright))
end
should "convert a hash into string format" do
posts = []
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc ddd")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
posts << FactoryGirl.create(:post, :tag_string => "aaa bbb")
tag = Tag.find_by_name("aaa")
counts = RelatedTagCalculator.calculate_from_sample("aaa", 10)
assert_equal("aaa 3 bbb 3 ccc 2 ddd 1", RelatedTagCalculator.convert_hash_to_string(counts))

View File

@@ -8,7 +8,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
context "a related tag query without a category constraint" do
setup do
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@@ -20,48 +20,48 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
Tag.named("aaa").first.update_related
@query = RelatedTagQuery.new("aaa", "")
end
should "work" do
assert_equal(["aaa", "bbb", "ccc"], @query.tags)
end
should "render the json" do
assert_equal("{\"query\":\"aaa\",\"category\":\"\",\"tags\":[[\"aaa\",0],[\"bbb\",0],[\"ccc\",0]],\"wiki_page_tags\":[]}", @query.to_json)
end
end
context "for a tag that doesn't exist" do
setup do
@query = RelatedTagQuery.new("zzz", "")
end
should "work" do
assert_equal([], @query.tags)
end
end
context "for a pattern search" do
setup do
@query = RelatedTagQuery.new("a*", "")
end
should "work" do
assert_equal(["aaa"], @query.tags)
end
end
context "for a tag with a wiki page" do
setup do
@wiki_page = FactoryGirl.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]")
@query = RelatedTagQuery.new("aaa", "")
end
should "find any tags embedded in the wiki page" do
assert_equal(["bbb", "ccc"], @query.wiki_page_tags)
end
end
end
context "a related tag query with a category constraint" do
setup do
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@@ -69,7 +69,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
@post_3 = FactoryGirl.create(:post, :tag_string => "aaa copy:ddd")
@query = RelatedTagQuery.new("aaa", "artist")
end
should "find the related tags" do
assert_equal(%w(ccc), @query.tags)
end

View File

@@ -10,19 +10,19 @@ module Sources
@site = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im1464351?track=ranking")
@site.get
end
should "get the profile" do
assert_equal("http://seiga.nicovideo.jp/user/illust/20446930?target=seiga", @site.profile_url)
end
should "get the artist name" do
assert_equal("rariemonn", @site.artist_name)
end
should "get the image url" do
assert_equal("http://seiga.nicovideo.jp/image/source?id=1464351", @site.image_url)
end
should "get the tags" do
assert(@site.tags.size > 0)
first_tag = @site.tags.first

View File

@@ -1,7 +1,7 @@
# # encoding: UTF-8
#
#
# require 'test_helper'
#
#
# module Sources
# class PixaTest < ActiveSupport::TestCase
# context "The source site for pixa" do
@@ -9,26 +9,26 @@
# @site = Sources::Site.new("http://www.pixa.cc/illustrations/show/75575")
# @site.get
# end
#
#
# should "get the profile" do
# assert_equal("http://www.pixa.cc/profiles/show/9191", @site.profile_url)
# end
#
#
# should "get the artist name" do
# assert_equal("air", @site.artist_name)
# end
#
#
# should "get the image url" do
# assert_equal("http://file0.pixa.cc/illustrations/34/cb/df/70/49/b4/52/2d/42/c6/middle/110910魔法少女のコピー.jpg?1315664621", @site.image_url)
# end
#
#
# should "get the tags" do
# assert(@site.tags.size > 0)
# first_tag = @site.tags.first
# assert_equal(2, first_tag.size)
# assert(first_tag[0] =~ /./)
# end
#
#
# should "convert a page into a json representation" do
# assert_nothing_raised do
# @site.to_json

View File

@@ -9,19 +9,19 @@ module Sources
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=big&illust_id=9646484")
@site.get
end
should "get the profile" do
assert_equal("http://www.pixiv.net/member.php?id=4015", @site.profile_url)
end
should "get the artist name" do
assert_equal("シビレ罠", @site.artist_name)
end
should "get the image url" do
assert_equal("http://i1.pixiv.net/img01/img/nisieda/9646484.jpg", @site.image_url)
end
should "get the tags" do
assert(@site.tags.size > 0)
first_tag = @site.tags.first
@@ -29,7 +29,7 @@ module Sources
assert(first_tag[0] =~ /./)
assert(first_tag[1] =~ /search\.php/)
end
should "convert a page into a json representation" do
assert_nothing_raised do
@site.to_json

View File

@@ -1,7 +1,7 @@
# # encoding: UTF-8
#
#
# require 'test_helper'
#
#
# module Sources
# class TinamiTest < ActiveSupport::TestCase
# context "The source site for tinami" do
@@ -10,23 +10,23 @@
# @site = Sources::Site.new("http://www.tinami.com/view/308311")
# @site.get
# end
#
#
# should "get the profile" do
# assert_equal("http://www.tinami.com/creator/profile/29399", @site.profile_url)
# end
#
#
# should "get the artist name" do
# assert_match(/ROM/, @site.artist_name)
# end
#
#
# should "get the image url" do
# assert_equal("http://img.tinami.com/illust2/img/336/4e80b9773c084.png", @site.image_url)
# end
#
#
# should "get the tags" do
# assert(@site.tags.size > 0)
# end
#
#
# should "convert a page into a json representation" do
# assert_nothing_raised do
# @site.to_json

View File

@@ -17,41 +17,41 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "with a bad cache and post counts" do
setup do
Cache.put("ta:aaa", "zzz")
Tag.update_all("post_count = -3", "name = 'aaa'")
@correction = TagAliasCorrection.new(@tag_alias.id)
end
should "have the correct statistics hash" do
assert_equal("zzz", @correction.statistics_hash["antecedent_cache"])
assert_equal("bbb", @correction.statistics_hash["consequent_cache"])
assert_equal(-3, @correction.statistics_hash["antecedent_count"])
assert_equal(1, @correction.statistics_hash["consequent_count"])
end
should "render to json" do
assert_nothing_raised do
@correction.to_json
end
assert_nothing_raised do
JSON.parse(@correction.to_json)
end
end
context "that is fixed" do
setup do
@correction.fix!
TagAlias.to_aliased(["aaa"])
end
should "now have the correct cache" do
assert_equal("bbb", Cache.get("ta:aaa"))
end
should "now have the correct count" do
assert_equal(0, Tag.find_by_name("aaa").post_count)
end

View File

@@ -15,13 +15,13 @@ class TagAliasRequestTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "raise an exception if invalid" do
assert_raises(TagAliasRequest::ValidationError) do
TagAliasRequest.new("", "", "reason").create
end
end
should "create a tag alias" do
assert_difference("TagAlias.count", 1) do
TagAliasRequest.new("aaa", "bbb", "reason").create

View File

@@ -14,12 +14,12 @@ class TagAliasTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "populate the creator information" do
ta = FactoryGirl.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 = FactoryGirl.create(:tag, :name => "aaa")
tag2 = FactoryGirl.create(:tag, :name => "bbb")
@@ -27,7 +27,7 @@ class TagAliasTest < ActiveSupport::TestCase
normalized_tags = TagAlias.to_aliased(["aaa", "ccc"])
assert_equal(["bbb", "ccc"], normalized_tags.sort)
end
should "update the cache" do
tag1 = FactoryGirl.create(:tag, :name => "aaa")
tag2 = FactoryGirl.create(:tag, :name => "bbb")
@@ -38,7 +38,7 @@ class TagAliasTest < ActiveSupport::TestCase
ta.destroy
assert_nil(Cache.get("ta:aaa"))
end
should "update any affected posts when saved" do
assert_equal(0, TagAlias.count)
post1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@@ -51,7 +51,7 @@ class TagAliasTest < ActiveSupport::TestCase
assert_equal("bbb ccc", post1.tag_string)
assert_equal("ccc ddd", post2.tag_string)
end
should "not validate for transitive relations" do
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
assert_difference("TagAlias.count", 0) do
@@ -61,7 +61,7 @@ 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
uploader = FactoryGirl.create(:user)
post = nil
@@ -73,7 +73,7 @@ class TagAliasTest < ActiveSupport::TestCase
assert_not_equal(tag_alias.creator_id, post.uploader_id)
assert_equal(tag_alias.creator_id, post.versions.last.updater_id)
end
should "push the antecedent's category to the consequent" do
tag1 = FactoryGirl.create(:tag, :name => "aaa", :category => 1)
tag2 = FactoryGirl.create(:tag, :name => "bbb")

View File

@@ -15,13 +15,13 @@ class TagImplicationRequestTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "raise an exception if invalid" do
assert_raises(TagImplicationRequest::ValidationError) do
TagImplicationRequest.new("", "", "reason").create
end
end
should "create a tag implication" do
assert_difference("TagImplication.count", 1) do
TagImplicationRequest.new("aaa", "bbb", "reason").create

View File

@@ -14,12 +14,12 @@ class TagImplicationTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "populate the creator information" do
ti = FactoryGirl.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 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "bbb", :consequent_name => "aaa")
@@ -27,7 +27,7 @@ class TagImplicationTest < ActiveSupport::TestCase
assert(ti2.errors.any?, "Tag implication should not have validated.")
assert_equal("Tag implication can not create a circular relation with another tag implication", ti2.errors.full_messages.join(""))
end
should "not allow for duplicates" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
@@ -35,11 +35,11 @@ class TagImplicationTest < ActiveSupport::TestCase
assert(ti2.errors.any?, "Tag implication should not have validated.")
assert_equal("Antecedent name has already been taken", ti2.errors.full_messages.join(""))
end
should "calculate all its descendants" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
assert_equal("ccc", ti1.descendant_names)
assert_equal(["ccc"], ti1.descendant_names_array)
assert_equal(["ccc"], ti1.descendant_names_array)
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
assert_equal("bbb ccc", ti2.descendant_names)
assert_equal(["bbb", "ccc"], ti2.descendant_names_array)
@@ -47,7 +47,7 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("ccc", ti1.descendant_names)
assert_equal(["ccc"], ti1.descendant_names_array)
end
should "update its descendants on save" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
@@ -59,7 +59,7 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("bbb ddd", ti1.descendant_names)
assert_equal("ddd", ti2.descendant_names)
end
should "update the decendants for its parent on create" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti1.reload
@@ -92,7 +92,7 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("eee", ti4.descendant_names)
end
should "update any affected post upon save" do
p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
@@ -100,7 +100,7 @@ class TagImplicationTest < ActiveSupport::TestCase
p1.reload
assert_equal("aaa bbb ccc xxx yyy", p1.tag_string)
end
should "record the implication's creator in the tag history" do
user = FactoryGirl.create(:user)
p1 = nil

View File

@@ -7,26 +7,26 @@ class TagSubscriptionTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "A tag subscription" do
context "for a user with too many subscriptions" do
setup do
Danbooru.config.stubs(:max_tag_subscriptions).returns(0)
@user = FactoryGirl.create(:user)
end
should "fail" do
sub = FactoryGirl.build(:tag_subscription, :tag_query => "aaa bbb", :creator => @user, :name => "zzz")
sub.save
assert_equal(["You can create up to 0 tag subscriptions"], sub.errors.full_messages)
end
end
should "find the union of all posts for each tag in its tag query" do
posts = []
user = FactoryGirl.create(:user)
@@ -41,7 +41,7 @@ class TagSubscriptionTest < ActiveSupport::TestCase
assert_equal([posts[2].id, posts[1].id, posts[0].id], TagSubscription.find_posts(user.id).map(&:id))
end
end
should "cache its tag query results" do
posts = []
user = FactoryGirl.create(:user)
@@ -53,7 +53,7 @@ class TagSubscriptionTest < ActiveSupport::TestCase
assert_equal("#{posts[1].id},#{posts[0].id}", sub.post_ids)
end
end
should "find posts based on its cached post ids" do
user = FactoryGirl.create(:user)
CurrentUser.scoped(user, "127.0.0.1") do

View File

@@ -8,17 +8,17 @@ class TagTest < ActiveSupport::TestCase
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "A tag category fetcher" do
setup do
MEMCACHE.flush_all
end
should "fetch for a single tag" do
FactoryGirl.create(:artist_tag, :name => "test")
assert_equal(Tag.categories.artist, Tag.category_for("test"))
@@ -28,7 +28,7 @@ class TagTest < ActiveSupport::TestCase
FactoryGirl.create(:artist_tag, :name => "!@$%")
assert_equal(Tag.categories.artist, Tag.category_for("!@$%"))
end
should "fetch for multiple tags" do
FactoryGirl.create(:artist_tag, :name => "aaa")
FactoryGirl.create(:copyright_tag, :name => "bbb")
@@ -38,26 +38,26 @@ class TagTest < ActiveSupport::TestCase
assert_equal(0, categories["ccc"])
end
end
context "A tag category mapping" do
setup do
MEMCACHE.flush_all
end
should "exist" do
assert_nothing_raised {Tag.categories}
end
should "have convenience methods for the four main categories" do
assert_equal(0, Tag.categories.general)
assert_equal(1, Tag.categories.artist)
assert_equal(3, Tag.categories.copyright)
assert_equal(4, Tag.categories.character)
end
should "have a regular expression for matching category names and shortcuts" do
regexp = Tag.categories.regexp
assert_match(regexp, "artist")
assert_match(regexp, "art")
assert_match(regexp, "copyright")
@@ -69,16 +69,16 @@ class TagTest < ActiveSupport::TestCase
assert_no_match(regexp, "c")
assert_no_match(regexp, "woodle")
end
should "map a category name to its value" do
assert_equal(0, Tag.categories.value_for("general"))
assert_equal(0, Tag.categories.value_for("gen"))
assert_equal(1, Tag.categories.value_for("artist"))
assert_equal(1, Tag.categories.value_for("art"))
assert_equal(0, Tag.categories.value_for("unknown"))
assert_equal(0, Tag.categories.value_for("unknown"))
end
end
context "A tag" do
setup do
MEMCACHE.flush_all
@@ -88,29 +88,29 @@ class TagTest < ActiveSupport::TestCase
@tag = FactoryGirl.create(:artist_tag)
assert_equal("Artist", @tag.category_name)
end
should "reset its category after updating" do
tag = FactoryGirl.create(:artist_tag)
tag.update_category_cache_for_all
assert_equal(Tag.categories.artist, MEMCACHE.get("tc:#{tag.name}"))
tag.update_attribute(:category, Tag.categories.copyright)
tag.update_category_cache_for_all
assert_equal(Tag.categories.copyright, MEMCACHE.get("tc:#{tag.name}"))
end
end
context "A tag parser" do
should "scan a query" do
assert_equal(%w(aaa bbb), Tag.scan_query("aaa bbb"))
assert_equal(%w(~AAa -BBB* -bbb*), Tag.scan_query("~AAa -BBB* -bbb*"))
end
should "strip out invalid characters when scanning" do
assert_equal(%w(aaa bbb), Tag.scan_tags("aaa bbb"))
assert_equal(%w(-BB;B* -b_b_b_), Tag.scan_tags("-B,B;B* -b_b_b_"))
end
should "cast values" do
assert_equal(2048, Tag.parse_cast("2kb", :filesize))
assert_equal(2097152, Tag.parse_cast("2m", :filesize))
@@ -118,7 +118,7 @@ class TagTest < ActiveSupport::TestCase
assert_nothing_raised {Tag.parse_cast("1234", :integer)}
assert_nothing_raised {Tag.parse_cast("1234.56", :float)}
end
should "parse a query" do
tag1 = FactoryGirl.create(:tag, :name => "abc")
tag2 = FactoryGirl.create(:tag, :name => "acb")
@@ -134,7 +134,7 @@ class TagTest < ActiveSupport::TestCase
assert_equal(["acb"], Tag.parse_query("a*b")[:tags][:include])
end
end
context "A tag" do
should "be found when one exists" do
tag = FactoryGirl.create(:tag)
@@ -142,7 +142,7 @@ class TagTest < ActiveSupport::TestCase
Tag.find_or_create_by_name(tag.name)
end
end
should "change the type for an existing tag" do
tag = FactoryGirl.create(:tag)
assert_difference("Tag.count", 0) do
@@ -152,7 +152,7 @@ class TagTest < ActiveSupport::TestCase
assert_equal(Tag.categories.artist, tag.category)
end
end
should "be created when one doesn't exist" do
assert_difference("Tag.count", 1) do
tag = Tag.find_or_create_by_name("hoge")
@@ -160,7 +160,7 @@ class TagTest < ActiveSupport::TestCase
assert_equal(Tag.categories.general, tag.category)
end
end
should "be created with the type when one doesn't exist" do
assert_difference("Tag.count", 1) do
tag = Tag.find_or_create_by_name("artist:hoge")

View File

@@ -18,11 +18,11 @@ class UploadTest < ActiveSupport::TestCase
@upload.delete_temp_file if @upload
end
context "An upload" do
context "An upload" do
teardown do
FileUtils.rm_f(Dir.glob("#{Rails.root}/tmp/test.*"))
end
context "that has incredibly absurd res dimensions" do
setup do
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
@@ -30,19 +30,19 @@ class UploadTest < ActiveSupport::TestCase
@upload.image_height = 10
@upload.add_dimension_tags!
end
should "have the incredibly_absurdres tag" do
assert_match(/incredibly_absurdres/, @upload.tag_string)
end
end
context "that has a large flie size" do
setup do
@upload = FactoryGirl.build(:jpg_upload, :tag_string => "")
@upload.file_size = 11.megabytes
@upload.add_file_size_tags!(@upload.file_path)
end
should "have the huge_filesize tag" do
assert_match(/huge_filesize/, @upload.tag_string)
end
@@ -131,7 +131,7 @@ class UploadTest < ActiveSupport::TestCase
assert_equal(28086, File.size(@upload.file_path))
assert_equal("jpg", @upload.file_ext)
end
should "process a transparent png" do
FileUtils.cp("#{Rails.root}/test/files/alpha.png", "#{Rails.root}/tmp")
@upload = Upload.new(:file => upload_file("#{Rails.root}/tmp/alpha.png", "image/png", "alpha.png"))
@@ -169,7 +169,7 @@ class UploadTest < ActiveSupport::TestCase
assert_equal(108224, File.size(@upload.resized_file_path_for(Danbooru.config.large_image_width)))
end
end
should "increment the uploaders post_upload_count" do
@upload = FactoryGirl.create(:source_upload)
assert_difference("CurrentUser.post_upload_count", 1) do
@@ -225,7 +225,7 @@ class UploadTest < ActiveSupport::TestCase
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
should "delete the temporary file upon completion" do

View File

@@ -11,27 +11,27 @@ class UserFeedbackTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
should "create a dmail" do
user = FactoryGirl.create(:user)
privileged = FactoryGirl.create(:privileged_user)
member = FactoryGirl.create(:user)
CurrentUser.user = privileged
assert_difference("Dmail.count", 2) do
FactoryGirl.create(:user_feedback, :user => user)
end
end
should "should not validate if the creator is not privileged" do
user = FactoryGirl.create(:user)
privileged = FactoryGirl.create(:privileged_user)
member = FactoryGirl.create(:user)
CurrentUser.user = privileged
feedback = FactoryGirl.create(:user_feedback, :user => user)
assert(feedback.errors.empty?)
CurrentUser.user = member
feedback = FactoryGirl.build(:user_feedback, :user => user)
feedback.save

View File

@@ -7,11 +7,11 @@ class UserPasswordResetNonceTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user, :email => "aaa@b.net")
@nonce = FactoryGirl.create(:user_password_reset_nonce, :email => @user.email)
end
should "validate" do
assert_equal([], @nonce.errors.full_messages)
end
should "populate the key with a random string" do
assert_equal(32, @nonce.key.size)
end
@@ -21,24 +21,24 @@ class UserPasswordResetNonceTest < ActiveSupport::TestCase
@nonce.reset_user!
end
end
context "with a blank email" do
setup do
@user = FactoryGirl.create(:user, :email => "")
@nonce = UserPasswordResetNonce.new(:email => "")
end
should "not validate" do
@nonce.save
assert_equal(["Email can't be blank", "Email is invalid"], @nonce.errors.full_messages.sort)
end
end
context "with an invalid email" do
setup do
@nonce = UserPasswordResetNonce.new(:email => "z@z.net")
end
should "not validate" do
@nonce.save
assert_equal(["Email is invalid"], @nonce.errors.full_messages)

View File

@@ -13,24 +13,24 @@ class UserTest < ActiveSupport::TestCase
CurrentUser.user = nil
CurrentUser.ip_addr = nil
end
context "that has been invited by a mod" do
setup do
@mod = FactoryGirl.create(:moderator_user)
end
should "work" do
@user.invite!(User::Levels::CONTRIBUTOR)
@user.reload
assert_equal(User::Levels::CONTRIBUTOR, @user.level)
end
should "not allow invites up to janitor level or beyond" do
@user.invite!(User::Levels::JANITOR)
@user.reload
assert_equal(User::Levels::MEMBER, @user.level)
end
should "create a mod action" do
assert_difference("ModAction.count") do
@user.invite!(User::Levels::CONTRIBUTOR)
@@ -38,16 +38,16 @@ class UserTest < ActiveSupport::TestCase
assert_equal("#{@user.name} level changed Member -> Contributor by #{CurrentUser.name}", ModAction.last.description)
end
end
context "who has negeative feedback and is trying to change their name" do
setup do
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.scoped(@mod, "127.0.0.1") do
FactoryGirl.create(:user_feedback, :user => @user, :category => "negative")
end
end
should "not validate" do
@user.reload
@user.update_attributes(:name => "fanfarlo")
@@ -62,20 +62,20 @@ class UserTest < ActiveSupport::TestCase
assert(user.errors.any?)
assert_equal("IP address is banned", user.errors.full_messages.join)
end
should "limit post uploads" do
assert(!@user.can_upload?)
@user.update_column(:level, User::Levels::CONTRIBUTOR)
assert(@user.can_upload?)
@user.update_column(:level, User::Levels::MEMBER)
40.times do
FactoryGirl.create(:post, :uploader => @user, :is_deleted => true)
end
assert(!@user.can_upload?)
end
should "limit comment votes" do
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
Danbooru.config.stubs(:member_comment_limit).returns(10)
@@ -84,12 +84,12 @@ class UserTest < ActiveSupport::TestCase
comment = FactoryGirl.create(:comment)
FactoryGirl.create(:comment_vote, :comment_id => comment.id)
end
assert(!@user.can_comment_vote?)
CommentVote.update_all("created_at = '1990-01-01'")
assert(@user.can_comment_vote?)
end
should "limit comments" do
assert(!@user.can_comment?)
@user.update_column(:level, User::Levels::PRIVILEGED)
@@ -102,7 +102,7 @@ class UserTest < ActiveSupport::TestCase
end
assert(!@user.can_comment?)
end
should "verify" do
assert(@user.is_verified?)
@user = FactoryGirl.create(:user)
@@ -113,92 +113,92 @@ class UserTest < ActiveSupport::TestCase
assert_nothing_raised {@user.verify!(@user.email_verification_key)}
assert(@user.is_verified?)
end
should "authenticate" do
assert(User.authenticate(@user.name, "password"), "Authentication should have succeeded")
assert(!User.authenticate(@user.name, "password2"), "Authentication should not have succeeded")
assert(User.authenticate_hash(@user.name, User.sha1("password")), "Authentication should have succeeded")
assert(!User.authenticate_hash(@user.name, User.sha1("xxx")), "Authentication should not have succeeded")
end
should "normalize its level" do
user = FactoryGirl.create(:user, :level => User::Levels::ADMIN)
assert(user.is_moderator?)
assert(user.is_janitor?)
assert(user.is_contributor?)
assert(user.is_privileged?)
user = FactoryGirl.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_privileged?)
user = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.create(:user, :level => User::Levels::PRIVILEGED)
assert(!user.is_admin?)
assert(!user.is_moderator?)
assert(!user.is_janitor?)
assert(!user.is_contributor?)
assert(user.is_privileged?)
user = FactoryGirl.create(:user)
user = FactoryGirl.create(:user)
assert(!user.is_admin?)
assert(!user.is_moderator?)
assert(!user.is_janitor?)
assert(!user.is_contributor?)
assert(!user.is_privileged?)
end
context "name" do
should "be #{Danbooru.config.default_guest_name} given an invalid user id" do
assert_equal(Danbooru.config.default_guest_name, User.id_to_name(-1))
end
should "be fetched given a user id" do
@user = FactoryGirl.create(:user)
assert_equal(@user.name, User.id_to_name(@user.id))
end
should "be updated" do
@user = FactoryGirl.create(:user)
@user.update_attribute(:name, "danzig")
assert_equal(@user.name, User.id_to_name(@user.id))
end
end
context "ip address" do
setup do
@user = FactoryGirl.create(:user)
end
context "in the json representation" do
should "not appear" do
assert(@user.to_json !~ /addr/)
end
end
context "in the xml representation" do
should "not appear" do
assert(@user.to_xml !~ /addr/)
end
end
end
context "password" do
should "match the cookie hash" do
@user = FactoryGirl.create(:user)
@@ -208,7 +208,7 @@ class UserTest < ActiveSupport::TestCase
@user.reload
assert(User.authenticate_cookie_hash(@user.name, @user.bcrypt_cookie_password_hash))
end
should "match the confirmation" do
@user = FactoryGirl.create(:user)
@user.password = "zugzug5"
@@ -217,7 +217,7 @@ class UserTest < ActiveSupport::TestCase
@user.reload
assert(User.authenticate(@user.name, "zugzug5"), "Authentication should have succeeded")
end
should "match the confirmation" do
@user = FactoryGirl.create(:user)
@user.password = "zugzug6"
@@ -225,7 +225,7 @@ class UserTest < ActiveSupport::TestCase
@user.save
assert_equal(["Password doesn't match confirmation"], @user.errors.full_messages)
end
should "not be too short" do
@user = FactoryGirl.create(:user)
@user.password = "x5"
@@ -233,52 +233,52 @@ class UserTest < ActiveSupport::TestCase
@user.save
assert_equal(["Password is too short (minimum is 5 characters)"], @user.errors.full_messages)
end
should "should be reset" do
@user = FactoryGirl.create(:user)
new_pass = @user.reset_password
assert(User.authenticate(@user.name, new_pass), "Authentication should have succeeded")
end
should "not change the password if the password and old password are blank" do
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "", :old_password => "")
assert(@user.bcrypt_password == User.sha1("67890"))
end
should "not change the password if the old password is incorrect" do
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "abcdefg")
assert(@user.bcrypt_password == User.sha1("67890"))
end
should "not change the password if the old password is blank" do
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "")
assert(@user.bcrypt_password == User.sha1("67890"))
end
should "change the password if the old password is correct" do
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "67890")
assert(@user.bcrypt_password == User.sha1("12345"))
end
context "in the json representation" do
setup do
@user = FactoryGirl.create(:user)
end
should "not appear" do
assert(@user.to_json !~ /password/)
end
end
context "in the xml representation" do
setup do
@user = FactoryGirl.create(:user)
end
should "not appear" do
assert(@user.to_xml !~ /password/)
end

View File

@@ -4,7 +4,7 @@ class WikiPageTest < ActiveSupport::TestCase
setup do
MEMCACHE.flush_all
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@@ -18,14 +18,14 @@ class WikiPageTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@wiki_page = FactoryGirl.create(:wiki_page)
end
should "allow the is_locked attribute to be updated" do
@wiki_page.update_attributes(:is_locked => true)
@wiki_page.reload
assert_equal(true, @wiki_page.is_locked?)
end
end
context "updated by a regular user" do
setup do
@user = FactoryGirl.create(:user)
@@ -33,14 +33,14 @@ class WikiPageTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@wiki_page = FactoryGirl.create(:wiki_page, :title => "HOT POTATO")
end
should "not allow the is_locked attribute to be updated" do
@wiki_page.update_attributes(:is_locked => true)
assert_equal(["Is locked can be modified by janitors only"], @wiki_page.errors.full_messages)
@wiki_page.reload
assert_equal(false, @wiki_page.is_locked?)
end
should "normalize its title" do
assert_equal("hot_potato", @wiki_page.title)
end
@@ -78,7 +78,7 @@ class WikiPageTest < ActiveSupport::TestCase
@wiki_page.save
end
version = WikiPageVersion.first
assert_not_equal(@wiki_page.creator_id, version.updater_id)
assert_not_equal(@wiki_page.creator_id, version.updater_id)
end
end
end