2014-11-20 11:29:32 +09:00
|
|
|
require "test_helper"
|
2010-04-20 23:05:11 +00:00
|
|
|
|
|
|
|
class CommentTest < ActiveSupport::TestCase
|
|
|
|
fixtures :users, :posts
|
2014-08-23 16:19:01 +09:00
|
|
|
|
2010-04-20 23:05:11 +00: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")
|
2010-04-20 23:05:11 +00:00
|
|
|
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)
|
2010-04-20 23:05:11 +00:00
|
|
|
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
|
2010-04-20 23:05:11 +00:00
|
|
|
|
|
|
|
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")
|
2010-04-20 23:05:11 +00:00
|
|
|
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")
|
2010-04-20 23:05:11 +00:00
|
|
|
assert_equal(comment_a.created_at.to_s, Post.find(1).last_commented_at.to_s)
|
2014-08-23 16:19:01 +09:00
|
|
|
|
2010-04-20 23:05:11 +00:00
|
|
|
CONFIG["comment_threshold"] = old_threshold
|
|
|
|
end
|
2014-08-23 16:19:01 +09:00
|
|
|
|
2010-04-20 23:05:11 +00: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")
|
2010-04-20 23:05:11 +00:00
|
|
|
assert_nothing_raised do
|
|
|
|
comment.to_xml
|
|
|
|
end
|
|
|
|
assert_nothing_raised do
|
|
|
|
comment.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|