* Removed Pixa/Tinami sources

* Upgraded to Rails 3.2.3
* Fixed tests
This commit is contained in:
albert
2012-06-01 19:22:58 -04:00
parent 105cba5963
commit 17881068e1
124 changed files with 1063 additions and 1214 deletions

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class AdvertisementTest < ActiveSupport::TestCase
context "An advertisement" do
setup do
@ad = Factory.create(:advertisement, :file => upload_jpeg("#{Rails.root}/test/files/test.jpg"))
@ad = FactoryGirl.create(:advertisement, :file => upload_jpeg("#{Rails.root}/test/files/test.jpg"))
end
teardown do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class AliasAndImplicationImporterTest < ActiveSupport::TestCase
context "The alias and implication importer" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -20,7 +20,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
end
should "process it" do
assert_difference("Delayed::Job.count", 2) do
assert_difference("Delayed::Job.count", 3) do
@importer.process!
end
end

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class ArtistTest < ActiveSupport::TestCase
context "An artist" do
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,8 +16,8 @@ class ArtistTest < ActiveSupport::TestCase
context "with a matching tag alias" do
setup do
@tag_alias = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
@artist = Factory.create(:artist, :name => "aaa")
@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
@@ -31,8 +31,8 @@ class ArtistTest < ActiveSupport::TestCase
context "that has been banned" do
setup do
@post = Factory.create(:post, :tag_string => "aaa")
@artist = Factory.create(:artist, :name => "aaa")
@post = FactoryGirl.create(:post, :tag_string => "aaa")
@artist = FactoryGirl.create(:artist, :name => "aaa")
@artist.update_attributes({:is_banned => true}, :as => :admin)
@post.reload
end
@@ -49,7 +49,7 @@ class ArtistTest < ActiveSupport::TestCase
should "create a new wiki page to store any note information" do
artist = nil
assert_difference("WikiPage.count") do
artist = Factory.create(:artist, :name => "aaa", :notes => "testing")
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
end
assert_equal("testing", artist.notes)
assert_equal("testing", artist.wiki_page.body)
@@ -57,7 +57,7 @@ class ArtistTest < ActiveSupport::TestCase
end
should "update the wiki page when notes are assigned" do
artist = Factory.create(:artist, :name => "aaa", :notes => "testing")
artist = FactoryGirl.create(:artist, :name => "aaa", :notes => "testing")
artist.update_attribute(:notes, "kokoko")
artist.reload
assert_equal("kokoko", artist.notes)
@@ -65,26 +65,26 @@ class ArtistTest < ActiveSupport::TestCase
end
should "normalize its name" do
artist = Factory.create(:artist, :name => " AAA BBB ")
artist = FactoryGirl.create(:artist, :name => " AAA BBB ")
assert_equal("aaa_bbb", artist.name)
end
should "resolve ambiguous urls" do
bobross = Factory.create(:artist, :name => "bob_ross", :url_string => "http://artists.com/bobross/image.jpg")
bob = Factory.create(:artist, :name => "bob", :url_string => "http://artists.com/bob/image.jpg")
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")
matches = Artist.find_all_by_url("http://artists.com/bob/test.jpg")
assert_equal(1, matches.size)
assert_equal("bob", matches.first.name)
end
should "parse urls" do
artist = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg http://aaa.com")
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 = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
artist = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
artist.url_string = "http://not.rembrandt.com/test.jpg"
artist.save
artist.reload
@@ -92,8 +92,8 @@ class ArtistTest < ActiveSupport::TestCase
end
should "find matches by url" do
a1 = Factory.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
a2 = Factory.create(:artist, :name => "subway", :url_string => "http://subway.com/test.jpg")
a1 = FactoryGirl.create(:artist, :name => "rembrandt", :url_string => "http://rembrandt.com/test.jpg")
a2 = FactoryGirl.create(:artist, :name => "subway", :url_string => "http://subway.com/test.jpg")
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/test.jpg").map(&:name))
assert_equal(["rembrandt"], Artist.find_all_by_url("http://rembrandt.com/another.jpg").map(&:name))
@@ -101,39 +101,39 @@ class ArtistTest < ActiveSupport::TestCase
end
should "not allow duplicates" do
Factory.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg\nhttp://warhol.com/b/image.jpg")
FactoryGirl.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg\nhttp://warhol.com/b/image.jpg")
assert_equal(["warhol"], Artist.find_all_by_url("http://warhol.com/test.jpg").map(&:name))
end
should "hide deleted artists" do
Factory.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg", :is_active => false)
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 = Factory.create(:artist, :name => "a1", :other_names => "aaa, bbb, ccc ddd")
artist = FactoryGirl.create(:artist, :name => "a1", :other_names => "aaa, bbb, ccc ddd")
assert_equal("aaa bbb ccc_ddd", artist.other_names)
end
should "search on other names should return matches" do
artist = Factory.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd")
artist = FactoryGirl.create(:artist, :name => "artist", :other_names => "aaa, ccc ddd")
assert_nil(Artist.other_names_match("artist").first)
assert_not_nil(Artist.other_names_match("aaa").first)
assert_not_nil(Artist.other_names_match("ccc_ddd").first)
end
should "search on group name and return matches" do
cat_or_fish = Factory.create(:artist, :name => "cat_or_fish")
yuu = Factory.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
cat_or_fish = FactoryGirl.create(:artist, :name => "cat_or_fish")
yuu = FactoryGirl.create(:artist, :name => "yuu", :group_name => "cat_or_fish")
cat_or_fish.reload
assert_equal("yuu", cat_or_fish.member_names)
assert_not_nil(Artist.search(:group_name_contains => "cat_or_fish").first)
end
should "have an associated wiki" do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
artist = Factory.create(:artist, :name => "max", :wiki_page_attributes => {:title => "xxx", :body => "this is max"})
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)
@@ -143,11 +143,11 @@ class ArtistTest < ActiveSupport::TestCase
end
should "revert to prior versions" do
user = Factory.create(:user)
reverter = Factory.create(:user)
user = FactoryGirl.create(:user)
reverter = FactoryGirl.create(:user)
artist = nil
assert_difference("ArtistVersion.count") do
artist = Factory.create(:artist, :other_names => "yyy")
artist = FactoryGirl.create(:artist, :other_names => "yyy")
end
assert_difference("ArtistVersion.count") do

View File

@@ -4,7 +4,7 @@ class ArtistUrlTest < ActiveSupport::TestCase
context "An artist url" do
setup do
MEMCACHE.flush_all
CurrentUser.user = Factory.create(:user)
CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -14,27 +14,27 @@ class ArtistUrlTest < ActiveSupport::TestCase
end
should "always add a trailing slash when normalized" do
url = Factory.create(:artist_url, :url => "http://monet.com")
url = FactoryGirl.create(:artist_url, :url => "http://monet.com")
assert_equal("http://monet.com", url.url)
assert_equal("http://monet.com/", url.normalized_url)
url = Factory.create(:artist_url, :url => "http://monet.com/")
url = FactoryGirl.create(:artist_url, :url => "http://monet.com/")
assert_equal("http://monet.com/", url.url)
assert_equal("http://monet.com/", url.normalized_url)
end
should "normalize fc2 urls" do
url = Factory.create(:artist_url, :url => "http://blog55.fc2.com/monet")
url = FactoryGirl.create(:artist_url, :url => "http://blog55.fc2.com/monet")
assert_equal("http://blog55.fc2.com/monet", url.url)
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
url = Factory.create(:artist_url, :url => "http://blog-imgs-55.fc2.com/monet")
url = FactoryGirl.create(:artist_url, :url => "http://blog-imgs-55.fc2.com/monet")
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 = Factory.create(:artist_url, :url => "http://img55.pixiv.net/monet")
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)
end

View File

