"attachment",
:type => :text, :name => l(:label_attachment)
)
+ add_available_filter(
+ "attachment_description",
+ :type => :text, :name => l(:label_attachment_description)
+ )
if User.current.logged?
add_available_filter(
"watcher_id",
end
end
+ def sql_for_attachment_description_field(field, operator, value)
+ cond_description = "a.description IS NOT NULL AND a.description <> ''"
+ c =
+ case operator
+ when '*', '!*'
+ (operator == '*' ? cond_description : "NOT (#{cond_description})")
+ when '~', '!~'
+ (operator == '~' ? '' : "#{cond_description} AND ") +
+ sql_contains('a.description', value.first, :match => (operator == '~'))
+ when '^', '$'
+ sql_contains('a.description', value.first, (operator == '^' ? :starts_with : :ends_with) => true)
+ else
+ '1=0'
+ end
+ "EXISTS (SELECT 1 FROM #{Attachment.table_name} a WHERE a.container_type = 'Issue' AND a.container_id = #{Issue.table_name}.id AND #{c})"
+ end
+
def sql_for_parent_id_field(field, operator, value)
case operator
when "="
assert_equal [3, 4], issues.collect(&:id).sort
end
+ def test_filter_on_attachment_description_when_any
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '*', :values => ['']}}
+ issues = find_issues_with_query(query)
+ assert_equal [2, 3, 14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_none
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '!*', :values => ['']}}
+ issues = find_issues_with_query(query)
+ assert_equal [2, 3, 4, 14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_contains
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '~', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [3, 14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_does_not_contain
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '!~', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [2], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_starts_with
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '^', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [14], issues.collect(&:id).sort
+ end
+
+ def test_filter_on_attachment_description_when_ends_with
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"attachment_description" => {:operator => '$', :values => ['attachment']}}
+ issues = find_issues_with_query(query)
+ assert_equal [3], issues.collect(&:id).sort
+ end
+
def test_filter_on_subject_when_starts_with
query = IssueQuery.new(:name => '_')
query.filters = {'subject' => {:operator => '^', :values => ['issue']}}