From 62300b580ff492625b313c47ee7fca1a7eff71d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABrs=20Pirogovs?= Date: Mon, 25 Sep 2023 17:40:27 +0300 Subject: [PATCH 1/2] Support for legacy in-memory storage behavior - In memory storage - persists encoding for upload / download --- CHANGELOG.md | 5 +++++ lib/bucket_store/in_memory.rb | 10 ++++++++-- lib/bucket_store/version.rb | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 738d1c8..5ebdb77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/bucket_store/in_memory.rb b/lib/bucket_store/in_memory.rb index 8fd88fd..35a1948 100644 --- a/lib/bucket_store/in_memory.rb +++ b/lib/bucket_store/in_memory.rb @@ -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 { @@ -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 diff --git a/lib/bucket_store/version.rb b/lib/bucket_store/version.rb index 5195582..259b845 100644 --- a/lib/bucket_store/version.rb +++ b/lib/bucket_store/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module BucketStore - VERSION = "0.6.0" + VERSION = "0.6.1" end From b39b65fc21e5612f1393aa89dfd6e0000240845f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Art=C5=ABrs=20Pirogovs?= Date: Mon, 25 Sep 2023 19:03:21 +0300 Subject: [PATCH 2/2] Add specs --- spec/bucket_store_integration_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/bucket_store_integration_spec.rb b/spec/bucket_store_integration_spec.rb index 22eef94..d49d3f5 100644 --- a/spec/bucket_store_integration_spec.rb +++ b/spec/bucket_store_integration_spec.rb @@ -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) + + 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 + + include_examples "encoding persistance", Encoding::UTF_8 + include_examples "encoding persistance", Encoding::ISO_8859_1 + end end