Feature #1005 » feature_1005_1.diff
test/unit/issue_relation_test.rb (working copy) | ||
---|---|---|
104 | 104 |
assert !r.save |
105 | 105 |
assert_not_nil r.errors[:base] |
106 | 106 |
end |
107 |
|
|
108 |
def test_create_should_make_journal_entry |
|
109 |
from = Issue.find(1) |
|
110 |
to = Issue.find(2) |
|
111 |
from_journals = from.journals.size |
|
112 |
to_journals = to.journals.size |
|
113 | ||
114 |
relation = IssueRelation.new :issue_from => from, :issue_to => to, |
|
115 |
:relation_type => IssueRelation::TYPE_PRECEDES |
|
116 |
assert relation.save |
|
117 |
from.reload |
|
118 |
to.reload |
|
119 |
relation.reload |
|
120 | ||
121 |
assert_equal from.journals.size, (from_journals + 1) |
|
122 |
assert_equal to.journals.size, (to_journals + 1) |
|
123 |
end |
|
124 | ||
125 |
def test_delete_should_make_journal_entry |
|
126 |
relation = issue_relations(:issue_relation_001) |
|
127 |
id = relation.id |
|
128 |
from = relation.issue_from |
|
129 |
to = relation.issue_to |
|
130 |
from_journals = from.journals.size |
|
131 |
to_journals = to.journals.size |
|
132 | ||
133 |
assert relation.destroy |
|
134 | ||
135 |
from.reload |
|
136 |
to.reload |
|
137 | ||
138 |
assert_equal from.journals.size, (from_journals + 1) |
|
139 |
assert_equal to.journals.size, (to_journals + 1) |
|
140 |
end |
|
107 | 141 |
end |
test/unit/issue_test.rb (working copy) | ||
---|---|---|
641 | 641 |
should "not create a journal" do |
642 | 642 |
copy = @issue.copy(:project_id => 3, :tracker_id => 2, :assigned_to_id => 3) |
643 | 643 |
copy.save! |
644 |
assert_equal 0, copy.reload.journals.size |
|
644 |
prev_journal_count = copy.journals.size |
|
645 |
assert_equal prev_journal_count, copy.reload.journals.size |
|
645 | 646 |
end |
646 | 647 | |
647 | 648 |
should "allow assigned_to changes" do |
app/helpers/issues_helper.rb (working copy) | ||
---|---|---|
236 | 236 |
end |
237 | 237 |
when 'attachment' |
238 | 238 |
label = l(:label_attachment) |
239 |
when 'relation' |
|
240 |
if detail.value && !detail.old_value |
|
241 |
value = link_to_issue(Issue.find(detail.value)) |
|
242 |
label = l(detail.prop_key.to_sym) |
|
243 |
elsif detail.old_value && !detail.value |
|
244 |
old_value = link_to_issue(Issue.find(detail.old_value)) if detail.old_value |
|
245 |
label = l(detail.prop_key.to_sym) |
|
246 |
end |
|
239 | 247 |
end |
248 | ||
240 | 249 |
call_hook(:helper_issues_show_detail_after_setting, |
241 | 250 |
{:detail => detail, :label => label, :value => value, :old_value => old_value }) |
242 | 251 | |
... | ... | |
277 | 286 |
end |
278 | 287 |
when 'attachment' |
279 | 288 |
l(:text_journal_added, :label => label, :value => value).html_safe |
289 |
when 'relation' |
|
290 |
l(:text_journal_added, :label => label, :value => value).html_safe |
|
280 | 291 |
end |
281 | 292 |
else |
282 | 293 |
l(:text_journal_deleted, :label => label, :old => old_value).html_safe |
app/models/issue_relation.rb (working copy) | ||
---|---|---|
45 | 45 | |
46 | 46 |
attr_protected :issue_from_id, :issue_to_id |
47 | 47 | |
48 |
before_save :handle_issue_order |
|
48 |
before_save :handle_issue_order |
|
49 |
after_create :create_journal_after_create |
|
50 |
after_destroy :create_journal_after_delete |
|
49 | 51 | |
50 | 52 |
def visible?(user=User.current) |
51 | 53 |
(issue_from.nil? || issue_from.visible?(user)) && (issue_to.nil? || issue_to.visible?(user)) |
... | ... | |
140 | 142 |
self.relation_type = TYPES[relation_type][:reverse] |
141 | 143 |
end |
142 | 144 |
end |
145 | ||
146 |
# property = 'relation' |
|
147 |
# prop_key = <type-of-relation> Look keys of TYPES |
|
148 |
# old_value = nil |
|
149 |
# value = id-of-the-related-issue |
|
150 |
def create_journal_after_create |
|
151 |
journal = issue_from.init_journal(User.current) |
|
152 |
journal.details << JournalDetail.new(:property => 'relation', |
|
153 |
:prop_key => label_for(issue_from).to_s, |
|
154 |
:value => issue_to.id |
|
155 |
) |
|
156 |
journal.save |
|
157 | ||
158 |
# issue-to |
|
159 |
journal = issue_to.init_journal(User.current) |
|
160 |
journal.details << JournalDetail.new(:property => 'relation', |
|
161 |
:prop_key => label_for(issue_to).to_s, |
|
162 |
:value => issue_from.id |
|
163 |
) |
|
164 |
journal.save |
|
165 |
end |
|
166 | ||
167 |
# property = 'relation' |
|
168 |
# prop_key = <type-of-relation> Look keys of TYPES |
|
169 |
# old_value = id-of-the-related-issue |
|
170 |
# value = nil |
|
171 |
def create_journal_after_delete |
|
172 |
journal = issue_from.init_journal(User.current) |
|
173 |
journal.details << JournalDetail.new(:property => 'relation', |
|
174 |
:prop_key => label_for(issue_from).to_s, |
|
175 |
:old_value => issue_to.id |
|
176 |
) |
|
177 |
journal.save |
|
178 | ||
179 |
# issue-to |
|
180 |
journal = issue_to.init_journal(User.current) |
|
181 |
journal.details << JournalDetail.new(:property => 'relation', |
|
182 |
:prop_key => label_for(issue_to).to_s, |
|
183 |
:old_value => issue_from.id |
|
184 |
) |
|
185 |
journal.save |
|
186 |
end |
|
143 | 187 |
end |