diff --git a/app/models/aspect.rb b/app/models/aspect.rb index a7b09e5a05131e359b0bd3e2a4b3b936f113f730..fde60c19b98c0c3d166dcd1340bace06c0a8473a 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -6,7 +6,7 @@ class Aspect < ActiveRecord::Base belongs_to :user has_many :aspect_memberships - has_many :members, :through => :aspect_memberships, :class_name => 'Person' + has_many :contacts, :through => :aspect_memberships has_and_belongs_to_many :posts diff --git a/app/models/person.rb b/app/models/person.rb index 62c7e024a77d30ea120a75dc6011851517025b25..a8858692a11069edcf4b03528dcd317147cd09c0 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -24,7 +24,7 @@ class Person < ActiveRecord::Base diaspora_handle.downcase! end - has_many :aspect_memberships + has_many :contacts belongs_to :owner, :class_name => 'User' diff --git a/app/models/user.rb b/app/models/user.rb index afd1cec3b5e0aa0107bb74555d3202a54639cd9f..c1fe9c59d1c6d738503f2fb9362fe7fb70de87ff 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -158,7 +158,7 @@ class User < ActiveRecord::Base if aspect_ids == "all" || aspect_ids == :all self.aspects else - aspect_ids = aspect_ids.to_a + aspect_ids = [aspect_ids] unless aspect_ids.is_a?(Array) aspects.where(:id => aspect_ids) end end @@ -167,8 +167,14 @@ class User < ActiveRecord::Base #send to the aspects target_aspect_ids = aspects.map {|a| a.id} - target_people = Person.includes(:aspect_memberships).where( - "aspect_memberships.aspect_id" => target_aspect_ids, "aspect_memberships.pending" => false) + #target_contacts = Contact.where(:user_id => self.id, "aspect_memberships + target_people = Person.joins( + :contacts => :aspect_memberships + ).where(:aspect_memberships => {:aspect_id => target_aspect_ids}) + #target_people = Person.includes(:contacts).where( + # "contacts.user_id" => self.id, + # "contacts.aspect_memberships.aspect_id" => target_aspect_ids, + # "contacts.pending" => false) post_to_hub(post) if post.respond_to?(:public) && post.public push_to_people(post, target_people) diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 6481b568c523bf46e983b9a11a7f4a23aedd4823..2ccbf1a9842a2cddf54fa696564874e9db07f022 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -25,10 +25,8 @@ describe User do end it 'saves post into visible post ids' do - pp user.raw_visible_posts proc { user.add_to_streams(@post, @aspect_ids) - pp user.raw_visible_posts }.should change(user.raw_visible_posts, :count).by(1) user.reload.raw_visible_posts.should include @post end