Skip to content

Commit

Permalink
Edge cases on including the size attributes on the image.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeering committed Apr 26, 2012
1 parent 6514ae6 commit 90c233a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/gravatar_image_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def gravatar_image_tag(email, options = {})
gravatar_overrides = options.delete(:gravatar)
options[:src] = GravatarImageTag::gravatar_url(email, gravatar_overrides)
options[:alt] ||= 'Gravatar'
options[:height] = options[:width] = "#{GravatarImageTag::gravatar_options(gravatar_overrides)[:size]}px" if GravatarImageTag.configuration.include_size_attributes
options[:height] = options[:width] = "#{GravatarImageTag::gravatar_options(gravatar_overrides)[:size] || 80}px" if GravatarImageTag.configuration.include_size_attributes
tag 'img', options, false, false # Patch submitted to rails to allow image_tag here https://rails.lighthouseapp.com/projects/8994/tickets/2878-image_tag-doesnt-allow-escape-false-option-anymore
end

Expand Down
18 changes: 16 additions & 2 deletions spec/gravatar_image_tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,24 @@
end

it 'should set the image tags height and width to avoid the page going all jiggy (technical term) when loading a page with lots of Gravatars' do
(!!view.gravatar_image_tag(email).match(/height="50px"/)).should be_true
(!!view.gravatar_image_tag(email).match(/width="50px"/)).should be_true
GravatarImageTag.configure { |c| c.size = 30 }
(!!view.gravatar_image_tag(email).match(/height="30px"/)).should be_true
(!!view.gravatar_image_tag(email).match(/width="30px"/)).should be_true
end

it 'should set the image tags height and width attributes to 80px (gravatars default) if no size is given.' do
GravatarImageTag.configure { |c| c.size = nil }
(!!view.gravatar_image_tag(email).match(/height="80px"/)).should be_true
(!!view.gravatar_image_tag(email).match(/width="80px"/)).should be_true
end

it 'should set the image tags height and width attributes from the overrides on the size' do
GravatarImageTag.configure { |c| c.size = 120 }
(!!view.gravatar_image_tag(email, :gravatar => { :size => 45 }).match(/height="45px"/)).should be_true
(!!view.gravatar_image_tag(email, :gravatar => { :size => 75 }).match(/width="75px"/)).should be_true
end


it 'should not include the height and width attributes on the image tag if it is turned off in the configuration' do
GravatarImageTag.configure { |c| c.include_size_attributes = false }
(!!view.gravatar_image_tag(email).match(/height=/)).should be_false
Expand Down

0 comments on commit 90c233a

Please sign in to comment.