Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for legacy in-memory storage behavior. In memory storage - persists encoding for upload / download #69

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v0.6.1
------
- Support for legacy in-memory storage behavior
* In memory storage - persists encoding for upload / download

v0.6.0
------
- [BREAKING] Remove support for Ruby 2.6
Expand Down
10 changes: 8 additions & 2 deletions lib/bucket_store/in_memory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def reset!

def upload!(bucket:, key:, file:)
file.tap do |f|
@buckets[bucket][key] = f.read
@buckets[bucket][key] = {
data: f.read,
encoding: file.external_encoding,
}
end

{
Expand All @@ -37,7 +40,10 @@ def upload!(bucket:, key:, file:)

def download(bucket:, key:, file:)
file.tap do |f|
f.write(@buckets[bucket].fetch(key))
f.set_encoding(
@buckets[bucket].fetch(key).fetch(:encoding),
)
f.write(@buckets[bucket].fetch(key).fetch(:data))
f.rewind
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bucket_store/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module BucketStore
VERSION = "0.6.0"
VERSION = "0.6.1"
end
23 changes: 23 additions & 0 deletions spec/bucket_store_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,27 @@
include_examples "adapter integration", "disk://bucket"
include_examples "adapter integration", "s3://bucket"
include_examples "adapter integration", "gs://bucket"

context "inmemory storage" do
let(:bucket_store) { described_class.for("#{base_bucket_uri}/#{temp_filename}") }
let(:base_bucket_uri) { "inmemory://bucket" }
let(:temp_filename) { "temp-file" }

shared_examples "encoding persistance" do |encoding|
it "persists encoding between upload/download for #{encoding}", :aggregate_failures do
upload_data = String.new("some string", encoding: encoding)
bucket_store.upload!(upload_data)
download = bucket_store.download
download_data = download.fetch(:content)
Comment on lines +193 to +196
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With let(:upload_data) string encoding bleeds out into the next test and fails 🤷


expect(upload_data.encoding).to eq(encoding)
expect(download_data.encoding).to eq(encoding)
expect(upload_data).to eq(download_data)
expect(upload_data.object_id).to_not eq(download_data.object_id)
end
end
Comment on lines +186 to +203
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be part of the shared examples and not specific of the in-memory adapter as otherwise we can't guarantee that the adapters behave in the same way.


include_examples "encoding persistance", Encoding::UTF_8
include_examples "encoding persistance", Encoding::ISO_8859_1
end
end