Skip to content
Extraits de code Groupes Projets
process_photo_spec.rb 1,81 ko
Newer Older
  • Learn to ignore specific revisions
  • Jonne Haß's avatar
    Jonne Haß a validé
    describe Workers::ProcessPhoto do
    
      before do
       @user = alice
       @aspect = @user.aspects.first
    
    
    Jonne Haß's avatar
    Jonne Haß a validé
       @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'button.png')
    
    
       @saved_photo = @user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id)
       @saved_photo.save
      end
    
      it 'saves the processed image' do
    
        expect(@saved_photo.processed_image.path).to be_nil
    
    Jonne Haß's avatar
    Jonne Haß a validé
        result = Workers::ProcessPhoto.new.perform(@saved_photo.id)
    
        expect(@saved_photo.processed_image.path).not_to be_nil
        expect(result).to be true
    
      end
    
      context 'when trying to process a photo that has already been processed' do
        before do
    
    Jonne Haß's avatar
    Jonne Haß a validé
          Workers::ProcessPhoto.new.perform(@saved_photo.id)
    
          @saved_photo.reload
        end
    
        it 'does not process the photo' do
          processed_image_path = @saved_photo.processed_image.path
    
    
    Jonne Haß's avatar
    Jonne Haß a validé
          result = Workers::ProcessPhoto.new.perform(@saved_photo.id)
    
          expect(@saved_photo.processed_image.path).to eq(processed_image_path)
          expect(result).to be false
    
        end
      end
    
      context 'when a gif is uploaded' do
        before do
    
    Jonne Haß's avatar
    Jonne Haß a validé
          @fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'button.gif')
    
          @saved_gif = @user.build_post(:photo, :user_file => File.open(@fixture_name), :to => @aspect.id)
          @saved_gif.save
        end
    
        it 'does not process the gif' do
    
    Jonne Haß's avatar
    Jonne Haß a validé
          result = Workers::ProcessPhoto.new.perform(@saved_gif.id)
    
          expect(@saved_gif.reload.processed_image.path).to be_nil
          expect(result).to be false
    
    
      it 'does not throw an error if it is called on a remote photo' do
    
    Jonne Haß's avatar
    Jonne Haß a validé
        p = FactoryGirl.create(:remote_photo)
    
    Jonne Haß's avatar
    Jonne Haß a validé
          result = Workers::ProcessPhoto.new.perform(p.id)