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.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +22 -0
  3. data/.github/workflows/publish_gem.yml +40 -0
  4. data/.gitignore +25 -0
  5. data/.travis.yml +20 -0
  6. data/CHANGELOG.md +141 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +842 -0
  10. data/Rakefile +7 -0
  11. data/caracal.gemspec +28 -0
  12. data/lib/caracal/core/bookmarks.rb +52 -0
  13. data/lib/caracal/core/custom_properties.rb +49 -0
  14. data/lib/caracal/core/file_name.rb +43 -0
  15. data/lib/caracal/core/fonts.rb +75 -0
  16. data/lib/caracal/core/iframes.rb +42 -0
  17. data/lib/caracal/core/ignorables.rb +47 -0
  18. data/lib/caracal/core/images.rb +37 -0
  19. data/lib/caracal/core/list_styles.rb +93 -0
  20. data/lib/caracal/core/lists.rb +57 -0
  21. data/lib/caracal/core/models/base_model.rb +51 -0
  22. data/lib/caracal/core/models/bookmark_model.rb +86 -0
  23. data/lib/caracal/core/models/border_model.rb +120 -0
  24. data/lib/caracal/core/models/custom_property_model.rb +60 -0
  25. data/lib/caracal/core/models/font_model.rb +64 -0
  26. data/lib/caracal/core/models/iframe_model.rb +148 -0
  27. data/lib/caracal/core/models/image_model.rb +133 -0
  28. data/lib/caracal/core/models/line_break_model.rb +15 -0
  29. data/lib/caracal/core/models/link_model.rb +94 -0
  30. data/lib/caracal/core/models/list_item_model.rb +108 -0
  31. data/lib/caracal/core/models/list_model.rb +132 -0
  32. data/lib/caracal/core/models/list_style_model.rb +118 -0
  33. data/lib/caracal/core/models/margin_model.rb +76 -0
  34. data/lib/caracal/core/models/namespace_model.rb +65 -0
  35. data/lib/caracal/core/models/page_break_model.rb +61 -0
  36. data/lib/caracal/core/models/page_number_model.rb +95 -0
  37. data/lib/caracal/core/models/page_size_model.rb +79 -0
  38. data/lib/caracal/core/models/paragraph_model.rb +186 -0
  39. data/lib/caracal/core/models/relationship_model.rb +114 -0
  40. data/lib/caracal/core/models/rule_model.rb +27 -0
  41. data/lib/caracal/core/models/style_model.rb +165 -0
  42. data/lib/caracal/core/models/table_cell_model.rb +176 -0
  43. data/lib/caracal/core/models/table_model.rb +206 -0
  44. data/lib/caracal/core/models/text_model.rb +118 -0
  45. data/lib/caracal/core/namespaces.rb +89 -0
  46. data/lib/caracal/core/page_breaks.rb +29 -0
  47. data/lib/caracal/core/page_numbers.rb +58 -0
  48. data/lib/caracal/core/page_settings.rb +74 -0
  49. data/lib/caracal/core/relationships.rb +90 -0
  50. data/lib/caracal/core/rules.rb +35 -0
  51. data/lib/caracal/core/styles.rb +86 -0
  52. data/lib/caracal/core/tables.rb +42 -0
  53. data/lib/caracal/core/text.rb +75 -0
  54. data/lib/caracal/document.rb +272 -0
  55. data/lib/caracal/errors.rb +23 -0
  56. data/lib/caracal/renderers/app_renderer.rb +41 -0
  57. data/lib/caracal/renderers/content_types_renderer.rb +54 -0
  58. data/lib/caracal/renderers/core_renderer.rb +44 -0
  59. data/lib/caracal/renderers/custom_renderer.rb +64 -0
  60. data/lib/caracal/renderers/document_renderer.rb +427 -0
  61. data/lib/caracal/renderers/fonts_renderer.rb +56 -0
  62. data/lib/caracal/renderers/footer_renderer.rb +90 -0
  63. data/lib/caracal/renderers/numbering_renderer.rb +88 -0
  64. data/lib/caracal/renderers/package_relationships_renderer.rb +51 -0
  65. data/lib/caracal/renderers/relationships_renderer.rb +48 -0
  66. data/lib/caracal/renderers/settings_renderer.rb +58 -0
  67. data/lib/caracal/renderers/styles_renderer.rb +181 -0
  68. data/lib/caracal/renderers/xml_renderer.rb +83 -0
  69. data/lib/caracal/utilities.rb +23 -0
  70. data/lib/caracal/version.rb +3 -0
  71. data/lib/caracal.rb +40 -0
  72. data/lib/tilt/caracal.rb +21 -0
  73. data/spec/lib/caracal/core/bookmarks_spec.rb +35 -0
  74. data/spec/lib/caracal/core/file_name_spec.rb +54 -0
  75. data/spec/lib/caracal/core/fonts_spec.rb +119 -0
  76. data/spec/lib/caracal/core/iframes_spec.rb +29 -0
  77. data/spec/lib/caracal/core/ignorables_spec.rb +79 -0
  78. data/spec/lib/caracal/core/images_spec.rb +25 -0
  79. data/spec/lib/caracal/core/list_styles_spec.rb +121 -0
  80. data/spec/lib/caracal/core/lists_spec.rb +43 -0
  81. data/spec/lib/caracal/core/models/base_model_spec.rb +38 -0
  82. data/spec/lib/caracal/core/models/bookmark_model_spec.rb +135 -0
  83. data/spec/lib/caracal/core/models/border_model_spec.rb +159 -0
  84. data/spec/lib/caracal/core/models/font_model_spec.rb +92 -0
  85. data/spec/lib/caracal/core/models/iframe_model_spec.rb +83 -0
  86. data/spec/lib/caracal/core/models/image_model_spec.rb +225 -0
  87. data/spec/lib/caracal/core/models/line_break_model_spec.rb +21 -0
  88. data/spec/lib/caracal/core/models/link_model_spec.rb +179 -0
  89. data/spec/lib/caracal/core/models/list_item_model_spec.rb +197 -0
  90. data/spec/lib/caracal/core/models/list_model_spec.rb +178 -0
  91. data/spec/lib/caracal/core/models/list_style_model_spec.rb +198 -0
  92. data/spec/lib/caracal/core/models/margin_model_spec.rb +111 -0
  93. data/spec/lib/caracal/core/models/namespace_model_spec.rb +107 -0
  94. data/spec/lib/caracal/core/models/page_break_model_spec.rb +21 -0
  95. data/spec/lib/caracal/core/models/page_number_model_spec.rb +136 -0
  96. data/spec/lib/caracal/core/models/page_size_model_spec.rb +101 -0
  97. data/spec/lib/caracal/core/models/paragraph_model_spec.rb +196 -0
  98. data/spec/lib/caracal/core/models/relationship_model_spec.rb +193 -0
  99. data/spec/lib/caracal/core/models/rule_model_spec.rb +108 -0
  100. data/spec/lib/caracal/core/models/style_model_spec.rb +225 -0
  101. data/spec/lib/caracal/core/models/table_cell_model_spec.rb +230 -0
  102. data/spec/lib/caracal/core/models/table_model_spec.rb +222 -0
  103. data/spec/lib/caracal/core/models/text_model_spec.rb +154 -0
  104. data/spec/lib/caracal/core/namespaces_spec.rb +116 -0
  105. data/spec/lib/caracal/core/page_breaks_spec.rb +25 -0
  106. data/spec/lib/caracal/core/page_numbers_spec.rb +89 -0
  107. data/spec/lib/caracal/core/page_settings_spec.rb +151 -0
  108. data/spec/lib/caracal/core/relationships_spec.rb +119 -0
  109. data/spec/lib/caracal/core/rules_spec.rb +25 -0
  110. data/spec/lib/caracal/core/styles_spec.rb +129 -0
  111. data/spec/lib/caracal/core/tables_spec.rb +25 -0
  112. data/spec/lib/caracal/core/text_spec.rb +52 -0
  113. data/spec/lib/caracal/errors_spec.rb +10 -0
  114. data/spec/spec_helper.rb +8 -0
  115. data/spec/support/_fixtures/snippet.docx +0 -0
  116. metadata +292 -0
