osheet 0.10.0 → 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile +0 -1
  2. data/Gemfile.lock +9 -6
  3. data/Rakefile +35 -19
  4. data/bench/bench_runner.rb +91 -0
  5. data/bench/profiler_runner.rb +1 -0
  6. data/examples/basic.rb +1 -1
  7. data/examples/basic.xls +2 -1
  8. data/examples/basic_with_templates.rb +2 -2
  9. data/examples/basic_with_templates.xls +3 -3
  10. data/examples/formats.rb +2 -2
  11. data/examples/formats.xls +46 -46
  12. data/examples/formula.rb +2 -2
  13. data/examples/styles.rb +2 -2
  14. data/examples/styles.xls +5 -5
  15. data/examples/trivial.rb +2 -2
  16. data/lib/osheet/cell.rb +48 -46
  17. data/lib/osheet/column.rb +23 -29
  18. data/lib/osheet/format.rb +3 -3
  19. data/lib/osheet/meta_element.rb +2 -1
  20. data/lib/osheet/mixin.rb +21 -9
  21. data/lib/osheet/partial.rb +5 -9
  22. data/lib/osheet/row.rb +28 -32
  23. data/lib/osheet/style.rb +11 -25
  24. data/lib/osheet/styled_element.rb +9 -1
  25. data/lib/osheet/template.rb +3 -8
  26. data/lib/osheet/version.rb +1 -1
  27. data/lib/osheet/workbook.rb +135 -43
  28. data/lib/osheet/workbook_api.rb +208 -0
  29. data/lib/osheet/workbook_element.rb +225 -8
  30. data/lib/osheet/worksheet.rb +22 -28
  31. data/lib/osheet/xmlss_writer/style_cache.rb +64 -0
  32. data/lib/osheet/xmlss_writer/style_settings.rb +148 -0
  33. data/lib/osheet/xmlss_writer.rb +143 -1
  34. data/lib/osheet.rb +3 -29
  35. data/osheet.gemspec +4 -1
  36. data/test/cell_test.rb +33 -98
  37. data/test/column_test.rb +20 -88
  38. data/test/{mixins.rb → fixtures/mixins.rb} +6 -4
  39. data/test/fixtures/test_writer.rb +68 -0
  40. data/test/format_test.rb +2 -2
  41. data/test/helper.rb +34 -68
  42. data/test/mixin_test.rb +37 -43
  43. data/test/partial_test.rb +3 -26
  44. data/test/row_test.rb +32 -85
  45. data/test/style_test.rb +9 -26
  46. data/test/template_test.rb +5 -6
  47. data/test/workbook_element_test.rb +231 -0
  48. data/test/workbook_test.rb +225 -116
  49. data/test/worksheet_test.rb +51 -98
  50. data/test/xmlss_writer/api_test.rb +139 -0
  51. data/test/xmlss_writer/style_cache_test.rb +65 -0
  52. data/test/xmlss_writer/style_settings_test.rb +263 -0
  53. data/test/xmlss_writer/styles_test.rb +121 -153
  54. data/test/xmlss_writer_test.rb +91 -0
  55. metadata +75 -50
  56. data/lib/osheet/associations.rb +0 -58
  57. data/lib/osheet/instance.rb +0 -30
  58. data/lib/osheet/markup_element.rb +0 -22
  59. data/lib/osheet/partial_set.rb +0 -57
  60. data/lib/osheet/railtie.rb +0 -9
  61. data/lib/osheet/style_set.rb +0 -39
  62. data/lib/osheet/template_set.rb +0 -51
  63. data/lib/osheet/view_handler/rails.rb +0 -44
  64. data/lib/osheet/view_handler/tilt.rb +0 -42
  65. data/lib/osheet/view_handler.rb +0 -2
  66. data/lib/osheet/worksheet_element.rb +0 -17
  67. data/lib/osheet/xmlss_writer/base.rb +0 -49
  68. data/lib/osheet/xmlss_writer/elements.rb +0 -56
  69. data/lib/osheet/xmlss_writer/styles.rb +0 -216
  70. data/test/osheet_test.rb +0 -13
  71. data/test/partial_set_test.rb +0 -64
  72. data/test/style_set_test.rb +0 -47
  73. data/test/template_set_test.rb +0 -74
  74. data/test/xmlss_writer/base_test.rb +0 -103
  75. data/test/xmlss_writer/elements_test.rb +0 -172
