rm6118-add_parent_issue_id_filter_to_issue_query-trunk_r13697.diff

Mischa The Evil, 2015-02-13 07:19

Download (2.94 KB)

View differences:

app/models/issue_query.rb
207 207
        :values => categories.collect{|s| [s.name, s.id.to_s] }
208 208
    end
209 209

  
210
    add_available_filter "parent_id", :type => :integer, :label => 'field_parent_issue'
210 211
    add_available_filter "subject", :type => :text
211 212
    add_available_filter "created_on", :type => :date_past
212 213
    add_available_filter "updated_on", :type => :date_past
test/unit/query_test.rb
848 848
    assert_equal [issue1], find_issues_with_query(query)
849 849
  end
850 850

  
851
  def test_filter_on_parent_task_id
852
    user = User.find(2)
853
    User.current = user
854

  
855
    Issue.delete_all
856

  
857
    iparent = Issue.generate!(:subject => 'Parent')
858
    ichild1 = Issue.generate!(:project => iparent.project, :subject => 'Child1', :parent_issue_id => iparent.id)
859
    ichild2 = Issue.generate!(:project => iparent.project, :subject => 'Child2', :parent_issue_id => iparent.id)
860
    igchild = Issue.generate!(:project => iparent.project, :subject => 'Grand child', :parent_issue_id => ichild2.id)
861

  
862
    query = IssueQuery.new(:name => '_')
863

  
864
    # check if the filter is available for issue queries
865
    assert query.available_filters.key?('parent_id')
866

  
867
    # add the filter using the equal operator
868
    query.add_filter('parent_id', '=', ["#{iparent.id}"])
869

  
870
    issues = find_issues_with_query(query)
871
    assert_equal 2, issues.size
872

  
873
    # test the filter using the greater-or-equal operator
874
    query = IssueQuery.new(:name => '_')
875
    query.add_filter('parent_id', '>=', ["#{iparent.id}"])
876

  
877
    issues = find_issues_with_query(query)
878
    assert_equal 3, issues.size
879

  
880
    # test the filter using the less-or-equal operator
881
    query = IssueQuery.new(:name => '_')
882
    query.add_filter('parent_id', '<=', ["#{iparent.id}"])
883

  
884
    issues = find_issues_with_query(query)
885
    assert_equal 2, issues.size
886

  
887
    # test the filter using the between operator
888
    query = IssueQuery.new(:name => '_')
889
    query.add_filter('parent_id', '><', ["#{ichild2.id}", "#{igchild.id}"])
890

  
891
    issues = find_issues_with_query(query)
892
    assert_equal 1, issues.size
893

  
894
    # test the filter using the none operator
895
    query = IssueQuery.new(:name => '_')
896
    query.add_filter('parent_id', '!*')
897

  
898
    issues = find_issues_with_query(query)
899
    assert_equal 1, issues.size
900

  
901
    # test the filter using the any operator
902
    query = IssueQuery.new(:name => '_')
903
    query.add_filter('parent_id', '*')
904

  
905
    issues = find_issues_with_query(query)
906
    assert_equal 3, issues.size
907
  ensure
908
    Issue.delete_all
909
    User.current = nil
910
  end
911

  
851 912
  def test_statement_should_be_nil_with_no_filters
852 913
    q = IssueQuery.new(:name => '_')
853 914
    q.filters = {}