Remove post logic

This commit is contained in:
Rei
2014-01-31 20:01:48 +08:00
parent dc6de89a4b
commit 722ca48696
32 changed files with 6 additions and 659 deletions

View File

@@ -1,62 +0,0 @@
require 'test_helper'
class PostTest < ActiveSupport::TestCase
test "should get post_number after create" do
topic = create(:topic)
assert_equal 1, topic.main_post.post_number
assert_equal 2, create(:post).post_number
assert_equal 3, create(:post, :topic => Topic.last).post_number
end
test "should create post_topic notification after create post" do
topic = create(:topic)
assert_difference "topic.user.notifications.named('post_topic').count" do
create :post, topic: topic
end
# skip author
assert_no_difference "topic.user.notifications.named('post_topic').count" do
create :post, topic: topic, user: topic.user
end
# skip top floor
user = create(:user)
assert_no_difference "user.notifications.named('post_topic').count" do
create :topic, user: user
end
end
test "should extract mentions" do
user1 = create :user, username: 'user1'
user2 = create :user, username: 'user2'
post = create(:post, content: '@user1 @user2 @user3')
assert_equal [user1, user2].sort, post.mentions.sort
assert_equal [], create(:post).mentions
end
test "should create post_mention notification" do
user = create :user, username: 'user'
assert_difference "user.notifications.named('post_mention').count" do
post = create(:post, content: '@user')
assert_equal [user], post.mentions
end
# skip author
assert_no_difference "user.notifications.named('post_mention').count" do
create(:post, user: user, content: '@user')
end
end
test "should delete post" do
post = create(:post)
assert_difference "Post.visible.count", -1 do
post.delete
end
assert post.deleted?
assert_difference "Post.visible.count" do
post.restore
end
assert !post.deleted?
end
end

View File

@@ -5,7 +5,7 @@ class TopicTest < ActiveSupport::TestCase
topic = create(:topic)
assert topic.calculate_hot > 0
old_hot = topic.hot
topic.posts_count += 1
topic.comments_count += 1
assert topic.calculate_hot > old_hot
end