##// END OF EJS Templates
Fixed that messages are not sorted by last reply (#12243)....
Jean-Philippe Lang -
r11194:c17ec1643c00
parent child
Show More
@@ -1,110 +1,111
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class BoardsController < ApplicationController
19 19 default_search_scope :messages
20 20 before_filter :find_project_by_project_id, :find_board_if_available, :authorize
21 21 accept_rss_auth :index, :show
22 22
23 23 helper :sort
24 24 include SortHelper
25 25 helper :watchers
26 26
27 27 def index
28 28 @boards = @project.boards.includes(:last_message => :author).all
29 29 # show the board if there is only one
30 30 if @boards.size == 1
31 31 @board = @boards.first
32 32 show
33 33 end
34 34 end
35 35
36 36 def show
37 37 respond_to do |format|
38 38 format.html {
39 39 sort_init 'updated_on', 'desc'
40 40 sort_update 'created_on' => "#{Message.table_name}.created_on",
41 41 'replies' => "#{Message.table_name}.replies_count",
42 'updated_on' => "#{Message.table_name}.updated_on"
42 'updated_on' => "COALESCE(last_replies_messages.created_on, #{Message.table_name}.created_on)"
43 43
44 44 @topic_count = @board.topics.count
45 45 @topic_pages = Paginator.new @topic_count, per_page_option, params['page']
46 46 @topics = @board.topics.
47 47 reorder("#{Message.table_name}.sticky DESC").
48 includes(:author, {:last_reply => :author}).
48 includes(:last_reply).
49 49 limit(@topic_pages.items_per_page).
50 50 offset(@topic_pages.offset).
51 51 order(sort_clause).
52 preload(:author, {:last_reply => :author}).
52 53 all
53 54 @message = Message.new(:board => @board)
54 55 render :action => 'show', :layout => !request.xhr?
55 56 }
56 57 format.atom {
57 58 @messages = @board.messages.
58 59 reorder('created_on DESC').
59 60 includes(:author, :board).
60 61 limit(Setting.feeds_limit.to_i).
61 62 all
62 63 render_feed(@messages, :title => "#{@project}: #{@board}")
63 64 }
64 65 end
65 66 end
66 67
67 68 def new
68 69 @board = @project.boards.build
69 70 @board.safe_attributes = params[:board]
70 71 end
71 72
72 73 def create
73 74 @board = @project.boards.build
74 75 @board.safe_attributes = params[:board]
75 76 if @board.save
76 77 flash[:notice] = l(:notice_successful_create)
77 78 redirect_to_settings_in_projects
78 79 else
79 80 render :action => 'new'
80 81 end
81 82 end
82 83
83 84 def edit
84 85 end
85 86
86 87 def update
87 88 @board.safe_attributes = params[:board]
88 89 if @board.save
89 90 redirect_to_settings_in_projects
90 91 else
91 92 render :action => 'edit'
92 93 end
93 94 end
94 95
95 96 def destroy
96 97 @board.destroy
97 98 redirect_to_settings_in_projects
98 99 end
99 100
100 101 private
101 102 def redirect_to_settings_in_projects
102 103 redirect_to settings_project_path(@project, :tab => 'boards')
103 104 end
104 105
105 106 def find_board_if_available
106 107 @board = @project.boards.find(params[:id]) if params[:id]
107 108 rescue ActiveRecord::RecordNotFound
108 109 render_404
109 110 end
110 111 end
@@ -1,202 +1,217
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class BoardsControllerTest < ActionController::TestCase
21 21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
22 22
23 23 def setup
24 24 User.current = nil
25 25 end
26 26
27 27 def test_index
28 28 get :index, :project_id => 1
29 29 assert_response :success
30 30 assert_template 'index'
31 31 assert_not_nil assigns(:boards)
32 32 assert_not_nil assigns(:project)
33 33 end
34 34
35 35 def test_index_not_found
36 36 get :index, :project_id => 97
37 37 assert_response 404
38 38 end
39 39
40 40 def test_index_should_show_messages_if_only_one_board
41 41 Project.find(1).boards.slice(1..-1).each(&:destroy)
42 42
43 43 get :index, :project_id => 1
44 44 assert_response :success
45 45 assert_template 'show'
46 46 assert_not_nil assigns(:topics)
47 47 end
48 48
49 49 def test_show
50 50 get :show, :project_id => 1, :id => 1
51 51 assert_response :success
52 52 assert_template 'show'
53 53 assert_not_nil assigns(:board)
54 54 assert_not_nil assigns(:project)
55 55 assert_not_nil assigns(:topics)
56 56 end
57 57
58 58 def test_show_should_display_sticky_messages_first
59 59 Message.update_all(:sticky => 0)
60 60 Message.update_all({:sticky => 1}, {:id => 1})
61 61
62 62 get :show, :project_id => 1, :id => 1
63 63 assert_response :success
64 64
65 65 topics = assigns(:topics)
66 66 assert_not_nil topics
67 67 assert topics.size > 1, "topics size was #{topics.size}"
68 68 assert topics.first.sticky?
69 69 assert topics.first.updated_on < topics.second.updated_on
70 70 end
71 71
72 def test_show_should_display_message_with_last_reply_first
73 Message.update_all(:sticky => 0)
74
75 # Reply to an old topic
76 old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
77 reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
78 old_topic.children << reply
79
80 get :show, :project_id => 1, :id => 1
81 assert_response :success
82 topics = assigns(:topics)
83 assert_not_nil topics
84 assert_equal old_topic, topics.first
85 end
86
72 87 def test_show_with_permission_should_display_the_new_message_form
73 88 @request.session[:user_id] = 2
74 89 get :show, :project_id => 1, :id => 1
75 90 assert_response :success
76 91 assert_template 'show'
77 92
78 93 assert_select 'form#message-form' do
79 94 assert_select 'input[name=?]', 'message[subject]'
80 95 end
81 96 end
82 97
83 98 def test_show_atom
84 99 get :show, :project_id => 1, :id => 1, :format => 'atom'
85 100 assert_response :success
86 101 assert_template 'common/feed'
87 102 assert_not_nil assigns(:board)
88 103 assert_not_nil assigns(:project)
89 104 assert_not_nil assigns(:messages)
90 105 end
91 106
92 107 def test_show_not_found
93 108 get :index, :project_id => 1, :id => 97
94 109 assert_response 404
95 110 end
96 111
97 112 def test_new
98 113 @request.session[:user_id] = 2
99 114 get :new, :project_id => 1
100 115 assert_response :success
101 116 assert_template 'new'
102 117
103 118 assert_select 'select[name=?]', 'board[parent_id]' do
104 119 assert_select 'option', (Project.find(1).boards.size + 1)
105 120 assert_select 'option[value=]', :text => ''
106 121 assert_select 'option[value=1]', :text => 'Help'
107 122 end
108 123 end
109 124
110 125 def test_new_without_project_boards
111 126 Project.find(1).boards.delete_all
112 127 @request.session[:user_id] = 2
113 128
114 129 get :new, :project_id => 1
115 130 assert_response :success
116 131 assert_template 'new'
117 132
118 133 assert_select 'select[name=?]', 'board[parent_id]', 0
119 134 end
120 135
121 136 def test_create
122 137 @request.session[:user_id] = 2
123 138 assert_difference 'Board.count' do
124 139 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
125 140 end
126 141 assert_redirected_to '/projects/ecookbook/settings/boards'
127 142 board = Board.first(:order => 'id DESC')
128 143 assert_equal 'Testing', board.name
129 144 assert_equal 'Testing board creation', board.description
130 145 end
131 146
132 147 def test_create_with_parent
133 148 @request.session[:user_id] = 2
134 149 assert_difference 'Board.count' do
135 150 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
136 151 end
137 152 assert_redirected_to '/projects/ecookbook/settings/boards'
138 153 board = Board.first(:order => 'id DESC')
139 154 assert_equal Board.find(2), board.parent
140 155 end
141 156
142 157 def test_create_with_failure
143 158 @request.session[:user_id] = 2
144 159 assert_no_difference 'Board.count' do
145 160 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
146 161 end
147 162 assert_response :success
148 163 assert_template 'new'
149 164 end
150 165
151 166 def test_edit
152 167 @request.session[:user_id] = 2
153 168 get :edit, :project_id => 1, :id => 2
154 169 assert_response :success
155 170 assert_template 'edit'
156 171 end
157 172
158 173 def test_edit_with_parent
159 174 board = Board.generate!(:project_id => 1, :parent_id => 2)
160 175 @request.session[:user_id] = 2
161 176 get :edit, :project_id => 1, :id => board.id
162 177 assert_response :success
163 178 assert_template 'edit'
164 179
165 180 assert_select 'select[name=?]', 'board[parent_id]' do
166 181 assert_select 'option[value=2][selected=selected]'
167 182 end
168 183 end
169 184
170 185 def test_update
171 186 @request.session[:user_id] = 2
172 187 assert_no_difference 'Board.count' do
173 188 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
174 189 end
175 190 assert_redirected_to '/projects/ecookbook/settings/boards'
176 191 assert_equal 'Testing', Board.find(2).name
177 192 end
178 193
179 194 def test_update_position
180 195 @request.session[:user_id] = 2
181 196 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
182 197 assert_redirected_to '/projects/ecookbook/settings/boards'
183 198 board = Board.find(2)
184 199 assert_equal 1, board.position
185 200 end
186 201
187 202 def test_update_with_failure
188 203 @request.session[:user_id] = 2
189 204 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
190 205 assert_response :success
191 206 assert_template 'edit'
192 207 end
193 208
194 209 def test_destroy
195 210 @request.session[:user_id] = 2
196 211 assert_difference 'Board.count', -1 do
197 212 delete :destroy, :project_id => 1, :id => 2
198 213 end
199 214 assert_redirected_to '/projects/ecookbook/settings/boards'
200 215 assert_nil Board.find_by_id(2)
201 216 end
202 217 end
General Comments 0
You need to be logged in to leave comments. Login now