Skip to content

Commit 542aea2

Browse files
authored
Merge pull request #51 from Flagsmith/fix/make_local_evaluation_multivariate_work
fix: Make local evaluation multivariate work
2 parents 9bc9d75 + 0f17b26 commit 542aea2

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

lib/flagsmith.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def get_identity_flags_from_document(identifier, traits = {})
209209

210210
Flagsmith::Flags::Collection.from_feature_state_models(
211211
engine.get_identity_feature_states(environment, identity_model),
212+
identity_id: identity_model.composite_key,
212213
analytics_processor: analytics_processor,
213214
default_flag_handler: default_flag_handler,
214215
offline_handler: offline_handler

spec/sdk/fixtures/environment.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@
6565
},
6666
"segment_id": null,
6767
"enabled": true
68+
},
69+
{
70+
"feature": {
71+
"id": 83755,
72+
"name": "test_mv",
73+
"type": "MULTIVARIATE"
74+
},
75+
"enabled": false,
76+
"django_id": 482285,
77+
"feature_segment": null,
78+
"featurestate_uuid": "c3af5fbf-39ba-422c-a846-f2fea952b37c",
79+
"feature_state_value": "1111",
80+
"multivariate_feature_state_values": [
81+
{
82+
"multivariate_feature_option": {
83+
"value": "8888",
84+
"id": 11516
85+
},
86+
"percentage_allocation": 100.0,
87+
"id": 38451,
88+
"mv_fs_value_uuid": "a4299c73-2430-47e4-9185-42accd01686c"
89+
}
90+
]
6891
}
6992
],
7093
"updated_at": "2023-07-14 16:12:00.000000",

spec/sdk/local_evaluation_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,18 @@
2020
expect(flag.value).to eq("some-overridden-value")
2121
end
2222
end
23+
24+
describe '#get_multivariate_flags' do
25+
it 'should return a 100% multivariate variation in local evaluation' do
26+
allow_any_instance_of(Flagsmith::Client).to receive(:api_client).and_return(mock_api_client)
27+
28+
flagsmith = Flagsmith::Client.new(environment_key: mock_api_key, api_url: mock_api_url, enable_local_evaluation: true)
29+
expect(flagsmith.config.local_evaluation?).to be_truthy
30+
31+
flag = flagsmith.get_identity_flags("some-identifier").get_flag("test_mv")
32+
33+
expect(flag.enabled).to be_falsy
34+
expect(flag.value).to eq("8888")
35+
end
36+
end
2337
end

spec/sdk/offline_mode_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
)
1515

1616
response = flagsmith.get_environment_flags
17-
expect(response.count).to eq(1)
17+
expect(response.count).to eq(2)
1818
expect(response.first[-1].feature_name).to eq("some_feature")
1919
end
2020

0 commit comments

Comments
 (0)