Skip to content

Commit

Permalink
add test for variant initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
gardleopard committed Aug 22, 2023
1 parent 4707a7b commit ac2e16b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/unleash/variant_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/unleash/activation_strategy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'unleash/constraint'
require 'unleash/variant_definition'

RSpec.describe Unleash::ActivationStrategy do
before do
Expand All @@ -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

Expand Down

0 comments on commit ac2e16b

Please sign in to comment.