caracal_the_curve 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +22 -0
- data/.github/workflows/publish_gem.yml +40 -0
- data/.gitignore +25 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +141 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +842 -0
- data/Rakefile +7 -0
- data/caracal.gemspec +28 -0
- data/lib/caracal/core/bookmarks.rb +52 -0
- data/lib/caracal/core/custom_properties.rb +49 -0
- data/lib/caracal/core/file_name.rb +43 -0
- data/lib/caracal/core/fonts.rb +75 -0
- data/lib/caracal/core/iframes.rb +42 -0
- data/lib/caracal/core/ignorables.rb +47 -0
- data/lib/caracal/core/images.rb +37 -0
- data/lib/caracal/core/list_styles.rb +93 -0
- data/lib/caracal/core/lists.rb +57 -0
- data/lib/caracal/core/models/base_model.rb +51 -0
- data/lib/caracal/core/models/bookmark_model.rb +86 -0
- data/lib/caracal/core/models/border_model.rb +120 -0
- data/lib/caracal/core/models/custom_property_model.rb +60 -0
- data/lib/caracal/core/models/font_model.rb +64 -0
- data/lib/caracal/core/models/iframe_model.rb +148 -0
- data/lib/caracal/core/models/image_model.rb +133 -0
- data/lib/caracal/core/models/line_break_model.rb +15 -0
- data/lib/caracal/core/models/link_model.rb +94 -0
- data/lib/caracal/core/models/list_item_model.rb +108 -0
- data/lib/caracal/core/models/list_model.rb +132 -0
- data/lib/caracal/core/models/list_style_model.rb +118 -0
- data/lib/caracal/core/models/margin_model.rb +76 -0
- data/lib/caracal/core/models/namespace_model.rb +65 -0
- data/lib/caracal/core/models/page_break_model.rb +61 -0
- data/lib/caracal/core/models/page_number_model.rb +95 -0
- data/lib/caracal/core/models/page_size_model.rb +79 -0
- data/lib/caracal/core/models/paragraph_model.rb +186 -0
- data/lib/caracal/core/models/relationship_model.rb +114 -0
- data/lib/caracal/core/models/rule_model.rb +27 -0
- data/lib/caracal/core/models/style_model.rb +165 -0
- data/lib/caracal/core/models/table_cell_model.rb +176 -0
- data/lib/caracal/core/models/table_model.rb +206 -0
- data/lib/caracal/core/models/text_model.rb +118 -0
- data/lib/caracal/core/namespaces.rb +89 -0
- data/lib/caracal/core/page_breaks.rb +29 -0
- data/lib/caracal/core/page_numbers.rb +58 -0
- data/lib/caracal/core/page_settings.rb +74 -0
- data/lib/caracal/core/relationships.rb +90 -0
- data/lib/caracal/core/rules.rb +35 -0
- data/lib/caracal/core/styles.rb +86 -0
- data/lib/caracal/core/tables.rb +42 -0
- data/lib/caracal/core/text.rb +75 -0
- data/lib/caracal/document.rb +272 -0
- data/lib/caracal/errors.rb +23 -0
- data/lib/caracal/renderers/app_renderer.rb +41 -0
- data/lib/caracal/renderers/content_types_renderer.rb +54 -0
- data/lib/caracal/renderers/core_renderer.rb +44 -0
- data/lib/caracal/renderers/custom_renderer.rb +64 -0
- data/lib/caracal/renderers/document_renderer.rb +427 -0
- data/lib/caracal/renderers/fonts_renderer.rb +56 -0
- data/lib/caracal/renderers/footer_renderer.rb +90 -0
- data/lib/caracal/renderers/numbering_renderer.rb +88 -0
- data/lib/caracal/renderers/package_relationships_renderer.rb +51 -0
- data/lib/caracal/renderers/relationships_renderer.rb +48 -0
- data/lib/caracal/renderers/settings_renderer.rb +58 -0
- data/lib/caracal/renderers/styles_renderer.rb +181 -0
- data/lib/caracal/renderers/xml_renderer.rb +83 -0
- data/lib/caracal/utilities.rb +23 -0
- data/lib/caracal/version.rb +3 -0
- data/lib/caracal.rb +40 -0
- data/lib/tilt/caracal.rb +21 -0
- data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
- data/spec/lib/caracal/core/file_name_spec.rb +54 -0
- data/spec/lib/caracal/core/fonts_spec.rb +119 -0
- data/spec/lib/caracal/core/iframes_spec.rb +29 -0
- data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
- data/spec/lib/caracal/core/images_spec.rb +25 -0
- data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
- data/spec/lib/caracal/core/lists_spec.rb +43 -0
- data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
- data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
- data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
- data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
- data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
- data/spec/lib/caracal/core/models/image_model_spec.rb +225 -0
- data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/link_model_spec.rb +179 -0
- data/spec/lib/caracal/core/models/list_item_model_spec.rb +197 -0
- data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
- data/spec/lib/caracal/core/models/list_style_model_spec.rb +198 -0
- data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
- data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
- data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
- data/spec/lib/caracal/core/models/page_number_model_spec.rb +136 -0
- data/spec/lib/caracal/core/models/page_size_model_spec.rb +101 -0
- data/spec/lib/caracal/core/models/paragraph_model_spec.rb +196 -0
- data/spec/lib/caracal/core/models/relationship_model_spec.rb +193 -0
- data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
- data/spec/lib/caracal/core/models/style_model_spec.rb +225 -0
- data/spec/lib/caracal/core/models/table_cell_model_spec.rb +230 -0
- data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
- data/spec/lib/caracal/core/models/text_model_spec.rb +154 -0
- data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
- data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
- data/spec/lib/caracal/core/page_numbers_spec.rb +89 -0
- data/spec/lib/caracal/core/page_settings_spec.rb +151 -0
- data/spec/lib/caracal/core/relationships_spec.rb +119 -0
- data/spec/lib/caracal/core/rules_spec.rb +25 -0
- data/spec/lib/caracal/core/styles_spec.rb +129 -0
- data/spec/lib/caracal/core/tables_spec.rb +25 -0
- data/spec/lib/caracal/core/text_spec.rb +52 -0
- data/spec/lib/caracal/errors_spec.rb +10 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/_fixtures/snippet.docx +0 -0
- metadata +292 -0
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::TableCellModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
background 'cccccc'
|
7
|
+
margins do
|
8
|
+
top 101
|
9
|
+
bottom 102
|
10
|
+
left 103
|
11
|
+
right 104
|
12
|
+
end
|
13
|
+
width 2000
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
#-------------------------------------------------------------
|
18
|
+
# Configuration
|
19
|
+
#-------------------------------------------------------------
|
20
|
+
|
21
|
+
describe 'configuration tests' do
|
22
|
+
|
23
|
+
# constants
|
24
|
+
describe 'constants' do
|
25
|
+
it { expect(described_class::DEFAULT_CELL_BACKGROUND).to eq 'ffffff' }
|
26
|
+
it { expect(described_class::DEFAULT_CELL_VERTICAL_ALIGN).to eq :top }
|
27
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS).to be_a(Caracal::Core::Models::MarginModel) }
|
28
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_top).to eq 100 }
|
29
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_bottom).to eq 100 }
|
30
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_left).to eq 100 }
|
31
|
+
it { expect(described_class::DEFAULT_CELL_MARGINS.margin_right).to eq 100 }
|
32
|
+
end
|
33
|
+
|
34
|
+
# accessors
|
35
|
+
describe 'accessors' do
|
36
|
+
it { expect(subject.cell_background).to eq 'cccccc' }
|
37
|
+
it { expect(subject.cell_margins).to be_a(Caracal::Core::Models::MarginModel) }
|
38
|
+
it { expect(subject.cell_width).to eq 2000 }
|
39
|
+
it { expect(subject.cell_vertical_align).to eq :top }
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
#-------------------------------------------------------------
|
46
|
+
# Public Methods
|
47
|
+
#-------------------------------------------------------------
|
48
|
+
|
49
|
+
describe 'public method tests' do
|
50
|
+
|
51
|
+
#=============== DATA ACCESSORS ====================
|
52
|
+
|
53
|
+
describe 'data tests' do
|
54
|
+
|
55
|
+
# .contents
|
56
|
+
describe '.contents' do
|
57
|
+
it { expect(subject.contents).to be_a(Array) }
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
#=============== GETTERS ==========================
|
64
|
+
|
65
|
+
describe 'getter tests' do
|
66
|
+
|
67
|
+
# margin attrs
|
68
|
+
describe 'margin attr tests' do
|
69
|
+
let(:model) { Caracal::Core::Models::MarginModel.new({ top: 201, bottom: 202, left: 203, right: 204 }) }
|
70
|
+
|
71
|
+
before do
|
72
|
+
allow(subject).to receive(:cell_margins).and_return(model)
|
73
|
+
end
|
74
|
+
|
75
|
+
[:top, :bottom, :left, :right].each do |m|
|
76
|
+
describe "cell_margin_#{ m }" do
|
77
|
+
it { expect(subject.send("cell_margin_#{ m }")).to eq model.send("margin_#{ m }") }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
#=============== SETTERS ==========================
|
86
|
+
|
87
|
+
# .background
|
88
|
+
describe '.background' do
|
89
|
+
before { subject.background('999999') }
|
90
|
+
|
91
|
+
it { expect(subject.cell_background).to eq '999999' }
|
92
|
+
end
|
93
|
+
|
94
|
+
# .width
|
95
|
+
describe '.width' do
|
96
|
+
before { subject.width(7500) }
|
97
|
+
|
98
|
+
it { expect(subject.cell_width).to eq 7500 }
|
99
|
+
end
|
100
|
+
|
101
|
+
#.vertical_allign
|
102
|
+
describe '.vertical_align' do
|
103
|
+
before { subject.vertical_align(:center) }
|
104
|
+
|
105
|
+
it { expect(subject.cell_vertical_align).to eq :center }
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
#=============== CONTENT FNS =======================
|
110
|
+
|
111
|
+
describe 'content functions' do
|
112
|
+
|
113
|
+
# .p
|
114
|
+
describe '.p' do
|
115
|
+
let!(:size) { subject.contents.size }
|
116
|
+
|
117
|
+
before { subject.p }
|
118
|
+
|
119
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
120
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ParagraphModel) }
|
121
|
+
end
|
122
|
+
|
123
|
+
# .img
|
124
|
+
describe '.img' do
|
125
|
+
let!(:size) { subject.contents.size }
|
126
|
+
|
127
|
+
before { subject.img 'https://www.google.com/images/srpr/logo11w.png', width: 538, height: 190 }
|
128
|
+
|
129
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
130
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ImageModel) }
|
131
|
+
end
|
132
|
+
|
133
|
+
# .ol
|
134
|
+
describe '.ol' do
|
135
|
+
let!(:size) { subject.contents.size }
|
136
|
+
|
137
|
+
before do
|
138
|
+
subject.ol do
|
139
|
+
li 'Item 1'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
144
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
|
145
|
+
end
|
146
|
+
|
147
|
+
# .ul
|
148
|
+
describe '.ul' do
|
149
|
+
let!(:size) { subject.contents.size }
|
150
|
+
|
151
|
+
before do
|
152
|
+
subject.ul do
|
153
|
+
li 'Item 1'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
158
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ListModel) }
|
159
|
+
end
|
160
|
+
|
161
|
+
# .hr
|
162
|
+
describe '.hr' do
|
163
|
+
let!(:size) { subject.contents.size }
|
164
|
+
|
165
|
+
before { subject.hr }
|
166
|
+
|
167
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
168
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::RuleModel) }
|
169
|
+
end
|
170
|
+
|
171
|
+
# .table
|
172
|
+
describe '.table' do
|
173
|
+
let!(:size) { subject.contents.size }
|
174
|
+
|
175
|
+
before { subject.table [['Sample Text']] }
|
176
|
+
|
177
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
178
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::TableModel) }
|
179
|
+
end
|
180
|
+
|
181
|
+
# text
|
182
|
+
[:p, :h1, :h2, :h3, :h4, :h5, :h6].each do |cmd|
|
183
|
+
describe ".#{ cmd }" do
|
184
|
+
let!(:size) { subject.contents.size }
|
185
|
+
|
186
|
+
before { subject.send(cmd, 'Sample text.') }
|
187
|
+
|
188
|
+
it { expect(subject.contents.size).to eq size + 1 }
|
189
|
+
it { expect(subject.contents.last).to be_a(Caracal::Core::Models::ParagraphModel) }
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
#=============== VALIDATION ========================
|
197
|
+
|
198
|
+
describe '.valid?' do
|
199
|
+
describe 'when content provided' do
|
200
|
+
before { allow(subject).to receive(:contents).and_return(['a']) }
|
201
|
+
|
202
|
+
it { expect(subject.valid?).to eq true }
|
203
|
+
end
|
204
|
+
describe 'when content not provided' do
|
205
|
+
before { allow(subject).to receive(:contents).and_return([]) }
|
206
|
+
|
207
|
+
it { expect(subject.valid?).to eq false }
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
#-------------------------------------------------------------
|
215
|
+
# Private Methods
|
216
|
+
#-------------------------------------------------------------
|
217
|
+
|
218
|
+
describe 'private method tests' do
|
219
|
+
|
220
|
+
# .option_keys
|
221
|
+
describe '.option_keys' do
|
222
|
+
let(:actual) { subject.send(:option_keys).sort }
|
223
|
+
let(:expected) { [:background, :colspan, :rowspan, :width, :vertical_align, :margins].sort }
|
224
|
+
|
225
|
+
it { expect(actual).to eq expected }
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::TableModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
data [ ['top lft', 'top right'], ['bottom left', 'bottom right'] ]
|
7
|
+
align :right
|
8
|
+
border_color '666666'
|
9
|
+
border_line :double
|
10
|
+
border_size 8
|
11
|
+
border_spacing 4
|
12
|
+
width 8000
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#-------------------------------------------------------------
|
17
|
+
# Configuration
|
18
|
+
#-------------------------------------------------------------
|
19
|
+
|
20
|
+
describe 'configuration tests' do
|
21
|
+
|
22
|
+
# constants
|
23
|
+
describe 'constants' do
|
24
|
+
it { expect(described_class::DEFAULT_TABLE_ALIGN).to eq :center }
|
25
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_COLOR).to eq 'auto' }
|
26
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_LINE).to eq :single }
|
27
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_SIZE).to eq 0 }
|
28
|
+
it { expect(described_class::DEFAULT_TABLE_BORDER_SPACING).to eq 0 }
|
29
|
+
end
|
30
|
+
|
31
|
+
# accessors
|
32
|
+
describe 'accessors' do
|
33
|
+
it { expect(subject.table_align).to eq :right }
|
34
|
+
it { expect(subject.table_width).to eq 8000 }
|
35
|
+
it { expect(subject.table_border_color).to eq '666666' }
|
36
|
+
it { expect(subject.table_border_line).to eq :double }
|
37
|
+
it { expect(subject.table_border_size).to eq 8 }
|
38
|
+
it { expect(subject.table_border_spacing).to eq 4 }
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#-------------------------------------------------------------
|
45
|
+
# Public Methods
|
46
|
+
#-------------------------------------------------------------
|
47
|
+
|
48
|
+
describe 'public method tests' do
|
49
|
+
|
50
|
+
#=============== DATA ACCESSORS ====================
|
51
|
+
|
52
|
+
describe 'data tests' do
|
53
|
+
let(:data) { [['top left', 'top right'], ['bottom left', 'bottom right']] }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow(subject).to receive(:rows).and_return(data)
|
57
|
+
end
|
58
|
+
|
59
|
+
# .rows
|
60
|
+
describe '.rows' do
|
61
|
+
it { expect(subject.rows[0]).to be_a(Array) }
|
62
|
+
it { expect(subject.rows[0][1]).to eq 'top right' }
|
63
|
+
end
|
64
|
+
|
65
|
+
# .cols
|
66
|
+
describe '.cols' do
|
67
|
+
it { expect(subject.cols[0]).to be_a(Array) }
|
68
|
+
it { expect(subject.cols[0][1]).to eq 'bottom left' }
|
69
|
+
end
|
70
|
+
|
71
|
+
# .cells
|
72
|
+
describe '.cells' do
|
73
|
+
it { expect(subject.cells[0]).to eq 'top left' }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
#=============== GETTERS ==========================
|
79
|
+
|
80
|
+
describe 'getter tests' do
|
81
|
+
|
82
|
+
# border attrs
|
83
|
+
describe 'border attr tests' do
|
84
|
+
let(:model) { Caracal::Core::Models::BorderModel.new({ color: '000000', line: :double, size: 10, spacing: 2 }) }
|
85
|
+
|
86
|
+
before do
|
87
|
+
allow(subject).to receive(:table_border_color).and_return('auto')
|
88
|
+
allow(subject).to receive(:table_border_line).and_return(:single)
|
89
|
+
allow(subject).to receive(:table_border_size).and_return(8)
|
90
|
+
allow(subject).to receive(:table_border_spacing).and_return(1)
|
91
|
+
end
|
92
|
+
|
93
|
+
[:top, :bottom, :left, :right, :horizontal, :vertical].each do |m|
|
94
|
+
[:color, :line, :size, :spacing].each do |attr|
|
95
|
+
describe "table_border_#{ m }_#{ attr }" do
|
96
|
+
let(:actual) { subject.send("table_border_#{ m }_#{ attr }") }
|
97
|
+
|
98
|
+
describe 'when detailed setting present' do
|
99
|
+
before do
|
100
|
+
allow(subject).to receive("table_border_#{ m }").and_return(model)
|
101
|
+
end
|
102
|
+
|
103
|
+
it { expect(actual).to eq model.send("border_#{ attr }") }
|
104
|
+
end
|
105
|
+
describe 'when detailed setting not present' do
|
106
|
+
before do
|
107
|
+
allow(subject).to receive("table_border_#{ m }").and_return(nil)
|
108
|
+
end
|
109
|
+
|
110
|
+
it { expect(actual).to eq subject.send("table_border_#{ attr }") }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
describe "table_border_#{ m }_total_size" do
|
115
|
+
let(:actual) { subject.send("table_border_#{ m }_total_size") }
|
116
|
+
|
117
|
+
describe 'when detailed setting present' do
|
118
|
+
before do
|
119
|
+
allow(subject).to receive("table_border_#{ m }").and_return(model)
|
120
|
+
end
|
121
|
+
|
122
|
+
it { expect(actual).to eq model.total_size }
|
123
|
+
end
|
124
|
+
describe 'when detailed setting not present' do
|
125
|
+
before do
|
126
|
+
allow(subject).to receive("table_border_#{ m }").and_return(nil)
|
127
|
+
end
|
128
|
+
|
129
|
+
it { expect(actual).to eq subject.send("table_border_#{ m }_total_size") }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
#=============== SETTERS ==========================
|
139
|
+
|
140
|
+
# .align
|
141
|
+
describe '.align' do
|
142
|
+
before { subject.align(:center) }
|
143
|
+
|
144
|
+
it { expect(subject.table_align).to eq :center }
|
145
|
+
end
|
146
|
+
|
147
|
+
# .border_color
|
148
|
+
describe '.border_color' do
|
149
|
+
before { subject.border_color('999999') }
|
150
|
+
|
151
|
+
it { expect(subject.table_border_color).to eq '999999' }
|
152
|
+
end
|
153
|
+
|
154
|
+
# .border_line
|
155
|
+
describe '.border_line' do
|
156
|
+
before { subject.border_line(:none) }
|
157
|
+
|
158
|
+
it { expect(subject.table_border_line).to eq :none }
|
159
|
+
end
|
160
|
+
|
161
|
+
# .border_size
|
162
|
+
describe '.border_size' do
|
163
|
+
before { subject.border_size(24) }
|
164
|
+
|
165
|
+
it { expect(subject.table_border_size).to eq 24 }
|
166
|
+
end
|
167
|
+
|
168
|
+
# .border_spacing
|
169
|
+
describe '.border_spacing' do
|
170
|
+
before { subject.border_spacing(16) }
|
171
|
+
|
172
|
+
it { expect(subject.table_border_spacing).to eq 16 }
|
173
|
+
end
|
174
|
+
|
175
|
+
# .width
|
176
|
+
describe '.width' do
|
177
|
+
before { subject.width(7500) }
|
178
|
+
|
179
|
+
it { expect(subject.table_width).to eq 7500 }
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
#=============== VALIDATION ===========================
|
186
|
+
|
187
|
+
describe '.valid?' do
|
188
|
+
describe 'when data provided' do
|
189
|
+
it { expect(subject.valid?).to eq true }
|
190
|
+
end
|
191
|
+
describe 'when no data provided' do
|
192
|
+
before do
|
193
|
+
allow(subject).to receive(:cells).and_return([[]])
|
194
|
+
end
|
195
|
+
|
196
|
+
it { expect(subject.valid?).to eq false }
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
#-------------------------------------------------------------
|
204
|
+
# Private Methods
|
205
|
+
#-------------------------------------------------------------
|
206
|
+
|
207
|
+
describe 'private method tests' do
|
208
|
+
|
209
|
+
# .option_keys
|
210
|
+
describe '.option_keys' do
|
211
|
+
let(:actual) { subject.send(:option_keys).sort }
|
212
|
+
let(:expected1) { [:data, :align, :width] }
|
213
|
+
let(:expected2) { [:border_color, :border_line, :border_size, :border_spacing] }
|
214
|
+
let(:expected3) { [:border_top, :border_bottom, :border_left, :border_right, :border_horizontal, :border_vertical] }
|
215
|
+
let(:expected) { (expected1 + expected2 + expected3).sort }
|
216
|
+
|
217
|
+
it { expect(actual).to eq expected }
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Caracal::Core::Models::TextModel do
|
4
|
+
subject do
|
5
|
+
described_class.new do
|
6
|
+
content 'Lorem ipsum dolor....'
|
7
|
+
font 'Courier New'
|
8
|
+
color '666666'
|
9
|
+
size 20
|
10
|
+
bold false
|
11
|
+
italic false
|
12
|
+
underline true
|
13
|
+
bgcolor 'cccccc'
|
14
|
+
vertical_align :subscript
|
15
|
+
highlight_color 'yellow'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#-------------------------------------------------------------
|
20
|
+
# Configuration
|
21
|
+
#-------------------------------------------------------------
|
22
|
+
|
23
|
+
describe 'configuration tests' do
|
24
|
+
|
25
|
+
# accessors
|
26
|
+
describe 'accessors' do
|
27
|
+
it { expect(subject.text_content).to eq 'Lorem ipsum dolor....' }
|
28
|
+
it { expect(subject.text_font).to eq 'Courier New' }
|
29
|
+
it { expect(subject.text_color).to eq '666666' }
|
30
|
+
it { expect(subject.text_size).to eq 20 }
|
31
|
+
it { expect(subject.text_bold).to eq false }
|
32
|
+
it { expect(subject.text_italic).to eq false }
|
33
|
+
it { expect(subject.text_underline).to eq true }
|
34
|
+
it { expect(subject.text_bgcolor).to eq 'cccccc' }
|
35
|
+
it { expect(subject.text_highlight_color).to eq 'yellow' }
|
36
|
+
it { expect(subject.text_vertical_align).to eq :subscript }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
#-------------------------------------------------------------
|
43
|
+
# Public Methods
|
44
|
+
#-------------------------------------------------------------
|
45
|
+
|
46
|
+
describe 'public method tests' do
|
47
|
+
|
48
|
+
#=============== GETTERS ==========================
|
49
|
+
|
50
|
+
# .run_attributes
|
51
|
+
describe '.run_attributes' do
|
52
|
+
let(:expected) { { style: nil, font: 'Courier New', color: '666666', size: 20, bold: false, italic: false, underline: true, bgcolor: 'cccccc', highlight_color: 'yellow', vertical_align: :subscript } }
|
53
|
+
|
54
|
+
it { expect(subject.run_attributes).to eq expected }
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
#=============== SETTERS ==========================
|
59
|
+
|
60
|
+
# booleans
|
61
|
+
describe '.bold' do
|
62
|
+
before { subject.bold(true) }
|
63
|
+
|
64
|
+
it { expect(subject.text_bold).to eq true }
|
65
|
+
end
|
66
|
+
describe '.italic' do
|
67
|
+
before { subject.italic(true) }
|
68
|
+
|
69
|
+
it { expect(subject.text_italic).to eq true }
|
70
|
+
end
|
71
|
+
describe '.underline' do
|
72
|
+
before { subject.underline(true) }
|
73
|
+
|
74
|
+
it { expect(subject.text_underline).to eq true }
|
75
|
+
end
|
76
|
+
|
77
|
+
# integers
|
78
|
+
describe '.size' do
|
79
|
+
before { subject.size(24) }
|
80
|
+
|
81
|
+
it { expect(subject.text_size).to eq 24 }
|
82
|
+
end
|
83
|
+
|
84
|
+
# strings
|
85
|
+
describe '.bgcolor' do
|
86
|
+
before { subject.bgcolor('dddddd') }
|
87
|
+
|
88
|
+
it { expect(subject.text_bgcolor).to eq 'dddddd' }
|
89
|
+
end
|
90
|
+
describe '.color' do
|
91
|
+
before { subject.color('999999') }
|
92
|
+
|
93
|
+
it { expect(subject.text_color).to eq '999999' }
|
94
|
+
end
|
95
|
+
describe '.content' do
|
96
|
+
before { subject.content('Something Else') }
|
97
|
+
|
98
|
+
it { expect(subject.text_content).to eq 'Something Else' }
|
99
|
+
end
|
100
|
+
describe '.font' do
|
101
|
+
before { subject.font('Palantino') }
|
102
|
+
|
103
|
+
it { expect(subject.text_font).to eq 'Palantino' }
|
104
|
+
end
|
105
|
+
describe '.hightlight_color' do
|
106
|
+
before { subject.highlight_color('green') }
|
107
|
+
|
108
|
+
it { expect(subject.text_highlight_color).to eq 'green' }
|
109
|
+
end
|
110
|
+
|
111
|
+
#symbols
|
112
|
+
describe '.vertical_align' do
|
113
|
+
before { subject.vertical_align(:superscript) }
|
114
|
+
|
115
|
+
it { expect(subject.text_vertical_align).to eq :superscript }
|
116
|
+
end
|
117
|
+
|
118
|
+
#=============== VALIDATION ===========================
|
119
|
+
|
120
|
+
describe '.valid?' do
|
121
|
+
describe 'when required attributes provided' do
|
122
|
+
it { expect(subject.valid?).to eq true }
|
123
|
+
end
|
124
|
+
[:content].each do |prop|
|
125
|
+
describe "when #{ prop } nil" do
|
126
|
+
before do
|
127
|
+
allow(subject).to receive("text_#{ prop }").and_return(nil)
|
128
|
+
end
|
129
|
+
|
130
|
+
it { expect(subject.valid?).to eq false }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
#-------------------------------------------------------------
|
139
|
+
# Private Methods
|
140
|
+
#-------------------------------------------------------------
|
141
|
+
|
142
|
+
describe 'private method tests' do
|
143
|
+
|
144
|
+
# .option_keys
|
145
|
+
describe '.option_keys' do
|
146
|
+
let(:actual) { subject.send(:option_keys).sort }
|
147
|
+
let(:expected) { [:bgcolor, :bold, :color, :content, :font, :highlight_color, :italic, :size, :style, :underline, :vertical_align].sort }
|
148
|
+
|
149
|
+
it { expect(actual).to eq expected }
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|