summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/query.rb4
-rw-r--r--test/unit/query_test.rb22
2 files changed, 15 insertions, 11 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 104b14e89..3a30e2769 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -783,7 +783,7 @@ class Query < ActiveRecord::Base
sql = "#{db_table}.#{db_field} BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5}"
end
else
- sql = "#{db_table}.#{db_field} IN (" + value.collect{|val| "'#{self.class.connection.quote_string(val)}'"}.join(",") + ")"
+ sql = queried_class.send(:sanitize_sql_for_conditions, ["#{db_table}.#{db_field} IN (?)", value])
end
else
# IN an empty set
@@ -791,7 +791,7 @@ class Query < ActiveRecord::Base
end
when "!"
if value.any?
- sql = "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + value.collect{|val| "'#{self.class.connection.quote_string(val)}'"}.join(",") + "))"
+ sql = queried_class.send(:sanitize_sql_for_conditions, ["(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (?))", value])
else
# NOT IN an empty set
sql = "1=1"
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 22eb985c8..cb01bcba8 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -144,15 +144,14 @@ class QueryTest < ActiveSupport::TestCase
def test_query_should_allow_shared_versions_for_a_project_query
subproject_version = Version.find(4)
query = IssueQuery.new(:project => Project.find(1), :name => '_')
- query.add_filter('fixed_version_id', '=', [subproject_version.id.to_s])
-
- assert query.statement.include?("#{Issue.table_name}.fixed_version_id IN ('4')")
+ filter = query.available_filters["fixed_version_id"]
+ assert_not_nil filter
+ assert_include subproject_version.id.to_s, filter[:values].map(&:last)
end
def test_query_with_multiple_custom_fields
query = IssueQuery.find(1)
assert query.valid?
- assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
issues = find_issues_with_query(query)
assert_equal 1, issues.length
assert_equal Issue.find(3), issues.first
@@ -328,6 +327,16 @@ class QueryTest < ActiveSupport::TestCase
assert issues.map(&:id).include?(3)
end
+ def test_operator_is_on_string_custom_field_with_utf8_value
+ f = IssueCustomField.create!(:name => 'filter', :field_format => 'string', :is_filter => true, :is_for_all => true, :trackers => Tracker.all)
+ CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => 'Kiểm')
+
+ query = IssueQuery.new(:name => '_')
+ query.add_filter("cf_#{f.id}", '=', ['Kiểm'])
+ issues = find_issues_with_query(query)
+ assert_equal [1], issues.map(&:id).sort
+ end
+
def test_operator_is_on_is_private_field
# is_private filter only available for those who can set issues private
User.current = User.find(2)
@@ -1585,7 +1594,6 @@ class QueryTest < ActiveSupport::TestCase
setup_member_of_group
@query.add_filter('member_of_group', '=', [@group.id.to_s])
- assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@group.id}')"
assert_find_issues_with_query_is_successful @query
end
@@ -1593,8 +1601,6 @@ class QueryTest < ActiveSupport::TestCase
setup_member_of_group
@query.add_filter('member_of_group', '!*', [''])
- # Users not in a group
- assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IS NULL OR #{Issue.table_name}.assigned_to_id NOT IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}','#{@group.id}','#{@group2.id}')"
assert_find_issues_with_query_is_successful @query
end
@@ -1602,8 +1608,6 @@ class QueryTest < ActiveSupport::TestCase
setup_member_of_group
@query.add_filter('member_of_group', '*', [''])
- # Only users in a group
- assert_query_statement_includes @query, "#{Issue.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}','#{@group.id}','#{@group2.id}')"
assert_find_issues_with_query_is_successful @query
end