report_cat 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +147 -0
- data/Rakefile +24 -0
- data/app/assets/javascripts/report_cat/application.js +13 -0
- data/app/assets/stylesheets/report_cat/application.css +13 -0
- data/app/controllers/report_cat/reports_controller.rb +43 -0
- data/app/helpers/report_cat/reports_helper.rb +132 -0
- data/app/models/report_cat/date_range.rb +94 -0
- data/app/views/report_cat/reports/_google_charts.html.erb +61 -0
- data/app/views/report_cat/reports/index.html.erb +2 -0
- data/app/views/report_cat/reports/show.html.erb +15 -0
- data/config/locales/en.yml +26 -0
- data/config/routes.rb +7 -0
- data/db/migrate/20130918075200_create_date_ranges.rb +13 -0
- data/lib/report_cat/config.rb +30 -0
- data/lib/report_cat/core/chart.rb +50 -0
- data/lib/report_cat/core/column.rb +70 -0
- data/lib/report_cat/core/param.rb +35 -0
- data/lib/report_cat/core/report.rb +127 -0
- data/lib/report_cat/engine.rb +11 -0
- data/lib/report_cat/matchers/have_chart.rb +58 -0
- data/lib/report_cat/matchers/have_column.rb +45 -0
- data/lib/report_cat/matchers/have_param.rb +52 -0
- data/lib/report_cat/reports/cohort_report.rb +113 -0
- data/lib/report_cat/reports/date_range_report.rb +66 -0
- data/lib/report_cat/version.rb +3 -0
- data/lib/report_cat.rb +39 -0
- data/lib/tasks/report_cat.rake +4 -0
- data/spec/controllers/report_cat/reports_controller_spec.rb +100 -0
- data/spec/coverage_spec.rb +18 -0
- data/spec/data/helpers/report_charts.html +1 -0
- data/spec/data/helpers/report_charts.html.tmp +1 -0
- data/spec/data/helpers/report_form.html +63 -0
- data/spec/data/helpers/report_form.html.tmp +63 -0
- data/spec/data/helpers/report_form_param.html +1 -0
- data/spec/data/helpers/report_form_param.html.tmp +1 -0
- data/spec/data/helpers/report_list.html +1 -0
- data/spec/data/helpers/report_list.html.tmp +1 -0
- data/spec/data/helpers/report_param_checkbox.html +1 -0
- data/spec/data/helpers/report_param_checkbox.html.tmp +1 -0
- data/spec/data/helpers/report_param_date.html +60 -0
- data/spec/data/helpers/report_param_date.html.tmp +60 -0
- data/spec/data/helpers/report_param_hidden.html +1 -0
- data/spec/data/helpers/report_param_hidden.html.tmp +1 -0
- data/spec/data/helpers/report_param_select.html +3 -0
- data/spec/data/helpers/report_param_select.html.tmp +3 -0
- data/spec/data/helpers/report_param_text_field.html +1 -0
- data/spec/data/helpers/report_param_text_field.html.tmp +1 -0
- data/spec/data/helpers/report_table.html +1 -0
- data/spec/data/helpers/report_table.html.tmp +1 -0
- data/spec/data/helpers/report_table_hidden.html +1 -0
- data/spec/data/helpers/report_table_hidden.html.tmp +1 -0
- data/spec/data/lib/chart_columns.json +1 -0
- data/spec/data/lib/chart_columns.json.tmp +1 -0
- data/spec/data/lib/chart_data.json +1 -0
- data/spec/data/lib/chart_data.json.tmp +1 -0
- data/spec/data/lib/date_range_report_where.sql +6 -0
- data/spec/data/lib/date_range_report_where.sql.tmp +6 -0
- data/spec/data/lib/report.csv +3 -0
- data/spec/data/lib/report.csv.tmp +3 -0
- data/spec/data/lib/report.sql +1 -0
- data/spec/data/lib/report.sql.tmp +1 -0
- data/spec/data/models/sql_intersect.sql +5 -0
- data/spec/data/models/sql_intersect.sql.tmp +5 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +21 -0
- data/spec/dummy/app/controllers/root_controller.rb +20 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +13 -0
- data/spec/dummy/app/models/visit.rb +16 -0
- data/spec/dummy/app/reports/retention_cohort_report.rb +19 -0
- data/spec/dummy/app/reports/retention_report.rb +30 -0
- data/spec/dummy/app/reports/user_report.rb +23 -0
- data/spec/dummy/app/views/layouts/admin.html.erb +19 -0
- data/spec/dummy/app/views/layouts/application.html.erb +19 -0
- data/spec/dummy/app/views/root/index.html.erb +8 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +31 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/report_cat.rb +15 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +38 -0
- data/spec/dummy/config/routes.rb +13 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +26 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +61 -0
- data/spec/dummy/log/test.log +26478 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/helpers/report_cat/reports_helper_spec.rb +224 -0
- data/spec/lib/report_cat/config_spec.rb +96 -0
- data/spec/lib/report_cat/core/chart_spec.rb +67 -0
- data/spec/lib/report_cat/core/column_spec.rb +156 -0
- data/spec/lib/report_cat/core/param_spec.rb +95 -0
- data/spec/lib/report_cat/core/report_spec.rb +342 -0
- data/spec/lib/report_cat/engine_spec.rb +9 -0
- data/spec/lib/report_cat/matchers/have_chart_spec.rb +36 -0
- data/spec/lib/report_cat/matchers/have_column_spec.rb +30 -0
- data/spec/lib/report_cat/matchers/have_param_spec.rb +33 -0
- data/spec/lib/report_cat/reports/cohort_report_spec.rb +215 -0
- data/spec/lib/report_cat/reports/date_range_report_spec.rb +125 -0
- data/spec/lib/report_cat/version_spec.rb +11 -0
- data/spec/lib/report_cat_spec.rb +62 -0
- data/spec/lib/tasks/report_cat.rake_spec.rb +13 -0
- data/spec/models/report_cat/date_range_spec.rb +144 -0
- data/spec/rails_helper.rb +49 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/setup_reports.rb +28 -0
- data/spec/views/report_cat/reports/index.html.erb_spec.rb +16 -0
- data/spec/views/report_cat/reports/show.html.erb_spec.rb +19 -0
- metadata +489 -0
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include ReportCat::Core
|
4
|
+
|
5
|
+
module ReportCat::Core
|
6
|
+
|
7
|
+
describe Column do
|
8
|
+
|
9
|
+
before( :each ) do
|
10
|
+
@name = :test
|
11
|
+
@type = :select
|
12
|
+
@options = { :sql => 'max( something )' }
|
13
|
+
end
|
14
|
+
|
15
|
+
#############################################################################
|
16
|
+
# #initialize
|
17
|
+
|
18
|
+
describe '#initialize' do
|
19
|
+
|
20
|
+
it 'initializes accessor values' do
|
21
|
+
column = Column.new( :name => @name, :type => @type, :options => @options )
|
22
|
+
expect( column.name ).to eql( @name )
|
23
|
+
expect( column.type ).to eql( @type )
|
24
|
+
expect( column.options ).to eql( @options )
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
#############################################################################
|
30
|
+
# #format
|
31
|
+
|
32
|
+
describe '#format' do
|
33
|
+
|
34
|
+
it 'formats floats' do
|
35
|
+
value = 22.0 / 7.0
|
36
|
+
expected = ("%.2f" % value).to_f
|
37
|
+
column = Column.new( :name => @name, :type => :float )
|
38
|
+
expect( column.format( value ) ).to eql( expected )
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it 'formats integers' do
|
43
|
+
value = '727'
|
44
|
+
expected = value.to_i
|
45
|
+
column = Column.new( :name => @name, :type => :integer )
|
46
|
+
expect( column.format( value ) ).to eql( expected )
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'passes everything else through' do
|
51
|
+
value = '727'
|
52
|
+
column = Column.new( :name => @name, :type => :string )
|
53
|
+
expect( column.format( value ) ).to eql( value )
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
#############################################################################
|
59
|
+
# #post_process
|
60
|
+
|
61
|
+
describe '#post_process' do
|
62
|
+
|
63
|
+
before( :each ) do
|
64
|
+
@report = Report.new
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'handles moving averages' do
|
68
|
+
column = Column.new( :name => @name, :type => :moving_average )
|
69
|
+
expect( column ).to receive( :post_process_moving_average ).with( @report )
|
70
|
+
column.post_process( @report )
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'handles ratios' do
|
74
|
+
column = Column.new( :name => @name, :type => :ratio )
|
75
|
+
expect( column ).to receive( :post_process_ratio ).with( @report )
|
76
|
+
column.post_process( @report )
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
#############################################################################
|
82
|
+
# #post_process_moving_average
|
83
|
+
|
84
|
+
describe '#post_process_moving_average' do
|
85
|
+
|
86
|
+
it 'fills in moving average values' do
|
87
|
+
@report = Report.new
|
88
|
+
@report.add_column( :value, :integer )
|
89
|
+
|
90
|
+
@report.rows[ 0 ] = [ 1, 0 ]
|
91
|
+
@report.rows[ 1 ] = [ 2, 0 ]
|
92
|
+
@report.rows[ 2 ] = [ 4, 0 ]
|
93
|
+
|
94
|
+
column = @report.add_column( :ma, :moving_average, :target => :value, :interval => 2 )
|
95
|
+
column.post_process( @report )
|
96
|
+
|
97
|
+
expect( @report.rows[ 0 ][ 1 ] ).to eql( 0 )
|
98
|
+
expect( @report.rows[ 1 ][ 1 ] ).to eql( 1.5 )
|
99
|
+
expect( @report.rows[ 2 ][ 1 ] ).to eql( 3.0 )
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
#############################################################################
|
105
|
+
# #post_process_moving_average
|
106
|
+
|
107
|
+
describe '#post_process_ratio' do
|
108
|
+
|
109
|
+
it 'fills in ratio values' do
|
110
|
+
@report = Report.new
|
111
|
+
@report.add_column( :n, :integer )
|
112
|
+
@report.add_column( :d, :integer )
|
113
|
+
|
114
|
+
@report.rows[ 0 ] = [ 1, 2, 0 ]
|
115
|
+
@report.rows[ 1 ] = [ 3, 4, 0 ]
|
116
|
+
@report.rows[ 2 ] = [ 4, 0, 0 ]
|
117
|
+
|
118
|
+
column = @report.add_column( :r, :ratio, :numerator => :n, :denominator => :d )
|
119
|
+
column.post_process( @report )
|
120
|
+
|
121
|
+
expect( @report.rows[ 0 ][ 2 ] ).to eql( 0.5 )
|
122
|
+
expect( @report.rows[ 1 ][ 2 ] ).to eql( 0.75 )
|
123
|
+
expect( @report.rows[ 2 ][ 2 ] ).to eql( 0.0 )
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
#############################################################################
|
129
|
+
# #to_sql
|
130
|
+
|
131
|
+
describe '#to_sql' do
|
132
|
+
|
133
|
+
it 'uses raw sql if provided in options' do
|
134
|
+
sql = 'count( id )'
|
135
|
+
column = Column.new( :name => @name, :type => :integer, :options => { :sql => sql } )
|
136
|
+
expect( column.to_sql ).to eql( "#{sql} as #{@name}" )
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
it 'uses 0 for calculated columns' do
|
141
|
+
column = Column.new( :name => @name, :type => :moving_average )
|
142
|
+
expect( column.to_sql ).to eql( "0 as #{@name}" )
|
143
|
+
|
144
|
+
column = Column.new( :name => @name, :type => :ratio )
|
145
|
+
expect( column.to_sql ).to eql( "0 as #{@name}" )
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'uses the column name as a last resort' do
|
149
|
+
column = Column.new( :name => @name, :type => :integer )
|
150
|
+
expect( column.to_sql ).to eql( @name )
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include ReportCat::Core
|
4
|
+
|
5
|
+
module ReportCat::Core
|
6
|
+
|
7
|
+
describe Param do
|
8
|
+
|
9
|
+
let( :param ) { Param.new }
|
10
|
+
|
11
|
+
before( :each ) do
|
12
|
+
@name = :test
|
13
|
+
@type = :select
|
14
|
+
@value = 727
|
15
|
+
@options = [ 314, 727 ]
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'initialize' do
|
19
|
+
|
20
|
+
it 'initializes accessor values' do
|
21
|
+
param = Param.new( :name => @name, :type => @type, :value => @value, :options => @options )
|
22
|
+
expect( param.name ).to eql( @name )
|
23
|
+
expect( param.type ).to eql( @type )
|
24
|
+
expect( param.value ).to eql( @value )
|
25
|
+
expect( param.options ).to eql( @options )
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'initializes options to an empty hash' do
|
29
|
+
expect( param.options ).to eql( {} )
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'assigning value' do
|
35
|
+
|
36
|
+
it 'turns checkboxes into booleans' do
|
37
|
+
param = Param.new( :name => :foo, :type => :check_box )
|
38
|
+
expect( param.value ).to be_nil
|
39
|
+
param.value = '1'
|
40
|
+
expect( param.value ).to be( true )
|
41
|
+
param.value = '0'
|
42
|
+
expect( param.value ).to be( false )
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'accepts checkboxes as booleans' do
|
46
|
+
param = Param.new( :name => :foo, :type => :check_box )
|
47
|
+
expect( param.value ).to be_nil
|
48
|
+
param.value = true
|
49
|
+
expect( param.value ).to be( true )
|
50
|
+
param.value = false
|
51
|
+
expect( param.value ).to be( false )
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'accepts checkboxes as strings' do
|
55
|
+
param = Param.new( :name => :foo, :type => :check_box )
|
56
|
+
expect( param.value ).to be_nil
|
57
|
+
param.value = 'true'
|
58
|
+
expect( param.value ).to be( true )
|
59
|
+
param.value = 'false'
|
60
|
+
expect( param.value ).to be( false )
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'parses date hashes' do
|
64
|
+
param = Param.new( :name => :foo, :type => :date )
|
65
|
+
param.value = { :year => '2013', :month => '9', :day => '16' }
|
66
|
+
expect( param.value ).to eql( Date.civil( 2013, 9, 16 ) )
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'parses date strings' do
|
70
|
+
param = Param.new( :name => :foo, :type => :date )
|
71
|
+
param.value = '2013-09-16'
|
72
|
+
expect( param.value ).to eql( Date.civil( 2013, 9, 16 ) )
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'passes everything else through untouched' do
|
76
|
+
param = Param.new( :name => :foo, :type => :text_field )
|
77
|
+
param.value = '2013-09-16'
|
78
|
+
expect( param.value ).to eql( '2013-09-16' )
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#hide' do
|
84
|
+
|
85
|
+
it 'sets the hidden option to true' do
|
86
|
+
expect( param.options[ :hidden ] ).to be_nil
|
87
|
+
param.hide
|
88
|
+
expect( param.options[ :hidden ] ).to be( true )
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,342 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include ReportCat::Core
|
4
|
+
|
5
|
+
module ReportCat::Core
|
6
|
+
|
7
|
+
describe Report do
|
8
|
+
|
9
|
+
include SetupReports
|
10
|
+
|
11
|
+
before( :each ) do
|
12
|
+
@name = :test
|
13
|
+
@report = Report.new( :name => @name )
|
14
|
+
end
|
15
|
+
|
16
|
+
#############################################################################
|
17
|
+
# initialize
|
18
|
+
|
19
|
+
describe '#initialize' do
|
20
|
+
|
21
|
+
it 'initializes accessor values' do
|
22
|
+
expect( @report.name ).to eql( @name )
|
23
|
+
expect( @report.params ).to eql( [] )
|
24
|
+
expect( @report.columns ).to eql( [] )
|
25
|
+
expect( @report.rows ).to eql( [] )
|
26
|
+
expect( @report.charts ).to eql( [] )
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts arrays' do
|
30
|
+
array = [ 'a', 'b' ]
|
31
|
+
|
32
|
+
report = Report.new(
|
33
|
+
:from => array,
|
34
|
+
:joins => array,
|
35
|
+
:where => array,
|
36
|
+
:group_by => array,
|
37
|
+
:order_by => array
|
38
|
+
)
|
39
|
+
|
40
|
+
expect( report.from ).to eql( 'a,b' )
|
41
|
+
expect( report.joins ).to eql( 'a b' )
|
42
|
+
expect( report.where ).to eql( 'a and b' )
|
43
|
+
expect( report.group_by ).to eql( 'a,b' )
|
44
|
+
expect( report.order_by ).to eql( 'a,b' )
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
#############################################################################
|
50
|
+
# accept_array
|
51
|
+
|
52
|
+
describe '#accept_array' do
|
53
|
+
|
54
|
+
it 'joins arrays with the separator' do
|
55
|
+
expected = '1,2,3'
|
56
|
+
expect( @report.accept_array( [ '1', '2', '3' ], ',' ) ).to eql( expected )
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns non arrays' do
|
60
|
+
expect( @report.accept_array( 1, ',' ) ).to eql( 1 )
|
61
|
+
expect( @report.accept_array( :foo, ',' ) ).to eql( :foo )
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
#############################################################################
|
67
|
+
# add_chart
|
68
|
+
|
69
|
+
describe '#add_chart' do
|
70
|
+
|
71
|
+
it 'adds a chart' do
|
72
|
+
name = :i_like_pie
|
73
|
+
type = :pie
|
74
|
+
label = :label
|
75
|
+
values = [ :value_1, :value_2 ]
|
76
|
+
options = { :sweet => true }
|
77
|
+
|
78
|
+
expect( @report.charts ).to be_empty
|
79
|
+
@report.add_chart( name, type, label, values, options )
|
80
|
+
expect( @report.charts.size ).to eql( 1 )
|
81
|
+
|
82
|
+
chart = @report.charts.first
|
83
|
+
|
84
|
+
expect( chart ).to be_an_instance_of( Chart )
|
85
|
+
expect( chart.name ).to eql( name )
|
86
|
+
expect( chart.type ).to eql( type )
|
87
|
+
expect( chart.label ).to eql( label )
|
88
|
+
expect( chart.values ).to eql( values )
|
89
|
+
expect( chart.options ).to eql( options )
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
#############################################################################
|
95
|
+
# add_column
|
96
|
+
|
97
|
+
describe '#add_column' do
|
98
|
+
|
99
|
+
it 'adds a column' do
|
100
|
+
name = :foo
|
101
|
+
type = :integer
|
102
|
+
options = { :sql => 'count( 1 )' }
|
103
|
+
|
104
|
+
expect( @report.columns ).to be_empty
|
105
|
+
@report.add_column( name, type, options )
|
106
|
+
expect( @report.columns.size ).to eql( 1 )
|
107
|
+
|
108
|
+
column = @report.columns.first
|
109
|
+
expect( column.name ).to eql( name )
|
110
|
+
expect( column.type ).to eql( type )
|
111
|
+
expect( column.options ).to eql( options )
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
#############################################################################
|
117
|
+
# add_param
|
118
|
+
|
119
|
+
describe '#add_param' do
|
120
|
+
|
121
|
+
it 'adds a param' do
|
122
|
+
name = :foo
|
123
|
+
type = :integer
|
124
|
+
|
125
|
+
expect( @report.params ).to be_empty
|
126
|
+
@report.add_param( name, type )
|
127
|
+
expect( @report.params.size ).to eql( 1 )
|
128
|
+
|
129
|
+
param = @report.params.first
|
130
|
+
expect( param ).to be_an_instance_of( Param )
|
131
|
+
expect( param.name ).to eql( name )
|
132
|
+
expect( param.type ).to eql( type )
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
#############################################################################
|
138
|
+
# column
|
139
|
+
|
140
|
+
describe '#column' do
|
141
|
+
|
142
|
+
before( :each ) do
|
143
|
+
setup_reports
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'returns the named column' do
|
147
|
+
expect( @report.columns.size ).to be > 1
|
148
|
+
@report.columns.each_index do |i|
|
149
|
+
column = @report.columns[ i ]
|
150
|
+
expect( @report.column( column.name ) ).to eql( column )
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
it 'returns nil if it is unable to find the column' do
|
157
|
+
expect( @report.column( :does_not_exist ) ).to be_nil
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
#############################################################################
|
164
|
+
# column_index
|
165
|
+
|
166
|
+
describe '#column_index' do
|
167
|
+
|
168
|
+
before( :each ) do
|
169
|
+
setup_reports
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'returns the index of the named column' do
|
173
|
+
expect( @report.columns.size ).to be > 1
|
174
|
+
@report.columns.each_index do |i|
|
175
|
+
column = @report.columns[ i ]
|
176
|
+
expect( @report.column_index( column.name ) ).to eql( i )
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
it 'returns nil if it is unable to find the column' do
|
183
|
+
expect( @report.column_index( :does_not_exist ) ).to be_nil
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
#############################################################################
|
190
|
+
# generate
|
191
|
+
|
192
|
+
describe '#generate' do
|
193
|
+
|
194
|
+
before( :each ) do
|
195
|
+
setup_reports
|
196
|
+
allow( @report ).to receive( :query ).and_return( nil )
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'applies passed in options to params of the same name' do
|
200
|
+
expect( @report.param( :text_field_test ).value ).to be_nil
|
201
|
+
@report.generate( :text_field_test => 'foobar' )
|
202
|
+
expect( @report.param( :text_field_test ).value ).to eql( 'foobar' )
|
203
|
+
end
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
#############################################################################
|
208
|
+
# param
|
209
|
+
|
210
|
+
describe '#param' do
|
211
|
+
|
212
|
+
before( :each ) do
|
213
|
+
@param = @report.add_param( :foo, :integer )
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'finds a parameter by name' do
|
217
|
+
expect( @report.param( :foo ) ).to be( @param )
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'returns nil if it can not find it' do
|
221
|
+
expect( @report.param( :bar ) ).to be_nil
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
#############################################################################
|
227
|
+
# to_csv
|
228
|
+
|
229
|
+
describe '#to_csv' do
|
230
|
+
|
231
|
+
before( :each ) do
|
232
|
+
setup_reports
|
233
|
+
allow( @report ).to receive( :query ).and_return( nil )
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'generates CSV' do
|
237
|
+
expect( @report.to_csv ).to eql_file( 'spec/data/lib/report.csv' )
|
238
|
+
end
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
#############################################################################
|
243
|
+
# attributes
|
244
|
+
|
245
|
+
describe '#attributes' do
|
246
|
+
|
247
|
+
before( :each ) do
|
248
|
+
setup_reports
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'includes the name as both name and id' do
|
252
|
+
expect( @report.attributes[ :id ] ).to eql( @report.name )
|
253
|
+
expect( @report.attributes[ :name ] ).to eql( @report.name )
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'includes back if defined' do
|
257
|
+
back = @report.attributes
|
258
|
+
expect( @report.attributes.has_key?( :back ) ).to be( false )
|
259
|
+
@report.back = back
|
260
|
+
expect( @report.attributes[ :back ] ).to eql( back )
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'returns a hash of param names to values' do
|
264
|
+
@report.params.each do |param|
|
265
|
+
expect( @report.attributes[ param.name ] ).to eql( param.value )
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
#############################################################################
|
272
|
+
# query
|
273
|
+
|
274
|
+
describe '#query' do
|
275
|
+
|
276
|
+
before( :each ) do
|
277
|
+
setup_reports
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'initializes rows' do
|
281
|
+
@report.rows << []
|
282
|
+
expect( @report.rows.size ).to be > 0
|
283
|
+
|
284
|
+
expect( @report ).to receive( :to_sql ).and_return( nil )
|
285
|
+
allow( ActiveRecord::Base.connection ).to receive( :execute ).and_return( nil )
|
286
|
+
|
287
|
+
@report.send( :query )
|
288
|
+
expect( @report.rows.size ).to eql( 0 )
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'executes SQL against ActiveRecord' do
|
292
|
+
sql = 'foobar
|
293
|
+
'
|
294
|
+
expect( @report ).to receive( :to_sql ).and_return( sql )
|
295
|
+
expect( ActiveRecord::Base.connection ).to receive( :execute ).with( sql ).and_return( nil )
|
296
|
+
@report.send( :query )
|
297
|
+
end
|
298
|
+
|
299
|
+
it 'tolerates nil results from ActiveRecord' do
|
300
|
+
expect( @report ).to receive( :to_sql ).and_return( nil )
|
301
|
+
expect( ActiveRecord::Base.connection ).to receive( :execute ).and_return( nil )
|
302
|
+
@report.send( :query )
|
303
|
+
end
|
304
|
+
|
305
|
+
it 'populates rows with the results of the query' do
|
306
|
+
results = [ [1], [2] ]
|
307
|
+
|
308
|
+
expect( @report ).to receive( :to_sql ).and_return( nil )
|
309
|
+
expect( ActiveRecord::Base.connection ).to receive( :execute ).and_return( results )
|
310
|
+
@report.send( :query )
|
311
|
+
expect( @report.rows.size ).to eql( results.size )
|
312
|
+
results.each_index { |i| expect( @report.rows[ i ] ).to eql( results[ i ] ) }
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'post processes each column' do
|
316
|
+
expect( ActiveRecord::Base.connection ).to receive( :execute ).and_return( [] )
|
317
|
+
|
318
|
+
@report.columns.each { |c| expect( c ).to receive( :post_process ).with( @report ) }
|
319
|
+
@report.send( :query )
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
323
|
+
|
324
|
+
#############################################################################
|
325
|
+
# to_sql
|
326
|
+
|
327
|
+
describe '#to_sql' do
|
328
|
+
|
329
|
+
before( :each ) do
|
330
|
+
setup_reports
|
331
|
+
allow( @report ).to receive( :query ).and_return( nil )
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'generates SQL' do
|
335
|
+
expect( @report.send( :to_sql ) ).to eql_file( 'spec/data/lib/report.sql' )
|
336
|
+
end
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
end
|
341
|
+
|
342
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include ReportCat::Core
|
4
|
+
|
5
|
+
describe RSpec::Matchers, 'have_chart' do
|
6
|
+
|
7
|
+
let( :name ) { :test }
|
8
|
+
let( :type ) { :integer }
|
9
|
+
let( :label ) { :label }
|
10
|
+
let( :values ) { [] }
|
11
|
+
let( :options ) { { :foo => true } }
|
12
|
+
|
13
|
+
before( :each ) do
|
14
|
+
@report = Report.new
|
15
|
+
@chart = @report.add_chart( name, type, label, values, options )
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'passes if the report has the chart' do
|
19
|
+
expect( @report ).to have_chart( name )
|
20
|
+
expect( @report ).to have_chart( name ).with_type( type )
|
21
|
+
expect( @report ).to have_chart( name ).with_label( label )
|
22
|
+
expect( @report ).to have_chart( name ).with_values( values )
|
23
|
+
expect( @report ).to have_chart( name ).with_options( options )
|
24
|
+
expect( @report ).to have_chart( name ).with_type( type ).with_label( label ).with_values( values ).with_options( options )
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'fails if the report does not have the chart' do
|
28
|
+
expect( @report ).to_not have_chart( :foo )
|
29
|
+
expect( @report ).to_not have_chart( name ).with_type( :foo )
|
30
|
+
expect( @report ).to_not have_chart( name ).with_label( :foo )
|
31
|
+
expect( @report ).to_not have_chart( name ).with_values( :foo )
|
32
|
+
expect( @report ).to_not have_chart( name ).with_options( :foo )
|
33
|
+
expect( @report ).to_not have_chart( name ).with_type( :foo ).with_label( :foo ).with_values( :foo ).with_options( :foo )
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include ReportCat::Core
|
4
|
+
|
5
|
+
describe RSpec::Matchers, 'have_column' do
|
6
|
+
|
7
|
+
let( :name ) { :test }
|
8
|
+
let( :type ) { :integer }
|
9
|
+
let( :options ) { { :foo => true } }
|
10
|
+
|
11
|
+
before( :each ) do
|
12
|
+
@report = Report.new
|
13
|
+
@column = @report.add_column( name, type, options )
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'passes if the report has the column' do
|
17
|
+
expect( @report ).to have_column( name )
|
18
|
+
expect( @report ).to have_column( name ).with_type( type )
|
19
|
+
expect( @report ).to have_column( name ).with_options( options )
|
20
|
+
expect( @report ).to have_column( name ).with_type( type ).with_options( options )
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'fails if the report does not have the column' do
|
24
|
+
expect( @report ).to_not have_column( :foo )
|
25
|
+
expect( @report ).to_not have_column( name ).with_type( :foo )
|
26
|
+
expect( @report ).to_not have_column( name ).with_options( :foo )
|
27
|
+
expect( @report ).to_not have_column( name ).with_type( :foo ).with_options( :foo )
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include ReportCat::Core
|
4
|
+
|
5
|
+
describe RSpec::Matchers, 'have_param' do
|
6
|
+
|
7
|
+
let( :name ) { :test }
|
8
|
+
let( :type ) { :select }
|
9
|
+
let( :value ) { :value }
|
10
|
+
let( :options ) { [ :foo, :bar ] }
|
11
|
+
|
12
|
+
before( :each ) do
|
13
|
+
@report = Report.new
|
14
|
+
@param = @report.add_param( name, type, value, options )
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'passes if the report has the param' do
|
18
|
+
expect( @report ).to have_param( name )
|
19
|
+
expect( @report ).to have_param( name ).with_type( type )
|
20
|
+
expect( @report ).to have_param( name ).with_value( value )
|
21
|
+
expect( @report ).to have_param( name ).with_options( options )
|
22
|
+
expect( @report ).to have_param( name ).with_type( type ).with_value( value ).with_options( options )
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'fails if the report does not have the param' do
|
26
|
+
expect( @report ).to_not have_param( :foo )
|
27
|
+
expect( @report ).to_not have_param( name ).with_type( :foo )
|
28
|
+
expect( @report ).to_not have_param( name ).with_value( :foo )
|
29
|
+
expect( @report ).to_not have_param( name ).with_options( :foo )
|
30
|
+
expect( @report ).to_not have_param( name ).with_type( :foo ).with_value( :foo ).with_options( :foo )
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|