docbrown/spec/services/users/safe_remote_profile_image_url_spec.rb
Andy Zhao 84d931136e
Fix bug where OAuth signups were not pulling in OAuth provider's profile image (#14711)
* Use regex to replace with https

* Refactor a bit

* Update logic to handle edge cases

* url being nil
* url not a valid URL (weak validation, checks for starting
string of http)

* Add new test case for http to https conversion
2021-09-14 22:13:16 -04:00

25 lines
845 B
Ruby

require "rails_helper"
RSpec.describe Users::SafeRemoteProfileImageUrl, type: :service do
it "returns the url if passed for proper URLs" do
url = "https://image.com/image.png"
expect(described_class.call(url)).to eq(url)
end
it "returns fallback image if passed nil" do
expect(described_class.call(nil)).to start_with("https://emojipedia-us.s3")
end
it "returns fallback image if passed blank" do
expect(described_class.call("")).to start_with("https://emojipedia-us.s3")
end
it "returns fallback image if passed non-URL" do
expect(described_class.call("image")).to start_with("https://emojipedia-us.s3")
end
it "returns a secure HTTPS image link if pass a regular HTTP link" do
url = "http://image.com/image.jpg"
expect(described_class.call(url)).to eq "https://image.com/image.jpg"
end
end