Tests for regular_url

pull/1338/head
Rick Carlino 2019-07-26 08:49:53 -05:00
parent 9535fd46b3
commit 3efb85ec92
2 changed files with 15 additions and 0 deletions

View File

@ -24,4 +24,13 @@ describe Image do
expect(url).to include("/images/attachments/000/000/123/x640/foo.jpg?")
expect(url).to include(now.to_i.to_s)
end
it "generates a URL when BUCKET is set" do
const_reassign(Image, :BUCKET, "foo") do
i = Image.new
expect(i).to receive(:attachment).and_return(Struct.new(:key).new("bar"))
url = i.regular_url
expect(url).to eq("https://storage.cloud.google.com/foo/bar")
end
end
end

View File

@ -117,8 +117,14 @@ end
# Reassign constants without getting a bunch of warnings to STDOUT.
# This is just for testing purposes, so NBD.
def const_reassign(target, const, value)
b4 = target.const_get(const)
target.send(:remove_const, const)
target.const_set(const, value)
if block_given?
yield
target.send(:remove_const, const)
target.const_set(const, b4)
end
end
class StubResp