|
48 | 48 | end |
49 | 49 |
|
50 | 50 | it "removes key if experiment has a winner" do |
51 | | - allow(Split::ExperimentCatalog).to receive(:find).with("link_color").and_return(experiment) |
52 | | - allow(experiment).to receive(:start_time).and_return(Date.today) |
53 | | - allow(experiment).to receive(:has_winner?).and_return(true) |
| 51 | + experiment = Split::ExperimentCatalog.find_or_create("link_color", "red", "blue") |
| 52 | + experiment.start |
| 53 | + experiment.winner = "red" |
| 54 | + |
| 55 | + expect(experiment.has_winner?).to be_truthy |
54 | 56 | @subject.cleanup_old_experiments! |
55 | 57 | expect(@subject.keys).to be_empty |
56 | 58 | end |
57 | 59 |
|
58 | 60 | it "removes key if experiment has not started yet" do |
59 | | - allow(Split::ExperimentCatalog).to receive(:find).with("link_color").and_return(experiment) |
60 | | - allow(experiment).to receive(:has_winner?).and_return(false) |
| 61 | + expect(Split::ExperimentCatalog.find("link_color")).to be_nil |
61 | 62 | @subject.cleanup_old_experiments! |
62 | 63 | expect(@subject.keys).to be_empty |
63 | 64 | end |
|
66 | 67 | let(:user_keys) { { "link_color" => "blue", "link_color:finished" => true } } |
67 | 68 |
|
68 | 69 | it "does not remove finished key for experiment without a winner" do |
69 | | - allow(Split::ExperimentCatalog).to receive(:find).with("link_color").and_return(experiment) |
70 | | - allow(Split::ExperimentCatalog).to receive(:find).with("link_color:finished").and_return(nil) |
71 | | - allow(experiment).to receive(:start_time).and_return(Date.today) |
72 | | - allow(experiment).to receive(:has_winner?).and_return(false) |
| 70 | + experiment = Split::ExperimentCatalog.find_or_create("link_color", "red", "blue") |
| 71 | + experiment.start |
| 72 | + |
| 73 | + expect(experiment.has_winner?).to be_falsey |
73 | 74 | @subject.cleanup_old_experiments! |
| 75 | + |
74 | 76 | expect(@subject.keys).to include("link_color") |
75 | 77 | expect(@subject.keys).to include("link_color:finished") |
76 | 78 | end |
|
0 commit comments