User#post is now like a future controller, Photo#instantiate no longer saves
This commit is contained in:
parent
1c67211ebc
commit
d5a4de58b3
3 changed files with 29 additions and 31 deletions
|
|
@ -34,15 +34,11 @@ class Photo < Post
|
||||||
before_destroy :ensure_user_picture
|
before_destroy :ensure_user_picture
|
||||||
|
|
||||||
def self.instantiate(params = {})
|
def self.instantiate(params = {})
|
||||||
|
photo = super(params)
|
||||||
image_file = params.delete(:user_file)
|
image_file = params.delete(:user_file)
|
||||||
person = params.delete(:person)
|
|
||||||
|
|
||||||
photo = Photo.new(params)
|
|
||||||
photo.diaspora_handle = params[:diaspora_handle]
|
|
||||||
|
|
||||||
|
photo.album_id = params[:album_id]
|
||||||
photo.image.store! image_file
|
photo.image.store! image_file
|
||||||
photo.person = person
|
|
||||||
photo.save
|
|
||||||
photo
|
photo
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,39 +138,38 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
######## Posting ########
|
######## Posting ########
|
||||||
def post(class_name, options = {})
|
def post(class_name, opts = {})
|
||||||
if class_name == :photo && !options[:album_id].to_s.empty?
|
post = build_post(class_name, opts)
|
||||||
aspect_ids = aspects_with_post(options[:album_id])
|
|
||||||
aspect_ids.map! { |aspect| aspect.id }
|
|
||||||
else
|
|
||||||
aspect_ids = options.delete(:to)
|
|
||||||
end
|
|
||||||
|
|
||||||
aspect_ids = validate_aspect_permissions(aspect_ids)
|
|
||||||
|
|
||||||
post = build_post(class_name, options)
|
|
||||||
|
|
||||||
if post.save
|
if post.save
|
||||||
raise 'MongoMapper failed to catch a failed save' unless post.id
|
raise 'MongoMapper failed to catch a failed save' unless post.id
|
||||||
dispatch_post(post, :to => aspect_ids)
|
dispatch_post(post, :to => opts[:to])
|
||||||
end
|
end
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_post(class_name, options = {})
|
def build_post(class_name, opts = {})
|
||||||
options[:person] = self.person
|
opts[:person] = self.person
|
||||||
options[:diaspora_handle] = self.person.diaspora_handle
|
opts[:diaspora_handle] = self.person.diaspora_handle
|
||||||
|
|
||||||
model_class = class_name.to_s.camelize.constantize
|
model_class = class_name.to_s.camelize.constantize
|
||||||
model_class.instantiate(options)
|
model_class.instantiate(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch_post(post, opts = {})
|
def dispatch_post(post, opts = {})
|
||||||
|
if post.is_a?(Photo) && post.album_id
|
||||||
|
aspect_ids = aspects_with_post(post.album_id)
|
||||||
|
aspect_ids.map! { |aspect| aspect.id }
|
||||||
|
else
|
||||||
|
aspect_ids = opts.delete(:to)
|
||||||
|
end
|
||||||
|
|
||||||
|
aspect_ids = validate_aspect_permissions(aspect_ids)
|
||||||
self.raw_visible_posts << post
|
self.raw_visible_posts << post
|
||||||
self.save
|
self.save
|
||||||
Rails.logger.info("Pushing: #{post.inspect} out to aspects")
|
Rails.logger.info("Pushing: #{post.inspect} out to aspects")
|
||||||
push_to_aspects(post, opts[:to])
|
push_to_aspects(post, aspect_ids)
|
||||||
post.socket_to_uid(id, :aspect_ids => opts[:to]) if post.respond_to?(:socket_to_uid)
|
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
|
||||||
if post.public
|
if post.public
|
||||||
self.services.each do |service|
|
self.services.each do |service|
|
||||||
self.send("post_to_#{service.provider}".to_sym, service, post.message)
|
self.send("post_to_#{service.provider}".to_sym, service, post.message)
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,19 @@ describe Photo do
|
||||||
it 'sets the persons diaspora handle' do
|
it 'sets the persons diaspora handle' do
|
||||||
@photo2.diaspora_handle.should == @user.person.diaspora_handle
|
@photo2.diaspora_handle.should == @user.person.diaspora_handle
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
it 'has a constructor' do
|
it 'has a constructor' do
|
||||||
image = File.open(@fixture_name)
|
image = File.open(@fixture_name)
|
||||||
photo = Photo.instantiate(
|
photo = Photo.instantiate(
|
||||||
:person => @user.person, :album => @album, :user_file => image)
|
:person => @user.person, :album => @album, :user_file => image)
|
||||||
photo.created_at.nil?.should be false
|
photo.created_at.nil?.should be true
|
||||||
photo.image.read.nil?.should be false
|
photo.image.read.nil?.should be false
|
||||||
|
photo.album.should == @album
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it 'should save a photo' do
|
it 'should save a photo' do
|
||||||
@photo.image.store! File.open(@fixture_name)
|
@photo.image.store! File.open(@fixture_name)
|
||||||
@photo.save.should == true
|
@photo.save.should == true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue