Project

General

Profile

Feature #1005 » trunk-r11262.diff

Toshi MARUYAMA, 2013-01-25 08:25

View differences:

app/models/issue_relation.rb
attr_protected :issue_from_id, :issue_to_id
before_save :handle_issue_order
after_create :create_journal_after_create
after_destroy :create_journal_after_delete
def visible?(user=User.current)
(issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user))
......
self.relation_type = TYPES[relation_type][:reverse]
end
end
def create_journal_after_create
journal = issue_from.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_from).to_s,
:value => issue_to.id)
journal.save
# issue-to
journal = issue_to.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_to).to_s,
:value => issue_from.id)
journal.save
end
def create_journal_after_delete
journal = issue_from.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_from).to_s,
:old_value => issue_to.id)
journal.save
# issue-to
journal = issue_to.init_journal(User.current)
journal.details << JournalDetail.new(:property => 'relation',
:prop_key => label_for(issue_to).to_s,
:old_value => issue_from.id)
journal.save
end
end
app/helpers/issues_helper.rb
end
when 'attachment'
label = l(:label_attachment)
when 'relation'
if detail.value && !detail.old_value
rel_issue = Issue.find_by_id(detail.value)
value = rel_issue ? link_to_issue(rel_issue) : "#{l(:label_issue)} #{detail.value}"
label = l(detail.prop_key.to_sym)
elsif detail.old_value && !detail.value
rel_issue = Issue.find_by_id(detail.old_value)
old_value = rel_issue ? link_to_issue(Issue.find(rel_issue)) : "#{l(:label_issue)} #{detail.old_value}"
label = l(detail.prop_key.to_sym)
end
end
call_hook(:helper_issues_show_detail_after_setting,
{:detail => detail, :label => label, :value => value, :old_value => old_value })
......
end
when 'attachment'
l(:text_journal_added, :label => label, :value => value).html_safe
when 'relation'
l(:text_journal_added, :label => label, :value => value).html_safe
end
else
l(:text_journal_deleted, :label => label, :old => old_value).html_safe
app/helpers/issues_helper.rb
unless no_html
label = content_tag('strong', label)
old_value = content_tag("i", h(old_value)) if detail.old_value
old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
if detail.old_value and detail.value.blank? and detail.property != 'relation'
old_value = content_tag("del", old_value)
end
if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
# Link to the attachment if it has not been removed
value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
test/unit/issue_relation_test.rb
assert !r.save
assert_not_nil r.errors[:base]
end
def test_create_should_make_journal_entry
from = Issue.find(1)
to = Issue.find(2)
from_journals = from.journals.size
to_journals = to.journals.size
relation = IssueRelation.new :issue_from => from, :issue_to => to,
:relation_type => IssueRelation::TYPE_PRECEDES
assert relation.save
from.reload
to.reload
relation.reload
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
end
def test_delete_should_make_journal_entry
relation = issue_relations(:issue_relation_001)
id = relation.id
from = relation.issue_from
to = relation.issue_to
from_journals = from.journals.size
to_journals = to.journals.size
assert relation.destroy
from.reload
to.reload
assert_equal from.journals.size, (from_journals + 1)
assert_equal to.journals.size, (to_journals + 1)
end
end
test/unit/issue_test.rb
should "not create a journal" do
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
copy.save!
assert_equal 0, copy.reload.journals.size
prev_journal_count = copy.journals.size
assert_equal prev_journal_count, copy.reload.journals.size
end
should "allow assigned_to changes" do
(7-7/9)