Skip to content

Commit

Permalink
Delegate methods that accept keywords from Fog::Collection to Array c…
Browse files Browse the repository at this point in the history
…orrectly for Ruby 2.x and Ruby 3.x (#292)
  • Loading branch information
DimitriosLisenko authored Dec 22, 2023
1 parent ec543a5 commit 7c4a832
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fog/core/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def #{method}(*args)
end
super
end
ruby2_keywords(method) if respond_to?(:ruby2_keywords, true)
EOS
end

Expand All @@ -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

Expand Down
24 changes: 24 additions & 0 deletions spec/core/collection_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7c4a832

Please sign in to comment.