From c3b91d6f04432811d7535b301d891498b907f7be Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 8 Feb 2015 16:01:20 +0000 Subject: [PATCH] Fixed assertions for SQLServer that format dates with MM/DD/YYYY in queries. git-svn-id: http://svn.redmine.org/redmine/trunk@13992 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- test/test_helper.rb | 5 +++++ test/unit/query_test.rb | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 63159ad9a..d163c10b2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -173,6 +173,11 @@ class ActiveSupport::TestCase ActiveRecord::Base.connection.adapter_name =~ /postgresql/i end + def quoted_date(date) + date = Date.parse(date) if date.is_a?(String) + ActiveRecord::Base.connection.quoted_date(date) + end + def assert_save(object) saved = object.save message = "#{object.class} could not be saved" diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 3468c9cbf..fdddba8cc 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -453,42 +453,44 @@ class QueryTest < ActiveSupport::TestCase def test_operator_date_equals query = IssueQuery.new(:name => '_') query.add_filter('due_date', '=', ['2011-07-10']) - assert_match /issues\.due_date > '2011-07-09 23:59:59(\.9+)?' AND issues\.due_date <= '2011-07-10 23:59:59(\.9+)?/, query.statement + assert_match /issues\.due_date > '#{quoted_date "2011-07-09"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-07-10"} 23:59:59(\.\d+)?/, + query.statement find_issues_with_query(query) end def test_operator_date_lesser_than query = IssueQuery.new(:name => '_') query.add_filter('due_date', '<=', ['2011-07-10']) - assert_match /issues\.due_date <= '2011-07-10 23:59:59(\.9+)?/, query.statement + assert_match /issues\.due_date <= '#{quoted_date "2011-07-10"} 23:59:59(\.\d+)?/, query.statement find_issues_with_query(query) end def test_operator_date_lesser_than_with_timestamp query = IssueQuery.new(:name => '_') query.add_filter('updated_on', '<=', ['2011-07-10T19:13:52']) - assert_match /issues\.updated_on <= '2011-07-10 19:13:52/, query.statement + assert_match /issues\.updated_on <= '#{quoted_date "2011-07-10"} 19:13:52/, query.statement find_issues_with_query(query) end def test_operator_date_greater_than query = IssueQuery.new(:name => '_') query.add_filter('due_date', '>=', ['2011-07-10']) - assert_match /issues\.due_date > '2011-07-09 23:59:59(\.9+)?'/, query.statement + assert_match /issues\.due_date > '#{quoted_date "2011-07-09"} 23:59:59(\.\d+)?'/, query.statement find_issues_with_query(query) end def test_operator_date_greater_than_with_timestamp query = IssueQuery.new(:name => '_') query.add_filter('updated_on', '>=', ['2011-07-10T19:13:52']) - assert_match /issues\.updated_on > '2011-07-10 19:13:51(\.0+)?'/, query.statement + assert_match /issues\.updated_on > '#{quoted_date "2011-07-10"} 19:13:51(\.0+)?'/, query.statement find_issues_with_query(query) end def test_operator_date_between query = IssueQuery.new(:name => '_') query.add_filter('due_date', '><', ['2011-06-23', '2011-07-10']) - assert_match /issues\.due_date > '2011-06-22 23:59:59(\.9+)?' AND issues\.due_date <= '2011-07-10 23:59:59(\.9+)?'/, query.statement + assert_match /issues\.due_date > '#{quoted_date "2011-06-22"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-07-10"} 23:59:59(\.\d+)?'/, + query.statement find_issues_with_query(query) end @@ -606,7 +608,8 @@ class QueryTest < ActiveSupport::TestCase query = IssueQuery.new(:project => Project.find(1), :name => '_') query.add_filter('due_date', 'w', ['']) - assert query.statement.match(/issues\.due_date > '2011-04-24 23:59:59(\.9+)?' AND issues\.due_date <= '2011-05-01 23:59:59(\.9+)?/), "range not found in #{query.statement}" + assert_match /issues\.due_date > '#{quoted_date "2011-04-24"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-05-01"} 23:59:59(\.\d+)?/, + query.statement I18n.locale = :en end @@ -618,7 +621,8 @@ class QueryTest < ActiveSupport::TestCase query = IssueQuery.new(:project => Project.find(1), :name => '_') query.add_filter('due_date', 'w', ['']) - assert query.statement.match(/issues\.due_date > '2011-04-23 23:59:59(\.9+)?' AND issues\.due_date <= '2011-04-30 23:59:59(\.9+)?/), "range not found in #{query.statement}" + assert_match /issues\.due_date > '#{quoted_date "2011-04-23"} 23:59:59(\.\d+)?' AND issues\.due_date <= '#{quoted_date "2011-04-30"} 23:59:59(\.\d+)?/, + query.statement end def test_operator_does_not_contains -- 2.39.5