Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/active_admin_import/import_result.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# frozen_string_literal: true
module ActiveAdminImport
class ImportResult
attr_reader :failed, :total
attr_reader :failed, :ids, :total

def initialize
@failed = []
@ids = []
@total = 0
end

def add(result, qty)
@failed += result.failed_instances
@total += qty
@ids += result.ids
@total += qty
end

def imported_qty
Expand Down
10 changes: 9 additions & 1 deletion spec/import_result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@
]
end

let(:ids){ [1,2] }

before do
@result = double \
failed_instances: failed_instances
failed_instances: failed_instances,
ids: ids
end

it 'should work without any failed instances' do
expect(import_result.failed_message).to eq('')
end

it 'should store the supplied ids' do
import_result.add(@result, 4)
expect(import_result.ids).to eq(ids)
end

it 'should work' do
import_result.add(@result, 4)
expect(import_result.failed_message)
Expand Down