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

Refactoring tests on photo saved with and without EXIF data

closes #6183
parent e7a2775c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Refactor person related URL generation [#6168](https://github.com/diaspora/diaspora/pull/6168) * 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/) * 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 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 ## Bug fixes
* Precompile facebox images [#6105](https://github.com/diaspora/diaspora/pull/6105) * Precompile facebox images [#6105](https://github.com/diaspora/diaspora/pull/6105)
......
...@@ -45,8 +45,7 @@ describe Photo, :type => :model do ...@@ -45,8 +45,7 @@ describe Photo, :type => :model do
describe '#diaspora_initialize' do describe '#diaspora_initialize' do
before do before do
@image = File.open(@fixture_name) @image = File.open(@fixture_name)
@photo = Photo.diaspora_initialize( @photo = Photo.diaspora_initialize(author: @user.person, user_file: @image)
:author => @user.person, :user_file => @image)
end end
it 'sets the persons diaspora handle' do it 'sets the persons diaspora handle' do
...@@ -115,6 +114,7 @@ describe Photo, :type => :model do ...@@ -115,6 +114,7 @@ describe Photo, :type => :model do
@photo.unprocessed_image.store! File.open(@fixture_name) @photo.unprocessed_image.store! File.open(@fixture_name)
end end
end end
it 'should have text' do it 'should have text' do
@photo.text= "cool story, bro" @photo.text= "cool story, bro"
expect(@photo.save).to be true expect(@photo.save).to be true
...@@ -141,35 +141,41 @@ describe Photo, :type => :model do ...@@ -141,35 +141,41 @@ describe Photo, :type => :model do
end end
context 'with a saved photo containing EXIF data' do 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 let(:base_path) { File.dirname(__FILE__) }
@alice_photo = alice.build_post(:photo, :user_file => File.open(@exif_name), :to => alice.aspects.first.id) 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 after do
@alice_photo.unprocessed_image.store! File.open(@exif_name) FileUtils.rm_r Dir.glob(File.join(public_path, "uploads/images/*"))
@alice_photo.save end
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) expect(image.exif.length).not_to eq(0)
end end
it 'should not contain EXIF data if user prefer' do it "should not preserve EXIF in according to user preference" do
@bob_photo = bob.build_post(:photo, :user_file => File.open(@exif_name), :to => @aspect.id) 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 with_carrierwave_processing do
@bob_photo.unprocessed_image.store! File.open(@exif_name) photo.unprocessed_image.store! photo_with_exif
@bob_photo.save photo.save
end end
new_filename = File.join(File.dirname(__FILE__), '../../public/', @bob_photo.unprocessed_image.store_dir, @bob_photo.unprocessed_image.filename) photo
image = MiniMagick::Image.new(new_filename) end
expect(image.exif.length).to eq(0)
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
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment