rgviz-rails 0.52 → 0.53

Sign up to get free protection for your applications and to get access to all the features.
@@ -275,6 +275,7 @@ module Rgviz
275
275
  if @group_bys.include?(original_column)
276
276
  hash = {}
277
277
  hash[:v] = key[group_i] unless @query.options && @query.options.no_values
278
+ hash[:v] = 0 if hash[:v].nil? && is_count_column(@query.select.columns[i])
278
279
 
279
280
  format = @formats[original_column]
280
281
  hash[:f] = format_value(@table.cols[i], format, hash[:v]) if format
@@ -288,6 +289,7 @@ module Rgviz
288
289
 
289
290
  hash = {}
290
291
  hash[:v] = v unless @query.options && @query.options.no_values
292
+ hash[:v] = 0 if hash[:v].nil? && is_count_column(@query.select.columns[i])
291
293
 
292
294
  format = @formats[original_column]
293
295
  hash[:f] = format_value(@table.cols[i], format, hash[:v]) if format
@@ -301,6 +303,10 @@ module Rgviz
301
303
  end
302
304
  end
303
305
 
306
+ def is_count_column(col)
307
+ col.is_a?(AggregateColumn) && col.function == AggregateColumn::Count
308
+ end
309
+
304
310
  def column_id(col, i)
305
311
  case col
306
312
  when IdColumn
@@ -471,6 +471,42 @@ describe Executor do
471
471
  end
472
472
  end
473
473
 
474
+ it "processes pivot with zeros instead of nulls in count", :focus => true do
475
+ Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 1000
476
+ Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 500
477
+ Person.make :name => 'Eng', :birthday => '2000-01-13', :age => 600
478
+ Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 400
479
+ Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 350
480
+ Person.make :name => 'Marketing', :birthday => '2000-01-13', :age => 800
481
+
482
+ table = exec 'select name, count(age) group by name pivot birthday order by name'
483
+
484
+ table.cols.length.should == 3
485
+
486
+ i = 0
487
+ [['c0', :string, 'name'],
488
+ ['c1', :number, '2000-01-12 count(age)'],
489
+ ['c2', :number, '2000-01-13 count(age)']].each do |id, type, label|
490
+ table.cols[i].id.should == id
491
+ table.cols[i].type.should == type
492
+ table.cols[i].label.should == label
493
+ i += 1
494
+ end
495
+
496
+ table.rows.length.should == 3
497
+
498
+ i = 0
499
+ [['Eng', 2, 1],
500
+ ['Marketing', 0, 1],
501
+ ['Sales', 2, 0]].each do |values|
502
+ table.rows[i].c.length.should == 3
503
+ values.each_with_index do |v, j|
504
+ table.rows[i].c[j].v.should == v
505
+ end
506
+ i += 1
507
+ end
508
+ end
509
+
474
510
  # Formatting
475
511
  it_processes_single_select_column 'false format false "%s is falsey"', 'c0', :boolean, false, 'false', 'false is falsey'
476
512
  it_processes_single_select_column '1 format 1 "%.2f"', 'c0', :number, 1, '1', '1.00'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.52'
4
+ version: '0.53'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgviz
16
- requirement: &70279841786980 !ruby/object:Gem::Requirement
16
+ requirement: &70094420919240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70279841786980
24
+ version_requirements: *70094420919240
25
25
  description:
26
26
  email: aborenszweig@manas.com.ar
27
27
  executables: []