elskwid-munger 0.1.4.5 → 0.1.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,35 +1,10 @@
1
- require 'rubygems'
2
- # Gem::manage_gems
3
- require 'rake/gempackagetask'
4
- require 'rake/rdoctask'
5
- require 'rspec/core/rake_task'
1
+ require "rake/testtask"
6
2
 
7
- spec = eval(File.new('munger.gemspec','r').read)
3
+ task default: [:test]
8
4
 
9
- Rake::GemPackageTask.new(spec) do |pkg|
10
- pkg.need_tar = true
11
- end
12
-
13
- task :default => "pkg/#{spec.name}-#{spec.version}.gem" do
14
- puts "generated latest version"
15
- end
16
-
17
- desc 'Run specs'
18
- RSpec::Core::RakeTask.new
19
-
20
- desc 'Generate coverage reports'
21
- RSpec::Core::RakeTask.new('spec:coverage') do |t|
22
- t.rcov = true
23
- end
24
-
25
- task :doc => [:rdoc]
26
- namespace :doc do
27
- Rake::RDocTask.new do |rdoc|
28
- files = ["README", "lib/**/*.rb"]
29
- rdoc.rdoc_files.add(files)
30
- rdoc.main = "README"
31
- rdoc.title = "Munger Docs"
32
- rdoc.rdoc_dir = "doc"
33
- rdoc.options << "--line-numbers" << "--inline-source"
34
- end
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "lib"
7
+ t.libs << "test"
8
+ t.pattern = "test/**/*_test.rb"
9
+ t.verbose = false
35
10
  end
data/munger.gemspec CHANGED
@@ -1,36 +1,46 @@
1
1
  Gem::Specification.new do |s|
2
- s.platform = Gem::Platform::RUBY
3
- s.name = "elskwid-munger"
4
- s.version = "0.1.4.5"
5
- s.authors = ['Scott Chacon', 'Brandon Mitchell', 'Don Morrison', 'Eric Lindvall']
6
- s.email = "elskwid@gmail.com"
7
- s.summary = "A reporting engine in Ruby - the elskwid fork!"
8
- s.homepage = "http://github.com/elskwid/munger"
9
- s.has_rdoc = true
10
- s.files = ["munger.gemspec",
11
- "Rakefile",
12
- "README",
13
- "examples/column_add.rb",
14
- "examples/development.log",
15
- "examples/example_helper.rb",
16
- "examples/sinatra_app.rb",
17
- "examples/test.html",
18
- "lib/munger.rb",
19
- "lib/munger/data.rb",
20
- "lib/munger/item.rb",
21
- "lib/munger/render.rb",
22
- "lib/munger/report.rb",
23
- "lib/munger/render/csv.rb",
24
- "lib/munger/render/html.rb",
25
- "lib/munger/render/sortable_html.rb",
26
- "lib/munger/render/text.rb",
27
- "spec/spec_helper.rb",
28
- "spec/munger/data_spec.rb",
29
- "spec/munger/item_spec.rb",
30
- "spec/munger/render_spec.rb",
31
- "spec/munger/report_spec.rb",
32
- "spec/munger/data/new_spec.rb",
33
- "spec/munger/render/csv_spec.rb",
34
- "spec/munger/render/html_spec.rb",
35
- "spec/munger/render/text_spec.rb"]
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = "elskwid-munger"
4
+ s.version = "0.1.4.6"
5
+ s.authors = ['Scott Chacon', 'Brandon Mitchell', 'Don Morrison', 'Eric Lindvall']
6
+ s.email = "elskwid@gmail.com"
7
+ s.summary = "A reporting engine in Ruby - the elskwid fork!"
8
+ s.homepage = "http://github.com/elskwid/munger"
9
+ s.has_rdoc = true
10
+
11
+ s.files = [
12
+ "munger.gemspec",
13
+ "Rakefile",
14
+ "README",
15
+ "examples/column_add.rb",
16
+ "examples/development.log",
17
+ "examples/example_helper.rb",
18
+ "examples/sinatra_app.rb",
19
+ "examples/test.html",
20
+ "lib/munger.rb",
21
+ "lib/munger/data.rb",
22
+ "lib/munger/item.rb",
23
+ "lib/munger/render.rb",
24
+ "lib/munger/report.rb",
25
+ "lib/munger/render/csv.rb",
26
+ "lib/munger/render/html.rb",
27
+ "lib/munger/render/sortable_html.rb",
28
+ "lib/munger/render/text.rb"]
29
+
30
+ s.test_files = [
31
+ "test/test_helper.rb",
32
+ "test/munger/csv_test.rb",
33
+ "test/munger/data_ar_test.rb",
34
+ "test/munger/data_test.rb",
35
+ "test/munger/html_test.rb",
36
+ "test/munger/item_test.rb",
37
+ "test/munger/new_test.rb",
38
+ "test/munger/render_test.rb",
39
+ "test/munger/report_test.rb",
40
+ "test/munger/text_test.rb"]
41
+
42
+ s.add_dependency "builder"
43
+
44
+ s.add_development_dependency "rake"
45
+ s.add_development_dependency "minitest", "~>5.0.8"
36
46
  end
@@ -1,27 +1,27 @@
1
- require File.dirname(__FILE__) + "/../../spec_helper"
1
+ require "test_helper"
2
2
 
3
- describe Munger::Render::CSV do
3
+ describe Munger::Render::CSV do
4
4
  include MungerSpecHelper
5
-
5
+
6
6
  before(:each) do
7
7
  @data = Munger::Data.new(:data => test_data + [{:name => 'Comma, Guy', :age => 100, :day => 0, :score => 0}])
8
8
  @report = Munger::Report.new(:data => @data)
9
9
  end
10
10
 
11
11
  it "should accept a Munger::Report object" do
12
- Munger::Render::Text.new(@report.process).should be_valid
12
+ Munger::Render::Text.new(@report.process).must_be :valid?
13
13
  end
14
-
14
+
15
15
  it "should render a basic text table" do
16
16
  @render = Munger::Render::CSV.new(@report.process)
17
17
  count = @report.rows
18
18
  text = @render.render
19
- text.split("\n").should have_at_least(count).items
19
+ text.split("\n").size.must_be :>, count
20
20
  end
21
-
21
+
22
22
  it "should quote data with commas" do
23
23
  @render = Munger::Render::CSV.new(@report.process)
24
24
  text = @render.render
25
- text.should match /"Comma, Guy"/
25
+ text.must_match /"Comma, Guy"/
26
26
  end
