* 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

@@ -1,8 +1,10 @@
Factory.define(:advertisement) do |f|
f.referral_url "http://google.com"
f.ad_type "vertical"
f.status "active"
f.width 728
f.height 90
f.file_name "google.gif"
FactoryGirl.define do
factory(:advertisement) do
referral_url "http://google.com"
ad_type "vertical"
status "active"
width 728
height 90
file_name "google.gif"
end
end

View File

@@ -1,4 +1,7 @@
Factory.define(:artist) do |f|
f.name {rand(1_000_000).to_s}
f.is_active true
FactoryGirl.define do
factory(:artist) do
name {rand(1_000_000).to_s}
is_active true
end
end

View File

@@ -1,4 +1,6 @@
Factory.define(:artist_url) do |f|
f.artist {|x| x.association(:artist)}
f.url {Faker::Internet.domain_name}
end
FactoryGirl.define do
factory(:artist_url) do
artist
url {Faker::Internet.domain_name}
end
end

View File

@@ -1,4 +1,6 @@
Factory.define(:ban) do |f|
f.reason {Faker::Lorem.words.join(" ")}
f.duration 60
end
FactoryGirl.define do
factory(:ban) do |f|
reason {Faker::Lorem.words.join(" ")}
duration 60
end
end

View File

@@ -1,4 +1,6 @@
Factory.define(:comment) do |f|
f.post {|x| x.association(:post)}
f.body {Faker::Lorem.sentences.join(" ")}
end
FactoryGirl.define do
factory(:comment) do |f|
post
body {Faker::Lorem.sentences.join(" ")}
end
end

View File

@@ -1,3 +1,5 @@
Factory.define(:comment_vote) do |f|
f.score 1
end
FactoryGirl.define do
factory(:comment_vote) do
score 1
end
end

View File

@@ -1,5 +1,7 @@
Factory.define(:dmail) do |f|
f.to {|x| x.association(:user)}
f.title {Faker::Lorem.words.join(" ")}
f.body {Faker::Lorem.sentences.join(" ")}
FactoryGirl.define do
factory(:dmail) do
to :factory => :user
title {Faker::Lorem.words.join(" ")}
body {Faker::Lorem.sentences.join(" ")}
end
end

View File

@@ -1,2 +1,3 @@
Factory.define(:favorite) do |f|
FactoryGirl.define do
factory(:favorite)
end

View File

@@ -1,3 +1,5 @@
Factory.define(:forum_post) do |f|
f.body {Faker::Lorem.sentences}
end
FactoryGirl.define do
factory(:forum_post) do
body {Faker::Lorem.sentences.join(" ")}
end
end

View File

@@ -1,5 +1,7 @@
Factory.define(:forum_topic) do |f|
f.title {Faker::Lorem.words}
f.is_sticky false
f.is_locked false
end
FactoryGirl.define do
factory(:forum_topic) do
title {Faker::Lorem.words.join(" ")}
is_sticky false
is_locked false
end
end

View File

@@ -1,5 +1,7 @@
Factory.define(:ip_ban) do |f|
f.creator {|x| x.association(:user)}
f.reason {Faker::Lorem.words.join(" ")}
f.ip_addr "127.0.0.1"
end
FactoryGirl.define do
factory(:ip_ban) do
creator :factory => :user
reason {Faker::Lorem.words.join(" ")}
ip_addr "127.0.0.1"
end
end

View File

@@ -1,3 +1,5 @@
Factory.define(:janitor_trial) do |f|
f.user {|x| x.association(:user)}
FactoryGirl.define do
factory(:janitor_trial) do
user
end
end

View File

@@ -1,4 +1,6 @@
Factory.define(:mod_action) do |f|
f.creator {|x| x.association(:user)}
f.description "1234"
FactoryGirl.define do
factory(:mod_action) do
creator :factory => :user
description "1234"
end
end

View File

@@ -1,3 +1,5 @@
Factory.define(:news_update) do |f|
f.message "xxx"
FactoryGirl.define do
factory(:news_update) do
message "xxx"
end
end

View File

@@ -1,12 +1,14 @@
Factory.define(:note) do |f|
f.creator {|x| x.association(:user)}
f.post {|x| x.association(:post)}
f.x 0
f.y 0
f.width 0
f.height 0
f.is_active true
f.body {Faker::Lorem.sentences.join}
f.updater_id {|x| x.association(:user)}
f.updater_ip_addr "127.0.0.1"
end
FactoryGirl.define do
factory(:note) do
creator :factory => :user
post
x 0
y 0
width 0
height 0
is_active true
body {Faker::Lorem.sentences.join(" ")}
updater_id :factory => :user
updater_ip_addr "127.0.0.1"
end
end

View File

@@ -1,5 +1,7 @@
Factory.define(:pool) do |f|
f.name {(rand(1_000_000) + 100).to_s}
f.creator {|x| x.association(:user)}
f.description {Faker::Lorem.sentences}
FactoryGirl.define do
factory(:pool) do
name {(rand(1_000_000) + 100).to_s}
association :creator, :factory => :user
description {Faker::Lorem.sentences.join(" ")}
end
end

View File

@@ -1,13 +1,15 @@
Factory.define(:post) do |f|
f.md5 {|x| Time.now.to_f.to_s}
f.uploader {|x| x.association(:user)}
f.uploader_ip_addr "127.0.0.1"
f.tag_string "tag1 tag2"
f.tag_count 2
f.tag_count_general 2
f.file_ext "jpg"
f.image_width 100
f.image_height 200
f.file_size 2000
f.rating "q"
end
FactoryGirl.define do
factory(:post) do
md5 {|x| Time.now.to_f.to_s}
uploader :factory => :user
uploader_ip_addr "127.0.0.1"
tag_string "tag1 tag2"
tag_count 2
tag_count_general 2
file_ext "jpg"
image_width 100
image_height 200
file_size 2000
rating "q"
end
end