@@ -0,0 +1,231 @@
1
+ require "assert"
2
+
3
+ require 'osheet/workbook_element'
4
+
5
+ module Osheet
6
+
7
+
8
+ class WorkbookElementTests < Assert::Context
9
+ desc "a WorkbookElement object"
10
+ before do
11
+ @wd = WorkbookElement.new
12
+ end
13
+ subject { @wd }
14
+
15
+ should have_reader :title
16
+ should have_readers :templates, :partials, :styles, :worksheets
17
+ should have_instance_methods :template, :partial, :style, :worksheet
18
+
19
+ should "set it's defaults" do
20
+ assert_nil subject.title
21
+ assert_equal WorkbookElement::TemplateSet.new, subject.templates
22
+ assert_equal WorkbookElement::PartialSet.new, subject.partials
23
+ assert_equal WorkbookElement::StyleSet.new, subject.styles
24
+ assert_equal WorkbookElement::WorksheetSet.new, subject.worksheets
25
+ end
26
+
27
+ end
28
+
29
+
30
+
31
+ class PartialSetTests < Assert::Context
32
+ desc "a PartialSet"
33
+ before { @ps = WorkbookElement::PartialSet.new }
34
+ subject { @ps }
35
+
36
+ should "be a Hash" do
37
+ assert_kind_of ::Hash, subject
38
+ end
39
+
40
+ should have_instance_method :<<
41
+ should have_reader :get
42
+
43
+ should "verify set objs are partials" do
44
+ assert_raises ArgumentError do
45
+ subject.send(:verify, {})
46
+ end
47
+ assert_nothing_raised do
48
+ subject.send(:verify, Partial.new(:poo) {})
49
+ end
50
+ end
51
+
52
+ should "key using name values" do
53
+ assert_equal 'poo', subject.send(:key, :poo)
54
+ end
55
+
56
+ should "key on partial objs" do
57
+ assert_equal 'poo', subject.send(:partial_key, Partial.new(:poo) {})
58
+ end
59
+
60
+ should "init the key in the set when verifying" do
61
+ key = subject.send(:verify, Partial.new(:thing) {})
62
+ assert_equal 'thing', key
63
+ assert_equal({'thing' => nil}, subject)
64
+ end
65
+
66
+ should "push partials onto the set" do
67
+ assert_nothing_raised do
68
+ subject << Partial.new(:poo) {}
69
+ subject << Partial.new(:not_poo) {}
70
+ subject << Partial.new(:awesome) {}
71
+ subject << Partial.new(:poo) {}
72
+ end
73
+
74
+ assert_equal 3, subject.keys.size
75
+ assert subject["poo"]
76
+ assert_kind_of Partial, subject["poo"]
77
+ end
78
+
79
+ should "lookup a partial by name" do
80
+ p = Partial.new(:poo) {}
81
+ subject << p
82
+ assert_equal p, subject.get(:poo)
83
+ assert_equal p, subject.get('poo')
84
+ assert_equal nil, subject.get(:ugh)
85
+ end
86
+
87
+ end
88
+
89
+
90
+
91
+ class TemplateSetTests < Assert::Context
92
+ desc "a TemplateSet"
93
+ before { @set = WorkbookElement::TemplateSet.new }
94
+ subject { @set }
95
+
96
+ should "be a PartialSet" do
97
+ assert_kind_of WorkbookElement::PartialSet, subject
98
+ end
99
+
100
+ should "verify set objs are templates" do
101
+ assert_raises ArgumentError do
102
+ subject.send(:verify, {})
103
+ end
104
+ assert_nothing_raised do
105
+ subject.send(:verify, Template.new(:row, :poo) {})
106
+ end
107
+ end
108
+
109
+ should "key templates using an array of their element and name" do
110
+ assert_equal ['row','poo'], subject.send(:key, :row, :poo)
111
+ end
112
+
113
+ should "key on templates objs" do
114
+ assert_equal ['row', 'poo'], subject.send(:template_key, Template.new(:row, :poo) {})
115
+ end
116
+
117
+ should "init the key in the set when verifying" do
118
+ key = subject.send(:verify, Template.new(:row, :poo) {})
119
+ assert_equal ['row', 'poo'], key
120
+ assert_equal({
121
+ key.first => { key.last => nil }
122
+ }, subject)
123
+ end
124
+
125
+ should "push templates onto the set" do
126
+ assert_nothing_raised do
127
+ subject << Template.new(:row, :poo) {}
128
+ subject << Template.new(:row, :not_poo) {}
129
+ subject << Template.new(:column, :awesome) {}
130
+ subject << Template.new(:column, :not_awesome) {}
131
+ end
132
+
133
+ assert_equal 2, subject.keys.size
134
+ assert subject["row"]
135
+ assert_equal 2, subject["row"].keys.size
136
+ assert subject["row"]["poo"]
137
+ assert_kind_of Template, subject["row"]["poo"]
138
+ assert subject["row"]["not_poo"]
139
+ assert_kind_of Template, subject["row"]["not_poo"]
140
+ assert subject["column"]
141
+ assert_equal 2, subject["column"].keys.size
142
+ assert subject["column"]["awesome"]
143
+ assert_kind_of Template, subject["column"]["awesome"]
144
+ assert subject["column"]["not_awesome"]
145
+ assert_kind_of Template, subject["column"]["not_awesome"]
146
+ end
147
+
148
+ should "lookup a template by element, name" do
149
+ t = Template.new(:row, :poo) {}
150
+ subject << t
151
+ assert_equal t, subject.get(:row, :poo)
152
+ assert_equal t, subject.get('row', 'poo')
153
+
154
+ assert_equal nil, subject.get(:row, :ugh)
155
+ assert_equal nil, subject.get(:col, :ugh)
156
+ end
157
+
158
+ end
159
+
160
+
161
+
162
+ class StyleSetTests < Assert::Context
163
+ desc "a StyleSet"
164
+ before { @set = WorkbookElement::StyleSet.new }
165
+ subject { @set }
166
+
167
+ should "be an Array" do
168
+ assert_kind_of ::Array, subject
169
+ end
170
+
171
+ should have_reader :for
172
+
173
+ should "verify Style objs" do
174
+ assert_raises ArgumentError do
175
+ subject.send(:verify, {})
176
+ end
177
+ assert_nothing_raised do
178
+ subject.send(:verify, Style.new('.awesome') {})
179
+ end
180
+ end
181
+
182
+ should "be able to lookup styles by class" do
183
+ subject << (a = Style.new('.awesome') {})
184
+ subject << (at = Style.new('.awesome.thing') {})
185
+ subject << (b = Style.new('.boring') {})
186
+ subject << (bt = Style.new('.boring.thing') {})
187
+ subject << (a_b = Style.new('.awesome', '.boring') {})
188
+ subject << (t = Style.new('.thing') {})
189
+ subject << (s = Style.new('.stupid') {})
190
+
191
+ { 'awesome' => [a, a_b],
192
+ 'boring' => [b, a_b],
193
+ 'thing' => [t],
194
+ 'awesome thing' => [a, at, a_b, t],
195
+ 'thing awesome' => [a, at, a_b, t],
196
+ 'other' => []
197
+ }.each do |style_class, styles_set|
198
+ assert_equal styles_set, subject.for(style_class)
199
+ end
200
+ end
201
+
202
+ should "return itself if calling for w/ no args" do
203
+ assert_equal subject, subject.for
204
+ end
205
+
206
+ end
207
+
208
+
209
+
210
+ class WorksheetSetTests < Assert::Context
211
+ desc "a WorksheetSet"
212
+ before { @set = WorkbookElement::WorksheetSet.new }
213
+ subject { @set }
214
+
215
+ should "be an Array" do
216
+ assert_kind_of ::Array, subject
217
+ end
218
+
219
+ should "verify Worksheet objs" do
220
+ assert_raises ArgumentError do
221
+ subject.send(:verify, {})
222
+ end
223
+ assert_nothing_raised do
224
+ subject.send(:verify, Worksheet.new {})
225
+ end
226
+ end
227
+
228
+ end
229
+
230
+
231
+ end
@@ -1,105 +1,143 @@
1
1
  require "assert"
