active_reporter 0.6.0 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -9
  3. data/lib/active_reporter/aggregator/array.rb +1 -1
  4. data/lib/active_reporter/aggregator/count.rb +2 -2
  5. data/lib/active_reporter/aggregator/count_if.rb +2 -2
  6. data/lib/active_reporter/aggregator/ratio.rb +1 -1
  7. data/lib/active_reporter/aggregator.rb +9 -9
  8. data/lib/active_reporter/calculator.rb +2 -2
  9. data/lib/active_reporter/dimension/base.rb +3 -3
  10. data/lib/active_reporter/dimension/bin/set.rb +3 -3
  11. data/lib/active_reporter/dimension/bin/table.rb +1 -1
  12. data/lib/active_reporter/dimension/bin.rb +23 -15
  13. data/lib/active_reporter/dimension/category.rb +1 -1
  14. data/lib/active_reporter/dimension/enum.rb +1 -1
  15. data/lib/active_reporter/dimension/number.rb +3 -3
  16. data/lib/active_reporter/dimension/time.rb +4 -4
  17. data/lib/active_reporter/dimension.rb +8 -8
  18. data/lib/active_reporter/evaluator.rb +2 -2
  19. data/lib/active_reporter/inflector.rb +1 -1
  20. data/lib/active_reporter/report/aggregation.rb +12 -12
  21. data/lib/active_reporter/report/definition.rb +6 -6
  22. data/lib/active_reporter/report/validation.rb +28 -13
  23. data/lib/active_reporter/report.rb +3 -3
  24. data/lib/active_reporter/serializer/base.rb +6 -6
  25. data/lib/active_reporter/serializer/csv.rb +2 -2
  26. data/lib/active_reporter/serializer/form_field.rb +5 -5
  27. data/lib/active_reporter/serializer/highcharts.rb +6 -6
  28. data/lib/active_reporter/serializer.rb +7 -7
  29. data/lib/active_reporter/tracker/base.rb +1 -1
  30. data/lib/active_reporter/tracker/value.rb +1 -1
  31. data/lib/active_reporter/tracker.rb +3 -3
  32. data/lib/active_reporter/version.rb +1 -1
  33. data/lib/active_reporter.rb +7 -3
  34. data/spec/acceptance/data_spec.rb +49 -49
  35. data/spec/active_reporter/aggregator_spec.rb +37 -37
  36. data/spec/active_reporter/dimension/base_spec.rb +29 -29
  37. data/spec/active_reporter/dimension/bin/set_spec.rb +29 -29
  38. data/spec/active_reporter/dimension/bin/table_spec.rb +7 -7
  39. data/spec/active_reporter/dimension/bin_spec.rb +12 -12
  40. data/spec/active_reporter/dimension/category_spec.rb +22 -22
  41. data/spec/active_reporter/dimension/enum_spec.rb +12 -12
  42. data/spec/active_reporter/dimension/number_spec.rb +11 -11
  43. data/spec/active_reporter/dimension/time_spec.rb +20 -20
  44. data/spec/active_reporter/report_spec.rb +162 -162
  45. data/spec/active_reporter/serializer/hash_table_spec.rb +13 -13
  46. data/spec/active_reporter/serializer/highcharts_spec.rb +30 -30
  47. data/spec/active_reporter/serializer/table_spec.rb +22 -22
  48. data/spec/dummy/Rakefile +1 -1
  49. data/spec/dummy/app/models/post_report.rb +1 -1
  50. data/spec/dummy/app/views/layouts/application.html.erb +2 -2
  51. data/spec/dummy/app/views/site/report.html.erb +5 -5
  52. data/spec/dummy/bin/bundle +2 -2
  53. data/spec/dummy/bin/rails +3 -3
  54. data/spec/dummy/bin/rake +2 -2
  55. data/spec/dummy/bin/setup +2 -2
  56. data/spec/dummy/config/application.rb +4 -4
  57. data/spec/dummy/config/boot.rb +3 -3
  58. data/spec/dummy/config/database.yml +3 -3
  59. data/spec/dummy/config/environment.rb +1 -1
  60. data/spec/dummy/config/environments/production.rb +4 -4
  61. data/spec/dummy/config/environments/test.rb +1 -1
  62. data/spec/dummy/config/initializers/assets.rb +1 -1
  63. data/spec/dummy/config/initializers/inflections.rb +4 -4
  64. data/spec/dummy/config/initializers/session_store.rb +1 -1
  65. data/spec/dummy/config/locales/en.yml +2 -2
  66. data/spec/dummy/config/routes.rb +9 -9
  67. data/spec/dummy/config.ru +1 -1
  68. data/spec/dummy/log/test.log +49678 -75977
  69. data/spec/spec_helper.rb +13 -13
  70. metadata +64 -44
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Base do
4
4
  def new_dimension(dimension_params = {}, report_params = {}, opts = {})
