Permissions for forums management can be set in "Admin -> Roles & Permissions". Forums can be created on the project settings screen ("Forums" tab). Once a project has a forum, a "Forums" link appears in the project menu. For now, posting messages in forums requires to be logged in. Files can be attached to messages. git-svn-id: http://redmine.rubyforge.org/svn/trunk@529 e93f8b46-1217-0410-a6f0-8f06a7374b81pull/351/head
parent
75582f80f8
commit
b90e84b9fe
@ -0,0 +1,87 @@ |
||||
# redMine - project management software |
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
class BoardsController < ApplicationController |
||||
layout 'base' |
||||
before_filter :find_project |
||||
before_filter :authorize, :except => [:index, :show] |
||||
before_filter :check_project_privacy, :only => [:index, :show] |
||||
|
||||
helper :messages |
||||
include MessagesHelper |
||||
helper :sort |
||||
include SortHelper |
||||
|
||||
def index |
||||
@boards = @project.boards |
||||
# show the board if there is only one |
||||
if @boards.size == 1 |
||||
@board = @boards.first |
||||
show |
||||
render :action => 'show' |
||||
end |
||||
end |
||||
|
||||
def show |
||||
sort_init "#{Message.table_name}.updated_on", "desc" |
||||
sort_update |
||||
|
||||
@topic_count = @board.topics.count |
||||
@topic_pages = Paginator.new self, @topic_count, 25, params['page'] |
||||
@topics = @board.topics.find :all, :order => sort_clause, |
||||
:include => [:author, {:last_reply => :author}], |
||||
:limit => @topic_pages.items_per_page, |
||||
:offset => @topic_pages.current.offset |
||||
render :action => 'show', :layout => false if request.xhr? |
||||
end |
||||
|
||||
verify :method => :post, :only => [ :destroy ], :redirect_to => { :action => :index } |
||||
|
||||
def new |
||||
@board = Board.new(params[:board]) |
||||
@board.project = @project |
||||
if request.post? && @board.save |
||||
flash[:notice] = l(:notice_successful_create) |
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
||||
end |
||||
end |
||||
|
||||
def edit |
||||
if request.post? && @board.update_attributes(params[:board]) |
||||
case params[:position] |
||||
when 'highest'; @board.move_to_top |
||||
when 'higher'; @board.move_higher |
||||
when 'lower'; @board.move_lower |
||||
when 'lowest'; @board.move_to_bottom |
||||
end if params[:position] |
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
||||
end |
||||
end |
||||
|
||||
def destroy |
||||
@board.destroy |
||||
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'boards' |
||||
end |
||||
|
||||
private |
||||
def find_project |
||||
@project = Project.find(params[:project_id]) |
||||
@board = @project.boards.find(params[:id]) if params[:id] |
||||
rescue ActiveRecord::RecordNotFound |
||||
render_404 |
||||
end |
||||
end |
@ -0,0 +1,66 @@ |
||||
# redMine - project management software |
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
class MessagesController < ApplicationController |
||||
layout 'base' |
||||
before_filter :find_project, :check_project_privacy |
||||
before_filter :require_login, :only => [:new, :reply] |
||||
|
||||
verify :method => :post, :only => [ :reply, :destroy ], :redirect_to => { :action => :show } |
||||
|
||||
def show |
||||
@reply = Message.new(:subject => "RE: #{@message.subject}") |
||||
render :action => "show", :layout => false if request.xhr? |
||||
end |
||||
|
||||
def new |
||||
@message = Message.new(params[:message]) |
||||
@message.author = logged_in_user |
||||
@message.board = @board |
||||
if request.post? && @message.save |
||||
params[:attachments].each { |file| |
||||
next unless file.size > 0 |
||||
Attachment.create(:container => @message, :file => file, :author => logged_in_user) |
||||
} if params[:attachments] and params[:attachments].is_a? Array |
||||
redirect_to :action => 'show', :id => @message |
||||
end |
||||
end |
||||
|
||||
def reply |
||||
@reply = Message.new(params[:reply]) |
||||
@reply.author = logged_in_user |
||||
@reply.board = @board |
||||
@message.children << @reply |
||||
redirect_to :action => 'show', :id => @message |
||||
end |
||||
|
||||
def download |
||||
@attachment = @message.attachments.find(params[:attachment_id]) |
||||
send_file @attachment.diskfile, :filename => @attachment.filename |
||||
rescue |
||||
render_404 |
||||
end |
||||
|
||||
private |
||||
def find_project |
||||
@board = Board.find(params[:board_id], :include => :project) |
||||
@project = @board.project |
||||
@message = @board.topics.find(params[:id]) if params[:id] |
||||
rescue ActiveRecord::RecordNotFound |
||||
render_404 |
||||
end |
||||
end |
@ -0,0 +1,19 @@ |
||||
# redMine - project management software |
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
module BoardsHelper |
||||
end |
@ -0,0 +1,28 @@ |
||||
# redMine - project management software |
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
module MessagesHelper |
||||
|
||||
def link_to_message(message) |
||||
return '' unless message |
||||
link_to h(truncate(message.subject, 60)), :controller => 'messages', |
||||
:action => 'show', |
||||
:board_id => message.board_id, |
||||
:id => message.root, |
||||
:anchor => (message.parent_id ? "message-#{message.id}" : nil) |
||||
end |
||||
end |
@ -0,0 +1,28 @@ |
||||
# redMine - project management software |
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
class Board < ActiveRecord::Base |
||||
belongs_to :project |
||||
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC" |
||||
has_many :messages, :dependent => :delete_all, :order => "#{Message.table_name}.created_on DESC" |
||||
belongs_to :last_message, :class_name => 'Message', :foreign_key => :last_message_id |
||||
acts_as_list :scope => :project_id |
||||
|
||||
validates_presence_of :name, :description |
||||
validates_length_of :name, :maximum => 30 |
||||
validates_length_of :description, :maximum => 255 |
||||
end |
@ -0,0 +1,37 @@ |
||||
# redMine - project management software |
||||
# Copyright (C) 2006-2007 Jean-Philippe Lang |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
|
||||
class Message < ActiveRecord::Base |
||||
belongs_to :board |
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
||||
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" |
||||
has_many :attachments, :as => :container, :dependent => :destroy |
||||
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id' |
||||
|
||||
validates_presence_of :subject, :content |
||||
validates_length_of :subject, :maximum => 255 |
||||
|
||||
def after_create |
||||
board.update_attribute(:last_message_id, self.id) |
||||
board.increment! :messages_count |
||||
if parent |
||||
parent.reload.update_attribute(:last_reply_id, self.id) |
||||
else |
||||
board.increment! :topics_count |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,8 @@ |
||||
<%= error_messages_for 'board' %> |
||||
|
||||
<!--[form:board]--> |
||||
<div class="box"> |
||||
<p><%= f.text_field :name, :required => true %></p> |
||||
<p><%= f.text_field :description, :required => true, :size => 80 %></p> |
||||
</div> |
||||
<!--[eoform:board]--> |
@ -0,0 +1,6 @@ |
||||
<h2><%= l(:label_board) %></h2> |
||||
|
||||
<% labelled_tabular_form_for :board, @board, :url => {:action => 'edit', :id => @board} do |f| %> |
||||
<%= render :partial => 'form', :locals => {:f => f} %> |
||||
<%= submit_tag l(:button_save) %> |
||||
<% end %> |
@ -0,0 +1,30 @@ |
||||
<h2><%= l(:label_board_plural) %></h2> |
||||
|
||||
<table class="list"> |
||||
<thead><tr> |
||||
<th><%= l(:label_board) %></th> |
||||
<th><%= l(:label_topic_plural) %></th> |
||||
<th><%= l(:label_message_plural) %></th> |
||||
<th><%= l(:label_message_last) %></th> |
||||
</tr></thead> |
||||
<tbody> |
||||
<% for board in @boards %> |
||||
<tr class="<%= cycle 'odd', 'even' %>"> |
||||
<td> |
||||
<%= link_to h(board.name), {:action => 'show', :id => board}, :class => "icon22 icon22-comment" %><br /> |
||||
<%=h board.description %> |
||||
</td> |
||||
<td align="center"><%= board.topics_count %></td> |
||||
<td align="center"><%= board.messages_count %></td> |
||||
<td> |
||||
<small> |
||||
<% if board.last_message %> |
||||
<%= board.last_message.author.name %>, <%= format_time(board.last_message.created_on) %><br /> |
||||
<%= link_to_message board.last_message %> |
||||
<% end %> |
||||
</small> |
||||
</td> |
||||
</tr> |
||||
<% end %> |
||||
</tbody> |
||||
</table> |
@ -0,0 +1,6 @@ |
||||
<h2><%= l(:label_board_new) %></h2> |
||||
|
||||
<% labelled_tabular_form_for :board, @board, :url => {:action => 'new'} do |f| %> |
||||
<%= render :partial => 'form', :locals => {:f => f} %> |
||||
<%= submit_tag l(:button_create) %> |
||||
<% end %> |
@ -0,0 +1,36 @@ |
||||
<div class="contextual"> |
||||
<%= link_to l(:label_message_new), {:controller => 'messages', :action => 'new', :board_id => @board}, :class => "icon icon-add" %> |
||||
</div> |
||||
|
||||
<h2><%=h @board.name %></h2> |
||||
|
||||
<table class="list"> |
||||
<thead><tr> |
||||
<th><%= l(:field_subject) %></th> |
||||
<th><%= l(:field_author) %></th> |
||||
<%= sort_header_tag("#{Message.table_name}.created_on", :caption => l(:field_created_on)) %> |
||||
<th><%= l(:label_reply_plural) %></th> |
||||
<%= sort_header_tag("#{Message.table_name}.updated_on", :caption => l(:label_message_last)) %> |
||||
</tr></thead> |
||||
<tbody> |
||||
<% @topics.each do |topic| %> |
||||
<tr class="<%= cycle 'odd', 'even' %>"> |
||||
<td><%= link_to h(topic.subject), :controller => 'messages', :action => 'show', :board_id => @board, :id => topic %></td> |
||||
<td align="center"><%= link_to_user topic.author %></td> |
||||
<td align="center"><%= format_time(topic.created_on) %></td> |
||||
<td align="center"><%= topic.replies_count %></td> |
||||
<td> |
||||
<small> |
||||
<% if topic.last_reply %> |
||||
<%= topic.last_reply.author.name %>, <%= format_time(topic.last_reply.created_on) %><br /> |
||||
<%= link_to_message topic.last_reply %> |
||||
<% end %> |
||||
</small> |
||||
</td> |
||||
</tr> |
||||
<% end %> |
||||
</tbody> |
||||
</table> |
||||
|
||||
<p><%= pagination_links_full @topic_pages %> |
||||
[ <%= @topic_pages.current.first_item %> - <%= @topic_pages.current.last_item %> / <%= @topic_count %> ]</p> |
@ -0,0 +1,17 @@ |
||||
<%= error_messages_for 'message' %> |
||||
|
||||
<div class="box"> |
||||
<!--[form:message]--> |
||||
<p><label><%= l(:field_subject) %></label><br /> |
||||
<%= f.text_field :subject, :required => true, :size => 80 %></p> |
||||
|
||||
<p><%= f.text_area :content, :required => true, :cols => 80, :rows => 15 %></p> |
||||
<%= wikitoolbar_for 'message_content' %> |
||||
<!--[eoform:message]--> |
||||
|
||||
<span class="tabular"> |
||||
<p id="attachments_p"><label><%=l(:label_attachment)%> |
||||
<%= image_to_function "add.png", "addFileField();return false" %></label> |
||||
<%= file_field_tag 'attachments[]', :size => 30 %> <em>(<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)</em></p> |
||||
</span> |
||||
</div> |
@ -0,0 +1,6 @@ |
||||
<h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%= l(:label_message_new) %></h2> |
||||
|
||||
<% form_for :message, @message, :url => {:action => 'new'}, :html => {:multipart => true} do |f| %> |
||||
<%= render :partial => 'form', :locals => {:f => f} %> |
||||
<%= submit_tag l(:button_create) %> |
||||
<% end %> |
@ -0,0 +1,29 @@ |
||||
<h2><%= link_to h(@board.name), :controller => 'boards', :action => 'show', :project_id => @project, :id => @board %> » <%=h @message.subject %></h2> |
||||
|
||||
<p><em><%= @message.author.name %>, <%= format_time(@message.created_on) %></em></p> |
||||
<div class="wiki"> |
||||
<%= textilizable(@message.content) %> |
||||
</div> |
||||
<div class="attachments"> |
||||
<% @message.attachments.each do |attachment| %> |
||||
<%= link_to attachment.filename, { :action => 'download', :id => @message, :attachment_id => attachment }, :class => 'icon icon-attachment' %> |
||||
(<%= number_to_human_size(attachment.filesize) %>)<br /> |
||||
<% end %> |
||||
</div> |
||||
<br /> |
||||
<h3 class="icon22 icon22-comment"><%= l(:label_reply_plural) %></h3> |
||||
<% @message.children.each do |message| %> |
||||
<a name="<%= "message-#{message.id}" %>"></a> |
||||
<h4><%=h message.subject %> - <%= message.author.name %>, <%= format_time(message.created_on) %></h4> |
||||
<div class="wiki"><p><%= textilizable message.content %></p></div> |
||||
<% end %> |
||||
|
||||
<p><%= toggle_link l(:button_reply), "reply", :focus => "reply_content" %></p> |
||||
<div id="reply" style="display:none;"> |
||||
<%= error_messages_for 'message' %> |
||||
<% form_for :reply, @reply, :url => {:action => 'reply', :id => @message} do |f| %> |
||||
<p><%= f.text_field :subject, :required => true, :size => 60 %></p> |
||||
<p><%= f.text_area :content, :required => true, :cols => 80, :rows => 10 %></p> |
||||
<p><%= submit_tag l(:button_submit) %></p> |
||||
<% end %> |
||||
</div> |
@ -0,0 +1,24 @@ |
||||
<table class="list"> |
||||
<thead><th><%= l(:label_board) %></th><th><%= l(:field_description) %></th><th style="width:15%"></th><th style="width:15%"></th><th style="width:15%"></th></thead> |
||||
<tbody> |
||||
<% @project.boards.each do |board| |
||||
next if board.new_record? %> |
||||
<tr class="<%= cycle 'odd', 'even' %>"> |
||||
<td><%=h board.name %></td> |
||||
<td><%=h board.description %></td> |
||||
<td align="center"> |
||||
<% if authorize_for("boards", "edit") %> |
||||
<%= link_to image_tag('2uparrow.png', :alt => l(:label_sort_highest)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'highest'}, :method => :post, :title => l(:label_sort_highest) %> |
||||
<%= link_to image_tag('1uparrow.png', :alt => l(:label_sort_higher)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'higher'}, :method => :post, :title => l(:label_sort_higher) %> - |
||||
<%= link_to image_tag('1downarrow.png', :alt => l(:label_sort_lower)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'lower'}, :method => :post, :title => l(:label_sort_lower) %> |
||||
<%= link_to image_tag('2downarrow.png', :alt => l(:label_sort_lowest)), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board, :position => 'lowest'}, :method => :post, :title => l(:label_sort_lowest) %> |
||||
<% end %> |
||||
</td> |
||||
<td align="center"><small><%= link_to_if_authorized l(:button_edit), {:controller => 'boards', :action => 'edit', :project_id => @project, :id => board}, :class => 'icon icon-edit' %></small></td> |
||||
<td align="center"><small><%= link_to_if_authorized l(:button_delete), {:controller => 'boards', :action => 'destroy', :project_id => @project, :id => board}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></small></td> |
||||
</tr> |
||||
<% end %> |
||||
</tbody> |
||||
</table> |
||||
|
||||
<p><%= link_to_if_authorized l(:label_board_new), {:controller => 'boards', :action => 'new', :project_id => @project} %></p> |
@ -0,0 +1,18 @@ |
||||
class CreateBoards < ActiveRecord::Migration |
||||
def self.up |
||||
create_table :boards do |t| |
||||
t.column :project_id, :integer, :null => false |
||||
t.column :name, :string, :default => "", :null => false |
||||
t.column :description, :string |
||||
t.column :position, :integer, :default => 1, :null => false |
||||
t.column :topics_count, :integer, :default => 0, :null => false |
||||
t.column :messages_count, :integer, :default => 0, :null => false |
||||
t.column :last_message_id, :integer |
||||
end |
||||
add_index :boards, [:project_id], :name => :boards_project_id |
||||
end |
||||
|
||||
def self.down |
||||
drop_table :boards |
||||
end |
||||
end |
@ -0,0 +1,21 @@ |
||||
class CreateMessages < ActiveRecord::Migration |
||||
def self.up |
||||
create_table :messages do |t| |
||||
t.column :board_id, :integer, :null => false |
||||
t.column :parent_id, :integer |
||||
t.column :subject, :string, :default => "", :null => false |
||||
t.column :content, :text |
||||
t.column :author_id, :integer |
||||
t.column :replies_count, :integer, :default => 0, :null => false |
||||
t.column :last_reply_id, :integer |
||||
t.column :created_on, :datetime, :null => false |
||||
t.column :updated_on, :datetime, :null => false |
||||
end |
||||
add_index :messages, [:board_id], :name => :messages_board_id |
||||
add_index :messages, [:parent_id], :name => :messages_parent_id |
||||
end |
||||
|
||||
def self.down |
||||
drop_table :messages |
||||
end |
||||
end |
@ -0,0 +1,13 @@ |
||||
class AddBoardsPermissions < ActiveRecord::Migration |
||||
def self.up |
||||
Permission.create :controller => "boards", :action => "new", :description => "button_add", :sort => 2000, :is_public => false, :mail_option => 0, :mail_enabled => 0 |
||||
Permission.create :controller => "boards", :action => "edit", :description => "button_edit", :sort => 2005, :is_public => false, :mail_option => 0, :mail_enabled => 0 |
||||
Permission.create :controller => "boards", :action => "destroy", :description => "button_delete", :sort => 2010, :is_public => false, :mail_option => 0, :mail_enabled => 0 |
||||
end |
||||
|
||||
def self.down |
||||
Permission.find_by_controller_and_action("boards", "new").destroy |
||||
Permission.find_by_controller_and_action("boards", "edit").destroy |
||||
Permission.find_by_controller_and_action("boards", "destroy").destroy |
||||
end |
||||
end |
Before Width: | Height: | Size: 520 B After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,19 @@ |
||||
--- |
||||
boards_001: |
||||
name: Help |
||||
project_id: 1 |
||||
topics_count: 1 |
||||
id: 1 |
||||
description: Help board |
||||
position: 1 |
||||
last_message_id: 2 |
||||
messages_count: 2 |
||||
boards_002: |
||||
name: Discussion |
||||
project_id: 1 |
||||
topics_count: 0 |
||||
id: 2 |
||||
description: Discussion board |
||||
position: 2 |
||||
last_message_id: |
||||
messages_count: 0 |
@ -0,0 +1,25 @@ |
||||
--- |
||||
messages_001: |
||||
created_on: 2007-05-12 17:15:32 +02:00 |
||||
updated_on: 2007-05-12 17:15:32 +02:00 |
||||
subject: First post |
||||
id: 1 |
||||
replies_count: 1 |
||||
last_reply_id: 2 |
||||
content: "This is the very first post\n\ |
||||
in the forum" |
||||
author_id: 1 |
||||
parent_id: |
||||
board_id: 1 |
||||
messages_002: |
||||
created_on: 2007-05-12 17:18:00 +02:00 |
||||
updated_on: 2007-05-12 17:18:00 +02:00 |
||||
subject: First reply |
||||
id: 2 |
||||
replies_count: 0 |
||||
last_reply_id: |
||||
content: "Reply to the first post" |
||||
author_id: 1 |
||||
parent_id: 1 |
||||
board_id: 1 |
||||
|
@ -0,0 +1,30 @@ |
||||
require File.dirname(__FILE__) + '/../test_helper' |
||||
|
||||
class BoardTest < Test::Unit::TestCase |
||||
fixtures :projects, :boards, :messages |
||||
|
||||
def setup |
||||
@project = Project.find(1) |
||||
end |
||||
|
||||
def test_create |
||||
board = Board.new(:project => @project, :name => 'Test board', :description => 'Test board description') |
||||
assert board.save |
||||
board.reload |
||||
assert_equal 'Test board', board.name |
||||
assert_equal 'Test board description', board.description |
||||
assert_equal @project, board.project |
||||
assert_equal 0, board.topics_count |
||||
assert_equal 0, board.messages_count |
||||
assert_nil board.last_message |
||||
# last position |
||||
assert_equal @project.boards.size, board.position |
||||
end |
||||
|
||||
def test_destroy |
||||
board = Board.find(1) |
||||
assert board.destroy |
||||
# make sure that the associated messages are removed |
||||
assert_equal 0, Message.count(:conditions => {:board_id => 1}) |
||||
end |
||||
end |
@ -0,0 +1,44 @@ |
||||
require File.dirname(__FILE__) + '/../test_helper' |
||||
|
||||
class MessageTest < Test::Unit::TestCase |
||||
fixtures :projects, :boards, :messages |
||||
|
||||
def setup |
||||
@board = Board.find(1) |
||||
@user = User.find(1) |
||||
end |
||||
|
||||
def test_create |
||||
topics_count = @board.topics_count |
||||
messages_count = @board.messages_count |
||||
|
||||
message = Message.new(:board => @board, :subject => 'Test message', :content => 'Test message content', :author => @user) |
||||
assert message.save |
||||
@board.reload |
||||
# topics count incremented |
||||
assert_equal topics_count+1, @board[:topics_count] |
||||
# messages count incremented |
||||
assert_equal messages_count+1, @board[:messages_count] |
||||
assert_equal message, @board.last_message |
||||
end |
||||
|
||||
def test_reply |
||||
topics_count = @board.topics_count |
||||
messages_count = @board.messages_count |
||||
@message = Message.find(1) |
||||
replies_count = @message.replies_count |
||||
|
||||
reply = Message.new(:board => @board, :subject => 'Test reply', :content => 'Test reply content', :parent => @message, :author => @user) |
||||
assert reply.save |
||||
@board.reload |
||||
# same topics count |
||||
assert_equal topics_count, @board[:topics_count] |
||||
# messages count incremented |
||||
assert_equal messages_count+1, @board[:messages_count] |
||||
assert_equal reply, @board.last_message |
||||
@message.reload |
||||
# replies count incremented |
||||
assert_equal replies_count+1, @message[:replies_count] |
||||
assert_equal reply, @message.last_reply |
||||
end |
||||
end |
Loading…
Reference in new issue