@@ -0,0 +1,198 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::ListStyleModel do
4
+ subject do
5
+ described_class.new do
6
+ type :ordered
7
+ level 2
8
+ format 'decimal'
9
+ value '%3.'
10
+ align :right
11
+ left 800
12
+ indent 400
13
+ start 2
14
+ restart 2
15
+ end
16
+ end
17
+
18
+ #-------------------------------------------------------------
19
+ # Configuration
20
+ #-------------------------------------------------------------
21
+
22
+ describe 'configuration tests' do
23
+
24
+ # constants
25
+ describe 'constants' do
26
+ it { expect(described_class::DEFAULT_STYLE_ALIGN).to eq :left }
27
+ it { expect(described_class::DEFAULT_STYLE_LEFT).to eq 720 }
28
+ it { expect(described_class::DEFAULT_STYLE_INDENT).to eq 360 }
29
+ it { expect(described_class::DEFAULT_STYLE_START).to eq 1 }
30
+ it { expect(described_class::DEFAULT_STYLE_RESTART).to eq 1 }
31
+ end
32
+
33
+ # accessors
34
+ describe 'accessors' do
35
+ it { expect(subject.style_type).to eq :ordered }
36
+ it { expect(subject.style_level).to eq 2 }
37
+ it { expect(subject.style_format).to eq 'decimal' }
38
+ it { expect(subject.style_value).to eq '%3.' }
39
+ it { expect(subject.style_align).to eq :right }
40
+ it { expect(subject.style_left).to eq 800 }
41
+ it { expect(subject.style_indent).to eq 400 }
42
+ it { expect(subject.style_start).to eq 2 }
43
+ it { expect(subject.style_restart).to eq 2 }
44
+ end
45
+
46
+ end
47
+
48
+
49
+ #-------------------------------------------------------------
50
+ # Class Methods
51
+ #-------------------------------------------------------------
52
+
53
+ describe 'class method tests' do
54
+ subject { described_class }
55
+
56
+ # .formatted_type
57
+ describe '.formatted_type' do
58
+ it { expect(subject.formatted_type(:ordered)).to eq 1 }
59
+ it { expect(subject.formatted_type(:unordered)).to eq 2 }
60
+ end
61
+
62
+ end
63
+
64
+
65
+
66
+ #-------------------------------------------------------------
67
+ # Public Methods
68
+ #-------------------------------------------------------------
69
+
70
+ describe 'public method tests' do
71
+
72
+ #=============== GETTERS ==========================
73
+
74
+ # .formatted_type
75
+ describe '.formatted_type' do
76
+ describe 'when ordered list' do
77
+ before { allow(subject).to receive(:style_type).and_return(:ordered) }
78
+
79
+ it { expect(subject.formatted_type).to eq 1 }
80
+ end
81
+ describe 'when unordered list' do
82
+ before { allow(subject).to receive(:style_type).and_return(:unordered) }
83
+
84
+ it { expect(subject.formatted_type).to eq 2 }
85
+ end
86
+ end
87
+
88
+
89
+ #=============== SETTERS ==========================
90
+
91
+ # booleans
92
+ describe '.restart' do
93
+ before { subject.restart(3) }
94
+
95
+ it { expect(subject.style_restart).to eq 3 }
96
+ end
97
+
98
+ # integers
99
+ describe '.level' do
100
+ before { subject.level(2) }
101
+
102
+ it { expect(subject.style_level).to eq 2 }
103
+ end
104
+ describe '.left' do
105
+ before { subject.left(800) }
106
+
107
+ it { expect(subject.style_left).to eq 800 }
108
+ end
109
+ describe '.indent' do
110
+ before { subject.indent(400) }
111
+
112
+ it { expect(subject.style_indent).to eq 400 }
113
+ end
114
+ describe '.start' do
115
+ before { subject.start(2) }
116
+
117
+ it { expect(subject.style_start).to eq 2 }
118
+ end
119
+
120
+ # strings
121
+ describe '.format' do
122
+ before { subject.format('decimal') }
123
+
124
+ it { expect(subject.style_format).to eq 'decimal' }
125
+ end
126
+ describe '.value' do
127
+ before { subject.value('%3.') }
128
+
129
+ it { expect(subject.style_value).to eq '%3.' }
130
+ end
131
+
132
+ # symbols
133
+ describe '.type' do
134
+ before { subject.type(:ordered) }
135
+
136
+ it { expect(subject.style_type).to eq :ordered }
137
+ end
138
+ describe '.align' do
139
+ before { subject.align(:right) }
140
+
141
+ it { expect(subject.style_align).to eq :right }
142
+ end
143
+
144
+
145
+ #=================== STATE ===============================
146
+
147
+ # .matches?
148
+ describe '.matches?' do
149
+ describe 'when search terms match' do
150
+ let(:actual) { subject.matches?(:ordered, 2) }
151
+
152
+ it { expect(actual).to eq true }
153
+ end
154
+ describe 'when search term does not match' do
155
+ let(:actual) { subject.matches?(:unordered, 4) }
156
+
157
+ it { expect(actual).to eq false }
158
+ end
159
+ end
160
+
161
+
162
+ #=============== VALIDATION ===========================
163
+
164
+ describe '.valid?' do
165
+ describe 'when required attributes provided' do
166
+ it { expect(subject.valid?).to eq true }
167
+ end
168
+ [:type, :level, :format, :value].each do |prop|
169
+ describe "when #{ prop } nil" do
170
+ before do
171
+ allow(subject).to receive("style_#{ prop }").and_return(nil)
172
+ end
173
+
174
+ it { expect(subject.valid?).to eq false }
175
+ end
176
+ end
177
+ end
178
+
179
+ end
180
+
181
+
182
+ #-------------------------------------------------------------
183
+ # Private Methods
184
+ #-------------------------------------------------------------
185
+
186
+ describe 'private method tests' do
187
+
188
+ # .option_keys
189
+ describe '.option_keys' do
190
+ let(:actual) { subject.send(:option_keys).sort }
191
+ let(:expected) { [:type, :level, :format, :value, :align, :left, :indent, :start].sort }
192
+
193
+ it { expect(actual).to eq expected }
194
+ end
195
+
196
+ end
197
+
198
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::MarginModel do
4
+ subject do
5
+ described_class.new do
6
+ top 1441
7
+ bottom 1442
8
+ left 1443
9
+ right 1444
10
+ end
11
+ end
12
+
13
+ #-------------------------------------------------------------
14
+ # Configuration
15
+ #-------------------------------------------------------------
16
+
17
+ describe 'configuration tests' do
18
+
19
+ # constants
20
+ describe 'constants' do
21
+ it { expect(described_class::DEFAULT_MARGIN_TOP).to eq 0 }
22
+ it { expect(described_class::DEFAULT_MARGIN_BOTTOM).to eq 0 }
23
+ it { expect(described_class::DEFAULT_MARGIN_LEFT).to eq 0 }
24
+ it { expect(described_class::DEFAULT_MARGIN_RIGHT).to eq 0 }
25
+ end
26
+
27
+ # accessors
28
+ describe 'accessors' do
29
+ it { expect(subject.margin_top).to eq 1441 }
30
+ it { expect(subject.margin_bottom).to eq 1442 }
31
+ it { expect(subject.margin_left).to eq 1443 }
32
+ it { expect(subject.margin_right).to eq 1444 }
33
+ end
34
+
35
+ end
36
+
37
+
38
+ #-------------------------------------------------------------
39
+ # Public Methods
40
+ #-------------------------------------------------------------
41
+
42
+ describe 'public method tests' do
43
+
44
+ #=============== SETTERS ==========================
45
+
46
+ # .top
47
+ describe '.top' do
48
+ before { subject.top(1000) }
49
+
50
+ it { expect(subject.margin_top).to eq 1000 }
51
+ end
52
+
53
+ # .bottom
54
+ describe '.bottom' do
55
+ before { subject.bottom(1000) }
56
+
57
+ it { expect(subject.margin_bottom).to eq 1000 }
58
+ end
59
+
60
+ # .left
61
+ describe '.left' do
62
+ before { subject.left(1000) }
63
+
64
+ it { expect(subject.margin_left).to eq 1000 }
65
+ end
66
+
67
+ # .right
68
+ describe '.right' do
69
+ before { subject.right(1000) }
70
+
71
+ it { expect(subject.margin_right).to eq 1000 }
72
+ end
73
+
74
+
75
+ #=============== VALIDATION ===========================
76
+
77
+ describe '.valid?' do
78
+ describe 'when all margins gt 0' do
79
+ it { expect(subject.valid?).to eq true }
80
+ end
81
+ [:top, :bottom, :left, :right].each do |d|
82
+ describe "when #{ d } lte 0" do
83
+ before do
84
+ allow(subject).to receive("margin_#{ d }").and_return(0)
85
+ end
86
+
87
+ it { expect(subject.valid?).to eq false }
88
+ end
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+
95
+ #-------------------------------------------------------------
96
+ # Private Methods
97
+ #-------------------------------------------------------------
98
+
99
+ describe 'private method tests' do
100
+
101
+ # .option_keys
102
+ describe '.option_keys' do
103
+ let(:actual) { subject.send(:option_keys).sort }
104
+ let(:expected) { [:top, :bottom, :left, :right].sort }
105
+
106
+ it { expect(actual).to eq expected }
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::NamespaceModel do
4
+ subject do
5
+ described_class.new do
6
+ prefix 'com'
7
+ href 'http://www.example.com'
8
+ end
9
+ end
10
+
11
+
12
+ #-------------------------------------------------------------
13
+ # Configuration
14
+ #-------------------------------------------------------------
15
+
16
+ describe 'configuration tests' do
17
+
18
+ # accessors
19
+ describe 'accessors' do
20
+ it { expect(subject.namespace_prefix).to eq 'com' }
21
+ it { expect(subject.namespace_href).to eq 'http://www.example.com' }
22
+ end
23
+
24
+ end
25
+
26
+
27
+ #-------------------------------------------------------------
28
+ # Public Methods
29
+ #-------------------------------------------------------------
30
+
31
+ describe 'public method tests' do
32
+
33
+ #=================== ATTRIBUTES ==========================
34
+
35
+ # .prefix
36
+ describe '.prefix' do
37
+ before do
38
+ subject.prefix('org')
39
+ end
40
+
41
+ it { expect(subject.namespace_prefix).to eq 'org' }
42
+ end
43
+
44
+ # .href
45
+ describe '.href' do
46
+ before do
47
+ subject.href('http://www.example.org')
48
+ end
49
+
50
+ it { expect(subject.namespace_href).to eq 'http://www.example.org' }
51
+ end
52
+
53
+
54
+ #=================== STATE ===============================
55
+
56
+ # .matches?
57
+ describe '.matches?' do
58
+ describe 'when search term matches key' do
59
+ let(:actual) { subject.matches?('com') }
60
+
61
+ it { expect(actual).to eq true }
62
+ end
63
+ describe 'when search term does not match key' do
64
+ let(:actual) { subject.matches?('org') }
65
+
66
+ it { expect(actual).to eq false }
67
+ end
68
+ end
69
+
70
+
71
+ #=============== VALIDATION ===========================
72
+
73
+ describe '.valid?' do
74
+ describe 'when prefix and href provided' do
75
+ it { expect(subject.valid?).to eq true }
76
+ end
77
+ [:prefix, :href].each do |prop|
78
+ describe "when #{ prop } nil" do
79
+ before do
80
+ allow(subject).to receive("namespace_#{ prop }").and_return(nil)
81
+ end
82
+
83
+ it { expect(subject.valid?).to eq false }
84
+ end
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+
91
+ #-------------------------------------------------------------
92
+ # Private Methods
93
+ #-------------------------------------------------------------
94
+
95
+ describe 'private method tests' do
96
+
97
+ # .option_keys
98
+ describe '.option_keys' do
99
+ let(:actual) { subject.send(:option_keys).sort }
100
+ let(:expected) { [:prefix, :href].sort }
101
+
102
+ it { expect(actual).to eq expected }
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::PageBreakModel do
4
+ let(:name) { 'Arial' }
5
+
6
+ subject { described_class.new }
7
+
8
+
9
+ #-------------------------------------------------------------
10
+ # Configuration
11
+ #-------------------------------------------------------------
12
+
13
+ describe 'configuration tests' do
14
+
15
+ describe 'inheritance' do
16
+ it { expect(subject).to be_a(Caracal::Core::Models::BaseModel) }
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::PageNumberModel do
4
+ subject do
5
+ described_class.new do
6
+ show true
7
+ align :right
8
+ label 'Page'
9
+ label_size 24
10
+ number_size 20
11
+ end
12
+ end
13
+
14
+ #-------------------------------------------------------------
15
+ # Configuration
16
+ #-------------------------------------------------------------
17
+
18
+ describe 'configuration tests' do
19
+
20
+ # constants
21
+ describe 'constants' do
22
+ it { expect(described_class::DEFAULT_PAGE_NUMBER_ALIGN).to eq :center }
23
+ end
24
+
25
+ # accessors
26
+ describe 'accessors' do
27
+ it { expect(subject.page_number_align).to eq :right }
28
+ it { expect(subject.page_number_label).to eq 'Page' }
29
+ it { expect(subject.page_number_label_size).to eq 24 }
30
+ it { expect(subject.page_number_number_size).to eq 20 }
31
+ it { expect(subject.page_number_show).to eq true }
32
+ end
33
+
34
+ end
35
+
36
+
37
+ #-------------------------------------------------------------
38
+ # Public Methods
39
+ #-------------------------------------------------------------
40
+
41
+ describe 'public method tests' do
42
+
43
+ #=============== SETTERS ==============================
44
+
45
+ # .align
46
+ describe '.align' do
47
+ before { subject.align(:left) }
48
+
49
+ it { expect(subject.page_number_align).to eq :left }
50
+ end
51
+
52
+ # .label
53
+ describe '.label' do
54
+ before { subject.label('Page') }
55
+
56
+ it { expect(subject.page_number_label).to eq 'Page' }
57
+ end
58
+
59
+ # .label_size
60
+ describe '.label_size' do
61
+ before { subject.label_size(28) }
62
+
63
+ it { expect(subject.page_number_label_size).to eq 28 }
64
+ end
65
+
66
+ # .number_size
67
+ describe '.number_size' do
68
+ before { subject.number_size(28) }
69
+
70
+ it { expect(subject.page_number_number_size).to eq 28 }
71
+ end
72
+
73
+ # .show
74
+ describe '.show' do
75
+ before { subject.show(true) }
76
+
77
+ it { expect(subject.page_number_show).to eq true }
78
+ end
79
+
80
+ # .size
81
+ describe '.size' do
82
+ before { subject.size(32) }
83
+
84
+ it { expect(subject.page_number_label_size).to eq 32 }
85
+ it { expect(subject.page_number_number_size).to eq 32 }
86
+ end
87
+
88
+
89
+ #=============== VALIDATIONS ==========================
90
+
91
+ describe '.valid?' do
92
+ describe 'when show is false' do
93
+ before do
94
+ allow(subject).to receive(:page_number_show).and_return(false)
95
+ end
96
+
97
+ it { expect(subject.valid?).to eq true }
98
+ end
99
+ describe 'when show is true and align is valid' do
100
+ before do
101
+ allow(subject).to receive(:page_number_show).and_return(true)
102
+ allow(subject).to receive(:page_number_align).and_return(:left)
103
+ end
104
+
105
+ it { expect(subject.valid?).to eq true }
106
+ end
107
+ describe 'when show is true and align is invalid' do
108
+ before do
109
+ allow(subject).to receive(:page_number_show).and_return(true)
110
+ allow(subject).to receive(:page_number_align).and_return(:dummy)
111
+ end
112
+
113
+ it { expect(subject.valid?).to eq false }
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+
120
+ #-------------------------------------------------------------
121
+ # Private Methods
122
+ #-------------------------------------------------------------
123
+
124
+ describe 'private method tests' do
125
+
126
+ # .option_keys
127
+ describe '.option_keys' do
128
+ let(:actual) { subject.send(:option_keys).sort }
129
+ let(:expected) { [:align, :label, :label_size, :number_size, :show].sort }
130
+
131
+ it { expect(actual).to eq expected }
132
+ end
133
+
134
+ end
135
+
136
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::PageSizeModel do
4
+ subject do
5
+ described_class.new do
6
+ width 15840
7
+ height 12240
8
+ end
9
+ end
10
+
11
+ #-------------------------------------------------------------
12
+ # Configuration
13
+ #-------------------------------------------------------------
14
+
15
+ describe 'configuration tests' do
16
+
17
+ # constants
18
+ describe 'constants' do
19
+ it { expect(described_class::DEFAULT_PAGE_WIDTH).to eq 12240 }
20
+ it { expect(described_class::DEFAULT_PAGE_HEIGHT).to eq 15840 }
21
+ it { expect(described_class::DEFAULT_PAGE_ORIENTATION).to eq 'portrait' }
22
+ end
23
+
24
+ # accessors
25
+ describe 'accessors' do
26
+ it { expect(subject.page_width).to eq 15840 }
27
+ it { expect(subject.page_height).to eq 12240 }
28
+ end
29
+
30
+ end
31
+
32
+
33
+ #-------------------------------------------------------------
34
+ # Public Methods
35
+ #-------------------------------------------------------------
36
+
37
+ describe 'public method tests' do
38
+
39
+ #=============== SETTERS ==========================
40
+
41
+ # .height
42
+ describe '.height' do
43
+ before { subject.height(10000) }
44
+
45
+ it { expect(subject.page_height).to eq 10000 }
46
+ end
47
+
48
+ # .orientation
49
+ describe '.orientation' do
50
+ before { subject.orientation('landscape') }
51
+
52
+ it { expect(subject.page_orientation).to eq 'landscape' }
53
+ end
54
+
55
+ # .width
56
+ describe '.width' do
57
+ before { subject.width(10000) }
58
+
59
+ it { expect(subject.page_width).to eq 10000 }
60
+ end
61
+
62
+
63
+
64
+
65
+ #=============== VALIDATION ===========================
66
+
67
+ describe '.valid?' do
68
+ describe 'when all sizes gt 0' do
69
+ it { expect(subject.valid?).to eq true }
70
+ end
71
+ [:width, :height].each do |d|
72
+ describe "when #{ d } lte 0" do
73
+ before do
74
+ allow(subject).to receive("page_#{ d }").and_return(0)
75
+ end
76
+
77
+ it { expect(subject.valid?).to eq false }
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+
85
+ #-------------------------------------------------------------
86
+ # Private Methods
87
+ #-------------------------------------------------------------
88
+
89
+ describe 'private method tests' do
90
+
91
+ # .option_keys
92
+ describe '.option_keys' do
93
+ let(:actual) { subject.send(:option_keys).sort }
94
+ let(:expected) { [:width, :height, :orientation].sort }
95
+
96
+ it { expect(actual).to eq expected }
97
+ end
98
+
99
+ end
100
+
101
+ end