active_olap 0.0.2

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/test/helper.rb ADDED
@@ -0,0 +1,115 @@
1
+ $:.reject! { |e| e.include? 'TextMate' }
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'active_record'
6
+
7
+ require "#{File.dirname(__FILE__)}/../lib/active_olap"
8
+ require "#{File.dirname(__FILE__)}/../lib/active_olap/test/assertions"
9
+
10
+ module ActiveOlapTestHelper
11
+
12
+ def self.included(base)
13
+ base.send :include, ActiveOLAP::Test::Assertions
14
+ end
15
+
16
+ def create_db
17
+
18
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
19
+
20
+ ActiveRecord::Schema.define(:version => 1) do
21
+ create_table :olap_tests do |t|
22
+ t.string :string_field
23
+ t.integer :int_field
24
+ t.string :category_field
25
+ t.datetime :datetime_field
26
+ t.integer :olap_category_id
27
+ t.timestamps
28
+ end
29
+
30
+ create_table :olap_associations do |t|
31
+ t.integer :olap_test_id
32
+ t.string :category
33
+ t.float :price
34
+ t.timestamps
35
+ end
36
+
37
+ create_table :olap_categories do |t|
38
+ t.string :category
39
+ end
40
+ end
41
+ end
42
+
43
+ def create_corpus
44
+
45
+ category_1 = OlapCategory.create(:category => 'first')
46
+ category_2 = OlapCategory.create(:category => 'second')
47
+
48
+ OlapTest.create!({ :string_field => '123', :int_field => 33, :category_field => 'first_cat', :datetime_field => 2.day.ago, :olap_category => category_1})
49
+ OlapTest.create!({ :string_field => '123', :int_field => 44, :category_field => 'second_cat', :datetime_field => nil, :olap_category => category_2 })
50
+ OlapTest.create!({ :string_field => '', :int_field => 33, :category_field => 'second_cat', :datetime_field => 4.days.ago, :olap_category => category_2 })
51
+ with_assocs = OlapTest.create!({ :string_field => '12', :int_field => 33, :category_field => nil, :datetime_field => nil })
52
+
53
+ with_assocs.olap_associations.create!({:category => 'first', :price => 1.2})
54
+ with_assocs.olap_associations.create!({:category => 'first', :price => 1.2})
55
+ with_assocs.olap_associations.create!({:category => 'second', :price => 1.4})
56
+ with_assocs.olap_associations.create!({:category => 'second', :price => 0.7})
57
+ with_assocs.olap_associations.create!({:category => nil, :price => 0.7})
58
+ with_assocs.olap_associations.create!({:category => 'third', :price => 0.5})
59
+ end
60
+
61
+ def cleanup_db
62
+ ActiveRecord::Base.connection.tables.each do |table|
63
+ ActiveRecord::Base.connection.drop_table(table)
64
+ end
65
+ end
66
+ end
67
+
68
+ class OlapTest < ActiveRecord::Base
69
+
70
+ belongs_to :olap_category
71
+ has_many :olap_associations
72
+ named_scope :int_field_33, :conditions => {:int_field => 33}
73
+
74
+ enable_active_olap do |olap|
75
+
76
+ olap.dimension :category, :categories => [
77
+ [:first_cat, { :category_field => 'first_cat' }],
78
+ [:second_cat, { :category_field => 'second_cat' }],
79
+ [:third_cat, { :category_field => 'third_cat' }],
80
+ [:no_category, { :category_field => nil }]
81
+ ]
82
+
83
+ olap.dimension :my_trend, lambda { {:trend => {
84
+ :timestamp_field => :datetime_field,
85
+ :period_count => 20,
86
+ :period_length => 1.day,
87
+ :trend_end => Time.now.midnight
88
+ } } }
89
+
90
+ olap.time_dimension :the_time, :datetime_field, {:period_count => 20, :period_length => 1.day}
91
+
92
+ olap.dimension :with_overlap, :overlap => true, :categories => {
93
+ :starts_with_1 => "string_field LIKE '1%'",
94
+ :like_23 => "string_field LIKE '%23%'"
95
+ }
96
+
97
+ olap.dimension :in_association, :overlap => true, :categories => {
98
+ :first => { :olap_associations => { :category => 'first' } },
99
+ :second => { :olap_associations => { :category => 'second' } }
100
+ }, :joins => [:olap_associations]
101
+
102
+ olap.aggregate :sum_int, :sum_int_field
103
+ olap.aggregate :avg_int_field
104
+ olap.aggregate :total_price, 'SUM(olap_associations.price)', :joins => [:olap_associations] #'LEFT JOIN olap_associations ON olap_associations.olap_test_id = olap_tests.id'
105
+ end
106
+
107
+ end
108
+
109
+ class OlapAssociation < ActiveRecord::Base
110
+ belongs_to :olap_test
111
+ end
112
+
113
+ class OlapCategory < ActiveRecord::Base
114
+ has_many :olap_tests
115
+ end
@@ -0,0 +1,65 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+
3
+ require 'action_view'
4
+
5
+ class ActiveOLAP::HelperTest < Test::Unit::TestCase
6
+
7
+ include ActiveOlapTestHelper
8
+
9
+ # include some helper modules from ActionView
10
+ include ActionView::Helpers::CaptureHelper
11
+ include ActionView::Helpers::TagHelper
12
+
13
+ # include the Active OLAP helper functions
14
+ include ActiveOLAP::Helpers::TableHelper
15
+
16
+ attr_accessor :output_buffer
17
+
18
+ def setup
19
+ create_db && create_corpus
20
+ end
21
+
22
+ def teardown
23
+ cleanup_db
24
+ end
25
+
26
+
27
+ def test_1d_table
28
+ cube = OlapTest.olap_query(:category_field)
29
+ assert_active_olap_cube cube, [:unknown]
30
+ puts active_olap_table(cube)
31
+
32
+ cube = OlapTest.olap_query(:with_overlap)
33
+ assert_active_olap_cube cube, [:unknown]
34
+ puts active_olap_table(cube)
35
+
36
+ cube = OlapTest.olap_query(:category_field, :aggregate => [:count_distinct, :avg_int_field])
37
+ assert_active_olap_cube cube, [:unknown]
38
+ puts active_olap_table(cube)
39
+ end
40
+
41
+ def test_2d_table
42
+ cube = OlapTest.olap_query(:category_field, :my_trend)
43
+ assert_active_olap_cube cube, 2
44
+
45
+ table = active_olap_matrix(cube)
46
+ puts table
47
+ end
48
+
49
+ def test_multi_dimensional_table
50
+ cube = OlapTest.olap_query(:category_field, :my_trend, :aggregate => [:count_distinct, :avg_int_field])
51
+ assert_active_olap_cube cube, 2
52
+ puts active_olap_table(cube)
53
+
54
+ cube = OlapTest.olap_query(:category_field, :with_overlap)
55
+ assert_active_olap_cube cube, 2
56
+ puts active_olap_table(cube)
57
+
58
+ cube = OlapTest.olap_query(:category_field, :my_trend, :with_overlap)
59
+ assert_active_olap_cube cube, 3
60
+ puts active_olap_table(cube)
61
+
62
+ end
63
+
64
+
65
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_olap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Willem van Bergen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-23 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Extends ActiveRecord with functionality to perform OLAP queries on your data. Includes helper method to ease displaying the results.
17
+ email:
18
+ - willem@vanbergen.org
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - test/helper_modules_test.rb
27
+ - spec/spec_helper.rb
28
+ - .gitignore
29
+ - lib/active_olap/helpers/table_helper.rb
30
+ - lib/active_olap/dimension.rb
31
+ - test/active_olap_test.rb
32
+ - lib/active_olap/helpers/display_helper.rb
33
+ - init.rb
34
+ - README.textile
35
+ - spec/integration/active_olap_spec.rb
36
+ - lib/active_olap/test/assertions.rb
37
+ - lib/active_olap/category.rb
38
+ - active_olap.gemspec
39
+ - Rakefile
40
+ - MIT-LICENSE
41
+ - tasks/github-gem.rake
42
+ - lib/active_olap.rb
43
+ - test/helper.rb
44
+ - lib/active_olap/helpers/form_helper.rb
45
+ - lib/active_olap/aggregate.rb
46
+ - spec/unit/cube_spec.rb
47
+ - lib/active_olap/helpers/chart_helper.rb
48
+ - lib/active_olap/cube.rb
49
+ - lib/active_olap/configurator.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/wvanbergen/active_olap/wikis
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Extend ActiveRecord with OLAP query functionality
78
+ test_files:
79
+ - test/helper_modules_test.rb
80
+ - test/active_olap_test.rb
81
+ - spec/integration/active_olap_spec.rb
82
+ - spec/unit/cube_spec.rb