ruby on rails - Failing specs after migration from CircleCi 2.0 -


i've migrated ruby on rails project run tests on circleci 2.0. after doing specs associated file upload failing. have following models:

slideaudio:

class slideaudio < applicationrecord   # == extensions ============================================================   paperclip.interpolates :locale |attachment, style|     attachment.instance.locale   end    # tell paperclip :slide_id means slideaudio#slide_id   # used in custom path , url below when define attachment   paperclip.interpolates :slide_id |attachment, style|     attachment.instance.slide_id   end    has_attached_file :audio,     path: ":rails_root/public/slides/:attachment/:style/:locale/:slide_id.:extension",     url: "/slides/:attachment/:style/:locale/:slide_id.:extension",     processors: [:audio_compression],     styles: {       original: {},       compressed_96k: {bitrate: '96k'}     }   # == associations ==========================================================   belongs_to :slide, optional: true    # == validations ===========================================================   validates_attachment :audio, content_type: {     content_type: [       'audio/mpeg',       'audio/x-mpeg',       'audio/mp3',       'audio/x-mp3',       'audio/mpeg3',       'audio/x-mpeg3',       'audio/mpg',       'audio/x-mpg',       'audio/x-mpegaudio'     ] }   # == instance methods ======================================================   def has_a_valid_audio_file?     return false if audio.blank?      # before slide_audio saved, audio file lives in tmp directory.     if audio.queued_for_write.present? && audio.queued_for_write[:original].present?       temporary_path = audio.queued_for_write[:original].path       file.exists?(temporary_path)     # after slide saved, paperclip copies file "path".     elsif audio.path.present?       file.exists?(audio.path)     else       false     end   end end 

slide:

class slide < applicationrecord   has_many :audios, class_name: 'slideaudio' end 

and have class responsible compressing audios:

module paperclip   class audiocompression < processor      def make       original_filepath = @file.path        if should_skip_compression?         # if no compression needed, can't return original file (@file)         # because paperclip remove during cleanup.         # that's why need copy , return copy.         new_filepath = original_filepath.gsub('.mp3', '-copy.mp3')         fileutils.cp(original_filepath, new_filepath)         return file.open(new_filepath)       end        desired_bitrate = options[:bitrate] # formatted string ffmpeg accepts, e.g. "96k"        paperclip::audiocompression.compress(original_filepath, desired_bitrate)     end      protected      # method not required paperclip processors - our "helper" method.     # if original bitrate not higher desired bitrate,     # won't try compress, because lose sound quality , wouldn't gain much.     def should_skip_compression?       return true if options[:style] == :original # not compress original files.        desired_bitrate = options[:bitrate] # formatted string ffmpeg accepts, e.g. "96k"       desired_bitrate_in_kbs = desired_bitrate.to_i # number, e.g. 96.        original_audio_info = `ffmpeg -i #{@file.path} 2>&1`        original_bitrate = original_audio_info.match(/(?:bitrate: )(\d+) (?:kb\/s)$/)&.captures&.first       original_bitrate_in_kbs = original_bitrate.to_i        upper_acceptable_bitrate_limit_in_kbs = desired_bitrate_in_kbs + 5        original_bitrate_in_kbs < upper_acceptable_bitrate_limit_in_kbs     end      def self.compress(original_filepath, desired_bitrate)       # file doesn't exist yet, we're constructing filepath.       compressed_filepath = original_filepath.gsub('.mp3', "-#{desired_bitrate}.mp3")        # use ffmpeg compress original file.       # files uploaded temporary location, such /var/folders.       # flags used:       # -y: if there's temporary file @ compressed_filepath, overwrite it.       # -i: specifies input filepath.       # -ab: specifies desired bitrate.       paperclip.run('ffmpeg', "-y -i #{original_filepath} -ab #{desired_bitrate} #{compressed_filepath}")        file.open(compressed_filepath)     end   end end 

my tests this:

require 'rails_helper'  rspec.describe slideaudio, type: :model   describe 'instance methods'     let(:slide) { create(:slide) }     let(:audio) { slide.audios.create(locale: 'en') }      let(:audio_file_128k)       rack::test::uploadedfile.new(         'spec/fixtures/audios/test-128k.mp3',         'audio/mpeg')     end      let(:audio_file_96k)       rack::test::uploadedfile.new(         'spec/fixtures/audios/test-96k.mp3',         'audio/mpeg')     end      describe '#audio='       'should compress mp3 files 96 kbps if bitrate high'         audio.audio = audio_file_128k         audio.save!          audio_info = `ffmpeg -i #{audio.audio.path(:compressed_96k)} 2>&1`         bitrate_info = audio_info[/bitrate:.*$/]          expect(bitrate_info).to eq('bitrate: 96 kb/s')       end     end   end end 

and failing following output:

 failure/error: expect(bitrate_info).to eq('bitrate: 96 kb/s')     expected: "bitrate: 96 kb/s"         got: nil     (compared using ==) 

any idea how can fix this? here circle.yml file:

version: 2 environment:   tz: "/usr/share/zoneinfo/america/los_angeles"  jobs:   build:     parallelism: 2     working_directory: ~/circleci-survey-builder     docker:       - image: circleci/ruby:2.3.4         environment:           pghost: 127.0.0.1           pguser: ubuntu           rails_env: test       - image: circleci/postgres:9.6-alpine         environment:           postgres_user: ubuntu           postgres_db: circle_test           postgres_password: ''     steps:       - checkout        - run:           name: 'install circleci dependencies'           command: bash deploy/circle-dependencies.sh        - type: cache-restore         key: survey-builder-{{ checksum "gemfile.lock" }}        - run:           name: 'install dependencies'           command: bundle install --path vendor/bundle        - type: cache-save         key: survey-builder-{{ checksum "gemfile.lock" }}         paths:           - vendor/bundle        - run:           name: 'create database.yml'           command: mv config/database.ci.yml config/database.yml        - run:           name: set surveybuilder database           command: bundle exec rake db:structure:load --trace        - run:           name: set dashboard database           command: |             createdb dashboard_test             psql -p 5432 dashboard_test < db/dashboard_test.sql        - run:           name: set foreign data wrapper           command: psql -p 5432 circle_test < db/test_foreign_data_wrapper.sql        - run:           name: 'run tests'           command: |             bundle exec rspec --format progress \                               $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings) 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -