diff --git a/Gemfile b/Gemfile index df6623bbf..3a186e27f 100644 --- a/Gemfile +++ b/Gemfile @@ -10,7 +10,7 @@ gem 'pg' gem 'pg_advisory_lock', git: 'https://github.com/didww/pg_advisory_lock.git' gem 'pg_sql_caller', git: 'https://github.com/didww/pg_sql_caller.git' gem 'rack', ' ~> 2.2.6' -gem 'rails', '~> 7.1.0' +gem 'rails', '~> 7.2.0' gem 'responders' # Authentication @@ -52,7 +52,7 @@ gem 'jsonapi-resources', '~> 0.9.12' # Ext gem 'validates_timeliness', '~> 7.0.0.beta1' -# Object oriented authorization for Rails applications +# Object-oriented authorization for Rails applications gem 'pundit' gem 'paper_trail' diff --git a/Gemfile.lock b/Gemfile.lock index 78fa259a5..d8ce6da8c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -96,51 +96,46 @@ GIT GEM remote: https://rubygems.org/ specs: - actioncable (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) + actioncable (7.2.2.1) + actionpack (= 7.2.2.1) + activesupport (= 7.2.2.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.5.1) - actionpack (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activesupport (= 7.1.5.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.2.1) + actionpack (= 7.2.2.1) + activejob (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) + mail (>= 2.8.0) + actionmailer (7.2.2.1) + actionpack (= 7.2.2.1) + actionview (= 7.2.2.1) + activejob (= 7.2.2.1) + activesupport (= 7.2.2.1) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.5.1) - actionview (= 7.1.5.1) - activesupport (= 7.1.5.1) + actionpack (7.2.2.1) + actionview (= 7.2.2.1) + activesupport (= 7.2.2.1) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.5.1) - actionpack (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + useragent (~> 0.16) + actiontext (7.2.2.1) + actionpack (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.5.1) - activesupport (= 7.1.5.1) + actionview (7.2.2.1) + activesupport (= 7.2.2.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -156,8 +151,8 @@ GEM active_admin_sidebar (1.1.0) activeadmin active_admin_theme (1.1.2) - active_record_extended (3.2.1) - activerecord (>= 5.2, < 7.2.0) + active_record_extended (3.3.0) + activerecord (>= 5.2, < 8.0.0) pg (< 3.0) activeadmin (3.2.2) arbre (~> 1.2, >= 1.2.1) @@ -169,8 +164,8 @@ GEM kaminari (>= 1.2.1) railties (>= 6.1) ransack (>= 4.0) - activejob (7.1.5.1) - activesupport (= 7.1.5.1) + activejob (7.2.2.1) + activesupport (= 7.2.2.1) globalid (>= 0.3.6) activeldap (5.1.1) activemodel (> 4.0.0) @@ -178,37 +173,36 @@ GEM gettext gettext_i18n_rails locale - activemodel (7.1.5.1) - activesupport (= 7.1.5.1) + activemodel (7.2.2.1) + activesupport (= 7.2.2.1) activemodel-serializers-xml (1.0.2) activemodel (> 5.x) activesupport (> 5.x) builder (~> 3.1) - activerecord (7.1.5.1) - activemodel (= 7.1.5.1) - activesupport (= 7.1.5.1) + activerecord (7.2.2.1) + activemodel (= 7.2.2.1) + activesupport (= 7.2.2.1) timeout (>= 0.4.0) activerecord-import (2.0.0) activerecord (>= 4.2) - activestorage (7.1.5.1) - actionpack (= 7.1.5.1) - activejob (= 7.1.5.1) - activerecord (= 7.1.5.1) - activesupport (= 7.1.5.1) + activestorage (7.2.2.1) + actionpack (= 7.2.2.1) + activejob (= 7.2.2.1) + activerecord (= 7.2.2.1) + activesupport (= 7.2.2.1) marcel (~> 1.0) - activesupport (7.1.5.1) + activesupport (7.2.2.1) base64 benchmark (>= 0.3) bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) logger (>= 1.4.2) minitest (>= 5.1) - mutex_m securerandom (>= 0.3) - tzinfo (~> 2.0) + tzinfo (~> 2.0, >= 2.0.5) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) annotate (3.2.0) @@ -288,10 +282,10 @@ GEM activerecord (>= 3.2) date (3.3.3) deep_merge (1.2.1) - delayed_job (4.1.11) - activesupport (>= 3.0, < 8.0) - delayed_job_active_record (4.1.7) - activerecord (>= 3.0, < 8.0) + delayed_job (4.1.13) + activesupport (>= 3.0, < 9.0) + delayed_job_active_record (4.1.11) + activerecord (>= 3.0, < 9.0) delayed_job (>= 3.0, < 5) devise (4.9.4) bcrypt (~> 3.0) @@ -451,7 +445,6 @@ GEM msgpack (1.7.2) multi_xml (0.6.0) mustache (1.1.1) - mutex_m (0.3.0) net-imap (0.3.6) date net-protocol @@ -697,20 +690,20 @@ GEM rackup (1.0.1) rack (< 3) webrick - rails (7.1.5.1) - actioncable (= 7.1.5.1) - actionmailbox (= 7.1.5.1) - actionmailer (= 7.1.5.1) - actionpack (= 7.1.5.1) - actiontext (= 7.1.5.1) - actionview (= 7.1.5.1) - activejob (= 7.1.5.1) - activemodel (= 7.1.5.1) - activerecord (= 7.1.5.1) - activestorage (= 7.1.5.1) - activesupport (= 7.1.5.1) + rails (7.2.2.1) + actioncable (= 7.2.2.1) + actionmailbox (= 7.2.2.1) + actionmailer (= 7.2.2.1) + actionpack (= 7.2.2.1) + actiontext (= 7.2.2.1) + actionview (= 7.2.2.1) + activejob (= 7.2.2.1) + activemodel (= 7.2.2.1) + activerecord (= 7.2.2.1) + activestorage (= 7.2.2.1) + activesupport (= 7.2.2.1) bundler (>= 1.15.0) - railties (= 7.1.5.1) + railties (= 7.2.2.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -718,17 +711,17 @@ GEM rails-html-sanitizer (1.6.1) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) - railties (7.1.5.1) - actionpack (= 7.1.5.1) - activesupport (= 7.1.5.1) - irb + railties (7.2.2.1) + actionpack (= 7.2.2.1) + activesupport (= 7.2.2.1) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.0.6) - ransack (4.1.1) + ransack (4.2.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n @@ -858,6 +851,7 @@ GEM unicode (0.4.4.5) unicode-display_width (2.4.2) uniform_notifier (1.16.0) + useragent (0.16.11) validates_timeliness (7.0.0.beta2) activemodel (>= 7.0.0, < 8) timeliness (>= 0.3.10, < 1) @@ -956,7 +950,7 @@ DEPENDENCIES puma_worker_killer pundit rack (~> 2.2.6) - rails (~> 7.1.0) + rails (~> 7.2.0) rails-html-sanitizer (>= 1.6.1) ransack responders @@ -988,4 +982,4 @@ DEPENDENCIES zip-zip BUNDLED WITH - 2.6.2 + 2.6.3 diff --git a/app/models/concerns/routing_tag_ids_scopeable.rb b/app/models/concerns/routing_tag_ids_scopeable.rb index 521128b49..f1ff6a82e 100644 --- a/app/models/concerns/routing_tag_ids_scopeable.rb +++ b/app/models/concerns/routing_tag_ids_scopeable.rb @@ -6,14 +6,14 @@ module RoutingTagIdsScopeable included do scope :routing_tag_ids_covers, lambda { |*routing_tag_ids| type = ActiveModel::Type::Integer.new(limit: 2) - routing_tag_ids = routing_tag_ids.map do |id| + serialized_tag_ids = routing_tag_ids.map do |id| type.serialize(id) rescue ActiveModel::RangeError nil end - return none if routing_tag_ids.any?(&:nil?) + return none if serialized_tag_ids.any?(&:nil?) - where('yeti_ext.tag_compare(routing_tag_ids, ARRAY[?], routing_tag_mode_id)>0', routing_tag_ids) + where('yeti_ext.tag_compare(routing_tag_ids, ARRAY[?]::smallint[], routing_tag_mode_id)>0', serialized_tag_ids) } scope :tagged, lambda { |value| diff --git a/app/models/report/realtime/bad_routing.rb b/app/models/report/realtime/bad_routing.rb index 35f855fef..fafcfc648 100644 --- a/app/models/report/realtime/bad_routing.rb +++ b/app/models/report/realtime/bad_routing.rb @@ -190,7 +190,11 @@ class Report::Realtime::BadRouting < Report::Realtime::Base } scope :time_interval_eq, lambda { |value| - where('time_start >=(now()-\'? seconds\'::interval) and time_start < (now()-\'? seconds\'::interval)', 2 * value.to_i, value.to_i) + where( + "time_start >= (now()-(?::varchar||' seconds')::interval) AND time_start < (now()-(?::varchar||' seconds')::interval)", + 2 * value.to_i, + value.to_i + ) } private diff --git a/app/models/report/realtime/not_authenticated.rb b/app/models/report/realtime/not_authenticated.rb index 625bd7b7a..8ab67eeb0 100644 --- a/app/models/report/realtime/not_authenticated.rb +++ b/app/models/report/realtime/not_authenticated.rb @@ -182,9 +182,9 @@ class Report::Realtime::NotAuthenticated < Report::Realtime::Base scope :time_interval_eq, lambda { |value| where( - "time_start >=(now()-(?||'seconds')::interval) and time_start < (now()-(?||'seconds')::interval)", - (2 * value.to_i).to_s, - value.to_i.to_s + "time_start >=(now()-(?::varchar||' seconds')::interval) and time_start < (now()-(?||'seconds')::interval)", + 2 * value.to_i, + value.to_i ) } diff --git a/app/models/report/realtime/origination_performance.rb b/app/models/report/realtime/origination_performance.rb index 896656063..17442a847 100644 --- a/app/models/report/realtime/origination_performance.rb +++ b/app/models/report/realtime/origination_performance.rb @@ -185,7 +185,11 @@ class Report::Realtime::OriginationPerformance < Report::Realtime::Base } scope :time_interval_eq, lambda { |value| - where('time_start >=(now()-\'? seconds\'::interval) and time_start < (now()-\'? seconds\'::interval)', 2 * value.to_i, value.to_i) + where( + "time_start >= (now()-(?::varchar||' seconds')::interval) AND time_start < (now()-(?::varchar||' seconds')::interval)", + 2 * value.to_i, + value.to_i + ) } private diff --git a/app/models/stats/termination_quality_stat.rb b/app/models/stats/termination_quality_stat.rb index c77300976..a1c736341 100644 --- a/app/models/stats/termination_quality_stat.rb +++ b/app/models/stats/termination_quality_stat.rb @@ -37,7 +37,8 @@ def self.total min(pdd) as min_pdd, #{GuiConfig.termination_stats_window}::integer as w ").where( - "time_start>= now()-'? hours'::interval", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval", + GuiConfig.termination_stats_window ).reorder('').take end @@ -51,7 +52,8 @@ def self.dp_measurement max(pdd) as max_pdd, min(pdd) as min_pdd, dialpeer_id").where( - "time_start>= now()-'? hours'::interval and dialpeer_id is not null", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval and dialpeer_id is not null", + GuiConfig.termination_stats_window ).group('dialpeer_id').having( 'count(id)>=? AND sum(duration)>=?', min_calls_count, min_calls_duration ).reorder('') @@ -67,7 +69,8 @@ def self.gw_measurement max(pdd) as max_pdd, min(pdd) as min_pdd, gateway_id").where( - "time_start>= now()-'? hours'::interval and gateway_id is not null", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval and gateway_id is not null", + GuiConfig.termination_stats_window ).group('gateway_id').having( 'count(id)>=? AND sum(duration)>=?', min_calls_count, min_calls_duration ).reorder('') @@ -83,7 +86,8 @@ def self.dst_measurement max(pdd) as max_pdd, min(pdd) as min_pdd, destination_id").where( - "time_start>= now()-'? hours'::interval and destination_id is not null", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval and destination_id is not null", + GuiConfig.termination_stats_window ).group('destination_id').having( 'count(id)>=? AND sum(duration)>=?', min_calls_count, min_calls_duration ).reorder('') @@ -91,7 +95,8 @@ def self.dst_measurement def self.pdd_distribution select('pdd::integer, count(id)').where( - "time_start>= now()-'? hours'::interval", GuiConfig.termination_stats_window + "time_start>= now()-(?::varchar||' hours')::interval", + GuiConfig.termination_stats_window ).where(success: true).group('pdd::integer').order('pdd::integer ASC') end diff --git a/config/application.rb b/config/application.rb index abbd9ce6a..e7b67186b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,10 +26,10 @@ module Yeti class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.1 + config.load_defaults 7.2 # changing defaults - Rails.application.config.action_view.default_enforce_utf8 = true + config.action_view.default_enforce_utf8 = true # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers @@ -86,11 +86,13 @@ class Application < Rails::Application } config.active_job.queue_adapter = :delayed_job + config.active_job.enqueue_after_transaction_commit = :never # Use RSpec for testing config.generators do |g| g.test_framework :rspec g.integration_tool :rspec + g.system_tests nil end # reimplementing minimal Rails.application.secrets, that was removed in Rails 7.2 diff --git a/config/environments/development.rb b/config/environments/development.rb index 594b6165d..7868c04d1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,7 +16,7 @@ # Show full error reports. config.consider_all_requests_local = true - # Enable server timing + # Enable server timing. config.server_timing = true # Enable/disable caching. By default caching is disabled. @@ -26,9 +26,7 @@ config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.to_i}" - } + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -38,8 +36,12 @@ # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false + config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log @@ -70,9 +72,9 @@ # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true + config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true if ENV['RAILS_LOG_TO_STDOUT'].present? diff --git a/config/environments/production.rb b/config/environments/production.rb index 181f832c9..2c9c32fdf 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -73,6 +73,8 @@ # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "yeti_production" + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. @@ -91,6 +93,9 @@ config.use_schema_cache_dump = true + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [:id] + # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com diff --git a/config/environments/test.rb b/config/environments/test.rb index c966e2cc3..d14faf7dd 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -20,10 +20,7 @@ config.eager_load = ENV['CI'].present? # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.to_i}" - } + config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true @@ -38,6 +35,8 @@ # config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = true + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. @@ -45,6 +44,10 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: 'www.example.com' } + # Print deprecation notices to the stderr. # config.active_support.deprecation = :stderr config.active_support.deprecation = :raise @@ -61,12 +64,14 @@ # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true - # Raise error when a before_action's only/except options reference missing actions + # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true + config.active_job.queue_adapter = :test + config.after_initialize do Bullet.enable = true # Detect unnecessary COUNT queries which could be avoided diff --git a/dev/db_test_prepare.sh b/dev/db_test_prepare.sh new file mode 100755 index 000000000..acc59657b --- /dev/null +++ b/dev/db_test_prepare.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "prepare test databases..." + +RAILS_ENV=test bundle exec rake db:drop \ + db:create \ + db:schema:load \ + db:seed \ + custom_seeds[network_prefixes] diff --git a/dev/migrate_test_db.sh b/dev/migrate_test_db.sh new file mode 100755 index 000000000..87b367cad --- /dev/null +++ b/dev/migrate_test_db.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "prepare and migrate test database..." + +RAILS_ENV=test bundle exec rake db:drop \ + db:create \ + db:schema:load \ + db:migrate \ + db:seed && \ +RAILS_ENV=test bundle exec rake custom_seeds[network_prefixes] && \ +RAILS_ENV=test bundle exec rake annotate_models diff --git a/public/404.html b/public/404.html index 9a48320a5..2be3af26f 100644 --- a/public/404.html +++ b/public/404.html @@ -2,25 +2,66 @@ The page you were looking for doesn't exist (404) - - +
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 000000000..7cf1e168e --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,66 @@ + + + + Your browser is not supported (406) + + + + + + +
+
+

