DG MS; validate_aspect_permissions broken out of post method
This commit is contained in:
parent
c8221cfcae
commit
107c05ef6f
2 changed files with 44 additions and 9 deletions
|
|
@ -106,11 +106,7 @@ class User
|
|||
aspect_ids = options.delete(:to)
|
||||
end
|
||||
|
||||
aspect_ids = [aspect_ids.to_s] if aspect_ids.is_a? BSON::ObjectId
|
||||
|
||||
raise ArgumentError.new("You must post to someone.") if aspect_ids.nil? || aspect_ids.empty?
|
||||
aspect_ids.each{ |aspect_id|
|
||||
raise ArgumentError.new("Cannot post to an aspect you do not own.") unless aspect_id == "all" || self.aspects.find(aspect_id) }
|
||||
aspect_ids = validate_aspect_permissions(aspect_ids)
|
||||
|
||||
post = build_post(class_name, options)
|
||||
|
||||
|
|
@ -120,6 +116,28 @@ class User
|
|||
post
|
||||
end
|
||||
|
||||
def repost( post, options = {} )
|
||||
aspect_ids = validate_aspect_permissions(options[:to])
|
||||
push_to_aspects(post, aspect_ids)
|
||||
post
|
||||
end
|
||||
|
||||
def validate_aspect_permissions(aspect_ids)
|
||||
aspect_ids = [aspect_ids.to_s] if aspect_ids.is_a? BSON::ObjectId
|
||||
|
||||
if aspect_ids.nil? || aspect_ids.empty?
|
||||
raise ArgumentError.new("You must post to someone.")
|
||||
end
|
||||
|
||||
aspect_ids.each do |aspect_id|
|
||||
unless aspect_id == "all" || self.aspects.find(aspect_id)
|
||||
raise ArgumentError.new("Cannot post to an aspect you do not own.")
|
||||
end
|
||||
end
|
||||
|
||||
aspect_ids
|
||||
end
|
||||
|
||||
def build_post( class_name, options = {})
|
||||
options[:person] = self.person
|
||||
model_class = class_name.to_s.camelize.constantize
|
||||
|
|
|
|||
|
|
@ -26,15 +26,22 @@ describe User do
|
|||
end
|
||||
|
||||
context 'posting' do
|
||||
describe '#post' do
|
||||
|
||||
describe '#validate_aspect_permissions' do
|
||||
it 'should not be able to post without a aspect' do
|
||||
proc {user.post(:status_message, :message => "heyheyhey")}.should raise_error /You must post to someone/
|
||||
proc {
|
||||
user.validate_aspect_permissions([])
|
||||
}.should raise_error /You must post to someone/
|
||||
end
|
||||
|
||||
it 'should not be able to post to someone elses aspect' do
|
||||
proc {user.post(:status_message, :message => "heyheyhey", :to => aspect2.id)}.should raise_error /Cannot post to an aspect you do not own./
|
||||
proc {
|
||||
user.validate_aspect_permissions(aspect2.id)
|
||||
}.should raise_error /Cannot post to an aspect you do not own./
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#post' do
|
||||
it 'should put the post in the aspect post array' do
|
||||
post = user.post(:status_message, :message => "hey", :to => aspect.id)
|
||||
aspect.reload
|
||||
|
|
@ -47,6 +54,16 @@ describe User do
|
|||
aspect.posts.should include album
|
||||
end
|
||||
end
|
||||
|
||||
describe '#repost' do
|
||||
let!(:status_message) { user.post(:status_message, :message => "hello", :to => aspect.id) }
|
||||
|
||||
it 'should make the post visible in another aspect' do
|
||||
user.repost( status_message, :to => aspect1.id )
|
||||
aspect1.reload
|
||||
aspect1.posts.count.should be 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'dispatching' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue