diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 3e4ac1f11f338e05a6a8966ac511900a9c81c9f8..5f94e07f909eda5bf537beb493a5ebc94cbb4409 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -108,9 +108,9 @@ class AspectsController < ApplicationController @contacts_in_aspect = @aspect.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } c = Contact.arel_table if @contacts_in_aspect.empty? - @contacts_not_in_aspect = current_user.contacts.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } + @contacts_not_in_aspect = current_user.contacts.receiving.includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } else - @contacts_not_in_aspect = current_user.contacts.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } + @contacts_not_in_aspect = current_user.contacts.receiving.where(c[:id].not_in(@contacts_in_aspect.map(&:id))).includes(:person => :profile).all.sort! { |x, y| x.person.name <=> y.person.name } end @contacts = @contacts_in_aspect + @contacts_not_in_aspect diff --git a/app/models/contact.rb b/app/models/contact.rb index 87242f8a20b9a6ea5ee5fe9814d16deefa546bb0..0a59eb215e0d49ba43a12c19b22af9816a391123 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -23,6 +23,10 @@ class Contact < ActiveRecord::Base where(:sharing => true) } + scope :receiving, lambda { + where(:receiving => true) + } + def dispatch_request request = self.generate_request Postzord::Dispatch.new(self.user, request).post diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index f7a32b7ad3f508c069a75e560703569edf997f97..5f89c84c3b57710573455bab262c5dfdb1e84062 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -57,6 +57,17 @@ describe Contact do }.by(1) end end + + describe 'receiving' do + it 'returns contacts with sharing true' do + lambda { + alice.contacts.create!(:receiving => true, :person => Factory(:person)) + alice.contacts.create!(:receiving => false, :person => Factory(:person)) + }.should change{ + Contact.receiving.count + }.by(1) + end + end end describe '#contacts' do