database_schema_check_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Admin::SystemCheck::DatabaseSchemaCheck do
  4. subject(:check) { described_class.new(user) }
  5. let(:user) { Fabricate(:user) }
  6. it_behaves_like 'a check available to devops users'
  7. describe 'pass?' do
  8. context 'when database needs migration' do
  9. before do
  10. context = instance_double(ActiveRecord::MigrationContext, needs_migration?: true)
  11. allow(ActiveRecord::Base.connection_pool).to receive(:migration_context).and_return(context)
  12. end
  13. it 'returns false' do
  14. expect(check.pass?).to be false
  15. end
  16. end
  17. context 'when database does not need migration' do
  18. before do
  19. context = instance_double(ActiveRecord::MigrationContext, needs_migration?: false)
  20. allow(ActiveRecord::Base.connection_pool).to receive(:migration_context).and_return(context)
  21. end
  22. it 'returns true' do
  23. expect(check.pass?).to be true
  24. end
  25. end
  26. end
  27. describe 'message' do
  28. it 'sends class name symbol to message instance' do
  29. allow(Admin::SystemCheck::Message).to receive(:new).with(:database_schema_check)
  30. check.message
  31. expect(Admin::SystemCheck::Message).to have_received(:new).with(:database_schema_check)
  32. end
  33. end
  34. end