rails-excel-reporter 1.0.1 → 1.0.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5f69c565c35735198074df4b774f284045b4193650cf09c5bb098eee945b0a4
|
4
|
+
data.tar.gz: cbb2aa4f5cb6dd736c3c6cb9d8e8ce83f8ae52d9047881b3dbffbe6d6877e56c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '090ada371d1359ef1a8a8642fda57b6d4f12fde107ce6f672982762a4d0db64ae8d2aad3ff31c4ec634efeb59d90b493c37c9abf46ae1d4f70f0f79d9b49128c'
|
7
|
+
data.tar.gz: 55c8659faa49e50f6cbf99fade6dec23c9e5bf4135d62051f5251ece5cfe0acf60685e84b62bf92a66c197333ddac044db932fce969581cbdc188300660d79a9
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rails-excel-reporter (1.0.
|
4
|
+
rails-excel-reporter (1.0.2)
|
5
5
|
activesupport (>= 8.0)
|
6
6
|
caxlsx (~> 4.0)
|
7
7
|
rails (>= 8.0)
|
@@ -125,7 +125,6 @@ GEM
|
|
125
125
|
marcel (1.0.4)
|
126
126
|
method_source (1.1.0)
|
127
127
|
mini_mime (1.1.5)
|
128
|
-
mini_portile2 (2.8.9)
|
129
128
|
minitest (5.25.5)
|
130
129
|
net-imap (0.5.9)
|
131
130
|
date
|
@@ -261,8 +260,6 @@ GEM
|
|
261
260
|
simplecov_json_formatter (~> 0.1)
|
262
261
|
simplecov-html (0.13.1)
|
263
262
|
simplecov_json_formatter (0.1.4)
|
264
|
-
sqlite3 (1.7.3)
|
265
|
-
mini_portile2 (~> 2.8.0)
|
266
263
|
sqlite3 (1.7.3-aarch64-linux)
|
267
264
|
sqlite3 (1.7.3-arm-linux)
|
268
265
|
sqlite3 (1.7.3-arm64-darwin)
|
@@ -65,8 +65,22 @@ module RailsExcelReporter
|
|
65
65
|
|
66
66
|
def stream_large_dataset(&block)
|
67
67
|
if @collection.respond_to? :find_each
|
68
|
-
|
69
|
-
|
68
|
+
stream_with_find_each(&block)
|
69
|
+
else
|
70
|
+
stream_with_fallback(&block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def stream_with_find_each(&block)
|
77
|
+
@collection.find_each(batch_size: 1000, &block)
|
78
|
+
rescue ArgumentError
|
79
|
+
stream_with_fallback(&block)
|
80
|
+
end
|
81
|
+
|
82
|
+
def stream_with_fallback(&block)
|
83
|
+
if @collection.respond_to? :each
|
70
84
|
@collection.each(&block)
|
71
85
|
else
|
72
86
|
@collection.to_a.each(&block)
|
@@ -125,7 +125,6 @@ RSpec.describe RailsExcelReporter::Base do
|
|
125
125
|
|
126
126
|
describe 'custom methods' do
|
127
127
|
it 'calls custom methods for attribute values' do
|
128
|
-
# Since we can't easily inspect binary xlsx data, test the underlying data
|
129
128
|
report_data = report.to_h[:data]
|
130
129
|
expect(report_data[0][1]).to eq('John Doe (Custom)')
|
131
130
|
expect(report_data[1][1]).to eq('Jane Smith (Custom)')
|
@@ -128,7 +128,6 @@ RSpec.describe RailsExcelReporter::Streaming do
|
|
128
128
|
report = report_class.new(small_data, &callback)
|
129
129
|
|
130
130
|
report.with_progress_tracking do |item, progress|
|
131
|
-
# Just iterate
|
132
131
|
end
|
133
132
|
|
134
133
|
expect(callback_calls.size).to eq(10)
|
@@ -136,4 +135,106 @@ RSpec.describe RailsExcelReporter::Streaming do
|
|
136
135
|
expect(callback_calls.last.current).to eq(10)
|
137
136
|
end
|
138
137
|
end
|
138
|
+
|
139
|
+
describe 'handling very large datasets' do
|
140
|
+
let :very_large_data do
|
141
|
+
(1..1500).map { |i| OpenStruct.new id: i, name: "User #{i}", email: "user#{i}@example.com" }
|
142
|
+
end
|
143
|
+
|
144
|
+
let :huge_data do
|
145
|
+
(1..2500).map { |i| OpenStruct.new id: i, name: "User #{i}", email: "user#{i}@example.com" }
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'handles 1500+ records efficiently' do
|
149
|
+
report = report_class.new very_large_data
|
150
|
+
|
151
|
+
expect(report.should_stream?).to be true
|
152
|
+
expect(report.collection_size).to eq(1500)
|
153
|
+
|
154
|
+
yielded_items = []
|
155
|
+
report.stream_data do |item|
|
156
|
+
yielded_items << item
|
157
|
+
end
|
158
|
+
|
159
|
+
expect(yielded_items.size).to eq(1500)
|
160
|
+
expect(yielded_items.first.id).to eq(1)
|
161
|
+
expect(yielded_items.last.id).to eq(1500)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'tracks progress correctly for 1500+ records' do
|
165
|
+
report = report_class.new very_large_data
|
166
|
+
progress_updates = []
|
167
|
+
|
168
|
+
report.with_progress_tracking do |item, progress|
|
169
|
+
progress_updates << progress if progress_updates.size < 5 || progress.current == 1500
|
170
|
+
end
|
171
|
+
|
172
|
+
expect(progress_updates.size).to be >= 5
|
173
|
+
expect(progress_updates.first.current).to eq(1)
|
174
|
+
expect(progress_updates.first.total).to eq(1500)
|
175
|
+
expect(progress_updates.first.percentage).to eq(0.07)
|
176
|
+
expect(progress_updates.last.current).to eq(1500)
|
177
|
+
expect(progress_updates.last.percentage).to eq(100.0)
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'handles extremely large datasets (2500+ records)' do
|
181
|
+
report = report_class.new huge_data
|
182
|
+
|
183
|
+
expect(report.should_stream?).to be true
|
184
|
+
expect(report.collection_size).to eq(2500)
|
185
|
+
|
186
|
+
item_count = 0
|
187
|
+
report.stream_data do |item|
|
188
|
+
item_count += 1
|
189
|
+
end
|
190
|
+
|
191
|
+
expect(item_count).to eq(2500)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'handles ActiveRecord-like collections with large datasets' do
|
195
|
+
mock_collection = double 'Large ActiveRecord Collection'
|
196
|
+
allow(mock_collection).to receive(:respond_to?).with(:count).and_return(true)
|
197
|
+
allow(mock_collection).to receive(:count).and_return(1500)
|
198
|
+
allow(mock_collection).to receive(:respond_to?).with(:find_each).and_return(true)
|
199
|
+
|
200
|
+
yielded_items = []
|
201
|
+
allow(mock_collection).to receive(:find_each).with(batch_size: 1000) do |&block|
|
202
|
+
very_large_data.each(&block)
|
203
|
+
end
|
204
|
+
|
205
|
+
report = report_class.new mock_collection
|
206
|
+
|
207
|
+
report.stream_data do |item|
|
208
|
+
yielded_items << item
|
209
|
+
end
|
210
|
+
|
211
|
+
expect(yielded_items.size).to eq(1500)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'falls back gracefully when find_each fails on large datasets' do
|
215
|
+
mock_collection = double 'Problematic ActiveRecord Collection'
|
216
|
+
allow(mock_collection).to receive(:respond_to?).with(:count).and_return(true)
|
217
|
+
allow(mock_collection).to receive(:count).and_return(1500)
|
218
|
+
allow(mock_collection).to receive(:respond_to?).with(:find_each).and_return(true)
|
219
|
+
allow(mock_collection).to receive(:respond_to?).with(:each).and_return(true)
|
220
|
+
|
221
|
+
allow(mock_collection).to receive(:find_each).with(batch_size: 1000).and_raise(ArgumentError,
|
222
|
+
'Invalid batch_size')
|
223
|
+
|
224
|
+
yielded_items = []
|
225
|
+
allow(mock_collection).to receive(:each) do |&block|
|
226
|
+
very_large_data.each(&block)
|
227
|
+
end
|
228
|
+
|
229
|
+
report = report_class.new mock_collection
|
230
|
+
|
231
|
+
expect {
|
232
|
+
report.stream_data do |item|
|
233
|
+
yielded_items << item
|
234
|
+
end
|
235
|
+
}.not_to raise_error
|
236
|
+
|
237
|
+
expect(yielded_items.size).to eq(1500)
|
238
|
+
end
|
239
|
+
end
|
139
240
|
end
|