trunk-r11262.diff

Toshi MARUYAMA, 2013-01-25 08:25

Download (6.59 KB)

View differences:

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

  
192
    # issue-to
193
    journal = issue_to.init_journal(User.current)
194
    journal.details << JournalDetail.new(:property => 'relation',
195
                                         :prop_key => label_for(issue_to).to_s,
196
                                         :value    => issue_from.id)
197
    journal.save
198
  end
199

  
200
  def create_journal_after_delete
201
    journal = issue_from.init_journal(User.current)
202
    journal.details << JournalDetail.new(:property  => 'relation',
203
                                         :prop_key  => label_for(issue_from).to_s,
204
                                         :old_value => issue_to.id)
205
    journal.save
206

  
207
    # issue-to
208
    journal = issue_to.init_journal(User.current)
209
    journal.details << JournalDetail.new(:property  => 'relation',
210
                                         :prop_key  => label_for(issue_to).to_s,
211
                                         :old_value => issue_from.id)
212
    journal.save
213
  end
182 214
end
app/helpers/issues_helper.rb
290 290
      end
291 291
    when 'attachment'
292 292
      label = l(:label_attachment)
293
    when 'relation'
294
      if detail.value && !detail.old_value
295
        rel_issue = Issue.find_by_id(detail.value)
296
        value = rel_issue ? link_to_issue(rel_issue) : "#{l(:label_issue)} #{detail.value}"
297
        label = l(detail.prop_key.to_sym)
298
      elsif detail.old_value && !detail.value
299
        rel_issue = Issue.find_by_id(detail.old_value)
300
        old_value = rel_issue ? link_to_issue(Issue.find(rel_issue)) : "#{l(:label_issue)} #{detail.old_value}"
301
        label = l(detail.prop_key.to_sym)
302
      end
293 303
    end
294 304
    call_hook(:helper_issues_show_detail_after_setting,
295 305
              {:detail => detail, :label => label, :value => value, :old_value => old_value })
......
339 349
        end
340 350
      when 'attachment'
341 351
        l(:text_journal_added, :label => label, :value => value).html_safe
352
      when 'relation'
353
        l(:text_journal_added, :label => label, :value => value).html_safe
342 354
      end
343 355
    else
344 356
      l(:text_journal_deleted, :label => label, :old => old_value).html_safe
app/helpers/issues_helper.rb
311 311
    unless no_html
312 312
      label = content_tag('strong', label)
313 313
      old_value = content_tag("i", h(old_value)) if detail.old_value
314
      old_value = content_tag("del", old_value) if detail.old_value and detail.value.blank?
314
      if detail.old_value and detail.value.blank? and detail.property != 'relation'
315
        old_value = content_tag("del", old_value)
316
      end
315 317
      if detail.property == 'attachment' && !value.blank? && atta = Attachment.find_by_id(detail.prop_key)
316 318
        # Link to the attachment if it has not been removed
317 319
        value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
test/unit/issue_relation_test.rb
132 132
    assert !r.save
133 133
    assert_not_nil r.errors[:base]
134 134
  end
135

  
136
  def test_create_should_make_journal_entry
137
    from = Issue.find(1)
138
    to = Issue.find(2)
139
    from_journals = from.journals.size
140
    to_journals = to.journals.size
141

  
142
    relation = IssueRelation.new :issue_from => from, :issue_to => to,
143
                                 :relation_type => IssueRelation::TYPE_PRECEDES
144
    assert relation.save
145
    from.reload
146
    to.reload
147
    relation.reload
148

  
149
    assert_equal from.journals.size, (from_journals + 1)
150
    assert_equal to.journals.size, (to_journals + 1)
151
  end
152

  
153
  def test_delete_should_make_journal_entry
154
    relation = issue_relations(:issue_relation_001)
155
    id = relation.id
156
    from = relation.issue_from
157
    to   = relation.issue_to
158
    from_journals = from.journals.size
159
    to_journals   = to.journals.size
160

  
161
    assert relation.destroy
162

  
163
    from.reload
164
    to.reload
165

  
166
    assert_equal from.journals.size, (from_journals + 1)
167
    assert_equal to.journals.size, (to_journals + 1)
168
  end
135 169
end
test/unit/issue_test.rb
1137 1137
    should "not create a journal" do
1138 1138
      copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
1139 1139
      copy.save!
1140
      assert_equal 0, copy.reload.journals.size
1140
      prev_journal_count = copy.journals.size
1141
      assert_equal prev_journal_count, copy.reload.journals.size
1141 1142
    end
1142 1143

  
1143 1144
    should "allow assigned_to changes" do