From 9cbabe797f5f2ba4fb853c6606824acd2b6f8d43 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sun, 11 Aug 2019 06:17:56 +0500 Subject: [PATCH] Add interactor ImportContact --- app/interactors/import_contact.rb | 36 +++++++++++++++++++++++++ spec/interactors/import_contact_spec.rb | 7 +++++ 2 files changed, 43 insertions(+) create mode 100644 app/interactors/import_contact.rb create mode 100644 spec/interactors/import_contact_spec.rb diff --git a/app/interactors/import_contact.rb b/app/interactors/import_contact.rb new file mode 100644 index 0000000..b8bdaa2 --- /dev/null +++ b/app/interactors/import_contact.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +class ImportContact + include Interactor + + def call + return if person_id.nil? + + person = Person.find person_id + contact_network = ContactNetwork.find contact_network_id + + context.contact = Contact.where(id: contact_id).lock(true).first_or_create!( + contact_list: person.contact_list, + contact_network: contact_network, + value: value, + ) + end + +private + + def contact_id + context.row[0].presence + end + + def person_id + context.row[1].presence + end + + def contact_network_id + context.row[2].presence + end + + def value + context.row[3].presence + end +end diff --git a/spec/interactors/import_contact_spec.rb b/spec/interactors/import_contact_spec.rb new file mode 100644 index 0000000..167acf1 --- /dev/null +++ b/spec/interactors/import_contact_spec.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe ImportContact do + pending "add some examples to (or delete) #{__FILE__}" +end