spreadbase 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -2
- data/.rspec +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/LICENSE +674 -0
- data/README.md +12 -17
- data/Rakefile +5 -0
- data/docs/STRUCTURE.md +3 -0
- data/docs/TESTING.md +11 -0
- data/lib/spreadbase/cell.rb +19 -0
- data/lib/spreadbase/codecs/open_document_12.rb +19 -41
- data/lib/spreadbase/codecs/open_document_12_modules/decoding.rb +72 -92
- data/lib/spreadbase/codecs/open_document_12_modules/encoding.rb +43 -72
- data/lib/spreadbase/document.rb +12 -33
- data/lib/spreadbase/helpers/helpers.rb +27 -61
- data/lib/spreadbase/table.rb +120 -86
- data/lib/spreadbase/version.rb +1 -3
- data/lib/spreadbase.rb +7 -28
- data/spec/codecs/open_document_12_spec.rb +42 -64
- data/spec/elements/document_spec.rb +33 -55
- data/spec/elements/table_spec.rb +186 -174
- data/spec/spec_helper.rb +100 -0
- data/spec/spec_helpers.rb +10 -30
- data/spreadbase.gemspec +14 -9
- data/utils/convert_sqlite_to_ods.rb +30 -49
- data/utils/test_ods_folder.rb +7 -26
- data/utils/test_recoding_file.rb +11 -27
- data/utils/test_recoding_from_content.rb +10 -29
- data/utils/utils_helpers.rb +19 -33
- metadata +41 -26
- data/COPYING.LESSER +0 -165
- data/utils/prettify_file.rb +0 -46
@@ -1,25 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
=begin
|
4
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
-
|
6
|
-
This file is part of SpreadBase.
|
7
|
-
|
8
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
-
version.
|
12
|
-
|
13
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU Lesser General Public License along
|
18
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
=end
|
20
|
-
|
21
|
-
require File.expand_path( '../../../lib/spreadbase', __FILE__ )
|
22
|
-
require File.expand_path( '../../spec_helpers', __FILE__ )
|
1
|
+
require_relative '../../lib/spreadbase'
|
2
|
+
require_relative '../spec_helpers'
|
23
3
|
|
24
4
|
require 'date'
|
25
5
|
require 'bigdecimal'
|
@@ -33,13 +13,13 @@ describe SpreadBase::Codecs::OpenDocument12 do
|
|
33
13
|
before :each do
|
34
14
|
table_1 = SpreadBase::Table.new(
|
35
15
|
'abc', [
|
36
|
-
[
|
37
|
-
[
|
38
|
-
[
|
16
|
+
[1, 1.1, T_BIGDECIMAL],
|
17
|
+
[T_DATE, T_DATETIME, T_TIME],
|
18
|
+
[nil, 'a', nil]
|
39
19
|
]
|
40
20
|
)
|
41
21
|
|
42
|
-
table_2 = SpreadBase::Table.new(
|
22
|
+
table_2 = SpreadBase::Table.new('cde')
|
43
23
|
|
44
24
|
@sample_document = SpreadBase::Document.new
|
45
25
|
|
@@ -49,89 +29,87 @@ describe SpreadBase::Codecs::OpenDocument12 do
|
|
49
29
|
# :encode/:decode
|
50
30
|
#
|
51
31
|
it "should encode and decode the sample document" do
|
52
|
-
document_archive = SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(
|
32
|
+
document_archive = SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(@sample_document)
|
53
33
|
|
54
|
-
document = SpreadBase::Codecs::OpenDocument12.new.decode_archive(
|
34
|
+
document = SpreadBase::Codecs::OpenDocument12.new.decode_archive(document_archive, floats_as_bigdecimal: true)
|
55
35
|
|
56
|
-
assert_size(
|
36
|
+
assert_size(document.tables, 2) do | table_1, table_2 |
|
57
37
|
|
58
|
-
table_1.name.
|
38
|
+
expect(table_1.name).to eq('abc')
|
59
39
|
|
60
|
-
assert_size(
|
40
|
+
assert_size(table_1.data, 3) do | row_1, row_2, row_3 |
|
61
41
|
|
62
|
-
assert_size(
|
63
|
-
value_1.
|
64
|
-
value_1.
|
65
|
-
value_2.
|
66
|
-
value_2.
|
67
|
-
value_3.
|
68
|
-
value_3.
|
42
|
+
assert_size(row_1, 3) do | value_1, value_2, value_3 |
|
43
|
+
expect(value_1).to eq(1)
|
44
|
+
expect(value_1).to be_a(Integer)
|
45
|
+
expect(value_2).to eq(1.1)
|
46
|
+
expect(value_2).to be_a(BigDecimal)
|
47
|
+
expect(value_3).to eq(T_BIGDECIMAL)
|
48
|
+
expect(value_3).to be_a(BigDecimal)
|
69
49
|
end
|
70
50
|
|
71
|
-
assert_size(
|
72
|
-
value_1.
|
73
|
-
value_2.
|
74
|
-
value_3.
|
51
|
+
assert_size(row_2, 3) do | value_1, value_2, value_3 |
|
52
|
+
expect(value_1).to eq(T_DATE)
|
53
|
+
expect(value_2).to eq(T_DATETIME)
|
54
|
+
expect(value_3).to eq(T_DATETIME)
|
75
55
|
end
|
76
56
|
|
77
|
-
assert_size(
|
78
|
-
value_1.
|
79
|
-
value_2.
|
80
|
-
value_3.
|
57
|
+
assert_size(row_3, 3) do | value_1, value_2, value_3 |
|
58
|
+
expect(value_1).to eq(nil)
|
59
|
+
expect(value_2).to eq('a')
|
60
|
+
expect(value_3).to eq(nil)
|
81
61
|
end
|
82
62
|
|
83
63
|
end
|
84
64
|
|
85
|
-
table_2.name.
|
65
|
+
expect(table_2.name).to eq('cde')
|
86
66
|
|
87
|
-
assert_size(
|
67
|
+
assert_size(table_2.data, 0)
|
88
68
|
end
|
89
69
|
end
|
90
70
|
|
91
71
|
# Not worth testing in detail; just ensure that the pref
|
92
72
|
#
|
93
73
|
it "should encode the document with makeup (:prettify) - SMOKE" do
|
94
|
-
formatter = stub_initializer(
|
74
|
+
formatter = stub_initializer(REXML::Formatters::Pretty)
|
95
75
|
|
96
|
-
formatter.
|
76
|
+
expect(formatter).to receive(:write)
|
97
77
|
|
98
|
-
SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(
|
78
|
+
SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(@sample_document, prettify: true)
|
99
79
|
end
|
100
80
|
|
101
81
|
# Those methods are actually "utility" (read: testing) methods.
|
102
82
|
#
|
103
83
|
it "should encode/decode the content.xml - SMOKE" do
|
104
|
-
content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(
|
84
|
+
content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(@sample_document)
|
105
85
|
|
106
|
-
document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(
|
86
|
+
document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(content_xml)
|
107
87
|
|
108
|
-
assert_size(
|
88
|
+
assert_size(document.tables, 2)
|
109
89
|
end
|
110
90
|
|
111
91
|
# If values are not converted to UTF-8, some encodings cause an error to be
|
112
92
|
# raised when assigning a value to a cell.
|
113
93
|
#
|
114
|
-
# 1.8 tests can't be done, since the official platform is 1.9
|
115
|
-
#
|
116
94
|
it "should convert to utf-8 before saving" do
|
117
|
-
string = "à".encode(
|
95
|
+
string = "à".encode('utf-16')
|
118
96
|
|
119
|
-
@sample_document.tables[
|
97
|
+
@sample_document.tables[0][0, 0] = string
|
120
98
|
|
121
99
|
# Doesn't encode correctly if the value is not converted
|
122
100
|
#
|
123
|
-
SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(
|
101
|
+
SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(@sample_document)
|
124
102
|
end
|
125
103
|
|
126
104
|
it "should decode as BigDecimal" do
|
127
|
-
content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(
|
105
|
+
content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(@sample_document)
|
128
106
|
|
129
|
-
document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(
|
107
|
+
document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(content_xml, floats_as_bigdecimal: true)
|
130
108
|
|
131
|
-
value = document.tables[
|
109
|
+
value = document.tables[0][2, 0]
|
132
110
|
|
133
|
-
value.
|
134
|
-
value.
|
111
|
+
expect(value).to be_a(BigDecimal)
|
112
|
+
expect(value).to eq(T_BIGDECIMAL)
|
135
113
|
end
|
136
114
|
|
137
115
|
end
|
@@ -1,25 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
=begin
|
4
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
-
|
6
|
-
This file is part of SpreadBase.
|
7
|
-
|
8
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
-
version.
|
12
|
-
|
13
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU Lesser General Public License along
|
18
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
=end
|
20
|
-
|
21
|
-
require File.expand_path( '../../../lib/spreadbase', __FILE__ )
|
22
|
-
require File.expand_path( '../../spec_helpers', __FILE__ )
|
1
|
+
require_relative '../../lib/spreadbase'
|
2
|
+
require_relative '../spec_helpers'
|
23
3
|
|
24
4
|
include SpecHelpers
|
25
5
|
|
@@ -30,9 +10,9 @@ describe SpreadBase::Document do
|
|
30
10
|
@sample_document.tables = [
|
31
11
|
SpreadBase::Table.new(
|
32
12
|
'abc', [
|
33
|
-
[
|
34
|
-
[
|
35
|
-
[
|
13
|
+
[1, 1.1, T_BIGDECIMAL],
|
14
|
+
[T_DATE, T_DATETIME, T_TIME],
|
15
|
+
[true, 'a', nil]
|
36
16
|
]
|
37
17
|
)
|
38
18
|
]
|
@@ -43,61 +23,59 @@ describe SpreadBase::Document do
|
|
43
23
|
it "should initialize out of thin air" do
|
44
24
|
document = SpreadBase::Document.new
|
45
25
|
|
46
|
-
document.document_path.
|
26
|
+
expect(document.document_path).to be(nil)
|
47
27
|
|
48
|
-
document.tables.
|
28
|
+
expect(document.tables).to be_empty
|
49
29
|
end
|
50
30
|
|
51
31
|
# A lazy use of stubs
|
52
32
|
#
|
53
33
|
it "should initialize from a file" do
|
54
|
-
codec = stub_initializer(
|
34
|
+
codec = stub_initializer(SpreadBase::Codecs::OpenDocument12)
|
55
35
|
|
56
|
-
File.
|
57
|
-
IO.
|
58
|
-
codec.
|
36
|
+
expect(File).to receive(:'exist?').with('/pizza/margerita.txt').and_return(true)
|
37
|
+
expect(IO).to receive(:read).with('/pizza/margerita.txt').and_return('abc')
|
38
|
+
expect(codec).to receive(:decode_archive).with('abc', {}).and_return(@sample_document)
|
59
39
|
|
60
|
-
document = SpreadBase::Document.new(
|
40
|
+
document = SpreadBase::Document.new('/pizza/margerita.txt')
|
61
41
|
|
62
|
-
assert_size(
|
63
|
-
table.name.
|
64
|
-
table.data.size.
|
42
|
+
assert_size(document.tables, 1) do | table |
|
43
|
+
expect(table.name).to eq('abc')
|
44
|
+
expect(table.data.size).to eq(3)
|
65
45
|
end
|
66
46
|
end
|
67
47
|
|
68
48
|
it "should initialize with a non-existing file" do
|
69
|
-
|
70
|
-
|
71
|
-
document = SpreadBase::Document.new( '/pizza/margerita.txt' )
|
49
|
+
document = SpreadBase::Document.new('/pizza/margerita.txt')
|
72
50
|
|
73
|
-
assert_size(
|
51
|
+
assert_size(document.tables, 0)
|
74
52
|
end
|
75
53
|
|
76
54
|
it "should save to a file" do
|
77
|
-
codec = stub_initializer(
|
55
|
+
codec = stub_initializer(SpreadBase::Codecs::OpenDocument12)
|
78
56
|
|
79
57
|
document = SpreadBase::Document.new
|
80
|
-
document.tables << SpreadBase::Table.new(
|
58
|
+
document.tables << SpreadBase::Table.new('Ya-ha!')
|
81
59
|
document.document_path = '/tmp/abc.ods'
|
82
60
|
|
83
|
-
codec.
|
84
|
-
File.
|
61
|
+
expect(codec).to receive(:encode_to_archive).with(document, prettify: 'abc').and_return('sob!')
|
62
|
+
expect(File).to receive(:open).with('/tmp/abc.ods', 'wb')
|
85
63
|
|
86
|
-
document.save(
|
64
|
+
document.save(prettify: 'abc')
|
87
65
|
end
|
88
66
|
|
89
67
|
it "should raise an error when trying to save without a filename" do
|
90
68
|
document = SpreadBase::Document.new
|
91
|
-
document.tables << SpreadBase::Table.new(
|
69
|
+
document.tables << SpreadBase::Table.new('Ya-ha!')
|
92
70
|
|
93
|
-
|
71
|
+
expect { document.save }.to raise_error(RuntimeError, "Document path not specified")
|
94
72
|
end
|
95
73
|
|
96
74
|
it "should raise an error when trying to save without tables" do
|
97
75
|
document = SpreadBase::Document.new
|
98
76
|
document.document_path = 'abc.ods'
|
99
77
|
|
100
|
-
|
78
|
+
expect { document.save }.to raise_error(RuntimeError, "At least one table must be present")
|
101
79
|
end
|
102
80
|
|
103
81
|
it "should return the data as string (:to_s)" do
|
@@ -105,14 +83,14 @@ describe SpreadBase::Document do
|
|
105
83
|
abc:
|
106
84
|
|
107
85
|
+------------+---------------------------+---------------------------+
|
108
|
-
| 1 | 1.1 |
|
109
|
-
| 2012-04-10 | 2012-04-
|
110
|
-
| true | a |
|
86
|
+
| 1 | 1.1 | 1.33 |
|
87
|
+
| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
|
88
|
+
| true | a | NIL |
|
111
89
|
+------------+---------------------------+---------------------------+
|
112
90
|
|
113
91
|
"
|
114
92
|
|
115
|
-
@sample_document.to_s.
|
93
|
+
expect(@sample_document.to_s).to eq(expected_string)
|
116
94
|
end
|
117
95
|
|
118
96
|
it "should return the data as string, with headers (:to_s)" do
|
@@ -120,15 +98,15 @@ abc:
|
|
120
98
|
abc:
|
121
99
|
|
122
100
|
+------------+---------------------------+---------------------------+
|
123
|
-
| 1 | 1.1 |
|
101
|
+
| 1 | 1.1 | 1.33 |
|
124
102
|
+------------+---------------------------+---------------------------+
|
125
|
-
| 2012-04-10 | 2012-04-
|
126
|
-
| true | a |
|
103
|
+
| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
|
104
|
+
| true | a | NIL |
|
127
105
|
+------------+---------------------------+---------------------------+
|
128
106
|
|
129
107
|
"
|
130
108
|
|
131
|
-
@sample_document.to_s(
|
109
|
+
expect(@sample_document.to_s(with_headers: true)).to eq(expected_string)
|
132
110
|
end
|
133
111
|
|
134
112
|
end
|