33feaa6c980b9ceec151dd2fb760ff54f9b2cec1.patch

Marius BALTEANU, 2021-08-06 01:52

Download (2.36 KB)

View differences:

app/controllers/issue_relations_controller.rb
56 56
      @relation.safe_attributes = params_relation
57 57
      @relation.init_journals(User.current)
58 58

  
59
      unless saved = @relation.save
60
        saved = false
61
        unsaved_relations << @relation
59
      begin
60
        saved = @relation.save
61
      rescue ActiveRecord::RecordNotUnique
62
        @relation.errors.add :base, :taken
62 63
      end
64

  
65
      unsaved_relations << @relation unless saved
63 66
    end
64 67

  
65 68
    respond_to do |format|
test/functional/issue_relations_controller_test.rb
216 216
    assert_include 'Related issue cannot be blank', response.body
217 217
  end
218 218

  
219
  def test_create_duplicated_follows_relations_should_not_raise_exception
220
    IssueRelation.create(
221
      :issue_from => Issue.find(1), :issue_to => Issue.find(2),
222
      :relation_type => IssueRelation::TYPE_PRECEDES
223
    )
224

  
225
    assert_no_difference 'IssueRelation.count' do
226
      post(
227
        :create,
228
        :params => {
229
          :issue_id => 2,
230
          :relation => {
231
            :issue_to_id => 1,
232
            :relation_type => 'follows',
233
            :delay => ''
234
          }
235
        },
236
        :xhr => true
237
      )
238
    end
239

  
240
    assert_response :success
241
    assert_include 'has already been taken', response.body
242
  end
243

  
219 244
  def test_bulk_create_with_multiple_issue_to_id_issues
220 245
    assert_difference 'IssueRelation.count', +3 do
221 246
      post :create, :params => {
222
-