2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-22 18:07:25 +00:00
moebooru/test/models/comment_test.rb

42 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

require "test_helper"
class CommentTest < ActiveSupport::TestCase
fixtures :users, :posts
2014-08-23 16:19:01 +09:00
def test_simple
2024-01-08 19:39:01 +09:00
comment = Comment.create(post_id: 1, user_id: 1, body: "hello world", ip_addr: "127.0.0.1")
assert_equal("admin", comment.author)
assert_equal("hello world", comment.body)
2014-12-05 11:48:38 +09:00
assert_equal(comment.created_at.to_i, Post.find(1).last_commented_at.to_i)
end
2014-08-23 16:19:01 +09:00
2014-08-23 20:18:26 +09:00
# def test_no_bump
# comment = Comment.create(:do_not_bump_post => "1", :post_id => 1, :user_id => 1, :body => "hello world", :ip_addr => "127.0.0.1")
# assert_equal("admin", comment.author)
# assert_equal("hello world", comment.body)
# assert_nil(Post.find(1).last_commented_at)
# end
def test_threshold
old_threshold = CONFIG["comment_threshold"]
CONFIG["comment_threshold"] = 1
2014-08-23 16:19:01 +09:00
2024-01-08 19:39:01 +09:00
comment_a = Comment.create(post_id: 1, user_id: 1, body: "mark 1", ip_addr: "127.0.0.1")
sleep 1
2024-01-08 19:39:01 +09:00
Comment.create(post_id: 1, user_id: 1, body: "mark 2", ip_addr: "127.0.0.1")
assert_equal(comment_a.created_at.to_s, Post.find(1).last_commented_at.to_s)
2014-08-23 16:19:01 +09:00
CONFIG["comment_threshold"] = old_threshold
end
2014-08-23 16:19:01 +09:00
def test_api
2024-01-08 19:39:01 +09:00
comment = Comment.create(post_id: 1, user_id: 1, body: "hello world", ip_addr: "127.0.0.1")
assert_nothing_raised do
comment.to_xml
end
assert_nothing_raised do
comment.to_json
end
end
end