Created
April 14, 2023 22:49
-
-
Save compwron/0ea4b6a90e2dc4f8d35896a9aca26fae to your computer and use it in GitHub Desktop.
Revisions
-
compwron created this gist
Apr 14, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ namespace :acts_as_paranoid do desc "Verify that all models using acts_as_paranoid have scopes on their unique indexes and validations" task lint: :environment do if Rails.env.test? currently_probably_buggy_classes_ignored = %w[ # too many things, redacted ] Zeitwerk::Loader.eager_load_all errors = [] allows_multiple_deleted = "(deleted_at IS NULL)" ApplicationRecord.descendants.each do |clazz| next unless clazz.paranoid? unique_indexes = ActiveRecord::Base.connection.indexes(clazz.table_name).select { |x| x.unique } next unless unique_indexes.any? unique_indexes.each do |idx| if idx in currently_probably_buggy_classes_ignored puts "#{idx.name} does not pass rake acts_as_paranoid:lint but we are not worrying about that right now" next end unless idx.where&.include?(allows_multiple_deleted) errors << "#{clazz} uses acts_as_paranoid but has a unique index #{idx.name} without #{allows_multiple_deleted} but it does have: #{idx.where}" end end end raise errors.join("\n") unless errors.empty? else system("bundle exec rake acts_as_paranoid:lint RAILS_ENV='test'") raise if $?.exitstatus.nonzero? end end end