ubicloud/spec/model/usage_alert_spec.rb
Jeremy Evans 4dc5c281c9 Support running specs with frozen environment
This allows for running the specs with a frozen environment that
should closely match the production environment.

This adds the following rake tasks:

* coverage: Runs specs in serial with coverage
* frozen_spec: Runs specs in serial in frozen environment
* frozen_pspec: Runs specs in parallel in frozen environment

It changes the default rake task to run both the coverage and
frozen_spec tasks.  It also changes the GitHub CI workflow
to use the default rake task.

When specs are run in the frozen environment they call
clover_freeze before running the specs, after loading all
other code.

There are currently 56 specs that do not work in the frozen
environment.  They are skipped by including the skip_if_frozen
method in each spec.
2024-10-27 13:25:30 -07:00

16 lines
768 B
Ruby

# frozen_string_literal: true
require_relative "spec_helper"
RSpec.describe UsageAlert do
it "trigger sends email and updates last_triggered_at" do
skip_if_frozen
alert = described_class.new
expect(alert).to receive(:user).and_return(instance_double(Account, name: "dummy-name", email: "dummy-email")).at_least(:once)
expect(alert).to receive(:project).and_return(instance_double(Project, name: "dummy-name", ubid: "dummy-ubid", path: "dummy-path", current_invoice: instance_double(Invoice, content: {"cost" => "dummy-cost"}))).at_least(:once)
expect(Util).to receive(:send_email)
expect(Time).to receive(:now).and_return("dummy-time")
expect(alert).to receive(:update).with(last_triggered_at: "dummy-time")
alert.trigger
end
end