Skip to content

Commit

Permalink
Fix kwargs vs options hash for Ruby 3.0 compatibility (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpenny committed Jul 20, 2023
1 parent 91923a6 commit 93a1400
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 52 deletions.
2 changes: 1 addition & 1 deletion spec/paperclip/io_adapters/uri_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@

it "calls open with read_timeout option" do
expect(@uri_opener)
.to receive(:open).with(@uri, read_timeout: 120).at_least(1).times
.to receive(:open).with(@uri, { read_timeout: 120 }).at_least(1).times
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/paperclip/paperclip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
context "Calling Paperclip.run with a logger" do
it "passes the defined logger if :log_command is set" do
Paperclip.options[:log_command] = true
expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", logger: Paperclip.logger).and_return(double(run: nil))
expect(Terrapin::CommandLine).to receive(:new).with("convert", "stuff", { logger: Paperclip.logger }).and_return(double(run: nil))
Paperclip.run("convert", "stuff")
end
end
Expand Down
163 changes: 113 additions & 50 deletions spec/paperclip/storage/s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,12 +395,22 @@ def counter
allow(@dummy.avatar).to receive(:s3_object).with(:thumbnail).and_return(object)

expect(object).to receive(:upload_file).
with(anything, content_type: "image/png",
acl: :"public-read")
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
},
)
expect(object).to receive(:upload_file).
with(anything, content_type: "image/png",
acl: :"public-read",
cache_control: "max-age=31557600")
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
cache_control: "max-age=31557600",
},
)
@dummy.save
end

Expand Down Expand Up @@ -445,20 +455,20 @@ def counter
it "uploads original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
{ content_type: "image/png" },
).and_return(true)
@dummy.avatar.reprocess!
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
{ content_type: "image/png" },
).and_return(true)
@dummy.avatar.reprocess!
end

it "doesn't upload original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
{ content_type: "image/png" },
).and_return(true)
@dummy.avatar.reprocess!
end
Expand Down Expand Up @@ -500,23 +510,29 @@ def counter
it "uploads original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
acl: :"public-read"
{
content_type: "image/png",
acl: :"public-read",
},
).and_return(true)
@dummy.avatar.reprocess!
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
acl: :"public-read"
{
content_type: "image/png",
acl: :"public-read",
},
).and_return(true)
@dummy.avatar.reprocess!
end

it "doesn't upload original" do
expect(@object).to receive(:upload_file).with(
anything,
content_type: "image/png",
acl: :"public-read"
{
content_type: "image/png",
acl: :"public-read",
},
).and_return(true)
@dummy.avatar.reprocess!
end
Expand Down Expand Up @@ -725,7 +741,7 @@ def counter
object = double
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:presigned_url).with(:get, expires_in: 3600)
expect(object).to receive(:presigned_url).with(:get, { expires_in: 3600 })
@dummy.avatar.expiring_url
end
end
Expand All @@ -740,8 +756,13 @@ def counter
object = double
allow(@dummy.avatar).to receive(:s3_object).and_return(object)
expect(object).to receive(:presigned_url).
with(:get, expires_in: 3600,
response_content_disposition: "inline")
with(
:get,
{
expires_in: 3600,
response_content_disposition: "inline",
},
)
@dummy.avatar.expiring_url
end
end
Expand All @@ -763,7 +784,13 @@ def counter
object = double
allow(@dummy.avatar).to receive(:s3_object).and_return(object)
expect(object).to receive(:presigned_url).
with(:get, expires_in: 3600, response_content_type: "image/png")
with(
:get,
{
expires_in: 3600,
response_content_type: "image/png",
},
)
@dummy.avatar.expiring_url
end
end
Expand Down Expand Up @@ -810,14 +837,14 @@ def counter
it "generates a url for the thumb" do
object = double
allow(@dummy.avatar).to receive(:s3_object).with(:thumb).and_return(object)
expect(object).to receive(:presigned_url).with(:get, expires_in: 1800)
expect(object).to receive(:presigned_url).with(:get, { expires_in: 1800 })
@dummy.avatar.expiring_url(1800, :thumb)
end

