rgviz-rails 0.60 → 0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rgviz_rails.rb CHANGED
@@ -2,3 +2,7 @@ require 'rgviz_rails/init.rb'
2
2
  require 'rgviz_rails/executor.rb'
3
3
  require 'rgviz_rails/js_renderer.rb'
4
4
  require 'rgviz_rails/tqx.rb'
5
+
6
+ module RgvizRails
7
+
8
+ end
@@ -586,16 +586,22 @@ module Rgviz
586
586
  col = klass.send(:columns).select{|x| x.name == name}.first
587
587
  return [klass, col, joins] if col
588
588
 
589
+ before = ""
589
590
  idx = name.index '_'
590
- return nil if not idx
591
-
592
- before = name[0 ... idx]
593
- name = name[idx + 1 .. -1]
594
-
595
- assoc = klass.send :reflect_on_association, before.to_sym
596
- raise "Unknown association #{before}" unless assoc
597
- klass = assoc.klass
598
- joins << assoc
591
+ while idx
592
+ before += "_" unless before.blank?
593
+ before += "#{name[0 ... idx]}"
594
+ name = name[idx + 1 .. -1]
595
+ assoc = klass.send :reflect_on_association, before.to_sym
596
+ if assoc
597
+ klass = assoc.klass
598
+ joins << assoc
599
+ idx = nil
600
+ else
601
+ idx = name.index '_'
602
+ raise "Unknown association #{before}" unless idx
603
+ end
604
+ end
599
605
  end
600
606
  end
601
607
 
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.60'
4
+ version: '0.61'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000Z
12
+ date: 2012-03-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgviz
16
- requirement: &70290789324480 !ruby/object:Gem::Requirement
16
+ requirement: &70254349665820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70290789324480
24
+ version_requirements: *70254349665820
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70254349665300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70254349665300
25
36
  description:
26
37
  email: aborenszweig@manas.com.ar
27
38
  executables: []
@@ -39,13 +50,6 @@ files:
39
50
  - lib/rgviz_rails/adapters/sqlite_adapter.rb
40
51
  - lib/rgviz_rails/init.rb
41
52
  - rails/init.rb
42
- - spec/blueprints.rb
43
- - spec/spec.opts
44
- - spec/spec_helper.rb
45
- - spec/models/city.rb
46
- - spec/models/country.rb
47
- - spec/models/person.rb
48
- - spec/rgviz/executor_spec.rb
49
53
  - README.rdoc
50
54
  homepage: http://github.com/asterite/rgviz-rails
51
55
  licenses: []