View File

@@ -1,3 +1,5 @@
Factory.define(:post_appeal) do |f|
f.reason "xxx"
FactoryGirl.define do
factory(:post_appeal) do
reason "xxx"
end
end

View File

@@ -1,4 +1,6 @@
Factory.define(:post_flag) do |f|
f.reason "xxx"
f.is_resolved false
FactoryGirl.define do
factory(:post_flag) do
reason "xxx"
is_resolved false
end
end

View File

@@ -1,19 +1,21 @@
Factory.define(:tag) do |f|
f.name {Faker::Name.first_name.downcase}
f.post_count 0
f.category {Tag.categories.general}
f.related_tags ""
f.related_tags_updated_at {Time.now}
end
FactoryGirl.define do
factory(:tag) do
name {Faker::Name.first_name.downcase}
post_count 0
category {Tag.categories.general}
related_tags ""
related_tags_updated_at {Time.now}
factory(:artist_tag) do
category {Tag.categories.artist}
end
Factory.define(:artist_tag, :parent => :tag) do |f|
f.category {Tag.categories.artist}
end
factory(:copyright_tag) do
category {Tag.categories.copyright}
end
Factory.define(:copyright_tag, :parent => :tag) do |f|
f.category {Tag.categories.copyright}
end
Factory.define(:character_tag, :parent => :tag) do |f|
f.category {Tag.categories.character}
factory(:character_tag) do
category {Tag.categories.character}
end
end
end

View File

@@ -3,7 +3,7 @@ FactoryGirl.define do
antecedent_name "aaa"
consequent_name "bbb"
after_create do |tag_alias|
after(:create) do |tag_alias|
tag_alias.process!
end
end

View File

@@ -3,7 +3,7 @@ FactoryGirl.define do
antecedent_name "aaa"
consequent_name "bbb"
after_create do |tag_implication|
after(:create) do |tag_implication|
tag_implication.process!
end
end

View File

@@ -1,5 +1,7 @@
Factory.define(:tag_subscription) do |f|
f.name {Faker::Lorem.words.join(" ")}
f.is_public true
f.tag_query "aaa"
FactoryGirl.define do
factory(:tag_subscription) do
name {Faker::Lorem.words.join(" ")}
is_public true
tag_query "aaa"
end
end

View File

