spec/flipper/adapters/sync/feature_synchronizer_spec.rb in flipper-1.0.0 vs spec/flipper/adapters/sync/feature_synchronizer_spec.rb in flipper-1.1.0

- old
+ new

@@ -6,10 +6,12 @@ let(:adapter) do Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new end let(:flipper) { Flipper.new(adapter) } let(:feature) { flipper[:search] } + let(:plan_expression) { Flipper.property(:plan).eq("basic") } + let(:age_expression) { Flipper.property(:age).gte(21) } context "when remote disabled" do let(:remote) { Flipper::GateValues.new({}) } it "does nothing if local is disabled" do @@ -61,10 +63,11 @@ adapter.reset remote_gate_values_hash = { boolean: nil, actors: Set["1"], groups: Set["staff"], + expression: plan_expression.value, percentage_of_time: 10, percentage_of_actors: 15, } remote = Flipper::GateValues.new(remote_gate_values_hash) @@ -72,11 +75,35 @@ local_gate_values_hash = adapter.get(feature) expect(local_gate_values_hash.fetch(:boolean)).to be(nil) expect(local_gate_values_hash.fetch(:actors)).to eq(Set["1"]) expect(local_gate_values_hash.fetch(:groups)).to eq(Set["staff"]) + expect(local_gate_values_hash.fetch(:expression)).to eq(plan_expression.value) expect(local_gate_values_hash.fetch(:percentage_of_time)).to eq("10") expect(local_gate_values_hash.fetch(:percentage_of_actors)).to eq("15") + end + + it "updates expression when remote is updated" do + any_expression = Flipper.any(plan_expression, age_expression) + remote = Flipper::GateValues.new(expression: any_expression.value) + feature.enable_expression(age_expression) + adapter.reset + + described_class.new(feature, feature.gate_values, remote).call + + expect(feature.expression_value).to eq(any_expression.value) + expect_only_enable + end + + it "does nothing to expression if in sync" do + remote = Flipper::GateValues.new(expression: plan_expression.value) + feature.enable_expression(plan_expression) + adapter.reset + + described_class.new(feature, feature.gate_values, remote).call + + expect(feature.expression_value).to eq(plan_expression.value) + expect_no_enable_or_disable end it "adds remotely added actors" do remote = Flipper::GateValues.new(actors: Set["1", "2"]) feature.enable_actor(Flipper::Actor.new("1"))