@@ -10,18 +10,18 @@ describe ActiveReporter::Dimension::Base do
10
10
  )
11
11
  end
12
12
 
13
- describe '#filter_values' do
14
- it 'accepts one' do
15
- dimension = new_dimension(only: 'bar')
13
+ describe "#filter_values" do
14
+ it "accepts one" do
15
+ dimension = new_dimension(only: "bar")
16
16
  expect(dimension.filter_values).to eq %w(bar)
17
17
  end
18
18
 
19
- it 'accepts many' do
19
+ it "accepts many" do
20
20
  dimension = new_dimension(only: %w(bar baz))
21
21
  expect(dimension.filter_values).to eq %w(bar baz)
22
22
  end
23
23
 
24
- it 'determines #filtering?' do
24
+ it "determines #filtering?" do
25
25
  dimension = new_dimension(only: %w(bar baz))
26
26
  expect(dimension).to be_filtering
27
27
 
@@ -30,42 +30,42 @@ describe ActiveReporter::Dimension::Base do
30
30
  end
31
31
  end
32
32
 
33
- describe '#sort_order' do
34
- it 'can be desc/asc, falls back to root, defaults to asc' do
33
+ describe "#sort_order" do
34
+ it "can be desc/asc, falls back to root, defaults to asc" do
35
35
  dimension = new_dimension
36
- expect(dimension.sort_order).to eq 'ASC'
36
+ expect(dimension.sort_order).to eq "ASC"
37
37
 
38
38
  dimension = new_dimension(sort_desc: true)
39
- expect(dimension.sort_order).to eq 'DESC'
39
+ expect(dimension.sort_order).to eq "DESC"
40
40
 
41
41
  dimension = new_dimension(sort_desc: false)
42
- expect(dimension.sort_order).to eq 'ASC'
42
+ expect(dimension.sort_order).to eq "ASC"
43
43
 
44
44
  dimension = new_dimension({}, sort_desc: true)
45
- expect(dimension.sort_order).to eq 'DESC'
45
+ expect(dimension.sort_order).to eq "DESC"
46
46
 
47
47
  dimension = new_dimension({}, sort_desc: false)
48
- expect(dimension.sort_order).to eq 'ASC'
48
+ expect(dimension.sort_order).to eq "ASC"
49
49
  end
50
50
  end
51
51
 
52
- describe '#null_order' do
53
- it 'can be first/last, falls back to root, defaults to first (only if postgres)' do
52
+ describe "#null_order" do
53
+ it "can be first/last, falls back to root, defaults to first (only if postgres)" do
54
54
  if ActiveReporter.database_type == :postgres
55
55
  dimension = new_dimension
56
- expect(dimension.null_order).to eq 'NULLS FIRST'
56
+ expect(dimension.null_order).to eq "NULLS FIRST"
57
57
 
58
58
  dimension = new_dimension(nulls_last: true)
59
- expect(dimension.null_order).to eq 'NULLS LAST'
59
+ expect(dimension.null_order).to eq "NULLS LAST"
60
60
 
61
61
  dimension = new_dimension(nulls_last: false)
62
- expect(dimension.null_order).to eq 'NULLS FIRST'
62
+ expect(dimension.null_order).to eq "NULLS FIRST"
63
63
 
64
64
  dimension = new_dimension({}, nulls_last: true)
65
- expect(dimension.null_order).to eq 'NULLS LAST'
65
+ expect(dimension.null_order).to eq "NULLS LAST"
66
66
 
67
67
  dimension = new_dimension({}, nulls_last: false)
