Skip to content

Commit 774ce4c

Browse files
committed
fixed spec
1 parent d90a18d commit 774ce4c

2 files changed

Lines changed: 42 additions & 21 deletions

File tree

lib/splitclient-rb/cache/repositories/splits_repository.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Cache
55
module Repositories
66
class SplitsRepository < Repository
77
attr_reader :adapter
8-
DEFAULT_CONDITIONS_TEMPLATE = {
8+
DEFAULT_CONDITIONS_TEMPLATE = [{
99
conditionType: "ROLLOUT",
1010
matcherGroup: {
1111
combiner: "AND",
@@ -30,7 +30,7 @@ class SplitsRepository < Repository
3030
}
3131
],
3232
label: "unsupported matcher type"
33-
}
33+
}]
3434
def initialize(config, flag_sets_repository, flag_set_filter)
3535
super(config)
3636
@tt_cache = {}
@@ -182,7 +182,7 @@ def add_feature_flag(split)
182182

183183
if check_undefined_matcher(split)
184184
@config.logger.warn("Feature Flag #{split[:name]} has undefined matcher, setting conditions to default template.")
185-
split[:conditions] = [SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE]
185+
split[:conditions] = SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE
186186
end
187187
if !split[:sets].nil?
188188
for flag_set in split[:sets]

spec/cache/repositories/splits_repository_spec.rb

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,49 @@
127127
}]
128128
}
129129
repository.update([split], [], -1)
130-
expect(repository.get_split('corge')[:conditions]).to eq [SplitIoClient::Cache::Repositories::SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE]
130+
expect(repository.get_split('corge')[:conditions]).to eq SplitIoClient::Cache::Repositories::SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE
131131

132132
# test with multiple conditions
133-
split[:conditions] .append({
134-
partitions: [
135-
{treatment: 'on', size: 25},
136-
{treatment: 'off', size: 75}
137-
],
138-
contitionType: 'WHITELIST',
139-
label: 'some_other_label',
140-
matcherGroup: {
141-
matchers: [
142-
{
143-
matcherType: 'ALL_KEYS',
144-
negate: false,
145-
}
133+
split2 = {
134+
name: 'corge2',
135+
trafficTypeName: 'tt_name_5',
136+
conditions: [
137+
{
138+
partitions: [
139+
{treatment: 'on', size: 50},
140+
{treatment: 'off', size: 50}
141+
],
142+
contitionType: 'WHITELIST',
143+
label: 'some_label',
144+
matcherGroup: {
145+
matchers: [
146+
{
147+
matcherType: 'UNDEFINED',
148+
whitelistMatcherData: {
149+
whitelist: ['k1', 'k2', 'k3']
150+
},
151+
negate: false,
152+
}
153+
],
154+
combiner: 'AND'
155+
}
156+
},
157+
{
158+
partitions: [
159+
{treatment: 'on', size: 25},
160+
{treatment: 'off', size: 75}
146161
],
147-
combiner: 'AND'
162+
contitionType: 'WHITELIST',
163+
label: 'some_other_label',
164+
matcherGroup: {
165+
matchers: [{matcherType: 'ALL_KEYS', negate: false}],
166+
combiner: 'AND'
167+
}
168+
}]
148169
}
149-
})
150-
repository.update([split], [], -1)
151-
expect(repository.get_split('corge')[:conditions]).to eq [SplitIoClient::Cache::Repositories::SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE]
170+
171+
repository.update([split2], [], -1)
172+
expect(repository.get_split('corge2')[:conditions]).to eq SplitIoClient::Cache::Repositories::SplitsRepository::DEFAULT_CONDITIONS_TEMPLATE
152173
end
153174
end
154175

0 commit comments

Comments
 (0)