move #add_contact_to_aspect from User-model to user_methods.rb
This commit is contained in:
parent
6fbfc2bf96
commit
d87756c4b7
4 changed files with 26 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
Loading…
Reference in a new issue