68
- expect(dimension.null_order).to eq 'NULLS FIRST'
68
+ expect(dimension.null_order).to eq "NULLS FIRST"
69
69
  else
70
70
  dimension = new_dimension
71
71
  expect(dimension.null_order).to be_blank
@@ -73,30 +73,30 @@ describe ActiveReporter::Dimension::Base do
73
73
  end
74
74
  end
75
75
 
76
- describe '#relate' do
77
- it 'defaults to the identity function' do
76
+ describe "#relate" do
77
+ it "defaults to the identity function" do
78
78
  dimension = new_dimension
79
79
  expect(dimension.relate(5)).to eq 5
80
80
  end
81
81
 
82
- it 'can be overridden, e.g. for joins' do
82
+ it "can be overridden, e.g. for joins" do
83
83
  dimension = new_dimension({}, {}, relation: ->(r) { r + 5 })
84
84
  expect(dimension.relate(5)).to eq 10
85
85
  end
86
86
  end
87
87
 
88
- describe '#expression' do
89
- it 'defaults to treating name as a column of the report klass table' do
88
+ describe "#expression" do
89
+ it "defaults to treating name as a column of the report klass table" do
90
90
  dimension = ActiveReporter::Dimension::Base.new(
91
91
  :bar,
92
- OpenStruct.new(table_name: 'foo')
92
+ OpenStruct.new(table_name: "foo")
93
93
  )
94
- expect(dimension.expression).to eq('foo.bar')
94
+ expect(dimension.expression).to eq("foo.bar")
95
95
  end
96
96
 
97
- it 'can be overridden' do
97
+ it "can be overridden" do
98
98
  dimension = new_dimension({}, {}, table_name: :baz, attribute: :bat)
99
- expect(dimension.expression).to eq 'baz.bat'
99
+ expect(dimension.expression).to eq "baz.bat"
100
100
  end
101
101
  end
102
102
  end
@@ -1,8 +1,8 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Bin::Set do
4
- describe '.from_hash' do
5
- it 'builds a bin from a hash or nil' do
4
+ describe ".from_hash" do
5
+ it "builds a bin from a hash or nil" do
6
6
  bin = described_class.from_hash(min: 1, max: 2)
7
7
  expect(bin.min).to eq 1
8
8
  expect(bin.max).to eq 2
@@ -13,19 +13,19 @@ describe ActiveReporter::Dimension::Bin::Set do
13
13
  end
14
14
  end
15
15
 
16
- describe '.from_sql' do
17
- it 'builds a bin from a bin text string' do
16
+ describe ".from_sql" do
17
+ it "builds a bin from a bin text string" do
18
18
  bin = described_class.from_sql("1,2")
19
- expect(bin.min).to eq '1'
20
- expect(bin.max).to eq '2'
19
+ expect(bin.min).to eq "1"
20
+ expect(bin.max).to eq "2"
21
21
 
22
22
  bin = described_class.from_sql("1,")
23
- expect(bin.min).to eq '1'
23
+ expect(bin.min).to eq "1"
24
24
  expect(bin.max).to eq nil
25
25
 
26
26
  bin = described_class.from_sql(",2")
27
27
  expect(bin.min).to eq nil
28
- expect(bin.max).to eq '2'
28
+ expect(bin.max).to eq "2"
29
29
 
30
30
  bin = described_class.from_sql(",")
31
31
  expect(bin.min).to eq nil
@@ -33,51 +33,51 @@ describe ActiveReporter::Dimension::Bin::Set do
33
33
  end
34
34
  end
35
35
 
36
- describe '#contains_sql' do
37
- it 'returns SQL checking if expr is in the bin' do
36
+ describe "#contains_sql" do
37
+ it "returns SQL checking if expr is in the bin" do
38
38
  bin = described_class.new(1, 2)
39
- expect(bin.contains_sql('foo')).to eq "(foo >= 1 AND foo < 2)"
39
+ expect(bin.contains_sql("foo")).to eq "(foo >= 1 AND foo < 2)"
40
40
 
41
41
  bin = described_class.new(1, nil)
42
- expect(bin.contains_sql('foo')).to eq "foo >= 1"
42
+ expect(bin.contains_sql("foo")).to eq "foo >= 1"
43
43
 
44
44
  bin = described_class.new(nil, 2)