@@ -4,7 +4,7 @@ class BanTest < ActiveSupport::TestCase
context "A ban" do
context "created by an admin" do
setup do
@banner = Factory.create(:admin_user)
@banner = FactoryGirl.create(:admin_user)
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -16,38 +16,38 @@ class BanTest < ActiveSupport::TestCase
end
should "not be valid against another admin" do
user = Factory.create(:admin_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
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 = Factory.create(:moderator_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:moderator_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:janitor_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:janitor_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:contributor_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:contributor_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:privileged_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:privileged_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
end
end
context "created by a moderator" do
setup do
@banner = Factory.create(:moderator_user)
@banner = FactoryGirl.create(:moderator_user)
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -59,39 +59,39 @@ class BanTest < ActiveSupport::TestCase
end
should "not be valid against an admin or moderator" do
user = Factory.create(:admin_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:admin_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = Factory.create(:moderator_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:moderator_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 or a moderator" do
user = Factory.create(:janitor_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:janitor_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:contributor_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:contributor_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:privileged_user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:privileged_user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
user = Factory.create(:user)
ban = Factory.create(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:user)
ban = FactoryGirl.create(:ban, :user => user, :banner => @banner)
assert(ban.errors.empty?)
end
end
context "created by a janitor" do
setup do
@banner = Factory.create(:janitor_user)
@banner = FactoryGirl.create(:janitor_user)
CurrentUser.user = @banner
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -103,53 +103,53 @@ class BanTest < ActiveSupport::TestCase
end
should "always be invalid" do
user = Factory.create(:admin_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:admin_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = Factory.create(:moderator_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:moderator_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = Factory.create(:janitor_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:janitor_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = Factory.create(:contributor_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:contributor_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = Factory.create(:privileged_user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:privileged_user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
user = Factory.create(:user)
ban = Factory.build(:ban, :user => user, :banner => @banner)
user = FactoryGirl.create(:user)
ban = FactoryGirl.build(:ban, :user => user, :banner => @banner)
ban.save
assert(ban.errors.any?)
end
end
should "initialize the expiration date" do
user = Factory.create(:user)
admin = Factory.create(:admin_user)
user = FactoryGirl.create(:user)
admin = FactoryGirl.create(:admin_user)
CurrentUser.user = admin
ban = Factory.create(:ban, :user => user, :banner => admin)
ban = FactoryGirl.create(:ban, :user => user, :banner => admin)
CurrentUser.user = nil
assert_not_nil(ban.expires_at)
end
should "update the user's feedback" do
user = Factory.create(:user)
admin = Factory.create(:admin_user)
user = FactoryGirl.create(:user)
admin = FactoryGirl.create(:admin_user)
assert(user.feedback.empty?)
CurrentUser.user = admin
ban = Factory.create(:ban, :user => user, :banner => admin)
ban = FactoryGirl.create(:ban, :user => user, :banner => admin)
CurrentUser.user = nil
assert(!user.feedback.empty?)
assert_equal("negative", user.feedback.last.category)
@@ -159,10 +159,10 @@ class BanTest < ActiveSupport::TestCase
context "Searching for a ban" do
context "by user id" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
teardown do
@@ -172,7 +172,7 @@ class BanTest < ActiveSupport::TestCase
context "when only expired bans exist" do
setup do
@ban = Factory.create(:ban, :user => @user, :banner => @admin, :duration => -1)
@ban = FactoryGirl.create(:ban, :user => @user, :banner => @admin, :duration => -1)
end
should "not return expired bans" do
@@ -182,7 +182,7 @@ class BanTest < ActiveSupport::TestCase
context "when active bans still exist" do
setup do
@ban = Factory.create(:ban, :user => @user, :banner => @admin, :duration => 1)
@ban = FactoryGirl.create(:ban, :user => @user, :banner => @admin, :duration => 1)
end
should "return active bans" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class CommentTest < ActiveSupport::TestCase
context "A comment" do
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -21,7 +21,7 @@ class CommentTest < ActiveSupport::TestCase
end
should "fail creation" do
comment = Factory.build(:comment)
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
@@ -34,36 +34,36 @@ class CommentTest < ActiveSupport::TestCase
end
should "be created" do
comment = Factory.build(:comment)
comment = FactoryGirl.build(:comment)
comment.save
assert(comment.errors.empty?, comment.errors.full_messages.join(", "))
end
should "not bump the parent post" do
post = Factory.create(:post)
comment = Factory.create(:comment, :do_not_bump_post => "1", :post => post)
post = FactoryGirl.create(:post)
comment = FactoryGirl.create(:comment, :do_not_bump_post => "1", :post => post)
post.reload
assert_nil(post.last_commented_at)
comment = Factory.create(:comment, :post => post)
comment = FactoryGirl.create(:comment, :post => post)
post.reload
assert_not_nil(post.last_commented_at)
end
should "not update the post after exceeding the threshold" do
Danbooru.config.stubs(:comment_threshold).returns(1)
p = Factory.create(:post)
c1 = Factory.create(:comment, :post => p)
p = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:comment, :post => p)
sleep 1
c2 = Factory.create(:comment, :post => p)
c2 = FactoryGirl.create(:comment, :post => p)
p.reload
assert_equal(c1.created_at.to_s, p.last_commented_at.to_s)
end
should "not allow duplicate votes" do
user = Factory.create(:user)
post = Factory.create(:post)
c1 = Factory.create(:comment, :post => post)
user = FactoryGirl.create(:user)
post = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:comment, :post => post)
comment_vote = c1.vote!("up")
assert_equal([], comment_vote.errors.full_messages)
comment_vote = c1.vote!("up")
@@ -71,16 +71,16 @@ class CommentTest < ActiveSupport::TestCase
assert_equal(1, CommentVote.count)
assert_equal(1, CommentVote.last.score)
c2 = Factory.create(:comment, :post => post)
c2 = FactoryGirl.create(:comment, :post => post)
comment_vote = c2.vote!("up")
assert_equal([], comment_vote.errors.full_messages)
assert_equal(2, CommentVote.count)
end
should "be searchable" do
c1 = Factory.create(:comment, :body => "aaa bbb ccc")
c2 = Factory.create(:comment, :body => "aaa ddd")
c3 = Factory.create(:comment, :body => "eee")
c1 = FactoryGirl.create(:comment, :body => "aaa bbb ccc")
c2 = FactoryGirl.create(:comment, :body => "aaa ddd")
c3 = FactoryGirl.create(:comment, :body => "eee")
matches = Comment.body_matches("aaa")
assert_equal(2, matches.count)

View File

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

View File

@@ -4,7 +4,7 @@ class DmailTest < ActiveSupport::TestCase
context "A dmail" do
setup do
MEMCACHE.flush_all
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
ActionMailer::Base.delivery_method = :test
@@ -18,7 +18,7 @@ class DmailTest < ActiveSupport::TestCase
context "search" do
should "return results based on title contents" do
dmail = Factory.create(:dmail, :title => "xxx", :owner => @user)
dmail = FactoryGirl.create(:dmail, :title => "xxx", :owner => @user)
matches = Dmail.search_message("xxx")
assert(matches.any?)
matches = Dmail.search_message("aaa")
@@ -26,7 +26,7 @@ class DmailTest < ActiveSupport::TestCase
end
should "return results based on body contents" do
dmail = Factory.create(:dmail, :body => "xxx", :owner => @user)
dmail = FactoryGirl.create(:dmail, :body => "xxx", :owner => @user)
matches = Dmail.search_message("xxx")
assert(matches.any?)
matches = Dmail.search_message("aaa")
@@ -35,14 +35,14 @@ class DmailTest < ActiveSupport::TestCase
end
should "should parse user names" do
dmail = Factory.build(:dmail, :owner => @user)
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 = Factory.create(:dmail, :owner => @user)
dmail = FactoryGirl.create(:dmail, :owner => @user)
response = dmail.build_response
assert_equal("Re: #{dmail.title}", response.title)
assert_equal(dmail.from_id, response.to_id)
@@ -50,28 +50,28 @@ class DmailTest < ActiveSupport::TestCase
end
should "create a copy for each user" do
@new_user = Factory.create(:user)
@new_user = FactoryGirl.create(:user)
assert_difference("Dmail.count", 2) do
Dmail.create_split(:to_id => @new_user.id, :title => "foo", :body => "foo")
end
end
should "send an email if the user wants it" do
user = Factory.create(:user, :receive_email_notifications => true)
user = FactoryGirl.create(:user, :receive_email_notifications => true)
assert_difference("ActionMailer::Base.deliveries.size", 1) do
Factory.create(:dmail, :to => user, :owner => @user)
FactoryGirl.create(:dmail, :to => user, :owner => @user)
end
end
should "be marked as read after the user reads it" do
dmail = Factory.create(:dmail, :owner => @user)
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 = Factory.create(:dmail, :owner => @user)
dmail = FactoryGirl.create(:dmail, :owner => @user)
assert(dmail.to(true).has_mail?)
dmail.mark_as_read!
assert(!dmail.to(true).has_mail?)

View File

@@ -1,18 +1,18 @@
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
# 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

@@ -1,18 +1,18 @@
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
# 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

@@ -2,7 +2,7 @@ require 'test_helper'
class FavoriteTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,8 +16,8 @@ class FavoriteTest < ActiveSupport::TestCase
context "A favorite" do
should "delete from all tables" do
user1 = Factory.create(:user)
p1 = Factory.create(:post)
user1 = FactoryGirl.create(:user)
p1 = FactoryGirl.create(:post)
user1.add_favorite!(p1)
assert_equal(1, Favorite.count)
@@ -27,10 +27,10 @@ class FavoriteTest < ActiveSupport::TestCase
end
should "know which table it belongs to" do
user1 = Factory.create(:user)
user2 = Factory.create(:user)
p1 = Factory.create(:post)
p2 = Factory.create(:post)
user1 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
p1 = FactoryGirl.create(:post)
p2 = FactoryGirl.create(:post)
user1.add_favorite!(p1)
user1.add_favorite!(p2)
@@ -47,9 +47,9 @@ class FavoriteTest < ActiveSupport::TestCase
end
should "not allow duplicates" do
user1 = Factory.create(:user)
p1 = Factory.create(:post)
p2 = Factory.create(:post)
user1 = FactoryGirl.create(:user)
p1 = FactoryGirl.create(:post)
p2 = FactoryGirl.create(:post)
user1.add_favorite!(p1)
user1.add_favorite!(p1)

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class ForumPostTest < ActiveSupport::TestCase
context "A forum post" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@topic = Factory.create(:forum_topic)
@topic = FactoryGirl.create(:forum_topic)
end
teardown do
@@ -16,7 +16,7 @@ class ForumPostTest < ActiveSupport::TestCase
context "belonging to a locked topic" do
setup do
@post = Factory.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => "zzz")
@topic.update_attribute(:is_locked, true)
@post.reload
end
@@ -36,26 +36,26 @@ class ForumPostTest < ActiveSupport::TestCase
should "update its parent when saved" do
sleep 1
original_topic_updated_at = @topic.updated_at
post = Factory.create(:forum_post, :topic_id => @topic.id)
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@topic.reload
assert_not_equal(original_topic_updated_at, @topic.updated_at)
end
should "be searchable by body content" do
post = Factory.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
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 = Factory.create(:forum_post, :topic_id => @topic.id)
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
assert_equal(@user.id, post.creator_id)
end
context "updated by a second user" do
setup do
@post = Factory.create(:forum_post, :topic_id => @topic.id)
@second_user = Factory.create(:user)
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@second_user = FactoryGirl.create(:user)
CurrentUser.user = @second_user
end

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class ForumTopicTest < ActiveSupport::TestCase
context "A forum topic" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@topic = Factory.create(:forum_topic, :title => "xxx")
@topic = FactoryGirl.create(:forum_topic, :title => "xxx")
end
teardown do
@@ -17,7 +17,7 @@ class ForumTopicTest < ActiveSupport::TestCase
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 = Factory.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
@topic = FactoryGirl.create(:forum_topic, :title => "abc", :original_post_attributes => {:body => "abc"})
end
end
end
@@ -33,7 +33,7 @@ class ForumTopicTest < ActiveSupport::TestCase
context "updated by a second user" do
setup do
@second_user = Factory.create(:user)
@second_user = FactoryGirl.create(:user)
CurrentUser.user = @second_user
end
@@ -46,7 +46,7 @@ class ForumTopicTest < ActiveSupport::TestCase
context "with multiple posts that has been deleted" do
setup do
5.times do
Factory.create(:forum_post, :topic_id => @topic.id)
FactoryGirl.create(:forum_post, :topic_id => @topic.id)
end
end

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class IpBanTest < ActiveSupport::TestCase
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -15,14 +15,14 @@ class IpBanTest < ActiveSupport::TestCase
end
should "be able to count the number of comments an IP address is associated with" do
comment = Factory.create(:comment)
comment = FactoryGirl.create(:comment)
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 = Factory.create(:comment, :body => "aaa")
comment = FactoryGirl.create(:comment, :body => "aaa")
counts = IpBan.query([comment.creator_id])
assert_equal([{"ip_addr" => "1.2.3.4", "count" => "1"}], counts["comments"])
end

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class JanitorTrialTest < ActiveSupport::TestCase
context "A janitor trial" do
setup do
@admin = Factory.create(:admin_user)
@user = Factory.create(:user)
@admin = FactoryGirl.create(:admin_user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -31,7 +31,7 @@ class JanitorTrialTest < ActiveSupport::TestCase
context "upon demotion" do
setup do
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
@janitor_trial = FactoryGirl.create(:janitor_trial, :user_id => @user.id)
end
should "create a negative feedback record" do
@@ -43,7 +43,7 @@ class JanitorTrialTest < ActiveSupport::TestCase
context "upon promotion" do
setup do
@janitor_trial = Factory.create(:janitor_trial, :user_id => @user.id)
@janitor_trial = FactoryGirl.create(:janitor_trial, :user_id => @user.id)
end
should "destroy the trial object" do

View File

@@ -5,7 +5,7 @@ module Maintenance
class LoginReminderMailerTest < ActionMailer::TestCase
context "The login reminder mailer" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
should "send the notie" do

View File

@@ -4,11 +4,11 @@ module Moderator
class IpAddrSearchTest < ActiveSupport::TestCase
context "an ip addr search" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
Factory.create(:comment)
FactoryGirl.create(:comment)
MEMCACHE.flush_all
end

View File

@@ -4,10 +4,10 @@ module Moderator
class TagBatchChangeTest < ActiveSupport::TestCase
context "a tag batch change" do
setup do
@user = Factory.create(:moderator_user)
@user = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post, :tag_string => "aaa")
@post = FactoryGirl.create(:post, :tag_string => "aaa")
end
teardown do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class NoteTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,12 +16,12 @@ class NoteTest < ActiveSupport::TestCase
context "creating a note" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
should "create a version" do
assert_difference("NoteVersion.count", 1) do
@note = Factory.create(:note, :post => @post)
@note = FactoryGirl.create(:note, :post => @post)
end
assert_equal(1, @note.versions.count)
@@ -30,7 +30,7 @@ class NoteTest < ActiveSupport::TestCase
should "update the post's last_noted_at field" do
assert_nil(@post.last_noted_at)
@note = Factory.create(:note, :post => @post)
@note = FactoryGirl.create(:note, :post => @post)
@post.reload
assert_not_nil(@post.last_noted_at)
end
@@ -42,7 +42,7 @@ class NoteTest < ActiveSupport::TestCase
should "fail" do
assert_difference("Note.count", 0) do
@note = Factory.build(:note, :post => @post)
@note = FactoryGirl.build(:note, :post => @post)
@note.save
end
assert_equal(["Post is note locked"], @note.errors.full_messages)
@@ -52,8 +52,8 @@ class NoteTest < ActiveSupport::TestCase
context "updating a note" do
setup do
@post = Factory.create(:post)
@note = Factory.create(:note, :post => @post)
@post = FactoryGirl.create(:post)
@note = FactoryGirl.create(:note, :post => @post)
end
should "increment the updater's note_update_count" do
@@ -91,8 +91,8 @@ class NoteTest < ActiveSupport::TestCase
context "when notes have been vandalized by one user" do
setup do
@vandal = Factory.create(:user)
@note = Factory.create(:note, :x => 100, :y => 100)
@vandal = FactoryGirl.create(:user)
@note = FactoryGirl.create(:note, :x => 100, :y => 100)
CurrentUser.scoped(@vandal, "127.0.0.1") do
@note.update_attributes(:x => 2000, :y => 2000)
end
@@ -110,7 +110,7 @@ class NoteTest < ActiveSupport::TestCase
context "searching for a note" do
setup do
@note = Factory.create(:note, :body => "aaa")
@note = FactoryGirl.create(:note, :body => "aaa")
end
context "where the body contains the string 'aaa'" do

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class PoolTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -15,7 +15,7 @@ class PoolTest < ActiveSupport::TestCase
context "A name" do
setup do
@pool = Factory.create(:pool, :name => "xxx")
@pool = FactoryGirl.create(:pool, :name => "xxx")
end
should "be mapped to a pool id" do
@@ -25,7 +25,7 @@ class PoolTest < ActiveSupport::TestCase
context "An id number" do
setup do
@pool = Factory.create(:pool)
@pool = FactoryGirl.create(:pool)
end
should "be mapped to a pool id" do
@@ -39,10 +39,10 @@ class PoolTest < ActiveSupport::TestCase
context "Reverting a pool" do
setup do
@pool = Factory.create(:pool)
@p1 = Factory.create(:post)
@p2 = Factory.create(:post)
@p3 = Factory.create(:post)
@pool = FactoryGirl.create(:pool)
@p1 = FactoryGirl.create(:post)
@p2 = FactoryGirl.create(:post)
@p3 = FactoryGirl.create(:post)
CurrentUser.ip_addr = "1.2.3.4"
@pool.add!(@p1)
CurrentUser.ip_addr = "1.2.3.5"
@@ -81,9 +81,9 @@ class PoolTest < ActiveSupport::TestCase
context "Updating a pool" do
setup do
@pool = Factory.create(:pool)
@p1 = Factory.create(:post)
@p2 = Factory.create(:post)
@pool = FactoryGirl.create(:pool)
@p1 = FactoryGirl.create(:post)
@p2 = FactoryGirl.create(:post)
end
context "by adding a new post" do
@@ -194,10 +194,10 @@ class PoolTest < ActiveSupport::TestCase
context "An existing pool" do
setup do
@pool = Factory.create(:pool)
@p1 = Factory.create(:post)
@p2 = Factory.create(:post)
@p3 = Factory.create(:post)
@pool = FactoryGirl.create(:pool)
@p1 = FactoryGirl.create(:post)
@p2 = FactoryGirl.create(:post)
@p3 = FactoryGirl.create(:post)
@pool.add!(@p1)
@pool.add!(@p2)
@pool.add!(@p3)
@@ -249,7 +249,7 @@ class PoolTest < ActiveSupport::TestCase
context "An anonymous pool" do
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
end

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostAppealTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = Factory.create(:user)
@alice = FactoryGirl.create(:user)
CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -17,7 +17,7 @@ class PostAppealTest < ActiveSupport::TestCase
context "a user" do
setup do
@post = Factory.create(:post, :tag_string => "aaa", :is_deleted => true)
@post = FactoryGirl.create(:post, :tag_string => "aaa", :is_deleted => true)
end
should "not be able to appeal a post more than twice" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostDisapprovalTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = Factory.create(:moderator_user)
@alice = FactoryGirl.create(:moderator_user)
CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,8 +16,8 @@ class PostDisapprovalTest < ActiveSupport::TestCase
context "A post disapproval" do
setup do
@post_1 = Factory.create(:post, :is_pending => true)
@post_2 = Factory.create(:post, :is_pending => true)
@post_1 = FactoryGirl.create(:post, :is_pending => true)
@post_2 = FactoryGirl.create(:post, :is_pending => true)
end
context "made by alice" do
@@ -38,7 +38,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
context "when the current user is brittony" do
setup do
@brittony = Factory.create(:moderator_user)
@brittony = FactoryGirl.create(:moderator_user)
CurrentUser.user = @brittony
end
@@ -51,8 +51,8 @@ class PostDisapprovalTest < ActiveSupport::TestCase
context "for a post that has been approved" do
setup do
@post = Factory.create(:post)
@user = Factory.create(:user)
@post = FactoryGirl.create(:post)
@user = FactoryGirl.create(:user)
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
end

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostFlagTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@alice = Factory.create(:user)
@alice = FactoryGirl.create(:user)
CurrentUser.user = @alice
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,7 +16,7 @@ class PostFlagTest < ActiveSupport::TestCase
context "a user" do
setup do
@post = Factory.create(:post, :tag_string => "aaa")
@post = FactoryGirl.create(:post, :tag_string => "aaa")
end
should "not be able to flag a post more than twice" do

View File

@@ -2,19 +2,19 @@ require 'test_helper'
class PostPrunerTest < ActiveSupport::TestCase
setup do
@user = Factory.create(:admin_user)
@user = FactoryGirl.create(:admin_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@flagger = Factory.create(:user)
@old_post = Factory.create(:post, :created_at => 5.days.ago, :is_pending => true)
@unresolved_flagged_post = Factory.create(:post, :is_flagged => true)
@resolved_flagged_post = Factory.create(:post, :is_flagged => true)
@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)
@resolved_flagged_post = FactoryGirl.create(:post, :is_flagged => true)
CurrentUser.scoped(@flagger, "127.0.0.2") do
@unresolved_post_flag = Factory.create(:post_flag, :created_at => 5.days.ago, :is_resolved => false, :post_id => @unresolved_flagged_post.id)
@resolved_post_flag = Factory.create(:post_flag, :created_at => 5.days.ago, :is_resolved => true, :post_id => @resolved_flagged_post.id)
@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!

View File

@@ -4,14 +4,14 @@ module PostSets
class FavoriteTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post_1 = Factory.create(:post)
@post_2 = Factory.create(:post)
@post_3 = Factory.create(:post)
@post_1 = FactoryGirl.create(:post)
@post_2 = FactoryGirl.create(:post)
@post_3 = FactoryGirl.create(:post)
@post_2.add_favorite!(@user)
@post_1.add_favorite!(@user)
@post_3.add_favorite!(@user)

View File

@@ -4,15 +4,15 @@ module PostSets
class PoolTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post_1 = Factory.create(:post)
@post_2 = Factory.create(:post)
@post_3 = Factory.create(:post)
@pool = Factory.create(:pool)
@post_1 = FactoryGirl.create(:post)
@post_2 = FactoryGirl.create(:post)
@post_3 = FactoryGirl.create(:post)
@pool = FactoryGirl.create(:pool)
@pool.add!(@post_2)
@pool.add!(@post_1)
@pool.add!(@post_3)

View File

@@ -5,14 +5,14 @@ module PostSets
class PostTest < ActiveSupport::TestCase
context "In all cases" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post_1 = Factory.create(:post, :tag_string => "a")
@post_2 = Factory.create(:post, :tag_string => "b")
@post_3 = Factory.create(:post, :tag_string => "c")
@post_1 = FactoryGirl.create(:post, :tag_string => "a")
@post_2 = FactoryGirl.create(:post, :tag_string => "b")
@post_3 = FactoryGirl.create(:post, :tag_string => "c")
end
teardown do
@@ -33,8 +33,8 @@ module PostSets
context "a set for the 'a' tag query" do
setup do
@post_4 = Factory.create(:post, :tag_string => "a")
@post_5 = Factory.create(:post, :tag_string => "a")
@post_4 = FactoryGirl.create(:post, :tag_string => "a")
@post_5 = FactoryGirl.create(:post, :tag_string => "a")
end
context "with no page" do
@@ -108,7 +108,7 @@ module PostSets
context "for a privileged user" do
setup do
CurrentUser.user = Factory.create(:privileged_user)
CurrentUser.user = FactoryGirl.create(:privileged_user)
end
should "pass" do
@@ -142,7 +142,7 @@ module PostSets
context "that has a matching wiki page" do
setup do
@wiki_page = Factory.create(:wiki_page, :title => "a")
@wiki_page = FactoryGirl.create(:wiki_page, :title => "a")
end
should "find the wiki page" do
@@ -153,7 +153,7 @@ module PostSets
context "that has a matching artist" do
setup do
@artist = Factory.create(:artist, :name => "a")
@artist = FactoryGirl.create(:artist, :name => "a")
end
should "find the artist" do

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class PostTest < ActiveSupport::TestCase
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,7 +16,7 @@ class PostTest < ActiveSupport::TestCase
context "Deletion:" do
context "Annihilating a post" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
context "that is status locked" do
@@ -40,7 +40,7 @@ class PostTest < ActiveSupport::TestCase
context "Deleting a post" do
context "that is status locked" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.update_attributes({:is_status_locked => true}, :as => :admin)
end
@@ -52,7 +52,7 @@ class PostTest < ActiveSupport::TestCase
end
should "update the fast count" do
post = Factory.create(:post, :tag_string => "aaa")
post = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal(1, Post.fast_count)
assert_equal(1, Post.fast_count("aaa"))
post.delete!
@@ -61,14 +61,14 @@ class PostTest < ActiveSupport::TestCase
end
should "toggle the is_deleted flag" do
post = Factory.create(:post)
post = FactoryGirl.create(:post)
assert_equal(false, post.is_deleted?)
post.delete!
assert_equal(true, post.is_deleted?)
end
should "decrement the tag counts" do
post = Factory.create(:post, :tag_string => "aaa")
post = FactoryGirl.create(:post, :tag_string => "aaa")
assert_equal(1, Tag.find_by_name("aaa").post_count)
post.delete!
assert_equal(0, Tag.find_by_name("aaa").post_count)
@@ -79,17 +79,17 @@ class PostTest < ActiveSupport::TestCase
context "Parenting:" do
context "Assignining a parent to a post" do
should "update the has_children flag on the parent" do
p1 = Factory.create(:post)
p1 = FactoryGirl.create(:post)
assert(!p1.has_children?, "Parent should not have any children")
c1 = Factory.create(:post, :parent_id => p1.id)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
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 = Factory.create(:post)
p2 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
p2 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
c1.parent_id = p2.id
c1.save
p1.reload
@@ -99,15 +99,15 @@ class PostTest < ActiveSupport::TestCase
end
should "validate that the parent exists" do
post = Factory.build(:post, :parent_id => 1_000_000)
post = FactoryGirl.build(:post, :parent_id => 1_000_000)
post.save
assert(post.errors[:parent].any?, "Parent should be invalid")
end
should "fail if the parent has a parent" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
c2 = Factory.build(:post, :parent_id => c1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
c2 = FactoryGirl.build(:post, :parent_id => c1.id)
c2.save
assert(c2.errors[:parent].any?, "Parent should be invalid")
end
@@ -116,17 +116,17 @@ class PostTest < ActiveSupport::TestCase
context "Destroying a post with" do
context "a parent" do
should "reset the has_children flag of the parent" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
c1.delete!
p1.reload
assert_equal(false, p1.has_children?)
end
should "reassign favorites to the parent" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
user = Factory.create(:user)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
user = FactoryGirl.create(:user)
c1.add_favorite!(user)
c1.delete!
p1.reload
@@ -135,8 +135,8 @@ class PostTest < ActiveSupport::TestCase
end
should "update the parent's has_children flag" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
c1.delete!
p1.reload
assert(!p1.has_children?, "Parent should not have children")
@@ -145,15 +145,15 @@ class PostTest < ActiveSupport::TestCase
context "one child" do
should "remove the has_children flag" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
p1.delete!
assert_equal(false, p1.has_children?)
end
should "remove the parent of that child" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
p1.delete!
c1.reload
assert_nil(c1.parent)
@@ -162,10 +162,10 @@ class PostTest < ActiveSupport::TestCase
context "two or more children" do
should "reparent all children to the first child" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
c2 = Factory.create(:post, :parent_id => p1.id)
c3 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
c2 = FactoryGirl.create(:post, :parent_id => p1.id)
c3 = FactoryGirl.create(:post, :parent_id => p1.id)
p1.delete!
c1.reload
c2.reload
@@ -179,8 +179,8 @@ class PostTest < ActiveSupport::TestCase
context "Undestroying a post with a parent" do
should "not preserve the parent's has_children flag" do
p1 = Factory.create(:post)
c1 = Factory.create(:post, :parent_id => p1.id)
p1 = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:post, :parent_id => p1.id)
c1.delete!
c1.undelete!
p1.reload
@@ -193,7 +193,7 @@ class PostTest < ActiveSupport::TestCase
context "Moderation:" do
context "A deleted post" do
setup do
@post = Factory.create(:post, :is_deleted => true)
@post = FactoryGirl.create(:post, :is_deleted => true)
end
context "that is status locked" do
@@ -225,7 +225,7 @@ class PostTest < ActiveSupport::TestCase
context "An approved post" do
should "be flagged" do
post = Factory.create(:post)
post = FactoryGirl.create(:post)
assert_difference("PostFlag.count", 1) do
post.flag!("bad")
end
@@ -234,7 +234,7 @@ class PostTest < ActiveSupport::TestCase
end
should "not be flagged if no reason is given" do
post = Factory.create(:post)
post = FactoryGirl.create(:post)
assert_difference("PostFlag.count", 0) do
assert_raises(PostFlag::Error) do
post.flag!("")
@@ -245,14 +245,14 @@ class PostTest < ActiveSupport::TestCase
context "An unapproved post" do
should "preserve the approver's identity when approved" do
post = Factory.create(:post, :is_pending => true)
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 = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.flag!("reason")
end
@@ -269,9 +269,9 @@ class PostTest < ActiveSupport::TestCase
context "that was previously approved by person X" do
setup do
@user = Factory.create(:janitor_user, :name => "xxx")
@user2 = Factory.create(:janitor_user, :name => "yyy")
@post = Factory.create(:post, :approver_id => @user.id)
@user = FactoryGirl.create(:janitor_user, :name => "xxx")
@user2 = FactoryGirl.create(:janitor_user, :name => "yyy")
@post = FactoryGirl.create(:post, :approver_id => @user.id)
@post.flag!("bad")
end
@@ -294,7 +294,7 @@ class PostTest < ActiveSupport::TestCase
context "that has been reapproved" do
should "no longer be flagged or pending" do
post = Factory.create(:post)
post = FactoryGirl.create(:post)
post.flag!("bad")
post.approve!
assert(post.errors.empty?, post.errors.full_messages.join(", "))
@@ -307,7 +307,7 @@ class PostTest < ActiveSupport::TestCase
context "A status locked post" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.update_attributes({:is_status_locked => true}, :as => :admin)
end
@@ -334,13 +334,13 @@ class PostTest < ActiveSupport::TestCase
context "Tagging:" do
context "A post" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
context "tagged with a metatag" do
context "for a parent" do
setup do
@parent = Factory.create(:post)
@parent = FactoryGirl.create(:post)
end
should "update the parent relationships for both posts" do
@@ -355,7 +355,7 @@ class PostTest < ActiveSupport::TestCase
context "for a pool" do
context "id" do
setup do
@pool = Factory.create(:pool)
@pool = FactoryGirl.create(:pool)
@post.update_attributes(:tag_string => "aaa pool:#{@pool.id}")
end
@@ -370,7 +370,7 @@ class PostTest < ActiveSupport::TestCase
context "name" do
context "that exists" do
setup do
@pool = Factory.create(:pool, :name => "abc")
@pool = FactoryGirl.create(:pool, :name => "abc")
@post.update_attributes(:tag_string => "aaa pool:abc")
end
@@ -423,7 +423,7 @@ class PostTest < ActiveSupport::TestCase
end
should "have an array representation of its tags" do
post = Factory.create(:post)
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)
@@ -431,7 +431,7 @@ class PostTest < ActiveSupport::TestCase
context "that has been updated" do
should "increment the updater's post_update_count" do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
assert_difference("CurrentUser.post_update_count", 1) do
post.update_attributes(:tag_string => "zzz")
@@ -440,8 +440,8 @@ class PostTest < ActiveSupport::TestCase
end
should "reset its tag array cache" do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
user = Factory.create(:user)
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
user = FactoryGirl.create(:user)
assert_equal(%w(aaa bbb ccc), post.tag_array)
post.tag_string = "ddd eee fff"
post.tag_string = "ddd eee fff"
@@ -452,14 +452,14 @@ class PostTest < ActiveSupport::TestCase
should "create the actual tag records" do
assert_difference("Tag.count", 3) do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
end
should "update the post counts of relevant tag records" do
post1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
post2 = Factory.create(:post, :tag_string => "bbb ccc ddd")
post3 = Factory.create(:post, :tag_string => "ccc ddd eee")
post1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
post2 = FactoryGirl.create(:post, :tag_string => "bbb ccc ddd")
post3 = FactoryGirl.create(:post, :tag_string => "ccc ddd eee")
assert_equal(1, Tag.find_by_name("aaa").post_count)
assert_equal(2, Tag.find_by_name("bbb").post_count)
assert_equal(3, Tag.find_by_name("ccc").post_count)
@@ -474,10 +474,10 @@ class PostTest < ActiveSupport::TestCase
end
should "update its tag counts" do
artist_tag = Factory.create(:artist_tag)
copyright_tag = Factory.create(:copyright_tag)
general_tag = Factory.create(:tag)
new_post = Factory.create(:post, :tag_string => "#{artist_tag.name} #{copyright_tag.name} #{general_tag.name}")
artist_tag = FactoryGirl.create(:artist_tag)
copyright_tag = FactoryGirl.create(:copyright_tag)
general_tag = FactoryGirl.create(:tag)
new_post = FactoryGirl.create(:post, :tag_string => "#{artist_tag.name} #{copyright_tag.name} #{general_tag.name}")
assert_equal(1, new_post.tag_count_artist)
assert_equal(1, new_post.tag_count_copyright)
assert_equal(1, new_post.tag_count_general)
@@ -494,7 +494,7 @@ class PostTest < ActiveSupport::TestCase
end
should "merge any changes that were made after loading the initial set of tags part 1" do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
# user a adds <ddd>
post_edited_by_user_a = Post.find(post.id)
@@ -517,7 +517,7 @@ class PostTest < ActiveSupport::TestCase
# This is the same as part 1, only the order of operations is reversed.
# The results should be the same.
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
# user a removes <ccc> adds <eee>
post_edited_by_user_a = Post.find(post.id)
@@ -539,7 +539,7 @@ class PostTest < ActiveSupport::TestCase
context "that has been tagged with a metatag" do
should "not include the metatag in its tag string" do
post = Factory.create(:post)
post = FactoryGirl.create(:post)
post.tag_string = "aaa pool:1234 pool:test rating:s fav:bob"
post.save
assert_equal("aaa", post.tag_string)
@@ -551,10 +551,10 @@ class PostTest < ActiveSupport::TestCase
context "Favorites:" do
context "Removing a post from a user's favorites" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.add_favorite!(@user)
end
@@ -571,7 +571,7 @@ class PostTest < ActiveSupport::TestCase
end
should "not decrement the user's favorite_count if the user did not favorite the post" do
@post2 = Factory.create(:post)
@post2 = FactoryGirl.create(:post)
assert_difference("CurrentUser.favorite_count", 0) do
@post2.remove_favorite!(@user)
CurrentUser.reload
@@ -581,10 +581,10 @@ class PostTest < ActiveSupport::TestCase
context "Adding a post to a user's favorites" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
teardown do
@@ -626,8 +626,8 @@ class PostTest < ActiveSupport::TestCase
context "Pools:" do
context "Removing a post from a pool" do
should "update the post's pool string" do
post = Factory.create(:post)
pool = Factory.create(:pool)
post = FactoryGirl.create(:post)
pool = FactoryGirl.create(:pool)
post.add_pool!(pool)
post.remove_pool!(pool)
post.reload
@@ -640,8 +640,8 @@ class PostTest < ActiveSupport::TestCase
context "Adding a post to a pool" do
should "update the post's pool string" do
post = Factory.create(:post)
pool = Factory.create(:pool)
post = FactoryGirl.create(:post)
pool = FactoryGirl.create(:pool)
post.add_pool!(pool)
post.reload
assert_equal("pool:#{pool.id}", post.pool_string)
@@ -658,10 +658,10 @@ class PostTest < ActiveSupport::TestCase
context "Uploading:" do
context "Uploading a post" do
should "capture who uploaded the post" do
post = Factory.create(:post)
user1 = Factory.create(:user)
user2 = Factory.create(:user)
user3 = Factory.create(:user)
post = FactoryGirl.create(:post)
user1 = FactoryGirl.create(:user)
user2 = FactoryGirl.create(:user)
user3 = FactoryGirl.create(:user)
post.uploader = user1
assert_equal(user1.id, post.uploader_id)
@@ -676,9 +676,9 @@ class PostTest < ActiveSupport::TestCase
context "Searching:" do
should "return posts for 1 tag" do
post1 = Factory.create(:post, :tag_string => "aaa")
post2 = Factory.create(:post, :tag_string => "aaa bbb")
post3 = Factory.create(:post, :tag_string => "bbb ccc")
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
relation = Post.tag_match("aaa")
assert_equal(2, relation.count)
assert_equal(post2.id, relation.all[0].id)
@@ -686,27 +686,27 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for a 2 tag join" do
post1 = Factory.create(:post, :tag_string => "aaa")
post2 = Factory.create(:post, :tag_string => "aaa bbb")
post3 = Factory.create(:post, :tag_string => "bbb ccc")
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
relation = Post.tag_match("aaa bbb")
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
end
should "return posts for 1 tag with exclusion" do
post1 = Factory.create(:post, :tag_string => "aaa")
post2 = Factory.create(:post, :tag_string => "aaa bbb")
post3 = Factory.create(:post, :tag_string => "bbb ccc")
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
relation = Post.tag_match("aaa -bbb")
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for 1 tag with a pattern" do
post1 = Factory.create(:post, :tag_string => "aaa")
post2 = Factory.create(:post, :tag_string => "aaab bbb")
post3 = Factory.create(:post, :tag_string => "bbb ccc")
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
relation = Post.tag_match("a*")
assert_equal(2, relation.count)
assert_equal(post2.id, relation.all[0].id)
@@ -714,18 +714,18 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for 2 tags, one with a pattern" do
post1 = Factory.create(:post, :tag_string => "aaa")
post2 = Factory.create(:post, :tag_string => "aaab bbb")
post3 = Factory.create(:post, :tag_string => "bbb ccc")
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
post2 = FactoryGirl.create(:post, :tag_string => "aaab bbb")
post3 = FactoryGirl.create(:post, :tag_string => "bbb ccc")
relation = Post.tag_match("a* bbb")
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
end
should "return posts for the <id> metatag" do
post1 = Factory.create(:post)
post2 = Factory.create(:post)
post3 = Factory.create(:post)
post1 = FactoryGirl.create(:post)
post2 = FactoryGirl.create(:post)
post3 = FactoryGirl.create(:post)
relation = Post.tag_match("id:#{post2.id}")
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
@@ -738,10 +738,10 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for the <fav> metatag" do
post1 = Factory.create(:post)
post2 = Factory.create(:post)
post3 = Factory.create(:post)
user = Factory.create(:user)
post1 = FactoryGirl.create(:post)
post2 = FactoryGirl.create(:post)
post3 = FactoryGirl.create(:post)
user = FactoryGirl.create(:user)
post1.add_favorite!(user)
relation = Post.tag_match("fav:#{user.name}")
assert_equal(1, relation.count)
@@ -749,10 +749,10 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for the <pool> metatag" do
post1 = Factory.create(:post)
post2 = Factory.create(:post)
post3 = Factory.create(:post)
pool = Factory.create(:pool, :name => "xxx")
post1 = FactoryGirl.create(:post)
post2 = FactoryGirl.create(:post)
post3 = FactoryGirl.create(:post)
pool = FactoryGirl.create(:pool, :name => "xxx")
post1.add_pool!(pool)
relation = Post.tag_match("pool:xxx")
assert_equal(1, relation.count)
@@ -760,14 +760,14 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for the <uploader> metatag" do
second_user = Factory.create(:user)
post1 = Factory.create(:post, :uploader => CurrentUser.user)
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 = Factory.create(:post)
post3 = Factory.create(:post)
post2 = FactoryGirl.create(:post)
post3 = FactoryGirl.create(:post)
end
relation = Post.tag_match("uploader:#{CurrentUser.user.name}")
@@ -776,53 +776,53 @@ class PostTest < ActiveSupport::TestCase
end
should "return posts for a list of md5 hashes" do
post1 = Factory.create(:post, :md5 => "abcd")
post2 = Factory.create(:post)
post3 = Factory.create(:post)
post1 = FactoryGirl.create(:post, :md5 => "abcd")
post2 = FactoryGirl.create(:post)
post3 = FactoryGirl.create(:post)
relation = Post.tag_match("md5:abcd")
assert_equal(1, relation.count)
assert_equal(post1.id, relation.first.id)
end
should "return posts for a source search" do
post1 = Factory.create(:post, :source => "abcd")
post2 = Factory.create(:post, :source => "abcdefg")
post3 = Factory.create(:post, :source => "xyz")
post1 = FactoryGirl.create(:post, :source => "abcd")
post2 = FactoryGirl.create(:post, :source => "abcdefg")
post3 = FactoryGirl.create(:post, :source => "xyz")
relation = Post.tag_match("source:abcde")
assert_equal(1, relation.count)
assert_equal(post2.id, relation.first.id)
end
should "return posts for a tag subscription search" do
post1 = Factory.create(:post, :tag_string => "aaa")
sub = Factory.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
post1 = FactoryGirl.create(:post, :tag_string => "aaa")
sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
TagSubscription.process_all
relation = Post.tag_match("sub:#{CurrentUser.name}")
assert_equal(1, relation.count)
end
should "return posts for a particular rating" do
post1 = Factory.create(:post, :rating => "s")
post2 = Factory.create(:post, :rating => "q")
post3 = Factory.create(:post, :rating => "e")
post1 = FactoryGirl.create(:post, :rating => "s")
post2 = FactoryGirl.create(:post, :rating => "q")
post3 = FactoryGirl.create(:post, :rating => "e")
relation = Post.tag_match("rating:e")
assert_equal(1, relation.count)
assert_equal(post3.id, relation.first.id)
end
should "return posts for a particular negated rating" do
post1 = Factory.create(:post, :rating => "s")
post2 = Factory.create(:post, :rating => "s")
post3 = Factory.create(:post, :rating => "e")
post1 = FactoryGirl.create(:post, :rating => "s")
post2 = FactoryGirl.create(:post, :rating => "s")
post3 = FactoryGirl.create(:post, :rating => "e")
relation = Post.tag_match("-rating:s")
assert_equal(1, relation.count)
assert_equal(post3.id, relation.first.id)
end
should "return posts ordered by a particular attribute" do
post1 = Factory.create(:post, :rating => "s")
post2 = Factory.create(:post, :rating => "s")
post3 = Factory.create(:post, :rating => "e", :score => 5, :image_width => 1000)
post1 = FactoryGirl.create(:post, :rating => "s")
post2 = FactoryGirl.create(:post, :rating => "s")
post3 = FactoryGirl.create(:post, :rating => "e", :score => 5, :image_width => 1000)
relation = Post.tag_match("order:id")
assert_equal(post1.id, relation.first.id)
relation = Post.tag_match("order:mpixels")
@@ -832,14 +832,14 @@ class PostTest < ActiveSupport::TestCase
end
should "fail for exclusive tag searches with no other tag" do
post1 = Factory.create(:post, :rating => "s", :tag_string => "aaa")
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
assert_raise(::Post::SearchError) do
relation = Post.tag_match("-aaa")
end
end
should "succeed for exclusive tag searches combined with a metatag" do
post1 = Factory.create(:post, :rating => "s", :tag_string => "aaa")
post1 = FactoryGirl.create(:post, :rating => "s", :tag_string => "aaa")
assert_nothing_raised do
relation = Post.tag_match("-aaa id:>0")
end
@@ -848,8 +848,8 @@ class PostTest < ActiveSupport::TestCase
context "Voting:" do
should "not allow duplicate votes" do
user = Factory.create(:user)
post = Factory.create(:post)
user = FactoryGirl.create(:user)
post = FactoryGirl.create(:post)
CurrentUser.scoped(user, "127.0.0.1") do
assert_nothing_raised {post.vote!("up")}
assert_raises(PostVote::Error) {post.vote!("up")}
@@ -864,7 +864,7 @@ class PostTest < ActiveSupport::TestCase
context "Creating a post" do
should "increment the post count" do
assert_equal(0, Post.fast_count(""))
post = Factory.create(:post, :tag_string => "aaa bbb")
post = FactoryGirl.create(:post, :tag_string => "aaa bbb")
assert_equal(1, Post.fast_count(""))
assert_equal(1, Post.fast_count("aaa"))
assert_equal(1, Post.fast_count("bbb"))
@@ -884,7 +884,7 @@ class PostTest < ActiveSupport::TestCase
context "Reverting: " do
context "a post that has been updated" do
setup do
@post = Factory.create(:post, :rating => "q", :tag_string => "aaa")
@post = FactoryGirl.create(:post, :rating => "q", :tag_string => "aaa")
@post.update_attributes(:tag_string => "aaa bbb ccc ddd")
@post.update_attributes(:tag_string => "bbb xxx yyy", :source => "xyz")
@post.update_attributes(:tag_string => "bbb mmm yyy", :source => "abc")

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostVersionTest < ActiveSupport::TestCase
context "A post" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,7 +16,7 @@ class PostVersionTest < ActiveSupport::TestCase
context "that has multiple versions: " do
setup do
@post = Factory.create(:post, :tag_string => "1")
@post = FactoryGirl.create(:post, :tag_string => "1")
@post.update_attributes(:tag_string => "1 2")
@post.update_attributes(:tag_string => "2 3")
end
@@ -41,8 +41,8 @@ class PostVersionTest < ActiveSupport::TestCase
context "that has been created" do
setup do
@parent = Factory.create(:post)
@post = Factory.create(:post, :tag_string => "aaa bbb ccc", :rating => "e", :parent => @parent, :source => "xyz")
@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
@@ -57,8 +57,8 @@ class PostVersionTest < ActiveSupport::TestCase
context "that has been updated" do
setup do
@parent = Factory.create(:post)
@post = Factory.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
@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

View File

@@ -2,12 +2,12 @@ require 'test_helper'
class PostVoteTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
context "Voting for a post" do

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class RelatedTagCalculatorTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,27 +16,27 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
context "A related tag calculator" do
should "calculate related tags for a tag" do
posts = []
posts << Factory.create(:post, :tag_string => "aaa bbb ccc ddd")
posts << Factory.create(:post, :tag_string => "aaa bbb ccc")
posts << Factory.create(:post, :tag_string => "aaa bbb")
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 << Factory.create(:post, :tag_string => "aaa bbb ccc")
posts << Factory.create(:post, :tag_string => "aaa bbb ccc ddd")
posts << Factory.create(:post, :tag_string => "aaa eee fff")
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
should "calculate typed related tags for a tag" do
posts = []
posts << Factory.create(:post, :tag_string => "aaa bbb art:ccc copy:ddd")
posts << Factory.create(:post, :tag_string => "aaa bbb art:ccc")
posts << Factory.create(:post, :tag_string => "aaa bbb")
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))
@@ -44,9 +44,9 @@ class RelatedTagCalculatorTest < ActiveSupport::TestCase
should "convert a hash into string format" do
posts = []
posts << Factory.create(:post, :tag_string => "aaa bbb ccc ddd")
posts << Factory.create(:post, :tag_string => "aaa bbb ccc")
posts << Factory.create(:post, :tag_string => "aaa bbb")
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)

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class RelatedTagQueryTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -11,8 +11,8 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
context "a related tag query without a category constraint" do
setup do
@post_1 = Factory.create(:post, :tag_string => "aaa bbb")
@post_2 = Factory.create(:post, :tag_string => "aaa bbb ccc")
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@post_2 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
context "for a tag that already exists" do
@@ -52,7 +52,7 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
context "for a tag with a wiki page" do
setup do
@wiki_page = Factory.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]")
@wiki_page = FactoryGirl.create(:wiki_page, :title => "aaa", :body => "[[bbb]] [[ccc]]")
@query = RelatedTagQuery.new("aaa", "")
end
@@ -64,9 +64,9 @@ class RelatedTagQueryTest < ActiveSupport::TestCase
context "a related tag query with a category constraint" do
setup do
@post_1 = Factory.create(:post, :tag_string => "aaa bbb")
@post_2 = Factory.create(:post, :tag_string => "aaa art:ccc")
@post_3 = Factory.create(:post, :tag_string => "aaa copy:ddd")
@post_1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
@post_2 = FactoryGirl.create(:post, :tag_string => "aaa art:ccc")
@post_3 = FactoryGirl.create(:post, :tag_string => "aaa copy:ddd")
@query = RelatedTagQuery.new("aaa", "artist")
end

View File

@@ -1,39 +1,39 @@
# encoding: UTF-8
require 'test_helper'
module Sources
class PixaTest < ActiveSupport::TestCase
context "The source site for pixa" do
setup do
@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
end
end
end
end
end
# # encoding: UTF-8
#
# require 'test_helper'
#
# module Sources
# class PixaTest < ActiveSupport::TestCase
# context "The source site for pixa" do
# setup do
# @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
# end
# end
# end
# end
# end

View File

@@ -1,38 +1,38 @@
# encoding: UTF-8
require 'test_helper'
module Sources
class TinamiTest < ActiveSupport::TestCase
context "The source site for tinami" do
context "for tinami" do
setup do
@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
end
end
end
end
end
end
# # encoding: UTF-8
#
# require 'test_helper'
#
# module Sources
# class TinamiTest < ActiveSupport::TestCase
# context "The source site for tinami" do
# context "for tinami" do
# setup do
# @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
# end
# end
# end
# end
# end
# end

View File

@@ -3,10 +3,11 @@ require 'test_helper'
class TagAliasTest < ActiveSupport::TestCase
context "A tag alias" do
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
teardown do
@@ -20,16 +21,16 @@ class TagAliasTest < ActiveSupport::TestCase
end
should "convert a tag to its normalized version" do
tag1 = Factory.create(:tag, :name => "aaa")
tag2 = Factory.create(:tag, :name => "bbb")
tag1 = FactoryGirl.create(:tag, :name => "aaa")
tag2 = FactoryGirl.create(:tag, :name => "bbb")
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
normalized_tags = TagAlias.to_aliased(["aaa", "ccc"])
assert_equal(["bbb", "ccc"], normalized_tags.sort)
end
should "update the cache" do
tag1 = Factory.create(:tag, :name => "aaa")
tag2 = Factory.create(:tag, :name => "bbb")
tag1 = FactoryGirl.create(:tag, :name => "aaa")
tag2 = FactoryGirl.create(:tag, :name => "bbb")
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
assert_nil(MEMCACHE.get("ta:aaa"))
ta.update_cache
@@ -40,8 +41,8 @@ class TagAliasTest < ActiveSupport::TestCase
should "update any affected posts when saved" do
assert_equal(0, TagAlias.count)
post1 = Factory.create(:post, :tag_string => "aaa bbb")
post2 = Factory.create(:post, :tag_string => "ccc ddd")
post1 = FactoryGirl.create(:post, :tag_string => "aaa bbb")
post2 = FactoryGirl.create(:post, :tag_string => "ccc ddd")
assert_equal("aaa bbb", post1.tag_string)
assert_equal("ccc ddd", post2.tag_string)
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "ccc")
@@ -54,7 +55,7 @@ class TagAliasTest < ActiveSupport::TestCase
should "not validate for transitive relations" do
ta1 = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
assert_difference("TagAlias.count", 0) do
ta3 = Factory.build(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ddd")
ta3 = FactoryGirl.build(:tag_alias, :antecedent_name => "bbb", :consequent_name => "ddd")
ta3.save
assert(ta3.errors.any?, "Tag alias should be invalid")
assert_equal("Tag alias can not create a transitive relation with another tag alias", ta3.errors.full_messages.join)
@@ -62,10 +63,10 @@ class TagAliasTest < ActiveSupport::TestCase
end
should "record the alias's creator in the tag history" do
uploader = Factory.create(:user)
uploader = FactoryGirl.create(:user)
post = nil
CurrentUser.scoped(uploader, "127.0.0.1") do
post = Factory.create(:post, :tag_string => "aaa bbb ccc")
post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "xxx")
post.reload

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class TagImplicationTest < ActiveSupport::TestCase
context "A tag implication" do
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
MEMCACHE.flush_all
end
@@ -22,7 +22,7 @@ class TagImplicationTest < ActiveSupport::TestCase
should "not validate when a circular relation is created" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = Factory.build(:tag_implication, :antecedent_name => "bbb", :consequent_name => "aaa")
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "bbb", :consequent_name => "aaa")
ti2.save
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(""))
@@ -30,7 +30,7 @@ class TagImplicationTest < ActiveSupport::TestCase
should "not allow for duplicates" do
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = Factory.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2 = FactoryGirl.build(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
ti2.save
assert(ti2.errors.any?, "Tag implication should not have validated.")
assert_equal("Antecedent name has already been taken", ti2.errors.full_messages.join(""))
@@ -94,7 +94,7 @@ class TagImplicationTest < ActiveSupport::TestCase
end
should "update any affected post upon save" do
p1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
ti2 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "yyy")
p1.reload
@@ -102,10 +102,10 @@ class TagImplicationTest < ActiveSupport::TestCase
end
should "record the implication's creator in the tag history" do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
p1 = nil
CurrentUser.scoped(user, "127.0.0.1") do
p1 = Factory.create(:post, :tag_string => "aaa bbb ccc")
p1 = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc")
end
ti1 = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "xxx")
p1.reload

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class TagSubscriptionTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,39 +16,39 @@ class TagSubscriptionTest < ActiveSupport::TestCase
context "A tag subscription" do
should "find the union of all posts for each tag in its tag query" do
posts = []
user = Factory.create(:user)
posts << Factory.create(:post, :tag_string => "aaa")
posts << Factory.create(:post, :tag_string => "bbb")
posts << Factory.create(:post, :tag_string => "ccc")
posts << Factory.create(:post, :tag_string => "ddd")
sub_1 = Factory.create(:tag_subscription, :tag_query => "aaa bbb", :creator => user, :name => "zzz")
sub_2 = Factory.create(:tag_subscription, :tag_query => "ccc", :creator => user, :name => "yyy")
user = FactoryGirl.create(:user)
posts << FactoryGirl.create(:post, :tag_string => "aaa")
posts << FactoryGirl.create(:post, :tag_string => "bbb")
posts << FactoryGirl.create(:post, :tag_string => "ccc")
posts << FactoryGirl.create(:post, :tag_string => "ddd")
sub_1 = FactoryGirl.create(:tag_subscription, :tag_query => "aaa bbb", :creator => user, :name => "zzz")
sub_2 = FactoryGirl.create(:tag_subscription, :tag_query => "ccc", :creator => user, :name => "yyy")
assert_equal([posts[1].id, posts[0].id], TagSubscription.find_posts(user.id, "zzz").map(&:id))
assert_equal([posts[2].id, posts[1].id, posts[0].id], TagSubscription.find_posts(user.id).map(&:id))
end
should "cache its tag query results" do
posts = []
user = Factory.create(:user)
posts << Factory.create(:post, :tag_string => "aaa")
posts << Factory.create(:post, :tag_string => "bbb")
posts << Factory.create(:post, :tag_string => "ccc")
sub = Factory.create(:tag_subscription, :tag_query => "aaa bbb", :creator => user, :name => "zzz")
user = FactoryGirl.create(:user)
posts << FactoryGirl.create(:post, :tag_string => "aaa")
posts << FactoryGirl.create(:post, :tag_string => "bbb")
posts << FactoryGirl.create(:post, :tag_string => "ccc")
sub = FactoryGirl.create(:tag_subscription, :tag_query => "aaa bbb", :creator => user, :name => "zzz")
assert_equal("#{posts[1].id},#{posts[0].id}", sub.post_ids)
end
should "find posts based on its cached post ids" do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
subs = []
subs << Factory.create(:tag_subscription, :tag_query => "aaa", :creator => user, :name => "zzz")
subs << Factory.create(:tag_subscription, :tag_query => "bbb", :creator => user, :name => "yyy")
subs << FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :creator => user, :name => "zzz")
subs << FactoryGirl.create(:tag_subscription, :tag_query => "bbb", :creator => user, :name => "yyy")
assert_equal([], TagSubscription.find_posts(user.id))
assert_equal([], TagSubscription.find_posts(user.id, "zzz"))
assert_equal([], TagSubscription.find_posts(user.id, "yyy"))
posts = []
posts << Factory.create(:post, :tag_string => "aaa")
posts << Factory.create(:post, :tag_string => "bbb")
posts << Factory.create(:post, :tag_string => "ccc")
posts << FactoryGirl.create(:post, :tag_string => "aaa")
posts << FactoryGirl.create(:post, :tag_string => "bbb")
posts << FactoryGirl.create(:post, :tag_string => "ccc")
subs.each {|x| x.process; x.save}
assert_equal([posts[1].id, posts[0].id], TagSubscription.find_posts(user.id).map(&:id))
assert_equal([posts[0].id], TagSubscription.find_posts(user.id, "zzz").map(&:id))
@@ -59,15 +59,15 @@ class TagSubscriptionTest < ActiveSupport::TestCase
context "A tag subscription manager" do
should "process all active tag subscriptions" do
users = []
users << Factory.create(:user)
users << Factory.create(:user)
users << FactoryGirl.create(:user)
users << FactoryGirl.create(:user)
posts = []
posts << Factory.create(:post, :tag_string => "aaa")
posts << Factory.create(:post, :tag_string => "bbb")
posts << Factory.create(:post, :tag_string => "ccc")
posts << FactoryGirl.create(:post, :tag_string => "aaa")
posts << FactoryGirl.create(:post, :tag_string => "bbb")
posts << FactoryGirl.create(:post, :tag_string => "ccc")
subscriptions = []
subscriptions << Factory.create(:tag_subscription, :tag_query => "aaa", :creator => users[0])
subscriptions << Factory.create(:tag_subscription, :tag_query => "bbb", :creator => users[1])
subscriptions << FactoryGirl.create(:tag_subscription, :tag_query => "aaa", :creator => users[0])
subscriptions << FactoryGirl.create(:tag_subscription, :tag_query => "bbb", :creator => users[1])
TagSubscription.process_all
subscriptions.each {|x| x.reload}
assert_equal("#{posts[0].id}", subscriptions[0].post_ids)

