diff --git a/lib/unleash/variant_definition.rb b/lib/unleash/variant_definition.rb index d9cecad..ca6ede5 100644 --- a/lib/unleash/variant_definition.rb +++ b/lib/unleash/variant_definition.rb @@ -2,8 +2,19 @@ module Unleash class VariantDefinition + include Comparable attr_accessor :name, :weight, :payload, :overrides, :stickiness + def ==(other) + equal = true + equal = false unless self.name == other.name + equal = false unless self.weight == other.weight + equal = false unless self.payload == other.payload + equal = false unless self.stickiness == other.stickiness + equal = false unless self.overrides == other.overrides + equal + end + def initialize(name, weight = 0, payload = nil, stickiness = nil, overrides = []) # rubocop:disable Metrics/ParameterLists self.name = name self.weight = weight diff --git a/spec/unleash/activation_strategy_spec.rb b/spec/unleash/activation_strategy_spec.rb index 812dbe0..82f0170 100644 --- a/spec/unleash/activation_strategy_spec.rb +++ b/spec/unleash/activation_strategy_spec.rb @@ -1,4 +1,5 @@ require 'unleash/constraint' +require 'unleash/variant_definition' RSpec.describe Unleash::ActivationStrategy do before do @@ -12,15 +13,17 @@ context 'with correct payload' do let(:params) { Hash.new(test: true) } let(:constraints) { [Unleash::Constraint.new("constraint_name", "IN", ["value"])] } + let(:variants) { [Unleash::VariantDefinition.new("variant_name")] } it 'initializes with correct attributes' do expect(Unleash.logger).to_not receive(:warn) - strategy = Unleash::ActivationStrategy.new(name, params, constraints) + strategy = Unleash::ActivationStrategy.new(name, params, constraints, [{ "name" => "variant_name" }]) expect(strategy.name).to eq name expect(strategy.params).to eq params expect(strategy.constraints).to eq constraints + expect(strategy.variants).to eq variants end end