45
- expect(bin.contains_sql('foo')).to eq "foo < 2"
45
+ expect(bin.contains_sql("foo")).to eq "foo < 2"
46
46
 
47
47
  bin = described_class.new(nil, nil)
48
- expect(bin.contains_sql('foo')).to eq "foo IS NULL"
48
+ expect(bin.contains_sql("foo")).to eq "foo IS NULL"
49
49
  end
50
50
  end
51
51
 
52
- describe '#to_json' do
53
- it 'reexpresses the bin as a hash' do
52
+ describe "#to_json" do
53
+ it "reexpresses the bin as a hash" do
54
54
  bin = described_class.new(1, 2)
55
55
  json = { a: bin }.to_json
56
- expect(JSON.parse(json)).to eq('a' => { 'min' => 1, 'max' => 2 })
56
+ expect(JSON.parse(json)).to eq("a" => { "min" => 1, "max" => 2 })
57
57
  end
58
58
  end
59
59
 
60
- describe 'hashing' do
61
- it 'works with hashes' do
60
+ describe "hashing" do
61
+ it "works with hashes" do
62
62
  bin1 = described_class.new(1, 2)
63
63
  bin2 = described_class.new(1, 2)
64
64
  bin3 = { min: 1, max: 2 }
65
65
 
66
- h = { bin3 => 'foo' }
67
- expect(h[bin1]).to eq 'foo'
68
- expect(h[bin2]).to eq 'foo'
69
- expect(h[bin3]).to eq 'foo'
66
+ h = { bin3 => "foo" }
67
+ expect(h[bin1]).to eq "foo"
68
+ expect(h[bin2]).to eq "foo"
69
+ expect(h[bin3]).to eq "foo"
70
70
  end
71
71
 
72
- it 'works with nil' do
72
+ it "works with nil" do
73
73
  bin1 = described_class.new(nil, nil)
74
74
  bin2 = described_class.new(nil, nil)
75
75
  bin3 = nil
76
76
 
77
- h = { bin3 => 'foo' }
78
- expect(h[bin1]).to eq 'foo'
79
- expect(h[bin2]).to eq 'foo'
80
- expect(h[bin3]).to eq 'foo'
77
+ h = { bin3 => "foo" }
78
+ expect(h[bin1]).to eq "foo"
79
+ expect(h[bin2]).to eq "foo"
80
+ expect(h[bin3]).to eq "foo"
81
81
  end
82
82
  end
83
83
  end
@@ -1,10 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Bin::Table do
4
4
  let(:bin_set) { ActiveReporter::Dimension::Bin::Set }
5
5
 
6
- describe '#filter' do
7
- it 'ORs together predicates across bins' do
6
+ describe "#filter" do
7
+ it "ORs together predicates across bins" do
8
8
  table = described_class.new([
9
9
  bin_set.new(nil, nil),
10
10
  bin_set.new(0, nil),
@@ -12,14 +12,14 @@ describe ActiveReporter::Dimension::Bin::Table do
12
12
  bin_set.new(3, 5)
13
13
  ])
14
14
 
15
- sql = table.filter(Post, 'x').to_sql
15
+ sql = table.filter(Post, "x").to_sql
16
16
 
17
17
  expect(sql).to include "WHERE (x IS NULL OR x >= 0 OR x < 10 OR (x >= 3 AND x < 5))"
18
18
  end
19
19
  end
20
20
 
21
- describe '#group' do
22
- it 'joins to a union of bin rows, then groups by the range' do
21
+ describe "#group" do
22
+ it "joins to a union of bin rows, then groups by the range" do
23
23
  table = described_class.new([
24
24
  bin_set.new(nil, nil),
25
25
  bin_set.new(0, nil),
@@ -27,7 +27,7 @@ describe ActiveReporter::Dimension::Bin::Table do
27
27
  bin_set.new(3, 5)
28
28
  ])
29
29
 
30
- sql = table.group(Post, 'likes', 'likes').to_sql
30
+ sql = table.group(Post, "likes", "likes").to_sql
31
31
 
32
32
  expect(sql).to start_with "SELECT likes_bin_table.bin_text AS likes"
33
33
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Bin do
4
4
  def new_dimension(dimension_params = {}, report_params = {}, opts = {})
