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,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::BookmarkModel do
4
+ subject do
5
+ described_class.new do
6
+ id '0'
7
+ name 'myAnchor'
8
+ start false
9
+ end
10
+ end
11
+
12
+ #-------------------------------------------------------------
13
+ # Configuration
14
+ #-------------------------------------------------------------
15
+
16
+ describe 'configuration tests' do
17
+
18
+ # accessors
19
+ describe 'accessors' do
20
+ it { expect(subject.bookmark_id).to eq '0' }
21
+ it { expect(subject.bookmark_name).to eq 'myAnchor' }
22
+ it { expect(subject.bookmark_start).to eq false }
23
+ end
24
+
25
+ end
26
+
27
+
28
+ #-------------------------------------------------------------
29
+ # Public Methods
30
+ #-------------------------------------------------------------
31
+
32
+ describe 'public method tests' do
33
+
34
+ #=============== GETTERS ==========================
35
+
36
+ # .run_attributes
37
+ describe '.run_attributes' do
38
+ let(:expected) { { id: '0', name: 'myAnchor', start: false} }
39
+
40
+ it { expect(subject.run_attributes).to eq expected }
41
+ end
42
+
43
+
44
+ #=============== SETTERS ==========================
45
+
46
+ # booleans
47
+ describe '.start' do
48
+ before { subject.start(true) }
49
+
50
+ it { expect(subject.bookmark_start).to eq true }
51
+ end
52
+
53
+ # strings
54
+ describe '.id' do
55
+ before { subject.id('dddddd') }
56
+
57
+ it { expect(subject.bookmark_id).to eq 'dddddd' }
58
+ end
59
+ describe '.name' do
60
+ before { subject.name('999999') }
61
+
62
+ it { expect(subject.bookmark_name).to eq '999999' }
63
+ end
64
+
65
+
66
+ #=============== STATE HELPERS ========================
67
+
68
+ describe '.start?' do
69
+ describe 'when start is true' do
70
+ before { subject.start(true) }
71
+
72
+ it { expect(subject.start?).to eq true }
73
+ end
74
+ describe 'when start is false' do
75
+ before { subject.start(false) }
76
+
77
+ it { expect(subject.start?).to eq false }
78
+ end
79
+ end
80
+
81
+
82
+ #=============== VALIDATION ===========================
83
+
84
+ describe '.valid?' do
85
+ describe 'when required attributes provided' do
86
+ it { expect(subject.valid?).to eq true }
87
+ end
88
+ describe 'when start is true' do
89
+ before { subject.start(true) }
90
+
91
+ [:id, :name].each do |prop|
92
+ describe "when #{ prop } is empty" do
93
+ before do
94
+ allow(subject).to receive("bookmark_#{ prop }").and_return(nil)
95
+ end
96
+
97
+ it { expect(subject.valid?).to eq false }
98
+ end
99
+ end
100
+ end
101
+ describe 'when start is false' do
102
+ before { subject.start(false) }
103
+
104
+ [:id].each do |prop|
105
+ describe "when #{ prop } is empty" do
106
+ before do
107
+ allow(subject).to receive("bookmark_#{ prop }").and_return(nil)
108
+ end
109
+
110
+ it { expect(subject.valid?).to eq false }
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ end
117
+
118
+
119
+ #-------------------------------------------------------------
120
+ # Private Methods
121
+ #-------------------------------------------------------------
122
+
123
+ describe 'private method tests' do
124
+
125
+ # .option_keys
126
+ describe '.option_keys' do
127
+ let(:actual) { subject.send(:option_keys).sort }
128
+ let(:expected) { [:id, :name, :start].sort }
129
+
130
+ it { expect(actual).to eq expected }
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -0,0 +1,159 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::BorderModel do
4
+ subject do
5
+ described_class.new do
6
+ color '666666'
7
+ size 8
8
+ spacing 2
9
+ line :double
10
+ type :horizontal
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_BORDER_COLOR).to eq 'auto' }
23
+ it { expect(described_class::DEFAULT_BORDER_LINE).to eq :single }
24
+ it { expect(described_class::DEFAULT_BORDER_SIZE).to eq 4 }
25
+ it { expect(described_class::DEFAULT_BORDER_SPACING).to eq 1 }
26
+ it { expect(described_class::DEFAULT_BORDER_TYPE).to eq :top }
27
+ end
28
+
29
+ # accessors
30
+ describe 'accessors' do
31
+ it { expect(subject.border_color).to eq '666666' }
32
+ it { expect(subject.border_line).to eq :double }
33
+ it { expect(subject.border_size).to eq 8 }
34
+ it { expect(subject.border_spacing).to eq 2 }
35
+ it { expect(subject.border_type).to eq :horizontal }
36
+ end
37
+
38
+ end
39
+
40
+
41
+ #-------------------------------------------------------------
42
+ # Public Methods
43
+ #-------------------------------------------------------------
44
+
45
+ describe 'public method tests' do
46
+
47
+ #=============== GETTERS ==========================
48
+
49
+ # .formatted_type
50
+ describe '.formatted_type' do
51
+ describe 'when horizontal' do
52
+ before do
53
+ allow(subject).to receive(:border_type).and_return(:horizontal)
54
+ end
55
+
56
+ it { expect(subject.formatted_type).to eq 'insideH'}
57
+ end
58
+ describe 'when vertical' do
59
+ before do
60
+ allow(subject).to receive(:border_type).and_return(:vertical)
61
+ end
62
+
63
+ it { expect(subject.formatted_type).to eq 'insideV'}
64
+ end
65
+ describe 'when other' do
66
+ before do
67
+ allow(subject).to receive(:border_type).and_return(:top)
68
+ end
69
+
70
+ it { expect(subject.formatted_type).to eq 'top'}
71
+ end
72
+ end
73
+
74
+ # .total_size
75
+ describe '.total_size' do
76
+ before do
77
+ allow(subject).to receive(:border_size).and_return(10)
78
+ allow(subject).to receive(:border_spacing).and_return(2)
79
+ end
80
+
81
+ it { expect(subject.total_size).to eq 14}
82
+ end
83
+
84
+
85
+ #=============== SETTERS ==========================
86
+
87
+ # .color
88
+ describe '.color' do
89
+ before { subject.color('999999') }
90
+
91
+ it { expect(subject.border_color).to eq '999999' }
92
+ end
93
+
94
+ # .line
95
+ describe '.line' do
96
+ before { subject.line(:single) }
97
+
98
+ it { expect(subject.border_line).to eq :single }
99
+ end
100
+
101
+ # .size
102
+ describe '.size' do
103
+ before { subject.size(24) }
104
+
105
+ it { expect(subject.border_size).to eq 24 }
106
+ end
107
+
108
+ # .spacing
109
+ describe '.spacing' do
110
+ before { subject.spacing(8) }
111
+
112
+ it { expect(subject.border_spacing).to eq 8 }
113
+ end
114
+
115
+ # .type
116
+ describe '.type' do
117
+ before { subject.type(:bottom) }
118
+
119
+ it { expect(subject.border_type).to eq :bottom }
120
+ end
121
+
122
+
123
+ #=============== VALIDATION ===========================
124
+
125
+ describe '.valid?' do
126
+ describe 'when all integers gt 0' do
127
+ it { expect(subject.valid?).to eq true }
128
+ end
129
+ [:size, :spacing].each do |d|
130
+ describe "when #{ d } lte 0" do
131
+ before do
132
+ allow(subject).to receive("border_#{ d }").and_return(0)
133
+ end
134
+
135
+ it { expect(subject.valid?).to eq false }
136
+ end
137
+ end
138
+ end
139
+
140
+ end
141
+
142
+
143
+ #-------------------------------------------------------------
144
+ # Private Methods
145
+ #-------------------------------------------------------------
146
+
147
+ describe 'private method tests' do
148
+
149
+ # .option_keys
150
+ describe '.option_keys' do
151
+ let(:actual) { subject.send(:option_keys).sort }
152
+ let(:expected) { [:color, :size, :spacing, :line, :type].sort }
153
+
154
+ it { expect(actual).to eq expected }
155
+ end
156
+
157
+ end
158
+
159
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::FontModel do
4
+ subject { described_class.new({ name: 'Arial' }) }
5
+
6
+
7
+ #-------------------------------------------------------------
8
+ # Configuration
9
+ #-------------------------------------------------------------
10
+
11
+ describe 'configuration tests' do
12
+
13
+ # accessors
14
+ describe 'accessors' do
15
+ it { expect(subject.font_name).to eq 'Arial' }
16
+ end
17
+
18
+ end
19
+
20
+
21
+ #-------------------------------------------------------------
22
+ # Public Methods
23
+ #-------------------------------------------------------------
24
+
25
+ describe 'public method tests' do
26
+
27
+ #=================== SETTERS =============================
28
+
29
+ # .name
30
+ describe '.name' do
31
+ before do
32
+ subject.name('Helvetica')
33
+ end
34
+
35
+ it { expect(subject.font_name).to eq 'Helvetica' }
36
+ end
37
+
38
+
39
+ #=================== STATE ===============================
40
+
41
+ # .matches?
42
+ describe '.matches?' do
43
+ describe 'when search term matches' do
44
+ let(:actual) { subject.matches?('Arial') }
45
+
46
+ it { expect(actual).to eq true }
47
+ end
48
+ describe 'when search term does not match' do
49
+ let(:actual) { subject.matches?('Dummy') }
50
+
51
+ it { expect(actual).to eq false }
52
+ end
53
+ end
54
+
55
+
56
+ #=============== VALIDATION ===========================
57
+
58
+ describe '.valid?' do
59
+ describe 'when name provided' do
60
+ it { expect(subject.valid?).to eq true }
61
+ end
62
+ [:name].each do |prop|
63
+ describe "when #{ prop } nil" do
64
+ before do
65
+ allow(subject).to receive("font_#{ prop }").and_return(nil)
66
+ end
67
+
68
+ it { expect(subject.valid?).to eq false }
69
+ end
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+
76
+ #-------------------------------------------------------------
77
+ # Private Methods
78
+ #-------------------------------------------------------------
79
+
80
+ describe 'private method tests' do
81
+
82
+ # .option_keys
83
+ describe '.option_keys' do
84
+ let(:actual) { subject.send(:option_keys).sort }
85
+ let(:expected) { [:name].sort }
86
+
87
+ it { expect(actual).to eq expected }
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::IFrameModel do
4
+ subject do
5
+ described_class.new do
6
+ url 'https://www.example.com/snippet.docx'
7
+ end
8
+ end
9
+
10
+
11
+
12
+ #-------------------------------------------------------------
13
+ # Configuration
14
+ #-------------------------------------------------------------
15
+
16
+ describe 'configuration tests' do
17
+
18
+ # accessors
19
+ describe 'accessors' do
20
+ it { expect(subject.iframe_url).to eq 'https://www.example.com/snippet.docx' }
21
+ end
22
+
23
+ end
24
+
25
+
26
+ #-------------------------------------------------------------
27
+ # Public Methods
28
+ #-------------------------------------------------------------
29
+
30
+ describe 'public method tests' do
31
+
32
+ #=============== SETTERS ==========================
33
+
34
+ # .url
35
+ describe '.url' do
36
+ before { subject.url('https://www.example.com/sample.docx') }
37
+
38
+ it { expect(subject.iframe_url).to eq 'https://www.example.com/sample.docx' }
39
+ end
40
+
41
+ # .data
42
+ describe '.data' do
43
+ before { subject.data('DOCX data follows here') }
44
+
45
+ it { expect(subject.iframe_data).to eq 'DOCX data follows here' }
46
+ end
47
+
48
+
49
+ #=============== VALIDATION ===========================
50
+
51
+ describe '.valid?' do
52
+ describe 'when either value present' do
53
+ it { expect(subject.valid?).to eq true }
54
+ end
55
+ describe 'when neither value present' do
56
+ before do
57
+ subject.url(nil)
58
+ subject.data(nil)
59
+ end
60
+ it { expect(subject.valid?).to eq false }
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+
67
+ #-------------------------------------------------------------
68
+ # Private Methods
69
+ #-------------------------------------------------------------
70
+
71
+ describe 'private method tests' do
72
+
73
+ # .option_keys
74
+ describe '.option_keys' do
75
+ let(:actual) { subject.send(:option_keys).sort }
76
+ let(:expected) { [:url, :data].sort }
77
+
78
+ it { expect(actual).to eq expected }
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,225 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::ImageModel do
4
+ subject do
5
+ described_class.new do
6
+ url 'https://www.google.com/images/srpr/logo11w.png'
7
+ ppi 96
8
+ width 250
9
+ height 200
10
+ align :right
11
+ top 12
12
+ bottom 13
13
+ left 14
14
+ right 15
15
+ end
16
+ end
17
+
18
+
19
+
20
+ #-------------------------------------------------------------
21
+ # Configuration
22
+ #-------------------------------------------------------------
23
+
24
+ describe 'configuration tests' do
25
+
26
+ # constants
27
+ describe 'constants' do
28
+ it { expect(described_class::DEFAULT_IMAGE_PPI).to eq 72 }
29
+ it { expect(described_class::DEFAULT_IMAGE_WIDTH).to eq 0 }
30
+ it { expect(described_class::DEFAULT_IMAGE_HEIGHT).to eq 0 }
31
+ it { expect(described_class::DEFAULT_IMAGE_ALIGN).to eq :left }
32
+ it { expect(described_class::DEFAULT_IMAGE_TOP).to eq 8 }
33
+ it { expect(described_class::DEFAULT_IMAGE_BOTTOM).to eq 8 }
34
+ it { expect(described_class::DEFAULT_IMAGE_LEFT).to eq 8 }
35
+ it { expect(described_class::DEFAULT_IMAGE_RIGHT).to eq 8 }
36
+ end
37
+
38
+ # accessors
39
+ describe 'accessors' do
40
+ it { expect(subject.image_url).to eq 'https://www.google.com/images/srpr/logo11w.png' }
41
+ it { expect(subject.image_data).to eq nil }
42
+ it { expect(subject.image_ppi).to eq 96 }
43
+ it { expect(subject.image_width).to eq 250 }
44
+ it { expect(subject.image_height).to eq 200 }
45
+ it { expect(subject.image_align).to eq :right }
46
+ it { expect(subject.image_top).to eq 12 }
47
+ it { expect(subject.image_bottom).to eq 13 }
48
+ it { expect(subject.image_left).to eq 14 }
49
+ it { expect(subject.image_right).to eq 15 }
50
+ end
51
+
52
+ end
53
+
54
+
55
+ #-------------------------------------------------------------
56
+ # Public Methods
57
+ #-------------------------------------------------------------
58
+
59
+ describe 'public method tests' do
60
+
61
+ #=============== GETTERS ==========================
62
+
63
+ # emu conversions (dimensions)
64
+ [:width, :height].each do |m|
65
+ describe ".formatted_#{ m }" do
66
+ let(:actual) { subject.send("formatted_#{ m }") }
67
+
68
+ before do
69
+ allow(subject).to receive("image_#{ m }").and_return(540)
70
+ allow(subject).to receive("image_ppi").and_return(96)
71
+ end
72
+
73
+ it { expect(actual).to eq 5143500 }
74
+ end
75
+ end
76
+
77
+ # emu conversions (margins)
78
+ [:top, :bottom, :left, :right].each do |m|
79
+ describe ".formatted_#{ m }" do
80
+ let(:actual) { subject.send("formatted_#{ m }") }
81
+
82
+ before { allow(subject).to receive("image_#{ m }").and_return(9) }
83
+
84
+ it { expect(actual).to eq 114300 }
85
+ end
86
+ end
87
+
88
+
89
+
90
+ #=============== SETTERS ==========================
91
+
92
+ # .url
93
+ describe '.url' do
94
+ before { subject.url('https://www.google.com/images/dummy.png') }
95
+
96
+ it { expect(subject.image_url).to eq 'https://www.google.com/images/dummy.png' }
97
+ end
98
+
99
+ # .data
100
+ describe '.data' do
101
+ before { subject.data('PNG Data follows here') }
102
+
103
+ it { expect(subject.image_data).to eq 'PNG Data follows here' }
104
+ end
105
+
106
+ # .ppi
107
+ describe '.ppi' do
108
+ before { subject.ppi(108) }
109
+
110
+ it { expect(subject.image_ppi).to eq 108 }
111
+ end
112
+
113
+ # .width
114
+ describe '.width' do
115
+ before { subject.width(300) }
116
+
117
+ it { expect(subject.image_width).to eq 300 }
118
+ end
119
+
120
+ # .height
121
+ describe '.height' do
122
+ before { subject.height(400) }
123
+
124
+ it { expect(subject.image_height).to eq 400 }
125
+ end
126
+
127
+ # .align
128
+ describe '.align' do
129
+ before { subject.align(:center) }
130
+
131
+ it { expect(subject.image_align).to eq :center }
132
+ end
133
+
134
+ # .top
135
+ describe '.top' do
136
+ before { subject.top(12) }
137
+
138
+ it { expect(subject.image_top).to eq 12 }
139
+ end
140
+
141
+ # .bottom
142
+ describe '.bottom' do
143
+ before { subject.bottom(12) }
144
+
145
+ it { expect(subject.image_bottom).to eq 12 }
146
+ end
147
+
148
+ # .left
149
+ describe '.left' do
150
+ before { subject.left(12) }
151
+
152
+ it { expect(subject.image_left).to eq 12 }
153
+ end
154
+
155
+ # .right
156
+ describe '.right' do
157
+ before { subject.right(12) }
158
+
159
+ it { expect(subject.image_right).to eq 12 }
160
+ end
161
+
162
+
163
+ #=============== VALIDATION ===========================
164
+
165
+ describe '.valid?' do
166
+ describe 'when all values okay' do
167
+ it { expect(subject.valid?).to eq true }
168
+ end
169
+ [:width, :height, :top, :bottom, :left, :right].each do |d|
170
+ describe "when #{ d } lte 0" do
171
+ before do
172
+ allow(subject).to receive("image_#{ d }").and_return(0)
173
+ end
174
+
175
+ it { expect(subject.valid?).to eq false }
176
+ end
177
+ end
178
+ end
179
+
180
+ end
181
+
182
+
183
+ #-------------------------------------------------------------
184
+ # Private Methods
185
+ #-------------------------------------------------------------
186
+
187
+ describe 'private method tests' do
188
+
189
+ # .option_keys
190
+ describe '.option_keys' do
191
+ let(:actual) { subject.send(:option_keys).sort }
192
+ let(:expected) { [:url, :width, :height, :align, :top, :bottom, :left, :right].sort }
193
+
194
+ it { expect(actual).to eq expected }
195
+ end
196
+
197
+ # .pixels_to_emus
198
+ describe '.pixels_to_emus' do
199
+ let(:actual) { subject.send(:pixels_to_emus, value, 72) }
200
+
201
+ describe 'when argument is nil' do
202
+ let(:value) { nil }
203
+
204
+ it { expect(actual).to eq 0 }
205
+ end
206
+ describe 'when argument is NaN' do
207
+ let(:value) { 'a' }
208
+
209
+ it { expect(actual).to eq 0 }
210
+ end
211
+ describe 'when argument is rational' do
212
+ let(:value) { 396.1 }
213
+
214
+ it { expect(actual).to eq 5029200 }
215
+ end
216
+ describe 'when argument is integer' do
217
+ let(:value) { 396 }
218
+
219
+ it { expect(actual).to eq 5029200 }
220
+ end
221
+ end
222
+
223
+ end
224
+
225
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Caracal::Core::Models::LineBreakModel 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