Skip to content

Commit 086962e

Browse files
oakbanikellyroach-optimizely
authored andcommitted
🖊️ sort feature keys (#91)
1 parent f410e92 commit 086962e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

lib/optimizely.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def get_enabled_features(user_id, attributes = nil)
326326
attributes
327327
) == true
328328
end
329-
enabled_features
329+
enabled_features.sort
330330
end
331331

332332
def get_feature_variable_string(feature_flag_key, variable_key, user_id, attributes = nil)

spec/project_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,31 @@ class InvalidErrorHandler; end
803803
# Checks prevented features should not return
804804
expect(project_instance.get_enabled_features('test_user', 'browser_type' => 'chrome')).not_to include(*disabled_features)
805805
end
806+
807+
it 'should return sorted feature keys' do
808+
# Mock is_feature_enabled and assert that is_feature_enabled does get called in an unsorted order
809+
expect(project_instance).to receive(:is_feature_enabled).with('boolean_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
810+
expect(project_instance).to receive(:is_feature_enabled).with('double_single_variable_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
811+
expect(project_instance).to receive(:is_feature_enabled).with('integer_single_variable_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
812+
expect(project_instance).to receive(:is_feature_enabled).with('boolean_single_variable_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
813+
expect(project_instance).to receive(:is_feature_enabled).with('string_single_variable_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
814+
expect(project_instance).to receive(:is_feature_enabled).with('multi_variate_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
815+
expect(project_instance).to receive(:is_feature_enabled).with('mutex_group_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
816+
expect(project_instance).to receive(:is_feature_enabled).with('empty_feature', 'test_user', 'browser_type' => 'chrome').and_return(true).ordered
817+
818+
expect(project_instance.get_enabled_features('test_user', 'browser_type' => 'chrome')).to eq(
819+
%w[
820+
boolean_feature
821+
boolean_single_variable_feature
822+
double_single_variable_feature
823+
empty_feature
824+
integer_single_variable_feature
825+
multi_variate_feature
826+
mutex_group_feature
827+
string_single_variable_feature
828+
]
829+
)
830+
end
806831
end
807832

808833
describe '#get_feature_variable_string' do

0 commit comments

Comments
 (0)