@@ -13,23 +13,23 @@ describe ActiveReporter::Dimension::Bin do
13
13
  expect { yield }.to raise_error(ActiveReporter::InvalidParamsError)
14
14
  end
15
15
 
16
- describe 'param validation' do
17
- it 'yells unless :bin_count is numeric' do
18
- expect_error { new_dimension(bin_count: 'hey') }
16
+ describe "param validation" do
17
+ it "yells unless :bin_count is numeric" do
18
+ expect_error { new_dimension(bin_count: "hey") }
19
19
  expect_error { new_dimension(bin_count: nil) }
20
20
  new_dimension(bin_count: 5)
21
21
  new_dimension(bin_count: 1.24)
22
22
  end
23
23
  end
24
24
 
25
- describe '#min/max' do
26
- it 'finds the extremes in filter_values' do
25
+ describe "#min/max" do
26
+ it "finds the extremes in filter_values" do
27
27
  dimension = new_dimension(only: [{ min: 1, max: 3 }, { min: -3 }, { min: 17, max: 40 }])
28
28
  expect(dimension.min).to eq -3
29
29
  expect(dimension.max).to eq 40
30
30
  end
31
31
 
32
- it 'falls back to the smallest value in the data' do
32
+ it "falls back to the smallest value in the data" do
33
33
  dimension = ActiveReporter::Dimension::Bin.new(:likes,
34
34
  OpenStruct.new(records: Post, params: {}),
35
35
  model: :post, attribute: :likes
@@ -44,8 +44,8 @@ describe ActiveReporter::Dimension::Bin do
44
44
  end
45
45
  end
46
46
 
47
- describe '#group_values' do
48
- it 'defaults to dividing the domain into bins of bin_width' do
47
+ describe "#group_values" do
48
+ it "defaults to dividing the domain into bins of bin_width" do
49
49
  dimension = new_dimension(only: { min: 0, max: 3 })
50
50
  allow(dimension).to receive(:bin_width).and_return(1)
51
51
  allow(dimension).to receive(:data_contains_nil?).and_return(false)
@@ -56,10 +56,10 @@ describe ActiveReporter::Dimension::Bin do
56
56
  ]
57
57
  end
58
58
 
59
- it 'is inclusive of max if data-driven' do
59
+ it "is inclusive of max if data-driven" do
60
60
  dimension = new_dimension(only: { min: 0 })
61
61
  allow(dimension.report).to receive(:records).and_return(Post)
62
- allow(dimension).to receive(:expression).and_return('posts.likes')
62
+ allow(dimension).to receive(:expression).and_return("posts.likes")
63
63
  allow(dimension).to receive(:bin_width).and_return(1)
64
64
  create(:post, likes: 2)
65
65
  expect(dimension.group_values).to eq [
@@ -69,7 +69,7 @@ describe ActiveReporter::Dimension::Bin do
69
69
  ]
70
70
  end
71
71
 
72
- it 'can be customized' do
72
+ it "can be customized" do
73
73
  dimension = new_dimension(bins: { min: 0, max: 1 })
74
74
  expect(dimension.group_values).to eq [{ min: 0, max: 1 }]
75
75
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Category do
4
4
  def author_dimension(report)
@@ -6,53 +6,53 @@ describe ActiveReporter::Dimension::Category do
6
6
  "LEFT OUTER JOIN authors ON authors.id = posts.author_id") })
7
7
  end
8
8
 
9
- describe '#filter' do
10
- it 'filters to rows matching at least one value' do
11
- p1 = create(:post, author: 'Alice')
12
- p2 = create(:post, author: 'Bob')
9
+ describe "#filter" do
10
+ it "filters to rows matching at least one value" do
11
+ p1 = create(:post, author: "Alice")
12
+ p2 = create(:post, author: "Bob")
13
13
  p3 = create(:post, author: nil)
14
14
 
15
15
  def filter_by(author_values)
16
16
  report = OpenStruct.new(
17
- table_name: 'posts',
17
+ table_name: "posts",
18
18
  params: { dimensions: { author: { only: author_values } } }
19
19
  )
20
20
  dimension = author_dimension(report)
21
21
  dimension.filter(dimension.relate(Post))
22
22
  end
23
23
 
24
- expect(filter_by(['Alice'])).to eq [p1]
24
+ expect(filter_by(["Alice"])).to eq [p1]
25
25
  expect(filter_by([nil])).to eq [p3]
26
- expect(filter_by(['Alice', nil])).to eq [p1, p3]
27
- expect(filter_by(['Alice', 'Bob'])).to eq [p1, p2]
26
+ expect(filter_by(["Alice", nil])).to eq [p1, p3]
27
+ expect(filter_by(["Alice", "Bob"])).to eq [p1, p2]
28
28
  expect(filter_by([])).to eq []
29
29
  end
30
30
  end
31
31
 
32
- describe '#group' do
33
- it 'groups the relation by the exact value of the SQL expression' do
34
- p1 = create(:post, author: 'Alice')
35
- p2 = create(:post, author: 'Alice')
32
+ describe "#group" do
33
+ it "groups the relation by the exact value of the SQL expression" do
34
+ p1 = create(:post, author: "Alice")
35
+ p2 = create(:post, author: "Alice")
36
36
  p3 = create(:post, author: nil)
37
- p4 = create(:post, author: 'Bob')
38
- p5 = create(:post, author: 'Bob')
39
- p6 = create(:post, author: 'Bob')
37
+ p4 = create(:post, author: "Bob")
38
+ p5 = create(:post, author: "Bob")
39
+ p6 = create(:post, author: "Bob")
40
40
 
41
- report = OpenStruct.new(table_name: 'posts', params: {})
41
+ report = OpenStruct.new(table_name: "posts", params: {})
42
42
  dimension = author_dimension(report)
43
43
 
44
44
  results = dimension.group(dimension.relate(Post)).select("COUNT(*) AS count").map do |r|
45
- r.attributes.values_at(dimension.send(:sql_value_name), 'count')
45
+ r.attributes.values_at(dimension.send(:sql_value_name), "count")
46
46
  end
47
47
 
48
- expect(results).to eq [[nil, 1], ['Alice', 2], ['Bob', 3]]
48
+ expect(results).to eq [[nil, 1], ["Alice", 2], ["Bob", 3]]
49
49
  end
50
50
  end
51
51
 
52
- describe '#group_values' do
53
- it 'echoes filter_values if filtering' do
52
+ describe "#group_values" do
53
+ it "echoes filter_values if filtering" do
54
54
  dimension = author_dimension(OpenStruct.new(params: {
55
- dimensions: { author: { only: ['foo', 'bar'] } }
55
+ dimensions: { author: { only: ["foo", "bar"] } }
56
56
  }))
57
57
  expect(dimension.group_values).to eq %w(foo bar)
58
58
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Enum do
4
4
  let(:report_model) { :post }
@@ -7,12 +7,12 @@ describe ActiveReporter::Dimension::Enum do
7
7
  let(:report) { OpenStruct.new(params: { dimensions: { status: status_dimension_options } }, groupers: [:status, :category], raw_data: raw_data) }
8
8
 
9
9
  let(:raw_data) { {
10
- ['published', 'post_count'] => 5, ['published', 'post_total'] => 500.00, ['published', 'post_average'] => 100.00,
11
- ['archived', 'post_count'] => 7, ['archived', 'post_total'] => 530.25, ['archived', 'post_average'] => 75.75,
10
+ ["published", "post_count"] => 5, ["published", "post_total"] => 500.00, ["published", "post_average"] => 100.00,
11
+ ["archived", "post_count"] => 7, ["archived", "post_total"] => 530.25, ["archived", "post_average"] => 75.75,
12
12
  } }
13
13
 
14
- let(:enum_values) { { 'draft' => 0, 'unpublished' => 1, 'published' => 2, 'archived' => 3 } }
15
- let(:group_values) { ['published', 'archived'] }
14
+ let(:enum_values) { { "draft" => 0, "unpublished" => 1, "published" => 2, "archived" => 3 } }
15
+ let(:group_values) { ["published", "archived"] }
16
16
  let(:all_values) { enum_values.keys.unshift(nil) }
17
17
 
18
18
  let(:status_dimension) do
@@ -23,24 +23,24 @@ describe ActiveReporter::Dimension::Enum do
23
23
  dimension
