osheet 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,17 @@ require 'osheet/workbook'
3
3
  require 'test/mixins'
4
4
 
5
5
  module Osheet
6
+
6
7
  class WorkbookTest < Test::Unit::TestCase
7
8
 
8
9
  context "Osheet::Workbook" do
9
- subject { Workbook.new }
10
+ subject do
11
+ Workbook.new
12
+ end
10
13
 
11
- should_have_readers :styles, :templates
12
- should_have_instance_methods :title, :style, :template, :attributes, :use
14
+ should_have_readers :styles, :templates, :partials
15
+ should_have_instance_methods :title, :attributes, :use, :add
16
+ should_have_instance_methods :style, :template, :partial
13
17
 
14
18
  should_hm(Workbook, :worksheets, Worksheet)
15
19
 
@@ -18,128 +22,169 @@ module Osheet
18
22
  assert_equal [], subject.worksheets
19
23
  assert_equal StyleSet.new, subject.styles
20
24
  assert_equal TemplateSet.new, subject.templates
25
+ assert_equal PartialSet.new, subject.partials
21
26
  end
22
27
 
23
- context "that has some columns and rows" do
24
- subject do
25
- Workbook.new {
26
- title "The Poo"
28
+ should "know it's attribute(s)" do
29
+ subject.send(:title, "The Poo")
30
+ [:title].each do |a|
31
+ assert subject.attributes.has_key?(a)
32
+ end
33
+ assert_equal "The Poo", subject.attributes[:title]
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ class WorkbookTitleTest < Test::Unit::TestCase
40
+ context "A workbook with a title" do
41
+ subject do
42
+ Workbook.new { title "The Poo" }
43
+ end
27
44
 
28
- worksheet {
29
- name "Poo!"
45
+ should "know it's title" do
46
+ assert_equal "The Poo", subject.title
47
+ end
48
+
49
+ should "set it's title" do
50
+ subject.title(false)
51
+ assert_equal false, subject.title
52
+ subject.title('la')
53
+ assert_equal 'la', subject.title
54
+ subject.title(nil)
55
+ assert_equal 'la', subject.title
56
+ end
30
57
 
31
- column
58
+ end
59
+ end
32
60
 
33
- row {
34
- cell {
35
- format :number
36
- data 1
37
- }
61
+ class WorkbookWorksheetsTest < Test::Unit::TestCase
62
+ context "A workbook with worksheets" do
63
+ subject do
64
+ Workbook.new {
65
+ worksheet {
66
+ name "Poo!"
67
+ column
68
+ row {
69
+ cell {
70
+ format :number
71
+ data 1
38
72
  }
39
73
  }
40
74
  }
41
- end
75
+ }
76
+ end
42
77
 
43
- should "set it's title" do
44
- assert_equal "The Poo", subject.send(:get_ivar, "title")
45
- end
78
+ should "set it's worksheets" do
79
+ assert_equal 1, subject.worksheets.size
80
+ assert_kind_of Worksheet, subject.worksheets.first
81
+ end
46
82
 
47
- should "know it's title" do
48
- subject.title(false)
49
- assert_equal false, subject.title
50
- subject.title('la')
51
- assert_equal 'la', subject.title
52
- subject.title(nil)
53
- assert_equal 'la', subject.title
83
+ should "not allow multiple worksheets with the same name" do
84
+ assert_raises ArgumentError do
85
+ Workbook.new {
86
+ worksheet { name "awesome" }
87
+ worksheet { name "awesome" }
88
+ }
54
89
  end
55
-
56
- should "set it's worksheets" do
57
- worksheets = subject.send(:get_ivar, "worksheets")
58
- assert_equal 1, worksheets.size
59
- assert_kind_of Worksheet, worksheets.first
90
+ assert_nothing_raised do
91
+ Workbook.new {
92
+ worksheet { name "awesome" }
93
+ worksheet { name "awesome1" }
94
+ }
60
95
  end
96
+ end
61
97
 
62
- should "not allow multiple worksheets with the same name" do
63
- assert_raises ArgumentError do
64
- Workbook.new {
65
- title "should fail"
66
-
67
- worksheet { name "awesome" }
68
- worksheet { name "awesome" }
69
- }
70
- end
71
- assert_nothing_raised do
72
- Workbook.new {
73
- title "should not fail"
98
+ end
99
+ end
74
100
 
75
- worksheet { name "awesome" }
76
- worksheet { name "awesome1" }
77
- }
78
- end
79
- end
101
+ class WorkbookStyleTest < Test::Unit::TestCase
102
+ context "A workbook that defines styles" do
103
+ subject do
104
+ Workbook.new {
105
+ style('.test')
106
+ style('.test.awesome')
107
+ }
108
+ end
80
109
 
81
- should "know it's attribute(s)" do
82
- [:title].each do |a|
83
- assert subject.attributes.has_key?(a)
84
- end
85
- assert_equal "The Poo", subject.attributes[:title]
86
- end
110
+ should "add them to it's styles" do
111
+ assert_equal 2, subject.styles.size
112
+ assert_equal 1, subject.styles.first.selectors.size
113
+ assert_equal '.test', subject.styles.first.selectors.first
114
+ assert_equal 1, subject.styles.last.selectors.size
115
+ assert_equal '.test.awesome', subject.styles.last.selectors.first
87
116
  end
88
117
 
89
- context "that defines styles" do
90
- subject do
91
- Workbook.new {
92
- style('.test')
93
- style('.test.awesome')
118
+ end
119
+ end
120
+
121
+ class WorkbookPartialTest < Test::Unit::TestCase
122
+ context "A workbook that defines partials" do
123
+ subject do
124
+ Workbook.new {
125
+ partial(:named_styles) { |name|
126
+ style(".#{name}")
127
+ style(".#{name}.awesome")
94
128
  }
95
- end
129
+ partial(:stuff) {}
130
+ }
131
+ end
96
132
 
97
- should "add them to it's styles" do
98
- assert_equal 2, subject.styles.size
99
- assert_equal 1, subject.styles.first.selectors.size
100
- assert_equal '.test', subject.styles.first.selectors.first
101
- assert_equal 1, subject.styles.last.selectors.size
102
- assert_equal '.test.awesome', subject.styles.last.selectors.first
103
- end
133
+ should "add them to it's partials" do
134
+ assert_equal 2, subject.partials.keys.size
135
+ assert subject.partials.has_key?('named_styles')
136
+ assert subject.partials.has_key?('stuff')
137
+ assert_kind_of Partial, subject.partials.get('stuff')
104
138
  end
105
139
 
106
- context "that defines templates" do
107
- subject do
108
- Workbook.new {
109
- template(:column, :yo) { |color|
110
- width 200
111
- meta(:color => color)
112
- }
113
- template(:row, :yo_yo) {
114
- height 500
115
- }
116
- template(:worksheet, :go) {
117
- column(:yo, 'blue')
118
- row(:yo_yo)
119
- }
140
+ should "add it's partials to it's markup" do
141
+ subject.add(:named_styles, 'test')
142
+ assert_equal 2, subject.styles.size
143
+ assert_equal '.test', subject.styles.first.selectors.first
144
+ assert_equal '.test.awesome', subject.styles.last.selectors.first
145
+ end
146
+
147
+ end
148
+ end
149
+
150
+ class WorkbookTemplateTest < Test::Unit::TestCase
151
+ context "A workbook that defines templates" do
152
+ subject do
153
+ Workbook.new {
154
+ template(:column, :yo) { |color|
155
+ width 200
156
+ meta(:color => color)
120
157
  }
121
- end
158
+ template(:row, :yo_yo) {
159
+ height 500
160
+ }
161
+ template(:worksheet, :go) {
162
+ column(:yo, 'blue')
163
+ row(:yo_yo)
164
+ }
165
+ }
166
+ end
122
167
 
123
- should "add them to it's templates" do
124
- assert subject.templates
125
- assert_kind_of TemplateSet, subject.templates
126
- assert_equal 3, subject.templates.keys.size
127
- assert_kind_of Template, subject.templates.get('column', 'yo')
128
- assert_kind_of Template, subject.templates.get('row', 'yo_yo')
129
- assert_kind_of Template, subject.templates.get('worksheet', 'go')
130
-
131
- subject.worksheet(:go)
132
- assert_equal 1, subject.worksheets.size
133
- assert_equal 'blue', subject.worksheets.first.columns.first.meta[:color]
134
- assert_equal 500, subject.worksheets.first.rows.first.attributes[:height]
135
- end
168
+ should "add them to it's templates" do
169
+ assert subject.templates
170
+ assert_kind_of TemplateSet, subject.templates
171
+ assert_equal 3, subject.templates.keys.size
172
+ assert_kind_of Template, subject.templates.get('column', 'yo')
173
+ assert_kind_of Template, subject.templates.get('row', 'yo_yo')
174
+ assert_kind_of Template, subject.templates.get('worksheet', 'go')
136
175
  end
137
176
 
138
- end
177
+ should "apply it's templates" do
178
+ subject.worksheet(:go)
179
+ assert_equal 1, subject.worksheets.size
180
+ assert_equal 'blue', subject.worksheets.first.columns.first.meta[:color]
181
+ assert_equal 500, subject.worksheets.first.rows.first.attributes[:height]
182
+ end
139
183
 
184
+ end
140
185
  end
141
186
 
142
- class WorksheetBindingTest < Test::Unit::TestCase
187
+ class WorkbookBindingTest < Test::Unit::TestCase
143
188
  context "a workbook defined w/ a block" do
144
189
  should "access instance vars from that block's binding" do
145
190
  @test = 'test'
@@ -151,6 +196,7 @@ module Osheet
151
196
  assert_equal @test, @workbook.attributes[:title]
152
197
  assert_equal @test.object_id, @workbook.attributes[:title].object_id
153
198
  end
199
+
154
200
  end
155
201
  end
156
202
 
@@ -2,8 +2,8 @@ require "test/helper"
2
2
  require 'osheet/worksheet'
3
3
 
4
4
  module Osheet
5
- class WorksheetTest < Test::Unit::TestCase
6
5
 
6
+ class WorksheetTest < Test::Unit::TestCase
7
7
  context "Osheet::Worksheet" do
8
8
  subject { Worksheet.new }
9
9
 
@@ -23,63 +23,102 @@ module Osheet
23
23
  should_hm(Worksheet, :columns, Column)
24
24
  should_hm(Worksheet, :rows, Row)
25
25
 
26
- context "that has some columns and rows" do
27
- subject do
28
- Worksheet.new do
29
- name "Poo!"
30
- meta(
31
- {}
32
- )
33
-
34
- column
35
-
36
- row do
37
- cell do
38
- format :number
39
- data 1
40
- end
41
- end
42
- end
26
+ should "know it's attribute(s)" do
27
+ subject.send(:name, "Poo!")
28
+ [:name].each do |a|
29
+ assert subject.attributes.has_key?(a)
43
30
  end
31
+ assert_equal "Poo!", subject.attributes[:name]
32
+ end
44
33
 
45
- should "set it's name and meta" do
46
- assert_equal "Poo!", subject.send(:get_ivar, "name")
47
- assert_equal({}, subject.meta)
48
- end
34
+ end
35
+ end
49
36
 
50
- should "know it's name" do
51
- subject.name(false)
52
- assert_equal false, subject.name
53
- subject.name('la')
54
- assert_equal 'la', subject.name
55
- subject.name(nil)
56
- assert_equal 'la', subject.name
57
- end
37
+ class WorksheetNameMetaTest < Test::Unit::TestCase
38
+ context "A named worksheet with meta" do
39
+ subject do
40
+ Worksheet.new {
41
+ name "Poo!"
42
+ meta({})
43
+ }
44
+ end
45
+
46
+ should "know it's name and meta" do
47
+ assert_equal "Poo!", subject.send(:get_ivar, "name")
48
+ assert_equal({}, subject.meta)
49
+ end
58
50
 
59
- should "know it's attribute(s)" do
60
- [:name].each do |a|
61
- assert subject.attributes.has_key?(a)
62
- end
63
- assert_equal "Poo!", subject.attributes[:name]
51
+ should "set it's name" do
52
+ subject.name(false)
53
+ assert_equal 'false', subject.name
54
+ subject.name('la')
55
+ assert_equal 'la', subject.name
56
+ subject.name(nil)
57
+ assert_equal 'la', subject.name
58
+ end
59
+
60
+ should "complain if name is longer than 31 chars" do
61
+ assert_raises ArgumentError do
62
+ subject.name('a'*32)
64
63
  end
65
- should "set it's columns" do
66
- columns = subject.columns
67
- assert_equal 1, columns.size
68
- assert_kind_of Column, columns.first
69
- assert_equal subject.columns, columns.first.columns
64
+ assert_nothing_raised do
65
+ subject.name('a'*31)
70
66
  end
67
+ end
71
68
 
72
- should "set it's rows" do
73
- rows = subject.rows
74
- assert_equal 1, rows.size
75
- assert_kind_of Row, rows.first
76
- assert_equal subject.columns, rows.first.columns
77
- assert_equal subject.columns, rows.first.cells.first.columns
78
- end
69
+ end
70
+ end
71
+
72
+ class WorksheetColumnRowTest < Test::Unit::TestCase
73
+ context "A worksheet that has columns and rows" do
74
+ subject do
75
+ Worksheet.new {
76
+ column
77
+ row { cell {
78
+ format :number
79
+ data 1
80
+ } }
81
+ }
82
+ end
83
+
84
+ should "set it's columns" do
85
+ columns = subject.columns
86
+ assert_equal 1, columns.size
87
+ assert_kind_of Column, columns.first
88
+ assert_equal subject.columns, columns.first.columns
89
+ end
90
+
91
+ should "set it's rows" do
92
+ rows = subject.rows
93
+ assert_equal 1, rows.size
94
+ assert_kind_of Row, rows.first
95
+ assert_equal subject.columns, rows.first.columns
96
+ assert_equal subject.columns, rows.first.cells.first.columns
79
97
  end
80
98
 
81
99
  end
100
+ end
101
+
102
+ class WorkbookPartialTest < Test::Unit::TestCase
103
+ context "A workbook that defines worksheet partials" do
104
+ subject do
105
+ Workbook.new {
106
+ partial(:worksheet_stuff) {
107
+ row {}
108
+ row {}
109
+ }
110
+
111
+ worksheet {
112
+ add :worksheet_stuff
113
+ }
114
+ }
115
+ end
82
116
 
117
+ should "add it's partials to it's markup" do
118
+ assert_equal 2, subject.worksheets.first.rows.size
119
+ end
120
+
121
+ end
83
122
  end
84
123
 
85
124
  class WorksheetBindingTest < Test::Unit::TestCase
@@ -94,6 +133,7 @@ module Osheet
94
133
  assert_equal @test, @worksheet.attributes[:name]
95
134
  assert_equal @test.object_id, @worksheet.attributes[:name].object_id
96
135
  end
136
+
97
137
  end
98
138
  end
99
139
 
@@ -129,6 +129,7 @@ module Osheet
129
129
  href 'http://example.com'
130
130
  rowspan 2
131
131
  colspan 5
132
+ index 3
132
133
  end
133
134
  subject.workbook = Workbook.new {
134
135
  style('.awesome') {
@@ -150,6 +151,7 @@ module Osheet
150
151
  assert_equal @cell.attributes[:data], @xmlss_cell.data.value
151
152
  assert_equal ::Xmlss::Data.type(:number), @xmlss_cell.data.type
152
153
  assert_equal 'http://example.com', @xmlss_cell.href
154
+ assert_equal 3, @xmlss_cell.index
153
155
  end
154
156
 
155
157
  should "handle rowspan and colspan" do
@@ -165,4 +167,4 @@ module Osheet
165
167
  end
166
168
  end
167
169
 
168
- end
170
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osheet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
8
+ - 6
9
9
  - 0
10
- version: 0.5.0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kelly Redding
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-19 00:00:00 -05:00
18
+ date: 2011-04-20 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -196,19 +196,22 @@ files:
196
196
  - lib/osheet/format/special.rb
197
197
  - lib/osheet/format/text.rb
198
198
  - lib/osheet/instance.rb
199
+ - lib/osheet/markup_element.rb
199
200
  - lib/osheet/meta_element.rb
200
201
  - lib/osheet/mixin.rb
202
+ - lib/osheet/partial.rb
203
+ - lib/osheet/partial_set.rb
201
204
  - lib/osheet/railtie.rb
202
205
  - lib/osheet/row.rb
203
206
  - lib/osheet/style.rb
204
207
  - lib/osheet/style_set.rb
205
208
  - lib/osheet/styled_element.rb
206
209
  - lib/osheet/template.rb
207
- - lib/osheet/template_handler.rb
208
- - lib/osheet/template_handler/rails.rb
209
- - lib/osheet/template_handler/tilt.rb
210
210
  - lib/osheet/template_set.rb
211
211
  - lib/osheet/version.rb
212
+ - lib/osheet/view_handler.rb
213
+ - lib/osheet/view_handler/rails.rb
214
+ - lib/osheet/view_handler/tilt.rb
212
215
  - lib/osheet/workbook.rb
213
216
  - lib/osheet/workbook_element.rb
214
217
  - lib/osheet/worksheet.rb
@@ -238,6 +241,8 @@ files:
238
241
  - test/mixin_test.rb
239
242
  - test/mixins.rb
240
243
  - test/osheet_test.rb
244
+ - test/partial_set_test.rb
245
+ - test/partial_test.rb
241
246
  - test/rails/three/.gitignore
242
247
  - test/rails/three/Gemfile
243
248
  - test/rails/three/Gemfile.lock
@@ -372,6 +377,8 @@ test_files:
372
377
  - test/mixin_test.rb
373
378
  - test/mixins.rb
374
379
  - test/osheet_test.rb
380
+ - test/partial_set_test.rb
381
+ - test/partial_test.rb
375
382
  - test/rails/three/.gitignore
376
383
  - test/rails/three/Gemfile
377
384
  - test/rails/three/Gemfile.lock
@@ -1,2 +0,0 @@
1
- require 'osheet/template_handler/tilt' if defined?(Tilt)
2
- require 'osheet/template_handler/rails' if defined?(Rails)