it "generates a url for the default style" do
object = double
allow(@dummy.avatar).to receive(:s3_object).with(:original).and_return(object)
expect(object).to receive(:presigned_url).with(:get, expires_in: 1800)
expect(object).to receive(:presigned_url).with(:get, { expires_in: 1800 })
@dummy.avatar.expiring_url(1800)
end
end
Expand Down Expand Up @@ -962,7 +989,7 @@ def counter
object = double
allow(@dummy.avatar).to receive(:s3_object).and_return(object)
expect(object).to receive(:upload_file).
with(anything, content_type: "image/png", acl: :"public-read")
with(anything, { content_type: "image/png", acl: :"public-read" })
@dummy.save
end

Expand Down Expand Up @@ -1122,10 +1149,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything,
content_type: "image/png",
acl: :"public-read",
cache_control: "max-age=31557600")
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
cache_control: "max-age=31557600",
},
)
@dummy.save
end

Expand Down Expand Up @@ -1163,10 +1194,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything,
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
metadata: { "color" => "red" })
metadata: { "color" => "red" },
},
)
@dummy.save
end

Expand Down Expand Up @@ -1204,10 +1239,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything,
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
metadata: { "color" => "red" })
metadata: { "color" => "red" },
},
)
@dummy.save
end

Expand Down Expand Up @@ -1246,10 +1285,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything,
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
storage_class: "reduced_redundancy")
storage_class: "reduced_redundancy",
},
)
@dummy.save
end

Expand Down Expand Up @@ -1342,9 +1385,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).with(style).and_return(object)

expect(object).to receive(:upload_file).
with(anything, content_type: "image/png",
acl: :"public-read",
storage_class: :reduced_redundancy)
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
storage_class: :reduced_redundancy,
},
)
end
@dummy.save
end
Expand Down Expand Up @@ -1387,7 +1435,7 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything, content_type: "image/png", acl: :"public-read")
with(anything, { content_type: "image/png", acl: :"public-read" })
@dummy.save
end

Expand Down Expand Up @@ -1426,9 +1474,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything, content_type: "image/png",
acl: :"public-read",
server_side_encryption: "AES256")
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
server_side_encryption: "AES256",
},
)
@dummy.save
end

Expand Down Expand Up @@ -1466,10 +1519,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything,
content_type: "image/png",
acl: :"public-read",
storage_class: :reduced_redundancy)
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
storage_class: :reduced_redundancy,
},
)
@dummy.save
end

Expand Down Expand Up @@ -1613,7 +1670,7 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything, content_type: "image/png", acl: :"public-read")
with(anything, { content_type: "image/png", acl: :"public-read" })
@dummy.save
end

Expand Down Expand Up @@ -1651,7 +1708,7 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).and_return(object)

expect(object).to receive(:upload_file).
with(anything, content_type: "image/png", acl: :private)
with(anything, { content_type: "image/png", acl: :private })
@dummy.save
end

Expand Down Expand Up @@ -1697,8 +1754,10 @@ class DummyCredentialProvider; end

expect(object).to receive(:upload_file).
with(anything,
content_type: "image/png",
acl: style == :thumb ? :public_read : :private)
{
content_type: "image/png",
acl: style == :thumb ? :public_read : :private
})
end
@dummy.save
end
Expand Down Expand Up @@ -1767,10 +1826,14 @@ class DummyCredentialProvider; end
allow(@dummy.avatar).to receive(:s3_object).with(style).and_return(object)

expect(object).to receive(:upload_file).
with(anything,
content_type: "image/png",
acl: :"public-read",
content_disposition: 'attachment; filename="Custom Avatar Name.png"')
with(
anything,
{
content_type: "image/png",
acl: :"public-read",
content_disposition: 'attachment; filename="Custom Avatar Name.png"',
},
)
end
@dummy.save
end
Expand Down

0 comments on commit 93a1400

Please sign in to comment.