spreadsheet_architect 3.3.0 → 4.2.0

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.
data/test/test_helper.rb CHANGED
@@ -1,5 +1,15 @@
1
1
  ENV["RAILS_ENV"] = "test"
2
2
 
3
+ begin
4
+ require 'warning'
5
+
6
+ Warning.ignore(
7
+ %r{mail/parsers/address_lists_parser}, ### Hide mail gem warnings
8
+ )
9
+ rescue LoadError
10
+ # Do nothing
11
+ end
12
+
3
13
  require File.expand_path("../dummy_app/config/environment.rb", __FILE__)
4
14
 
5
15
  migration_path = Rails.root.join('db/migrate')
@@ -27,8 +37,6 @@ Minitest::Reporters.use!(
27
37
  Minitest.backtrace_filter
28
38
  )
29
39
 
30
- require 'custom_assertions'
31
-
32
40
  post_count = Post.count
33
41
  if post_count < 5
34
42
  (5 - post_count).times do |i|
@@ -36,14 +44,14 @@ if post_count < 5
36
44
  end
37
45
  end
38
46
 
39
- axlsx_spec = Gem.loaded_specs['axlsx']
40
- if !axlsx_spec.source.is_a?(Bundler::Source::Rubygems)
41
- axlsx_version = 'axlsx-master'
47
+ caxlsx_spec = Gem.loaded_specs['caxlsx']
48
+ if caxlsx_spec.source.is_a?(Bundler::Source::Rubygems)
49
+ caxlsx_version = caxlsx_spec.version.to_s
42
50
  else
43
- axlsx_version = axlsx_spec.version.to_s
51
+ caxlsx_version = 'caxlsx-master'
44
52
  end
45
53
 
46
- VERSIONED_BASE_PATH = Rails.root.join("../../tmp/#{axlsx_version}")
54
+ VERSIONED_BASE_PATH = Rails.root.join("../../tmp/#{caxlsx_version}")
47
55
 
48
56
  ### Cleanup old test spreadsheets
49
57
  FileUtils.remove_dir(VERSIONED_BASE_PATH, true)
@@ -19,6 +19,14 @@ class ExceptionsTest < ActiveSupport::TestCase
19
19
  conditional_row_styles = [{if: true, styles: false}]
20
20
  SpreadsheetArchitect::Utils::XLSX.conditional_styles_for_row(conditional_row_styles, true, true)
21
21
  end
22
+
23
+ assert_raise error do
24
+ SpreadsheetArchitect::Utils.get_options({freeze: {rows: 1}, freeze_headers: true}, SpreadsheetArchitect)
25
+ end
26
+
27
+ assert_raise error do
28
+ SpreadsheetArchitect.to_csv(foo: :bar)
29
+ end
22
30
  end
23
31
 
24
32
  test "NoDataError" do
@@ -27,7 +35,7 @@ class ExceptionsTest < ActiveSupport::TestCase
27
35
  assert error.new
28
36
 
29
37
  assert_raise error do
30
- SpreadsheetArchitect.to_csv(foo: :bar)
38
+ SpreadsheetArchitect.to_csv(headers: [])
31
39
  end
32
40
  end
33
41
 
@@ -11,7 +11,8 @@ class KitchenSinkTest < ActiveSupport::TestCase
11
11
  data: 50.times.map{|i| [i, "foobar-#{i}", 5.4*i, true, Date.today, Time.now]},
12
12
  header_style: {background_color: "000000", color: "FFFFFF", align: :center, font_size: 12, bold: true},
13
13
  row_style: {background_color: nil, color: "000000", align: :left, font_size: 12},
14
- sheet_name: 'Kitchen Sink'
14
+ sheet_name: 'Kitchen Sink',
15
+ freeze_headers: true,
15
16
  }
16
17
  end
17
18
 
@@ -19,7 +20,7 @@ class KitchenSinkTest < ActiveSupport::TestCase
19
20
  end
20
21
 
21
22
  def test_xlsx
