From b8ae6b44a2bd44abad8b7b04c1c4584a16dba679 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Aug 2010 10:05:34 -0700 Subject: [PATCH 1/5] RS; Image filename is now the Photo model id --- app/uploaders/image_uploader.rb | 6 +++++- spec/models/photo_spec.rb | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb index 7bf9cf2fe..af157647d 100644 --- a/app/uploaders/image_uploader.rb +++ b/app/uploaders/image_uploader.rb @@ -10,7 +10,11 @@ class ImageUploader < CarrierWave::Uploader::Base def extension_white_list %w(jpg jpeg gif png) end - + + def filename + model.id.to_s + File.extname(@filename) + end + version :thumb_small do process :resize_to_fill => [30,30] end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 3646d0626..1b516bfc1 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Photo do before do @user = Factory.create(:user) + @fixture_filename = 'bp.jpeg' @fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' @fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml' @album = Album.create(:name => "foo", :person => @user) @@ -47,6 +48,13 @@ describe Photo do User.first.profile.image_url.should be nil end + it 'should not use the imported filename as the url' do + @photo.image.store! File.open(@fixture_name) + puts @photo.image.url(:thumb_medium) + @photo.image.url.include?(@fixture_filename).should be false + @photo.image.url(:thumb_medium).include?(@fixture_filename).should be false + end + describe 'non-image files' do it 'should not store' do file = File.open(@fail_fixture_name) @@ -64,7 +72,7 @@ describe Photo do @photo.save.should == false end end - + describe 'with encryption' do before do @@ -91,15 +99,13 @@ describe Photo do xml = @photo.to_xml.to_s - xml.include?("bp.jpeg").should be true + xml.include?(@photo.image.url).should be true end it 'should have an album id on serialization' do - @photo.image = File.open(@fixture_name) - + @photo.image.store! File.open(@fixture_name) xml = @photo.to_xml.to_s - puts xml - xml.include?("scaled_full_bp.").should be true + xml.include?(@photo.album_id.to_s).should be true end end end From d503c6541f926ca0d61d631169de79780a5a7599 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Aug 2010 11:13:21 -0700 Subject: [PATCH 2/5] RS; posted statuses now use the websocket to update latest, time is now styled right --- app/helpers/sockets_helper.rb | 2 ++ app/models/status_message.rb | 5 ++--- app/views/js/_websocket_js.haml | 18 +++++++++++++++++- app/views/layouts/application.html.haml | 6 +++--- public/javascripts/publisher.js | 2 -- public/stylesheets/application.css | 5 +++++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 27a86a8e5..f13576306 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -22,6 +22,8 @@ module SocketsHelper if object.is_a? Photo action_hash[:photo_hash] = object.thumb_hash + elsif object.is_a? StatusMessage + action_hash[:status_message_hash] = object.latest_hash end action_hash.to_json diff --git a/app/models/status_message.rb b/app/models/status_message.rb index accad2a8c..fe641bdb2 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -21,9 +21,8 @@ class StatusMessage < Post XML end - def ==(other) - (self.message == other.message) && (self.person.email == other.person.email) + def latest_hash + {:mine? => self.person == User.owner, :text => message} end - end diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 218fe8fd6..768c03cb7 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -20,9 +20,13 @@ }else if (obj['class']=='photos' && onPageForClass('albums')){ processPhotoInAlbum(obj['photo_hash']) + }else if (obj['class']=='status_messages'){ + processStatusMessage(obj['class'], obj['html'], obj['status_message_hash']) }else{ processPost(obj['class'], obj['html']) } + + }; ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { @@ -56,6 +60,18 @@ } } + function processStatusMessage(className, html, messageHash){ + processPost(className, html); + if(messageHash['mine?']){ + updateMyLatestStatus(messageHash); + } + } + + function updateMyLatestStatus(messageHash){ + $("#latest_message").text(messageHash['text']); + $("#latest_message_time").text(' - just now'); + } + function processPhotoInAlbum(photoHash){ if (location.href.indexOf(photoHash['album_id']) == -1){ return ; @@ -65,7 +81,7 @@ \"New \ " $("#thumbnails").append( $(html) ) - $(".image_thumb img").load( function() { + $("#"+ photoHash['id'] + " img").load( function() { $(this).fadeIn("slow"); }); } diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 31388333b..35298bdaf 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -50,9 +50,9 @@ = link_to current_user.real_name, root_path %span#latest_message = my_latest_message - - unless @latest_status_message.nil? - %span{:style => "font-size: small"} - = " - #{how_long_ago @latest_status_message}" + - unless @latest_status_message.nil? + %span{:style => "font-size: small", :id => 'latest_message_time'} + = " - #{how_long_ago @latest_status_message}" %ul.nav %li= link_to "home", root_path diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index 85b16a478..f8e0f369d 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -7,8 +7,6 @@ $("#new_status_message").submit(function() { - var new_status = $('#status_message_message').val() + " - just now"; - $('#latest_message').text( new_status ); }); function selectPublisherTab(evt){ diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index c50e1e9ff..efa4b50fa 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -177,6 +177,11 @@ form { #user_name #latest_message span { size: small; font-style: italic; } + #user_name #latest_message_time{ + font-weight: normal; + color: #999999; + size: small; + font-style: italic; } #user_name ul { display: inline; margin: 0; From 8658276385e5f685bbca670807b231416933630e Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Aug 2010 11:21:04 -0700 Subject: [PATCH 3/5] Post button back, but needs moving, did latest_message css change in sass --- public/stylesheets/application.css | 15 +++++---------- public/stylesheets/sass/application.sass | 8 ++++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index efa4b50fa..e08ee09eb 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -171,17 +171,11 @@ form { line-height: 18px; } #user_name h1 a { color: black; } - #user_name #latest_message { + #user_name span { + size: small; + font-style: italic; font-weight: normal; color: #999999; } - #user_name #latest_message span { - size: small; - font-style: italic; } - #user_name #latest_message_time{ - font-weight: normal; - color: #999999; - size: small; - font-style: italic; } #user_name ul { display: inline; margin: 0; @@ -306,7 +300,8 @@ label { background-color: rgba(10, 81, 109, 0.05); border-bottom: 2px #999999 solid; color: #999999; - padding: 15px 1em; } + padding: 15px 1em; + position: relative; } #new_blog, #new_bookmark { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 3490e3b39..022e5f415 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -205,13 +205,12 @@ form a :color #000 - #latest_message + span + :size small + :font-style italic :font :weight normal :color #999 - span - :size small - :font-style italic ul :display inline @@ -365,6 +364,7 @@ label :bottom 2px #999 solid :color #999 :padding 15px 1em + :position relative #new_blog, #new_bookmark From ac45960bbfd0e07e038a4397788b3faa632b9183 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Aug 2010 12:33:36 -0700 Subject: [PATCH 4/5] Fixed album spec, condensed traversing tests to halve the time of the spec (It was reading the photos from disk on every spec) --- spec/models/album_spec.rb | 54 ++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/spec/models/album_spec.rb b/spec/models/album_spec.rb index 7b3daffd9..b93de4888 100644 --- a/spec/models/album_spec.rb +++ b/spec/models/album_spec.rb @@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Album do before do + @fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg' @user = Factory.create(:user) @album = Album.new(:name => "test collection", :person => @user) end @@ -33,11 +34,13 @@ describe Album do end it 'should remove all photos on album delete' do - 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] + photos = [] + 1.upto 3 do + photo = Photo.new(:person => @user, :album => @album, :created_at => Time.now) + photo.image.store! File.open @fixture_name + photos << photo + end + @album.photos += photos Photo.all.count.should == 3 @album.destroy @@ -46,29 +49,28 @@ describe Album do describe 'traversing' do before do - @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 - - it 'should retrieve the next photo relative to a given photo' do - @album.next_photo(@photo_two).id.should == @photo_three.id - end - - it 'should retrieve the previous photo relative to a given photo' do - @album.prev_photo(@photo_two).id.should == @photo_one.id - end - - describe 'wrapping' do - it 'does next photo of last to first' do - @album.next_photo(@photo_three).id.should == @photo_one.id + @photos = [] + 1.upto 3 do |n| + photo = Photo.new(:person => @user, :album => @album, :created_at => Time.now + n) + photo.image.store! File.open @fixture_name + @photos << photo end + @album.photos += @photos + end + + it 'should traverse the album correctly' do + #should retrieve the next photo relative to a given photo + @album.next_photo(@photos[1]).id.should == @photos[2].id - it 'does previous photo of first to last' do - @album.prev_photo(@photo_one).id.should == @photo_three.id - end + #should retrieve the previous photo relative to a given photo + @album.prev_photo(@photos[1]).id.should == @photos[0].id + + #wrapping + #does next photo of last to first + @album.next_photo(@photos[2]).id.should == @photos[0].id + + #does previous photo of first to last + @album.prev_photo(@photos[0]).id.should == @photos[2].id end end From 8432db34b3f59bf23e4c0c2b5dbe86fb7cdb20ea Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 2 Aug 2010 12:52:13 -0700 Subject: [PATCH 5/5] RS; Fixed profile marshalling spec, now CI should pass! --- spec/lib/diaspora_parser_spec.rb | 33 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index a0906609b..d7075fd77 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -154,25 +154,36 @@ describe Diaspora::DiasporaParser do end it 'should marshal a profile for a person' do + #Create person person = Factory.create(:person) - + id = person.id person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") + person.save + + #Cache profile for checking against marshaled profile old_profile = person.profile - - puts person.profile.inspect + old_profile.first_name.should == 'bob' - xml = Post.build_xml_for(person.profile) - person.profile = nil - person.save + #Build xml for profile, clear profile + xml = Post.build_xml_for(person.profile) + reloaded_person = Person.first(:id => id) + reloaded_person.profile = nil + reloaded_person.save - puts person.profile.inspect - person.profile.should_be nil - store_objects_from_xml xml + #Make sure profile is cleared + Person.first(:id=> id).profile.should be nil + old_profile.first_name.should == 'bob' + + #Marshal profile + store_objects_from_xml xml + #Check that marshaled profile is the same as old profile person = Person.first(:id => person.id) - - person.profile.should == old_profile person.profile.should_not be nil + person.profile.first_name.should == old_profile.first_name + person.profile.last_name.should == old_profile.last_name + person.profile.image_url.should == old_profile.image_url + end end