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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 332bd4ea2ac0af888861df66f9c77a1dcdbccd96
4
- data.tar.gz: e08ba3193eabfb901dc6c9d7fd0e0a7114797a27
3
+ metadata.gz: d59a47b0e8e98ff7d163d597470f3041634a2772
4
+ data.tar.gz: d749f3c76d7e52a07c8c180f8e25bcd95e6d56a8
5
5
  SHA512:
6
- metadata.gz: 26fda13a7187b87ce7b587a287dabbd212310cf5bba29d12a837f141435ce685a55c59bc781ee4236a53751f6683a664e37f48b12488aea145e4bf25b50c5b05
7
- data.tar.gz: '01078e18ef529bfd2364d90adf1833b4e640889425cf94b3062d0b6a628815c85bc9f02b5e2cfc5d2840b83bd8556bf9313d83fdab9b9acae249d532ebb4332e'
6
+ metadata.gz: 54a1a35bbd0871c87a694c7ff60894f9e1d82551d4312cfb31d5e57baa8d801ccd4783f83d95c81a2155881b55179c786e17f51c1d1dc91851bd963b50e88b3d
7
+ data.tar.gz: 80e4c44a6671f5c41ae8d2e098e5524fa66f4a341a171babf3d84dd6fb6e4be9aa087e05e967f73c28c4e6c364a964b8d1c753d9838089dd2493af52394c6c47
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.1
6
+
7
+ * Restore support for manual links
8
+
5
9
  ## 0.1.0
6
10
 
7
11
  * Improve class names
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TableCreator
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,7 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe TableCreator::Table do
4
- let(:row) { ['col1', 2, Money.new(3), Booking.new(42, '22TEST')] }
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>'
@@ -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: 4) }
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: 8)
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: 5)
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
@@ -1,4 +1,4 @@
1
1
  require 'simplecov-rcov'
2
2
  require 'coveralls'
3
3
  require 'coverage/kit'
4
- Coverage::Kit.setup(minimum_coverage: 76.5)
4
+ Coverage::Kit.setup(minimum_coverage: 88.1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_creator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack