31879_add_filter_operators_attachment.patch

Yuichi HARADA, 2019-09-30 10:20

Download (1.77 KB)

View differences:

app/models/issue_query.rb
526 526
      c = sql_contains("a.filename", value.first)
527 527
      e = (operator == "~" ? "EXISTS" : "NOT EXISTS")
528 528
      "#{e} (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
529
    when "^", "$"
530
      c = sql_contains("a.filename", value.first, (operator == "^" ? :starts_with : :ends_with) => true)
531
      "EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
529 532
    end
530 533
  end
531 534

  
test/unit/query_test.rb
1353 1353
    assert_nil issues.detect {|issue| issue.attachments.any? {|attachment| attachment.filename.include?('error281')}}
1354 1354
  end
1355 1355

  
1356
  def test_filter_on_attachment_when_starts_with
1357
    query = IssueQuery.new(:name => '_')
1358
    query.filters = {"attachment" => {:operator => '^', :values =>  ['testfile']}}
1359
    issues = find_issues_with_query(query)
1360
    assert_equal [14], issues.collect(&:id).sort
1361
  end
1362

  
1363
  def test_filter_on_attachment_when_ends_with
1364
    query = IssueQuery.new(:name => '_')
1365
    query.filters = {"attachment" => {:operator => '$', :values =>  ['zip']}}
1366
    issues = find_issues_with_query(query)
1367
    assert_equal [3, 4], issues.collect(&:id).sort
1368
  end
1369

  
1356 1370
  def test_filter_on_subject_when_starts_with
1357 1371
    query = IssueQuery.new(:name => '_')
1358 1372
    query.filters = {'subject' => {:operator => '^', :values => ['issue']}}