fix tests

This commit is contained in:
r888888888
2016-01-18 17:13:26 -08:00
parent 243368a758
commit ce3af81c9f
11 changed files with 37 additions and 20 deletions

View File

@@ -1034,17 +1034,19 @@ class Post < ActiveRecord::Base
# optimize some cases. these are just estimates but at these
# quantities being off by a few hundred doesn't matter much
if tags == ""
return (Post.maximum(:id) * (2200402.0 / 2232212)).floor
if Danbooru.config.estimate_post_counts
if tags == ""
return (Post.maximum(:id) * (2200402.0 / 2232212)).floor
elsif tags =~ /^rating:s(?:afe)?$/
return (Post.maximum(:id) * (1648652.0 / 2200402)).floor
elsif tags =~ /^rating:s(?:afe)?$/
return (Post.maximum(:id) * (1648652.0 / 2200402)).floor
elsif tags =~ /^rating:q(?:uestionable)?$/
return (Post.maximum(:id) * (350101.0 / 2200402)).floor
elsif tags =~ /^rating:q(?:uestionable)?$/
return (Post.maximum(:id) * (350101.0 / 2200402)).floor
elsif tags =~ /^rating:e(?:xplicit)?$/
return (Post.maximum(:id) * (201650.0 / 2200402)).floor
elsif tags =~ /^rating:e(?:xplicit)?$/
return (Post.maximum(:id) * (201650.0 / 2200402)).floor
end
end
count = get_count_from_cache(tags)

View File

@@ -387,6 +387,11 @@ module Danbooru
def addthis_key
end
# enable some (donmai-specific) optimizations for post counts
def estimate_post_counts
true
end
# listbooru options
def listbooru_enabled?
false

View File

@@ -19,7 +19,7 @@ class ArtistTest < ActiveSupport::TestCase
context "An artist" do
setup do
user = FactoryGirl.create(:user)
user = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all

View File

@@ -51,7 +51,7 @@ class ForumPostTest < ActiveSupport::TestCase
end
dmail = Dmail.last
assert_equal("You were mentioned in the forum topic \"#{@topic.title}\":http://#{Danbooru.config.hostname}/forum_topics/#{@topic.id}?page=1\n\n---\n\nHey @#{@user2.name} check this out!", dmail.body)
assert_equal("You were mentioned in the forum topic \"#{@topic.title}\":http://#{Danbooru.config.hostname}/forum_topics/#{@topic.id}?page=1\n\n---\n\n[i]#{@user.name} said:[/i]\n\nHey @#{@user2.name} check this out!", dmail.body)
end
end
end

View File

@@ -17,7 +17,7 @@ class JanitorTrialTest < ActiveSupport::TestCase
context "upon creation" do
should "create a dmail when testing a new janitor" do
assert_difference("Dmail.count", 2) do
assert_difference("Dmail.count", 4) do
JanitorTrial.create(:user_id => @user.id)
end
end

View File

@@ -4,8 +4,10 @@ require 'test_helper'
class PoolTest < ActiveSupport::TestCase
setup do
user = FactoryGirl.create(:user)
CurrentUser.user = user
Timecop.travel(1.month.ago) do
user = FactoryGirl.create(:user)
CurrentUser.user = user
end
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
end
@@ -201,7 +203,7 @@ class PoolTest < ActiveSupport::TestCase
should "create new versions for each distinct user" do
assert_equal(1, @pool.versions.size)
user2 = FactoryGirl.create(:user)
user2 = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
CurrentUser.scoped(user2, "127.0.0.2") do
@pool.post_ids = "#{@p1.id}"
@@ -294,7 +296,7 @@ class PoolTest < ActiveSupport::TestCase
context "An anonymous pool" do
setup do
user = FactoryGirl.create(:user)
user = Timecop.travel(1.month.ago) {FactoryGirl.create(:user)}
CurrentUser.user = user
end

View File

@@ -81,6 +81,7 @@ class PostTest < ActiveSupport::TestCase
end
should "update the fast count" do
Danbooru.config.stubs(:estimate_post_counts).returns(false)
post = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal(1, Post.fast_count)
assert_equal(1, Post.fast_count("aaa"))
@@ -1491,6 +1492,7 @@ class PostTest < ActiveSupport::TestCase
context "Creating a post" do
setup do
Danbooru.config.stubs(:blank_tag_search_fast_count).returns(nil)
Danbooru.config.stubs(:estimate_post_counts).returns(false)
end
context "with a primed cache" do
@@ -1505,7 +1507,7 @@ class PostTest < ActiveSupport::TestCase
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(""))
assert_equal(1, Post.fast_count(""))
assert_equal(1, Post.fast_count("aaa"))
assert_equal(1, Post.fast_count("alias"))
assert_equal(0, Post.fast_count("bbb"))

View File

@@ -3,7 +3,9 @@ require 'test_helper'
class PostVersionTest < ActiveSupport::TestCase
context "A post" do
setup do
@user = FactoryGirl.create(:user)
Timecop.travel(1.month.ago) do
@user = FactoryGirl.create(:user)
end
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -18,6 +20,7 @@ class PostVersionTest < ActiveSupport::TestCase
setup do
@post = FactoryGirl.create(:post, :tag_string => "1")
@post.stubs(:merge_version?).returns(false)
@post.stubs(:tag_string_changed?).returns(true)
@post.update_attributes(:tag_string => "1 2")
@post.update_attributes(:tag_string => "2 3")
end

View File

@@ -44,6 +44,7 @@ class SavedSearchTest < ActiveSupport::TestCase
context "Destroying a saved search" do
setup do
SqsService.any_instance.stubs(:send_message)
@user = FactoryGirl.create(:user)
@saved_search = @user.saved_searches.create(:tag_query => "xxx")
@saved_search.destroy

View File

@@ -3,8 +3,10 @@ require 'test_helper'
class TagAliasTest < ActiveSupport::TestCase
context "A tag alias" do
setup do
user = FactoryGirl.create(:user)
CurrentUser.user = user
Timecop.travel(1.month.ago) do
user = FactoryGirl.create(:user)
CurrentUser.user = user
end
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false

View File

@@ -30,7 +30,7 @@ class UserTest < ActiveSupport::TestCase
@user.promote_to!(User::Levels::GOLD)
end
assert_equal("Promoted from Member to Gold", @user.feedback.last.body)
assert_equal("You have been promoted to a Gold level account from Member.", @user.feedback.last.body)
end
should "create a dmail" do