diff --git a/app/models/issue.rb b/app/models/issue.rb index 10d028a63..92fbad208 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1454,7 +1454,6 @@ def css_classes(user=User.current) end # Retrieves issue's original status from journal if modified since issue creation - # TODO: 書けそうだったらissue_test.rbにテスト追加 def event_status changed_statuses = JournalDetail.joins("LEFT OUTER JOIN #{Journal.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id"). where("#{Journal.table_name}.journalized_id = ? AND #{Journal.table_name}.journalized_type = 'Issue' AND #{JournalDetail.table_name}.prop_key = 'status_id'", self.id). diff --git a/test/unit/activity_test.rb b/test/unit/activity_test.rb index 8c61d8e67..9137815a3 100644 --- a/test/unit/activity_test.rb +++ b/test/unit/activity_test.rb @@ -134,18 +134,18 @@ def test_event_group_for_wiki_content_version def test_activity_contains_issue_status_update_events issue = Issue.generate!(:status_id => 1) - + events = find_events(User.anonymous, :project => @project) target_issue_events = events.find_all { |event| event == issue || (event.is_a?(Journal) && event.issue == issue ) } target_issue_events.sort! { |x, y| x.event_datetime <=> y.event_datetime } event_titles = target_issue_events.map{ |e| e.event_title } assert_equal("Bug ##{issue.id} (New): Generated", event_titles[0], "event title should includes (New)") - + issue = Issue.find(issue.id) - issue.init_journal(User.first, "Assign") + issue.init_journal(User.first) issue.status_id = 2 assert issue.save - + events = find_events(User.anonymous, :project => @project) target_issue_events = events.find_all { |event| event == issue || (event.is_a?(Journal) && event.issue == issue ) } target_issue_events.sort! { |x, y| x.event_datetime <=> y.event_datetime } @@ -154,7 +154,7 @@ def test_activity_contains_issue_status_update_events assert_equal("Bug ##{issue.id} (Assigned): Generated", event_titles[1], "event title should includes (Assinged)") issue = Issue.find(issue.id) - issue.init_journal(User.first, "Resolve") + issue.init_journal(User.first) issue.status_id = 3 assert issue.save @@ -165,9 +165,68 @@ def test_activity_contains_issue_status_update_events assert_equal("Bug ##{issue.id} (New): Generated", event_titles[0], "event title should includes (New)") assert_equal("Bug ##{issue.id} (Assigned): Generated", event_titles[1], "event title should includes (Assinged)") assert_equal("Bug ##{issue.id} (Resolved): Generated", event_titles[2], "event title should includes (Resolved)") - end + def test_activity_contains_issue_status_update_events2 + # ステータス以外(サブジェクト)を変更後、ステータスを変更する + # ステータス以外(サブジェクト)とステータスを一度に変更する + + issue = Issue.generate!(:status_id => 1, :subject => "Generated") + + issue = Issue.find(issue.id) + issue.init_journal(User.first) + issue.subject = "Activity test" + assert issue.save + + issue = Issue.find(issue.id) + issue.init_journal(User.first) + issue.status_id = 3 + assert issue.save + + events = find_events(User.anonymous, :project => @project) + target_issue_events = events.find_all { |event| event == issue || (event.is_a?(Journal) && event.issue == issue ) } + target_issue_events.sort! { |x, y| x.event_datetime <=> y.event_datetime } + event_titles = target_issue_events.map{ |e| e.event_title } + assert_equal("Bug ##{issue.id} (New): Activity test", event_titles[0], "event title should includes (New)") + assert_equal("Bug ##{issue.id} (Resolved): Activity test", event_titles[1], "event title should includes (Resolved)") + + issue = Issue.find(issue.id) + issue.init_journal(User.first, "Close") + issue.subject = "Closing test" + issue.status_id = 5 + assert issue.save + + events = find_events(User.anonymous, :project => @project) + target_issue_events = events.find_all { |event| event == issue || (event.is_a?(Journal) && event.issue == issue ) } + target_issue_events.sort! { |x, y| x.event_datetime <=> y.event_datetime } + event_titles = target_issue_events.map{ |e| e.event_title } + assert_equal("Bug ##{issue.id} (New): Closing test", event_titles[0], "event title should includes (New)") + assert_equal("Bug ##{issue.id} (Resolved): Closing test", event_titles[1], "event title should includes (Resolved)") + assert_equal("Bug ##{issue.id} (Closed): Closing test", event_titles[2], "event title should includes (Closed)") + end + + def test_activity_contains_issue_status_update_events3 + # コメントを追記後、ステータスを変更する + issue = Issue.generate!(:status_id => 1, :subject => "Generated") + + issue = Issue.find(issue.id) + issue.init_journal(User.first, "note") + assert issue.save + + issue = Issue.find(issue.id) + issue.init_journal(User.first) + issue.status_id = 3 + assert issue.save + + events = find_events(User.anonymous, :project => @project) + target_issue_events = events.find_all { |event| event == issue || (event.is_a?(Journal) && event.issue == issue ) } + target_issue_events.sort! { |x, y| x.event_datetime <=> y.event_datetime } + event_titles = target_issue_events.map{ |e| e.event_title } + assert_equal("Bug ##{issue.id} (New): Generated", event_titles[0], "event title should includes (New)") + assert_equal("Bug ##{issue.id}: Generated", event_titles[1], "event title should not include status") + assert_equal("Bug ##{issue.id} (Resolved): Generated", event_titles[2], "event title should includes (Resolved)") + end + class TestActivityProviderWithPermission def self.activity_provider_options {'test' => {:permission => :custom_permission}}