2
+ require 'test/fixtures/mixins'
3
+ require 'test/fixtures/test_writer'
4
+
2
5
  require 'osheet/workbook'
3
- require 'test/mixins'
4
6
 
5
7
  module Osheet
6
8
 
7
- class WorkbookTest < Assert::Context
8
- desc "Osheet::Workbook"
9
- before { @wkbk = Workbook.new }
9
+ class WorkbookTests < Assert::Context
10
+ desc "a Workbook"
11
+ before do
12
+ @wkbk = Workbook.new
13
+ @test_writer = TestWriter.new
14
+ end
10
15
  subject { @wkbk }
11
16
 
12
- should have_readers :styles, :templates, :partials
13
- should have_instance_methods :title, :attributes, :use, :add
14
- should have_instance_methods :style, :template, :partial
17
+ should have_instance_methods :writer, :element_stack
18
+ should have_instance_methods :use, :add
19
+ should have_instance_methods :to_s, :to_data, :to_file
20
+
21
+ should have_instance_methods :workbook_element, :workbook
22
+ should have_instance_methods :templates, :template
23
+ should have_instance_methods :partials, :partial
24
+ should have_instance_methods :styles, :style
25
+ should have_instance_methods :worksheets, :worksheet
26
+ should have_instance_methods :columns, :column
27
+ should have_instance_methods :rows, :row
28
+ should have_instance_methods :cells, :cell
15
29
 
