Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #15 from tomykaira/fix_failure

Fix test failure. Thanks @tomykaira
  • Loading branch information...
commit 2677a38d5b9260eaa614e423858871813556762b 2 parents 59d2f63 + e3ac438
@tokumine authored
Showing with 41 additions and 12 deletions.
  1. +38 −11 lib/fusion_tables/data/table.rb
  2. +3 −1 test/test_ext.rb
View
49 lib/fusion_tables/data/table.rb
@@ -111,21 +111,12 @@ def encode data
data.inject([]) do |ar,h|
ret = {}
h.each do |key, value|
- if value.nil?
- #empty string for nils
- ret["'#{key.to_s}'"] = "''"
- else
- ret["'#{key.to_s}'"] = case get_datatype(key)
- when "number", "location" then "#{value}"
- when "datetime" then "'#{value.strftime("%m-%d-%Y %H:%M:%S")}'"
- else "'#{value.gsub(/\\/, '\&\&').gsub(/'/, "''")}'"
- end
- end
+ ret["'#{key}'"] = encode_value(get_datatype(key), value)
end
ar << ret
ar
end
- end
+ end
#
# Returns datatype of given column name
@@ -138,6 +129,42 @@ def get_datatype column_name
end
raise ArgumentError, "The column doesn't exist"
end
+
+ private
+ def encode_value_as_numeric(value)
+ value.to_s
+ end
+
+ def encode_value_as_datetime(value)
+ encode_value_as_string(value.strftime("%m-%d-%Y %H:%M:%S"))
+ end
+
+ def encode_value_as_string(value)
+ quoted = value.to_s.gsub(/\\/, '\&\&').gsub(/'/, "''")
+ "'#{quoted}'"
+ end
+
+ def encode_value type, value
+ if value.nil?
+ #empty string for nils
+ "''"
+ else
+ case type
+ when "number"
+ encode_value_as_numeric(value)
+ when "datetime"
+ encode_value_as_datetime(value)
+ when "location"
+ if value.is_a?(Numeric)
+ encode_value_as_numeric(value)
+ else
+ encode_value_as_string(value)
+ end
+ else
+ encode_value_as_string(value)
+ end
+ end
+ end
end
end
end
View
4 test/test_ext.rb
@@ -51,7 +51,9 @@ class TestExt < Test::Unit::TestCase
end
should "return zero if passed a silly id" do
- assert_equal 0, @ft.drop(235243875629384756)
+ assert_raise GData::Client::BadRequestError do
+ assert_equal 0, @ft.drop(235243875629384756)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.