spreadsheet_architect 4.2.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +10 -14
- data/lib/spreadsheet_architect/class_methods/ods.rb +18 -8
- data/lib/spreadsheet_architect/class_methods/xlsx.rb +76 -32
- data/lib/spreadsheet_architect/exceptions.rb +30 -13
- data/lib/spreadsheet_architect/utils/ods.rb +66 -0
- data/lib/spreadsheet_architect/utils/xlsx.rb +29 -8
- data/lib/spreadsheet_architect/utils.rb +13 -38
- data/lib/spreadsheet_architect/version.rb +1 -1
- data/lib/spreadsheet_architect.rb +3 -2
- data/test/dummy_app/app/controllers/spreadsheets_controller.rb +1 -1
- data/test/dummy_app/config/application.rb +4 -12
- data/test/dummy_app/config/routes.rb +1 -1
- data/test/dummy_app/db/test.sqlite3 +0 -0
- data/test/dummy_app/log/test.log +79842 -63691
- data/test/dummy_app/tmp/2.0.1/integration/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/integration/csv.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/integration/ods.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/integration/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/kitchen_sink.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/kitchen_sink.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/empty.csv +1 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/ActiveModelObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/empty.csv +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomColumnsMethodPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.csv +1 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/CustomPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/LegacyPlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/PlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/data.csv +3 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/data.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/data.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/empty.csv +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/empty.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/empty.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/instances.csv +6 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/instances.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/models/Post/instances.xlsx +0 -0
- data/test/dummy_app/tmp/2.0.1/multi_sheet.ods +0 -0
- data/test/dummy_app/tmp/2.0.1/multi_sheet.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/csv.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/integration/ods.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/integration/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/kitchen_sink.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/kitchen_sink.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.csv +1 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/ActiveModelObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/data.csv +1 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/instances.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomColumnsMethodPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.csv +1 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/CustomPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.csv +1 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/LegacyPlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.csv +1 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.csv +0 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/PlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.csv +1 -1
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/data.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.csv +1 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/empty.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/instances.csv +5 -5
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/instances.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/models/Post/instances.xlsx +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/multi_sheet.ods +0 -0
- data/test/dummy_app/tmp/3.0.0.pre/multi_sheet.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/integration/alt_xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/integration/csv.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/integration/ods.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/integration/xlsx.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/kitchen_sink.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/kitchen_sink.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.csv +4 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/ActiveModelObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/data.csv +4 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomColumnsMethodPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.csv +4 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/CustomPost/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.csv +4 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/LegacyPlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.csv +4 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/PlainRubyObject/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/data.csv +4 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/data.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/data.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/empty.csv +1 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/empty.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/empty.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/instances.csv +6 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/instances.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/models/Post/instances.xlsx +0 -0
- data/test/dummy_app/tmp/axlsx-master/multi_sheet.ods +0 -0
- data/test/dummy_app/tmp/axlsx-master/multi_sheet.xlsx +0 -0
- data/test/integration/application_test.rb +8 -16
- data/test/models/all_models_test.rb +15 -19
- data/test/test_helper.rb +38 -9
- data/test/unit/ods/general_test.rb +121 -0
- data/test/unit/{formats_test.rb → rails/formats_test.rb} +1 -1
- data/test/unit/{exceptions_test.rb → spreadsheet_architect/exceptions_test.rb} +19 -15
- data/test/unit/{general_test.rb → spreadsheet_architect/spreadsheet_architect_test.rb} +3 -3
- data/test/unit/spreadsheet_architect/utils/ods_test.rb +58 -0
- data/test/unit/{xlsx_utils_test.rb → spreadsheet_architect/utils/xlsx_test.rb} +13 -21
- data/test/unit/{utils_test.rb → spreadsheet_architect/utils_test.rb} +12 -35
- data/test/unit/xlsx/freeze_test.rb +79 -0
- data/test/unit/xlsx/general_test.rb +199 -0
- metadata +381 -128
- data/test/dummy_app/config/environments/development.rb +0 -30
- data/test/dummy_app/config/environments/production.rb +0 -60
- data/test/unit/kitchen_sink_test.rb +0 -110
- data/test/unit/multi_sheet_test.rb +0 -29
- data/test/unit/options_test.rb +0 -9
- data/test/unit/xlsx_freeze_test.rb +0 -44
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class SpreadsheetArchitectUtilsTest < ActiveSupport::TestCase
|
4
4
|
klass = SpreadsheetArchitect::Utils
|
5
5
|
|
6
6
|
def setup
|
@@ -40,7 +40,7 @@ class UtilsTest < ActiveSupport::TestCase
|
|
40
40
|
|
41
41
|
### using Data option
|
42
42
|
output = klass.get_cell_data(@options.merge(headers: true), SpreadsheetArchitect)
|
43
|
-
assert_equal
|
43
|
+
assert_equal false, output[:headers]
|
44
44
|
|
45
45
|
output = klass.get_cell_data(@options.merge(headers: false), SpreadsheetArchitect)
|
46
46
|
assert_equal false, output[:headers]
|
@@ -88,7 +88,7 @@ class UtilsTest < ActiveSupport::TestCase
|
|
88
88
|
assert_not_empty klass.get_options(@options, Post)
|
89
89
|
|
90
90
|
### without :headers removes :header_style
|
91
|
-
|
91
|
+
assert_nil klass.get_options({header_style: false, headers: false}, SpreadsheetArchitect)[:header_style]
|
92
92
|
|
93
93
|
### sets :sheet_name if needed
|
94
94
|
assert_equal klass.get_options({sheet_name: false}, SpreadsheetArchitect)[:sheet_name], 'Sheet1'
|
@@ -96,40 +96,17 @@ class UtilsTest < ActiveSupport::TestCase
|
|
96
96
|
### sets :sheet_name if needed, using pluralized only when using Rails
|
97
97
|
assert_equal klass.get_options({sheet_name: false}, Post)[:sheet_name], 'Posts'
|
98
98
|
|
99
|
+
### sets :escape_formulas if not given
|
100
|
+
assert_equal klass.get_options({}, SpreadsheetArchitect)[:escape_formulas], true
|
101
|
+
|
102
|
+
assert_equal klass.get_options({}, SpreadsheetArchitect)[:use_zero_based_row_index], false
|
103
|
+
|
99
104
|
### removes default styles
|
100
|
-
assert_equal klass.get_options({skip_defaults: true}, SpreadsheetArchitect), {skip_defaults: true, sheet_name: "Sheet1"}
|
101
|
-
assert_equal klass.get_options({skip_defaults: true}, Post), {skip_defaults: true, sheet_name: "Posts"}
|
105
|
+
assert_equal klass.get_options({skip_defaults: true}, SpreadsheetArchitect), {skip_defaults: true, sheet_name: "Sheet1", escape_formulas: true, use_zero_based_row_index: false}
|
106
|
+
assert_equal klass.get_options({skip_defaults: true}, Post), {skip_defaults: true, sheet_name: "Posts", escape_formulas: true, use_zero_based_row_index: false}
|
102
107
|
|
103
|
-
assert_not_equal klass.get_options({skip_defaults: false}, SpreadsheetArchitect), {skip_defaults: true, sheet_name: "Sheet1"}
|
104
|
-
assert_not_equal klass.get_options({skip_defaults: false}, Post), {skip_defaults: true, sheet_name: "Posts"}
|
105
|
-
end
|
106
|
-
|
107
|
-
test "convert_styles_to_ods" do
|
108
|
-
ods_styles = klass.convert_styles_to_ods({
|
109
|
-
background_color: '333333',
|
110
|
-
color: '000000',
|
111
|
-
align: true,
|
112
|
-
bold: true,
|
113
|
-
font_size: 14,
|
114
|
-
italic: true,
|
115
|
-
underline: true,
|
116
|
-
test: true
|
117
|
-
})
|
118
|
-
|
119
|
-
assert_equal(ods_styles, {
|
120
|
-
'cell' => {
|
121
|
-
'background-color' => '#333333'
|
122
|
-
},
|
123
|
-
'text' => {
|
124
|
-
'color' => '#000000',
|
125
|
-
'align' => true,
|
126
|
-
'font-weight' => 'bold',
|
127
|
-
'font-size' => 14,
|
128
|
-
'font-style' => 'italic',
|
129
|
-
'text-underline-type' => 'single',
|
130
|
-
'text-underline-style' => 'solid'
|
131
|
-
}
|
132
|
-
})
|
108
|
+
assert_not_equal klass.get_options({skip_defaults: false}, SpreadsheetArchitect), {skip_defaults: true, sheet_name: "Sheet1", escape_formulas: true, use_zero_based_row_index: false}
|
109
|
+
assert_not_equal klass.get_options({skip_defaults: false}, Post), {skip_defaults: true, sheet_name: "Posts", escape_formulas: true, use_zero_based_row_index: false}
|
133
110
|
end
|
134
111
|
|
135
112
|
test "is_ar_model" do
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class XlsxFreezeTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@options = {
|
7
|
+
headers: [
|
8
|
+
['Latest Posts'],
|
9
|
+
['Title','Category','Author','Posted on','Posted At','Earnings']
|
10
|
+
],
|
11
|
+
data: 50.times.map{|i| [i, "foobar-#{i}", 5.4*i, true, Date.today, Time.now]},
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
end
|
17
|
+
|
18
|
+
test "basic" do
|
19
|
+
opts = @options.merge({
|
20
|
+
freeze: {rows: 1, columns: 1},
|
21
|
+
})
|
22
|
+
|
23
|
+
# Using Array Data
|
24
|
+
file_data = SpreadsheetArchitect.to_xlsx(opts)
|
25
|
+
|
26
|
+
save_file("xlsx/freeze_basic.xlsx", file_data)
|
27
|
+
end
|
28
|
+
|
29
|
+
test "using_ranges" do
|
30
|
+
opts = @options.merge({
|
31
|
+
freeze: {rows: (2..4), columns: (2..4)},
|
32
|
+
})
|
33
|
+
|
34
|
+
# Using Array Data
|
35
|
+
file_data = SpreadsheetArchitect.to_xlsx(opts)
|
36
|
+
|
37
|
+
save_file("xlsx/freeze_using_ranges.xlsx", file_data)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "using_legacy_arguments" do
|
41
|
+
opts = @options.merge({
|
42
|
+
freeze: {rows: :all, columns: 2},
|
43
|
+
})
|
44
|
+
|
45
|
+
# Using Array Data
|
46
|
+
file_data = SpreadsheetArchitect.to_xlsx(opts)
|
47
|
+
|
48
|
+
save_file("xlsx/freeze_using_legacy_arguments.xlsx", file_data)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "freeze_type" do
|
52
|
+
opts = @options.merge({
|
53
|
+
freeze: {row: (@options[:data].size-2), column: 16, type: "split_panes"},
|
54
|
+
})
|
55
|
+
|
56
|
+
# Using Array Data
|
57
|
+
file_data = SpreadsheetArchitect.to_xlsx(opts)
|
58
|
+
|
59
|
+
save_file("xlsx/freeze_type.xlsx", file_data)
|
60
|
+
end
|
61
|
+
|
62
|
+
test "panes_all_axlsx_options" do
|
63
|
+
opts = @options.merge({
|
64
|
+
freeze: {
|
65
|
+
row: (@options[:data].size-2),
|
66
|
+
column: 16,
|
67
|
+
state: "split",
|
68
|
+
#active_pane: "top_right",
|
69
|
+
#top_left_cell: "A2",
|
70
|
+
},
|
71
|
+
})
|
72
|
+
|
73
|
+
# Using Array Data
|
74
|
+
file_data = SpreadsheetArchitect.to_xlsx(opts)
|
75
|
+
|
76
|
+
save_file("xlsx/freeze_panes_all_axlsx_options.xlsx", file_data)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class XlsxGeneralTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
describe "header" do
|
6
|
+
test "header: false" do
|
7
|
+
spreadsheet = SpreadsheetArchitect.to_xlsx(headers: false, data: [[1]])
|
8
|
+
|
9
|
+
save_file("xlsx/headers_false_test.xlsx", spreadsheet)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
test "use_zero_based_row_index" do
|
14
|
+
spreadsheet = SpreadsheetArchitect.to_xlsx(
|
15
|
+
use_zero_based_row_index: true,
|
16
|
+
headers: [1, 2, 3],
|
17
|
+
data: [
|
18
|
+
[4,5,6],
|
19
|
+
[7,8,9],
|
20
|
+
[10,11,12],
|
21
|
+
],
|
22
|
+
range_styles: [
|
23
|
+
{range: {rows: 0, columns: 0}, styles: {bold: true}},
|
24
|
+
{range: {rows: (2..3), columns: 0}, styles: {italic: true}},
|
25
|
+
],
|
26
|
+
merges: [
|
27
|
+
{range: {rows: 0, columns: 1..2}},
|
28
|
+
{range: {rows: (2..3), columns: 2}},
|
29
|
+
],
|
30
|
+
borders: [
|
31
|
+
{range: {rows: 0, columns: :all}},
|
32
|
+
{range: {rows: 3, columns: 0}},
|
33
|
+
],
|
34
|
+
)
|
35
|
+
|
36
|
+
save_file("xlsx/use_zero_based_row_index_test.xlsx", spreadsheet)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "multisheet" do
|
40
|
+
test_data = [[1,2,3], [4,5,6], [7,8,9]]
|
41
|
+
|
42
|
+
package = Post.to_axlsx_package
|
43
|
+
package = CustomPost.to_axlsx_package({sheet_name: 'Latest Projects'}, package)
|
44
|
+
package = SpreadsheetArchitect.to_axlsx_package({data: test_data, sheet_name: 'Another Sheet'}, package)
|
45
|
+
|
46
|
+
save_file("xlsx/multi_sheet.xlsx", package)
|
47
|
+
end
|
48
|
+
|
49
|
+
test "kitchen sink" do
|
50
|
+
options = {
|
51
|
+
headers: [
|
52
|
+
['Latest Posts'],
|
53
|
+
['Title','Category','Author','Posted on','Posted At','Earnings']
|
54
|
+
],
|
55
|
+
data: 50.times.map{|i| [i, "foobar-#{i}", 5.4*i, true, Date.today, Time.now]},
|
56
|
+
header_style: {background_color: "000000", color: "FFFFFF", align: :center, font_size: 12, bold: true},
|
57
|
+
row_style: {background_color: nil, color: "000000", align: :left, font_size: 12},
|
58
|
+
sheet_name: 'Kitchen Sink',
|
59
|
+
freeze_headers: true,
|
60
|
+
|
61
|
+
column_styles: [
|
62
|
+
{columns: 0, styles: {bold: true}},
|
63
|
+
{columns: (1..3), styles: {color: "444444"}},
|
64
|
+
{columns: [4], include_header: false, styles: {italic: true}}
|
65
|
+
],
|
66
|
+
|
67
|
+
range_styles: [
|
68
|
+
{range: "B2:C4", styles: {background_color: "CCCCCC"}},
|
69
|
+
{range: {rows: 1, columns: :all}, styles: {bold: true}},
|
70
|
+
{range: {rows: (20..25), columns: (1..4)}, styles: {italic: true}},
|
71
|
+
{range: {rows: :all, columns: (3..4)}, styles: {color: "999999"}}
|
72
|
+
],
|
73
|
+
|
74
|
+
conditional_row_styles: [
|
75
|
+
{
|
76
|
+
if: Proc.new{|row_data, row_index|
|
77
|
+
row_index == 0 || row_data[0].to_i == 2
|
78
|
+
},
|
79
|
+
styles: {font_size: 18}
|
80
|
+
},
|
81
|
+
{
|
82
|
+
unless: Proc.new{|row_data, row_index|
|
83
|
+
row_index <= 10 || row_data[0].to_i == 15
|
84
|
+
},
|
85
|
+
styles: {align: :right}
|
86
|
+
},
|
87
|
+
],
|
88
|
+
|
89
|
+
borders: [
|
90
|
+
{range: "B2:C4"},
|
91
|
+
{range: "D6:D7", border_styles: {style: :dashDot, color: "333333"}},
|
92
|
+
{range: {rows: (2..11), columns: :all}, border_styles: {edges: [:top,:bottom]}},
|
93
|
+
{range: {rows: 3, columns: 4}, border_styles: {edges: [:top,:bottom]}}
|
94
|
+
],
|
95
|
+
|
96
|
+
merges: [
|
97
|
+
{range: "A1:C1"},
|
98
|
+
{range: {rows: 2, columns: :all}},
|
99
|
+
{range: {rows: (3..4), columns: (0..3)}}
|
100
|
+
],
|
101
|
+
|
102
|
+
column_types: [
|
103
|
+
:integer,
|
104
|
+
:string,
|
105
|
+
:float,
|
106
|
+
:boolean,
|
107
|
+
:date,
|
108
|
+
:time,
|
109
|
+
nil,
|
110
|
+
],
|
111
|
+
}
|
112
|
+
|
113
|
+
# Using Array Data
|
114
|
+
file_data = SpreadsheetArchitect.to_xlsx(options)
|
115
|
+
|
116
|
+
save_file("xlsx/kitchen_sink.xlsx", file_data)
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "column_types" do
|
120
|
+
test "validates provided types" do
|
121
|
+
assert_raise SpreadsheetArchitect::Exceptions::ArgumentError do
|
122
|
+
SpreadsheetArchitect.to_axlsx_package(
|
123
|
+
data: [],
|
124
|
+
column_types: [""]
|
125
|
+
)
|
126
|
+
end
|
127
|
+
|
128
|
+
SpreadsheetArchitect.to_axlsx_package(
|
129
|
+
data: [],
|
130
|
+
column_types: [:string, :integer, :float, :date, :time, :boolean, :hyperlink, nil, ->(x){ :foo }]
|
131
|
+
)
|
132
|
+
end
|
133
|
+
|
134
|
+
test "works with Proc types" do
|
135
|
+
url = "https://github.com/westonganger/spreadsheet_architect"
|
136
|
+
|
137
|
+
data = [
|
138
|
+
[1, 2],
|
139
|
+
[1, url],
|
140
|
+
]
|
141
|
+
|
142
|
+
p = SpreadsheetArchitect.to_axlsx_package(
|
143
|
+
data: data,
|
144
|
+
column_types: [
|
145
|
+
:string,
|
146
|
+
->(x){ x.to_s.start_with?("http") ? :hyperlink : :string }
|
147
|
+
]
|
148
|
+
)
|
149
|
+
|
150
|
+
doc = parse_axlsx_package(p)
|
151
|
+
|
152
|
+
hyperlinks = doc.css("hyperlinks hyperlink")
|
153
|
+
|
154
|
+
assert_equal 1, hyperlinks.size
|
155
|
+
|
156
|
+
ref = "B2"
|
157
|
+
assert_equal ref, hyperlinks[0].attr("ref")
|
158
|
+
cell = doc.at("c[r='#{ref}']")
|
159
|
+
assert_equal url, cell.text
|
160
|
+
assert_equal "inlineStr", cell.attr("t")
|
161
|
+
|
162
|
+
save_file("xlsx/hyperlinks.xlsx", p)
|
163
|
+
end
|
164
|
+
|
165
|
+
describe "hyperlinks" do
|
166
|
+
test "shows the text and have the correct attributes" do
|
167
|
+
url = "https://github.com/westonganger/spreadsheet_architect"
|
168
|
+
|
169
|
+
data = [
|
170
|
+
[1,2,3],
|
171
|
+
[1, url, "https://github.com/caxlsx/caxlsx"],
|
172
|
+
]
|
173
|
+
|
174
|
+
p = SpreadsheetArchitect.to_axlsx_package(data: data, column_types: [:string, :hyperlink, :string])
|
175
|
+
|
176
|
+
doc = parse_axlsx_package(p)
|
177
|
+
|
178
|
+
hyperlinks = doc.css("hyperlinks hyperlink")
|
179
|
+
|
180
|
+
assert_equal 2, hyperlinks.size
|
181
|
+
|
182
|
+
ref = "B1"
|
183
|
+
assert_equal ref, hyperlinks[0].attr("ref")
|
184
|
+
cell = doc.at("c[r='#{ref}']")
|
185
|
+
assert_equal "2", cell.text
|
186
|
+
assert_equal "inlineStr", cell.attr("t")
|
187
|
+
|
188
|
+
ref = "B2"
|
189
|
+
assert_equal ref, hyperlinks[1].attr("ref")
|
190
|
+
cell = doc.at("c[r='#{ref}']")
|
191
|
+
assert_equal url, cell.text
|
192
|
+
assert_equal "inlineStr", cell.attr("t")
|
193
|
+
|
194
|
+
save_file("xlsx/hyperlinks.xlsx", p)
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|