View File

@@ -2,7 +2,7 @@ require 'test_helper'
class TagTest < ActiveSupport::TestCase
setup do
user = Factory.create(:user)
user = FactoryGirl.create(:user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -20,18 +20,18 @@ class TagTest < ActiveSupport::TestCase
end
should "fetch for a single tag" do
Factory.create(:artist_tag, :name => "test")
FactoryGirl.create(:artist_tag, :name => "test")
assert_equal(Tag.categories.artist, Tag.category_for("test"))
end
should "fetch for a single tag with strange markup" do
Factory.create(:artist_tag, :name => "!@$%")
FactoryGirl.create(:artist_tag, :name => "!@$%")
assert_equal(Tag.categories.artist, Tag.category_for("!@$%"))
end
should "fetch for multiple tags" do
Factory.create(:artist_tag, :name => "aaa")
Factory.create(:copyright_tag, :name => "bbb")
FactoryGirl.create(:artist_tag, :name => "aaa")
FactoryGirl.create(:copyright_tag, :name => "bbb")
categories = Tag.categories_for(%w(aaa bbb ccc))
assert_equal(Tag.categories.artist, categories["aaa"])
assert_equal(Tag.categories.copyright, categories["bbb"])
@@ -85,12 +85,12 @@ class TagTest < ActiveSupport::TestCase
end
should "know its category name" do
@tag = Factory.create(:artist_tag)
@tag = FactoryGirl.create(:artist_tag)
assert_equal("Artist", @tag.category_name)
end
should "reset its category after updating" do
tag = Factory.create(:artist_tag)
tag = FactoryGirl.create(:artist_tag)
assert_equal(Tag.categories.artist, MEMCACHE.get("tc:#{tag.name}"))
tag.update_attribute(:category, Tag.categories.copyright)
@@ -118,8 +118,8 @@ class TagTest < ActiveSupport::TestCase
end
should "parse a query" do
tag1 = Factory.create(:tag, :name => "abc")
tag2 = Factory.create(:tag, :name => "acb")
tag1 = FactoryGirl.create(:tag, :name => "abc")
tag2 = FactoryGirl.create(:tag, :name => "acb")
assert_equal(["abc"], Tag.parse_query("md5:abc")[:md5])
assert_equal([:between, 1, 2], Tag.parse_query("id:1..2")[:post_id])
@@ -135,14 +135,14 @@ class TagTest < ActiveSupport::TestCase
context "A tag" do
should "be found when one exists" do
tag = Factory.create(:tag)
tag = FactoryGirl.create(:tag)
assert_difference("Tag.count", 0) do
Tag.find_or_create_by_name(tag.name)
end
end
should "change the type for an existing tag" do
tag = Factory.create(:tag)
tag = FactoryGirl.create(:tag)
assert_difference("Tag.count", 0) do
assert_equal(Tag.categories.general, tag.category)
Tag.find_or_create_by_name("artist:#{tag.name}")

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class UploadTest < ActiveSupport::TestCase
context "In all cases" do
setup do
user = Factory.create(:contributor_user)
user = FactoryGirl.create(:contributor_user)
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -23,21 +23,21 @@ class UploadTest < ActiveSupport::TestCase
context "image size calculator" do
should "discover the dimensions for a JPG" do
@upload = Factory.create(:jpg_upload)
@upload = FactoryGirl.create(:jpg_upload)
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
assert_equal(500, @upload.image_width)
assert_equal(335, @upload.image_height)
end
should "discover the dimensions for a PNG" do
@upload = Factory.create(:png_upload)
@upload = FactoryGirl.create(:png_upload)
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
assert_equal(768, @upload.image_width)
assert_equal(1024, @upload.image_height)
end
should "discover the dimensions for a GIF" do
@upload = Factory.create(:gif_upload)
@upload = FactoryGirl.create(:gif_upload)
assert_nothing_raised {@upload.calculate_dimensions(@upload.file_path)}
assert_equal(400, @upload.image_width)
assert_equal(400, @upload.image_height)
@@ -46,7 +46,7 @@ class UploadTest < ActiveSupport::TestCase
context "content type calculator" do
should "know how to parse jpeg, png, gif, and swf file extensions" do
@upload = Factory.create(:jpg_upload)
@upload = FactoryGirl.create(:jpg_upload)
assert_equal("image/jpeg", @upload.file_ext_to_content_type("test.jpeg"))
assert_equal("image/gif", @upload.file_ext_to_content_type("test.gif"))
assert_equal("image/png", @upload.file_ext_to_content_type("test.png"))
@@ -55,7 +55,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "know how to parse jpeg, png, gif, and swf content types" do
@upload = Factory.create(:jpg_upload)
@upload = FactoryGirl.create(:jpg_upload)
assert_equal("jpg", @upload.content_type_to_file_ext("image/jpeg"))
assert_equal("gif", @upload.content_type_to_file_ext("image/gif"))
assert_equal("png", @upload.content_type_to_file_ext("image/png"))
@@ -66,7 +66,7 @@ class UploadTest < ActiveSupport::TestCase
context "downloader" do
should "initialize the final path and content type after downloading a file" do
@upload = Factory.create(:source_upload)
@upload = FactoryGirl.create(:source_upload)
path = "#{Rails.root}/tmp/test.download.jpg"
assert_nothing_raised {@upload.download_from_source(path)}
assert(File.exists?(path))
@@ -101,7 +101,7 @@ class UploadTest < ActiveSupport::TestCase
context "hash calculator" do
should "caculate the hash" do
@upload = Factory.create(:jpg_upload)
@upload = FactoryGirl.create(:jpg_upload)
@upload.calculate_hash(@upload.file_path)
assert_equal("ecef68c44edb8a0d6a3070b5f8e8ee76", @upload.md5)
end
@@ -115,7 +115,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "generate several resized versions of the image" do
@upload = Factory.create(:large_jpg_upload)
@upload = FactoryGirl.create(:large_jpg_upload)
@upload.calculate_hash(@upload.file_path)
@upload.calculate_dimensions(@upload.file_path)
assert_nothing_raised {@upload.generate_resizes(@upload.file_path)}
@@ -127,7 +127,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "increment the uploaders post_upload_count" do
@upload = Factory.create(:source_upload)
@upload = FactoryGirl.create(:source_upload)
assert_difference("CurrentUser.post_upload_count", 1) do
@upload.process!
CurrentUser.reload
@@ -135,7 +135,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "process completely for a downloaded image" do
@upload = Factory.create(:source_upload,
@upload = FactoryGirl.create(:source_upload,
:rating => "s",
:uploader_ip_addr => "127.0.0.1",
:tag_string => "hoge foo"
@@ -160,7 +160,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "process completely for an uploaded image" do
@upload = Factory.create(:jpg_upload,
@upload = FactoryGirl.create(:jpg_upload,
:rating => "s",
:uploader_ip_addr => "127.0.0.1",
:tag_string => "hoge foo"
@@ -185,7 +185,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "delete the temporary file upon completion" do
@upload = Factory.create(:source_upload,
@upload = FactoryGirl.create(:source_upload,
:rating => "s",
:uploader_ip_addr => "127.0.0.1",
:tag_string => "hoge foo"

View File

@@ -13,16 +13,16 @@ class UserFeedbackTest < ActiveSupport::TestCase
end
should "should not validate if the creator is not privileged" do
user = Factory.create(:user)
privileged = Factory.create(:privileged_user)
member = Factory.create(:user)
user = FactoryGirl.create(:user)
privileged = FactoryGirl.create(:privileged_user)
member = FactoryGirl.create(:user)
CurrentUser.user = privileged
feedback = Factory.create(:user_feedback, :user => user)
feedback = FactoryGirl.create(:user_feedback, :user => user)
assert(feedback.errors.empty?)
CurrentUser.user = member
feedback = Factory.build(:user_feedback, :user => user)
feedback = FactoryGirl.build(:user_feedback, :user => user)
feedback.save
assert(feedback.errors.any?)
end

View File

@@ -4,8 +4,8 @@ class UserPasswordResetNonceTest < ActiveSupport::TestCase
context "Creating a new nonce" do
context "with a valid email" do
setup do
@user = Factory.create(:user, :email => "aaa@b.net")
@nonce = Factory.create(:user_password_reset_nonce, :email => @user.email)
@user = FactoryGirl.create(:user, :email => "aaa@b.net")
@nonce = FactoryGirl.create(:user_password_reset_nonce, :email => @user.email)
end
should "validate" do
@@ -24,7 +24,7 @@ class UserPasswordResetNonceTest < ActiveSupport::TestCase
context "with a blank email" do
setup do
@user = Factory.create(:user, :email => "")
@user = FactoryGirl.create(:user, :email => "")
@nonce = UserPasswordResetNonce.new(:email => "")
end

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class UserTest < ActiveSupport::TestCase
context "A user" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@@ -16,7 +16,7 @@ class UserTest < ActiveSupport::TestCase
context "that has been invited by a mod" do
setup do
@mod = Factory.create(:moderator_user)
@mod = FactoryGirl.create(:moderator_user)
end
should "work" do
@@ -34,10 +34,10 @@ class UserTest < ActiveSupport::TestCase
context "who has negeative feedback and is trying to change their name" do
setup do
@mod = Factory.create(:moderator_user)
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.scoped(@mod, "127.0.0.1") do
Factory.create(:user_feedback, :user => @user, :category => "negative")
FactoryGirl.create(:user_feedback, :user => @user, :category => "negative")
end
end
@@ -49,8 +49,8 @@ class UserTest < ActiveSupport::TestCase
end
should "not validate if the originating ip address is banned" do
Factory.create(:ip_ban)
user = Factory.build(:user)
FactoryGirl.create(:ip_ban)
user = FactoryGirl.build(:user)
user.save
assert(user.errors.any?)
assert_equal("IP address is banned", user.errors.full_messages.join)
@@ -63,7 +63,7 @@ class UserTest < ActiveSupport::TestCase
@user.update_column(:level, User::Levels::MEMBER)
40.times do
Factory.create(:post, :uploader => @user, :is_deleted => true)
FactoryGirl.create(:post, :uploader => @user, :is_deleted => true)
end
assert(!@user.can_upload?)
@@ -74,8 +74,8 @@ class UserTest < ActiveSupport::TestCase
Danbooru.config.stubs(:member_comment_limit).returns(10)
assert(@user.can_comment_vote?)
10.times do
comment = Factory.create(:comment)
Factory.create(:comment_vote, :comment_id => comment.id)
comment = FactoryGirl.create(:comment)
FactoryGirl.create(:comment_vote, :comment_id => comment.id)
end
assert(!@user.can_comment_vote?)
@@ -91,14 +91,14 @@ class UserTest < ActiveSupport::TestCase
@user.update_column(:created_at, 1.year.ago)
assert(@user.can_comment?)
(Danbooru.config.member_comment_limit).times do
Factory.create(:comment)
FactoryGirl.create(:comment)
end
assert(!@user.can_comment?)
end
should "verify" do
assert(@user.is_verified?)
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
@user.generate_email_verification_key
@user.save
assert(!@user.is_verified?)
@@ -115,41 +115,41 @@ class UserTest < ActiveSupport::TestCase
end
should "normalize its level" do
user = Factory.create(:user, :level => User::Levels::ADMIN)
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 = Factory.create(:user, :level => User::Levels::MODERATOR)
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 = Factory.create(:user, :level => User::Levels::JANITOR)
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 = Factory.create(:user, :level => User::Levels::CONTRIBUTOR)
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 = Factory.create(:user, :level => User::Levels::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 = Factory.create(:user)
user = FactoryGirl.create(:user)
assert(!user.is_admin?)
assert(!user.is_moderator?)
assert(!user.is_janitor?)
@@ -163,12 +163,12 @@ class UserTest < ActiveSupport::TestCase
end
should "be fetched given a user id" do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
assert_equal(@user.name, User.id_to_name(@user.id))
end
should "be updated" do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
@user.update_attribute(:name, "danzig")
assert_equal(@user.name, User.id_to_name(@user.id))
end
@@ -176,7 +176,7 @@ class UserTest < ActiveSupport::TestCase
context "ip address" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
context "in the json representation" do
@@ -194,7 +194,7 @@ class UserTest < ActiveSupport::TestCase
context "cookie password hash" do
setup do
@user = Factory.create(:user, :name => "albert", :password_hash => "1234")
@user = FactoryGirl.create(:user, :name => "albert", :password_hash => "1234")
end
should "be correct" do
@@ -208,7 +208,7 @@ class UserTest < ActiveSupport::TestCase
context "password" do
should "match the confirmation" do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
@user.password = "zugzug5"
@user.password_confirmation = "zugzug5"
@user.save
@@ -217,7 +217,7 @@ class UserTest < ActiveSupport::TestCase
end
should "match the confirmation" do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
@user.password = "zugzug6"
@user.password_confirmation = "zugzug5"
@user.save
@@ -225,7 +225,7 @@ class UserTest < ActiveSupport::TestCase
end
should "not be too short" do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
@user.password = "x5"
@user.password_confirmation = "x5"
@user.save
@@ -233,38 +233,38 @@ class UserTest < ActiveSupport::TestCase
end
should "should be reset" do
@user = Factory.create(:user)
@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 = Factory.create(:user, :password => "67890")
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "", :old_password => "")
assert_equal(User.sha1("67890"), @user.password_hash)
end
should "not change the password if the old password is incorrect" do
@user = Factory.create(:user, :password => "67890")
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "abcdefg")
assert_equal(User.sha1("67890"), @user.password_hash)
end
should "not change the password if the old password is blank" do
@user = Factory.create(:user, :password => "67890")
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "")
assert_equal(User.sha1("67890"), @user.password_hash)
end
should "change the password if the old password is correct" do
@user = Factory.create(:user, :password => "67890")
@user = FactoryGirl.create(:user, :password => "67890")
@user.update_attributes(:password => "12345", :old_password => "67890")
assert_equal(User.sha1("12345"), @user.password_hash)
end
context "in the json representation" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
should "not appear" do
@@ -274,7 +274,7 @@ class UserTest < ActiveSupport::TestCase
context "in the xml representation" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
should "not appear" do

View File

@@ -13,10 +13,10 @@ class WikiPageTest < ActiveSupport::TestCase
context "A wiki page" do
context "updated by a janitor" do
setup do
@user = Factory.create(:janitor_user)
@user = FactoryGirl.create(:janitor_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@wiki_page = Factory.create(:wiki_page)
@wiki_page = FactoryGirl.create(:wiki_page)
end
should "allow the is_locked attribute to be updated" do
@@ -28,10 +28,10 @@ class WikiPageTest < ActiveSupport::TestCase
context "updated by a regular user" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@wiki_page = Factory.create(:wiki_page, :title => "HOT POTATO")
@wiki_page = FactoryGirl.create(:wiki_page, :title => "HOT POTATO")
end
should "not allow the is_locked attribute to be updated" do
@@ -53,7 +53,7 @@ class WikiPageTest < ActiveSupport::TestCase
should "create versions" do
assert_difference("WikiPageVersion.count") do
@wiki_page = Factory.create(:wiki_page, :title => "xxx")
@wiki_page = FactoryGirl.create(:wiki_page, :title => "xxx")
end
assert_difference("WikiPageVersion.count") do
@@ -72,7 +72,7 @@ class WikiPageTest < ActiveSupport::TestCase
end
should "differentiate between updater and creator" do
another_user = Factory.create(:user)
another_user = FactoryGirl.create(:user)
CurrentUser.scoped(another_user, "127.0.0.1") do
@wiki_page.title = "yyy"
@wiki_page.save