-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
active flag on experiments derived from start and end times
- Loading branch information
1 parent
402179b
commit ad7a4dc
Showing
5 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20240812081108_remove_active_flag_from_experiments.rb
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveActiveFlagFromExperiments < ActiveRecord::Migration[6.1] | ||
def change | ||
remove_column :experiments, :active, :boolean | ||
end | ||
end |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Experiment, type: :model do | ||
|
||
describe "#is_active?" do | ||
context "when the experiment has neither start or end times" do | ||
it "is active" do | ||
experiment = build(:experiment, starts_at: nil, ends_at: nil) | ||
expect(experiment).to be_active | ||
end | ||
end | ||
|
||
context "when the experiment has a start time but no end time" do | ||
it "is inactive before the start time" do | ||
experiment = build(:experiment, starts_at: Time.now + 1.hour, ends_at: nil) | ||
expect(experiment).not_to be_active | ||
end | ||
|
||
it "is active after the start time" do | ||
experiment = build(:experiment, starts_at: Time.now - 1.hour, ends_at: nil) | ||
expect(experiment).to be_active | ||
end | ||
end | ||
|
||
context "when the experiment has an end time but no start time" do | ||
it "is active before the end time" do | ||
experiment = build(:experiment, starts_at: nil, ends_at: Time.now + 1.hour) | ||
expect(experiment).to be_active | ||
end | ||
|
||
it "is inactive after the end time" do | ||
experiment = build(:experiment, starts_at: nil, ends_at: Time.now - 1.hour) | ||
expect(experiment).not_to be_active | ||
end | ||
end | ||
|
||
context "when the experiment has both start and end times" do | ||
it "is inactive before the start time" do | ||
experiment = build(:experiment, starts_at: Time.now + 1.hour, ends_at: Time.now + 2.hours) | ||
expect(experiment).not_to be_active | ||
end | ||
|
||
it "is active between the start and end times" do | ||
experiment = build(:experiment, starts_at: Time.now - 1.hour, ends_at: Time.now + 1.hour) | ||
expect(experiment).to be_active | ||
end | ||
|
||
it "is inactive after the end time" do | ||
experiment = build(:experiment, starts_at: Time.now - 2.hours, ends_at: Time.now - 1.hour) | ||
expect(experiment).not_to be_active | ||
end | ||
end | ||
end | ||
end |