##// END OF EJS Templates
Merged r9350 and r9351 from trunk....
Jean-Philippe Lang -
r9218:15ff361894eb
parent child
Show More
@@ -37,7 +37,6 class Message < ActiveRecord::Base
37 :author_key => :author_id
37 :author_key => :author_id
38 acts_as_watchable
38 acts_as_watchable
39
39
40 attr_protected :locked, :sticky
41 validates_presence_of :board, :subject, :content
40 validates_presence_of :board, :subject, :content
42 validates_length_of :subject, :maximum => 255
41 validates_length_of :subject, :maximum => 255
43 validate :cannot_reply_to_locked_topic, :on => :create
42 validate :cannot_reply_to_locked_topic, :on => :create
@@ -50,7 +49,7 class Message < ActiveRecord::Base
50 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
49 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_messages, *args) } }
51
50
52 safe_attributes 'subject', 'content'
51 safe_attributes 'subject', 'content'
53 safe_attributes 'locked', 'sticky',
52 safe_attributes 'locked', 'sticky', 'board_id',
54 :if => lambda {|message, user|
53 :if => lambda {|message, user|
55 user.allowed_to?(:edit_messages, message.project)
54 user.allowed_to?(:edit_messages, message.project)
56 }
55 }
@@ -6,13 +6,17
6 <p><label for="message_subject"><%= l(:field_subject) %></label><br />
6 <p><label for="message_subject"><%= l(:field_subject) %></label><br />
7 <%= f.text_field :subject, :size => 120, :id => "message_subject" %>
7 <%= f.text_field :subject, :size => 120, :id => "message_subject" %>
8
8
9 <% if !replying && User.current.allowed_to?(:edit_messages, @project) %>
9 <% unless replying %>
10 <% if @message.safe_attribute? 'sticky' %>
10 <label><%= f.check_box :sticky %><%= l(:label_board_sticky) %></label>
11 <label><%= f.check_box :sticky %><%= l(:label_board_sticky) %></label>
12 <% end %>
13 <% if @message.safe_attribute? 'locked' %>
11 <label><%= f.check_box :locked %><%= l(:label_board_locked) %></label>
14 <label><%= f.check_box :locked %><%= l(:label_board_locked) %></label>
15 <% end %>
12 <% end %>
16 <% end %>
13 </p>
17 </p>
14
18
15 <% if !replying && !@message.new_record? && User.current.allowed_to?(:edit_messages, @project) %>
19 <% if !replying && !@message.new_record? && @message.safe_attribute?('board_id') %>
16 <p><label><%= l(:label_board) %></label><br />
20 <p><label><%= l(:label_board) %></label><br />
17 <%= f.select :board_id, @project.boards.collect {|b| [b.name, b.id]} %></p>
21 <%= f.select :board_id, @project.boards.collect {|b| [b.name, b.id]} %></p>
18 <% end %>
22 <% end %>
@@ -131,6 +131,30 class MessagesControllerTest < ActionController::TestCase
131 assert_equal 'New body', message.content
131 assert_equal 'New body', message.content
132 end
132 end
133
133
134 def test_post_edit_sticky_and_locked
135 @request.session[:user_id] = 2
136 post :edit, :board_id => 1, :id => 1,
137 :message => { :subject => 'New subject',
138 :content => 'New body',
139 :locked => '1',
140 :sticky => '1'}
141 assert_redirected_to '/boards/1/topics/1'
142 message = Message.find(1)
143 assert_equal true, message.sticky?
144 assert_equal true, message.locked?
145 end
146
147 def test_post_edit_should_allow_to_change_board
148 @request.session[:user_id] = 2
149 post :edit, :board_id => 1, :id => 1,
150 :message => { :subject => 'New subject',
151 :content => 'New body',
152 :board_id => 2}
153 assert_redirected_to '/boards/2/topics/1'
154 message = Message.find(1)
155 assert_equal Board.find(2), message.board
156 end
157
134 def test_reply
158 def test_reply
135 @request.session[:user_id] = 2
159 @request.session[:user_id] = 2
136 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
160 post :reply, :board_id => 1, :id => 1, :reply => { :content => 'This is a test reply', :subject => 'Test reply' }
General Comments 0
You need to be logged in to leave comments. Login now