16
- should_hm(Workbook, :worksheets, Worksheet)
30
+ should have_instance_methods :use, :add, :template, :partial
31
+
32
+ should have_instance_methods :align, :font, :bg, :border
33
+ should have_instance_methods :border_left, :border_top
34
+ should have_instance_methods :border_right, :border_bottom
35
+
36
+ should have_instance_methods :style_class, :format
37
+ should have_instance_methods :title, :meta, :name
38
+ should have_instance_methods :width, :height
39
+ should have_instance_methods :autofit, :autofit?, :hidden, :hidden?
40
+ should have_instance_methods :data, :href, :formula
41
+ should have_instance_methods :index, :rowspan, :colspan
17
42
 
18
43
  should "set it's defaults" do
19
- assert_equal nil, subject.send(:get_ivar, "title")
20
- assert_equal [], subject.worksheets
21
- assert_equal StyleSet.new, subject.styles
22
- assert_equal TemplateSet.new, subject.templates
23
- assert_equal PartialSet.new, subject.partials
44
+ assert_equal nil, subject.workbook.title
45
+
46
+ assert_equal WorkbookElement.new, subject.workbook_element
47
+ assert_equal subject.workbook_element, subject.workbook
48
+
49
+ assert_kind_of Workbook::ElementStack, subject.element_stack
50
+ assert_equal 1, subject.element_stack.size
51
+ assert_equal subject.workbook_element, subject.element_stack.current
24
52
  end
25
53
 
26
- should "know it's attribute(s)" do
27
- subject.send(:title, "The Poo")
28
- [:title].each do |a|
29
- assert subject.attributes.has_key?(a)
30
- end
31
- assert_equal "The Poo", subject.attributes[:title]
54
+ should "set its title, casting it to a string" do
55
+ wb = Workbook.new { title :fun }
56
+ assert_equal "fun", wb.workbook.title
32
57
  end
33
58
 
34
59
  end
35
60
 
36
- class WorkbookTitleTest < WorkbookTest
37
- desc "A workbook with a title"
38
- before { @wkbk = Workbook.new { title "The Poo" } }
61
+ class ElementStackTests < Assert::Context
62
+ desc "an ElementStack"
63
+ before { @s = Workbook::ElementStack.new }
64
+ subject { @s }
39
65
 
40
- should "know it's title" do
41
- assert_equal "The Poo", subject.title
66
+ should "be an Array" do
67
+ assert_kind_of ::Array, subject
42
68
  end
43
69
 
44
- should "set it's title" do
45
- subject.title(false)
46
- assert_equal false, subject.title
47
- subject.title('la')
48
- assert_equal 'la', subject.title
49
- subject.title(nil)
50
- assert_equal 'la', subject.title
70
+ should have_instance_method :push, :pop, :current, :size, :using
71
+
72
+ should "push objects onto the stack" do
73
+ assert_nothing_raised do
74
+ subject.push("something")
75
+ subject.push("something else")
76
+ end
77
+
78
+ assert_equal 2, subject.size
51
79
  end
