FIX: Date class encoding

FIX: Date class encoding

Previously we had attempted to call .utc on Date objects, that do not exist.

diff --git a/lib/mini_sql/inline_param_encoder.rb b/lib/mini_sql/inline_param_encoder.rb
index 8a4a3cc..b200de1 100644
--- a/lib/mini_sql/inline_param_encoder.rb
+++ b/lib/mini_sql/inline_param_encoder.rb
@@ -36,13 +36,13 @@ module MiniSql
 
     def encode_array(sql, array)
       i = -1
-      sql.gsub("?") do |p|
+      sql.gsub("?") do
         i += 1
         quote_val(array[i])
       end
     end
 
-    def quoted_date(value)
+    def quoted_time(value)
       value.utc.iso8601
     end
 
@@ -51,7 +51,8 @@ module MiniSql
       when String     then "'#{conn.escape_string(value.to_s)}'"
       when Numeric    then value.to_s
       when BigDecimal then value.to_s("F")
-      when Date, Time then "'#{quoted_date(value)}'"
+      when Time       then "'#{quoted_time(value)}'"
+      when Date       then "'#{value.to_s}'"
       when Symbol     then "'#{conn.escape_string(value.to_s)}'"
       when true       then "true"
       when false      then "false"
diff --git a/test/mini_sql/inline_param_encoder_test.rb b/test/mini_sql/inline_param_encoder_test.rb
index 348d930..4a37643 100644
--- a/test/mini_sql/inline_param_encoder_test.rb
+++ b/test/mini_sql/inline_param_encoder_test.rb
@@ -45,5 +45,11 @@ module MiniSql
       result = @encoder.encode("select 1,?,?", "a", 2)
       assert_equal("select 1,'a',2", result)
     end
+
+    def test_encode_dates
+      t = Date.parse('2010-10-01')
+      result = @encoder.encode("select :t", t: t)
+      assert_equal("select '2010-10-01'", result)
+    end
   end
 end

GitHub sha: bae9ec8d

This commit appears in #28 which was merged by SamSaffron.