google_visualr 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock
CHANGED
@@ -238,12 +238,12 @@ module GoogleVisualr
|
|
238
238
|
raise ArgumentError, "cell value '#{v}' is not a String", caller unless v.is_a?(String)
|
239
239
|
when type == "number"
|
240
240
|
raise ArgumentError, "cell value '#{v}' is not an Integer or a Float", caller unless v.is_a?(Integer) || v.is_a?(Float)
|
241
|
-
when type == "date"
|
242
|
-
raise ArgumentError, "cell value '#{v}' is not a Date", caller unless v.is_a?(Date)
|
243
|
-
when type == 'datetime'
|
244
|
-
raise ArgumentError, "cell value '#{v}' is not a DateTime", caller unless v.is_a?(DateTime)
|
245
241
|
when type == "boolean"
|
246
242
|
raise ArgumentError, "cell value '#{v}' is not a Boolean", caller unless v.is_a?(TrueClass) || v.is_a?(FalseClass)
|
243
|
+
when type == 'datetime'
|
244
|
+
raise ArgumentError, "cell value '#{v}' is not a DateTime", caller unless v.is_a?(DateTime) || v.is_a?(Time)
|
245
|
+
when type == "date"
|
246
|
+
raise ArgumentError, "cell value '#{v}' is not a Date", caller unless v.is_a?(Date)
|
247
247
|
end
|
248
248
|
end
|
249
249
|
|
@@ -32,10 +32,10 @@ module GoogleVisualr
|
|
32
32
|
return value
|
33
33
|
when value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
34
34
|
return "#{value}"
|
35
|
-
when value.is_a?(Date)
|
36
|
-
return "new Date(#{value.year}, #{value.month-1}, #{value.day})"
|
37
35
|
when value.is_a?(DateTime) || value.is_a?(Time)
|
38
36
|
return "new Date(#{value.year}, #{value.month-1}, #{value.day}, #{value.hour}, #{value.min}, #{value.sec})"
|
37
|
+
when value.is_a?(Date)
|
38
|
+
return "new Date(#{value.year}, #{value.month-1}, #{value.day})"
|
39
39
|
when value.nil?
|
40
40
|
return "null"
|
41
41
|
when value.is_a?(Hash)
|
@@ -155,17 +155,17 @@ describe GoogleVisualr::DataTable do
|
|
155
155
|
context "cell value" do
|
156
156
|
before do
|
157
157
|
@dt = GoogleVisualr::DataTable.new
|
158
|
-
@dt.new_columns( [ {:type => 'number'}, {:type => '
|
158
|
+
@dt.new_columns( [ {:type => 'string'}, {:type => 'number'}, {:type => 'boolean'}, {:type => 'datetime'}, {:type => 'date'} ] )
|
159
159
|
@dt.add_row
|
160
160
|
end
|
161
161
|
|
162
162
|
|
163
163
|
describe "#set_cell" do
|
164
164
|
it "sets cell" do
|
165
|
-
@dt.set_cell(0, 0,
|
166
|
-
@dt.set_cell(0, 1,
|
165
|
+
@dt.set_cell(0, 0, {:v => 'ABCD'})
|
166
|
+
@dt.set_cell(0, 1, 1000)
|
167
167
|
|
168
|
-
@dt.get_row(0).should == [
|
168
|
+
@dt.get_row(0).should == ['ABCD', 1000]
|
169
169
|
end
|
170
170
|
|
171
171
|
it "raises an exception if the row_index or column_index specified is out of range" do
|
@@ -178,31 +178,45 @@ describe GoogleVisualr::DataTable do
|
|
178
178
|
}.to raise_exception(RangeError)
|
179
179
|
end
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
describe "#verify_against_column_type" do
|
182
|
+
def assert_raises_exception(col, value)
|
183
|
+
expect {
|
184
|
+
@dt.set_cell(0, col, value)
|
185
|
+
}.to raise_exception(ArgumentError)
|
186
|
+
end
|
185
187
|
|
186
|
-
|
187
|
-
|
188
|
-
|
188
|
+
it "raises an exception if value is not string" do
|
189
|
+
assert_raises_exception(0, 1234)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "raises an exception if value is not number" do
|
193
|
+
assert_raises_exception(1, 'ABCD')
|
194
|
+
end
|
195
|
+
|
196
|
+
it "raises an exception if value is not boolean" do
|
197
|
+
assert_raises_exception(2, 'ABCD')
|
198
|
+
end
|
199
|
+
|
200
|
+
it "raises an exception if value is not datetime or time" do
|
201
|
+
assert_raises_exception(3, 'ABCD')
|
202
|
+
end
|
203
|
+
|
204
|
+
it "raises an exception if value is not date" do
|
205
|
+
assert_raises_exception(4, 'ABCD')
|
206
|
+
end
|
189
207
|
end
|
190
208
|
|
191
209
|
it "accepts 'nil' for all column types" do
|
192
210
|
expect {
|
193
211
|
@dt.set_cell(0, 0, nil)
|
194
212
|
}.to_not raise_exception(ArgumentError)
|
195
|
-
|
196
|
-
expect {
|
197
|
-
@dt.set_cell(0, 1, nil)
|
198
|
-
}.to_not raise_exception(ArgumentError)
|
199
213
|
end
|
200
214
|
end
|
201
215
|
|
202
216
|
describe "#get_cell" do
|
203
217
|
it "gets cell" do
|
204
|
-
@dt.set_cell(0, 0,
|
205
|
-
@dt.get_cell(0, 0).should ==
|
218
|
+
@dt.set_cell(0, 0, 'ABCD')
|
219
|
+
@dt.get_cell(0, 0).should == 'ABCD'
|
206
220
|
end
|
207
221
|
|
208
222
|
it "raises an exception if the row_index or column_index specified is out of range" do
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "GoogleVisualr::ParamsHelper" do
|
4
|
+
module GoogleVisualr
|
5
|
+
class Mock
|
6
|
+
include GoogleVisualr::ParamHelpers
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
before do
|
11
|
+
@klass = GoogleVisualr::Mock.new
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#stringify" do
|
15
|
+
it "converts symbol keys to string keys" do
|
16
|
+
options = @klass.stringify_keys!({:a => 1})
|
17
|
+
options.should == {"a" => 1}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#js_parameters" do
|
22
|
+
it "converts params to be js-ready string" do
|
23
|
+
options = @klass.js_parameters({:a => 1})
|
24
|
+
options.should == "{a: 1}"
|
25
|
+
|
26
|
+
options = @klass.js_parameters({:a => {:b=> 1}})
|
27
|
+
options.should == "{a: {b: 1}}"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns empty string for nil options" do
|
31
|
+
options = @klass.js_parameters(nil)
|
32
|
+
options.should == ""
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#typecast" do
|
37
|
+
def assert_equal(input, expected)
|
38
|
+
options = @klass.typecast(input)
|
39
|
+
options.should == expected
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns string" do
|
43
|
+
assert_equal("a's", "'a\\'s'")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns number" do
|
47
|
+
assert_equal(1, 1)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns boolean" do
|
51
|
+
assert_equal(true , "true" )
|
52
|
+
assert_equal(false, "false")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns datetime" do
|
56
|
+
date = DateTime.now
|
57
|
+
expected = "new Date(#{date.year}, #{date.month-1}, #{date.day}, #{date.hour}, #{date.min}, #{date.sec})"
|
58
|
+
assert_equal(date, expected)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns time" do
|
62
|
+
date = Time.now
|
63
|
+
expected = "new Date(#{date.year}, #{date.month-1}, #{date.day}, #{date.hour}, #{date.min}, #{date.sec})"
|
64
|
+
assert_equal(date, expected)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns date" do
|
68
|
+
date = Date.today
|
69
|
+
expected = "new Date(#{date.year}, #{date.month-1}, #{date.day})"
|
70
|
+
assert_equal(date, expected)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns null" do
|
74
|
+
assert_equal(nil, "null")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "recursively calls js_parameters" do
|
78
|
+
assert_equal({:a => {:b => {:c => 1}}}, "{a: {b: {c: 1}}}")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: google_visualr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 2.0.
|
5
|
+
version: 2.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Winston Teo
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-07 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- spec/google_visualr/base_chart_spec.rb
|
84
84
|
- spec/google_visualr/data_table_spec.rb
|
85
85
|
- spec/google_visualr/formatters_spec.rb
|
86
|
+
- spec/google_visualr/param_helpers_spec.rb
|
86
87
|
- spec/spec_helper.rb
|
87
88
|
- test/google_visualr_spec.rb
|
88
89
|
- test/helper.rb
|