Project

General

Profile

Feature #16045 » previous-assignee-v3.patch

Mizuki ISHIKAWA, 2023-04-06 10:09

View differences:

app/helpers/application_helper.rb
646 646
    if collection.include?(User.current)
647 647
      s << content_tag('option', "<< #{l(:label_me)} >>", :value => User.current.id)
648 648
    end
649
    # do not add option in case of bulk and issue category edit
650
    unless @issue.nil?
651
      previous_assignee = @issue.previous_assigned_to
652
      s << content_tag('option', "<< #{l(:label_previous_assignee, name: previous_assignee.name)} >>", value: previous_assignee.id) if previous_assignee && previous_assignee != User.current && collection.include?(previous_assignee)
653
    end
654

  
649 655
    groups = +''
650 656
    collection.sort.each do |element|
651 657
      if option_value_selected?(element, selected) || element.id.to_s == selected
app/models/issue.rb
924 924
    result
925 925
  end
926 926

  
927
  # Returns the previous assignee from the issue history
928
  def previous_assigned_to
929
    journals.reverse_each do |j|
930
      previous_assignee_change = j.detail_for_attribute 'assigned_to_id'
931
      return User.find_by(id: previous_assignee_change.old_value.to_i) if previous_assignee_change && previous_assignee_change.old_value
932
    end
933
    nil
934
  end
935

  
927 936
  # Returns the initial status of the issue
928 937
  # Returns nil for a new issue
929 938
  def status_was
config/locales/en.yml
898 898
  label_optional: optional
899 899
  label_show_completed_versions: Show completed versions
900 900
  label_me: me
901
  label_previous_assignee: "Previous: %{name}"
901 902
  label_board: Forum
902 903
  label_board_new: New forum
903 904
  label_board_plural: Forums
test/helpers/application_helper_test.rb
2035 2035
                   principals_options_for_select(users)
2036 2036
  end
2037 2037

  
2038
  def test_principals_options_for_select_should_include_previous_assignee_option_when_previous_assignee_is_in_collection
2039
    set_language_if_valid 'en'
2040
    users = [User.find(2), User.find(3)]
2041
    @issue = Issue.generate!(assigned_to_id: 2)
2042
    @issue.init_journal(users.first, 'update')
2043
    @issue.assigned_to_id = 3
2044
    @issue.save
2045

  
2046
    # when previous assignee is not in collection
2047
    assert_not_include 'Previous:', principals_options_for_select([User.find(3)])
2048
    # when previous assignee is not in collection
2049
    assert_include '<option value="2">&lt;&lt; Previous: John Smith &gt;&gt;</option>', principals_options_for_select(users)
2050
  end
2051

  
2052
  def test_principals_options_for_select_should_include_previous_assignee_option_when_previous_assignee_is_not_current_user
2053
    set_language_if_valid 'en'
2054
    users = [User.find(2), User.find(3)]
2055
    @issue = Issue.generate!(assigned_to_id: 2)
2056
    @issue.init_journal(users.first, 'update')
2057
    @issue.assigned_to_id = 3
2058
    @issue.save
2059

  
2060
    # when previous_assignee is current user
2061
    User.current = User.find(2)
2062
    assert_not_include 'Previous:', principals_options_for_select(users)
2063
    # when previous_assignee is not current user
2064
    User.current = User.find(3)
2065
    assert_include '<option value="2">&lt;&lt; Previous: John Smith &gt;&gt;</option>', principals_options_for_select(users)
2066
  end
2067

  
2038 2068
  def test_stylesheet_link_tag_should_pick_the_default_stylesheet
2039 2069
    assert_match 'href="/stylesheets/styles.css"', stylesheet_link_tag("styles")
2040 2070
  end
test/unit/issue_test.rb
3210 3210
    assert_equal was_closed_on, issue.closed_on
3211 3211
  end
3212 3212

  
3213
  def test_previous_assigned_to
3214
    issue = Issue.generate!(assigned_to_id: 2)
3215
    issue.init_journal(User.find(2), 'update')
3216
    issue.assigned_to_id = 3
3217
    issue.save
3218

  
3219
    assert_equal User.find(2), issue.previous_assigned_to
3220
  end
3221

  
3222
  def test_previous_assigned_to_should_return_nil
3223
    issue = Issue.generate!(assigned_to_id: 2)
3224
    issue.assigned_to_id = 3
3225
    issue.save
3226

  
3227
    assert_equal 0, issue.journals.count
3228
    assert_nil issue.previous_assigned_to
3229
  end
3230

  
3213 3231
  def test_status_was_should_return_nil_for_new_issue
3214 3232
    issue = Issue.new
3215 3233
    assert_nil issue.status_was
(6-6/15)