@@ -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 | } |
@@ -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