mirror of
https://github.com/moebooru/moebooru
synced 2025-09-01 14:35:14 +00:00
part of r1800: tests
--HG-- branch : moe extra : convert_revision : svn%3A2d28d66d-8d94-df11-8c86-00306ef368cb/trunk/moe%40121
This commit is contained in:
7
test/fixtures/favorite_tags.yml
vendored
Normal file
7
test/fixtures/favorite_tags.yml
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||||
|
|
||||||
|
# one:
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
# two:
|
||||||
|
# column: value
|
@@ -49,7 +49,7 @@ class CommentControllerTest < ActionController::TestCase
|
|||||||
CONFIG["member_comment_limit"] = 1
|
CONFIG["member_comment_limit"] = 1
|
||||||
create_comment(1, "c1", :user_id => 4)
|
create_comment(1, "c1", :user_id => 4)
|
||||||
post :create, {:comment => {:post_id => 1, :body => "c2"}, :commit => "Post"}, {:user_id => 4}
|
post :create, {:comment => {:post_id => 1, :body => "c2"}, :commit => "Post"}, {:user_id => 4}
|
||||||
assert_redirected_to :controller => "comment", :action => "index"
|
assert_redirected_to :controller => "post", :action => "show", :id => 1
|
||||||
assert_equal(1, Post.find(1).comments.size)
|
assert_equal(1, Post.find(1).comments.size)
|
||||||
assert_equal("c1", Post.find(1).comments[0].body)
|
assert_equal("c1", Post.find(1).comments[0].body)
|
||||||
CONFIG["member_comment_limit"] = old_member_comment_limit
|
CONFIG["member_comment_limit"] = old_member_comment_limit
|
||||||
|
@@ -93,17 +93,8 @@ class UserControllerTest < ActionController::TestCase
|
|||||||
post :create, {:user => {:name => "mog", :email => "mog@danbooru.com", :password => "zugzug1", :password_confirmation => "zugzug1"}}
|
post :create, {:user => {:name => "mog", :email => "mog@danbooru.com", :password => "zugzug1", :password_confirmation => "zugzug1"}}
|
||||||
mog = User.find_by_name("mog")
|
mog = User.find_by_name("mog")
|
||||||
assert_not_nil(mog)
|
assert_not_nil(mog)
|
||||||
|
|
||||||
if CONFIG["enable_account_email_activation"]
|
|
||||||
assert_equal(CONFIG["user_levels"]["Unactivated"], mog.level)
|
|
||||||
assert_equal(1, ActionMailer::Base.deliveries.size)
|
|
||||||
|
|
||||||
post :activate_user, {:hash => User.confirmation_hash("mog")}
|
|
||||||
mog.reload
|
|
||||||
assert_equal(CONFIG["user_levels"]["Member"], mog.level)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
get :edit, {}, {:user_id => 4}
|
get :edit, {}, {:user_id => 4}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
@@ -156,16 +147,4 @@ class UserControllerTest < ActionController::TestCase
|
|||||||
banned.reload
|
banned.reload
|
||||||
assert_equal(CONFIG["user_levels"]["Member"], banned.level)
|
assert_equal(CONFIG["user_levels"]["Member"], banned.level)
|
||||||
end
|
end
|
||||||
|
|
||||||
if CONFIG["enable_account_email_activation"]
|
|
||||||
def test_resend_confirmation
|
|
||||||
setup_action_mailer
|
|
||||||
|
|
||||||
get :resend_confirmation, {}, {}
|
|
||||||
assert_response :success
|
|
||||||
|
|
||||||
post :resend_confirmation, {:email => "unactivated@danbooru.com"}
|
|
||||||
assert_equal(1, ActionMailer::Base.deliveries.size)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@@ -1,79 +1,8 @@
|
|||||||
require File.dirname(__FILE__) + '/../test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class FavoriteTagTest < ActiveSupport::TestCase
|
class FavoriteTagTest < ActiveSupport::TestCase
|
||||||
fixtures :users
|
# Replace this with your real tests.
|
||||||
|
def test_truth
|
||||||
def create_fav_tag(tag_query, user_id)
|
assert true
|
||||||
FavoriteTag.create(:tag_query => tag_query, :user_id => user_id, :cached_post_ids => "")
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_post(post_number, params = {})
|
|
||||||
Post.create({:user_id => 1, :score => 0, :source => "", :rating => "s", :width => 100, :height => 100, :ip_addr => '127.0.0.1', :updater_ip_addr => "127.0.0.1", :updater_user_id => 1, :status => "active", :tags => "tag1 tag2", :file => upload_jpeg("#{RAILS_ROOT}/test/mocks/test/test#{post_number}.jpg")}.merge(params))
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_interested
|
|
||||||
p1 = create_post(1, :tags => "hoge")
|
|
||||||
p2 = create_post(2, :tags => "moge")
|
|
||||||
fav_tag = create_fav_tag("hoge", 1)
|
|
||||||
|
|
||||||
assert(fav_tag.interested?(p1.id))
|
|
||||||
assert(!fav_tag.interested?(p2.id))
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_add_post
|
|
||||||
p1 = create_post(1, :tags => "hoge")
|
|
||||||
p2 = create_post(2, :tags => "moge")
|
|
||||||
fav_tag = create_fav_tag("hoge", 1)
|
|
||||||
|
|
||||||
p3 = create_post(3, :tags => "hoge moge")
|
|
||||||
FavoriteTag.process_all(p2.id)
|
|
||||||
fav_tag.reload
|
|
||||||
|
|
||||||
assert_equal("#{p3.id},#{p1.id}", fav_tag.cached_post_ids)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_prune
|
|
||||||
old_limit = CONFIG["favorite_tag_limit"]
|
|
||||||
|
|
||||||
CONFIG["favorite_tag_limit"] = 1
|
|
||||||
|
|
||||||
p1 = create_post(1, :tags => "hoge")
|
|
||||||
p2 = create_post(2, :tags => "moge")
|
|
||||||
fav_tag = create_fav_tag("hoge", 1)
|
|
||||||
|
|
||||||
fav_tag.add_post!(p1.id)
|
|
||||||
fav_tag.add_post!(p2.id)
|
|
||||||
fav_tag.prune!
|
|
||||||
assert_equal("#{p2.id}", fav_tag.cached_post_ids)
|
|
||||||
|
|
||||||
CONFIG["favorite_tag_limit"] = old_limit
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_find_posts
|
|
||||||
p1 = create_post(1, :tags => "hoge")
|
|
||||||
p2 = create_post(2, :tags => "moge")
|
|
||||||
fav_tag = create_fav_tag("hoge", 1)
|
|
||||||
fav_tag.add_post!(p1.id)
|
|
||||||
fav_tag.add_post!(p2.id)
|
|
||||||
|
|
||||||
assert_equal([p1.id, p2.id], FavoriteTag.find_posts(1).map(&:id).sort)
|
|
||||||
|
|
||||||
fav_tag_2 = create_fav_tag("soge", 1)
|
|
||||||
p3 = create_post(3, :tags => "soge")
|
|
||||||
fav_tag_2.add_post!(p3.id)
|
|
||||||
|
|
||||||
assert_equal([p1.id, p2.id, p3.id], FavoriteTag.find_posts(1).map(&:id).sort)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_process_all
|
|
||||||
fav_tag = create_fav_tag("hoge", 1)
|
|
||||||
|
|
||||||
p1 = create_post(1, :tags => "hoge")
|
|
||||||
p2 = create_post(2, :tags => "moge")
|
|
||||||
|
|
||||||
FavoriteTag.process_all(0)
|
|
||||||
|
|
||||||
fav_tag.reload
|
|
||||||
assert_equal("#{p1.id}", fav_tag.cached_post_ids)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -19,12 +19,12 @@ class UserMailerTest < ActiveSupport::TestCase
|
|||||||
user
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_confirmation_email
|
# def test_confirmation_email
|
||||||
user = create_user("bob")
|
# user = create_user("bob")
|
||||||
assert_nothing_raised {UserMailer.deliver_confirmation_email(user)}
|
# assert_nothing_raised {UserMailer.deliver_confirmation_email(user)}
|
||||||
assert_not_equal(0, ActionMailer::Base.deliveries.size)
|
# assert_not_equal(0, ActionMailer::Base.deliveries.size)
|
||||||
assert_equal("From: #{CONFIG['admin_contact']}\r\nTo: bob@danbooru.com\r\nSubject: #{CONFIG['app_name']} - Confirm email address\r\nMime-Version: 1.0\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<p>Hello, bob. You need to activate your account by visiting <a href=\"http://#{CONFIG['server_host']}/user/activate_user?hash=#{User.confirmation_hash('bob')}\">this link</a>.</p>\n", ActionMailer::Base.deliveries[0].encoded)
|
# assert_equal("From: #{CONFIG['admin_contact']}\r\nTo: bob@danbooru.com\r\nSubject: #{CONFIG['app_name']} - Confirm email address\r\nMime-Version: 1.0\r\nContent-Type: text/html; charset=utf-8\r\n\r\n<p>Hello, bob. You need to activate your account by visiting <a href=\"http://#{CONFIG['server_host']}/user/activate_user?hash=#{User.confirmation_hash('bob')}\">this link</a>.</p>\n", ActionMailer::Base.deliveries[0].encoded)
|
||||||
end
|
# end
|
||||||
|
|
||||||
def test_new_password
|
def test_new_password
|
||||||
user = create_user("bob")
|
user = create_user("bob")
|
||||||
|
Reference in New Issue
Block a user