Merge branch 'master' into close-accounts

This commit is contained in:
r888888888
2013-05-16 14:16:47 -07:00
129 changed files with 55250 additions and 462 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -32,7 +32,7 @@ class NotesControllerTest < ActionController::TestCase
context "create action" do
should "create a note" do
assert_difference("Note.count", 1) do
post :create, {:note => {:x => 100, :y => 100, :width => 100, :height => 100, :body => "abc", :post_id => @post.id}}, {:user_id => @user.id}
post :create, {:note => {:x => 0, :y => 0, :width => 10, :height => 10, :body => "abc", :post_id => @post.id}, :format => :json}, {:user_id => @user.id}
end
end
end

View File

@@ -89,3 +89,9 @@ class MockMemcache
end
MEMCACHE = MockMemcache.new
VCR.configure do |c|
c.cassette_library_dir = "test/fixtures/vcr_cassettes"
c.hook_into :fakeweb
c.allow_http_connections_when_no_cassette = true
end

View File

@@ -51,5 +51,16 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
end
end
end
should "rename an aliased tag's artist entry and wiki page" do
tag1 = FactoryGirl.create(:tag, :name => "aaa", :category => 1)
tag2 = FactoryGirl.create(:tag, :name => "bbb")
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
@importer = AliasAndImplicationImporter.new("create alias aaa -> bbb", "", "1")
@importer.process!
artist.reload
assert_equal("bbb", artist.name)
assert_match(/automatically renamed/, artist.notes)
end
end
end

View File

@@ -95,6 +95,12 @@ class ArtistTest < ActiveSupport::TestCase
assert_equal(["http://not.rembrandt.com/test.jpg"], artist.urls.map(&:to_s).sort)
end
should "ignore pixiv.net/ and pixiv.net/img/ url matches" do
a1 = FactoryGirl.create(:artist, :name => "yomosaka", :url_string => "http://i2.pixiv.net/img100/img/yomosaka/27618292.jpg")
a2 = FactoryGirl.create(:artist, :name => "niwatazumi_bf", :url_string => "http://i2.pixiv.net/img16/img/niwatazumi_bf/35488864_big_p6.jpg")
assert_equal([], Artist.find_all_by_url("http://i2.pixiv.net/img28/img/kyang692/35563903.jpg"))
end
should "find matches by url" do
a1 = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/x/test.jpg")
a2 = FactoryGirl.create(:artist, :name => "subway", :url_string => "http://subway.com/x/test.jpg")

View File

@@ -40,9 +40,9 @@ class ArtistUrlTest < ActiveSupport::TestCase
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)
assert_equal("http://img.pixiv.net/monet/", url.normalized_url)
url = FactoryGirl.create(:artist_url, :url => "http://img55.pixiv.net/img/monet")
assert_equal("http://img55.pixiv.net/img/monet", url.url)
assert_equal("http://img.pixiv.net/img/monet/", url.normalized_url)
end
end
end

View File

@@ -1,18 +0,0 @@
require 'test_helper'
module Downloads
class NicoSeigaTest < ActiveSupport::TestCase
context "a download for a nico seiga image" do
setup do
# @source = "http://img.tinami.com/illust2/img/330/4e85ecd880a8f.jpg"
# @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))
end
end
end
end

View File

@@ -1,18 +0,0 @@
# require 'test_helper'
#
# module Downloads
# class PixaTest < ActiveSupport::TestCase
# context "a download for a pixa image" do
# setup do
# @source = "http://file0.pixa.cc/illustrations/6f/d6/3f/f9/51/61/29/72/23/ac/middle/sse.jpg?1317405928"
# @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))
# end
# end
# end
# end

View File

@@ -7,7 +7,9 @@ module Downloads
@source = "http://img65.pixiv.net/img/kiyoringo/21755794_p2.png"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
VCR.use_cassette("download-pixiv-manga", :record => :new_episodes) do
@download.download!
end
end
should "instead download the big version" do
@@ -21,7 +23,9 @@ module Downloads
@source = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=4348318"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
VCR.use_cassette("download-pixiv-html", :record => :new_episodes) do
@download.download!
end
end
should "work" do
@@ -34,7 +38,9 @@ module Downloads
@source = "http://img02.pixiv.net/img/wanwandoh/4348318_m.jpg"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
VCR.use_cassette("download-pixiv-small", :record => :new_episodes) do
@download.download!
end
end
should "instead download the original version" do

View File

@@ -1,18 +0,0 @@
# require 'test_helper'
#
# module Downloads
# class TinamiTest < ActiveSupport::TestCase
# context "a download for a pixa image" do
# setup do
# @source = "http://img.tinami.com/illust2/img/330/4e85ecd880a8f.jpg"
# @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))
# end
# end
# end
# end

View File

@@ -18,9 +18,11 @@ class ForumPostTest < ActiveSupport::TestCase
setup do
Danbooru.config.stubs(:posts_per_page).returns(3)
@posts = []
10.times do
9.times do
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
sleep 2
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
should "know which page it's on" do
@@ -29,6 +31,12 @@ class ForumPostTest < ActiveSupport::TestCase
assert_equal(2, @posts[5].forum_topic_page)
assert_equal(3, @posts[6].forum_topic_page)
end
should "update the topic's updated_at when deleted" do
@posts.last.destroy
@topic.reload
assert_equal(@posts[0].updated_at.to_s, @topic.updated_at.to_s)
end
end
context "belonging to a locked topic" do

View File