Your browser is not supported.

+

Please upgrade your browser to continue.

+
+
+ + diff --git a/public/422.html b/public/422.html index 83660ab18..c08eac0d1 100644 --- a/public/422.html +++ b/public/422.html @@ -2,25 +2,66 @@ The change you wanted was rejected (422) - - +
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

diff --git a/public/500.html b/public/500.html index f3648a0db..78a030af2 100644 --- a/public/500.html +++ b/public/500.html @@ -2,24 +2,65 @@ We're sorry, but something went wrong (500) - - +
-

We're sorry, but something went wrong.

+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

diff --git a/public/robots.txt b/public/robots.txt index 085187fa5..c19f78ab6 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1 @@ -# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file -# -# To ban all spiders from the entire site uncomment the next two lines: -# User-Agent: * -# Disallow: / +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/delayed_job_spec.rb b/spec/delayed_job_spec.rb index 61ef99462..b178fca45 100644 --- a/spec/delayed_job_spec.rb +++ b/spec/delayed_job_spec.rb @@ -16,7 +16,15 @@ end let!(:regular_delayed_jobs) do - active_jobs = with_real_active_job_adapter do + klasses = [ + Worker::CdrExportJob, + Worker::FillInvoiceJob, + Worker::PingCallbackUrlJob, + Worker::RemoveCdrExportFileJob, + Worker::SendEmailLogJob, + Worker::GenerateReportDataJob + ] + active_jobs = with_dj_queue_adapter(*klasses) do [ Worker::CdrExportJob.perform_later(123), Worker::CdrExportJob.perform_later(124), @@ -36,7 +44,7 @@ Delayed::Job.find(*delayed_job_ids) end let!(:custom_cdr_report_job) do - active_job = with_real_active_job_adapter do + active_job = with_dj_queue_adapter(Worker::CustomCdrReportJob) do Worker::CustomCdrReportJob.perform_later(123) end Delayed::Job.find(active_job.provider_job_id) @@ -69,7 +77,7 @@ context 'when 2 Worker::CustomCdrReportJob are enqueued' do let!(:old_custom_cdr_report_job) do - active_job = with_real_active_job_adapter do + active_job = with_dj_queue_adapter(Worker::CustomCdrReportJob) do Worker::CustomCdrReportJob.perform_later(122) end Delayed::Job.find(active_job.provider_job_id) @@ -103,13 +111,13 @@ context 'when 3 Worker::CustomCdrReportJob are enqueued' do let!(:old_custom_cdr_report_job) do - active_job = with_real_active_job_adapter do + active_job = with_dj_queue_adapter(Worker::CustomCdrReportJob) do Worker::CustomCdrReportJob.perform_later(122) end Delayed::Job.find(active_job.provider_job_id) end let!(:very_old_custom_cdr_report_job) do - active_job = with_real_active_job_adapter do + active_job = with_dj_queue_adapter(Worker::CustomCdrReportJob) do Worker::CustomCdrReportJob.perform_later(121) end Delayed::Job.find(active_job.provider_job_id) @@ -148,7 +156,7 @@ describe 'enqueue' do subject do - active_job = with_real_active_job_adapter do + active_job = with_dj_queue_adapter(active_job_class) do active_job_class.perform_later(*active_job_args) end Delayed::Job.find(active_job.provider_job_id) diff --git a/spec/features/routing/destinations/copy_destination_spec.rb b/spec/features/routing/destinations/copy_destination_spec.rb index 308844479..d7c360f26 100644 --- a/spec/features/routing/destinations/copy_destination_spec.rb +++ b/spec/features/routing/destinations/copy_destination_spec.rb @@ -16,7 +16,7 @@ click_link 'Copy' end - it 'check only not standart attribute **batch_prefix**' do + it 'check only not standard attribute **batch_prefix**' do within 'form#new_routing_destination' do expect(page).to have_field('Prefix', with: attrs[:prefix]) end diff --git a/spec/features/system/background_tasks/index_background_task_spec.rb b/spec/features/system/background_tasks/index_background_task_spec.rb index 202021e14..ae3301f3d 100644 --- a/spec/features/system/background_tasks/index_background_task_spec.rb +++ b/spec/features/system/background_tasks/index_background_task_spec.rb @@ -14,7 +14,16 @@ end let!(:background_tasks) do - active_jobs = with_real_active_job_adapter do + klasses = [ + Worker::CdrExportJob, + Worker::FillInvoiceJob, + Worker::PingCallbackUrlJob, + Worker::RemoveCdrExportFileJob, + Worker::SendEmailLogJob, + Worker::CustomCdrReportJob, + Worker::GenerateReportDataJob + ] + active_jobs = with_dj_queue_adapter(*klasses) do [ Worker::CdrExportJob.perform_later(123), Worker::FillInvoiceJob.perform_later(123), diff --git a/spec/features/system/background_tasks/show_spec.rb b/spec/features/system/background_tasks/show_spec.rb index 209bf098f..58a498267 100644 --- a/spec/features/system/background_tasks/show_spec.rb +++ b/spec/features/system/background_tasks/show_spec.rb @@ -8,7 +8,7 @@ include_context :login_as_admin let!(:background_task) do - active_job = with_real_active_job_adapter do + active_job = with_dj_queue_adapter(active_job_class) do active_job_class.perform_later(*active_job_args) end delayed_job_id = active_job.provider_job_id diff --git a/spec/models/cdr_export_spec.rb b/spec/models/cdr_export_spec.rb index e3aa6734c..419befddd 100644 --- a/spec/models/cdr_export_spec.rb +++ b/spec/models/cdr_export_spec.rb @@ -339,7 +339,7 @@ 'AND', '(1 = ANY(routing_tag_ids))', 'AND', - 'NOT (2 = ANY(routing_tag_ids))', + 'NOT ((2 = ANY(routing_tag_ids)))', 'AND', "(\"cdr\".\"cdr\".\"time_start\" >= '2018-01-01 00:00:00'", 'AND', @@ -381,7 +381,7 @@ 'AND', '(1 = ANY(routing_tag_ids))', 'AND', - 'NOT (2 = ANY(routing_tag_ids))', + 'NOT ((2 = ANY(routing_tag_ids)))', 'AND NOT', '(routing_tag_ids IS NULL OR routing_tag_ids = \'{}\')', 'AND', @@ -426,7 +426,7 @@ 'AND', '(1 = ANY(routing_tag_ids))', 'AND', - 'NOT (2 = ANY(routing_tag_ids))', + 'NOT ((2 = ANY(routing_tag_ids)))', 'AND', '(routing_tag_ids IS NULL OR routing_tag_ids = \'{}\')', 'AND', diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 5ce76fe72..3c529af55 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -45,6 +45,8 @@ driver.render(path, full: true) end +Capybara.raise_server_errors = true + # Capybara::Screenshot.screenshot_and_save_page Capybara::Screenshot.prune_strategy = :keep_last_run diff --git a/spec/support/helpers/custom_rspec_helper.rb b/spec/support/helpers/custom_rspec_helper.rb index 366887b41..b759b2eaa 100644 --- a/spec/support/helpers/custom_rspec_helper.rb +++ b/spec/support/helpers/custom_rspec_helper.rb @@ -7,13 +7,20 @@ def safe_subject nil end - # @see ActiveJob::TestHelper - def with_real_active_job_adapter - queue_adapter_changed_jobs.each(&:disable_test_adapter) + def with_dj_queue_adapter(*job_klasses, &) + with_queue_adapter(:delayed_job, *job_klasses, &) + end + + def with_queue_adapter(adapter_name, *job_klasses) + raise ArgumentError if job_klasses.empty? + begin + job_klasses.each { |klass| klass.queue_adapter = adapter_name } yield ensure - queue_adapter_changed_jobs.each { |klass| klass.enable_test_adapter(queue_adapter_for_test) } + # we need to set the exact same adapter for all job classes, because it will affect matchers + test_adapter = ActiveJob::Base.queue_adapter + job_klasses.each { |klass| klass.queue_adapter = test_adapter } end end end