Skip to content

Commit 729f06b

Browse files
committed
Specs for Poll adapter
1 parent 9ccc5e8 commit 729f06b

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

spec/flipper/adapters/poll_spec.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'flipper/adapters/poll'
2+
require 'flipper/adapters/operation_logger'
3+
require 'active_support/notifications'
4+
5+
RSpec.describe Flipper::Adapters::Poll do
6+
let(:remote_adapter) do
7+
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
8+
end
9+
let(:local_adapter) do
10+
Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
11+
end
12+
let(:local) { Flipper.new(local_adapter) }
13+
let(:remote) { Flipper.new(remote_adapter) }
14+
let(:poll) { Flipper.new(subject) }
15+
16+
subject do
17+
described_class.new(local_adapter, remote_adapter, key: 'test', start_automatically: false)
18+
end
19+
20+
it_should_behave_like 'a flipper adapter'
21+
22+
it 'syncs features when poller has been synced' do
23+
remote.enable(:search)
24+
25+
subject.poller.sync # sync poller from remote
26+
27+
expect(subject.poller.adapter).to receive(:get_all).and_call_original
28+
expect(poll[:search].boolean_value).to be(true)
29+
expect(subject.features.sort).to eq(%w(search))
30+
end
31+
32+
it 'writes to both local and remote' do
33+
poll.enable(:search)
34+
35+
expect(local[:search].boolean_value).to be(true)
36+
expect(remote[:search].boolean_value).to be(true)
37+
end
38+
39+
it 'does not sync features with poller has not been synced' do
40+
# Perform initial sync
41+
subject.poller.sync
42+
subject.features
43+
44+
# Remote feature enabled, but poller has not synced yet
45+
remote.enable(:search)
46+
expect(subject.poller.adapter).to_not receive(:get_all)
47+
48+
expect(subject.features.sort).to eq(%w())
49+
end
50+
51+
describe '#sync' do
52+
it "performs initial sync and then does not sync during block" do
53+
remote.enable(:search)
54+
subject.poller.sync # Sync poller
55+
56+
subject.sync do
57+
expect(poll[:search].boolean_value).to be(true)
58+
59+
remote.enable(:stats)
60+
subject.poller.sync # Sync poller
61+
62+
expect(poll[:stats].boolean_value).to be(false)
63+
end
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)