Skip to content

Commit 2fc8372

Browse files
update: Refactor attribute filtering logic and improve test attribute structure
1 parent 351e055 commit 2fc8372

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/optimizely/cmab/cmab_service.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def filter_attributes(project_config, user_context, rule_id)
119119
cmab_attribute_ids = experiment['cmab']['attributeIds']
120120
cmab_attribute_ids.each do |attribute_id|
121121
attribute = project_config.attribute_id_map[attribute_id]
122-
filtered_user_attributes[attribute.key] = user_attributes[attribute.key] if attribute && user_attributes.key?(attribute.key)
122+
next unless attribute
123+
124+
attribute_key = attribute['key']
125+
filtered_user_attributes[attribute_key] = user_attributes[attribute_key] if user_attributes.key?(attribute_key)
123126
end
124127

125128
filtered_user_attributes

spec/cmab/cmab_service_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
let(:user_attributes) { {'age' => 25, 'location' => 'USA'} }
2020

2121
let(:mock_experiment) { {'cmab' => {'attributeIds' => %w[66 77]}} }
22-
let(:mock_attr1) { double('attribute', key: 'age') }
23-
let(:mock_attr2) { double('attribute', key: 'location') }
22+
let(:mock_attr1) { {'key' => 'age'} }
23+
let(:mock_attr2) { {'key' => 'location'} }
2424

2525
before do
2626
allow(mock_user_context).to receive(:user_id).and_return(user_id)

0 commit comments

Comments
 (0)