From 76b4b55e98caa2781f501fe69c0f49a5766d0384 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 17:39:38 -0700 Subject: [PATCH 1/4] Added spec for remote photo url setting to photos --- app/models/photo.rb | 15 +++++++-------- spec/models/photo_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index c11aae84a..d982f92b9 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -30,7 +30,8 @@ class Photo < Post validates_true_for :album_id, :logic => lambda {self.validate_album_person} before_destroy :ensure_user_picture - + key :remote_photo_path + key :remote_photo_name def validate_album_person album.person_id == person_id @@ -42,15 +43,13 @@ class Photo < Post def remote_photo= remote_path name_start = remote_path.rindex '/' - @remote_photo_path = remote_path.slice(0, name_start ) - @remote_photo_name = remote_path.slice(name_start, remote_path.length) - save - raise "Failed to set path for : #{self.inspect}" if Photo.first(:id => self.id).url.nil? + self.remote_photo_path = remote_path.slice(0, name_start ) + self.remote_photo_name = remote_path.slice(name_start, remote_path.length) end - def url name = nil - if @remote_photo_path - @remote_photo_path + name.to_s + @remote_photo_name + def url(name = nil) + if remote_photo_path + person.url.chop + remote_photo_path + name.to_s + remote_photo_name else image.url name end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index c91fd3c1a..e258ad781 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -108,5 +108,21 @@ describe Photo do xml = @photo.to_xml.to_s xml.include?(@photo.album_id.to_s).should be true end + + it 'should set the remote_photo on marshalling' do + @photo.image.store! File.open(@fixture_name) + + @photo.save + @photo.reload + + xml = @photo.to_diaspora_xml + id = @photo.id + + @photo.destroy + @user.receive xml + + new_photo = Photo.first(:id => id) + new_photo.url.nil?.should be false + end end end From f6892b88d6942a4e0a8a51d5b4310bc63d35d12d Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 17:50:13 -0700 Subject: [PATCH 2/4] photo.remote_photo is relative --- 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 d982f92b9..68a138531 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -38,7 +38,7 @@ class Photo < Post end def remote_photo - url + image.url.nil? ? (remote_photo_path + remote_photo_name) : image.url end def remote_photo= remote_path From 5cae2b21b1857d9c77862e0f0a67065fd048e339 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 18:06:13 -0700 Subject: [PATCH 3/4] RS, IZ fixed the url for the image --- app/models/photo.rb | 5 +++-- app/views/photos/_photo.haml | 2 +- spec/models/photo_spec.rb | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 68a138531..db0caaa82 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -44,12 +44,13 @@ class Photo < Post def remote_photo= remote_path name_start = remote_path.rindex '/' self.remote_photo_path = remote_path.slice(0, name_start ) - self.remote_photo_name = remote_path.slice(name_start, remote_path.length) + self.remote_photo_name = remote_path.slice(name_start + 1, remote_path.length) end def url(name = nil) if remote_photo_path - person.url.chop + remote_photo_path + name.to_s + remote_photo_name + name = name.to_s + "_" if name + person.url.chop + remote_photo_path + "/" + name.to_s + remote_photo_name else image.url name end diff --git a/app/views/photos/_photo.haml b/app/views/photos/_photo.haml index e6734639a..e15dcb0d5 100644 --- a/app/views/photos/_photo.haml +++ b/app/views/photos/_photo.haml @@ -8,7 +8,7 @@ = link_to post.album.name, object_path(post.album) %br - = link_to (image_tag post.image.url(:thumb_large)), object_path(post) + = link_to (image_tag post.url(:thumb_large)), object_path(post) %div.time = link_to(how_long_ago(post), photo_path(post)) diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index e258ad781..b0ad79b83 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -114,6 +114,9 @@ describe Photo do @photo.save @photo.reload + + url = @photo.url + thumb_url = @photo.url :thumb_medium xml = @photo.to_diaspora_xml id = @photo.id @@ -123,6 +126,8 @@ describe Photo do new_photo = Photo.first(:id => id) new_photo.url.nil?.should be false + new_photo.url.include?(url).should be true + new_photo.url(:thumb_medium).include?(thumb_url).should be true end end end From ef15cddf191d897249a33308971dcb57eebbeb3e Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 18 Aug 2010 18:13:17 -0700 Subject: [PATCH 4/4] RS, IZ a slash --- 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 db0caaa82..bedcdc143 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -38,7 +38,7 @@ class Photo < Post end def remote_photo - image.url.nil? ? (remote_photo_path + remote_photo_name) : image.url + image.url.nil? ? (remote_photo_path + '/' + remote_photo_name) : image.url end def remote_photo= remote_path