0001-Fix-undefined-method-split-when-issue-to-id-is-numer.patch

Marius BALTEANU, 2021-04-07 08:06

Download (2.99 KB)

View differences:

app/controllers/issue_relations_controller.rb
107 107
  end
108 108

  
109 109
  def relation_issues_to_id
110
    params[:relation].require(:issue_to_id).split(',').reject(&:blank?)
110
    issue_to_id = params[:relation].require(:issue_to_id)
111
    case issue_to_id
112
    when String
113
      issue_to_id = issue_to_id.split(',').reject(&:blank?)
114
    when Integer
115
      issue_to_id = [issue_to_id]
116
    end
117
    issue_to_id
111 118
  rescue ActionController::ParameterMissing => e
112 119
    # We return a empty array just to loop once and return a validation error
113 120
    # ToDo: Find a better method to return an error if the param is missing.
test/integration/api_test/issue_relations_test.rb
42 42
    assert_difference('IssueRelation.count') do
43 43
      post(
44 44
        '/issues/2/relations.xml',
45
        :params => {:relation => {:issue_to_id => 7, :relation_type => 'relates'}},
45
        :params => {:relation => {:issue_to_id => "7", :relation_type => 'relates'}},
46 46
        :headers => credentials('jsmith')
47 47
      )
48 48
    end
......
57 57
    assert_select 'relation id', :text => relation.id.to_s
58 58
  end
59 59

  
60
  test "POST /issues/:issue_id/relations.json with numeric issue to id should create the relation" do
61
    assert_difference('IssueRelation.count') do
62
      post(
63
        '/issues/2/relations.json',
64
        :params => {:relation => {:issue_to_id => 7, :relation_type => 'relates'}},
65
        :headers => credentials('jsmith'),
66
        :as => :json
67
      )
68
    end
69

  
70
    relation = IssueRelation.order('id DESC').first
71
    assert_equal 2, relation.issue_from_id
72
    assert_equal 7, relation.issue_to_id
73
    assert_equal 'relates', relation.relation_type
74

  
75
    assert_response :created
76
    assert_equal 'application/json', @response.media_type
77
    json = ActiveSupport::JSON.decode(response.body)
78
    assert_equal relation.id, json['relation']['id']
79
  end
80

  
60 81
  test "POST /issues/:issue_id/relations.xml with failure should return errors" do
61 82
    assert_no_difference('IssueRelation.count') do
62 83
      post(
63
-