From d87756c4b7db3cf4f2ff904367ba842e402e5164 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 16 May 2016 16:02:17 +0200 Subject: [PATCH] move #add_contact_to_aspect from User-model to user_methods.rb --- app/models/user.rb | 6 ------ spec/misc_spec.rb | 22 +++++++++++++++++++++- spec/models/user_spec.rb | 20 -------------------- spec/support/user_methods.rb | 5 +++++ 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index b2d42c3fd..8e8060b6c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -231,12 +231,6 @@ class User < ActiveRecord::Base save end - ######### Aspects ###################### - def add_contact_to_aspect(contact, aspect) - return true if AspectMembership.exists?(:contact_id => contact.id, :aspect_id => aspect.id) - contact.aspect_memberships.create!(:aspect => aspect) - end - ######## Posting ######## def build_post(class_name, opts={}) opts[:author] = self.person diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 332de924e..b33b296c0 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -17,7 +17,7 @@ describe 'making sure the spec runner works' do end end - describe '#connect_users' do + describe "#connect_users" do before do @user1 = User.where(:username => 'alice').first @user2 = User.where(:username => 'eve').first @@ -50,6 +50,26 @@ describe 'making sure the spec runner works' do end end + describe "#add_contact_to_aspect" do + let(:contact) { alice.contact_for(bob.person) } + + it "adds the contact to the aspect" do + new_aspect = alice.aspects.create(name: "two") + + expect { + alice.add_contact_to_aspect(contact, new_aspect) + }.to change(new_aspect.contacts, :count).by(1) + end + + it "does nothing if they are already in the aspect" do + original_aspect = alice.aspects.where(name: "generic").first + + expect { + alice.add_contact_to_aspect(contact, original_aspect) + }.not_to change(contact.aspect_memberships, :count) + end + end + describe '#post' do it 'creates a notification with a mention' do skip("TODO: handle local receive") # TODO diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1ac371994..6667fd55d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -611,26 +611,6 @@ describe User, :type => :model do end end - context "aspect management" do - before do - @contact = alice.contact_for(bob.person) - @original_aspect = alice.aspects.where(:name => "generic").first - @new_aspect = alice.aspects.create(:name => 'two') - end - - describe "#add_contact_to_aspect" do - it 'adds the contact to the aspect' do - expect { - alice.add_contact_to_aspect(@contact, @new_aspect) - }.to change(@new_aspect.contacts, :count).by(1) - end - - it 'returns true if they are already in the aspect' do - expect(alice.add_contact_to_aspect(@contact, @original_aspect)).to be true - end - end - end - context 'likes' do before do alices_aspect = alice.aspects.where(:name => "generic").first diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb index 30d38cbca..dc8869d33 100644 --- a/spec/support/user_methods.rb +++ b/spec/support/user_methods.rb @@ -7,6 +7,11 @@ class User end end + def add_contact_to_aspect(contact, aspect) + return if AspectMembership.exists?(contact_id: contact.id, aspect_id: aspect.id) + contact.aspect_memberships.create!(aspect: aspect) + end + def post(class_name, opts = {}) inlined_jobs do aspects = self.aspects_from_ids(opts[:to])