Feature #1005 » issue-1005-trunk-r11723.diff
app/models/issue_relation.rb | ||
---|---|---|
72 | 72 | |
73 | 73 |
attr_protected :issue_from_id, :issue_to_id |
74 | 74 |
before_save :handle_issue_order |
75 |
after_create :create_journal_after_create |
|
76 |
after_destroy :create_journal_after_delete |
|
75 | 77 | |
76 | 78 |
def visible?(user=User.current) |
77 | 79 |
(issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user)) |
... | ... | |
179 | 181 |
self.relation_type = TYPES[relation_type][:reverse] |
180 | 182 |
end |
181 | 183 |
end |
184 | ||
185 |
def create_journal_after_create |
|
186 |
journal = issue_from.init_journal(User.current) |
|
187 |
journal.details << JournalDetail.new(:property => 'relation', |
|
188 |
:prop_key => label_for(issue_from).to_s, |
|
189 |
:value => issue_to.id) |
|
190 |
journal.save |
|
191 |
journal = issue_to.init_journal(User.current) |
|
192 |
journal.details << JournalDetail.new(:property => 'relation', |
|
193 |
:prop_key => label_for(issue_to).to_s, |
|
194 |
:value => issue_from.id) |
|
195 |
journal.save |
|
196 |
end |
|
197 | ||
198 |
def create_journal_after_delete |
|
199 |
journal = issue_from.init_journal(User.current) |
|
200 |
journal.details << JournalDetail.new(:property => 'relation', |
|
201 |
:prop_key => label_for(issue_from).to_s, |
|
202 |
:old_value => issue_to.id) |
|
203 |
journal.save |
|
204 |
journal = issue_to.init_journal(User.current) |
|
205 |
journal.details << JournalDetail.new(:property => 'relation', |
|
206 |
:prop_key => label_for(issue_to).to_s, |
|
207 |
:old_value => issue_from.id) |
|
208 |
journal.save |
|
209 |
end |
|
182 | 210 |
end |
test/unit/issue_relation_test.rb | ||
---|---|---|
167 | 167 |
assert !r.save |
168 | 168 |
assert_not_nil r.errors[:base] |
169 | 169 |
end |
170 | ||
171 |
def test_create_should_make_journal_entry |
|
172 |
from = Issue.find(1) |
|
173 |
to = Issue.find(2) |
|
174 |
from_journals = from.journals.size |
|
175 |
to_journals = to.journals.size |
|
176 |
relation = IssueRelation.new(:issue_from => from, :issue_to => to, |
|
177 |
:relation_type => IssueRelation::TYPE_PRECEDES) |
|
178 |
assert relation.save |
|
179 |
from.reload |
|
180 |
to.reload |
|
181 |
relation.reload |
|
182 |
assert_equal from.journals.size, (from_journals + 1) |
|
183 |
assert_equal to.journals.size, (to_journals + 1) |
|
184 |
assert_equal 'relation', from.journals.last.details.last.property |
|
185 |
assert_equal 'label_precedes', from.journals.last.details.last.prop_key |
|
186 |
assert_equal '2', from.journals.last.details.last.value |
|
187 |
assert_nil from.journals.last.details.last.old_value |
|
188 |
assert_equal 'relation', to.journals.last.details.last.property |
|
189 |
assert_equal 'label_follows', to.journals.last.details.last.prop_key |
|
190 |
assert_equal '1', to.journals.last.details.last.value |
|
191 |
assert_nil to.journals.last.details.last.old_value |
|
192 |
end |
|
193 | ||
194 |
def test_delete_should_make_journal_entry |
|
195 |
relation = IssueRelation.find(1) |
|
196 |
id = relation.id |
|
197 |
from = relation.issue_from |
|
198 |
to = relation.issue_to |
|
199 |
from_journals = from.journals.size |
|
200 |
to_journals = to.journals.size |
|
201 |
assert relation.destroy |
|
202 |
from.reload |
|
203 |
to.reload |
|
204 |
assert_equal from.journals.size, (from_journals + 1) |
|
205 |
assert_equal to.journals.size, (to_journals + 1) |
|
206 |
assert_equal 'relation', from.journals.last.details.last.property |
|
207 |
assert_equal 'label_blocks', from.journals.last.details.last.prop_key |
|
208 |
assert_equal '9', from.journals.last.details.last.old_value |
|
209 |
assert_nil from.journals.last.details.last.value |
|
210 |
assert_equal 'relation', to.journals.last.details.last.property |
|
211 |
assert_equal 'label_blocked_by', to.journals.last.details.last.prop_key |
|
212 |
assert_equal '10', to.journals.last.details.last.old_value |
|
213 |
assert_nil to.journals.last.details.last.value |
|
214 |
end |
|
170 | 215 |
end |
app/helpers/issues_helper.rb | ||
---|---|---|
292 | 292 |
end |
293 | 293 |
when 'attachment' |
294 | 294 |
label = l(:label_attachment) |
295 |
when 'relation' |
|
296 |
if detail.value && !detail.old_value |
|
297 |
rel_issue = Issue.find_by_id(detail.value) |
|
298 |
value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.value}" : |
|
299 |
(no_html ? rel_issue : link_to_issue(rel_issue)) |
|
300 |
elsif detail.old_value && !detail.value |
|
301 |
rel_issue = Issue.find_by_id(detail.old_value) |
|
302 |
old_value = rel_issue.nil? ? "#{l(:label_issue)} #{detail.old_value}" : |
|
303 |
(no_html ? rel_issue : link_to_issue(rel_issue)) |
|
304 |
end |
|
305 |
label = l(detail.prop_key.to_sym) |
|
295 | 306 |
end |
296 | 307 |
call_hook(:helper_issues_show_detail_after_setting, |
297 | 308 |
{:detail => detail, :label => label, :value => value, :old_value => old_value }) |
... | ... | |
339 | 350 |
else |
340 | 351 |
l(:text_journal_set_to, :label => label, :value => value).html_safe |
341 | 352 |
end |
342 |
when 'attachment' |
|
353 |
when 'attachment', 'relation'
|
|
343 | 354 |
l(:text_journal_added, :label => label, :value => value).html_safe |
344 | 355 |
end |
345 | 356 |
else |
test/unit/helpers/issues_helper_test.rb | ||
---|---|---|
209 | 209 |
:old_value => 'error281.txt', :value => nil) |
210 | 210 |
assert_match 'error281.txt', show_detail(detail, true) |
211 | 211 |
end |
212 | ||
213 |
def test_show_detail_create_relation |
|
214 |
detail = JournalDetail.new(:property => 'relation', |
|
215 |
:prop_key => 'label_precedes', |
|
216 |
:value => 1) |
|
217 |
assert_equal "Precedes Bug #1: Can't print recipes added", show_detail(detail, true) |
|
218 |
assert_match %r{<strong>Precedes</strong> <i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i> added}, |
|
219 |
show_detail(detail, false) |
|
220 |
non_existed_issue_number = 9999 |
|
221 |
assert_nil Issue.find_by_id(non_existed_issue_number) |
|
222 |
detail = JournalDetail.new(:property => 'relation', |
|
223 |
:prop_key => 'label_precedes', |
|
224 |
:value => non_existed_issue_number) |
|
225 |
assert_equal "Precedes Issue #{non_existed_issue_number} added", show_detail(detail, true) |
|
226 |
assert_equal "<strong>Precedes</strong> <i>Issue #{non_existed_issue_number}</i> added", show_detail(detail, false) |
|
227 |
end |
|
228 | ||
229 |
def test_show_detail_delete_relation |
|
230 |
detail = JournalDetail.new(:property => 'relation', |
|
231 |
:prop_key => 'label_precedes', |
|
232 |
:old_value => 1) |
|
233 |
assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true) |
|
234 |
assert_match %r{<strong>Precedes</strong> deleted \(<del><i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i></del>\)}, |
|
235 |
show_detail(detail, false) |
|
236 |
non_existed_issue_number = 9999 |
|
237 |
assert_nil Issue.find_by_id(non_existed_issue_number) |
|
238 |
detail = JournalDetail.new(:property => 'relation', |
|
239 |
:prop_key => 'label_precedes', |
|
240 |
:old_value => non_existed_issue_number) |
|
241 |
assert_equal "Precedes deleted (Issue 9999)", show_detail(detail, true) |
|
242 |
assert_equal "<strong>Precedes</strong> deleted (<del><i>Issue 9999</i></del>)", show_detail(detail, false) |
|
243 |
end |
|
212 | 244 |
end |
app/helpers/issues_helper.rb | ||
---|---|---|
314 | 314 |
unless no_html |
315 | 315 |
label = content_tag('strong', label) |
316 | 316 |
old_value = content_tag("i", h(old_value)) if detail.old_value |
317 |
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank? |
|
317 |
if detail.old_value && detail.value.blank? && detail.property != 'relation' |
|
318 |
old_value = content_tag("del", old_value) |
|
319 |
end |
|
318 | 320 |
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key) |
319 | 321 |
# Link to the attachment if it has not been removed |
320 | 322 |
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path]) |
test/unit/helpers/issues_helper_test.rb | ||
---|---|---|
231 | 231 |
:prop_key => 'label_precedes', |
232 | 232 |
:old_value => 1) |
233 | 233 |
assert_equal "Precedes deleted (Bug #1: Can't print recipes)", show_detail(detail, true) |
234 |
assert_match %r{<strong>Precedes</strong> deleted \(<del><i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i></del>\)},
|
|
234 |
assert_match %r{<strong>Precedes</strong> deleted \(<i><a href="/issues/1" class=".+">Bug #1</a>: Can't print recipes</i>\)},
|
|
235 | 235 |
show_detail(detail, false) |
236 | 236 |
non_existed_issue_number = 9999 |
237 | 237 |
assert_nil Issue.find_by_id(non_existed_issue_number) |
... | ... | |
239 | 239 |
:prop_key => 'label_precedes', |
240 | 240 |
:old_value => non_existed_issue_number) |
241 | 241 |
assert_equal "Precedes deleted (Issue 9999)", show_detail(detail, true) |
242 |
assert_equal "<strong>Precedes</strong> deleted (<del><i>Issue 9999</i></del>)", show_detail(detail, false)
|
|
242 |
assert_equal "<strong>Precedes</strong> deleted (<i>Issue 9999</i>)", show_detail(detail, false)
|
|
243 | 243 |
end |
244 | 244 |
end |
- « Previous
- 1
- …
- 7
- 8
- 9
- Next »