From 7c4a8320da5ecad884e4ee32b6baf41de5410ee5 Mon Sep 17 00:00:00 2001 From: DimitriosLisenko Date: Fri, 22 Dec 2023 15:18:17 +0000 Subject: [PATCH] Delegate methods that accept keywords from Fog::Collection to Array correctly for Ruby 2.x and Ruby 3.x (#292) --- lib/fog/core/collection.rb | 2 ++ spec/core/collection_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 spec/core/collection_spec.rb diff --git a/lib/fog/core/collection.rb b/lib/fog/core/collection.rb index 7441958..b2799c4 100644 --- a/lib/fog/core/collection.rb +++ b/lib/fog/core/collection.rb @@ -19,6 +19,7 @@ def #{method}(*args) end super end + ruby2_keywords(method) if respond_to?(:ruby2_keywords, true) EOS end @@ -31,6 +32,7 @@ def #{method}(*args) data = super self.clone.clear.concat(data) end + ruby2_keywords(method) if respond_to?(:ruby2_keywords, true) EOS end diff --git a/spec/core/collection_spec.rb b/spec/core/collection_spec.rb new file mode 100644 index 0000000..acea928 --- /dev/null +++ b/spec/core/collection_spec.rb @@ -0,0 +1,24 @@ +require "spec_helper" +require "securerandom" + +class FogTestModelForCollection < Fog::Model + identity :id +end + +class FogTestCollection < Fog::Collection + model FogTestModelForCollection + + def all + self + end +end + +describe Fog::Collection do + describe "array delegation" do + it "delegates methods with keywords to Array" do + c = FogTestCollection.new + c << FogTestModelForCollection.new(id: SecureRandom.hex) + assert_equal c.sample(1, random: Random)[0], c[0] + end + end +end