diff --git a/Gemfile b/Gemfile index 8f36640b40..6c1a0a81a1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' ruby '3.2.4' -gem 'rails', '~> 7.1.3.1' +gem 'rails', github: 'rails/rails', branch: '7-2-stable' gem 'pg', '~> 1.3.4' gem 'puma', '~> 6.4.2' gem 'bcrypt', '~> 3.1.7' @@ -50,7 +50,7 @@ gem 'kaminari', '~> 1.2.0' # Postgres/DB extensions gem 'active_record_union' gem 'active_record_distinct_on', '~> 1.6' -gem 'activerecord_where_assoc', '~> 1.1.4' +gem 'activerecord_where_assoc', '~> 1.1.5' gem 'ar_lazy_preload', '~> 2.0' gem 'strong_migrations' @@ -109,7 +109,7 @@ group :development, :test do gem 'byebug', platform: :mri gem 'dotenv-rails' gem 'timecop', '~> 0.9.5' - gem 'bullet', '~> 7.1.6' + # gem 'bullet', '~> 7.1.6' gem 'parallel_tests', '~> 4.2.1' gem 'cuke_modeler', '~> 3.19' # for running `parallel_test --group-by scenarios` gem 'faker', '~> 2.20.0' diff --git a/Gemfile.lock b/Gemfile.lock index 0e98157077..3f7411995c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,49 +1,31 @@ GIT - remote: https://github.com/stripe-ruby-mock/stripe-ruby-mock.git - revision: 6ceea9679bb573cb8bc6830f1bdf670b220a9859 - ref: 6ceea9679bb573cb8bc6830f1bdf670b220a9859 + remote: https://github.com/rails/rails.git + revision: fb4300ce193c338e00c8fe3a8372dc594f6c5de8 + branch: 7-2-stable specs: - stripe-ruby-mock (3.1.0.rc3) - dante (>= 0.2.0) - multi_json (~> 1.0) - stripe (> 5, < 6) - -GEM - remote: https://rubygems.org/ - specs: - aasm (5.0.8) - concurrent-ruby (~> 1.0) - action_policy (0.6.3) - ruby-next-core (>= 0.14.0) - actioncable (7.1.3.2) - actionpack (= 7.1.3.2) - activesupport (= 7.1.3.2) + actioncable (7.2.0.alpha) + actionpack (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.3.2) - actionpack (= 7.1.3.2) - activejob (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.3.2) - actionpack (= 7.1.3.2) - actionview (= 7.1.3.2) - activejob (= 7.1.3.2) - activesupport (= 7.1.3.2) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.0.alpha) + actionpack (= 7.2.0.alpha) + activejob (= 7.2.0.alpha) + activerecord (= 7.2.0.alpha) + activestorage (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) + mail (>= 2.8.0) + actionmailer (7.2.0.alpha) + actionpack (= 7.2.0.alpha) + actionview (= 7.2.0.alpha) + activejob (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.3.2) - actionview (= 7.1.3.2) - activesupport (= 7.1.3.2) + actionpack (7.2.0.alpha) + actionview (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -51,50 +33,90 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.3.2) - actionpack (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) + useragent (~> 0.16) + actiontext (7.2.0.alpha) + actionpack (= 7.2.0.alpha) + activerecord (= 7.2.0.alpha) + activestorage (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.3.2) - activesupport (= 7.1.3.2) + actionview (7.2.0.alpha) + activesupport (= 7.2.0.alpha) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - active_record_distinct_on (1.6.0) - activerecord (>= 6.1, < 7.2) - active_record_union (1.3.0) - activerecord (>= 4.0) - activejob (7.1.3.2) - activesupport (= 7.1.3.2) + activejob (7.2.0.alpha) + activesupport (= 7.2.0.alpha) globalid (>= 0.3.6) - activemodel (7.1.3.2) - activesupport (= 7.1.3.2) - activerecord (7.1.3.2) - activemodel (= 7.1.3.2) - activesupport (= 7.1.3.2) + activemodel (7.2.0.alpha) + activesupport (= 7.2.0.alpha) + activerecord (7.2.0.alpha) + activemodel (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) timeout (>= 0.4.0) - activerecord_where_assoc (1.1.4) - activerecord (>= 4.1.0) - activestorage (7.1.3.2) - actionpack (= 7.1.3.2) - activejob (= 7.1.3.2) - activerecord (= 7.1.3.2) - activesupport (= 7.1.3.2) + activestorage (7.2.0.alpha) + actionpack (= 7.2.0.alpha) + activejob (= 7.2.0.alpha) + activerecord (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) marcel (~> 1.0) - activesupport (7.1.3.2) + activesupport (7.2.0.alpha) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) - minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + minitest (>= 5.1, < 5.22.0) + tzinfo (~> 2.0, >= 2.0.5) + rails (7.2.0.alpha) + actioncable (= 7.2.0.alpha) + actionmailbox (= 7.2.0.alpha) + actionmailer (= 7.2.0.alpha) + actionpack (= 7.2.0.alpha) + actiontext (= 7.2.0.alpha) + actionview (= 7.2.0.alpha) + activejob (= 7.2.0.alpha) + activemodel (= 7.2.0.alpha) + activerecord (= 7.2.0.alpha) + activestorage (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) + bundler (>= 1.15.0) + railties (= 7.2.0.alpha) + railties (7.2.0.alpha) + actionpack (= 7.2.0.alpha) + activesupport (= 7.2.0.alpha) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + +GIT + remote: https://github.com/stripe-ruby-mock/stripe-ruby-mock.git + revision: 6ceea9679bb573cb8bc6830f1bdf670b220a9859 + ref: 6ceea9679bb573cb8bc6830f1bdf670b220a9859 + specs: + stripe-ruby-mock (3.1.0.rc3) + dante (>= 0.2.0) + multi_json (~> 1.0) + stripe (> 5, < 6) + +GEM + remote: https://rubygems.org/ + specs: + aasm (5.0.8) + concurrent-ruby (~> 1.0) + action_policy (0.6.3) + ruby-next-core (>= 0.14.0) + active_record_distinct_on (1.6.0) + activerecord (>= 6.1, < 7.2) + active_record_union (1.3.0) + activerecord (>= 4.0) + activerecord_where_assoc (1.1.5) + activerecord (>= 4.1.0) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) anbt-sql-formatter (0.1.0) @@ -118,13 +140,10 @@ GEM barnes (0.0.9) multi_json (~> 1) statsd-ruby (~> 1.1) - base64 (0.1.1) + base64 (0.2.0) bcrypt (3.1.17) - bigdecimal (3.1.4) + bigdecimal (3.1.8) builder (3.2.4) - bullet (7.1.6) - activesupport (>= 3.0.0) - uniform_notifier (~> 1.11) byebug (11.1.3) capybara (3.36.0) addressable @@ -135,7 +154,7 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) connection_pool (2.4.1) crack (0.4.5) rexml @@ -191,14 +210,13 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - date (3.3.3) + date (3.3.4) diff-lcs (1.5.0) dotenv (2.7.6) dotenv-rails (2.7.6) dotenv (= 2.7.6) railties (>= 3.2) - drb (2.1.1) - ruby2_keywords + drb (2.2.1) ed25519 (1.3.0) elif (0.1.0) erubi (1.12.0) @@ -240,12 +258,12 @@ GEM httparty (0.21.0) mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.8.1) - rdoc - reline (>= 0.3.8) + io-console (0.7.2) + irb (1.13.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) jmespath (1.6.1) json (2.3.1) jsonapi-deserializable (0.2.0) @@ -287,7 +305,7 @@ GEM activesupport (>= 4) railties (>= 4) request_store (~> 1.0) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -302,22 +320,21 @@ GEM mime-types-data (3.2022.0105) mini_mime (1.1.5) mini_portile2 (2.8.6) - minitest (5.20.0) + minitest (5.21.2) msgpack (1.7.2) multi_json (1.15.0) multi_test (0.1.2) multi_xml (0.6.0) - mutex_m (0.1.2) - net-imap (0.4.0) + net-imap (0.4.11) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.5.0) net-protocol - nio4r (2.5.9) + nio4r (2.7.3) nokogiri (1.16.5) mini_portile2 (~> 2.8.2) racc (~> 1.4) @@ -334,19 +351,19 @@ GEM premailer-rails (1.11.1) actionmailer (>= 3) premailer (~> 1.7, >= 1.7.9) - psych (5.1.0) + psych (5.1.2) stringio public_suffix (4.0.6) puma (6.4.2) nio4r (~> 2.0) raabro (1.4.0) - racc (1.7.1) + racc (1.7.3) rack (2.2.8.1) rack-attack (6.6.0) rack (>= 1.0, < 3) rack-cors (1.1.1) rack (>= 2.0.0) - rack-session (1.0.1) + rack-session (1.0.2) rack (< 3) rack-test (2.1.0) rack (>= 1.3) @@ -354,20 +371,6 @@ GEM rackup (1.0.0) rack (< 3) webrick - rails (7.1.3.2) - actioncable (= 7.1.3.2) - actionmailbox (= 7.1.3.2) - actionmailer (= 7.1.3.2) - actionpack (= 7.1.3.2) - actiontext (= 7.1.3.2) - actionview (= 7.1.3.2) - activejob (= 7.1.3.2) - activemodel (= 7.1.3.2) - activerecord (= 7.1.3.2) - activestorage (= 7.1.3.2) - activesupport (= 7.1.3.2) - bundler (>= 1.15.0) - railties (= 7.1.3.2) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest @@ -378,25 +381,17 @@ GEM rails-pattern_matching (0.2.0) activemodel activerecord - railties (7.1.3.2) - actionpack (= 7.1.3.2) - activesupport (= 7.1.3.2) - irb - rackup (>= 1.0.0) - rake (>= 12.2) - thor (~> 1.0, >= 1.2.2) - zeitwerk (~> 2.6) - rake (13.0.6) + rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.5.0) + rdoc (6.6.3.1) psych (>= 4.0.0) redis (4.7.1) redis-client (0.22.1) connection_pool regexp_parser (2.2.1) - reline (0.3.9) + reline (0.5.7) io-console (~> 0.5) request_migrations (1.1.1) rails (>= 6.0) @@ -423,7 +418,6 @@ GEM rspec-support (~> 3.12) rspec-support (3.12.0) ruby-next-core (0.15.2) - ruby2_keywords (0.0.5) ruby_http_client (3.5.5) ruby_parser (3.19.0) sexp_processor (~> 4.16) @@ -477,35 +471,35 @@ GEM sprockets (>= 3.0.0) stackprof (0.2.26) statsd-ruby (1.5.0) - stringio (3.0.8) + stringio (3.1.0) stripe (5.48.0) strong_migrations (1.8.0) activerecord (>= 5.2) sys-uname (1.2.2) ffi (~> 1.1) temple (0.8.2) - thor (1.2.2) + thor (1.3.1) tilt (2.0.10) timecop (0.9.5) - timeout (0.4.0) + timeout (0.4.1) tracer (0.1.1) typed_params (1.2.5) rails (>= 6.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - uniform_notifier (1.16.0) uri (0.12.2) + useragent (0.16.10) webmock (3.14.0) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) - webrick (1.7.0) + webrick (1.8.1) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.12) + zeitwerk (2.6.14) PLATFORMS ruby @@ -515,13 +509,12 @@ DEPENDENCIES action_policy (~> 0.6.3) active_record_distinct_on (~> 1.6) active_record_union - activerecord_where_assoc (~> 1.1.4) + activerecord_where_assoc (~> 1.1.5) anbt-sql-formatter ar_lazy_preload (~> 2.0) aws-sdk-s3 (~> 1) barnes bcrypt (~> 3.1.7) - bullet (~> 7.1.6) byebug cucumber-rails (~> 2.5) cuke_modeler (~> 3.19) @@ -554,7 +547,7 @@ DEPENDENCIES rack-attack (~> 6.6) rack-cors rack-timeout - rails (~> 7.1.3.1) + rails! rails-pattern_matching redis (~> 4.7.1) request_migrations (~> 1.1) diff --git a/app/controllers/api/v1/release_engines/pypi/simple_controller.rb b/app/controllers/api/v1/release_engines/pypi/simple_controller.rb index 9fb34399de..fc29e27920 100644 --- a/app/controllers/api/v1/release_engines/pypi/simple_controller.rb +++ b/app/controllers/api/v1/release_engines/pypi/simple_controller.rb @@ -42,7 +42,7 @@ def show attr_reader :package def set_package - Current.resource = @package = FindByAliasService.call( + @package = Current.resource = FindByAliasService.call( authorized_scope(current_account.release_packages.pypi), id: params[:package], aliases: :key, diff --git a/app/controllers/api/v1/release_engines/tauri/upgrades_controller.rb b/app/controllers/api/v1/release_engines/tauri/upgrades_controller.rb index fee1e00cd0..ea78d78e93 100644 --- a/app/controllers/api/v1/release_engines/tauri/upgrades_controller.rb +++ b/app/controllers/api/v1/release_engines/tauri/upgrades_controller.rb @@ -71,7 +71,7 @@ def show attr_reader :package def set_package - Current.resource = @package = FindByAliasService.call( + @package = Current.resource = FindByAliasService.call( authorized_scope(current_account.release_packages.tauri), id: params[:package], aliases: :key, diff --git a/app/controllers/api/v1/release_engines_controller.rb b/app/controllers/api/v1/release_engines_controller.rb index 3f4960aaf2..b80f0c1bae 100644 --- a/app/controllers/api/v1/release_engines_controller.rb +++ b/app/controllers/api/v1/release_engines_controller.rb @@ -27,7 +27,7 @@ def show def set_engine scoped_engines = authorized_scope(current_account.release_engines) - Current.resource = @engine = FindByAliasService.call( + @engine = Current.resource = FindByAliasService.call( scoped_engines, id: params[:id], aliases: :key, diff --git a/app/controllers/api/v1/release_packages_controller.rb b/app/controllers/api/v1/release_packages_controller.rb index c7ab49af28..24287e1823 100644 --- a/app/controllers/api/v1/release_packages_controller.rb +++ b/app/controllers/api/v1/release_packages_controller.rb @@ -129,7 +129,7 @@ def destroy def set_package scoped_packages = authorized_scope(current_account.release_packages) - Current.resource = @package = FindByAliasService.call( + @package = Current.resource = FindByAliasService.call( scoped_packages, id: params[:id], aliases: :key, diff --git a/app/models/concerns/accountable.rb b/app/models/concerns/accountable.rb index eb98698209..92ecad9819 100644 --- a/app/models/concerns/accountable.rb +++ b/app/models/concerns/accountable.rb @@ -29,6 +29,10 @@ def has_account(default: nil, **kwargs) # Hook into both initialization and validation to ensure the current account # is applied to new records (given no :account was provided). + # + # We're not using belongs_to(default:) because it only adds a before_validation + # callback, but we want to also do it after_initialize because new children + # may rely on the account being set on their parent. after_initialize -> { self.account_id ||= Current.account&.id }, unless: -> { account_id_attribute_assigned? || account_attribute_assigned? }, if: -> { new_record? && account_id.nil? } diff --git a/app/models/concerns/environmental.rb b/app/models/concerns/environmental.rb index 2c872a9ade..5d9388384b 100644 --- a/app/models/concerns/environmental.rb +++ b/app/models/concerns/environmental.rb @@ -61,15 +61,18 @@ module Environmental # # Use :default to automatically configure a default environment for the model. # Accepts a proc that resolves into an Environment or environment ID. - def has_environment(default: nil) - belongs_to :environment, - optional: true + def has_environment(default: nil, **kwargs) + belongs_to :environment, optional: true, **kwargs tracks_attributes :environment_id, :environment # Hook into both initialization and validation to ensure the current environment # is applied to new records (given no :environment was provided). + # + # We're not using belongs_to(default:) because it only adds a before_validation + # callback, but we want to also do it after_initialize because new children + # may rely on the environment being set on their parent. after_initialize -> { self.environment_id ||= Current.environment&.id }, unless: -> { environment_id_attribute_assigned? || environment_attribute_assigned? }, if: -> { new_record? && environment.nil? } diff --git a/app/models/concerns/roleable.rb b/app/models/concerns/roleable.rb index a0300424b6..9fee24e904 100644 --- a/app/models/concerns/roleable.rb +++ b/app/models/concerns/roleable.rb @@ -97,6 +97,9 @@ def define_roleable_association_and_delgate accepts_nested_attributes_for :role, update_only: true tracks_nested_attributes_for :role + validates :role, + presence: { message: 'must exist' } + delegate :permissions, :permission_ids, :role_permissions, :role_permissions_attributes_assigned?, :role_permissions_attributes, allow_nil: true, diff --git a/app/models/current.rb b/app/models/current.rb index 1d67b7d5c8..3a8ccb9381 100644 --- a/app/models/current.rb +++ b/app/models/current.rb @@ -19,4 +19,10 @@ def account=(account) self.token = nil self.resource = nil end + + def account_id = account&.id + def environment_id = environment&.id + def bearer_id = bearer&.id + def token_id = token&.id + def resource_id = resource&.id end diff --git a/app/models/environment.rb b/app/models/environment.rb index 4a12429797..69433851d1 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -19,7 +19,7 @@ def owned = where(bearer: proxy_association.owner) # TODO(ezekg) Should deleting queue up a cancelable background job? has_many :webhook_endpoints, dependent: :destroy_async - has_many :webhook_event, dependent: :destroy_async + has_many :webhook_events, dependent: :destroy_async has_many :entitlements, dependent: :destroy_async has_many :groups, dependent: :destroy_async has_many :products, dependent: :destroy_async diff --git a/config/application.rb b/config/application.rb index 2fd824c814..f3e54db5c5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,7 +20,7 @@ module Keygen class Application < Rails::Application - config.load_defaults 7.1 + config.load_defaults 7.2 config.generators do |generator| # Use UUIDs for table primary keys @@ -80,6 +80,9 @@ class Application < Rails::Application **config.active_record.encryption, ) + # Show all attributes in Rails console + config.active_record.attributes_for_inspect = :all + # Update async destroy batch size config.active_record.destroy_association_async_batch_size = 1_000 diff --git a/config/environments/development.rb b/config/environments/development.rb index 7023b517a2..eaddd63dfd 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bullet' +# require 'bullet' Rails.application.configure do config.host_authorization = { exclude: -> req { req.path =~ %r(^/v\d+/health) } } @@ -91,12 +91,12 @@ # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker - # Configure Bullet for performance tests - config.after_initialize do - Bullet.enable = true - Bullet.bullet_logger = true - Bullet.rails_logger = true - end + # # Configure Bullet for performance tests + # config.after_initialize do + # Bullet.enable = true + # Bullet.bullet_logger = true + # Bullet.rails_logger = true + # end # Clear cache on reload when using caching (see https://github.com/rails/rails/issues/43767) unless config.cache_classes diff --git a/config/environments/test.rb b/config/environments/test.rb index 22c789328b..618d805ca6 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'bullet' +# require 'bullet' Rails.application.configure do # Configure 'rails notes' to inspect Cucumber files @@ -95,18 +95,18 @@ # Disable colored logs in test env config.colorize_logging = false - # Configure Bullet for performance tests - config.after_initialize do - Bullet.enable = true - Bullet.bullet_logger = true + # # Configure Bullet for performance tests + # config.after_initialize do + # Bullet.enable = true + # Bullet.bullet_logger = true - # Raise an error if e.g. an n+1 query is detected - Bullet.raise = true + # # Raise an error if e.g. an n+1 query is detected + # Bullet.raise = true - # FIXME(ezekg) For some reason, we're seeing failures even though - # we're not eager loading anything. - Bullet.unused_eager_loading_enable = false - end + # # FIXME(ezekg) For some reason, we're seeing failures even though + # # we're not eager loading anything. + # Bullet.unused_eager_loading_enable = false + # end end # Speed up tests by disabling the WAL. diff --git a/config/initializers/to_time_preserves_timezone.rb b/config/initializers/to_time_preserves_timezone.rb deleted file mode 100644 index e1e6c75f5c..0000000000 --- a/config/initializers/to_time_preserves_timezone.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -# Preserve the timezone of the receiver when calling to `to_time`. -# Ruby 2.4 will change the behavior of `to_time` to preserve the timezone -# when converting to an instance of `Time` instead of the previous behavior -# of converting to the local system timezone. -# -# Rails 5.0 introduced this config option so that apps made with earlier -# versions of Rails are not affected when upgrading. -ActiveSupport.to_time_preserves_timezone = true diff --git a/features/api/v1/engines/tauri/upgrade.feature b/features/api/v1/engines/tauri/upgrade.feature index 01761c468a..7316d63157 100644 --- a/features/api/v1/engines/tauri/upgrade.feature +++ b/features/api/v1/engines/tauri/upgrade.feature @@ -303,18 +303,15 @@ Feature: Tauri upgrade package Scenario: License retrieves an upgrade for a release that has entitlement constraints (no entitlements) Given the current account has 3 "entitlements" - And the current account has 1 "release-entitlement-constraint" with the following: + And the current account has 1 "release-entitlement-constraint" for the first "release" with the following: """ - { - "entitlementId": "$entitlements[0]", - "releaseId": "$releases[0]" - } + { "entitlementId": "$entitlements[0]" } """ - And the current account has 1 "policy" for the last "product" with the following: + And the current account has 1 "policy" for the first "product" with the following: """ { "authenticationStrategy": "LICENSE" } """ - And the current account has 1 "license" for the last "policy" + And the current account has 1 "license" for the first "policy" And I am a license of account "test1" And I authenticate with my key When I send a GET request to "/accounts/test1/engines/tauri/app1?platform=darwin&arch=x86_64&version=1.0.0" @@ -322,18 +319,15 @@ Feature: Tauri upgrade package Scenario: License retrieves an upgrade that has entitlement constraints (no entitlements) Given the current account has 3 "entitlements" - And the current account has 1 "release-entitlement-constraint" with the following: + And the current account has 1 "release-entitlement-constraint" for the second "release" with the following: """ - { - "entitlementId": "$entitlements[0]", - "releaseId": "$releases[1]" - } + { "entitlementId": "$entitlements[0]" } """ - And the current account has 1 "policy" for the last "product" with the following: + And the current account has 1 "policy" for the first "product" with the following: """ { "authenticationStrategy": "LICENSE" } """ - And the current account has 1 "license" for the last "policy" + And the current account has 1 "license" for the first "policy" And I am a license of account "test1" And I authenticate with my key When I send a GET request to "/accounts/test1/engines/tauri/app1?platform=darwin&arch=x86_64&version=1.0.0" @@ -341,24 +335,18 @@ Feature: Tauri upgrade package Scenario: License retrieves an upgrade that has entitlement constraints (has entitlements) Given the current account has 3 "entitlements" - And the current account has 1 "release-entitlement-constraint" with the following: + And the current account has 1 "release-entitlement-constraint" for the second "release" with the following: """ - { - "entitlementId": "$entitlements[0]", - "releaseId": "$releases[1]" - } + { "entitlementId": "$entitlements[0]" } """ And the current account has 1 "policy" for the last "product" with the following: """ { "authenticationStrategy": "LICENSE" } """ And the current account has 1 "license" for the last "policy" - And the current account has 1 "license-entitlement" with the following: + And the current account has 1 "license-entitlement" for the first "license" with the following: """ - { - "entitlementId": "$entitlements[0]", - "licenseId": "$licenses[0]" - } + { "entitlementId": "$entitlements[0]" } """ And I am a license of account "test1" And I authenticate with my key diff --git a/features/api/v1/searches/search.feature b/features/api/v1/searches/search.feature index aa5167d2e8..6b47a15a62 100644 --- a/features/api/v1/searches/search.feature +++ b/features/api/v1/searches/search.feature @@ -1,4 +1,4 @@ -@skip/bullet +# @skip/bullet @api/v1 Feature: Search diff --git a/features/step_definitions/before_after_steps.rb b/features/step_definitions/before_after_steps.rb index 356e9eb178..3c0a9c0625 100644 --- a/features/step_definitions/before_after_steps.rb +++ b/features/step_definitions/before_after_steps.rb @@ -14,10 +14,10 @@ end end -# FIXME(ezekg) This is super hacky but there's no easy way to disable -# bullet outside of adding controller filters -Before("@skip/bullet") { Bullet.instance_variable_set :@enable, false } -After("@skip/bullet") { Bullet.instance_variable_set :@enable, true } +# # FIXME(ezekg) This is super hacky but there's no easy way to disable +# # bullet outside of adding controller filters +# Before("@skip/bullet") { Bullet.instance_variable_set :@enable, false } +# After("@skip/bullet") { Bullet.instance_variable_set :@enable, true } Before do |scenario| # Skip CE tests if we're running in an EE env, and vice-versa @@ -36,7 +36,7 @@ return skip_this_scenario if scenario.tags.any? { _1.name == '@skip' } - Bullet.start_request if Bullet.enable? + # Bullet.start_request if Bullet.enable? ActionMailer::Base.deliveries.clear Sidekiq::Worker.clear_all @@ -51,8 +51,8 @@ end After do |scenario| - Bullet.perform_out_of_channel_notifications if Bullet.enable? && Bullet.notification? - Bullet.end_request if Bullet.enable? + # Bullet.perform_out_of_channel_notifications if Bullet.enable? && Bullet.notification? + # Bullet.end_request if Bullet.enable? Faker::UniqueGenerator.clear StripeHelper.stop diff --git a/features/support/bullet.rb b/features/support/bullet.rb index d6f5ea7427..ab8ec6ed68 100644 --- a/features/support/bullet.rb +++ b/features/support/bullet.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -require 'bullet' +# require 'bullet' diff --git a/spec/factories/entitlement.rb b/spec/factories/entitlement.rb index 7769291656..9ff3013113 100644 --- a/spec/factories/entitlement.rb +++ b/spec/factories/entitlement.rb @@ -4,7 +4,7 @@ factory :entitlement do # Prevent duplicates due to cyclic entitlement codes below. Attempting # to insert duplicate codes would fail, and this prevents that. - initialize_with { Entitlement.find_by(code:) || new(**attributes.reject { _2 in NIL_ACCOUNT | NIL_ENVIRONMENT }) } + initialize_with { Entitlement.find_by(account:, code:) || new(**attributes.reject { _2 in NIL_ACCOUNT | NIL_ENVIRONMENT }) } account { NIL_ACCOUNT } environment { NIL_ENVIRONMENT } diff --git a/spec/factories/environment.rb b/spec/factories/environment.rb index f07c7f26f7..ce818f893a 100644 --- a/spec/factories/environment.rb +++ b/spec/factories/environment.rb @@ -4,7 +4,7 @@ factory :environment do # Prevent duplicates due to recurring environment codes. Attempting # to insert duplicate codes would fail, and this prevents that. - initialize_with { Environment.find_by(code:) || new(**attributes.reject { NIL_ACCOUNT == _2 }) } + initialize_with { Environment.find_by(account:, code:) || new(**attributes.reject { NIL_ACCOUNT == _2 }) } account { NIL_ACCOUNT } diff --git a/spec/factories/license.rb b/spec/factories/license.rb index 387d462d78..07831665fd 100644 --- a/spec/factories/license.rb +++ b/spec/factories/license.rb @@ -148,7 +148,7 @@ end trait :in_isolated_environment do - environment { create(:environment, :isolated, account:) } + environment { build(:environment, :isolated, account:) } end trait :isolated do @@ -156,7 +156,7 @@ end trait :in_shared_environment do - environment { create(:environment, :shared, account:) } + environment { build(:environment, :shared, account:) } end trait :shared do diff --git a/spec/factories/release_arch.rb b/spec/factories/release_arch.rb index 5293163659..b3897f5f12 100644 --- a/spec/factories/release_arch.rb +++ b/spec/factories/release_arch.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :release_arch, aliases: %i[arch] do - initialize_with { new(**attributes) } + initialize_with { new(**attributes.reject { NIL_ACCOUNT == _2 }) } sequence :key, %w[386 amd64 arm arm64 mips mips64 mips64le mipsle ppc64 ppc64le s390x].cycle diff --git a/spec/factories/release_channel.rb b/spec/factories/release_channel.rb index dd1334dee4..83f8c1f931 100644 --- a/spec/factories/release_channel.rb +++ b/spec/factories/release_channel.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :release_channel, aliases: %i[channel] do - initialize_with { ReleaseChannel.find_by(key:) || new(**attributes) } + initialize_with { new(**attributes.reject { NIL_ACCOUNT == _2 }) } sequence :key, %w[stable rc beta alpha dev].cycle diff --git a/spec/factories/release_download_link.rb b/spec/factories/release_download_link.rb index c73e30ea51..3968820286 100644 --- a/spec/factories/release_download_link.rb +++ b/spec/factories/release_download_link.rb @@ -2,9 +2,9 @@ FactoryBot.define do factory :release_download_link do - initialize_with { new(**attributes.reject { NIL_ENVIRONMENT == _2 }) } + initialize_with { new(**attributes.reject { _2 in NIL_ACCOUNT | NIL_ENVIRONMENT }) } - account { nil } + account { NIL_ACCOUNT } environment { NIL_ENVIRONMENT } release { build(:release, account:, environment:) } diff --git a/spec/factories/release_engine.rb b/spec/factories/release_engine.rb index b0b72409d4..08e9769ffe 100644 --- a/spec/factories/release_engine.rb +++ b/spec/factories/release_engine.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :release_engine, aliases: %i[engine] do - initialize_with { new(**attributes) } + initialize_with { new(**attributes.reject { NIL_ACCOUNT == _2 }) } sequence :key, %w[pypi tauri].cycle diff --git a/spec/factories/release_filetype.rb b/spec/factories/release_filetype.rb index 29479a3a67..2fc897d3f8 100644 --- a/spec/factories/release_filetype.rb +++ b/spec/factories/release_filetype.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :release_filetype, aliases: %i[filetype] do - initialize_with { new(**attributes) } + initialize_with { new(**attributes.reject { NIL_ACCOUNT == _2 }) } sequence :key, %w[dmg exe zip tar.gz appimage].cycle diff --git a/spec/factories/release_platform.rb b/spec/factories/release_platform.rb index 6f14ce43bf..58d04f7584 100644 --- a/spec/factories/release_platform.rb +++ b/spec/factories/release_platform.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :release_platform, aliases: %i[platform] do - initialize_with { new(**attributes) } + initialize_with { new(**attributes.reject { _2 in NIL_ACCOUNT }) } sequence :key, %w[darwin linux windows].cycle diff --git a/spec/factories/release_upgrade_link.rb b/spec/factories/release_upgrade_link.rb index 8fc337efbb..eb67f61e8e 100644 --- a/spec/factories/release_upgrade_link.rb +++ b/spec/factories/release_upgrade_link.rb @@ -2,9 +2,9 @@ FactoryBot.define do factory :release_upgrade_link do - initialize_with { new(**attributes.reject { NIL_ENVIRONMENT == _2 }) } + initialize_with { new(**attributes.reject { _2 in NIL_ACCOUNT | NIL_ENVIRONMENT }) } - account { nil } + account { NIL_ACCOUNT } environment { NIL_ENVIRONMENT } release { build(:release, account:, environment:) } diff --git a/spec/factories/release_upload_link.rb b/spec/factories/release_upload_link.rb index 6681f53074..bee875ff22 100644 --- a/spec/factories/release_upload_link.rb +++ b/spec/factories/release_upload_link.rb @@ -2,9 +2,9 @@ FactoryBot.define do factory :release_upload_link do - initialize_with { new(**attributes.reject { NIL_ENVIRONMENT == _2 }) } + initialize_with { new(**attributes.reject { _2 in NIL_ACCOUNT | NIL_ENVIRONMENT }) } - account { nil } + account { NIL_ACCOUNT } environment { NIL_ENVIRONMENT } release { build(:release, account:, environment:) } diff --git a/spec/factories/role.rb b/spec/factories/role.rb index db7e86fba3..34ff88ea4a 100644 --- a/spec/factories/role.rb +++ b/spec/factories/role.rb @@ -30,6 +30,10 @@ name { :read_only } end + trait :environment do + name { :environment } + end + trait :product do name { :product } end diff --git a/spec/models/policy_spec.rb b/spec/models/policy_spec.rb index 573f803451..5cfe7acf00 100644 --- a/spec/models/policy_spec.rb +++ b/spec/models/policy_spec.rb @@ -75,6 +75,9 @@ end context 'on update' do + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } + it 'should denormalize product to licenses' do product = create(:product, account:) policy = create(:policy, account:, licenses: build_list(:license, 10, account:)) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8ec71fdba9..3a3f4a4637 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -310,6 +310,9 @@ end describe '#destroy' do + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } + it 'should destroy owned machines' do user = create(:user, account:) license = create(:license, account:) diff --git a/spec/services/broadcast_event_service_spec.rb b/spec/services/broadcast_event_service_spec.rb index 3722e6a422..4144f911b7 100644 --- a/spec/services/broadcast_event_service_spec.rb +++ b/spec/services/broadcast_event_service_spec.rb @@ -43,9 +43,10 @@ def jsonapi_render(resource, account:, meta: nil, **options) .to_json end - before do - Sidekiq::Testing.inline! + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } + before do # FIXME(ezekg) Instantiate models so Active Record lazy loads the model's # attributes otherwise the mocks below will fail WebhookEvent.new @@ -63,10 +64,6 @@ def jsonapi_render(resource, account:, meta: nil, **options) } end - after do - Sidekiq::Worker.clear_all - end - it 'should create a new webhook event' do event = create_webhook_event!(account, resource) diff --git a/spec/workers/cull_dead_machines_worker_spec.rb b/spec/workers/cull_dead_machines_worker_spec.rb index c079cd8a67..a00554f124 100644 --- a/spec/workers/cull_dead_machines_worker_spec.rb +++ b/spec/workers/cull_dead_machines_worker_spec.rb @@ -7,14 +7,8 @@ let(:worker) { CullDeadMachinesWorker } let(:account) { create(:account) } - # See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing - before do - Sidekiq::Testing.inline! - end - - after do - Sidekiq::Worker.clear_all - end + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } context 'without a monitor' do let(:heartbeat_jid) { nil } diff --git a/spec/workers/cull_dead_processes_worker_spec.rb b/spec/workers/cull_dead_processes_worker_spec.rb index 1582b778d3..42161e3c7d 100644 --- a/spec/workers/cull_dead_processes_worker_spec.rb +++ b/spec/workers/cull_dead_processes_worker_spec.rb @@ -7,14 +7,8 @@ let(:worker) { CullDeadProcessesWorker } let(:account) { create(:account) } - # See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing - before do - Sidekiq::Testing.inline! - end - - after do - Sidekiq::Worker.clear_all - end + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } context 'without a monitor' do let(:heartbeat_jid) { nil } diff --git a/spec/workers/prune_event_logs_worker_spec.rb b/spec/workers/prune_event_logs_worker_spec.rb index 944f361dc0..b23374fc95 100644 --- a/spec/workers/prune_event_logs_worker_spec.rb +++ b/spec/workers/prune_event_logs_worker_spec.rb @@ -7,14 +7,8 @@ let(:worker) { PruneEventLogsWorker } let(:account) { create(:account) } - # See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing - before do - Sidekiq::Testing.inline! - end - - after do - Sidekiq::Worker.clear_all - end + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } it 'should prune backlog of high-volume event logs' do license = create(:license, account:) diff --git a/spec/workers/prune_request_logs_worker_spec.rb b/spec/workers/prune_request_logs_worker_spec.rb index d9a1caf68b..3a8622e220 100644 --- a/spec/workers/prune_request_logs_worker_spec.rb +++ b/spec/workers/prune_request_logs_worker_spec.rb @@ -7,14 +7,8 @@ let(:worker) { PruneRequestLogsWorker } let(:account) { create(:account) } - # See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing - before do - Sidekiq::Testing.inline! - end - - after do - Sidekiq::Worker.clear_all - end + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } it 'should prune backlog of request logs' do create_list(:request_log, 50, account:, created_at: (worker::BACKLOG_DAYS + 1).days.ago) diff --git a/spec/workers/prune_webhook_events_worker_spec.rb b/spec/workers/prune_webhook_events_worker_spec.rb index c3fa1aff47..4b7e2324d9 100644 --- a/spec/workers/prune_webhook_events_worker_spec.rb +++ b/spec/workers/prune_webhook_events_worker_spec.rb @@ -7,14 +7,8 @@ let(:worker) { PruneWebhookEventsWorker } let(:account) { create(:account) } - # See: https://github.com/mhenrixon/sidekiq-unique-jobs#testing - before do - Sidekiq::Testing.inline! - end - - after do - Sidekiq::Worker.clear_all - end + before { Sidekiq::Testing.inline! } + after { Sidekiq::Testing.fake! } it 'should prune backlog of webhook events' do create_list(:webhook_event, 50, account:, created_at: (worker::BACKLOG_DAYS + 1).days.ago)