From acc901e7141a91c06b0dd4187088d3144d674158 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 14 Aug 2019 19:29:33 +0500 Subject: [PATCH] Add interactor SetAccountPerson --- app/interactors/set_account_person.rb | 10 ++++ spec/interactors/set_account_person_spec.rb | 64 +++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 app/interactors/set_account_person.rb create mode 100644 spec/interactors/set_account_person_spec.rb diff --git a/app/interactors/set_account_person.rb b/app/interactors/set_account_person.rb new file mode 100644 index 0000000..3f0b92c --- /dev/null +++ b/app/interactors/set_account_person.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class SetAccountPerson + include Interactor + + def call + context.account.update! person: context.person, + contact_list: context.new_contact_list + end +end diff --git a/spec/interactors/set_account_person_spec.rb b/spec/interactors/set_account_person_spec.rb new file mode 100644 index 0000000..21eafc2 --- /dev/null +++ b/spec/interactors/set_account_person_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe SetAccountPerson do + subject { described_class.call account: account, person: person } + + let(:account) { create :usual_account, contact_list: old_contact_list } + let(:person) { create :initial_person, contact_list: new_contact_list } + + let(:old_contact_list) { create :some_contact_list } + let(:new_contact_list) { create :some_contact_list } + + specify do + expect { subject }.to \ + change(account, :person) + .from(nil) + .to(person) + end + + specify do + expect { subject }.to \ + change(person, :account) + .from(nil) + .to(account) + end + + specify do + expect { subject }.to \ + change(account, :contact_list) + .from(old_contact_list) + .to(new_contact_list) + end + + specify do + expect { subject }.not_to \ + change(person, :contact_list) + .from(new_contact_list) + end + + specify do + expect { subject }.not_to \ + change(old_contact_list.contacts, :count) + .from(old_contact_list.contacts.count) + end + + specify do + expect { subject }.not_to \ + change(new_contact_list.contacts, :count) + .from(new_contact_list.contacts.count) + end + + specify do + expect { subject }.not_to \ + change(old_contact_list.contacts, :to_a) + .from(old_contact_list.contacts.to_a) + end + + specify do + expect { subject }.not_to \ + change(new_contact_list.contacts, :to_a) + .from(new_contact_list.contacts.to_a) + end +end