From 14533f65343eaad20cadc7d70b937c8771f5f7de Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 21 Jul 2010 21:13:31 -0700 Subject: [PATCH 01/10] url not path --- app/models/photo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 8964e0089..08f72a4b2 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -16,7 +16,7 @@ class Photo < Post def remote_photo - User.first.url.chop + image.path + User.first.url.chop + image.url end def remote_photo= remote_path From 8d87f07d3173bc6698f2bf2f3604593474ed44e0 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 22 Jul 2010 09:55:13 -0700 Subject: [PATCH 02/10] using owner instead of first user --- app/models/photo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 08f72a4b2..d2a92c922 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -16,7 +16,7 @@ class Photo < Post def remote_photo - User.first.url.chop + image.url + User.owner.url.chop + image.url end def remote_photo= remote_path From b6ab4db7ccdf11ab9377d5a23cfd59a3e9616dd9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 22 Jul 2010 10:12:25 -0700 Subject: [PATCH 03/10] Trying to get photos working again --- lib/common.rb | 2 +- spec/models/photo_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/common.rb b/lib/common.rb index 8b8e0acf4..2974371d0 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -21,7 +21,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/models/photo_spec.rb b/spec/models/photo_spec.rb index b17192f39..ddf5c2086 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -5,7 +5,7 @@ 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")) + @photo = Photo.new(:person => @user, :album => Album.create(:name => "foo", :person => @user)) end it 'should save a @photo to GridFS' do file = File.open(@fixture_name) @@ -36,7 +36,7 @@ describe Photo do it 'must have an album' do photo = Photo.new(:person => @user) photo.valid?.should be false - photo.album = Album.new(:name => "foo") + photo.album = Album.new(:name => "foo", :person => @user) photo.save Photo.first.album.name.should == 'foo' end @@ -64,7 +64,7 @@ describe Photo do it 'should write the url on serialization' do @photo.image = File.open(@fixture_name) xml = @photo.to_xml.to_s - xml.include?(@photo.image.path).should be true + xml.include?(@photo.image.url).should be true remote_photo = Photo.from_xml xml @photo.destroy remote_photo.image.read.nil?.should be false From 773dbd91aa2e96f09c081b65b0bf0abf9a352635 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 22 Jul 2010 10:21:10 -0700 Subject: [PATCH 04/10] RS IZ one more test passing going to bisect --- app/models/photo.rb | 1 + spec/models/photo_spec.rb | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index d2a92c922..bfb7c912f 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -16,6 +16,7 @@ class Photo < Post def remote_photo + puts image.url User.owner.url.chop + image.url end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index ddf5c2086..439e40ce6 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -15,6 +15,19 @@ describe Photo do fixture_binary = File.open(@fixture_name).read binary.should == fixture_binary end + + it 'must have an album' do + + photo = Photo.new(:person => @user) + file = File.open(@fixture_name) + photo.image = file + 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 +46,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", :person => @user) - photo.save - Photo.first.album.name.should == 'foo' - end + end describe 'with encryption' do From 0cb6e39ff4ef035f72c568b04f8bca3167f2d331 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 22 Jul 2010 10:43:35 -0700 Subject: [PATCH 05/10] comment signing spec was broken --- spec/user_encryption_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 07767e62fe2772ce8ad1294c4c3b6f2c7bdb4471 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 22 Jul 2010 10:49:27 -0700 Subject: [PATCH 06/10] Photo factory --- spec/factories.rb | 4 ++++ 1 file changed, 4 insertions(+) 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) {} From 24f8b33f2f37b680d60ade77d7ea90992b6e94aa Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 22 Jul 2010 11:36:32 -0700 Subject: [PATCH 07/10] Tests all pass! --- app/models/album.rb | 3 +++ app/models/photo.rb | 8 +++++++- app/uploaders/image_uploader.rb | 2 +- spec/models/album_spec.rb | 17 +++++++---------- spec/models/photo_spec.rb | 26 ++++++++++++++------------ 5 files changed, 32 insertions(+), 24 deletions(-) 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 bfb7c912f..5a5dd1c90 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -14,9 +14,15 @@ 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 - puts image.url User.owner.url.chop + image.url end 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/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 439e40ce6..208fd1d96 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -5,8 +5,16 @@ 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", :person => @user)) + @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 @@ -60,9 +68,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 @@ -70,21 +78,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.url).should be true - remote_photo = Photo.from_xml xml - @photo.destroy - remote_photo.image.read.nil?.should be false - 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 From b90cb95c648221429d36069750472a902a4f4bee Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 22 Jul 2010 11:41:00 -0700 Subject: [PATCH 08/10] RS IZ the photo controller now uses instantiate --- app/controllers/photos_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 From 41c358d53cfd1da3273f2e5117d234c07f34c97d Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 22 Jul 2010 11:43:59 -0700 Subject: [PATCH 09/10] Storing in phototest --- spec/models/photo_spec.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 208fd1d96..9ca10e39b 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -16,8 +16,7 @@ describe Photo do 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 @@ -27,8 +26,7 @@ describe Photo do it 'must have an album' do photo = Photo.new(:person => @user) - file = File.open(@fixture_name) - photo.image = file + photo.image = File.open(@fixture_name) photo.save photo.valid?.should be false photo.album = Album.create(:name => "foo", :person => @user) From e75cb8e8d28027c743c99dbe8020979ac472df07 Mon Sep 17 00:00:00 2001 From: ilya Date: Thu, 22 Jul 2010 11:47:44 -0700 Subject: [PATCH 10/10] Changing back to gridfs --- config/initializers/carrierwave.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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