24
24
  end
25
25
 
26
- describe '#group_values' do
27
- context 'when filtering' do
28
- let(:filter_values) { ['unpublished', 'published', 'archived'] }
26
+ describe "#group_values" do
27
+ context "when filtering" do
28
+ let(:filter_values) { ["unpublished", "published", "archived"] }
29
29
 
30
- it 'returns filter_values' do
30
+ it "returns filter_values" do
31
31
  expect(status_dimension).to be_filtering
32
32
  expect(status_dimension.group_values).to eq filter_values
33
33
  end
34
34
  end
35
35
 
36
- it 'returns group enum values' do
36
+ it "returns group enum values" do
37
37
  expect(status_dimension).not_to be_filtering
38
38
  expect(status_dimension.group_values).to match group_values
39
39
  end
40
40
  end
41
41
 
42
- describe '#all_values' do
43
- it 'returns model enum values' do
42
+ describe "#all_values" do
43
+ it "returns model enum values" do
44
44
  expect(status_dimension.all_values).to match all_values
45
45
  end
46
46
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Number do
4
4
  def new_dimension(dimension_params = {}, report_params = {}, opts = {})
@@ -14,23 +14,23 @@ describe ActiveReporter::Dimension::Number do
14
14
  expect { yield }.to raise_error(ActiveReporter::InvalidParamsError)
15
15
  end
16
16
 
17
- describe 'param validation' do
18
- it 'yells unless :bin_width is numeric' do
19
- expect_error { new_dimension(bin_width: '') }
20
- expect_error { new_dimension(bin_width: '49er') }
17
+ describe "param validation" do
18
+ it "yells unless :bin_width is numeric" do
19
+ expect_error { new_dimension(bin_width: "") }
20
+ expect_error { new_dimension(bin_width: "49er") }
21
21
  expect_error { new_dimension(bin_width: { seconds: 1 }) }
22
22
  expect(new_dimension(bin_width: 10.5).bin_width).to eq 10.5
23
- expect(new_dimension(bin_width: '10').bin_width).to eq 10.0
23
+ expect(new_dimension(bin_width: "10").bin_width).to eq 10.0
24
24
  end
25
25
  end
26
26
 
27
- describe '#bin_width' do
28
- it 'reads from params' do
27
+ describe "#bin_width" do
28
+ it "reads from params" do
29
29
  dimension = new_dimension(bin_width: 7)
30
30
  expect(dimension.bin_width).to eq 7
31
31
  end
32
32
 
33
- it 'can divide the domain into :bin_count bins' do
33
+ it "can divide the domain into :bin_count bins" do
34
34
  dimension = new_dimension(bin_count: 5, only: { min: 0, max: 5 })
35
35
  expect(dimension.bin_width).to eq 1
36
36
  allow(dimension).to receive(:data_contains_nil?).and_return(false)
@@ -43,7 +43,7 @@ describe ActiveReporter::Dimension::Number do
43
43
  ]
44
44
  end
45
45
 
46
- it 'can include nils if they are present in the data' do
46
+ it "can include nils if they are present in the data" do
47
47
  dimension = new_dimension(bin_count: 3, only: { min: 0, max: 3 })
48
48
  allow(dimension).to receive(:data_contains_nil?).and_return(true)
49
49
  expect(dimension.group_values).to eq [
@@ -63,7 +63,7 @@ describe ActiveReporter::Dimension::Number do
63
63
  ]
64
64
  end
65
65
 
66
- it 'defaults to 10 equal bins' do
66
+ it "defaults to 10 equal bins" do
67
67
  dimension = new_dimension(only: { min: 0, max: 5 })
68
68
  expect(dimension.bin_width).to eq 0.5
69
69
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ActiveReporter::Dimension::Time do
4
4
  def new_dimension(dimension_params = {}, report_params = {}, opts = {})
@@ -14,47 +14,47 @@ describe ActiveReporter::Dimension::Time do
14
14
  expect { yield }.to raise_error(ActiveReporter::InvalidParamsError)
15
15
  end
16
16
 
17
- describe 'param validation' do
18
- it 'yells unless :bin_width is a duration hash' do
19
- expect_error { new_dimension(bin_width: '') }
17
+ describe "param validation" do
18
+ it "yells unless :bin_width is a duration hash" do
19
+ expect_error { new_dimension(bin_width: "") }
20
20
  expect_error { new_dimension(bin_width: 5) }
