Skip to content

Commit 8488c51

Browse files
authored
3.0.1 (#97)
1 parent a7579e5 commit 8488c51

File tree

4 files changed

+23
-48
lines changed

4 files changed

+23
-48
lines changed

lib/ldclient-rb/requestor.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@ def initialize(sdk_key, config)
1818
end
1919
end
2020

21-
def request_all_flags()
22-
make_request("/sdk/latest-flags")
23-
end
24-
2521
def request_flag(key)
2622
make_request("/sdk/latest-flags/" + key)
2723
end
2824

29-
def request_all_segments()
30-
make_request("/sdk/latest-segments")
31-
end
32-
3325
def request_segment(key)
3426
make_request("/sdk/latest-segments/" + key)
3527
end

lib/ldclient-rb/stream.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def process_message(message, method)
110110
@initialized.make_true
111111
@config.logger.info("[LDClient] Stream initialized (via indirect message)")
112112
elsif method == INDIRECT_PATCH
113-
key = feature_key_for_path(message.data)
113+
key = key_for_path(FEATURES, message.data)
114114
if key
115115
@feature_store.upsert(FEATURES, @requestor.request_flag(key))
116116
else
117-
key = segment_key_for_path(message.data)
117+
key = key_for_path(SEGMENTS, message.data)
118118
if key
119-
@feature_store.upsert(SEGMENTS, key, @requestor.request_segment(key))
119+
@feature_store.upsert(SEGMENTS, @requestor.request_segment(key))
120120
end
121121
end
122122
else

spec/requestor_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
allow(faraday).to receive(:get) do |*args, &block|
2020
req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new)
2121
block.call(req)
22-
expect(args).to eq ['http://ld.com/sdk/latest-flags']
22+
expect(args).to eq ['http://ld.com/sdk/latest-all']
2323
expect(req.options.proxy[:uri]).to eq URI("http://proxy.com")
2424
double(body: '{"foo": "bar"}', status: 200, headers: {})
2525
end
2626

27-
requestor.request_all_flags()
27+
requestor.request_all_data()
2828
end
2929
end
3030
describe "without a proxy" do
@@ -42,11 +42,11 @@
4242
allow(faraday).to receive(:get) do |*args, &block|
4343
req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new)
4444
block.call(req)
45-
expect(args).to eq ['http://ld.com/sdk/latest-flags']
45+
expect(args).to eq ['http://ld.com/sdk/latest-all']
4646
expect(req.options.proxy).to eq nil
4747
double(body: '{"foo": "bar"}', status: 200, headers: {})
4848
end
49-
requestor.request_all_flags()
49+
requestor.request_all_data()
5050
end
5151
end
5252
end

spec/stream_spec.rb

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,10 @@
11
require "spec_helper"
22
require 'ostruct'
33

4-
describe LaunchDarkly::InMemoryFeatureStore do
5-
subject { LaunchDarkly::InMemoryFeatureStore }
6-
7-
include LaunchDarkly
8-
9-
let(:store) { subject.new }
10-
let(:key) { :asdf }
11-
let(:feature) { { key: "asdf", value: "qwer", version: 0 } }
12-
13-
describe '#all' do
14-
it "will get all keys" do
15-
store.upsert(LaunchDarkly::FEATURES, feature)
16-
data = store.all(LaunchDarkly::FEATURES)
17-
expect(data).to eq(key => feature)
18-
end
19-
it "will not get deleted keys" do
20-
store.upsert(LaunchDarkly::FEATURES, feature)
21-
store.delete(LaunchDarkly::FEATURES, key, 1)
22-
data = store.all(LaunchDarkly::FEATURES)
23-
expect(data).to eq({})
24-
end
25-
end
26-
27-
describe '#initialized?' do
28-
it "will return whether the store has been initialized" do
29-
expect(store.initialized?).to eq false
30-
store.init(key => feature)
31-
expect(store.initialized?).to eq true
32-
end
33-
end
34-
end
35-
364
describe LaunchDarkly::StreamProcessor do
375
subject { LaunchDarkly::StreamProcessor }
386
let(:config) { LaunchDarkly::Config.new }
39-
let(:requestor) { LaunchDarkly::Requestor.new("sdk_key", config)}
7+
let(:requestor) { double() }
408
let(:processor) { subject.new("sdk_key", config, requestor) }
419

4210
describe '#process_message' do
@@ -45,6 +13,9 @@
4513
let(:patch_seg_message) { OpenStruct.new({data: '{"path": "/segments/key", "data": {"key": "asdf", "version": 1}}'}) }
4614
let(:delete_flag_message) { OpenStruct.new({data: '{"path": "/flags/key", "version": 2}'}) }
4715
let(:delete_seg_message) { OpenStruct.new({data: '{"path": "/segments/key", "version": 2}'}) }
16+
let(:indirect_patch_flag_message) { OpenStruct.new({data: "/flags/key"}) }
17+
let(:indirect_patch_segment_message) { OpenStruct.new({data: "/segments/key"}) }
18+
4819
it "will accept PUT methods" do
4920
processor.send(:process_message, put_message, LaunchDarkly::PUT)
5021
expect(config.feature_store.get(LaunchDarkly::FEATURES, "asdf")).to eq(key: "asdf")
@@ -68,6 +39,18 @@
6839
processor.send(:process_message, delete_seg_message, LaunchDarkly::DELETE)
6940
expect(config.feature_store.get(LaunchDarkly::SEGMENTS, "key")).to eq(nil)
7041
end
42+
it "will accept INDIRECT PATCH method for flags" do
43+
flag = { key: 'key', version: 1 }
44+
allow(requestor).to receive(:request_flag).with(flag[:key]).and_return(flag)
45+
processor.send(:process_message, indirect_patch_flag_message, LaunchDarkly::INDIRECT_PATCH);
46+
expect(config.feature_store.get(LaunchDarkly::FEATURES, flag[:key])).to eq(flag)
47+
end
48+
it "will accept INDIRECT PATCH method for segments" do
49+
segment = { key: 'key', version: 1 }
50+
allow(requestor).to receive(:request_segment).with(segment[:key]).and_return(segment)
51+
processor.send(:process_message, indirect_patch_segment_message, LaunchDarkly::INDIRECT_PATCH);
52+
expect(config.feature_store.get(LaunchDarkly::SEGMENTS, segment[:key])).to eq(segment)
53+
end
7154
it "will log a warning if the method is not recognized" do
7255
expect(processor.instance_variable_get(:@config).logger).to receive :warn
7356
processor.send(:process_message, put_message, "get")

0 commit comments

Comments
 (0)