Change v_aspect_ids to prune_aspect_ids
This commit is contained in:
parent
75caecc6a3
commit
e63a29be64
3 changed files with 44 additions and 28 deletions
|
|
@ -163,7 +163,7 @@ class User
|
|||
def dispatch_post(post, opts = {})
|
||||
aspect_ids = opts.delete(:to)
|
||||
|
||||
aspect_ids = validate_aspect_permissions(aspect_ids)
|
||||
aspect_ids = prune_aspect_ids(aspect_ids)
|
||||
self.raw_visible_posts << post
|
||||
self.save
|
||||
|
||||
|
|
@ -199,24 +199,14 @@ class User
|
|||
end
|
||||
end
|
||||
|
||||
def validate_aspect_permissions(aspect_ids)
|
||||
if aspect_ids == "all"
|
||||
return aspect_ids
|
||||
def prune_aspect_ids(aspect_ids)
|
||||
return aspect_ids if aspect_ids == "all"
|
||||
if aspect_ids.respond_to? :to_id
|
||||
aspect_ids = [aspect_ids]
|
||||
end
|
||||
|
||||
aspect_ids = [aspect_ids.to_s] unless aspect_ids.is_a? Array
|
||||
|
||||
if aspect_ids.nil? || aspect_ids.empty?
|
||||
raise ArgumentError.new("You must post to someone.")
|
||||
end
|
||||
|
||||
aspect_ids.each do |aspect_id|
|
||||
unless self.aspects.find(aspect_id)
|
||||
raise ArgumentError.new("Cannot post to an aspect you do not own.")
|
||||
end
|
||||
end
|
||||
|
||||
aspect_ids
|
||||
aspect_ids.map!{ |x| x.to_id }
|
||||
aspects.map{ |x| x.id } & aspect_ids
|
||||
end
|
||||
|
||||
def push_to_aspects(post, aspect_ids)
|
||||
|
|
|
|||
|
|
@ -16,23 +16,38 @@ describe User do
|
|||
let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
|
||||
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }
|
||||
|
||||
|
||||
describe '#validate_aspect_permissions' do
|
||||
it 'requires an aspect' do
|
||||
proc {
|
||||
user.validate_aspect_permissions([])
|
||||
}.should raise_error /You must post to someone/
|
||||
describe '#add_to_stream' do
|
||||
before do
|
||||
pending "not implemented"
|
||||
@params = {:message => "hey", :to => [aspect.id, aspect1.id]}
|
||||
@post = user.build_post(:status_message, @params)
|
||||
@post.save
|
||||
@aspect_ids = @params[:to]
|
||||
end
|
||||
|
||||
it "won't let you post to someone else's aspect" do
|
||||
it 'saves post into visible post ids' do
|
||||
proc {
|
||||
user.validate_aspect_permissions(aspect2.id)
|
||||
}.should raise_error /Cannot post to an aspect you do not own./
|
||||
user.add_to_stream(@post, @aspect_ids)
|
||||
}.should change(user.raw_visible_posts, :count).by(1)
|
||||
user.reload.raw_visible_posts.should include @post
|
||||
end
|
||||
|
||||
it 'saves post into each aspect in aspect_ids' do
|
||||
user.add_to_stream(@post, @aspect_ids)
|
||||
aspect.reload.post_ids.should include @post.id
|
||||
aspect1.reload.post_ids.should include @post.id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#prune_aspect_ids' do
|
||||
it 'returns a list of all valid aspects a user can post to' do
|
||||
aspect_ids = Aspect.all.map(&:id)
|
||||
user.prune_aspect_ids(aspect_ids).should =~ [aspect.id, aspect1.id]
|
||||
end
|
||||
it "lets you post to your own aspects" do
|
||||
user.validate_aspect_permissions(aspect.id).should be_true
|
||||
user.validate_aspect_permissions(aspect1.id).should be_true
|
||||
user.prune_aspect_ids(aspect.id).should be_true
|
||||
user.prune_aspect_ids(aspect1.id).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,17 @@ describe User do
|
|||
connect_users(user, aspect, user2, aspect2)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
it 'should stream only one message to the everyone aspect when a multi-aspected contacts posts' do
|
||||
user.add_person_to_aspect(user2.person.id, user.aspects.create(:name => "villains").id)
|
||||
status = user2.post(:status_message, :message => "Users do things", :to => aspect2.id)
|
||||
|
|
|
|||
Loading…
Reference in a new issue