Defect #7293 » activity_new_issue_event_status.patch
app/models/issue.rb (working copy) | ||
---|---|---|
30 | 30 |
has_many :journals, :as => :journalized, :dependent => :destroy |
31 | 31 |
has_many :time_entries, :dependent => :delete_all |
32 | 32 |
has_and_belongs_to_many :changesets, :order => "#{Changeset.table_name}.committed_on ASC, #{Changeset.table_name}.id ASC" |
33 |
|
|
33 |
|
|
34 | 34 |
has_many :relations_from, :class_name => 'IssueRelation', :foreign_key => 'issue_from_id', :dependent => :delete_all |
35 | 35 |
has_many :relations_to, :class_name => 'IssueRelation', :foreign_key => 'issue_to_id', :dependent => :delete_all |
36 | 36 |
|
... | ... | |
42 | 42 |
:include => [:project, :journals], |
43 | 43 |
# sort by id so that limited eager loading doesn't break with postgresql |
44 | 44 |
:order_column => "#{table_name}.id" |
45 |
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.status}): #{o.subject}"},
|
|
45 |
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id} (#{o.initial_status()}): #{o.subject}"},
|
|
46 | 46 |
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}, |
47 | 47 |
:type => Proc.new {|o| 'issue' + (o.closed? ? ' closed' : '') } |
48 | 48 |
|
... | ... | |
90 | 90 |
before_save :close_duplicates, :update_done_ratio_from_issue_status |
91 | 91 |
after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal |
92 | 92 |
after_destroy :update_parent_attributes |
93 |
|
|
93 |
|
|
94 |
# Retrieves issue's original status from journal if modified since issue creation |
|
95 |
def initial_status() |
|
96 |
|
|
97 |
status_modifications = journals.find_all { |journal| journal.new_status } |
|
98 |
status_modifications.sort! { |journal_a, journal_b| journal_a.created_on <=> journal_b.created_on } |
|
99 |
|
|
100 |
status_modifications.empty? ? self.status : status_modifications.first.prev_status |
|
101 |
end |
|
102 |
|
|
94 | 103 |
# Returns true if usr or current user is allowed to view the issue |
95 | 104 |
def visible?(usr=nil) |
96 | 105 |
(usr || User.current).allowed_to?(:view_issues, self.project) |
app/models/journal.rb (working copy) | ||
---|---|---|
48 | 48 |
c = details.detect {|detail| detail.prop_key == 'status_id'} |
49 | 49 |
(c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil |
50 | 50 |
end |
51 |
|
|
51 |
|
|
52 |
def prev_status |
|
53 |
c = details.detect {|detail| detail.prop_key == 'status_id'} |
|
54 |
(c && c.old_value) ? IssueStatus.find_by_id(c.old_value.to_i) : nil |
|
55 |
end |
|
56 |
|
|
52 | 57 |
def new_value_for(prop) |
53 | 58 |
c = details.detect {|detail| detail.prop_key == prop} |
54 | 59 |
c ? c.value : nil |
test/unit/activity_test.rb (working copy) | ||
---|---|---|
24 | 24 |
def setup |
25 | 25 |
@project = Project.find(1) |
26 | 26 |
end |
27 |
|
|
27 |
|
|
28 |
def test_activity_contains_issue_status_update_events |
|
29 |
events = find_events(User.anonymous, :project => @project) |
|
30 |
assert_not_nil events |
|
31 |
|
|
32 |
events.sort! { |x,y| x.event_datetime <=> y.event_datetime } |
|
33 |
|
|
34 |
issue_creation_events = events.find_all { |event| event == Issue.find(8) } |
|
35 |
|
|
36 |
assert_equal 1, issue_creation_events.size |
|
37 |
assert_equal IssueStatus.find_by_name('New'), issue_creation_events.first.initial_status |
|
38 |
|
|
39 |
issue_status_update_events = events.find_all { |event| event.is_a?(Journal) && event.issue == Issue.find(8) } |
|
40 |
|
|
41 |
assert_equal 2, issue_status_update_events.size |
|
42 |
assert_equal IssueStatus.find_by_name('New'), issue_status_update_events.first.prev_status |
|
43 |
assert_equal IssueStatus.find_by_name('Resolved'), issue_status_update_events.first.new_status |
|
44 |
|
|
45 |
assert_equal IssueStatus.find_by_name('Resolved'), issue_status_update_events.last.prev_status |
|
46 |
assert_equal IssueStatus.find_by_name('Closed'), issue_status_update_events.last.new_status |
|
47 |
end |
|
48 |
|
|
28 | 49 |
def test_activity_without_subprojects |
29 | 50 |
events = find_events(User.anonymous, :project => @project) |
30 | 51 |
assert_not_nil events |
test/fixtures/journal_details.yml (working copy) | ||
---|---|---|
20 | 20 |
value: "6" |
21 | 21 |
prop_key: fixed_version_id |
22 | 22 |
journal_id: 4 |
23 |
journal_details_004: |
|
24 |
old_value: "1" |
|
25 |
property: attr |
|
26 |
id: 4 |
|
27 |
value: "3" |
|
28 |
prop_key: status_id |
|
29 |
journal_id: 5 |
|
30 |
journal_details_005: |
|
31 |
old_value: "3" |
|
32 |
property: attr |
|
33 |
id: 5 |
|
34 |
value: "5" |
|
35 |
prop_key: status_id |
|
36 |
journal_id: 6 |
test/fixtures/issues.yml (working copy) | ||
---|---|---|
132 | 132 |
lft: 1 |
133 | 133 |
rgt: 2 |
134 | 134 |
issues_008: |
135 |
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
|
|
135 |
created_on: <%= 12.days.ago.to_date.to_s(:db) %>
|
|
136 | 136 |
project_id: 1 |
137 | 137 |
updated_on: <%= 10.days.ago.to_date.to_s(:db) %> |
138 | 138 |
priority_id: 5 |
test/fixtures/journals.yml (working copy) | ||
---|---|---|
27 | 27 |
journalized_type: Issue |
28 | 28 |
user_id: 1 |
29 | 29 |
journalized_id: 6 |
30 |
journals_005: |
|
31 |
created_on: <%= 11.days.ago.to_date.to_s(:db) %> |
|
32 |
notes: "Resolving issue 8." |
|
33 |
id: 5 |
|
34 |
journalized_type: Issue |
|
35 |
user_id: 1 |
|
36 |
journalized_id: 8 |
|
37 |
journals_006: |
|
38 |
created_on: <%= 10.days.ago.to_date.to_s(:db) %> |
|
39 |
notes: "Closing issue 8." |
|
40 |
id: 6 |
|
41 |
journalized_type: Issue |
|
42 |
user_id: 1 |
|
43 |
journalized_id: 8 |