Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juno-nishizaki authored and Redmine Patch Meetup committed Aug 21, 2021
1 parent 531fbf2 commit cdf3b9a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
1 change: 0 additions & 1 deletion app/models/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,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).
Expand Down
71 changes: 65 additions & 6 deletions test/unit/activity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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

Expand All @@ -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}}
Expand Down

0 comments on commit cdf3b9a

Please sign in to comment.