diff --git a/Changelog.md b/Changelog.md index 47f86cccd137355ba52fd98fc07719dbe9a0330e..1565b4abb0efcd1a2bc500f6390a9db64ae30dd8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ * Refactor person related URL generation [#6168](https://github.com/diaspora/diaspora/pull/6168) * Move webfinger and HCard generation out of the core and embed the `diaspora_federation-rails` gem [#6151](https://github.com/diaspora/diaspora/pull/6151/) * Refactor rspec tests to to use `let` instead of before blocks [#6199](https://github.com/diaspora/diaspora/pull/6199) +* Refactor tests for EXIF stripping [#6183](https://github.com/diaspora/diaspora/pull/6183) ## Bug fixes * Precompile facebox images [#6105](https://github.com/diaspora/diaspora/pull/6105) diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 7f4902c0d525c4cb451d6be5cb26db0e6423efc5..49ecf950d292f31cf393753e5c4c9b177281a21d 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -45,8 +45,7 @@ describe Photo, :type => :model do describe '#diaspora_initialize' do before do @image = File.open(@fixture_name) - @photo = Photo.diaspora_initialize( - :author => @user.person, :user_file => @image) + @photo = Photo.diaspora_initialize(author: @user.person, user_file: @image) end it 'sets the persons diaspora handle' do @@ -115,6 +114,7 @@ describe Photo, :type => :model do @photo.unprocessed_image.store! File.open(@fixture_name) end end + it 'should have text' do @photo.text= "cool story, bro" expect(@photo.save).to be true @@ -141,35 +141,41 @@ describe Photo, :type => :model do end context 'with a saved photo containing EXIF data' do - before do - @exif_filename = 'exif.jpg' - @exif_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @exif_filename) - end - it 'should contain EXIF data if user prefer' do - @alice_photo = alice.build_post(:photo, :user_file => File.open(@exif_name), :to => alice.aspects.first.id) + let(:base_path) { File.dirname(__FILE__) } + let(:public_path) { File.join(base_path, "../../public/") } + let(:photo_with_exif) { File.open(File.join(base_path, "..", "fixtures", "exif.jpg")) } - with_carrierwave_processing do - @alice_photo.unprocessed_image.store! File.open(@exif_name) - @alice_photo.save - end + after do + FileUtils.rm_r Dir.glob(File.join(public_path, "uploads/images/*")) + end + + it "should preserve EXIF data in according to user preference" do + image = image_from a_photo_sent_by(alice) - new_filename = File.join(File.dirname(__FILE__), '../../public/', @alice_photo.unprocessed_image.store_dir, @alice_photo.unprocessed_image.filename) - image = MiniMagick::Image.new(new_filename) expect(image.exif.length).not_to eq(0) end - it 'should not contain EXIF data if user prefer' do - @bob_photo = bob.build_post(:photo, :user_file => File.open(@exif_name), :to => @aspect.id) + it "should not preserve EXIF in according to user preference" do + image = image_from a_photo_sent_by(bob) + + expect(image.exif.length).to eq(0) + end + + def a_photo_sent_by(user) + photo = user.build_post(:photo, user_file: photo_with_exif, to: @aspect.id) with_carrierwave_processing do - @bob_photo.unprocessed_image.store! File.open(@exif_name) - @bob_photo.save + photo.unprocessed_image.store! photo_with_exif + photo.save end - new_filename = File.join(File.dirname(__FILE__), '../../public/', @bob_photo.unprocessed_image.store_dir, @bob_photo.unprocessed_image.filename) - image = MiniMagick::Image.new(new_filename) - expect(image.exif.length).to eq(0) + photo + end + + def image_from(photo) + photo_path = File.join(public_path, photo.unprocessed_image.store_dir, photo.unprocessed_image.filename) + MiniMagick::Image.new(photo_path) end end