Skip to content

Commit

Permalink
Merge pull request hotsh#611 from chrismdp/master
Browse files Browse the repository at this point in the history
Upped gravatars and image protocols to https by default
  • Loading branch information
carols10cents committed Aug 31, 2012
2 parents c5342ad + 12a5db5 commit bfeb44e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
7 changes: 6 additions & 1 deletion app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Author

# Normalize the domain so we can use them the same way
before_save :normalize_domain
before_save :https_image_url

# The Author has a profile and with that various entries
key :name, String
Expand Down Expand Up @@ -202,7 +203,7 @@ def display_name
# Query described [here](http://en.gravatar.com/site/implement/images/#default-image).
def gravatar_url
email_digest = Digest::MD5.hexdigest email
"http://#{GRAVATAR}/avatar/#{email_digest}?s=48&r=r&d=#{ENCODED_DEFAULT_AVATAR}"
"https://#{GRAVATAR}/avatar/#{email_digest}?s=48&r=r&d=#{ENCODED_DEFAULT_AVATAR}"
end

# Returns an OStatus::Author instance describing this author model
Expand Down Expand Up @@ -246,6 +247,10 @@ def normalize_domain
self.domain = norm
end

def https_image_url
self.image_url.sub!(/^http:/, 'https:') if self.image_url.present?
end

def to_param
username
end
Expand Down
20 changes: 16 additions & 4 deletions test/models/author_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
assert_equal @author.remote_url, @author.url
end

it "ensures that image_url is always https" do
@author.image_url = 'http://example.net/cool-avatar'
@author.save!
assert_equal 'https://example.net/cool-avatar', @author.image_url
end

it "ensures that https image_urls are untouched" do
@author.image_url = 'https://example.net/cool-avatar'
@author.save!
assert_equal 'https://example.net/cool-avatar', @author.image_url
end

describe "#fully_qualified_name" do

it "returns simple name if a local user" do
Expand All @@ -47,14 +59,14 @@
describe "#avatar_url" do

it "returns image_url as avatar_url if image_url is set" do
image_url = 'http://example.net/cool-avatar'
image_url = 'https://example.net/cool-avatar'
@author.image_url = image_url
assert_equal image_url, @author.avatar_url
assert_equal 'https://example.net/cool-avatar', @author.avatar_url
end

it "returns a gravatar if there is an email and image_url is not set" do
it "returns https gravatar if there is an email and image_url is not set" do
@author.email = "[email protected]"
assert_match 'http://gravatar.com/', @author.avatar_url
assert_match 'https://gravatar.com/', @author.avatar_url
end

it "uses the default avatar if neither image_url nor email is set" do
Expand Down

0 comments on commit bfeb44e

Please sign in to comment.