data/spec/blueprints.rb DELETED
@@ -1,25 +0,0 @@
1
- require 'machinist/active_record'
2
- require 'sham'
3
- require 'faker'
4
-
5
- Sham.define do
6
- name { Faker::Name.name }
7
- number(:unique => false) { rand(100) + 1 }
8
- date { Date.parse("#{rand(40) + 1970}-#{rand(12) + 1}-#{rand(28) + 1}") }
9
- end
10
-
11
- City.blueprint do
12
- name
13
- country
14
- end
15
-
16
- Country.blueprint do
17
- name
18
- end
19
-
20
- Person.blueprint do
21
- name
22
- age { Sham::number }
23
- birthday { Sham::date }
24
- city
25
- end
data/spec/models/city.rb DELETED
@@ -1,4 +0,0 @@
1
- class City < ActiveRecord::Base
2
- has_many :people
3
- belongs_to :country
4
- end
@@ -1,3 +0,0 @@
1
- class Country < ActiveRecord::Base
2
- has_many :cities
3
- end
@@ -1,3 +0,0 @@
1
- class Person < ActiveRecord::Base
2
- belongs_to :city
3
- end
@@ -1,553 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- #require 'rgviz'
3
-
4
- include Rgviz
5
-
6
- describe Executor do
7
- before :each do
8
- [Person, City, Country].each &:delete_all
9
- end
10
-
11
- def exec(query, options = {})
12
- exec = Executor.new Person
13
- exec.execute query, options
14
- end
15
-
16
- def format_datetime(date)
17
- date.strftime "new Date(%Y, %m, %d, %H, %M, %S)"
18
- end
19
-
20
- def format_date(date)
21
- date.strftime "new Date(%Y, %m, %d)"
22
- end
23
-
24
- def self.it_processes_single_select_column(query, id, type, value, label, format = nil, options = {}, test_options = {})
25
- it "processes select #{query}", test_options do
26
- if block_given?
27
- yield
28
- else
29
- Person.make
30
- end
31
-
32
- table = exec "select #{query}", options
33
- table.cols.length.should == 1
34
-
35
- table.cols[0].id.should == id
36
- table.cols[0].type.should == type
37
- table.cols[0].label.should == label
38
-
39
- table.rows.length.should == 1
40
- table.rows[0].c.length.should == 1
41
-
42
- table.rows[0].c[0].v.should == value
43
- table.rows[0].c[0].f.should == format
44
- end
45
- end
46
-
47
- it "processes select *" do
48
- p = Person.make
49
-
50
- table = exec 'select *'
51
- table.cols.length.should == 7
52
-
53
- i = 0
54
- [['id', :number], ['name', :string], ['age', :number], ['birthday', :date],
55
- ['created_at', :datetime], ['updated_at', :datetime],
56
- ['city_id', :number]].each do |id, type|
57
- table.cols[i].id.should == id
58
- table.cols[i].type.should == type
59
- table.cols[i].label.should == id
60
- i += 1
61
- end
62
-
63
- table.rows.length.should == 1
64
- table.rows[0].c.length.should == 7
65
-
66
- i = 0
67
- [p.id, p.name, p.age, p.birthday,
68
- p.created_at, p.updated_at, p.city.id].each do |val|
69
- table.rows[0].c[i].v.should == val
70
- i += 1
71
- end
72
- end
73
-
74
- it_processes_single_select_column 'name', 'name', :string, 'foo', 'name' do
75
- Person.make :name => 'foo'
76
- end
77
-
78
- it_processes_single_select_column '1', 'c0', :number, 1, '1'
79
- it_processes_single_select_column '1.2', 'c0', :number, 1.2, '1.2'
80
- it_processes_single_select_column '"hello"', 'c0', :string, 'hello', "'hello'"
81
- it_processes_single_select_column 'false', 'c0', :boolean, false, 'false'
82
- it_processes_single_select_column 'true', 'c0', :boolean, true, 'true'
83
- it_processes_single_select_column 'date "2010-01-02"', 'c0', :date, Time.parse('2010-01-02').to_date, "date '2010-01-02'"
84
- it_processes_single_select_column 'datetime "2010-01-02 10:11:12"', 'c0', :datetime, Time.parse('2010-01-02 10:11:12'), "datetime '2010-01-02 10:11:12'"
85
- it_processes_single_select_column 'timeofday "10:11:12"', 'c0', :timeofday, Time.parse('10:11:12'), "timeofday '10:11:12'"
86
-
87
- it_processes_single_select_column '1 + 2', 'c0', :number, 3, '1 + 2'
88
- it_processes_single_select_column '3 - 2', 'c0', :number, 1, '3 - 2'
89
- it_processes_single_select_column '2 * 3', 'c0', :number, 6, '2 * 3'
90
- it_processes_single_select_column '6 / 3', 'c0', :number, 2, '6 / 3'
91
- it_processes_single_select_column '3 * age', 'c0', :number, 60, '3 * age' do
92
- Person.make :age => 20
93
- end
94
-
95
- it_processes_single_select_column 'sum(age)', 'c0', :number, 6, 'sum(age)' do
96
- [1, 2, 3].each{|i| Person.make :age => i}
97
- end
98
-
99
- it_processes_single_select_column 'avg(age)', 'c0', :number, 30, 'avg(age)' do
100
- [10, 20, 60].each{|i| Person.make :age => i}
101
- end
102
-
103
- it_processes_single_select_column 'count(age)', 'c0', :number, 3, 'count(age)' do
104
- 3.times{|i| Person.make}
105
- end
106
-
107
- it_processes_single_select_column 'max(age)', 'c0', :number, 3, 'max(age)' do
108
- [1, 2, 3].each{|i| Person.make :age => i}
109
- end
110
-
111
- it_processes_single_select_column 'min(age)', 'c0', :number, 1, 'min(age)' do
112
- [1, 2, 3].each{|i| Person.make :age => i}
113
- end
114
-
115
- it_processes_single_select_column 'age where age > 2', 'age', :number, 3, 'age' do
116
- [1, 2, 3].each{|i| Person.make :age => i}
117
- end
118
-
119
- it_processes_single_select_column 'age where age > 2 and age <= 3', 'age', :number, 3, 'age' do
120
- [1, 2, 3, 4, 5].each{|i| Person.make :age => i}
121
- end
122
-
123
- it_processes_single_select_column 'name where age is null', 'name', :string, 'b', 'name' do
124
- Person.make :age => 1, :name => 'a'
125
- Person.make :age => nil, :name => 'b'
126
- end
127
-
128
- it_processes_single_select_column "age where city_name = 'Laos' and year(birthday) = '2010'", 'age', :number, 1, 'age' do
129
- Person.make :age => 1, :name => 'a', :city => City.make(:name => 'Laos'), :birthday => '2010-01-01'
130
- end
131
-
132
- it_processes_single_select_column 'name where age is not null', 'name', :string, 'a', 'name' do
133
- Person.make :age => 1, :name => 'a'
134
- Person.make :age => nil, :name => 'b'
135
- end
136
-
137
- it "processes group by" do
138
- Person.make :name => 'one', :age => 1
139
- Person.make :name => 'one', :age => 2
140
- Person.make :name => 'two', :age => 3
141
- Person.make :name => 'two', :age => 4
142
-
143
- table = exec 'select max(age) group by name order by name'
144
-
145
- table.rows.length.should == 2
146
- table.rows[0].c.length.should == 1
147
- table.rows[0].c[0].v.should == 2
148
- table.rows[1].c.length.should == 1
149
- table.rows[1].c[0].v.should == 4
150
- end
151
-
152
- it "processes order by" do
153
- Person.make :age => 1
154
- Person.make :age => 3
155
- Person.make :age => 2
156
-
157
- table = exec 'select age order by age desc'
158
-
159
- table.rows.length.should == 3
160
- table.rows[0].c.length.should == 1
161
- table.rows[0].c[0].v.should == 3
162
- table.rows[1].c.length.should == 1
163
- table.rows[1].c[0].v.should == 2
164
- table.rows[2].c.length.should == 1
165
- table.rows[2].c[0].v.should == 1
166
- end
167
-
168
- it_processes_single_select_column 'age where age > 3 order by age limit 1', 'age', :number, 4, 'age' do
169
- [1, 2, 3, 4, 5].each{|i| Person.make :age => i}
170
- end
171
-
172
- it_processes_single_select_column 'age where age > 3 order by age limit 1 offset 1', 'age', :number, 5, 'age' do
173
- [1, 2, 3, 4, 5].each{|i| Person.make :age => i}
174
- end
175
-
176
- it_processes_single_select_column 'city_name', 'city_name', :string, 'Buenos Aires', 'city_name' do
177
- Person.make :city => City.make(:name => 'Buenos Aires')
178
- end
179
-
180
- it_processes_single_select_column 'city_country_name', 'city_country_name', :string, 'Argentina', 'city_country_name' do
181
- Person.make :city => City.make(:country => Country.make(:name => 'Argentina'))
182
- end
183
-
184
- it_processes_single_select_column 'city_country_name group by city_country_name', 'city_country_name', :string, 'Argentina', 'city_country_name' do
185
- Person.make :city => City.make(:country => Country.make(:name => 'Argentina'))
186
- end
187
-
188
- it "processes with conditions as string" do
189
- Person.make :age => 1
190
- Person.make :age => 2
191
- Person.make :age => 3
192
-
193
- table = exec 'select age', :conditions => 'age = 2'
194
-
195
- table.rows.length.should == 1
196
- table.rows[0].c.length.should == 1
197
- table.rows[0].c[0].v.should == 2
198
- end
199
-
200
- it "processes with conditions as string and another filter" do
201
- Person.make :age => 1
202
- Person.make :age => 2
203
- Person.make :age => 3
204
-
205
- table = exec 'select age where age > 1', :conditions => 'age < 3'
206
-
207
- table.rows.length.should == 1
208
- table.rows[0].c.length.should == 1
209
- table.rows[0].c[0].v.should == 2
210
- end
211
-
212
- it "processes with conditions as array" do
213
- Person.make :age => 1
214
- Person.make :age => 2
215
- Person.make :age => 3
216
-
217
- table = exec 'select age', :conditions => ['age = ?', 2]
218
-
219
- table.rows.length.should == 1
220
- table.rows[0].c.length.should == 1
221
- table.rows[0].c[0].v.should == 2
222
- end
223
-
224
- it "processes with conditions as array and another filter" do
225
- Person.make :age => 1
226
- Person.make :age => 2
227
- Person.make :age => 3
228
-
229
- table = exec 'select age where age > 1', :conditions => ['age < ?', 3]
230
-
231
- table.rows.length.should == 1
232
- table.rows[0].c.length.should == 1
233
- table.rows[0].c[0].v.should == 2
234
- end
235
-
236
- [['year', 2006], ['month', 5], ['day', 2],
237
- ['hour', 3], ['minute', 4], ['second', 9],
238
- ['dayOfWeek', 3]].each do |str, val|
239
- it_processes_single_select_column "#{str}(created_at)", 'c0', :number, val, "#{str}(created_at)" do
240
- Person.make :created_at => Time.parse('2006-05-02 3:04:09')
241
- end
242
- end
243
-
244
- # it_processes_single_select_column "quarter(created_at)", 'c0', :number, 2, 'quarter(created_at)' do
245
- # Person.make :created_at => Time.parse('2006-05-02 3:04:09')
246
- # end
247
-
248
- it_processes_single_select_column "dateDiff(date '2008-03-13', date '2008-03-10')", 'c0', :number, 3, "dateDiff(date '2008-03-13', date '2008-03-10')"
249
-
250
- # it_processes_single_select_column "now()", 'c0', :datetime, Time.now.utc.strftime("%Y-%m-%d %H:%M:%S"), "now()" do
251
- # Person.make :created_at => Time.parse('2006-05-02 3:04:09')
252
- # end
253
-
254
- it_processes_single_select_column "toDate('2008-03-13')", 'c0', :date, Time.parse("2008-03-13").to_date, "toDate('2008-03-13')"
255
-
256
- it_processes_single_select_column "toDate(created_at)", 'c0', :date, Time.parse("2008-03-13").to_date, "toDate(created_at)" do
257
- Person.make :created_at => Time.parse('2008-03-13 3:04:09')
258
- end
259
-
260
- # it_processes_single_select_column "toDate(1234567890000)", 'c0', :date, Date.parse('2009-02-13').to_s, "toDate(1234567890000)"
261
-
262
- it_processes_single_select_column "upper(name)", 'c0', :string, 'FOO', "upper(name)" do
263
- Person.make :name => 'foo'
264
- end
265
-
266
- it_processes_single_select_column "lower(name)", 'c0', :string, 'foo', "lower(name)" do
267
- Person.make :name => 'FOO'
268
- end
269
-
270
- it_processes_single_select_column "concat(age)", 'c0', :string, '20', "concat(age)", nil, :extensions => true do
271
- Person.make :age => 20
272
- end
273
-
274
- it_processes_single_select_column "concat(name, 'bar')", 'c0', :string, 'foobar', "concat(name, 'bar')", nil, :extensions => true do
275
- Person.make :name => 'foo'
276
- end
277
-
278
- it_processes_single_select_column "name label name 'my name'", 'name', :string, 'foo', "my name" do
279
- Person.make :name => 'foo'
280
- end
281
-
282
- it_processes_single_select_column "1 + 2 label 1 + 2 'my name'", 'c0', :number, 3, "my name"
283
-
284
- it_processes_single_select_column "sum(age) label sum(age) 'my name'", 'c0', :number, 2, "my name" do
285
- Person.make :age => 2
286
- end
287
-
288
- it_processes_single_select_column "1 options no_values", 'c0', :number, nil, "1"
289
-
290
- it "processes pivot" do
291
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 1000
292
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 500
293
- Person.make :name => 'Eng', :birthday => '2000-01-13', :age => 600
294
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 400
295
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 350
296
- Person.make :name => 'Marketing', :birthday => '2000-01-13', :age => 800
297
-
298
- table = exec 'select name, sum(age) group by name pivot birthday order by name'
299
-
300
- table.cols.length.should == 3
301
-
302
- i = 0
303
- [['c0', :string, 'name'],
304
- ['c1', :number, '2000-01-12 sum(age)'],
305
- ['c2', :number, '2000-01-13 sum(age)']].each do |id, type, label|
306
- table.cols[i].id.should == id
307
- table.cols[i].type.should == type
308
- table.cols[i].label.should == label
309
- i += 1
310
- end
311
-
312
- table.rows.length.should == 3
313
-
314
- i = 0
315
- [['Eng', 1500, 600],
316
- ['Marketing', nil, 800],
317
- ['Sales', 750, nil]].each do |values|
318
- table.rows[i].c.length.should == 3
319
- values.each_with_index do |v, j|
320
- table.rows[i].c[j].v.should == v
321
- end
322
- i += 1
323
- end
324
- end
325
-
326
- it "processes pivot2" do
327
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 1000
328
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 500
329
- Person.make :name => 'Eng', :birthday => '2000-01-13', :age => 600
330
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 400
331
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 350
332
- Person.make :name => 'Marketing', :birthday => '2000-01-13', :age => 800
333
-
334
- table = exec 'select sum(age), name group by name pivot birthday order by name'
335
-
336
- table.cols.length.should == 3
337
-
338
- i = 0
339
- [['c0', :number, '2000-01-12 sum(age)'],
340
- ['c1', :number, '2000-01-13 sum(age)'],
341
- ['c2', :string, 'name']].each do |id, type, label|
342
- table.cols[i].id.should == id
343
- table.cols[i].type.should == type
344
- table.cols[i].label.should == label
345
- i += 1
346
- end
347
-
348
- table.rows.length.should == 3
349
-
350
- i = 0
351
- [[1500, 600, 'Eng'],
352
- [nil, 800, 'Marketing'],
353
- [750, nil, 'Sales']].each do |values|
354
- table.rows[i].c.length.should == 3
355
- values.each_with_index do |v, j|
356
- table.rows[i].c[j].v.should == v
357
- end
358
- i += 1
359
- end
360
- end
361
-
362
- it "processes pivot3" do
363
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 10
364
- Person.make :name => 'Eng', :birthday => '2001-02-12', :age => 10
365
-
366
- table = exec 'select name, sum(age) group by name pivot year(birthday), month(birthday)'
367
-
368
- table.cols.length.should == 3
369
-
370
- i = 0
371
- [['Eng', 10, 10]].each do |values|
372
- table.rows[i].c.length.should == 3
373
- values.each_with_index do |v, j|
374
- table.rows[i].c[j].v.should == v
375
- end
376
- i += 1
377
- end
378
- end
379
-
380
- it "processes pivot4" do
381
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 10
382
- Person.make :name => 'Sales', :birthday => '2001-02-12', :age => 20
383
-
384
- table = exec 'select birthday, month(birthday), sum(age) group by month(birthday) pivot name order by name'
385
-
386
- table.cols.length.should == 5
387
-
388
- i = 0
389
- [
390
- [Time.parse('2000-01-12').to_date, nil, 1, 10, nil],
391
- [nil, Time.parse('2001-02-12').to_date, 2, nil, 20],
392
- ].each do |values|
393
- table.rows[i].c.length.should == 5
394
- values.each_with_index do |v, j|
395
- table.rows[i].c[j].v.should == v
396
- end
397
- i += 1
398
- end
399
- end
400
-
401
- it "processes pivot without group by" do
402
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 1000
403
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 500
404
- Person.make :name => 'Eng', :birthday => '2000-01-13', :age => 600
405
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 400
406
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 350
407
- Person.make :name => 'Marketing', :birthday => '2000-01-13', :age => 800
408
-
409
- table = exec 'select sum(age) pivot name order by name'
410
-
411
- table.cols.length.should == 3
412
-
413
- i = 0
414
- [['c0', :number, 'Eng sum(age)'],
415
- ['c1', :number, 'Marketing sum(age)'],
416
- ['c2', :number, 'Sales sum(age)']].each do |id, type, label|
417
- table.cols[i].id.should == id
418
- table.cols[i].type.should == type
419
- table.cols[i].label.should == label
420
- i += 1
421
- end
422
-
423
- table.rows.length.should == 1
424
-
425
- i = 0
426
- [[2100, 800, 750]].each do |values|
427
- table.rows[i].c.length.should == 3
428
- values.each_with_index do |v, j|
429
- table.rows[i].c[j].v.should == v
430
- end
431
- i += 1
432
- end
433
- end
434
-
435
- it "processes pivot with no results" do
436
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 10
437
- Person.make :name => 'Sales', :birthday => '2001-02-12', :age => 20
438
-
439
- table = exec 'select birthday, sum(age) where 1 = 2 group by month(birthday) pivot name order by name'
440
-
441
- table.cols.length.should == 2
442
-
443
- i = 0
444
- [['birthday', :date, 'birthday'],
445
- ['c1', :number, 'sum(age)']].each do |id, type, label|
446
- table.cols[i].id.should == id
447
- table.cols[i].type.should == type
448
- table.cols[i].label.should == label
449
- i += 1
450
- end
451
- end
452
-
453
- it "processes pivot with group by not in select" do
454
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 10
455
- Person.make :name => 'Sales', :birthday => '2001-02-12', :age => 20
456
-
457
- table = exec 'select birthday, sum(age) group by month(birthday) pivot name order by name'
458
-
459
- table.cols.length.should == 4
460
-
461
- i = 0
462
- [
463
- [Time.parse('2000-01-12').to_date, nil, 10, nil],
464
- [nil, Time.parse('2001-02-12').to_date, nil, 20],
465
- ].each do |values|
466
- table.rows[i].c.length.should == 4
467
- values.each_with_index do |v, j|
468
- table.rows[i].c[j].v.should == v
469
- end
470
- i += 1
471
- end
472
- end
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
-
510
- # Formatting
511
- it_processes_single_select_column 'false format false "%s is falsey"', 'c0', :boolean, false, 'false', 'false is falsey'
512
- it_processes_single_select_column '1 format 1 "%.2f"', 'c0', :number, 1, '1', '1.00'
513
- it_processes_single_select_column '1.2 format 1.2 "%.2f"', 'c0', :number, 1.2, '1.2', '1.20'
514
- it_processes_single_select_column '"hello" format "hello" "%s world"', 'c0', :string, "hello", "'hello'", 'hello world'
515
- it_processes_single_select_column 'date "2001-01-02" format date "2001-01-02" "%Y"', 'c0', :date, Time.parse('2001-01-02').to_date, "date '2001-01-02'", '2001'
516
-
517
- it "processes pivot with format" do
518
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 1000
519
- Person.make :name => 'Eng', :birthday => '2000-01-12', :age => 500
520
- Person.make :name => 'Eng', :birthday => '2000-01-13', :age => 600
521
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 400
522
- Person.make :name => 'Sales', :birthday => '2000-01-12', :age => 350
523
- Person.make :name => 'Marketing', :birthday => '2000-01-13', :age => 800
524
-
525
- table = exec 'select name, sum(age) group by name pivot birthday order by name format name "x %s", sum(age) "%.2f"'
526
-
527
- table.cols.length.should == 3
528
-
529
- i = 0
530
- [['c0', :string, 'name'],
531
- ['c1', :number, '2000-01-12 sum(age)'],
532
- ['c2', :number, '2000-01-13 sum(age)']].each do |id, type, label|
533
- table.cols[i].id.should == id
534
- table.cols[i].type.should == type
535
- table.cols[i].label.should == label
536
- i += 1
537
- end
538
-
539
- table.rows.length.should == 3
540
-
541
- i = 0
542
- [[['Eng', 'x Eng'], [1500, '1500.00'], [600, '600.00']],
543
- [['Marketing', 'x Marketing'], [nil, nil], [800, '800.00']],
544
- [['Sales', 'x Sales'], [750, '750.00'], [nil, nil]]].each do |values|
545
- table.rows[i].c.length.should == 3
546
- values.each_with_index do |v, j|
547
- table.rows[i].c[j].v.should == v[0]
548
- table.rows[i].c[j].f.should == v[1]
549
- end
550
- i += 1
551
- end
552
- end
553
- end
data/spec/spec.opts DELETED
@@ -1,4 +0,0 @@
1
- --colour
2
- --format progress
3
- --loadby mtime
4
- --reverse
data/spec/spec_helper.rb DELETED
@@ -1,49 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
- require 'rubygems'
4
- require 'logger'
5
-
6
- require 'active_record'
7
-
8
- #ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
9
- ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'rgviz_rails', :username => 'root', :password => '')
10
- #ActiveRecord::Base.establish_connection(:adapter => 'postgresql', :database => 'rgviz_rails', :username => 'postgres', :password => '###', :host => '/var/run/postgresql/')
11
-
12
- ActiveRecord::Schema.define do
13
- create_table "cities", :force => true do |t|
14
- t.string "name"
15
- t.datetime "created_at"
16
- t.datetime "updated_at"
17
- t.integer "country_id"
18
- end
19
-
20
- create_table "countries", :force => true do |t|
21
- t.string "name"
22
- t.datetime "created_at"
23
- t.datetime "updated_at"
24
- end
25
-
26
- create_table "people", :force => true do |t|
27
- t.string "name"
28
- t.integer "age"
29
- t.date "birthday"
30
- t.datetime "created_at"
31
- t.datetime "updated_at"
32
- t.integer "city_id"
33
- end
34
- end
35
-
36
- require File.dirname(__FILE__) + '/models/person'
37
- require File.dirname(__FILE__) + '/models/city'
38
- require File.dirname(__FILE__) + '/models/country'
39
-
40
- require File.dirname(__FILE__) + '/blueprints'
41
-
42
- require File.dirname(__FILE__) + '/../../rgviz/lib/rgviz'
43
- #require 'rgviz'
44
- require 'rgviz_rails/executor'
45
-
46
- RAILS_ENV = 'test'
47
-
48
- # Add this directory so the ActiveSupport autoloading works
49
- #ActiveSupport::Dependencies.load_paths << File.dirname(__FILE__)