52
80
 
53
- end
81
+ should "push objects onto the stack for the duration of a block" do
82
+ subject.push("something")
54
83
 
55
- class WorkbookWorksheetsTest < WorkbookTest
56
- desc "A workbook with worksheets"
57
- before do
58
- @wkbk = Workbook.new {
59
- worksheet {
60
- name "Poo!"
61
- column
62
- row {
63
- cell {
64
- format :number
65
- data 1
66
- }
67
- }
68
- }
69
- }
84
+ assert_equal "something", subject.current
85
+ subject.using("using") do
86
+ assert_equal "using", subject.current
87
+ end
88
+ assert_equal "something", subject.current
70
89
  end
71
90
 
72
- should "set it's worksheets" do
73
- assert_equal 1, subject.worksheets.size
74
- assert_kind_of Worksheet, subject.worksheets.first
91
+ should "fetch the last item in the array with the current method" do
92
+ subject.push("something")
93
+ subject.push("something else")
94
+
95
+ assert_equal "something else", subject.current
75
96
  end
76
97
 
77
- should "not allow multiple worksheets with the same name" do
78
- assert_raises ArgumentError do
79
- Workbook.new {
80
- worksheet { name "awesome" }
81
- worksheet { name "awesome" }
82
- }
83
- end
98
+ should "remove the last item in the array with the pop method" do
99
+ subject.push("something")
100
+ subject.push("something else")
101
+
102
+ assert_equal 2, subject.size
103
+
104
+ item = subject.pop
105
+ assert_equal "something else", item
106
+ assert_equal 1, subject.size
107
+ end
108
+
109
+ should "return nil if trying to pop on an empty stack" do
110
+ assert_equal 0, subject.size
111
+
84
112
  assert_nothing_raised do
85
- Workbook.new {
86
- worksheet { name "awesome" }
87
- worksheet { name "awesome1" }
88
- }
113
+ subject.pop
89
114
  end
115
+
116
+ assert_nil subject.pop
90
117
  end
91
118
 
92
119
  end
93
120
 
94
- class WorkbookStyleTest < WorkbookTest
95
- desc "A workbook that defines styles"
121
+ class WorkbookStyleTests < WorkbookTests
122
+ desc "that defines styles"
96
123
  before do
