To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / unit / message_test.rb @ 442:753f1380d6bc
History | View | Annotate | Download (4.83 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
| 3 |
#
|
| 4 |
# This program is free software; you can redistribute it and/or
|
| 5 |
# modify it under the terms of the GNU General Public License
|
| 6 |
# as published by the Free Software Foundation; either version 2
|
| 7 |
# of the License, or (at your option) any later version.
|
| 8 |
#
|
| 9 |
# This program is distributed in the hope that it will be useful,
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
# GNU General Public License for more details.
|
| 13 |
#
|
| 14 |
# You should have received a copy of the GNU General Public License
|
| 15 |
# along with this program; if not, write to the Free Software
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__) |
| 19 |
|
| 20 |
class MessageTest < ActiveSupport::TestCase |
| 21 |
fixtures :projects, :roles, :members, :member_roles, :boards, :messages, :users, :watchers |
| 22 |
|
| 23 |
def setup |
| 24 |
@board = Board.find(1) |
| 25 |
@user = User.find(1) |
| 26 |
end
|
| 27 |
|
| 28 |
def test_create |
| 29 |
topics_count = @board.topics_count
|
| 30 |
messages_count = @board.messages_count
|
| 31 |
|
| 32 |
message = Message.new(:board => @board, :subject => 'Test message', :content => 'Test message content', :author => @user) |
| 33 |
assert message.save |
| 34 |
@board.reload
|
| 35 |
# topics count incremented
|
| 36 |
assert_equal topics_count+1, @board[:topics_count] |
| 37 |
# messages count incremented
|
| 38 |
assert_equal messages_count+1, @board[:messages_count] |
| 39 |
assert_equal message, @board.last_message
|
| 40 |
# author should be watching the message
|
| 41 |
assert message.watched_by?(@user)
|
| 42 |
end
|
| 43 |
|
| 44 |
def test_reply |
| 45 |
topics_count = @board.topics_count
|
| 46 |
messages_count = @board.messages_count
|
| 47 |
@message = Message.find(1) |
| 48 |
replies_count = @message.replies_count
|
| 49 |
|
| 50 |
reply_author = User.find(2) |
| 51 |
reply = Message.new(:board => @board, :subject => 'Test reply', :content => 'Test reply content', :parent => @message, :author => reply_author) |
| 52 |
assert reply.save |
| 53 |
@board.reload
|
| 54 |
# same topics count
|
| 55 |
assert_equal topics_count, @board[:topics_count] |
| 56 |
# messages count incremented
|
| 57 |
assert_equal messages_count+1, @board[:messages_count] |
| 58 |
assert_equal reply, @board.last_message
|
| 59 |
@message.reload
|
| 60 |
# replies count incremented
|
| 61 |
assert_equal replies_count+1, @message[:replies_count] |
| 62 |
assert_equal reply, @message.last_reply
|
| 63 |
# author should be watching the message
|
| 64 |
assert @message.watched_by?(reply_author)
|
| 65 |
end
|
| 66 |
|
| 67 |
def test_moving_message_should_update_counters |
| 68 |
@message = Message.find(1) |
| 69 |
assert_no_difference 'Message.count' do |
| 70 |
# Previous board
|
| 71 |
assert_difference 'Board.find(1).topics_count', -1 do |
| 72 |
assert_difference 'Board.find(1).messages_count', -(1 + @message.replies_count) do |
| 73 |
# New board
|
| 74 |
assert_difference 'Board.find(2).topics_count' do |
| 75 |
assert_difference 'Board.find(2).messages_count', (1 + @message.replies_count) do |
| 76 |
@message.update_attributes(:board_id => 2) |
| 77 |
end
|
| 78 |
end
|
| 79 |
end
|
| 80 |
end
|
| 81 |
end
|
| 82 |
end
|
| 83 |
|
| 84 |
def test_destroy_topic |
| 85 |
message = Message.find(1) |
| 86 |
board = message.board |
| 87 |
topics_count, messages_count = board.topics_count, board.messages_count |
| 88 |
|
| 89 |
assert_difference('Watcher.count', -1) do |
| 90 |
assert message.destroy |
| 91 |
end
|
| 92 |
board.reload |
| 93 |
|
| 94 |
# Replies deleted
|
| 95 |
assert Message.find_all_by_parent_id(1).empty? |
| 96 |
# Checks counters
|
| 97 |
assert_equal topics_count - 1, board.topics_count
|
| 98 |
assert_equal messages_count - 3, board.messages_count
|
| 99 |
# Watchers removed
|
| 100 |
end
|
| 101 |
|
| 102 |
def test_destroy_reply |
| 103 |
message = Message.find(5) |
| 104 |
board = message.board |
| 105 |
topics_count, messages_count = board.topics_count, board.messages_count |
| 106 |
assert message.destroy |
| 107 |
board.reload |
| 108 |
|
| 109 |
# Checks counters
|
| 110 |
assert_equal topics_count, board.topics_count |
| 111 |
assert_equal messages_count - 1, board.messages_count
|
| 112 |
end
|
| 113 |
|
| 114 |
def test_editable_by |
| 115 |
message = Message.find(6) |
| 116 |
author = message.author |
| 117 |
assert message.editable_by?(author) |
| 118 |
|
| 119 |
author.roles_for_project(message.project).first.remove_permission!(:edit_own_messages)
|
| 120 |
assert !message.reload.editable_by?(author.reload) |
| 121 |
end
|
| 122 |
|
| 123 |
def test_destroyable_by |
| 124 |
message = Message.find(6) |
| 125 |
author = message.author |
| 126 |
assert message.destroyable_by?(author) |
| 127 |
|
| 128 |
author.roles_for_project(message.project).first.remove_permission!(:delete_own_messages)
|
| 129 |
assert !message.reload.destroyable_by?(author.reload) |
| 130 |
end
|
| 131 |
|
| 132 |
def test_set_sticky |
| 133 |
message = Message.new
|
| 134 |
assert_equal 0, message.sticky
|
| 135 |
message.sticky = nil
|
| 136 |
assert_equal 0, message.sticky
|
| 137 |
message.sticky = false
|
| 138 |
assert_equal 0, message.sticky
|
| 139 |
message.sticky = true
|
| 140 |
assert_equal 1, message.sticky
|
| 141 |
message.sticky = '0'
|
| 142 |
assert_equal 0, message.sticky
|
| 143 |
message.sticky = '1'
|
| 144 |
assert_equal 1, message.sticky
|
| 145 |
end
|
| 146 |
end
|