ldclient-rb 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -9
- data/lib/ldclient-rb/evaluation.rb +123 -77
- data/lib/ldclient-rb/events.rb +1 -0
- data/lib/ldclient-rb/flags_state.rb +2 -1
- data/lib/ldclient-rb/ldclient.rb +110 -54
- data/lib/ldclient-rb/version.rb +1 -1
- data/spec/evaluation_spec.rb +267 -95
- data/spec/ldclient_spec.rb +98 -17
- metadata +2 -2
data/spec/ldclient_spec.rb
CHANGED
@@ -34,11 +34,18 @@ describe LaunchDarkly::LDClient do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '#variation' do
|
37
|
-
|
37
|
+
feature_with_value = { key: "key", on: false, offVariation: 0, variations: ["value"], version: 100,
|
38
|
+
trackEvents: true, debugEventsUntilDate: 1000 }
|
39
|
+
|
40
|
+
it "returns the default value if the client is offline" do
|
38
41
|
result = offline_client.variation("doesntmatter", user, "default")
|
39
42
|
expect(result).to eq "default"
|
40
43
|
end
|
41
44
|
|
45
|
+
it "returns the default value for an unknown feature" do
|
46
|
+
expect(client.variation("badkey", user, "default")).to eq "default"
|
47
|
+
end
|
48
|
+
|
42
49
|
it "queues a feature request event for an unknown feature" do
|
43
50
|
expect(event_processor).to receive(:add_event).with(hash_including(
|
44
51
|
kind: "feature", key: "badkey", user: user, value: "default", default: "default"
|
@@ -46,56 +53,130 @@ describe LaunchDarkly::LDClient do
|
|
46
53
|
client.variation("badkey", user, "default")
|
47
54
|
end
|
48
55
|
|
56
|
+
it "returns the value for an existing feature" do
|
57
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
58
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
59
|
+
expect(client.variation("key", user, "default")).to eq "value"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns the default value if a feature evaluates to nil" do
|
63
|
+
empty_feature = { key: "key", on: false, offVariation: nil }
|
64
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
65
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, empty_feature)
|
66
|
+
expect(client.variation("key", user, "default")).to eq "default"
|
67
|
+
end
|
68
|
+
|
49
69
|
it "queues a feature request event for an existing feature" do
|
50
70
|
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
51
|
-
config.feature_store.upsert(LaunchDarkly::FEATURES,
|
71
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
52
72
|
expect(event_processor).to receive(:add_event).with(hash_including(
|
53
73
|
kind: "feature",
|
54
|
-
key:
|
55
|
-
version:
|
74
|
+
key: "key",
|
75
|
+
version: 100,
|
56
76
|
user: user,
|
57
77
|
variation: 0,
|
58
|
-
value:
|
78
|
+
value: "value",
|
59
79
|
default: "default",
|
60
80
|
trackEvents: true,
|
61
|
-
debugEventsUntilDate:
|
81
|
+
debugEventsUntilDate: 1000
|
62
82
|
))
|
63
|
-
client.variation(
|
83
|
+
client.variation("key", user, "default")
|
64
84
|
end
|
65
85
|
|
66
86
|
it "queues a feature event for an existing feature when user is nil" do
|
67
87
|
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
68
|
-
config.feature_store.upsert(LaunchDarkly::FEATURES,
|
88
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
69
89
|
expect(event_processor).to receive(:add_event).with(hash_including(
|
70
90
|
kind: "feature",
|
71
|
-
key:
|
72
|
-
version:
|
91
|
+
key: "key",
|
92
|
+
version: 100,
|
73
93
|
user: nil,
|
74
94
|
variation: nil,
|
75
95
|
value: "default",
|
76
96
|
default: "default",
|
77
97
|
trackEvents: true,
|
78
|
-
debugEventsUntilDate:
|
98
|
+
debugEventsUntilDate: 1000
|
79
99
|
))
|
80
|
-
client.variation(
|
100
|
+
client.variation("key", nil, "default")
|
81
101
|
end
|
82
102
|
|
83
103
|
it "queues a feature event for an existing feature when user key is nil" do
|
84
104
|
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
85
|
-
config.feature_store.upsert(LaunchDarkly::FEATURES,
|
105
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
86
106
|
bad_user = { name: "Bob" }
|
87
107
|
expect(event_processor).to receive(:add_event).with(hash_including(
|
88
108
|
kind: "feature",
|
89
|
-
key:
|
90
|
-
version:
|
109
|
+
key: "key",
|
110
|
+
version: 100,
|
91
111
|
user: bad_user,
|
92
112
|
variation: nil,
|
93
113
|
value: "default",
|
94
114
|
default: "default",
|
95
115
|
trackEvents: true,
|
96
|
-
debugEventsUntilDate:
|
116
|
+
debugEventsUntilDate: 1000
|
117
|
+
))
|
118
|
+
client.variation("key", bad_user, "default")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe '#variation_detail' do
|
123
|
+
feature_with_value = { key: "key", on: false, offVariation: 0, variations: ["value"], version: 100,
|
124
|
+
trackEvents: true, debugEventsUntilDate: 1000 }
|
125
|
+
|
126
|
+
it "returns the default value if the client is offline" do
|
127
|
+
result = offline_client.variation_detail("doesntmatter", user, "default")
|
128
|
+
expected = LaunchDarkly::EvaluationDetail.new("default", nil, { kind: 'ERROR', errorKind: 'CLIENT_NOT_READY' })
|
129
|
+
expect(result).to eq expected
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns the default value for an unknown feature" do
|
133
|
+
result = client.variation_detail("badkey", user, "default")
|
134
|
+
expected = LaunchDarkly::EvaluationDetail.new("default", nil, { kind: 'ERROR', errorKind: 'FLAG_NOT_FOUND'})
|
135
|
+
expect(result).to eq expected
|
136
|
+
end
|
137
|
+
|
138
|
+
it "queues a feature request event for an unknown feature" do
|
139
|
+
expect(event_processor).to receive(:add_event).with(hash_including(
|
140
|
+
kind: "feature", key: "badkey", user: user, value: "default", default: "default",
|
141
|
+
reason: { kind: 'ERROR', errorKind: 'FLAG_NOT_FOUND' }
|
142
|
+
))
|
143
|
+
client.variation_detail("badkey", user, "default")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "returns a value for an existing feature" do
|
147
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
148
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
149
|
+
result = client.variation_detail("key", user, "default")
|
150
|
+
expected = LaunchDarkly::EvaluationDetail.new("value", 0, { kind: 'OFF' })
|
151
|
+
expect(result).to eq expected
|
152
|
+
end
|
153
|
+
|
154
|
+
it "returns the default value if a feature evaluates to nil" do
|
155
|
+
empty_feature = { key: "key", on: false, offVariation: nil }
|
156
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
157
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, empty_feature)
|
158
|
+
result = client.variation_detail("key", user, "default")
|
159
|
+
expected = LaunchDarkly::EvaluationDetail.new("default", nil, { kind: 'OFF' })
|
160
|
+
expect(result).to eq expected
|
161
|
+
expect(result.default_value?).to be true
|
162
|
+
end
|
163
|
+
|
164
|
+
it "queues a feature request event for an existing feature" do
|
165
|
+
config.feature_store.init({ LaunchDarkly::FEATURES => {} })
|
166
|
+
config.feature_store.upsert(LaunchDarkly::FEATURES, feature_with_value)
|
167
|
+
expect(event_processor).to receive(:add_event).with(hash_including(
|
168
|
+
kind: "feature",
|
169
|
+
key: "key",
|
170
|
+
version: 100,
|
171
|
+
user: user,
|
172
|
+
variation: 0,
|
173
|
+
value: "value",
|
174
|
+
default: "default",
|
175
|
+
trackEvents: true,
|
176
|
+
debugEventsUntilDate: 1000,
|
177
|
+
reason: { kind: "OFF" }
|
97
178
|
))
|
98
|
-
client.
|
179
|
+
client.variation_detail("key", user, "default")
|
99
180
|
end
|
100
181
|
end
|
101
182
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldclient-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LaunchDarkly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|