22
- @options.merge!({
23
+ opts = @options.merge({
23
24
  column_styles: [
24
25
  {columns: 0, styles: {bold: true}},
25
26
  {columns: (1..3), styles: {color: "444444"}},
@@ -73,7 +74,7 @@ class KitchenSinkTest < ActiveSupport::TestCase
73
74
  })
74
75
 
75
76
  # Using Array Data
76
- file_data = SpreadsheetArchitect.to_xlsx(@options)
77
+ file_data = SpreadsheetArchitect.to_xlsx(opts)
77
78
 
78
79
  File.open(VERSIONED_BASE_PATH.join("kitchen_sink.xlsx"),'w+b') do |f|
79
80
  f.write file_data
@@ -81,7 +82,7 @@ class KitchenSinkTest < ActiveSupport::TestCase
81
82
  end
82
83
 
83
84
  def test_ods
84
- @options.merge!({
85
+ opts = @options.merge({
85
86
  headers: [
86
87
  ['Latest Posts'],
87
88
  ['Title','Category','Author','Boolean','Posted on','Posted At']
@@ -99,7 +100,7 @@ class KitchenSinkTest < ActiveSupport::TestCase
99
100
  })
100
101
 
101
102
  # Using Array Data
102
- file_data = SpreadsheetArchitect.to_ods(@options)
103
+ file_data = SpreadsheetArchitect.to_ods(opts)
103
104
 
104
105
  File.open(VERSIONED_BASE_PATH.join("kitchen_sink.ods"),'w+b') do |f|
105
106
  f.write file_data
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class OptionsTest < ActiveSupport::TestCase
4
+
5
+ test "header: false" do
6
+ assert SpreadsheetArchitect.to_xlsx(headers: false, data: [[1]])
7
+ end
8
+
9
+ end
@@ -40,6 +40,9 @@ 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 [[]], output[:headers]
44
+
45
+ output = klass.get_cell_data(@options.merge(headers: false), SpreadsheetArchitect)
43
46
  assert_equal false, output[:headers]
44
47
 
45
48
  output = klass.get_cell_data(@options.merge(column_types: nil), SpreadsheetArchitect)
@@ -85,13 +88,20 @@ class UtilsTest < ActiveSupport::TestCase
85
88
  assert_not_empty klass.get_options(@options, Post)
86
89
 
87
90
  ### without :headers removes :header_style
88
- assert_equal klass.get_options({header_style: false, headers: false}, SpreadsheetArchitect)[:header_style], false
91
+ assert_equal klass.get_options({header_style: false, headers: false}, SpreadsheetArchitect)[:header_style], nil
89
92
 
90
93
  ### sets :sheet_name if needed
91
94
  assert_equal klass.get_options({sheet_name: false}, SpreadsheetArchitect)[:sheet_name], 'Sheet1'
92
95
 
93
96
  ### sets :sheet_name if needed, using pluralized only when using Rails
94
97
  assert_equal klass.get_options({sheet_name: false}, Post)[:sheet_name], 'Posts'
98
+
99
+ ### 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"}
102
+
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"}
95
105
  end
96
106
 
97
107
  test "convert_styles_to_ods" do
@@ -153,7 +163,7 @@ class UtilsTest < ActiveSupport::TestCase
153
163
  end
154
164
 
155
165
  test "stringify_keys" do
156
- hash = klass.stringify_keys
166
+ hash = klass.stringify_keys({})
157
167
  assert_empty hash
158
168
 
159
169
  hash = klass.stringify_keys({foo: :bar})
@@ -176,4 +186,35 @@ class UtilsTest < ActiveSupport::TestCase
176
186
  assert_nil hash[:foo]
177
187
  assert_equal hash['foo']['foo']['foo']['foo'], :bar
178
188
  end
189
+
190
+ test "symbolize_keys" do
191
+ hash = klass.symbolize_keys({})
192
+ assert_empty hash
193
+
194
+ hash = klass.symbolize_keys({'foo' => :bar})
195
+ assert_nil hash['foo']
196
+ assert_equal hash[:foo], :bar
197
+
198
+ hash = klass.symbolize_keys({'foo' => :bar, bar: :foo})
199
+ assert_nil hash['foo']
200
+ assert_equal hash[:foo], :bar
201
+
202
+ hash = klass.symbolize_keys({'foo' => {'foo' => :bar}})
203
+ assert_nil hash['foo']
204
+ assert_equal hash[:foo][:foo], :bar
205
+
206
+ hash = klass.symbolize_keys({'foo' => {'foo' => {'foo' => :bar}}})
207
+ assert_nil hash['foo']
208
+ assert_equal hash[:foo][:foo][:foo], :bar
209
+ end
210
+
211
+ test "hash_array_symbolize_keys" do
212
+ array = klass.hash_array_symbolize_keys([])
213
+ assert_empty array
214
+
215
+ array = klass.hash_array_symbolize_keys([{'foo' => :bar}])
216
+ assert_nil array[0]['foo']
217
+ assert_equal array[0][:foo], :bar
218
+ end
219
+
179
220
  end
@@ -0,0 +1,44 @@
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
+ def test_1
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
+ File.open(VERSIONED_BASE_PATH.join("freeze_test_1.xlsx"),'w+b') do |f|
27
+ f.write file_data
28
+ end
29
+ end
30
+
31
+ def test_2
32
+ opts = @options.merge({
33
+ freeze: {rows: (2..4), columns: (2..4)},
34
+ })
35
+
36
+ # Using Array Data
37
+ file_data = SpreadsheetArchitect.to_xlsx(opts)
38
+
39
+ File.open(VERSIONED_BASE_PATH.join("freeze_test_2.xlsx"),'w+b') do |f|
40
+ f.write file_data
41
+ end
42
+ end
43
+
44
+ end
@@ -113,27 +113,6 @@ class XlsxUtilsTest < ActiveSupport::TestCase
113
113
  #end
114
114
  end
115
115
 
116
- test "symbolize_keys" do
117
- hash = klass.symbolize_keys
118
- assert_empty hash
119
-
120
- hash = klass.symbolize_keys({'foo' => :bar})
121
- assert_nil hash['foo']
122
- assert_equal hash[:foo], :bar
123
-
124
- hash = klass.symbolize_keys({'foo' => :bar, bar: :foo})
125
- assert_nil hash['foo']
126
- assert_equal hash[:foo], :bar
127
-
128
- hash = klass.symbolize_keys({'foo' => {'foo' => :bar}})
129
- assert_nil hash['foo']
130
- assert_equal hash[:foo][:foo], :bar
131
-
132
- hash = klass.symbolize_keys({'foo' => {'foo' => {'foo' => :bar}}})
133
- assert_nil hash['foo']
134
- assert_equal hash[:foo][:foo][:foo], :bar
135
- end
136
-
137
116
  test "constants" do
138
117
  assert_equal klass::COL_NAMES.count, 16384
139
118
  assert_equal klass::COL_NAMES.first, 'A'
metadata CHANGED
@@ -1,22 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet_architect
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weston Ganger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-28 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: axlsx
14
+ name: caxlsx
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
19
+ version: 2.0.2
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '4'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '2'
29
+ version: 2.0.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4'
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.1.7
39
+ version: 1.0.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '2'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.1.7
49
+ version: 1.0.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '2'
@@ -168,6 +168,20 @@ dependencies:
168
168
  - - ">="
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
+ - !ruby/object:Gem::Dependency
172
+ name: warning
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ type: :development
179
+ prerelease: false
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
171
185
  description: Spreadsheet Architect is a library that allows you to create XLSX, ODS,
172
186
  or CSV spreadsheets easily from ActiveRecord relations, Plain Ruby classes, or predefined
173
187
  data.
@@ -182,16 +196,15 @@ files:
182
196
  - Rakefile
183
197
  - lib/spreadsheet_architect.rb
184
198
  - lib/spreadsheet_architect/action_controller_renderers.rb
199
+ - lib/spreadsheet_architect/axlsx_string_width_patch.rb
185
200
  - lib/spreadsheet_architect/class_methods/csv.rb
186
201
  - lib/spreadsheet_architect/class_methods/ods.rb
187
202
  - lib/spreadsheet_architect/class_methods/xlsx.rb
188
203
  - lib/spreadsheet_architect/exceptions.rb
189
204
  - lib/spreadsheet_architect/mime_types.rb
190
- - lib/spreadsheet_architect/monkey_patches/axlsx_column_width.rb
191
205
  - lib/spreadsheet_architect/utils.rb
192
206
  - lib/spreadsheet_architect/utils/xlsx.rb
193
207
  - lib/spreadsheet_architect/version.rb
194
- - test/custom_assertions.rb
195
208
  - test/dummy_app/Rakefile
196
209
  - test/dummy_app/app/assets/config/manifest.js
197
210
  - test/dummy_app/app/assets/javascripts/application.js
@@ -298,11 +311,13 @@ files:
298
311
  - test/unit/general_test.rb
299
312
  - test/unit/kitchen_sink_test.rb
300
313
  - test/unit/multi_sheet_test.rb
301
- - test/unit/regressions_test.rb
314
+ - test/unit/options_test.rb
302
315
  - test/unit/utils_test.rb
316
+ - test/unit/xlsx_freeze_test.rb
303
317
  - test/unit/xlsx_utils_test.rb
304
318
  homepage: https://github.com/westonganger/spreadsheet_architect
305
- licenses: []
319
+ licenses:
320
+ - MIT
306
321
  metadata: {}
307
322
  post_install_message:
308
323
  rdoc_options: []
@@ -312,14 +327,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
312
327
  requirements:
313
328
  - - ">="
314
329
  - !ruby/object:Gem::Version
315
- version: 1.9.3
330
+ version: 2.3.0
316
331
  required_rubygems_version: !ruby/object:Gem::Requirement
317
332
  requirements:
318
333
  - - ">="
319
334
  - !ruby/object:Gem::Version
320
335
  version: '0'
321
336
  requirements: []
322
- rubygems_version: 3.0.3
337
+ rubygems_version: 3.1.2
323
338
  signing_key:
324
339
  specification_version: 4
325
340
  summary: Spreadsheet Architect is a library that allows you to create XLSX, ODS, or
@@ -329,11 +344,12 @@ test_files:
329
344
  - test/models/all_models_test.rb
330
345
  - test/integration/application_test.rb
331
346
  - test/test_helper.rb
347
+ - test/unit/options_test.rb
332
348
  - test/unit/multi_sheet_test.rb
333
- - test/unit/regressions_test.rb
334
349
  - test/unit/formats_test.rb
335
350
  - test/unit/kitchen_sink_test.rb
336
351
  - test/unit/utils_test.rb
352
+ - test/unit/xlsx_freeze_test.rb
337
353
  - test/unit/general_test.rb
338
354
  - test/unit/xlsx_utils_test.rb
339
355
  - test/unit/exceptions_test.rb
@@ -435,4 +451,3 @@ test_files:
435
451
  - test/dummy_app/db/schema.rb
436
452
  - test/dummy_app/db/test.sqlite3
437
453
  - test/dummy_app/db/migrate/20170103234524_add_posts.rb
438
- - test/custom_assertions.rb
@@ -1,56 +0,0 @@
1
- if RUBY_VERSION.to_f >= 2
2
-
3
- module SpreadsheetArchitect
4
- module AxlsxColumnWidthPatch
5
- def initialize(*args)
6
- @width = nil
7
- super
8
- end
9
-
10
- def width=(v)
11
- if v.nil?
12
- @custom_width = false
13
- @width = nil
14
- elsif @width.nil? || @width < v+5
15
- @custom_width = true
16
- @best_fit = true
17
- @width = v + 5
18
- else
19
- @custom_width = true
20
- @width = v
21
- end
22
- end
23
- end
24
- end
25
-
26
- module Axlsx
27
- class Col
28
- prepend ::SpreadsheetArchitect::AxlsxColumnWidthPatch
29
- end
30
- end
31
-
32
- else
33
-
34
- module Axlsx
35
- class Col
36
- original_initialize = instance_method(:initialize)
37
- define_method :initialize do |*args|
38
- @width = nil
39
-
40
- original_initialize.bind(self).(*args)
41
- end
42
-
43
- def width=(v)
44
- if v.nil?
45
- @custom_width = false
46
- @width = nil
47
- elsif @width.nil? || @width < v+5
48
- @custom_width = true
49
- @best_fit = true
50
- @width = v + 5
51
- end
52
- end
53
- end
54
- end
55
-
56
- end