From 161e3869582f3e4fd4f44990d5c742010979a573 Mon Sep 17 00:00:00 2001 From: Pascal Zumkehr Date: Mon, 21 Sep 2020 21:31:16 +0200 Subject: [PATCH] Update gems --- .rubocop.yml | 15 ++ Capfile | 2 +- Gemfile | 6 +- Gemfile.lock | 232 ++++++++---------- app/controllers/auth/access_code.rb | 3 +- app/controllers/auth/api_token.rb | 2 +- app/controllers/concerns/sortable.rb | 2 +- app/models/access_code.rb | 2 +- app/models/airtime/show_instance.rb | 2 +- app/models/audio_file.rb | 4 +- app/models/broadcast.rb | 3 +- app/models/profile.rb | 4 +- app/services/audio_processor/ffmpeg.rb | 2 +- app/services/downgrade/downgrader.rb | 2 +- app/services/import/recording/file/iso8601.rb | 6 +- app/services/import/recording/file/mp3_rec.rb | 2 +- config.ru | 2 +- config/deploy.rb | 2 +- config/environments/production.rb | 2 +- config/puma.rb | 8 +- test/integration/downgrade_test.rb | 6 +- test/services/downgrade/downgrader_test.rb | 22 +- 22 files changed, 155 insertions(+), 176 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b31d538..9cf2391 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ require: AllCops: DisplayCopNames: true + NewCops: enable Exclude: # only generated files - db/schema.rb @@ -55,6 +56,9 @@ Style/EmptyMethod: Style/FormatStringToken: Enabled: false +Style/HashAsLastArrayItem: + EnforcedStyle: no_braces + Style/GuardClause: MinBodyLength: 3 @@ -71,10 +75,21 @@ Rails/CreateTableWithTimestamps: Rails/Delegate: Enabled: false +Rails/FilePath: + EnforcedStyle: arguments + # with dry_crud, this is a pattern Rails/LexicallyScopedActionFilter: Enabled: false +# not all +Rails/RakeEnvironment: + Enabled: false + # we should know about update_all constraints. Rails/SkipsModelValidations: Enabled: false + +# disable for tuple uniqueness +Rails/UniqueValidationWithoutIndex: + Enabled: false diff --git a/Capfile b/Capfile index 10a9f4f..5b3c8b9 100644 --- a/Capfile +++ b/Capfile @@ -27,7 +27,7 @@ require 'capistrano/passenger' $LOAD_PATH.push File.expand_path('lib', __dir__) -require_relative 'lib/capistrano/artifact_plugin.rb' +require_relative 'lib/capistrano/artifact_plugin' install_plugin Capistrano::ArtifactPlugin # Load custom tasks from `lib/capistrano/tasks` if you have any defined diff --git a/Gemfile b/Gemfile index 90faa78..dfdec4c 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,11 @@ source 'https://rubygems.org' -gem 'rails', '6.0.1' +gem 'actionpack' +gem 'activemodel' +gem 'activerecord' +gem 'activesupport' +gem 'railties' gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 7adb33a..2ccf35c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,38 +1,21 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.0.1) - actionpack (= 6.0.1) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.0.1) - actionpack (= 6.0.1) - activejob (= 6.0.1) - activerecord (= 6.0.1) - activestorage (= 6.0.1) - activesupport (= 6.0.1) - mail (>= 2.7.1) - actionmailer (6.0.1) - actionpack (= 6.0.1) - actionview (= 6.0.1) - activejob (= 6.0.1) + actionmailer (6.0.3.3) + actionpack (= 6.0.3.3) + actionview (= 6.0.3.3) + activejob (= 6.0.3.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (6.0.1) - actionview (= 6.0.1) - activesupport (= 6.0.1) - rack (~> 2.0) + actionpack (6.0.3.3) + actionview (= 6.0.3.3) + activesupport (= 6.0.3.3) + rack (~> 2.0, >= 2.0.8) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.1) - actionpack (= 6.0.1) - activerecord (= 6.0.1) - activestorage (= 6.0.1) - activesupport (= 6.0.1) - nokogiri (>= 1.8.5) - actionview (6.0.1) - activesupport (= 6.0.1) + actionview (6.0.3.3) + activesupport (= 6.0.3.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -42,129 +25,103 @@ GEM activemodel (>= 4.1, < 6.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (6.0.1) - activesupport (= 6.0.1) + activejob (6.0.3.3) + activesupport (= 6.0.3.3) globalid (>= 0.3.6) - activemodel (6.0.1) - activesupport (= 6.0.1) - activerecord (6.0.1) - activemodel (= 6.0.1) - activesupport (= 6.0.1) - activestorage (6.0.1) - actionpack (= 6.0.1) - activejob (= 6.0.1) - activerecord (= 6.0.1) - marcel (~> 0.3.1) - activesupport (6.0.1) + activemodel (6.0.3.3) + activesupport (= 6.0.3.3) + activerecord (6.0.3.3) + activemodel (= 6.0.3.3) + activesupport (= 6.0.3.3) + activesupport (6.0.3.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - zeitwerk (~> 2.2) + zeitwerk (~> 2.2, >= 2.2.2) airbrussh (1.4.0) sshkit (>= 1.6.1, != 1.7.0) - ast (2.4.0) - bootsnap (1.4.5) + ast (2.4.1) + bootsnap (1.4.8) msgpack (~> 1.0) - builder (3.2.3) - byebug (11.0.1) - capistrano (3.11.2) + builder (3.2.4) + byebug (11.1.3) + capistrano (3.14.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) sshkit (>= 1.9.0) - capistrano-bundler (1.6.0) + capistrano-bundler (2.0.1) capistrano (~> 3.1) capistrano-passenger (0.2.0) capistrano (~> 3.0) - capistrano-rails (1.4.0) + capistrano-rails (1.6.1) capistrano (~> 3.1) - capistrano-bundler (~> 1.1) + capistrano-bundler (>= 1.1, < 3) case_transform (0.2) activesupport choice (0.2.0) - concurrent-ruby (1.1.5) + concurrent-ruby (1.1.7) coveralls (0.8.23) json (>= 1.8, < 3) simplecov (~> 0.16.1) term-ansicolor (~> 1.3) thor (>= 0.19.4, < 2.0) tins (~> 1.6) - crass (1.0.5) + crass (1.0.6) docile (1.3.2) erubi (1.9.0) - exception_notification (4.4.0) + exception_notification (4.4.3) actionmailer (>= 4.0, < 7) activesupport (>= 4.0, < 7) globalid (0.4.2) activesupport (>= 4.2.0) - i18n (1.7.0) + i18n (1.8.5) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.4) - json (2.2.0) + json (2.3.1) jsonapi-renderer (0.2.2) - jwt (2.2.1) - kaminari (1.1.1) + jwt (2.2.2) + kaminari (1.2.1) activesupport (>= 4.1.0) - kaminari-actionview (= 1.1.1) - kaminari-activerecord (= 1.1.1) - kaminari-core (= 1.1.1) - kaminari-actionview (1.1.1) + kaminari-actionview (= 1.2.1) + kaminari-activerecord (= 1.2.1) + kaminari-core (= 1.2.1) + kaminari-actionview (1.2.1) actionview - kaminari-core (= 1.1.1) - kaminari-activerecord (1.1.1) + kaminari-core (= 1.2.1) + kaminari-activerecord (1.2.1) activerecord - kaminari-core (= 1.1.1) - kaminari-core (1.1.1) - loofah (2.3.1) + kaminari-core (= 1.2.1) + kaminari-core (1.2.1) + loofah (2.7.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (0.3.3) - mimemagic (~> 0.3.2) - metaclass (0.0.4) - method_source (0.9.2) - mimemagic (0.3.3) + method_source (1.0.0) mini_mime (1.0.2) mini_portile2 (2.4.0) - minitest (5.13.0) - mocha (1.9.0) - metaclass (~> 0.0.1) - msgpack (1.3.1) - multi_json (1.14.1) - net-scp (2.0.0) - net-ssh (>= 2.6.5, < 6.0.0) - net-ssh (5.2.0) - nio4r (2.5.2) - nokogiri (1.10.5) + minitest (5.14.2) + mocha (1.11.2) + msgpack (1.3.3) + multi_json (1.15.0) + net-scp (3.0.0) + net-ssh (>= 2.6.5, < 7.0.0) + net-ssh (6.1.0) + nio4r (2.5.4) + nokogiri (1.10.10) mini_portile2 (~> 2.4.0) - parallel (1.19.1) - parser (2.7.0.2) - ast (~> 2.4.0) - pg (1.1.4) - puma (4.3.0) + parallel (1.19.2) + parser (2.7.1.4) + ast (~> 2.4.1) + pg (1.2.3) + puma (5.0.0) nio4r (~> 2.0) - rack (2.0.7) - rack-cors (1.0.6) - rack (>= 1.6.0) + rack (2.2.3) + rack-cors (1.1.1) + rack (>= 2.0.0) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.0.1) - actioncable (= 6.0.1) - actionmailbox (= 6.0.1) - actionmailer (= 6.0.1) - actionpack (= 6.0.1) - actiontext (= 6.0.1) - actionview (= 6.0.1) - activejob (= 6.0.1) - activemodel (= 6.0.1) - activerecord (= 6.0.1) - activestorage (= 6.0.1) - activesupport (= 6.0.1) - bundler (>= 1.3.0) - railties (= 6.0.1) - sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -178,66 +135,71 @@ GEM rails-i18n (6.0.0) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 7) - railties (6.0.1) - actionpack (= 6.0.1) - activesupport (= 6.0.1) + railties (6.0.3.3) + actionpack (= 6.0.3.3) + activesupport (= 6.0.3.3) method_source rake (>= 0.8.7) thor (>= 0.20.3, < 2.0) rainbow (3.0.0) rake (13.0.1) - rubocop (0.79.0) - jaro_winkler (~> 1.5.1) + regexp_parser (1.8.0) + rexml (3.2.4) + rubocop (0.91.0) parallel (~> 1.10) - parser (>= 2.7.0.1) + parser (>= 2.7.1.1) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) + rexml + rubocop-ast (>= 0.4.0, < 1.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.5.1) - rubocop (>= 0.71.0) - rubocop-rails (2.3.2) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (0.4.2) + parser (>= 2.7.1.4) + rubocop-performance (1.8.1) + rubocop (>= 0.87.0) + rubocop-ast (>= 0.4.0) + rubocop-rails (2.8.1) + activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.72.0) - ruby-graphviz (1.2.4) + rubocop (>= 0.87.0) + ruby-graphviz (1.2.5) + rexml ruby-progressbar (1.10.1) simplecov (0.16.1) docile (~> 1.1) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.2) - spring (2.1.0) - sprockets (4.0.0) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.2.1) - actionpack (>= 4.0) - activesupport (>= 4.0) - sprockets (>= 3.0.0) - sqlite3 (1.4.1) - sshkit (1.20.0) + spring (2.1.1) + sqlite3 (1.4.2) + sshkit (1.21.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) streamio-ffmpeg (3.0.2) multi_json (~> 1.8) swagger-blocks (3.0.0) + sync (0.5.0) term-ansicolor (1.7.1) tins (~> 1.0) - thor (0.20.3) + thor (1.0.1) thread_safe (0.3.6) - tins (1.22.2) - tzinfo (1.2.5) + tins (1.25.0) + sync + tzinfo (1.2.7) thread_safe (~> 0.1) - unicode-display_width (1.6.0) - websocket-driver (0.7.1) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) - zeitwerk (2.2.1) + unicode-display_width (1.7.0) + zeitwerk (2.4.0) PLATFORMS ruby DEPENDENCIES + actionpack active_model_serializers + activemodel + activerecord + activesupport bootsnap byebug capistrano-passenger @@ -250,9 +212,9 @@ DEPENDENCIES pg puma rack-cors - rails (= 6.0.1) rails-erd rails-i18n + railties rubocop-performance rubocop-rails simplecov diff --git a/app/controllers/auth/access_code.rb b/app/controllers/auth/access_code.rb index e56479d..972143b 100644 --- a/app/controllers/auth/access_code.rb +++ b/app/controllers/auth/access_code.rb @@ -27,8 +27,7 @@ def access_code def access_granted(code) # This may be subject to timing attacks. Please fix if you read this. ::AccessCode.where('expires_at IS NULL OR expires_at >= ?', Time.zone.today) - .where(code: code) - .exists? + .exists?(code: code) end end diff --git a/app/controllers/auth/api_token.rb b/app/controllers/auth/api_token.rb index 99896b6..7e4d022 100644 --- a/app/controllers/auth/api_token.rb +++ b/app/controllers/auth/api_token.rb @@ -13,7 +13,7 @@ def fetch_user private def fetch_user_from_api_token(token) - return if token.blank? || !token.include?('$') + return if token.blank? || token.exclude?('$') id, key = token.split('$') key = key.presence || '[blank]' diff --git a/app/controllers/concerns/sortable.rb b/app/controllers/concerns/sortable.rb index b276e66..6e88245 100644 --- a/app/controllers/concerns/sortable.rb +++ b/app/controllers/concerns/sortable.rb @@ -48,7 +48,7 @@ def default_sort_expression(column) # Split the sort param into sort field and order. def sort_with_order - sort = params[:sort].to_s.gsub(/\A\-/, '') + sort = params[:sort].to_s.gsub(/\A-/, '') [sort, sort == params[:sort] ? 'ASC' : 'DESC'] end diff --git a/app/models/access_code.rb b/app/models/access_code.rb index 7c4239c..afe0901 100644 --- a/app/models/access_code.rb +++ b/app/models/access_code.rb @@ -29,7 +29,7 @@ class AccessCode < ApplicationRecord def generate_code self.code = SecureRandom.base58(CODE_LENGTH) - generate_code if AccessCode.where(code: code).exists? + generate_code if AccessCode.exists?(code: code) end end diff --git a/app/models/airtime/show_instance.rb b/app/models/airtime/show_instance.rb index f1ee5c7..411835e 100644 --- a/app/models/airtime/show_instance.rb +++ b/app/models/airtime/show_instance.rb @@ -56,7 +56,7 @@ class ShowInstance < Base # A little hack to avoid DangerousAttributeErrors with the #record column. # Should not create issues as we do not write to Airtime anyways. def self.dangerous_attribute_method?(name) - !%w[record_changed?].include?(name.to_s) && super + %w[record_changed?].exclude?(name.to_s) && super end end diff --git a/app/models/audio_file.rb b/app/models/audio_file.rb index b6c63a8..d1e01a0 100644 --- a/app/models/audio_file.rb +++ b/app/models/audio_file.rb @@ -88,8 +88,8 @@ def playback_format_name def timestamp_params timestamp = broadcast.started_at - [:year, :month, :day, :hour, :min, :sec].each_with_object({}) do |key, hash| - hash[key] = format('%02d', timestamp.send(key)) + [:year, :month, :day, :hour, :min, :sec].index_with do |key| + format('%02d', timestamp.send(key)) end end diff --git a/app/models/broadcast.rb b/app/models/broadcast.rb index 7044c22..3355525 100644 --- a/app/models/broadcast.rb +++ b/app/models/broadcast.rb @@ -29,9 +29,8 @@ class Broadcast < ApplicationRecord validates :label, :started_at, :finished_at, presence: true validates :started_at, :finished_at, uniqueness: true - after_create :assign_tracks - before_validation :set_show_label_if_empty + after_create :assign_tracks scope :list, -> { order('broadcasts.started_at') } diff --git a/app/models/profile.rb b/app/models/profile.rb index d05b8ac..05ddde3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -25,9 +25,9 @@ class Profile < ApplicationRecord validates :default, inclusion: [true, false] validate :assert_exactly_one_default_profile_exists + before_destroy :protect_default # If we set a new default, remove flag from other instances. after_save :clear_defaults, if: :default - before_destroy :protect_default scope :list, -> { order(Arel.sql('LOWER(name)')) } @@ -46,7 +46,7 @@ def to_s private def clear_defaults - Profile.where('id <> ?', id).update_all(default: false) + Profile.where.not(id: id).update_all(default: false) end def assert_exactly_one_default_profile_exists diff --git a/app/services/audio_processor/ffmpeg.rb b/app/services/audio_processor/ffmpeg.rb index 2a4b192..62efe97 100644 --- a/app/services/audio_processor/ffmpeg.rb +++ b/app/services/audio_processor/ffmpeg.rb @@ -106,7 +106,7 @@ def concat_audio(new_path, list_file) def accurate_duration out = run_command(FFMPEG.ffmpeg_binary, '-i', file, '-acodec', 'copy', '-f', 'null', '-') - segments = out.scan(/\btime=(\d+)\:(\d\d)\:(\d\d(\.\d+)?)\b/) + segments = out.scan(/\btime=(\d+):(\d\d):(\d\d(\.\d+)?)\b/) raise("Could not determine duration for #{file}: #{out}") if segments.blank? number_of_seconds(segments.last) diff --git a/app/services/downgrade/downgrader.rb b/app/services/downgrade/downgrader.rb index 3935dfe..6bbda23 100644 --- a/app/services/downgrade/downgrader.rb +++ b/app/services/downgrade/downgrader.rb @@ -6,7 +6,7 @@ class Downgrader < ActionHandler class << self def actions - DowngradeAction.where('bitrate IS NOT NULL') + DowngradeAction.where.not(bitrate: nil) end end diff --git a/app/services/import/recording/file/iso8601.rb b/app/services/import/recording/file/iso8601.rb index c49e303..b5db24d 100644 --- a/app/services/import/recording/file/iso8601.rb +++ b/app/services/import/recording/file/iso8601.rb @@ -17,8 +17,8 @@ class Iso8601 < Base PERIOD_GLOB = 'PT{*H,*M,*S}' # ISO time period, e.g. PT1H30M FILENAME_GLOB = "#{DATE_GLOB}T#{TIME_GLOB}_{#{DURATION_GLOB},#{PERIOD_GLOB}}" - self.pending_glob = FILENAME_GLOB + '.*' - self.imported_glob = FILENAME_GLOB + IMPORTED_SUFFIX + '.*' + self.pending_glob = "#{FILENAME_GLOB}.*" + self.imported_glob = "#{FILENAME_GLOB}#{IMPORTED_SUFFIX}.*" def started_at @started_at ||= Time.strptime(filename_parts[1], DATE_TIME_FORMAT).in_time_zone @@ -48,7 +48,7 @@ def parse_duration(part) def filename_parts name = basename('.*') - name.match(/^(.+)_(\d{3}|PT[0-9\.\,HMS]+)(#{IMPORTED_SUFFIX})?$/) + name.match(/^(.+)_(\d{3}|PT[0-9.,HMS]+)(#{IMPORTED_SUFFIX})?$/) end end diff --git a/app/services/import/recording/file/mp3_rec.rb b/app/services/import/recording/file/mp3_rec.rb index 35b5f7e..c11da7a 100644 --- a/app/services/import/recording/file/mp3_rec.rb +++ b/app/services/import/recording/file/mp3_rec.rb @@ -25,7 +25,7 @@ def show_name private def filename_parts - basename.match(/\-(\d{8}\-\d{4})\d{2}\-(\d{4})-sec-(.+)\.\w+.mp3$/) + basename.match(/-(\d{8}-\d{4})\d{2}-(\d{4})-sec-(.+)\.\w+.mp3$/) end end diff --git a/config.ru b/config.ru index 61c04e1..667e328 100644 --- a/config.ru +++ b/config.ru @@ -2,5 +2,5 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) +require ::File.expand_path('config/environment', __dir__) run Rails.application diff --git a/config/deploy.rb b/config/deploy.rb index 0aac16d..483bae0 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # config valid only for current version of Capistrano -lock '3.11.2' +lock '3.14.1' set :application, 'raar' set :repo_url, 'git@github.com:radiorabe/raar.git' diff --git a/config/environments/production.rb b/config/environments/production.rb index d72632d..dace001 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -51,7 +51,7 @@ else ActiveSupport::TaggedLogging.new(Syslog::Logger.new('raar-api')) end when 'stdout' - config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) + config.logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout)) when /.+/ file = ENV['RAAR_LOG'].to_s FileUtils.mkdir_p(File.dirname(file)) diff --git a/config/puma.rb b/config/puma.rb index 6d84069..69e2645 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,20 +6,20 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +max_threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch('PORT') { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch('RAILS_ENV') { 'development' } +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch('PIDFILE') { 'tmp/pids/server.pid' } +pidfile ENV.fetch('PIDFILE', 'tmp/pids/server.pid') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together diff --git a/test/integration/downgrade_test.rb b/test/integration/downgrade_test.rb index 53efa03..706fe10 100644 --- a/test/integration/downgrade_test.rb +++ b/test/integration/downgrade_test.rb @@ -28,7 +28,7 @@ class DowngradeTest < ActiveSupport::TestCase assert_equal 1, file_count('2013', '05', '20') info = broadcasts(:info_april) - assert_not info.audio_files.where(bitrate: 320).exists? + assert_not info.audio_files.exists?(bitrate: 320) file = info.audio_files.where(bitrate: 224).first assert file assert_equal 2, file.channels @@ -36,8 +36,8 @@ class DowngradeTest < ActiveSupport::TestCase assert 224, AudioProcessor.new(file.absolute_path).bitrate g9s = broadcasts(:g9s_mai) - assert_not g9s.audio_files.where(bitrate: 192).exists? - assert_not g9s.audio_files.where(bitrate: 320).exists? + assert_not g9s.audio_files.exists?(bitrate: 192) + assert_not g9s.audio_files.exists?(bitrate: 320) assert_equal 1, g9s.audio_files.where(bitrate: 128).count klangbecken = broadcasts(:klangbecken_mai1) diff --git a/test/services/downgrade/downgrader_test.rb b/test/services/downgrade/downgrader_test.rb index 920e343..a388a3c 100644 --- a/test/services/downgrade/downgrader_test.rb +++ b/test/services/downgrade/downgrader_test.rb @@ -29,7 +29,7 @@ class DowngraderTest < ActiveSupport::TestCase assert_no_difference('AudioFile.count') do downgrader.handle(file) end - assert_not AudioFile.where(id: file.id).exists? + assert_not AudioFile.exists?(id: file.id) lower = AudioFile.where(broadcast_id: b1.id, bitrate: 192, channels: 2).first assert_equal path, lower.path end @@ -72,9 +72,9 @@ class DowngraderTest < ActiveSupport::TestCase assert_difference('AudioFile.count', -2) do [file1, file2, file3].shuffle.each { |file| downgrader.handle(file) } end - assert_not AudioFile.where(id: file1.id).exists? - assert_not AudioFile.where(id: file2.id).exists? - assert_not AudioFile.where(id: file3.id).exists? + assert_not AudioFile.exists?(id: file1.id) + assert_not AudioFile.exists?(id: file2.id) + assert_not AudioFile.exists?(id: file3.id) lower = AudioFile.where(broadcast_id: b1.id, bitrate: 192, channels: 2).first assert_equal path, lower.path end @@ -91,7 +91,7 @@ class DowngraderTest < ActiveSupport::TestCase assert_difference('AudioFile.count', -1) do downgrader.handle(higher) end - assert_not AudioFile.where(id: higher.id).exists? + assert_not AudioFile.exists?(id: higher.id) end test 're-creates lower-bitrate file even if database entry exists' do @@ -109,7 +109,7 @@ class DowngraderTest < ActiveSupport::TestCase assert_difference('AudioFile.count', -1) do downgrader.handle(higher) end - assert_not AudioFile.where(id: higher.id).exists? + assert_not AudioFile.exists?(id: higher.id) end test 're-creates database entry if lower-bitrate file exists' do @@ -125,11 +125,11 @@ class DowngraderTest < ActiveSupport::TestCase assert_no_difference('AudioFile.count') do downgrader.handle(higher) end - assert_not AudioFile.where(id: higher.id).exists? - assert AudioFile.where(broadcast_id: lower.broadcast_id, - codec: 'mp3', - bitrate: 192, - channels: 2).exists? + assert_not AudioFile.exists?(id: higher.id) + assert AudioFile.exists?(broadcast_id: lower.broadcast_id, + codec: 'mp3', + bitrate: 192, + channels: 2) end test 'finds files with higher bitrate' do