feature_1005_r11061.diff

Toshi MARUYAMA, 2012-12-21 06:03

Download (5.12 KB)

View differences:

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
        value = link_to_issue(Issue.find(detail.value))
296
        label = l(detail.prop_key.to_sym)
297
      elsif detail.old_value && !detail.value
298
        old_value = link_to_issue(Issue.find(detail.old_value)) if detail.old_value
299
        label = l(detail.prop_key.to_sym)
293 300
    end
294 301
    call_hook(:helper_issues_show_detail_after_setting,
295 302
              {:detail => detail, :label => label, :value => value, :old_value => old_value })
......
339 346
        end
340 347
      when 'attachment'
341 348
        l(:text_journal_added, :label => label, :value => value).html_safe
349
      when 'relation'
350
        l(:text_journal_added, :label => label, :value => value).html_safe
342 351
      end
343 352
    else
344 353
      l(:text_journal_deleted, :label => label, :old => old_value).html_safe
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
  # property = 'relation'
186
  # prop_key = <type-of-relation> Look keys of TYPES
187
  # old_value = nil
188
  # value     = id-of-the-related-issue
189
  def create_journal_after_create
190
    journal = issue_from.init_journal(User.current)
191
    journal.details << JournalDetail.new(:property => 'relation',
192
                                         :prop_key => label_for(issue_from).to_s,
193
                                         :value    => issue_to.id)
194
    journal.save
195

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

  
204
  # property = 'relation'
205
  # prop_key = <type-of-relation> Look keys of TYPES
206
  # old_value = id-of-the-related-issue
207
  # value     = nil
208
  def create_journal_after_delete
209
    journal = issue_from.init_journal(User.current)
210
    journal.details << JournalDetail.new(:property  => 'relation',
211
                                         :prop_key  => label_for(issue_from).to_s,
212
                                         :old_value => issue_to.id)
213
    journal.save
214

  
215
    # issue-to
216
    journal = issue_to.init_journal(User.current)
217
    journal.details << JournalDetail.new(:property  => 'relation',
218
                                         :prop_key  => label_for(issue_to).to_s,
219
                                         :old_value => issue_from.id)
220
    journal.save
221
  end
182 222
end
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
1118 1118
    should "not create a journal" do
1119 1119
      copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3)
1120 1120
      copy.save!
1121
      assert_equal 0, copy.reload.journals.size
1121
      prev_journal_count = copy.journals.size
1122
      assert_equal prev_journal_count, copy.reload.journals.size
1122 1123
    end
1123 1124

  
1124 1125
    should "allow assigned_to changes" do