21
- expect_error { new_dimension(bin_width: { seconds: 'hey' }) }
21
+ expect_error { new_dimension(bin_width: { seconds: "hey" }) }
22
22
  expect_error { new_dimension(bin_width: { seconds: 1, chickens: 0 }) }
23
23
  new_dimension(bin_width: { seconds: 1, minutes: 2 })
24
24
  new_dimension(bin_width: { weeks: 12, years: 7 })
25
25
  end
26
26
 
27
- it 'yells unless :bins and :only values are times' do
28
- expect_error { new_dimension(bins: { min: 'hey' }) }
29
- expect_error { new_dimension(only: { min: 'hey' }) }
30
- expect_error { new_dimension(only: [{ min: '2015-01-01', max: '2015-01-10' }, { min: 'chicken' }]) }
31
- new_dimension(bins: { min: '2015-01-01', max: '2015-01-10' })
32
- new_dimension(only: { min: '2015-01-01', max: '2015-01-10' })
33
- new_dimension(only: [nil, { min: '2015-01-01', max: '2015-01-10' }, { max: '2015-02-10' }])
27
+ it "yells unless :bins and :only values are times" do
28
+ expect_error { new_dimension(bins: { min: "hey" }) }
29
+ expect_error { new_dimension(only: { min: "hey" }) }
30
+ expect_error { new_dimension(only: [{ min: "2015-01-01", max: "2015-01-10" }, { min: "chicken" }]) }
31
+ new_dimension(bins: { min: "2015-01-01", max: "2015-01-10" })
32
+ new_dimension(only: { min: "2015-01-01", max: "2015-01-10" })
33
+ new_dimension(only: [nil, { min: "2015-01-01", max: "2015-01-10" }, { max: "2015-02-10" }])
34
34
  end
35
35
  end
36
36
 
37
- describe '#bin_width' do
38
- it 'can translate a duration hash into an ActiveSupport::Duration' do
37
+ describe "#bin_width" do
38
+ it "can translate a duration hash into an ActiveSupport::Duration" do
39
39
  dimension = new_dimension(bin_width: { seconds: 10, minutes: 1 })
40
40
  expect(dimension.bin_width).to eq 70.seconds
41
41
  dimension = new_dimension(bin_width: { days: 8, weeks: 1 })
42
42
  expect(dimension.bin_width).to eq 15.days
43
43
  end
44
44
 
45
- it 'can divide the domain into :bin_count bins' do
46
- dimension = new_dimension(bin_count: 10, only: [{ min: '2015-01-01' }, { max: '2015-01-11' }])
45
+ it "can divide the domain into :bin_count bins" do
46
+ dimension = new_dimension(bin_count: 10, only: [{ min: "2015-01-01" }, { max: "2015-01-11" }])
47
47
  allow(dimension).to receive(:data_contains_nil?).and_return(false)
48
48
  expect(dimension.bin_width).to eq 1.day
49
49
  expect(dimension.group_values.map(&:min).map(&:day)).to eq (1..10).to_a
50
50
  end
51
51
 
52
- it 'defaults to a sensical, standard duration' do
53
- dimension = new_dimension(only: [{ min: '2015-01-01' }, { max: '2015-01-02' }])
52
+ it "defaults to a sensical, standard duration" do
53
+ dimension = new_dimension(only: [{ min: "2015-01-01" }, { max: "2015-01-02" }])
54
54
  expect(dimension.bin_width).to eq 1.hour
55
- dimension = new_dimension(only: [{ min: '2015-01-01' }, { max: '2015-01-11' }])
55
+ dimension = new_dimension(only: [{ min: "2015-01-01" }, { max: "2015-01-11" }])
56
56
  expect(dimension.bin_width).to eq 1.day
57
- dimension = new_dimension(only: [{ min: '2015-01-01' }, { max: '2015-02-11' }])
57
+ dimension = new_dimension(only: [{ min: "2015-01-01" }, { max: "2015-02-11" }])
58
58
  expect(dimension.bin_width).to eq 1.week
59
59
  end
60
60
  end