97
- @wkbk = Workbook.new {
124
+ @wkbk = Workbook.new(@test_writer) {
98
125
  style('.test')
99
126
  style('.test.awesome')
127
+
128
+ worksheet("styles") {
129
+ column { style_class "test awesome" }
130
+ }
100
131
  }
101
132
  end
102
133
 
134
+ should "return the style obj created" do
135
+ style = subject.style(".a.test.style")
136
+
137
+ assert_kind_of Style, style
138
+ assert_equal '.a.test.style', style.selectors.first
139
+ end
140
+
103
141
  should "add them to it's styles" do
104
142
  assert_equal 2, subject.styles.size
105
143
  assert_equal 1, subject.styles.first.selectors.size
@@ -108,12 +146,104 @@ module Osheet
108
146
  assert_equal '.test.awesome', subject.styles.last.selectors.first
109
147
  end
110
148
 
149
+ should "write the style class on the element" do
150
+ assert_equal "test awesome", subject.worksheets.last.columns.last.style_class
151
+ end
152
+
111
153
  end
112
154
 
113
- class WorkbookPartialTest < WorkbookTest
114
- desc "A workbook that defines partials"
155
+ class WorkbookWorksheetTests < WorkbookTests
156
+ desc "with worksheets"
115
157
  before do
116
- @wkbk = Workbook.new {
158
+ @wkbk = Workbook.new(@test_writer) {
159
+ worksheet {
160
+ name "one"
161
+ }
162
+ worksheet {
163
+ name "two"
164
+ meta :some_meta
165
+ }
166
+ }
167
+ end
168
+
169
+ should "return the worksheet obj created" do
170
+ assert_kind_of Worksheet, subject.worksheet("test")
171
+ end
172
+
173
+ should "add them to it's worksheets reader" do
174
+ assert_equal 2, subject.worksheets.size
175
+ assert_equal "one", subject.worksheets.first.name
176
+ assert_equal "two", subject.worksheets.last.name
177
+ assert_equal :some_meta, subject.worksheets.last.meta
178
+ end
179
+
180
+ should "return the last worksheet added if called with no args" do
181
+ assert_equal subject.worksheets.last, subject.worksheet
182
+ end
183
+
184
+ should "call the writer with the created worksheet obj" do
185
+ assert_equal subject.worksheets.last, subject.writer.worksheets.last
186
+ end
187
+
188
+ end
189
+
190
+ class WorkbookRowCellMetaTests < WorkbookTests
191
+ desc "with columns, meta, rows, and cells"
192
+ before do
193
+ @wkbk = Workbook.new(@test_writer) {
194
+ worksheet {
195
+ column(100) { meta(:label => 'One') }
196
+ column { meta(:label => 'Two') }
197
+
198
+ row {
199
+ columns.each do |column|
200
+ cell(column.meta[:label])
201
+ end
202
+ }
203
+ row(120) {
204
+ cell {
205
+ data 12234
206
+ format :currency
207
+ }
208
+ cell(Time.now) {
209
+ format :datetime, 'mm/dd/yyyy'
210
+ }
211
+
212
+ }
213
+ }
214
+ }
215
+ end
216
+
217
+ should "add the columns to it's columns reader" do
218
+ assert_equal 2, subject.columns.size
219
+ assert_equal 100, subject.columns.first.width
220
+ assert_equal nil, subject.columns.last.width
221
+
222
+ assert_equal subject.columns.last, subject.writer.columns.last
223
+ end
224
+
225
+ should "just keep the last row in its rows reader" do
226
+ assert_equal 1, subject.rows.size
227
+ assert_equal 120, subject.rows.first.height
228
+
229
+ assert_equal 2, subject.writer.rows.size
230
+ assert_equal subject.rows.first, subject.writer.rows.last
231
+ end
232
+
233
+ should "access the cells of its last row" do
234
+ assert_equal 2, subject.cells.size
235
+ assert_equal 12234, subject.cells.first.data
236
+
237
+ assert_equal 4, subject.writer.cells.size
238
+ assert_equal subject.cells.last, subject.writer.rows.last.cells.last
239
+ end
240
+
241
+ end
242
+
243
+ class WorkbookPartialTests < WorkbookTests
244
+ desc "that defines partials"
245
+ before do
246
+ @wkbk = Workbook.new(@test_writer) {
117
247
  partial(:named_styles) { |name|
118
248
  style(".#{name}")
119
249
  style(".#{name}.awesome")
@@ -123,10 +253,10 @@ module Osheet
123
253
  end
124
254
 
125
255
  should "add them to it's partials" do
126
- assert_equal 2, subject.partials.keys.size
127
- assert subject.partials.has_key?('named_styles')
128
- assert subject.partials.has_key?('stuff')
129
- assert_kind_of Partial, subject.partials.get('stuff')
256
+ assert_equal 2, subject.workbook.partials.keys.size
257
+ assert subject.workbook.partials.has_key?('named_styles')
258
+ assert subject.workbook.partials.has_key?('stuff')
259
+ assert_kind_of Partial, subject.workbook.partials.get('stuff')
130
260
  end
131
261
 
132
262
  should "add it's partials to it's markup" do
@@ -138,10 +268,10 @@ module Osheet
138
268
 
139
269
  end
140
270
 
141
- class WorkbookTemplateTest < WorkbookTest
142
- desc "A workbook that defines templates"
271
+ class WorkbookTemplateTests < WorkbookTests
272
+ desc "that defines templates"
143
273
  before do
144
- @wkbk = Workbook.new {
274
+ @wkbk = Workbook.new(@test_writer) {
145
275
  template(:column, :yo) { |color|
146
276
  width 200
147
277
  meta(:color => color)
@@ -158,7 +288,7 @@ module Osheet
158
288
 
159
289
  should "add them to it's templates" do
160
290
  assert subject.templates
161
- assert_kind_of TemplateSet, subject.templates
291
+ assert_kind_of WorkbookElement::TemplateSet, subject.templates
162
292
  assert_equal 3, subject.templates.keys.size
163
293
  assert_kind_of Template, subject.templates.get('column', 'yo')
164
294
  assert_kind_of Template, subject.templates.get('row', 'yo_yo')
@@ -169,32 +299,18 @@ module Osheet
169
299
  subject.worksheet(:go)
170
300
  assert_equal 1, subject.worksheets.size
171
301
  assert_equal 'blue', subject.worksheets.first.columns.first.meta[:color]
172
- assert_equal 500, subject.worksheets.first.rows.first.attributes[:height]
302
+ assert_equal 500, subject.worksheets.first.rows.first.height
173
303
  end
174
304
 
175
305
  end
176
306
 
177
- class WorkbookBindingTest < WorkbookTest
178
- desc "a workbook defined w/ a block"
179
- should "access instance vars from that block's binding" do
180
- @test = 'test'
181
- @workbook = Workbook.new { title @test }
182
-
183
- assert !@workbook.send(:instance_variable_get, "@test").nil?
184
- assert_equal @test, @workbook.send(:instance_variable_get, "@test")
185
- assert_equal @test.object_id, @workbook.send(:instance_variable_get, "@test").object_id
186
- assert_equal @test, @workbook.attributes[:title]
187
- assert_equal @test.object_id, @workbook.attributes[:title].object_id
188
- end
189
-
190
- end
191
-
192
- class WorkbookMixins < WorkbookTest
193
- desc "a workbook w/ mixins"
307
+ class WorkbookMixinTests < WorkbookTests
308
+ desc "with mixins"
194
309
  before do
195
- @wkbk = Workbook.new {
310
+ @wkbk = Workbook.new(@test_writer) {
196
311
  use StyledMixin
197
312
  use TemplatedMixin
313
+ use PartialedMixin
198
314
  }
199
315
  end
200
316
 
@@ -204,39 +320,32 @@ module Osheet
204
320
  assert_equal '.test', subject.styles.first.selectors.first
205
321
  assert_equal 1, subject.styles.last.selectors.size
206
322
  assert_equal '.test.awesome', subject.styles.last.selectors.first
323
+ assert_equal [:left], subject.styles.last.align
207
324
  end
208
325
 
209
326
  should "add the mixin templates to it's templates" do
210
- assert subject.templates
211
- assert_kind_of TemplateSet, subject.templates
212
- assert_equal 3, subject.templates.keys.size
213
- assert_kind_of Template, subject.templates.get('column', 'yo')
214
- assert_kind_of Template, subject.templates.get('row', 'yo_yo')
215
- assert_kind_of Template, subject.templates.get('worksheet', 'go')
216
-
217
327
  subject.worksheet(:go)
328
+
218
329
  assert_equal 1, subject.worksheets.size
219
330
  assert_equal 'blue', subject.worksheets.first.columns.first.meta[:color]
220
- assert_equal 500, subject.worksheets.first.rows.first.attributes[:height]
331
+ assert_equal 500, subject.worksheets.first.rows.first.height
221
332
  end
222
333
 
223
- end
224
-
225
- class WorkbookWriter < WorkbookTest
226
- desc "a workbook"
227
- before do
228
- @wkbk = Workbook.new {
229
- style('.test')
230
- style('.test.awesome')
334
+ should "add the mixin partials to it's partials" do
335
+ subject.worksheet {
336
+ subject.add(:three_empty_rows)
337
+ subject.add(:two_cells_in_a_row, "one", "two")
231
338
  }
232
- end
233
339
 
234
- should have_instance_method :writer, :to_data, :to_file
340
+ assert_equal 4, subject.writer.rows.size
341
+
342
+ assert_empty subject.writer.rows[0].cells
343
+ assert_empty subject.writer.rows[1].cells
344
+ assert_empty subject.writer.rows[2].cells
235
345
 
236
- should "provide a writer for itself" do
237
- writer = subject.writer
238
- assert writer
239
- assert_kind_of XmlssWriter::Base, writer
346
+ assert_equal 2, subject.writer.rows.last.cells.size
347
+ assert_equal "one", subject.writer.rows.last.cells.first.data
348
+ assert_equal "two", subject.writer.rows.last.cells.last.data
240
349
  end
241
350
 
242
351
  end