From 99ec0209fd80a376c07d09c0bd5075733449ef9a Mon Sep 17 00:00:00 2001 From: Georg Ledermann Date: Fri, 28 Dec 2012 11:22:03 +0100 Subject: [PATCH] DataTable: Accept BigDecimal as number --- lib/google_visualr/data_table.rb | 2 +- spec/google_visualr/data_table_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/google_visualr/data_table.rb b/lib/google_visualr/data_table.rb index f459d22..e251498 100644 --- a/lib/google_visualr/data_table.rb +++ b/lib/google_visualr/data_table.rb @@ -243,7 +243,7 @@ def verify_against_column_type(type, value) when type == "string" raise ArgumentError, "cell value '#{v}' is not a String", caller unless v.is_a?(String) when type == "number" - raise ArgumentError, "cell value '#{v}' is not an Integer or a Float", caller unless v.is_a?(Integer) || v.is_a?(Float) + raise ArgumentError, "cell value '#{v}' is not an Integer, Float or BigDecimal", caller unless v.is_a?(Integer) || v.is_a?(Float) || v.is_a?(BigDecimal) when type == "boolean" raise ArgumentError, "cell value '#{v}' is not a Boolean", caller unless v.is_a?(TrueClass) || v.is_a?(FalseClass) when type == 'datetime' diff --git a/spec/google_visualr/data_table_spec.rb b/spec/google_visualr/data_table_spec.rb index 8f18d2d..bfdcbfb 100644 --- a/spec/google_visualr/data_table_spec.rb +++ b/spec/google_visualr/data_table_spec.rb @@ -205,6 +205,12 @@ def assert_raises_exception(col, value) it "raises an exception if value is not date" do assert_raises_exception(4, 'ABCD') end + + it "accepts BigDecimal as number" do + expect { + dt.set_cell(0, 1, BigDecimal.new(42)) + }.to_not raise_exception(ArgumentError) + end end it "accepts 'nil' for all column types" do