Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test requiring data migrations to have an associated spec file #247

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions spec/automated_review/data_migrations_need_tests_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
describe "Data migrations" do
KNOWN_MISSING_DATA_MIGRATION_SPEC_FILES = [
"20151021174044_add_tenant_default_group_spec.rb",
"20160317041206_add_maintenance_to_host_spec.rb",
"20160428215808_add_filters_to_entitlements_spec.rb",
"20160713130940_remove_type_template_and_vms_filters_from_miq_search_spec.rb",
"20170419154137_remove_deleted_migration_timestamps_spec.rb",
"20171011180000_move_openstack_refresher_settings_spec.rb"
].freeze

def data_migration_files
Spec::Support::ConstantWatcher.classes_by_file.keys.select { |file| file.include?("db/migrate") }
end

it "need tests" do
Dir.glob(ManageIQ::Schema::Engine.root.join("db", "migrate", "*.rb")).each { |i| require i }

data_migration_files.each do |data_migration_file|
spec_file_basename = File.basename(data_migration_file).sub(".rb", "_spec.rb")
spec_file = ManageIQ::Schema::Engine.root.join("spec", "migrations", spec_file_basename)

if spec_file_basename.in?(KNOWN_MISSING_DATA_MIGRATION_SPEC_FILES)
expect(spec_file.file?).to eq(false), "Thanks for adding a test!! Please remove #{spec_file_basename} from KNOWN_MISSING_DATA_MIGRATION_SPEC_FILES in #{__FILE__}"
else
expect(spec_file.file?).to eq(true), "Missing data migration spec at #{spec_file}"
end
end
end
end
21 changes: 21 additions & 0 deletions spec/support/constant_watcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Spec
module Support
module ConstantWatcher
mattr_accessor :classes_by_file

def inherited(other)
Spec::Support::ConstantWatcher.add(other)
super
end

def self.add(const)
path = caller_locations(2..2).first.path
self.classes_by_file ||= {}
self.classes_by_file[path] ||= []
self.classes_by_file[path] << const.name
end
end
end
end

ActiveRecord::Base.singleton_class.prepend(Spec::Support::ConstantWatcher)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify this works locally if you do bundle exec rspec spec/specific/spec/file.rb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's loaded by spec_helper