@@ -1,44 +1,47 @@
require 'fileutils'
Factory.define(:upload) do |f|
f.rating "s"
f.uploader {|x| x.association(:user, :level => 200)}
f.uploader_ip_addr "127.0.0.1"
f.tag_string "special"
f.status "pending"
end
FactoryGirl.define do
factory(:upload) do
rating "s"
uploader :factory => :user, :level => 20
uploader_ip_addr "127.0.0.1"
tag_string "special"
status "pending"
factory(:source_upload) do
source "http://www.google.com/intl/en_ALL/images/logo.gif"
end
Factory.define(:source_upload, :parent => :upload) do |f|
f.source "http://www.google.com/intl/en_ALL/images/logo.gif"
end
factory(:jpg_upload) do
content_type "image/jpeg"
file_path do
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test.jpg"
end
end
Factory.define(:jpg_upload, :parent => :upload) do |f|
f.content_type "image/jpeg"
f.file_path do
FileUtils.cp("#{Rails.root}/test/files/test.jpg", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test.jpg"
factory(:large_jpg_upload) do
file_ext "jpg"
content_type "image/jpeg"
file_path do
FileUtils.cp("#{Rails.root}/test/files/test-large.jpg", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test-large.jpg"
end
end
factory(:png_upload) do
file_path do
FileUtils.cp("#{Rails.root}/test/files/test.png", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test.png"
end
end
factory(:gif_upload) do
file_path do
FileUtils.cp("#{Rails.root}/test/files/test.gif", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test.gif"
end
end
end
end
Factory.define(:large_jpg_upload, :parent => :upload) do |f|
f.file_ext "jpg"
f.content_type "image/jpeg"
f.file_path do
FileUtils.cp("#{Rails.root}/test/files/test-large.jpg", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test-large.jpg"
end
end
Factory.define(:png_upload, :parent => :upload) do |f|
f.file_path do
FileUtils.cp("#{Rails.root}/test/files/test.png", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test.png"
end
end
Factory.define(:gif_upload, :parent => :upload) do |f|
f.file_path do
FileUtils.cp("#{Rails.root}/test/files/test.gif", "#{Rails.root}/tmp")
"#{Rails.root}/tmp/test.gif"
end
end

View File

@@ -1,35 +1,38 @@
Factory.define(:user) do |f|
f.name {rand(1_000_000).to_s}
f.password "password"
f.password_hash {User.sha1("password")}
f.email {Faker::Internet.email}
f.default_image_size "large"
f.base_upload_limit 10
f.level 20
f.last_logged_in_at {Time.now}
FactoryGirl.define do
factory(:user) do
name {rand(1_000_000).to_s}
password "password"
password_hash {User.sha1("password")}
email {Faker::Internet.email}
default_image_size "large"
base_upload_limit 10
level 20
last_logged_in_at {Time.now}
factory(:banned_user) do
is_banned true
ban {|x| x.association(:ban)}
end
factory(:privileged_user) do
level 30
end
factory(:contributor_user) do
level 33
end
factory(:janitor_user) do
level 35
end
factory(:moderator_user) do
level 40
end
factory(:admin_user) do
level 50
end
end
end
Factory.define(:banned_user, :parent => :user) do |f|
f.is_banned true
f.ban {|x| x.association(:ban)}
end
Factory.define(:privileged_user, :parent => :user) do |f|
f.level 30
end
Factory.define(:contributor_user, :parent => :user) do |f|
f.level 33
end
Factory.define(:janitor_user, :parent => :user) do |f|
f.level 35
end
Factory.define(:moderator_user, :parent => :user) do |f|
f.level 40
end
Factory.define(:admin_user, :parent => :user) do |f|
f.level 50
end

View File

@@ -1,5 +1,7 @@
Factory.define(:user_feedback) do |f|
f.user {|x| x.association(:user)}
f.category "positive"
f.body {Faker::Lorem.words.join(" ")}
FactoryGirl.define do
factory(:user_feedback) do
user
category "positive"
body {Faker::Lorem.words.join(" ")}
end
end

View File

@@ -1,2 +1,3 @@
Factory.define(:user_password_reset_nonce) do |f|
FactoryGirl.define do
factory(:user_password_reset_nonce)
end

View File

@@ -1,5 +1,7 @@
Factory.define(:wiki_page) do |f|
f.creator {|x| x.association(:user)}
f.title {|x| Faker::Lorem.words.join(" ")}
f.body {Faker::Lorem.sentences.join(" ")}
FactoryGirl.define do
factory(:wiki_page) do
creator :factory => :user
title {Faker::Lorem.words.join(" ")}
body {Faker::Lorem.sentences.join(" ")}
end
end

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class AdvertisementHitsControllerTest < ActionController::TestCase
context "An advertisement hits controller" do
setup do
@ad = Factory.create(:advertisement)
@advertiser = Factory.create(:admin_user)
@ad = FactoryGirl.create(:advertisement)
@advertiser = FactoryGirl.create(:admin_user)
end
should "create a new hit" do

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class AdvertisementsControllerTest < ActionController::TestCase
context "An advertisement controller" do
setup do
@ad = Factory.create(:advertisement)
@advertiser = Factory.create(:admin_user)
@ad = FactoryGirl.create(:advertisement)
@advertiser = FactoryGirl.create(:admin_user)
end
should "get the new page" do
@@ -29,7 +29,7 @@ class AdvertisementsControllerTest < ActionController::TestCase
should "create an ad" do
assert_difference("Advertisement.count", 1) do
post :create, {:advertisement => Factory.attributes_for(:advertisement)}, {:user_id => @advertiser.id}
post :create, {:advertisement => FactoryGirl.attributes_for(:advertisement)}, {:user_id => @advertiser.id}
end
ad = Advertisement.last
assert_redirected_to(advertisement_path(ad))
@@ -50,7 +50,7 @@ class AdvertisementsControllerTest < ActionController::TestCase
end
should "block non-advertisers" do
regular_user = Factory.create(:user)
regular_user = FactoryGirl.create(:user)
get :index, {}, {:user_id => regular_user.id}
assert_redirected_to("/static/access_denied")
end

View File

@@ -3,9 +3,9 @@ require 'test_helper'
class ArtistVersionsControllerTest < ActionController::TestCase
context "An artist versions controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
@artist = Factory.create(:artist)
@artist = FactoryGirl.create(:artist)
end
teardown do

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class ArtistsControllerTest < ActionController::TestCase
context "An artists controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
@artist = Factory.create(:artist)
@user = Factory.create(:user)
@artist = FactoryGirl.create(:artist)
@user = FactoryGirl.create(:user)
end
teardown do
@@ -42,7 +42,7 @@ class ArtistsControllerTest < ActionController::TestCase
should "create an artist" do
assert_difference("Artist.count", 1) do
post :create, {:artist => Factory.attributes_for(:artist)}, {:user_id => @user.id}
post :create, {:artist => FactoryGirl.attributes_for(:artist)}, {:user_id => @user.id}
end
artist = Artist.last
assert_redirected_to(artist_path(artist))

View File

@@ -3,11 +3,11 @@ require 'test_helper'
class BansControllerTest < ActionController::TestCase
context "A bans controller" do
setup do
@mod = Factory.create(:moderator_user)
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @mod
CurrentUser.ip_addr = "127.0.0.1"
@user = Factory.create(:user)
@ban = Factory.create(:ban, :user_id => @user.id)
@user = FactoryGirl.create(:user)
@ban = FactoryGirl.create(:ban, :user_id => @user.id)
end
teardown do

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class CommentVotesControllerTest < ActionController::TestCase
context "A comment votes controller" do
setup do
CurrentUser.user = @user = Factory.create(:user)
CurrentUser.user = @user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
@comment = Factory.create(:comment)
@comment = FactoryGirl.create(:comment)
end
teardown do
@@ -22,7 +22,7 @@ class CommentVotesControllerTest < ActionController::TestCase
end
should "fail silently on errors" do
Factory.create(:comment_vote, :comment => @comment)
FactoryGirl.create(:comment_vote, :comment => @comment)
assert_difference("CommentVote.count", 0) do
post :create, {:format => "js", :comment_id => @comment.id, :score => 1}, {:user_id => @user.id}
assert_response :success

View File

@@ -3,12 +3,12 @@ require 'test_helper'
class CommentsControllerTest < ActionController::TestCase
context "A comments controller" do
setup do
CurrentUser.user = Factory.create(:user)
CurrentUser.user = FactoryGirl.create(:user)
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
@post = Factory.create(:post)
@comment = Factory.create(:comment, :post => @post)
@user = Factory.create(:moderator_user)
@post = FactoryGirl.create(:post)
@comment = FactoryGirl.create(:comment, :post => @post)
@user = FactoryGirl.create(:moderator_user)
end
teardown do
@@ -38,7 +38,7 @@ class CommentsControllerTest < ActionController::TestCase
context "create action"do
should "create a comment" do
assert_difference("Comment.count", 1) do
post :create, {:comment => Factory.attributes_for(:comment, :post_id => @post.id)}, {:user_id => @user.id}
post :create, {:comment => FactoryGirl.attributes_for(:comment, :post_id => @post.id)}, {:user_id => @user.id}
end
comment = Comment.last
assert_redirected_to post_path(comment.post)

View File

@@ -3,11 +3,11 @@ require 'test_helper'
class DmailsControllerTest < ActionController::TestCase
context "The dmails controller" do
setup do
@user = Factory.create(:user)
@unrelated_user = Factory.create(:user)
@user = FactoryGirl.create(:user)
@unrelated_user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@dmail = Factory.create(:dmail, :owner => @user)
@dmail = FactoryGirl.create(:dmail, :owner => @user)
end
teardown do
@@ -73,7 +73,7 @@ class DmailsControllerTest < ActionController::TestCase
context "create action" do
setup do
@user_2 = Factory.create(:user)
@user_2 = FactoryGirl.create(:user)
end
should "create two messages, one for the sender and one for the recipient" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class FavoritesControllerTest < ActionController::TestCase
context "The favorites controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,7 +15,7 @@ class FavoritesControllerTest < ActionController::TestCase
context "index action" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.add_favorite!(@user)
end
@@ -35,7 +35,7 @@ class FavoritesControllerTest < ActionController::TestCase
context "create action" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
should "create a favorite for the current user" do
@@ -47,7 +47,7 @@ class FavoritesControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.add_favorite!(@user)
end

View File

@@ -3,13 +3,13 @@ require 'test_helper'
class ForumPostsControllerTest < ActionController::TestCase
context "The forum posts controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@other_user = Factory.create(:user)
@mod = Factory.create(:moderator_user)
@forum_topic = Factory.create(:forum_topic, :title => "my forum topic", :creator => @user)
@forum_post = Factory.create(:forum_post, :topic_id => @forum_topic.id, :body => "xxx")
@other_user = FactoryGirl.create(:user)
@mod = FactoryGirl.create(:moderator_user)
@forum_topic = FactoryGirl.create(:forum_topic, :title => "my forum topic", :creator => @user)
@forum_post = FactoryGirl.create(:forum_post, :topic_id => @forum_topic.id, :body => "xxx")
end
teardown do

View File

@@ -3,12 +3,12 @@ require 'test_helper'
class ForumTopicsControllerTest < ActionController::TestCase
context "The forum topics controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@other_user = Factory.create(:user)
@mod = Factory.create(:moderator_user)
@forum_topic = Factory.create(:forum_topic, :title => "my forum topic", :creator => @user)
@other_user = FactoryGirl.create(:user)
@mod = FactoryGirl.create(:moderator_user)
@forum_topic = FactoryGirl.create(:forum_topic, :title => "my forum topic", :creator => @user)
end
teardown do
@@ -75,7 +75,7 @@ class ForumTopicsControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@post = Factory.create(:forum_post, :topic_id => @forum_topic.id)
@post = FactoryGirl.create(:forum_post, :topic_id => @forum_topic.id)
end
should "destroy the topic and any associated posts" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class IpBansControllerTest < ActionController::TestCase
context "The ip bans controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -25,7 +25,7 @@ class IpBansControllerTest < ActionController::TestCase
context "index action" do
setup do
Factory.create(:ip_ban)
FactoryGirl.create(:ip_ban)
end
should "render" do
@@ -43,7 +43,7 @@ class IpBansControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@ip_ban = Factory.create(:ip_ban)
@ip_ban = FactoryGirl.create(:ip_ban)
end
should "destroy an ip ban" do

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class JanitorTrialsControllerTest < ActionController::TestCase
context "The janitor trials controller" 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"
end
@@ -30,7 +30,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
context "promote action" 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 "promote the janitor trial" do
@@ -44,7 +44,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
context "demote action" 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 "demote the janitor trial" do
@@ -58,7 +58,7 @@ class JanitorTrialsControllerTest < ActionController::TestCase
context "index action" do
setup do
Factory.create(:janitor_trial)
FactoryGirl.create(:janitor_trial)
end
should "render" do

View File

@@ -5,8 +5,8 @@ module Maintenance
class LoginRemindersControllerTest < ActionController::TestCase
context "A login reminder controller" do
setup do
@user = Factory.create(:user)
@blank_email_user = Factory.create(:user, :email => "")
@user = FactoryGirl.create(:user)
@blank_email_user = FactoryGirl.create(:user, :email => "")
CurrentUser.user = nil
CurrentUser.ip_addr = "127.0.0.1"
ActionMailer::Base.delivery_method = :test

View File

@@ -5,7 +5,7 @@ module Maintenance
class PasswordResetsControllerTest < ActionController::TestCase
context "A password resets controller" do
setup do
@user = Factory.create(:user, :email => "abc@com.net")
@user = FactoryGirl.create(:user, :email => "abc@com.net")
CurrentUser.user = nil
CurrentUser.ip_addr = "127.0.0.1"
ActionMailer::Base.delivery_method = :test
@@ -73,8 +73,8 @@ module Maintenance
context "with valid parameters" do
setup do
@user = Factory.create(:user)
@nonce = Factory.create(:user_password_reset_nonce, :email => @user.email)
@user = FactoryGirl.create(:user)
@nonce = FactoryGirl.create(:user_password_reset_nonce, :email => @user.email)
ActionMailer::Base.deliveries.clear
get :edit, :email => @nonce.email, :key => @nonce.key
end
@@ -98,8 +98,8 @@ module Maintenance
context "with valid parameters" do
setup do
@user = Factory.create(:user)
@nonce = Factory.create(:user_password_reset_nonce, :email => @user.email)
@user = FactoryGirl.create(:user)
@nonce = FactoryGirl.create(:user_password_reset_nonce, :email => @user.email)
ActionMailer::Base.deliveries.clear
@old_password = @user.password_hash
post :update, :email => @nonce.email, :key => @nonce.key

View File

@@ -4,7 +4,7 @@ module Moderator
class DashboardsControllerTest < ActionController::TestCase
context "The moderator dashboards controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
Danbooru.config.stubs(:member_comment_time_threshold).returns(1.week.from_now)
@@ -13,7 +13,7 @@ module Moderator
context "show action" do
context "for mod actions" do
setup do
@mod_action = Factory.create(:mod_action)
@mod_action = FactoryGirl.create(:mod_action)
end
should "render" do
@@ -25,7 +25,7 @@ module Moderator
context "for user feedbacks" do
setup do
@feedback = Factory.create(:user_feedback)
@feedback = FactoryGirl.create(:user_feedback)
end
should "render" do
@@ -37,7 +37,7 @@ module Moderator
context "for wiki pages" do
setup do
@wiki_page = Factory.create(:wiki_page)
@wiki_page = FactoryGirl.create(:wiki_page)
end
should "render" do
@@ -49,7 +49,7 @@ module Moderator
context "for tags and uploads" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
should "render" do
@@ -61,8 +61,8 @@ module Moderator
context "for notes"do
setup do
@post = Factory.create(:post)
@note = Factory.create(:note, :post_id => @post.id)
@post = FactoryGirl.create(:post)
@note = FactoryGirl.create(:note, :post_id => @post.id)
end
should "render" do
@@ -74,10 +74,10 @@ module Moderator
context "for comments" do
setup do
@users = (0..5).map {Factory.create(:user)}
@users = (0..5).map {FactoryGirl.create(:user)}
CurrentUser.scoped(@users[0], "1.2.3.4") do
@comment = Factory.create(:comment)
@comment = FactoryGirl.create(:comment)
end
@users.each do |user|
@@ -95,7 +95,7 @@ module Moderator
context "for artists" do
setup do
@artist = Factory.create(:artist)
@artist = FactoryGirl.create(:artist)
end
should "render" do
@@ -107,7 +107,7 @@ module Moderator
context "for flags" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.flag!("blah")
end
@@ -119,7 +119,7 @@ module Moderator
context "for appeals" do
setup do
@post = Factory.create(:post, :is_deleted => true)
@post = FactoryGirl.create(:post, :is_deleted => true)
@post.appeal!("blah")
end

View File

@@ -4,13 +4,13 @@ module Moderator
class InvitationsControllerTest < ActionController::TestCase
context "The invitations controller" do
setup do
@mod = Factory.create(:moderator_user)
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @mod
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
@user_1 = Factory.create(:user)
@user_2 = Factory.create(:user, :inviter_id => @mod.id)
@user_1 = FactoryGirl.create(:user)
@user_2 = FactoryGirl.create(:user, :inviter_id => @mod.id)
end
should "render the new page" do

View File

@@ -4,10 +4,10 @@ module Moderator
class IpAddrsControllerTest < ActionController::TestCase
context "The ip addrs controller" do
setup do
@user = Factory.create(:moderator_user)
@user = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
Factory.create(:comment)
FactoryGirl.create(:comment)
MEMCACHE.flush_all
end

View File

@@ -5,11 +5,11 @@ module Moderator
class ApprovalsControllerTest < ActionController::TestCase
context "The moderator post approvals controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post, :is_pending => true)
@post = FactoryGirl.create(:post, :is_pending => true)
end
context "create action" do

View File

@@ -5,11 +5,11 @@ module Moderator
class DisapprovalsControllerTest < ActionController::TestCase
context "The moderator post disapprovals controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post, :is_pending => true)
@post = FactoryGirl.create(:post, :is_pending => true)
end
context "create action" do

View File

@@ -5,14 +5,14 @@ module Moderator
class PostsControllerTest < ActionController::TestCase
context "The moderator post disapprovals controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
end
context "delete action" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
should "render" do
@@ -25,7 +25,7 @@ module Moderator
context "undelete action" do
setup do
@post = Factory.create(:post, :is_deleted => true)
@post = FactoryGirl.create(:post, :is_deleted => true)
end
should "render" do

View File

@@ -5,11 +5,11 @@ module Moderator
class QueuesControllerTest < ActionController::TestCase
context "The moderator post queues controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post, :is_pending => true)
@post = FactoryGirl.create(:post, :is_pending => true)
end
context "show action" do

View File

@@ -4,10 +4,10 @@ module Moderator
class TagsControllerTest < ActionController::TestCase
context "The tags controller" 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)
@post = FactoryGirl.create(:post)
end
should "render the edit action" do

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class NewsUpdatesControllerTest < ActionController::TestCase
context "the news updates controller" do
setup do
@admin = Factory.create(:admin_user)
@admin = FactoryGirl.create(:admin_user)
CurrentUser.user = @admin
CurrentUser.ip_addr = "127.0.0.1"
@news_update = Factory.create(:news_update)
@news_update = FactoryGirl.create(:news_update)
end
teardown do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class NoteVersionsControllerTest < ActionController::TestCase
context "The note versions controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,8 +15,8 @@ class NoteVersionsControllerTest < ActionController::TestCase
context "index action" do
setup do
@note = Factory.create(:note)
@user_2 = Factory.create(:user)
@note = FactoryGirl.create(:note)
@user_2 = FactoryGirl.create(:user)
CurrentUser.scoped(@user_2, "1.2.3.4") do
@note.update_attributes(:body => "1 2")

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class NotesControllerTest < ActionController::TestCase
context "The notes controller" 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
@@ -15,7 +15,7 @@ class NotesControllerTest < ActionController::TestCase
context "index action" do
setup do
Factory.create(:note)
FactoryGirl.create(:note)
end
should "list all notes" do
@@ -39,7 +39,7 @@ class NotesControllerTest < ActionController::TestCase
context "update action" do
setup do
@note = Factory.create(:note)
@note = FactoryGirl.create(:note)
end
should "update a note" do
@@ -51,7 +51,7 @@ class NotesControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@note = Factory.create(:note)
@note = FactoryGirl.create(:note)
end
should "destroy a note" do
@@ -63,7 +63,7 @@ class NotesControllerTest < ActionController::TestCase
context "revert action" do
setup do
@note = Factory.create(:note, :body => "000")
@note = FactoryGirl.create(:note, :body => "000")
@note.update_attributes(:body => "111")
@note.update_attributes(:body => "222")
end

View File

@@ -3,12 +3,12 @@ require 'test_helper'
class PoolElementsControllerTest < ActionController::TestCase
context "The pools posts controller" do
setup do
@user = Factory.create(:user)
@mod = Factory.create(:moderator_user)
@user = FactoryGirl.create(:user)
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
@pool = Factory.create(:pool, :name => "abc")
@post = FactoryGirl.create(:post)
@pool = FactoryGirl.create(:pool, :name => "abc")
end
teardown do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PoolVersionsControllerTest < ActionController::TestCase
context "The pool versions controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,9 +15,9 @@ class PoolVersionsControllerTest < ActionController::TestCase
context "index action" do
setup do
@pool = Factory.create(:pool)
@user_2 = Factory.create(:user)
@user_3 = Factory.create(:user)
@pool = FactoryGirl.create(:pool)
@user_2 = FactoryGirl.create(:user)
@user_3 = FactoryGirl.create(:user)
CurrentUser.scoped(@user_2, "1.2.3.4") do
@pool.update_attributes(:post_ids => "1 2")

View File

@@ -3,11 +3,11 @@ require 'test_helper'
class PoolsControllerTest < ActionController::TestCase
context "The pools controller" do
setup do
@user = Factory.create(:user)
@mod = Factory.create(:moderator_user)
@user = FactoryGirl.create(:user)
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
teardown do
@@ -16,7 +16,7 @@ class PoolsControllerTest < ActionController::TestCase
context "index action" do
setup do
Factory.create(:pool, :name => "abc")
FactoryGirl.create(:pool, :name => "abc")
end
should "list all pools" do
@@ -32,7 +32,7 @@ class PoolsControllerTest < ActionController::TestCase
context "show action" do
setup do
@pool = Factory.create(:pool)
@pool = FactoryGirl.create(:pool)
end
should "render" do
@@ -51,7 +51,7 @@ class PoolsControllerTest < ActionController::TestCase
context "update action" do
setup do
@pool = Factory.create(:pool)
@pool = FactoryGirl.create(:pool)
end
should "update a pool" do
@@ -63,7 +63,7 @@ class PoolsControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@pool = Factory.create(:pool)
@pool = FactoryGirl.create(:pool)
end
should "destroy a pool" do
@@ -75,7 +75,7 @@ class PoolsControllerTest < ActionController::TestCase
context "undelete action" do
setup do
@pool = Factory.create(:pool)
@pool = FactoryGirl.create(:pool)
@pool.is_deleted = true
@pool.save
end
@@ -89,8 +89,8 @@ class PoolsControllerTest < ActionController::TestCase
context "revert action" do
setup do
@post_2 = Factory.create(:post)
@pool = Factory.create(:pool, :post_ids => "#{@post.id}")
@post_2 = FactoryGirl.create(:post)
@pool = FactoryGirl.create(:pool, :post_ids => "#{@post.id}")
CurrentUser.ip_addr = "1.2.3.4" # this is to get around the version collation
@pool.update_attributes(:post_ids => "#{@post.id} #{@post_2.id}")
CurrentUser.ip_addr = "127.0.0.1"

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostAppealsControllerTest < ActionController::TestCase
context "The post appeals controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -22,8 +22,8 @@ class PostAppealsControllerTest < ActionController::TestCase
context "index action" do
setup do
@post = Factory.create(:post, :is_deleted => true)
@post_appeal = Factory.create(:post_appeal, :post => @post)
@post = FactoryGirl.create(:post, :is_deleted => true)
@post_appeal = FactoryGirl.create(:post_appeal, :post => @post)
end
should "render" do
@@ -41,7 +41,7 @@ class PostAppealsControllerTest < ActionController::TestCase
context "create action" do
setup do
@post = Factory.create(:post, :is_deleted => true)
@post = FactoryGirl.create(:post, :is_deleted => true)
end
should "create a new appeal" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostFlagsControllerTest < ActionController::TestCase
context "The post flags controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -22,8 +22,8 @@ class PostFlagsControllerTest < ActionController::TestCase
context "index action" do
setup do
@post = Factory.create(:post)
@post_flag = Factory.create(:post_flag, :post => @post)
@post = FactoryGirl.create(:post)
@post_flag = FactoryGirl.create(:post_flag, :post => @post)
end
should "render" do
@@ -41,7 +41,7 @@ class PostFlagsControllerTest < ActionController::TestCase
context "create action" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
should "create a new flag" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class PostVersionsControllerTest < ActionController::TestCase
context "The post versions controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,7 +15,7 @@ class PostVersionsControllerTest < ActionController::TestCase
context "index action" do
setup do
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
@post.update_attributes(:tag_string => "1 2", :source => "xxx")
@post.update_attributes(:tag_string => "2 3", :rating => "e")
end

View File

@@ -3,10 +3,10 @@ require 'test_helper'
class PostVotesControllerTest < ActionController::TestCase
context "The post vote controller" do
setup do
@user = Factory.create(:privileged_user)
@user = FactoryGirl.create(:privileged_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = Factory.create(:post)
@post = FactoryGirl.create(:post)
end
teardown do

View File

@@ -3,10 +3,10 @@ require "test_helper"
class PostsControllerTest < ActionController::TestCase
context "The posts controller" 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, :uploader_id => @user.id, :tag_string => "aaaa")
@post = FactoryGirl.create(:post, :uploader_id => @user.id, :tag_string => "aaaa")
MEMCACHE.flush_all
end

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
context "the sessions controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
context "new action" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class TagAliasesControllerTest < ActionController::TestCase
context "The tag aliases controller" do
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
@@ -17,7 +17,7 @@ class TagAliasesControllerTest < ActionController::TestCase
context "index action" do
setup do
@tag_alias = Factory.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
end
should "list all tag aliass" do
@@ -41,7 +41,7 @@ class TagAliasesControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@tag_alias = Factory.create(:tag_alias)
@tag_alias = FactoryGirl.create(:tag_alias)
end
should "destroy a tag_alias" do
@@ -53,7 +53,7 @@ class TagAliasesControllerTest < ActionController::TestCase
context "destroy_cache action" do
setup do
@tag_alias = Factory.create(:tag_alias, :antecedent_name => "aaa")
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa")
end
should "reset the cache" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class TagImplicationsControllerTest < ActionController::TestCase
context "The tag implicationes controller" do
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
@@ -17,7 +17,7 @@ class TagImplicationsControllerTest < ActionController::TestCase
context "index action" do
setup do
@tag_implication = Factory.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :creator => @user)
@tag_implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb", :creator => @user)
end
should "list all tag implications" do
@@ -41,7 +41,7 @@ class TagImplicationsControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@tag_implication = Factory.create(:tag_implication, :creator => @user)
@tag_implication = FactoryGirl.create(:tag_implication, :creator => @user)
end
should "destroy a tag_implication" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class TagSubscriptionsControllerTest < ActionController::TestCase
context "The tag subscriptions controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,7 +15,7 @@ class TagSubscriptionsControllerTest < ActionController::TestCase
context "index action" do
setup do
@tag_subscription = Factory.create(:tag_subscription, :name => "aaa")
@tag_subscription = FactoryGirl.create(:tag_subscription, :name => "aaa")
end
should "list all visible tag subscriptions" do
@@ -26,7 +26,7 @@ class TagSubscriptionsControllerTest < ActionController::TestCase
context "posts action" do
setup do
@tag_subscription = Factory.create(:tag_subscription, :name => "aaa")
@tag_subscription = FactoryGirl.create(:tag_subscription, :name => "aaa")
end
should "list all visible tag subscriptions" do
@@ -37,7 +37,7 @@ class TagSubscriptionsControllerTest < ActionController::TestCase
context "edit action" do
setup do
@tag_subscription = Factory.create(:tag_subscription)
@tag_subscription = FactoryGirl.create(:tag_subscription)
end
should "render" do
@@ -63,7 +63,7 @@ class TagSubscriptionsControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@tag_subscription = Factory.create(:tag_subscription)
@tag_subscription = FactoryGirl.create(:tag_subscription)
end
should "destroy the posts" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class TagsControllerTest < ActionController::TestCase
context "The tags controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,7 +15,7 @@ class TagsControllerTest < ActionController::TestCase
context "edit action" do
setup do
@tag = Factory.create(:tag, :name => "aaa")
@tag = FactoryGirl.create(:tag, :name => "aaa")
end
should "render" do
@@ -26,7 +26,7 @@ class TagsControllerTest < ActionController::TestCase
context "index action" do
setup do
@tag = Factory.create(:tag, :name => "aaa")
@tag = FactoryGirl.create(:tag, :name => "aaa")
end
should "render" do
@@ -44,7 +44,7 @@ class TagsControllerTest < ActionController::TestCase
context "show action" do
setup do
@tag = Factory.create(:tag)
@tag = FactoryGirl.create(:tag)
end
should "render" do
@@ -55,7 +55,7 @@ class TagsControllerTest < ActionController::TestCase
context "update action" do
setup do
@tag = Factory.create(:tag)
@tag = FactoryGirl.create(:tag)
end
should "update the tag" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class UploadsControllerTest < ActionController::TestCase
context "The uploads controller" do
setup do
@user = Factory.create(:contributor_user)
@user = FactoryGirl.create(:contributor_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -21,7 +21,7 @@ class UploadsControllerTest < ActionController::TestCase
context "for a post that has already been uploaded" do
setup do
@post = Factory.create(:post, :source => "aaa")
@post = FactoryGirl.create(:post, :source => "aaa")
end
should "initialize the post" do
@@ -34,7 +34,7 @@ class UploadsControllerTest < ActionController::TestCase
context "index action" do
setup do
@upload = Factory.create(:source_upload)
@upload = FactoryGirl.create(:source_upload)
end
should "render" do
@@ -52,7 +52,7 @@ class UploadsControllerTest < ActionController::TestCase
context "show action" do
setup do
@upload = Factory.create(:jpg_upload)
@upload = FactoryGirl.create(:jpg_upload)
end
should "render" do
@@ -73,7 +73,7 @@ class UploadsControllerTest < ActionController::TestCase
context "update action" do
setup do
@upload = Factory.create(:jpg_upload)
@upload = FactoryGirl.create(:jpg_upload)
end
should "process an unapproval" do

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class UserFeedbacksControllerTest < ActionController::TestCase
context "The user feedbacks controller" do
setup do
@user = Factory.create(:user)
@critic = Factory.create(:privileged_user)
@user = FactoryGirl.create(:user)
@critic = FactoryGirl.create(:privileged_user)
CurrentUser.user = @critic
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -23,7 +23,7 @@ class UserFeedbacksControllerTest < ActionController::TestCase
context "edit action" do
setup do
@user_feedback = Factory.create(:user_feedback)
@user_feedback = FactoryGirl.create(:user_feedback)
end
should "render" do
@@ -34,7 +34,7 @@ class UserFeedbacksControllerTest < ActionController::TestCase
context "index action" do
setup do
@user_feedback = Factory.create(:user_feedback)
@user_feedback = FactoryGirl.create(:user_feedback)
end
should "render" do
@@ -62,7 +62,7 @@ class UserFeedbacksControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@user_feedback = Factory.create(:user_feedback)
@user_feedback = FactoryGirl.create(:user_feedback)
end
should "delete a feedback" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class UsersControllerTest < ActionController::TestCase
context "The users controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -14,7 +14,7 @@ class UsersControllerTest < ActionController::TestCase
context "index action" do
setup do
Factory.create(:user, :name => "abc")
FactoryGirl.create(:user, :name => "abc")
end
should "list all users" do
@@ -30,7 +30,7 @@ class UsersControllerTest < ActionController::TestCase
context "show action" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
should "render" do
@@ -51,7 +51,7 @@ class UsersControllerTest < ActionController::TestCase
context "edit action" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
should "render" do
@@ -62,7 +62,7 @@ class UsersControllerTest < ActionController::TestCase
context "update action" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
end
should "update a user" do

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class WikiPageVersionsControllerTest < ActionController::TestCase
context "The wiki page versions controller" do
setup do
@user = Factory.create(:user)
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,7 +15,7 @@ class WikiPageVersionsControllerTest < ActionController::TestCase
context "index action" do
setup do
@wiki_page = Factory.create(:wiki_page)
@wiki_page = FactoryGirl.create(:wiki_page)
@wiki_page.update_attributes(:body => "1 2")
@wiki_page.update_attributes(:body => "2 3")
end

View File

@@ -3,8 +3,8 @@ require 'test_helper'
class WikiPagesControllerTest < ActionController::TestCase
context "The wiki pages controller" do
setup do
@user = Factory.create(:user)
@mod = Factory.create(:moderator_user)
@user = FactoryGirl.create(:user)
@mod = FactoryGirl.create(:moderator_user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
end
@@ -15,8 +15,8 @@ class WikiPagesControllerTest < ActionController::TestCase
context "index action" do
setup do
@wiki_page_abc = Factory.create(:wiki_page, :title => "abc")
@wiki_page_def = Factory.create(:wiki_page, :title => "def")
@wiki_page_abc = FactoryGirl.create(:wiki_page, :title => "abc")
@wiki_page_def = FactoryGirl.create(:wiki_page, :title => "def")
end
should "list all wiki_pages" do
@@ -32,7 +32,7 @@ class WikiPagesControllerTest < ActionController::TestCase
context "show action" do
setup do
@wiki_page = Factory.create(:wiki_page)
@wiki_page = FactoryGirl.create(:wiki_page)
end
should "render" do
@@ -57,7 +57,7 @@ class WikiPagesControllerTest < ActionController::TestCase
context "update action" do
setup do
@wiki_page = Factory.create(:wiki_page)
@wiki_page = FactoryGirl.create(:wiki_page)
end
should "update a wiki_page" do
@@ -69,7 +69,7 @@ class WikiPagesControllerTest < ActionController::TestCase
context "destroy action" do
setup do
@wiki_page = Factory.create(:wiki_page)
@wiki_page = FactoryGirl.create(:wiki_page)
end
should "destroy a wiki_page" do
@@ -81,7 +81,7 @@ class WikiPagesControllerTest < ActionController::TestCase
context "revert action" do
setup do
@wiki_page = Factory.create(:wiki_page, :body => "1")
@wiki_page = FactoryGirl.create(:wiki_page, :body => "1")
@wiki_page.update_attributes(:body => "1 2")
@wiki_page.update_attributes(:body => "1 2 3")
end

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")

Some files were not shown because too many files have changed in this diff Show More