File: column_box_spec.rb

package info (click to toggle)
ruby-prawn 2.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,380 kB
  • sloc: ruby: 15,820; sh: 43; makefile: 20
file content (75 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

require 'spec_helper'

describe Prawn::Document::ColumnBox do
  let(:pdf) { create_pdf }

  it 'has sensible left and right values' do
    pdf.column_box(
      [0, pdf.cursor],
      width: pdf.bounds.width,
      height: 200,
      columns: 3,
      spacer: 25
    ) do
      left = pdf.bounds.left
      right = pdf.bounds.right

      pdf.bounds.move_past_bottom # next column

      expect(pdf.bounds.left).to be > left
      expect(pdf.bounds.left).to be > right
      expect(pdf.bounds.right).to be > pdf.bounds.left
    end
  end

  it 'includes spacers between columns but not at the end' do
    pdf.column_box(
      [0, pdf.cursor],
      width: 500,
      height: 200,
      columns: 3,
      spacer: 25
    ) do
      expect(pdf.bounds.width).to eq(150) # (500 - (25 * 2)) / 3

      pdf.bounds.move_past_bottom
      pdf.bounds.move_past_bottom

      expect(pdf.bounds.right).to eq(500)
    end
  end

  it 'does not reset the top margin on a new page by default' do
    page_top = pdf.cursor
    pdf.move_down 50
    init_column_top = pdf.cursor
    pdf.column_box [0, pdf.cursor], width: 500, height: 200, columns: 2 do
      pdf.bounds.move_past_bottom
      pdf.bounds.move_past_bottom

      expect(pdf.bounds.absolute_top).to eq(init_column_top)
      expect(pdf.bounds.absolute_top).to_not eq(page_top)
    end
  end

  it 'does reset the top margin when reflow_margins is set' do
    page_top = pdf.cursor
    pdf.move_down 50
    init_column_top = pdf.cursor
    pdf.column_box(
      [0, pdf.cursor],
      width: 500,
      reflow_margins: true,
      height: 200,
      columns: 2
    ) do
      pdf.bounds.move_past_bottom
      pdf.bounds.move_past_bottom

      expect(pdf.bounds.absolute_top).to eq(page_top)
      expect(pdf.bounds.absolute_top).to_not eq(init_column_top)
    end
  end
end