diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index deaa38deb..5d2eeb868 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -2,12 +2,10 @@ class PhotosController < ApplicationController before_filter :authenticate_user! def create - @photo = Photo.new(params[:photo]) + @photo = Photo.instantiate(params[:photo]) @photo.person = current_user - #@photo.album = Album.first(:id => params[:photo][:album_id]) if @photo.save - #@photo.album.save flash[:notice] = "Successfully uploaded photo." redirect_to @photo.album else diff --git a/app/models/album.rb b/app/models/album.rb index 3f993a9bf..1a0a50de3 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -36,4 +36,7 @@ class Album photos.each{|p| p.destroy} end + def propagate_retraction + Retraction.for(self).notify_people + end end diff --git a/app/models/photo.rb b/app/models/photo.rb index 8964e0089..5a5dd1c90 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -14,9 +14,16 @@ class Photo < Post validates_presence_of :album + def self.instantiate params = {} + image_file = params[:image] + params.delete :image + photo = Photo.new(params) + photo.image.store! image_file + photo + end def remote_photo - User.first.url.chop + image.path + User.owner.url.chop + image.url end def remote_photo= remote_path diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 5009aa9d2..460d96abd 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -10,7 +10,7 @@ class ImageUploader < CarrierWave::Uploader::Base def extension_white_list %w(jpg jpeg gif png) end - + version :thumb_small do process :resize_to_fill => [30,30] end diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index ea3c837d5..8ac46d5d1 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -2,6 +2,6 @@ CarrierWave.configure do |config| #config.grid_fs_database = "#diaspora-#{Rails.env}" #config.grid_fs_host = 'localhost' #config.grid_fs_access_url = "/images" - #config.storage = :grid_fs - config.storage = :file + config.storage = :grid_fs + #config.storage = :file end diff --git a/lib/common.rb b/lib/common.rb index a4bb19717..7fd24eb6e 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -35,7 +35,7 @@ module Diaspora object.person = parse_owner_from_xml post.to_s if object.respond_to? :person objects << object rescue - puts "Not a real type: #{object.to_s}" + Rails.logger.info "Not a real type: #{object.to_s}" end end objects diff --git a/spec/factories.rb b/spec/factories.rb index 1fdd262bf..07baa2488 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -44,4 +44,8 @@ end Factory.define :post do |p| end +Factory.define :photo do |p| + p.image File.open( File.dirname(__FILE__) + '/fixtures/bp.jpeg') + +end Factory.define(:comment) {} diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 58dbb0927..df37e02a1 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -24,16 +24,16 @@ describe Album do it 'should contain photos' do album = Album.create(:name => "test collection") - photo = Photo.new(:person => @user) + photo = Factory.build(:photo, :person => @user) album.photos << photo album.photos.count.should == 1 end it 'should remove all photos on album delete' do - photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now) - photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now-1) - photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now-2) + photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now) + photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-1) + photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now-2) @album.photos += [photo_one, photo_two, photo_three] @@ -45,9 +45,9 @@ describe Album do describe 'traversing' do before do @album = Album.create(:name => "test collection") - @photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now) - @photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now+1) - @photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2) + @photo_one = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now) + @photo_two = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+1) + @photo_three = Factory.create(:photo, :person => @user, :album => @album, :created_at => Time.now+2) @album.photos += [@photo_one, @photo_two, @photo_three] end @@ -76,9 +76,6 @@ describe Album do @album.person = @user @album.save @xml = @album.to_xml.to_s - @photo_one = Photo.create(:person => @user, :album => @album, :created_at => Time.now) - @photo_two = Photo.create(:person => @user, :album => @album, :created_at => Time.now+1) - @photo_three = Photo.create(:person => @user, :album => @album, :created_at => Time.now+2) end it 'should have a person' do @xml.include?(@album.person.id.to_s).should be true diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index b17192f39..9ca10e39b 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -5,16 +5,35 @@ describe Photo do @user = Factory.create(:user) @fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' @fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml' - @photo = Photo.new(:person => @user, :album => Album.create(:name => "foo")) + @album = Album.create(:name => "foo", :person => @user) + @photo = Photo.new(:person => @user, :album => @album) end + + it 'should have a constructor' do + photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name)) + photo.save.should be true + photo.image.read.nil?.should be false + end + it 'should save a @photo to GridFS' do - file = File.open(@fixture_name) - @photo.image = file + @photo.image.store! File.open(@fixture_name) @photo.save.should == true binary = @photo.image.read fixture_binary = File.open(@fixture_name).read binary.should == fixture_binary end + + it 'must have an album' do + + photo = Photo.new(:person => @user) + photo.image = File.open(@fixture_name) + photo.save + photo.valid?.should be false + photo.album = Album.create(:name => "foo", :person => @user) + photo.save + Photo.first.album.name.should == 'foo' + end + describe 'non-image files' do it 'should not store' do file = File.open(@fail_fixture_name) @@ -33,13 +52,7 @@ describe Photo do end - it 'must have an album' do - photo = Photo.new(:person => @user) - photo.valid?.should be false - photo.album = Album.new(:name => "foo") - photo.save - Photo.first.album.name.should == 'foo' - end + end describe 'with encryption' do @@ -53,9 +66,9 @@ describe Photo do end it 'should save a signed @photo to GridFS' do - @photo.image = File.open(@fixture_name) - @photo.save.should == true - @photo.verify_creator_signature.should be true + photo = Photo.instantiate(:person => @user, :album => @album, :image => File.open(@fixture_name)) + photo.save.should == true + photo.verify_creator_signature.should be true end end @@ -63,21 +76,15 @@ describe Photo do describe 'remote photos' do it 'should write the url on serialization' do @photo.image = File.open(@fixture_name) + @photo.image.store! + @photo.save xml = @photo.to_xml.to_s - xml.include?(@photo.image.path).should be true - remote_photo = Photo.from_xml xml - @photo.destroy - remote_photo.image.read.nil?.should be false - + xml.include?(@photo.image.url).should be true end it 'should have an album id on serialization' do @photo.image = File.open(@fixture_name) xml = @photo.to_xml.to_s xml.include?(@photo.album.id.to_s).should be true - remote_photo = Photo.from_xml xml - @photo.destroy - remote_photo.save.should be true - remote_photo.album.nil?.should be false end end end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index e05b31d29..5719a327e 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -156,7 +156,7 @@ describe 'user encryption' do message = Factory.create(:status_message, :person => @user) @user.comment "Yeah, it was great", :on => message message.comments.first.verify_creator_signature.should be true - StatusMessage.first.comments.first.verify_post_creator_signature.should be true + StatusMessage.first(:message => message.message).comments.first.verify_post_creator_signature.should be true end it 'should verify a comment made on a remote post by a different friend' do