From 63a0a37171e1d9f920d8bc5d9034377ccef7f453 Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Fri, 20 Apr 2012 12:53:02 -0700 Subject: [PATCH] width and height should now federate --- app/models/photo.rb | 5 +++++ spec/models/photo_spec.rb | 30 +++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index 0f3f4aa92..05d9fb4ce 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -21,6 +21,8 @@ class Photo < ActiveRecord::Base :medium => photo.url(:thumb_medium), :large => photo.url(:scaled_full) } }, :as => :sizes + t.add :height + t.add :width end mount_uploader :processed_image, ProcessedImage @@ -32,6 +34,9 @@ class Photo < ActiveRecord::Base xml_attr :text xml_attr :status_message_guid + xml_attr :height + xml_attr :width + belongs_to :status_message, :foreign_key => :status_message_guid, :primary_key => :guid validates_associated :status_message diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 9bcdd50fb..57605223a 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -4,6 +4,13 @@ require 'spec_helper' +def with_carrierwave_processing(&block) + UnprocessedImage.enable_processing = true + val = yield + UnprocessedImage.enable_processing = false + val +end + describe Photo do before do @user = alice @@ -125,11 +132,9 @@ describe Photo do context 'with a saved photo' do before do - UnprocessedImage.enable_processing = true - - @photo.unprocessed_image.store! File.open(@fixture_name) - UnprocessedImage.enable_processing = false - + with_carrierwave_processing do + @photo.unprocessed_image.store! File.open(@fixture_name) + end end it 'should have text' do @photo.text= "cool story, bro" @@ -146,12 +151,11 @@ describe Photo do end it 'should not use the imported filename as the url' do - @photo.url.include?(@fixture_filename).should be false - @photo.url(:thumb_medium).include?("/" + @fixture_filename).should be false + @photo.url.should_not include @fixture_filename + @photo.url(:thumb_medium).should_not include ("/" + @fixture_filename) end it 'should save the image dimensions' do - @photo.width.should == 40 @photo.height.should == 40 end @@ -169,7 +173,9 @@ describe Photo do describe 'serialization' do before do - Jobs::ProcessPhoto.perform(@saved_photo.id) + @saved_photo = with_carrierwave_processing do + @user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id) + end @xml = @saved_photo.to_xml.to_s end @@ -181,6 +187,12 @@ describe Photo do it 'serializes the diaspora_handle' do @xml.include?(@user.diaspora_handle).should be true end + + it 'serializes the height and width' do + @xml.should include 'height' + @xml.include?('width').should be true + @xml.include?('40').should be true + end end describe 'remote photos' do