activeadmin-xls 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0061e54090d183ee6259739d20d7db62eb890790
4
- data.tar.gz: 7691fe01a10bcdd3aac3239f690ae98f95258460
3
+ metadata.gz: d5dcd598421b522ad83b3ddd1a1a038b3d173f3e
4
+ data.tar.gz: c882e40a69baa02ef345c31001f77b5f2b291652
5
5
  SHA512:
6
- metadata.gz: 522ac0e6309ad124d216acdd64228efec606836dd75369f90b9f8e2e806e017c658190a841c56bf54b3e77fe72bd3b5cac00be571db3602745a22f432855f33d
7
- data.tar.gz: ffab449bd41cfb19b97d5b879d656f531a2cde929e98a5188b90765a5bce506200fd328f3f49a1ce4819d8837c8d5e994839abf4a36bd3c8e2dc1cbff97d1990
6
+ metadata.gz: 5909fa865c0f9664b61d7771215faaf2695e2b6fe72c8de21b61d5286ba1c7213496d1271057ab9df6579f265e3203f0e40ccb9b7ca5ca227e0493709801e53c
7
+ data.tar.gz: 10ea87bd2f9c629b4c4f5acf58f37dcb89f2c8f263e58ba6b12c840d70b80922e00bc65af457495d08bfef5deff3d2b3278e442eb6ce443166b8b531e378f991
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## 2.0.1
6
+
7
+ ### Fixed
8
+
9
+ * fix issue with xls_builder retaining data between requests when there is an exception on a computed field [#13][]
10
+
11
+ ## 2.0.0
12
+
13
+ ### Changed
14
+
15
+ * Drop support for ruby 1.9, rails 3.2, and ActiveAdmin 0.6.6.
16
+ * Add support for rails 5.1 [#8][]
17
+
5
18
  ## 1.1.0
6
19
 
7
20
  ### Added
@@ -45,7 +58,9 @@
45
58
  [#3]: https://github.com/thambley/activeadmin-xls/issues/3
46
59
  [#4]: https://github.com/thambley/activeadmin-xls/pull/4
47
60
  [#7]: https://github.com/thambley/activeadmin-xls/issues/7
61
+ [#8]: https://github.com/thambley/activeadmin-xls/issues/8
48
62
  [#11]: https://github.com/thambley/activeadmin-xls/pull/11
63
+ [#13]: https://github.com/thambley/activeadmin-xls/issues/13
49
64
 
50
65
  [@rewritten]: https://github.com/rewritten
51
66
  [@ejaypcanaria]: https://github.com/ejaypcanaria
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gem 'spreadsheet', '~> 1.1', '>= 1.1.4'
4
4
 
5
5
  group :development, :test do
6
6
  gem 'rails-i18n' # Gives us default i18n for many languages
7
- gem 'sqlite3'
7
+ gem 'sqlite3', '~> 1.3.0'
8
8
  gem 'yard'
9
9
  end
10
10
 
@@ -10,7 +10,7 @@ module ActiveAdmin
10
10
  # @param [Class] resource_class The resource this builder generate column
11
11
  # information for.
12
12
  # @param [Hash] options the options for the builder
13
- # @option options [Hash] :header_format a hash of format properties to
13
+ # @option options [Hash] :header_format A hash of format properties to
14
14
  # apply to the header row. Any properties specified will be merged with
15
15
  # the default header styles.
16
16
  # @option options [Array] :i18n_scope the I18n scope to use when looking
@@ -264,11 +264,13 @@ module ActiveAdmin
264
264
  def serialize(collection, view_context = nil)
265
265
  @collection = collection
266
266
  @view_context = view_context
267
+ book = Spreadsheet::Workbook.new
268
+ sheet = book.create_worksheet
267
269
  load_columns unless @columns_loaded
268
- apply_filter @before_filter
269
- export_collection(collection)
270
- apply_filter @after_filter
271
- to_stream
270
+ apply_filter @before_filter, sheet
271
+ export_collection collection, sheet
272
+ apply_filter @after_filter, sheet
273
+ to_stream book
272
274
  end
273
275
 
274
276
  # Xls column information
@@ -314,18 +316,13 @@ module ActiveAdmin
314
316
  columns
315
317
  end
316
318
 
317
- def to_stream
319
+ def to_stream(book)
318
320
  stream = StringIO.new('')
319
321
  book.write stream
320
- clean_up
321
322
  stream.string
322
323
  end
323
324
 
324
- def clean_up
325
- @book = @sheet = nil
326
- end
327
-
328
- def export_collection(collection)
325
+ def export_collection(collection, sheet)
329
326
  return if columns.none?
330
327
  row_index = sheet.dimensions[1]
331
328
 
@@ -354,7 +351,7 @@ module ActiveAdmin
354
351
  end.compact
355
352
  end
356
353
 
357
- def apply_filter(filter)
354
+ def apply_filter(filter, sheet)
358
355
  filter.call(sheet) if filter
359
356
  end
360
357
 
@@ -376,14 +373,6 @@ module ActiveAdmin
376
373
  resource.respond_to?(column.name)
377
374
  end
378
375
 
379
- def sheet
380
- @sheet ||= book.create_worksheet
381
- end
382
-
383
- def book
384
- @book ||= ::Spreadsheet::Workbook.new
385
- end
386
-
387
376
  def resource_columns(resource)
388
377
  [Column.new(:id)] + resource.content_columns.map do |column|
389
378
  Column.new(column.name.to_sym)
@@ -51,8 +51,6 @@ module ActiveAdmin
51
51
  end
52
52
 
53
53
  # Returns the collection to use when generating an xls file.
54
- # It uses the find_collection function if it is available, and uses
55
- # collection if find_collection isn't available.
56
54
  def xls_collection
57
55
  find_collection except: :pagination
58
56
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveAdmin
2
2
  module Xls
3
3
  # ActiveAdmin XLS gem version
4
- VERSION = '2.0.0'.freeze
4
+ VERSION = '2.0.1'.freeze
5
5
  end
6
6
  end
@@ -93,8 +93,8 @@ inject_into_file(
93
93
  after: "config.cache_classes = true\n"
94
94
  )
95
95
 
96
- lib_path = File.expand_path('../../../lib/activeadmin-xls', __FILE__)
97
96
  # Add our local Active Admin to the load path
97
+ lib_path = File.expand_path('../../../lib/activeadmin-xls', __FILE__)
98
98
  inject_into_file 'config/environment.rb',
99
99
  "\nrequire '#{lib_path}'\n",
100
100
  after: "require File.expand_path('../application', __FILE__)"
@@ -84,12 +84,7 @@ module ActiveAdmin
84
84
  end
85
85
 
86
86
  before do
87
- # disable clean up so we can get the book.
88
- allow(builder).to receive(:clean_up) { false }
89
- # @book = Spreadsheet.open(builder.serialize(posts))
90
- builder.serialize(posts)
91
- @book = builder.send(:book)
92
- @collection = builder.collection
87
+ @book = Spreadsheet.open(StringIO.new(builder.serialize(posts)))
93
88
  end
94
89
 
95
90
  it 'does not serialize the header' do
@@ -113,12 +108,7 @@ module ActiveAdmin
113
108
  end
114
109
 
115
110
  before do
116
- allow(User).to receive(:all) { users }
117
- allow(Post).to receive(:all) { posts }
118
- # disable clean up so we can get the book.
119
- allow(builder).to receive(:clean_up) { false }
120
- builder.serialize(Post.all)
121
- @book = builder.send(:book)
111
+ @book = Spreadsheet.open(StringIO.new(builder.serialize(posts)))
122
112
  @collection = builder.collection
123
113
  end
124
114
 
@@ -173,10 +163,7 @@ module ActiveAdmin
173
163
  @post = Post.create!(title: 'bob',
174
164
  body: 'is a swell guy',
175
165
  author: @user)
176
- # disable clean up so we can get the book.
177
- allow(builder).to receive(:clean_up) { false }
178
- builder.serialize(Post.all)
179
- @book = builder.send(:book)
166
+ @book = Spreadsheet.open(StringIO.new(builder.serialize(Post.all)))
180
167
  @collection = builder.collection
181
168
  end
182
169
 
@@ -209,6 +196,48 @@ module ActiveAdmin
209
196
  expect(@book.worksheets.first.last_row[0]).to eq('Set In Proc nancy')
210
197
  end
211
198
  end
199
+
200
+ ################################
201
+ context 'Sheet generation with a exceptions.' do
202
+ let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
203
+
204
+ let!(:posts) do
205
+ [Post.new(title: 'bob', body: 'is a swell guy', author: users.first)]
206
+ end
207
+
208
+ let!(:exposts) do
209
+ [Post.new(title: 'sal', body: 'is a swell guy', author: users.first),
210
+ Post.new(title: 'err', body: 'is a swell guy', author: users.first)]
211
+ end
212
+
213
+ let!(:builder) do
214
+ Builder.new(Post, header_style: {}, i18n_scope: %i[xls post]) do
215
+ delete_columns :id, :created_at, :updated_at
216
+ column(:author) do |resource|
217
+ raise 'err' if resource.title == 'err'
218
+ "#{resource.author.first_name} #{resource.author.last_name}"
219
+ end
220
+ end
221
+ end
222
+
223
+ before do
224
+ begin
225
+ @book1 = Spreadsheet.open(StringIO.new(builder.serialize(exposts)))
226
+ rescue StandardError => err
227
+ raise unless err.message == 'err'
228
+ end
229
+ @book2 = Spreadsheet.open(StringIO.new(builder.serialize(posts)))
230
+ @collection = builder.collection
231
+ end
232
+
233
+ it 'does not contain data from other collections with errors' do
234
+ sheet = @book2.worksheets.first
235
+ expect(sheet.dimensions[1]).to eq(2)
236
+ expect(sheet[0, 0]).to eq('Title')
237
+ expect(sheet[1, 0]).to eq(@collection.first.title)
238
+ end
239
+ end
240
+ ################################
212
241
  end
213
242
  end
214
243
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin-xls
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Hambley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-07 00:00:00.000000000 Z
11
+ date: 2019-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -44,8 +44,7 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
47
- description: |2
48
- This gem provides excel/xls downloads for resources in Active Admin.
47
+ description: " This gem provides excel/xls downloads for resources in Active Admin.\n"
49
48
  email: thambley@travelleaders.com
50
49
  executables: []
51
50
  extensions: []
@@ -105,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
104
  version: '0'
106
105
  requirements: []
107
106
  rubyforge_project:
108
- rubygems_version: 2.4.5.2
107
+ rubygems_version: 2.6.14.1
109
108
  signing_key:
110
109
  specification_version: 4
111
110
  summary: Adds excel (xls) downloads for resources within the Active Admin framework.