|
1 | 1 | require 'rails_helper' |
2 | 2 |
|
3 | 3 | RSpec.describe VariantDetail do |
4 | | - let(:split) { FactoryGirl.create(:split, name: 'split_enabled', registry: { true: 50, false: 50 }) } |
| 4 | + let(:split) { FactoryGirl.create(:split, name: "some_feature_enabled", registry: { true: 40, false: 60 }) } |
| 5 | + |
| 6 | + describe "#weight" do |
| 7 | + subject { described_class.new(split: split, variant: 'true') } |
| 8 | + |
| 9 | + it "is the weight of the given variant" do |
| 10 | + expect(subject.weight).to eq 40 |
| 11 | + end |
| 12 | + end |
| 13 | + |
| 14 | + describe "#assignment_count" do |
| 15 | + let!(:true_assignment) { FactoryGirl.create(:assignment, split: split, variant: "true") } |
| 16 | + let!(:false_assignment) { FactoryGirl.create_pair(:assignment, split: split, variant: "false") } |
| 17 | + |
| 18 | + let(:true_presenter) { described_class.new(split: split, variant: 'true') } |
| 19 | + let(:false_presenter) { described_class.new(split: split, variant: 'false') } |
| 20 | + |
| 21 | + it "is the number of assignments of given variant" do |
| 22 | + expect(true_presenter.assignment_count).to eq 1 |
| 23 | + expect(false_presenter.assignment_count).to eq 2 |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + describe "#retirable?" do |
| 28 | + subject { described_class.new(split: split, variant: 'true') } |
| 29 | + |
| 30 | + context 'with a 0% weight' do |
| 31 | + let(:split) { FactoryGirl.create(:split, name: "some_feature_enabled", registry: { true: 0, false: 100 }) } |
| 32 | + |
| 33 | + context 'with no assignments' do |
| 34 | + it "is false" do |
| 35 | + expect(subject).not_to be_retirable |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context 'with some assignments' do |
| 40 | + let!(:assignment) { FactoryGirl.create(:assignment, split: split, variant: "true") } |
| 41 | + |
| 42 | + it "is true" do |
| 43 | + expect(subject).to be_retirable |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context 'with a non0% weight' do |
| 49 | + let(:split) { FactoryGirl.create(:split, name: "some_feature_enabled", registry: { true: 1, false: 99 }) } |
| 50 | + |
| 51 | + context 'with no assignments' do |
| 52 | + it "is false" do |
| 53 | + expect(subject).not_to be_retirable |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context 'with some assignments' do |
| 58 | + let!(:assignment) { FactoryGirl.create(:assignment, split: split, variant: "true") } |
| 59 | + |
| 60 | + it "is false for a non 0% weight that has assignments" do |
| 61 | + expect(subject).not_to be_retirable |
| 62 | + end |
| 63 | + end |
| 64 | + end |
| 65 | + end |
5 | 66 |
|
6 | 67 | describe '#valid?' do |
7 | 68 | context 'with a variant that exists' do |
|
0 commit comments