Skip to content

Commit

Permalink
Avoid any possibility of sync writing back to remote
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Jul 21, 2023
1 parent aef3275 commit 45ef4ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 3 additions & 6 deletions lib/flipper/cloud/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ def sync_method
private

def app_adapter
sync_method == :webhook ? dual_write_adapter : poll_adapter
end

def dual_write_adapter
Flipper::Adapters::DualWrite.new(local_adapter, http_adapter)
read_adapter = sync_method == :webhook ? local_adapter : poll_adapter
Flipper::Adapters::DualWrite.new(read_adapter, http_adapter)
end

def poller
Expand All @@ -172,7 +169,7 @@ def poller
end

def poll_adapter
Flipper::Adapters::Poll.new(poller, dual_write_adapter)
Flipper::Adapters::Poll.new(poller, local_adapter)
end

def http_adapter
Expand Down
2 changes: 1 addition & 1 deletion spec/flipper/cloud/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
stub_request(:get, /flippercloud\.io/).to_return(status: 200, body: "{}")

instance = described_class.new(required_options)
expect(instance.adapter).to be_instance_of(Flipper::Adapters::Poll)
expect(instance.adapter).to be_instance_of(Flipper::Adapters::DualWrite)
end

it "can override adapter block" do
Expand Down
15 changes: 9 additions & 6 deletions spec/flipper/cloud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
it 'configures the correct adapter' do
# pardon the nesting...
memoized_adapter = @instance.adapter
poll_adapter = memoized_adapter.adapter
dual_write_adapter = poll_adapter.adapter

expect(poll_adapter).to be_instance_of(Flipper::Adapters::Poll)
dual_write_adapter = memoized_adapter.adapter
expect(dual_write_adapter).to be_instance_of(Flipper::Adapters::DualWrite)
poll_adapter = dual_write_adapter.local
expect(poll_adapter).to be_instance_of(Flipper::Adapters::Poll)

http_adapter = dual_write_adapter.remote
client = http_adapter.client
Expand All @@ -43,8 +42,12 @@

context 'initialize with token and options' do
it 'sets correct url' do
@instance = described_class.new(token: 'asdf', url: 'https://www.fakeflipper.com/sadpanda')
uri = @instance.adapter.adapter.adapter.remote.client.uri
instance = described_class.new(token: 'asdf', url: 'https://www.fakeflipper.com/sadpanda')
# pardon the nesting...
memoized = instance.adapter
dual_write = memoized.adapter
remote = dual_write.remote
uri = remote.client.uri
expect(uri.scheme).to eq('https')
expect(uri.host).to eq('www.fakeflipper.com')
expect(uri.path).to eq('/sadpanda')
Expand Down

0 comments on commit 45ef4ab

Please sign in to comment.