Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/ldclient-rb/requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@ def initialize(sdk_key, config)
end
end

def request_all_flags()
make_request("/sdk/latest-flags")
end

def request_flag(key)
make_request("/sdk/latest-flags/" + key)
end

def request_all_segments()
make_request("/sdk/latest-segments")
end

def request_segment(key)
make_request("/sdk/latest-segments/" + key)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ldclient-rb/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def process_message(message, method)
@initialized.make_true
@config.logger.info("[LDClient] Stream initialized (via indirect message)")
elsif method == INDIRECT_PATCH
key = feature_key_for_path(message.data)
key = key_for_path(FEATURES, message.data)
if key
@feature_store.upsert(FEATURES, @requestor.request_flag(key))
else
key = segment_key_for_path(message.data)
key = key_for_path(SEGMENTS, message.data)
if key
@feature_store.upsert(SEGMENTS, key, @requestor.request_segment(key))
@feature_store.upsert(SEGMENTS, @requestor.request_segment(key))
end
end
else
Expand Down
8 changes: 4 additions & 4 deletions spec/requestor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
allow(faraday).to receive(:get) do |*args, &block|
req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new)
block.call(req)
expect(args).to eq ['http://ld.com/sdk/latest-flags']
expect(args).to eq ['http://ld.com/sdk/latest-all']
expect(req.options.proxy[:uri]).to eq URI("http://proxy.com")
double(body: '{"foo": "bar"}', status: 200, headers: {})
end

requestor.request_all_flags()
requestor.request_all_data()
end
end
describe "without a proxy" do
Expand All @@ -42,11 +42,11 @@
allow(faraday).to receive(:get) do |*args, &block|
req = double(Faraday::Request, :headers => {}, :options => Faraday::RequestOptions.new)
block.call(req)
expect(args).to eq ['http://ld.com/sdk/latest-flags']
expect(args).to eq ['http://ld.com/sdk/latest-all']
expect(req.options.proxy).to eq nil
double(body: '{"foo": "bar"}', status: 200, headers: {})
end
requestor.request_all_flags()
requestor.request_all_data()
end
end
end
Expand Down
49 changes: 16 additions & 33 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
require "spec_helper"
require 'ostruct'

describe LaunchDarkly::InMemoryFeatureStore do
subject { LaunchDarkly::InMemoryFeatureStore }

include LaunchDarkly

let(:store) { subject.new }
let(:key) { :asdf }
let(:feature) { { key: "asdf", value: "qwer", version: 0 } }

describe '#all' do
it "will get all keys" do
store.upsert(LaunchDarkly::FEATURES, feature)
data = store.all(LaunchDarkly::FEATURES)
expect(data).to eq(key => feature)
end
it "will not get deleted keys" do
store.upsert(LaunchDarkly::FEATURES, feature)
store.delete(LaunchDarkly::FEATURES, key, 1)
data = store.all(LaunchDarkly::FEATURES)
expect(data).to eq({})
end
end

describe '#initialized?' do
it "will return whether the store has been initialized" do
expect(store.initialized?).to eq false
store.init(key => feature)
expect(store.initialized?).to eq true
end
end
end

describe LaunchDarkly::StreamProcessor do
subject { LaunchDarkly::StreamProcessor }
let(:config) { LaunchDarkly::Config.new }
let(:requestor) { LaunchDarkly::Requestor.new("sdk_key", config)}
let(:requestor) { double() }
let(:processor) { subject.new("sdk_key", config, requestor) }

describe '#process_message' do
Expand All @@ -45,6 +13,9 @@
let(:patch_seg_message) { OpenStruct.new({data: '{"path": "/segments/key", "data": {"key": "asdf", "version": 1}}'}) }
let(:delete_flag_message) { OpenStruct.new({data: '{"path": "/flags/key", "version": 2}'}) }
let(:delete_seg_message) { OpenStruct.new({data: '{"path": "/segments/key", "version": 2}'}) }
let(:indirect_patch_flag_message) { OpenStruct.new({data: "/flags/key"}) }
let(:indirect_patch_segment_message) { OpenStruct.new({data: "/segments/key"}) }

it "will accept PUT methods" do
processor.send(:process_message, put_message, LaunchDarkly::PUT)
expect(config.feature_store.get(LaunchDarkly::FEATURES, "asdf")).to eq(key: "asdf")
Expand All @@ -68,6 +39,18 @@
processor.send(:process_message, delete_seg_message, LaunchDarkly::DELETE)
expect(config.feature_store.get(LaunchDarkly::SEGMENTS, "key")).to eq(nil)
end
it "will accept INDIRECT PATCH method for flags" do
flag = { key: 'key', version: 1 }
allow(requestor).to receive(:request_flag).with(flag[:key]).and_return(flag)
processor.send(:process_message, indirect_patch_flag_message, LaunchDarkly::INDIRECT_PATCH);
expect(config.feature_store.get(LaunchDarkly::FEATURES, flag[:key])).to eq(flag)
end
it "will accept INDIRECT PATCH method for segments" do
segment = { key: 'key', version: 1 }
allow(requestor).to receive(:request_segment).with(segment[:key]).and_return(segment)
processor.send(:process_message, indirect_patch_segment_message, LaunchDarkly::INDIRECT_PATCH);
expect(config.feature_store.get(LaunchDarkly::SEGMENTS, segment[:key])).to eq(segment)
end
it "will log a warning if the method is not recognized" do
expect(processor.instance_variable_get(:@config).logger).to receive :warn
processor.send(:process_message, put_message, "get")
Expand Down