Files
ubicloud/clover.rb
Jeremy Evans 45a66b2195 Support testing with frozen Database and models
This makes the testing more like the production environment.

This renames the previous frozen_{,p}spec rake task to
frozen_core_{,p}spec, and adds:

* frozen_db_model_{,p}spec for running the specs with just a frozen
  Database and models
* frozen_{,p}spec for running the specs with a frozen core, Database,
  and models (the most similar to the production environment, but
  the most skipped tests).

This adds rspec and turbo_tests lambdas to DRY up the related rake
task code. It sets RAKE_ENV explicitly for turbo_tests, instead
of relying on the Rakefile setting it implicitly due to how the
spec tasks is currently defined.

This adds a skip_if_frozen_models method to the specs, which does
nothing when running without frozen Database and models, but skips
the spec if running with frozen Database and models.  It then
adds a call to skip_if_frozen_models to all specs that try to mock
DB or the models (109 callsites, 124 specs).

To avoid pages of output of skipped specs, this uses the approach
recommended by the rspec maintainers to suppress skipped specs.
The approach is stored in a separate spec/supress_pending file
so it is usable by both the normal and parallel specs.

I tested this with the implicit_subquery commit
(0085befc4a), and the frozen model
tests fail with it, showing that this approach would have caught
that failure before the change was put into production.
2024-10-28 14:31:00 -07:00

41 lines
678 B
Ruby

# frozen_string_literal: true
require_relative "model"
require "roda"
class Clover < Roda
def self.freeze
# :nocov:
if Config.test? && ENV["CLOVER_FREEZE_MODELS"] != "1"
Sequel::Model.descendants.each(&:finalize_associations)
else
Sequel::Model.freeze_descendants
DB.freeze
end
# :nocov:
super
end
route do |r|
if r.host.start_with?("api.")
r.run CloverApi
end
# To make test and development easier
# :nocov:
unless Config.production?
r.on "api" do
r.run CloverApi
end
end
# :nocov:
r.on "runtime" do
r.run CloverRuntime
end
r.run CloverWeb
end
end