table_creator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/table_creator/col.rb +4 -0
- data/lib/table_creator/version.rb +1 -1
- data/spec/data_table_spec.rb +11 -2
- data/spec/result_group_spec.rb +25 -3
- data/spec/support/coverage_loader.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d59a47b0e8e98ff7d163d597470f3041634a2772
|
4
|
+
data.tar.gz: d749f3c76d7e52a07c8c180f8e25bcd95e6d56a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a1a35bbd0871c87a694c7ff60894f9e1d82551d4312cfb31d5e57baa8d801ccd4783f83d95c81a2155881b55179c786e17f51c1d1dc91851bd963b50e88b3d
|
7
|
+
data.tar.gz: 80e4c44a6671f5c41ae8d2e098e5524fa66f4a341a171babf3d84dd6fb6e4be9aa087e05e967f73c28c4e6c364a964b8d1c753d9838089dd2493af52394c6c47
|
data/CHANGELOG.md
CHANGED
data/lib/table_creator/col.rb
CHANGED
@@ -67,6 +67,10 @@ module TableCreator
|
|
67
67
|
else
|
68
68
|
@data
|
69
69
|
end
|
70
|
+
|
71
|
+
# Links are passed in manually too
|
72
|
+
link_to ||= @link_to
|
73
|
+
|
70
74
|
col_tag = type == :header ? :th : :td
|
71
75
|
content = content_tag :a, content, :href => link_to if link_to
|
72
76
|
content = content_tag :a, content, :name => anchor if anchor
|
data/spec/data_table_spec.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe TableCreator::Table do
|
4
|
-
let(:row) {
|
4
|
+
let(:row) {
|
5
|
+
[
|
6
|
+
'col1',
|
7
|
+
2,
|
8
|
+
Money.new(3),
|
9
|
+
Booking.new(42, '22TEST'),
|
10
|
+
{ data: '22TEST', link_to: '/bookings/42' }
|
11
|
+
]
|
12
|
+
}
|
5
13
|
let(:money_class) {
|
6
14
|
Class.new do
|
7
15
|
def initialize(dollars)
|
@@ -46,7 +54,7 @@ describe TableCreator::Table do
|
|
46
54
|
end
|
47
55
|
|
48
56
|
it 'should generate csv' do
|
49
|
-
expect(subject.to_csv).to eq 'col1,2,3.00,22TEST'
|
57
|
+
expect(subject.to_csv).to eq 'col1,2,3.00,22TEST,22TEST'
|
50
58
|
end
|
51
59
|
|
52
60
|
it 'should generate html' do
|
@@ -58,6 +66,7 @@ describe TableCreator::Table do
|
|
58
66
|
'<td class="number">2</td>'\
|
59
67
|
'<td class="money">$3.00</td>'\
|
60
68
|
'<td class="booking"><a href="/bookings/42">22TEST</a></td>'\
|
69
|
+
'<td class="text"><a href="/bookings/42">22TEST</a></td>'\
|
61
70
|
'</tr>'\
|
62
71
|
'</tbody>'\
|
63
72
|
'</table>'
|
data/spec/result_group_spec.rb
CHANGED
@@ -39,7 +39,7 @@ end
|
|
39
39
|
describe TableCreator::ResultGroup, 'when aggregating' do
|
40
40
|
let(:row1) { double(odd: true, amount: Money.new(1), quantity: 1) }
|
41
41
|
let(:row2) { double(odd: false, amount: Money.new(9), quantity: 3) }
|
42
|
-
let(:row3) { double(odd: true, amount: Money.new(4), quantity:
|
42
|
+
let(:row3) { double(odd: true, amount: Money.new(4), quantity: 1) }
|
43
43
|
subject { TableCreator::ResultGroup.new(nil, [row1, row2, row3]) }
|
44
44
|
|
45
45
|
it 'should not allow non standard/implemented aggregates' do
|
@@ -52,7 +52,7 @@ describe TableCreator::ResultGroup, 'when aggregating' do
|
|
52
52
|
it 'should aggregate on multiple levels' do
|
53
53
|
expect(subject.sum).to be nil
|
54
54
|
subject.aggregate(amount: :sum, quantity: :sum)
|
55
|
-
expect(subject.sum).to eq(amount: Money.new(14), quantity:
|
55
|
+
expect(subject.sum).to eq(amount: Money.new(14), quantity: 5)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should group and aggregate at each level' do
|
@@ -60,10 +60,32 @@ describe TableCreator::ResultGroup, 'when aggregating' do
|
|
60
60
|
expect(subject.sum).to be nil
|
61
61
|
subject.aggregate(amount: :sum, quantity: :sum)
|
62
62
|
expect(subject.rows[0].group_object).to eq 'true'
|
63
|
-
expect(subject.rows[0].sum).to eq(amount: Money.new(5), quantity:
|
63
|
+
expect(subject.rows[0].sum).to eq(amount: Money.new(5), quantity: 2)
|
64
64
|
expect(subject.rows[1].group_object).to eq 'false'
|
65
65
|
expect(subject.rows[1].sum).to eq(amount: Money.new(9), quantity: 3)
|
66
66
|
end
|
67
|
+
|
68
|
+
context 'to_data_rows' do
|
69
|
+
subject {
|
70
|
+
result = TableCreator::ResultGroup.new(nil, [row1, row2, row3])
|
71
|
+
result.group([:odd, :quantity])
|
72
|
+
result.to_data_rows do |row_group, row|
|
73
|
+
[row_group.try(:group_object), row]
|
74
|
+
end
|
75
|
+
}
|
76
|
+
|
77
|
+
specify do
|
78
|
+
expect(subject).to eq [
|
79
|
+
{ class: 'd1 l2 summary', data: ['true', nil] },
|
80
|
+
{ class: 'd0 l2 summary', data: ['1', nil] },
|
81
|
+
[nil, row1],
|
82
|
+
[nil, row3],
|
83
|
+
{ class: 'd1 l2 summary', data: ['false', nil] },
|
84
|
+
{ class: 'd0 l2 summary', data: ['3', nil] },
|
85
|
+
[nil, row2]
|
86
|
+
]
|
87
|
+
end
|
88
|
+
end
|
67
89
|
end
|
68
90
|
|
69
91
|
class Money
|