@@ -34,7 +34,25 @@ class NoteTest < ActiveSupport::TestCase
context "creating a note" do
setup do
@post = FactoryGirl.create(:post)
@post = FactoryGirl.create(:post, :image_width => 1000, :image_height => 1000)
end
should "not validate if the note is outside the image" do
@note = FactoryGirl.build(:note, :x => 1001, :y => 500, :post => @post)
@note.save
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
end
should "not validate if the note is larger than the image" do
@note = FactoryGirl.build(:note, :x => 500, :y => 500, :height => 501, :width => 500, :post => @post)
@note.save
assert_equal(["Note must be inside the image"], @note.errors.full_messages)
end
should "not validate if the post does not exist" do
@note = FactoryGirl.build(:note, :x => 500, :y => 500, :post_id => -1)
@note.save
assert_equal(["Post must exist"], @note.errors.full_messages)
end
should "create a version" do
@@ -72,7 +90,7 @@ class NoteTest < ActiveSupport::TestCase
context "updating a note" do
setup do
@post = FactoryGirl.create(:post)
@post = FactoryGirl.create(:post, :image_width => 1000, :image_height => 1000)
@note = FactoryGirl.create(:note, :post => @post)
end
@@ -84,7 +102,7 @@ class NoteTest < ActiveSupport::TestCase
should "update the post's last_noted_at field" do
assert_nil(@post.last_noted_at)
@note.update_attributes(:x => 1000)
@note.update_attributes(:x => 500)
@post.reload
assert_equal(@post.last_noted_at.to_i, @note.updated_at.to_i)
end
@@ -105,7 +123,7 @@ class NoteTest < ActiveSupport::TestCase
end
should "fail" do
@note.update_attributes(:x => 1000)
@note.update_attributes(:x => 500)
assert_equal(["Post is note locked"], @note.errors.full_messages)
end
end

View File

@@ -690,6 +690,7 @@ class PostTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryGirl.create(:post)
@post.add_favorite!(@user)
@user.reload
end
teardown do
@@ -698,9 +699,9 @@ class PostTest < ActiveSupport::TestCase
end
should "decrement the user's favorite_count" do
assert_difference("CurrentUser.favorite_count", -1) do
assert_difference("@user.favorite_count", -1) do
@post.remove_favorite!(@user)
CurrentUser.reload
@user.reload
end
end
@@ -721,9 +722,9 @@ class PostTest < ActiveSupport::TestCase
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
assert_difference("@user.favorite_count", 0) do
@post2.remove_favorite!(@user)
CurrentUser.reload
@user.reload
end
end
end

View File

@@ -7,8 +7,10 @@ module Sources
context "The source site for nico seiga" do
setup do
# Sources::Strategies::NicoSeiga.new("http://lohas.nicoseiga.jp/priv/2853566?e=1361296671&h=794b3686b02edfd64c22ed2f99a4c55650371854")
@site = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im1464351?track=ranking")
@site.get
VCR.use_cassette("source-nico-seiga-unit-test", :record => :new_episodes) do
@site = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im1464351?track=ranking")
end
end
should "get the profile" do

View File

@@ -6,8 +6,9 @@ module Sources
class PixivTest < ActiveSupport::TestCase
context "The source site for pixiv" do
setup do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=big&illust_id=9646484")
@site.get
VCR.use_cassette("source-pixiv-unit-test", :record => :new_episodes) do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=big&illust_id=9646484")
end
end
should "get the profile" do

View File

@@ -62,18 +62,6 @@ class TagAliasTest < ActiveSupport::TestCase
end
end
should "record the alias's creator in the tag history" do
uploader = FactoryGirl.create(:user)
post = nil
CurrentUser.scoped(uploader, "127.0.0.1") do
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
post.reload
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

@@ -8,6 +8,7 @@ class TagImplicationTest < ActiveSupport::TestCase
CurrentUser.ip_addr = "127.0.0.1"
@user = FactoryGirl.create(:user)
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
teardown do
@@ -67,7 +68,18 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("ddd", ti2.descendant_names)
end
should "update the decendants for its parent on create" do
should "update the descendants for its parent on destroy" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
ti2.destroy
ti1.reload
ti3.reload
assert_equal("bbb", ti1.descendant_names)
assert_equal("ddd", ti3.descendant_names)
end
should "update the descendants for its parent on create" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti1.reload
assert_equal("active", ti1.status)
@@ -97,7 +109,17 @@ class TagImplicationTest < ActiveSupport::TestCase
assert_equal("ccc ddd eee", ti2.descendant_names)
assert_equal("ddd", ti3.descendant_names)
assert_equal("eee", ti4.descendant_names)
end
should "update any affected post upon destroy" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "bbb", :consequent_name => "ccc")
ti3 = FactoryGirl.create(:tag_implication, :antecedent_name => "ccc", :consequent_name => "ddd")
p1 = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal("aaa bbb ccc ddd", p1.tag_string)
ti2.destroy
p1.reload
assert_equal("aaa bbb ddd", p1.tag_string)
end
should "update any affected post upon save" do
@@ -107,17 +129,5 @@ 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
CurrentUser.scoped(user, "127.0.0.1") do
p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
p1.reload
assert_not_equal(ti1.creator_id, p1.uploader_id)
assert_equal(ti1.creator_id, p1.versions.last.updater_id)
end
end
end

View File

@@ -71,7 +71,7 @@ class UserTest < ActiveSupport::TestCase
assert_difference("ModAction.count") do
@user.invite!(User::Levels::CONTRIBUTOR)
end
assert_equal("#{@user.name} level changed Member -> Contributor by #{CurrentUser.name}", ModAction.last.description)
assert_equal(%{"#{@user.name}":/users/#{@user.id} level changed Member -> Contributor}, ModAction.last.description)
end
end