27
- end
27
+ end
@@ -0,0 +1,194 @@
1
+ require "test_helper"
2
+
3
+ describe "Munger::Data with AR like records" do
4
+ include MungerSpecHelper
5
+
6
+ before(:each) do
7
+ @data = Munger::Data.new(:data => test_ar_data)
8
+ end
9
+
10
+ it "must accept an AR dataset" do
11
+ Munger::Data.new(:data => test_ar_data).must_be :valid?
12
+ end
13
+
14
+ it "must be able to set AR data after init" do
15
+ m = Munger::Data.new
16
+ m.data = test_ar_data
17
+ m.must_be :valid?
18
+ end
19
+
20
+ it "must be able to set AR data in init block" do
21
+ m = Munger::Data.new do |d|
22
+ d.data = test_ar_data
23
+ end
24
+ m.must_be :valid?
25
+ end
26
+ #
27
+ it "must be able to add more data after init" do
28
+ m = Munger::Data.new
29
+ m.data = test_ar_data
30
+ m.add_data more_test_data
31
+ m.must_be :valid?
32
+ additional_names = m.data.select { |r| r[:name] == 'David' || r[:name] == 'Michael' }
33
+ additional_names.size.must_equal(4)
34
+ end
35
+
36
+
37
+ it "must be able to extract columns from AR data" do
38
+ @titles = @data.columns
39
+ @titles.size.must_equal(4)
40
+ @titles.must_include(:name)
41
+ @titles.must_include(:score)
42
+ @titles.must_include(:age)
43
+ end
44
+
45
+ it "must be able to add a new column with a default value" do
46
+ @data.add_column('new_column', :default => 1)
47
+ @data.data.first['new_column'].must_equal(1)
48
+ @data.must_be :valid?
49
+ end
50
+
51
+ it "must be able to add a new column with a block" do
52
+ @data.add_column('new_column') { |c| c.age + 1 }
53
+ @data.data.first['new_column'].must_equal(24)
54
+ @data.must_be :valid?
55
+ end
56
+
57
+ it "must be able to add multiple new columns with defaults" do
58
+ @data.add_column(['col1', 'col2'], :default => [1, 2])
59
+ @data.data.first['col1'].must_equal(1)
60
+ @data.data.first['col2'].must_equal(2)
61
+ @data.must_be :valid?
62
+ end
63
+
64
+
65
+ it "must be able to add multiple new columns with a block" do
66
+ @data.add_column(['col1', 'col2']) { |c| [c.age * 2, c.score * 3]}
67
+ @data.data.first['col1'].must_equal(46)
68
+ @data.data.first['col2'].must_equal(36)
69
+ @data.must_be :valid?
70
+ end
71
+
72
+ it "must work with add_columns, too" do
73
+ @data.add_columns(['col1', 'col2'], :default => [1, 2])
74
+ @data.data.first['col1'].must_equal(1)
75
+ @data.data.first['col2'].must_equal(2)
76
+ @data.must_be :valid?
77
+ end
78
+
79
+ it "must be able to transform a column" do
80
+ @data.data.first[:age].must_equal(23)
81
+ @data.transform_column(:age) { |c| c.age * 2 }
82
+ @data.data.first[:age].must_equal(46)
83
+ @data.must_be :valid?
84
+ end
85
+
86
+ it "must be able to transform multiple rows" do
87
+ @data.data.first[:age].must_equal(23)
88
+ @data.data.first[:score].must_equal(12)
89
+ @data.transform_columns([:age, :score]) { |c| [c.age * 2, c.score * 3] }
90
+ @data.data.first[:age].must_equal(46)
91
+ @data.data.first[:score].must_equal(36)
92
+ @data.must_be :valid?
93
+ end
94
+
95
+ it "must be able to filter the data down" do
96
+ orig_size = @data.size
97
+ @data.filter_rows { |r| r.age < 30 }
98
+ @data.size.must_be :<, orig_size
99
+ @data.size.must_equal(4)
100
+ @data.must_be :valid?
101
+ end
102
+
103
+ it "must be able to pivot the data (1 column)" do
104
+ orig_size = @data.size
105
+ new_keys = @data.pivot(:day, :name, :score)
106
+ @data.size.must_be :<, orig_size
107
+ new_keys.must_include(1)
108
+ new_keys.must_include(2)
109
+ scott = @data.data.select { |r| r.name == 'Scott' }.first
110
+ scott[1].must_equal(43)
111
+ @data.must_be :valid?
112
+ end
113
+
114
+ it "must be able to pivot the data with average aggregation" do
115
+ new_keys = @data.pivot(:day, :name, :score, :average)
116
+ new_keys.must_include(1)
117
+ new_keys.must_include(2)
118
+ scott = @data.data.select { |r| r.name == 'Scott' }.first
119
+ scott[1].must_equal(21)
120
+ @data.must_be :valid?
121
+ end
122
+
123
+ it "must be able to pivot the data with count aggregation" do
124
+ new_keys = @data.pivot(:day, :name, :score, :count)
125
+ scott = @data.data.select { |r| r.name == 'Scott' }.first
126
+ scott[1].must_equal(2)
127
+ @data.must_be :valid?
128
+ end
129
+
130
+ it "must be able to pivot the data in three dimensions (1 col, 2 row)" do
131
+ new_keys = @data.pivot(:name, [:score, :age], :score, :count)
132
+ alice = @data.data.select { |r| r.name == 'Alice' }.first
133
+ alice.Alice.must_equal(2)
134
+ @data.must_be :valid?
135
+ end
136
+
137
+
138
+ it "must be able to add a column then pivot the data (1 column)" do
139
+ @data.add_column(:day_of_week) { |c| Date::DAYNAMES[c.day] }
140
+ @data.add_column(:name_length) { |c| c.name.length }
141
+ orig_size = @data.size
142
+ new_keys = @data.pivot(:day_of_week, :name, :score)
143
+ @data.size.must_be :<, orig_size
144
+ new_keys.must_include("Monday")
145
+ new_keys.must_include("Tuesday")
146
+ alice = @data.data.select { |r| r.name == 'Alice' }.first
147
+ alice["Monday"].must_equal(12)
148
+ alice["Tuesday"].must_equal(24)
149
+ @data.must_be :valid?
150
+ end
151
+
152
+
153
+ # like sql group command, give aggregation block
154
+ it "must be able to group the data like sql" do
155
+ @data.group(:name)
156
+ @data.size.must_equal(6)
157
+ @data.must_be :valid?
158
+ end
159
+
160
+ it "must be able to group on multiple columns" do
161
+ @data.group([:age, :score], :count => :day, :sum => :day, :average => :score)
162
+ alice = @data.data.select { |r| (r.score == 12) && (r.age == 33)}.first
163
+ alice.count_day.must_equal(2)
164
+ alice.sum_day.must_equal(3)
165
+ alice.average_day.must_equal(nil)
166
+ @data.must_be :valid?
167
+ end
168
+
169
+ it "must be able to group with a proc aggregation" do
170
+ pr = Proc.new {|arr| arr.inject(0) { |a,b| a + (b*2) }}
171
+ @data.group([:age, :score], :sum => :day, ['test', pr] => :age)
172
+ alice = @data.data.select { |r| (r.score == 12) && (r.age == 33)}.first
173
+ alice.test_age.must_equal(132)
174
+ alice.sum_day.must_equal(3)
175
+ @data.must_be :valid?
176
+ end
177
+
178
+ it "must be able to output an array" do
179
+ array = @data.to_a
180
+ array.must_be_kind_of(Array)
181
+ array.first.size.must_equal(@data.columns.size)
182
+ @data.must_be :valid?
183
+ end
184
+
185
+ it "must be able to output a filtered array" do
186
+ array = @data.to_a([:name, :age])
187
+ array.must_be_kind_of(Array)
188
+ array.first.size.must_equal(2)
189
+ scotts = array.select { |a| a.include?('Scott') }
190
+ scotts.first.must_include('Scott')
191
+ scotts.first.must_include(23)
192
+ @data.must_be :valid?
193
+ end
194
+ end
@@ -0,0 +1,185 @@
1
+ require "test_helper"
2
+
3
+ describe Munger::Data do
4
+ include MungerSpecHelper
5
+
6
+ before(:each) do
7
+ @data = Munger::Data.new(:data => test_data)
8
+ end
9
+
10
+ it "must accept an array of hashes" do
11
+ Munger::Data.new(:data => test_data).must_be :valid?
12
+ end
13
+
14
+ it "must be able to set data after init" do
15
+ m = Munger::Data.new
16
+ m.data = test_data
17
+ m.must_be :valid?
18
+ end
19
+
20
+ it "must be able to set data in init block" do
21
+ m = Munger::Data.new do |d|
22
+ d.data = test_data
23
+ end
24
+ m.must_be :valid?
25
+ end
26
+
27
+ it "must be able to add more data after init" do
28
+ m = Munger::Data.new
29
+ m.data = test_data
30
+ m.add_data more_test_data
31
+ m.must_be :valid?
32
+ additional_names = m.data.select { |r| r[:name] == 'David' || r[:name] == 'Michael' }
33
+ additional_names.size.must_equal(4)
34
+ end
35
+
36
+ it "must be able to add data without initial data" do
37
+ m = Munger::Data.new
38
+ m.add_data more_test_data
39
+ m.must_be :valid?
40
+ m.size.must_equal(4)
41
+ end
42
+
43
+ it "must be able to extract columns from data" do
44
+ @titles = @data.columns
45
+ @titles.size.must_equal(4)
46
+ @titles.must_include(:name)
47
+ @titles.must_include(:score)
48
+ @titles.must_include(:age)
49
+ end
50
+
51
+ it "must be able to add a new column with a default value" do
52
+ @data.add_column('new_column', :default => 1)
53
+ @data.data.first['new_column'].must_equal(1)
54
+ end
55
+
56
+ it "must be able to add a new column with a block" do
57
+ @data.add_column('new_column') { |c| c.age + 1 }
58
+ @data.data.first['new_column'].must_equal(24)
59
+ end
60
+
61
+ it "must be able to add multiple new columns with defaults" do
62
+ @data.add_column(['col1', 'col2'], :default => [1, 2])
63
+ @data.data.first['col1'].must_equal(1)
64
+ @data.data.first['col2'].must_equal(2)
65
+ end
66
+
67
+ it "must be able to add multiple new columns with a block" do
68
+ @data.add_column(['col1', 'col2']) { |c| [c.age * 2, c.score * 3]}
69
+ @data.data.first['col1'].must_equal(46)
70
+ @data.data.first['col2'].must_equal(36)
71
+ end
72
+
73
+ it "must work with add_columns, too" do
74
+ @data.add_columns(['col1', 'col2'], :default => [1, 2])
75
+ @data.data.first['col1'].must_equal(1)
76
+ @data.data.first['col2'].must_equal(2)
77
+ end
78
+
79
+ it "must be able to transform a column" do
80
+ @data.data.first[:age].must_equal(23)
81
+ @data.transform_column(:age) { |c| c.age * 2 }
82
+ @data.data.first[:age].must_equal(46)
83
+ end
84
+
85
+ it "must be able to transform multiple rows" do
86
+ @data.data.first[:age].must_equal(23)
87
+ @data.data.first[:score].must_equal(12)
88
+ @data.transform_columns([:age, :score]) { |c| [c.age * 2, c.score * 3] }
89
+ @data.data.first[:age].must_equal(46)
90
+ @data.data.first[:score].must_equal(36)
91
+ end
92
+
93
+ it "must be able to filter the data down" do
94
+ orig_size = @data.size
95
+ @data.filter_rows { |r| r.age < 30 }
96
+ @data.size.must_be :<, orig_size
97
+ @data.size.must_equal(4)
98
+ end
99
+
100
+ it "must be able to pivot the data (1 column)" do
101
+ orig_size = @data.size
102
+ new_keys = @data.pivot(:day, :name, :score)
103
+ @data.size.must_be :<, orig_size
104
+ new_keys.must_include(1, 2)
105
+ scott = @data.data.select { |r| r.name == 'Scott' }.first
106
+ scott[1].must_equal(43)
107
+ end
108
+
109
+ it "must be able to pivot the data with average aggregation" do
110
+ new_keys = @data.pivot(:day, :name, :score, :average)
111
+ new_keys.must_include(1, 2)
112
+ scott = @data.data.select { |r| r.name == 'Scott' }.first
113
+ scott[1].must_equal(21)
114
+ end
115
+
116
+ it "must be able to pivot the data with count aggregation" do
117
+ new_keys = @data.pivot(:day, :name, :score, :count)
118
+ scott = @data.data.select { |r| r.name == 'Scott' }.first
119
+ scott[1].must_equal(2)
120
+ end
121
+
122
+ it "must be able to pivot the data in three dimensions (1 col, 2 row)" do
123
+ new_keys = @data.pivot(:name, [:score, :age], :score, :count)
124
+ alice = @data.data.select { |r| r.name == 'Alice' }.first
125
+ alice.Alice.must_equal(2)
126
+ end
127
+
128
+ it "must be able to add a column then pivot the data (1 column)" do
129
+ @data.add_column(:day_of_week) { |c| Date::DAYNAMES[c.day] }
130
+ orig_size = @data.size
131
+ new_keys = @data.pivot(:day_of_week, :name, :score)
132
+ @data.size.must_be :<, orig_size
133
+ new_keys.must_include("Monday", "Tuesday")
134
+ alice = @data.data.select { |r| r.name == 'Alice' }.first
135
+ alice["Monday"].must_equal(12)
136
+ alice["Tuesday"].must_equal(24)
137
+ end
138
+
139
+ # like sql group command, give aggregation block
140
+ it "must be able to group the data like sql" do
141
+ @data.group(:name)
142
+ @data.size.must_equal(6)
143
+ end
144
+
145
+ it "must be able to group on multiple columns" do
146
+ @data.group([:age, :score], :count => :day, :sum => :day, :average => :score)
147
+ alice = @data.data.select { |r| (r.score == 12) && (r.age == 33)}.first
148
+ alice.count_day.must_equal(2)
149
+ alice.sum_day.must_equal(3)
150
+ alice.average_day.must_equal(nil)
151
+ end
152
+
153
+ it "must be able to group with a proc aggregation" do
154
+ pr = Proc.new {|arr| arr.inject(0) { |a,b| a + (b*2) }}
155
+ @data.group([:age, :score], :sum => :day, ['test', pr] => :age)
156
+ alice = @data.data.select { |r| (r.score == 12) && (r.age == 33)}.first
157
+ alice.test_age.must_equal(132)
158
+ alice.sum_day.must_equal(3)
159
+ end
160
+
161
+ it "must be able to output an array" do
162
+ array = @data.to_a
163
+ array.must_be_kind_of(Array)
164
+ array.first.size.must_equal(@data.columns.size)
165
+ end
166
+
167
+ it "must be able to output a filtered array" do
168
+ array = @data.to_a([:name, :age])
169
+ array.must_be_kind_of(Array)
170
+ array.first.size.must_equal(2)
171
+ scotts = array.select { |a| a.include?('Scott') }
172
+ scotts.first.must_include('Scott', 23)
173
+ end
174
+
175
+ it "must be able to pivot the data in three dimensions (2 col, 1 row)"
176
+
177
+ it "must be able to pivot the data in four dimensions (2 col, 2 row)"
178
+
179
+ it "must be able to add two Munger::Datas together if they have the same columns"
180
+
181
+ it "must be able to add data and check if it is Munger::Data"
182
+
183
+ it "(maybe) must be able to zip two Munger::Datas together given a unique key column in each"
184
+
185
+ end