Skip to content

Store result ids on ImportResult (postgres only) #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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