-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from alphagov/refac-sync-4
Refactor versioning into service class
- Loading branch information
Showing
8 changed files
with
114 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
RSpec.describe Coordination::DocumentVersionCache do | ||
subject(:document_version_cache) { described_class.new("content-id", payload_version:) } | ||
|
||
let(:payload_version) { 1234 } | ||
let(:remote_version) { nil } | ||
|
||
let(:redis_client) { instance_double(Redis, get: nil, set: nil) } | ||
|
||
before do | ||
allow(Rails.application.config.redis_pool).to receive(:with).and_yield(redis_client) | ||
allow(redis_client).to receive(:get) | ||
.with("search_api_v2:latest_synced_version:content-id").and_return(remote_version) | ||
end | ||
|
||
describe "outdated?" do | ||
subject(:outdated) { document_version_cache.outdated? } | ||
|
||
context "when the remote version is newer" do | ||
let(:remote_version) { payload_version + 1 } | ||
|
||
it { is_expected.to be true } | ||
end | ||
|
||
context "when the remote version is the same" do | ||
let(:remote_version) { payload_version } | ||
|
||
it { is_expected.to be true } | ||
end | ||
|
||
context "when the remote version is older" do | ||
let(:remote_version) { payload_version - 1 } | ||
|
||
it { is_expected.to be false } | ||
end | ||
|
||
context "when there is no remote version" do | ||
let(:remote_version) { nil } | ||
|
||
it { is_expected.to be false } | ||
end | ||
|
||
context "when there is no payload version" do | ||
let(:payload_version) { nil } | ||
|
||
it { is_expected.to be false } | ||
end | ||
end | ||
|
||
describe "set_as_latest_synced_version" do | ||
it "sets the latest synced version" do | ||
document_version_cache.set_as_latest_synced_version | ||
|
||
expect(redis_client).to have_received(:set) | ||
.with("search_api_v2:latest_synced_version:content-id", 1234) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.