Commit e21dad78 authored by JoeBew42's avatar JoeBew42 Committed by Jonne Haß
Browse files

Refactoring tests on photo saved with and without EXIF data

closes #6183
parent e7a2775c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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)
+27 −21
Original line number Diff line number Diff line
@@ -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
    after do
      FileUtils.rm_r Dir.glob(File.join(public_path, "uploads/images/*"))
    end

      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)
    it "should preserve EXIF data in according to user preference" do
      image = image_from a_photo_sent_by(alice)

      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