Skip to content

Commit

Permalink
Merge pull request #69 from imgix/fix-68
Browse files Browse the repository at this point in the history
Remove trailing widthless src in srcset generation
  • Loading branch information
jayeb authored Nov 21, 2018
2 parents 47b6c7a + 498de78 commit 8458c72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 0 additions & 2 deletions lib/imgix/rails/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def srcset(url_params: @url_params, widths: @widths)

"#{ix_image_url(@source, @path, srcset_url_params)} #{width}w"
end.join(', ')

srcsetvalue += ", #{ix_image_url(@source, @path, srcset_url_params.except(:w, :h))}"
end

@@standard_widths = nil
Expand Down
11 changes: 3 additions & 8 deletions spec/imgix/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@

it 'generates the expected number of srcset values' do
tag = Nokogiri::HTML.fragment(helper.ix_image_tag("image.jpg")).children[0]
expect(tag.attribute('srcset').value.split(',').size).to eq(31)
expect(tag.attribute('srcset').value.split(',').size).to eq(30)
end

it 'generates the excpected number of srcset values with custom srcset-width-tolerance' do
Expand All @@ -226,11 +226,6 @@ def get_standard_widths
expect(Foo.new.get_standard_widths.size).to eq(7)
end

it 'last value is a fallback image' do
tag = Nokogiri::HTML.fragment(helper.ix_image_tag("image.jpg", url_params: {page: 3, w: 600, h: 300})).children[0]
expect(tag.attribute('srcset').value.split(',').last).not_to match("w=|h=")
end

it 'correctly calculates `h` to maintain aspect ratio, when specified' do
tag = Nokogiri::HTML.fragment(helper.ix_image_tag('presskit/imgix-presskit.pdf', url_params: {page: 3, w: 600, h: 300})).children[0]
sources = tag.attribute('srcset').value.split(',')
Expand All @@ -249,7 +244,7 @@ def get_standard_widths
end

it 'generates the expected number of srcset values' do
expect(tag.attribute('srcset').value.split(',').size).to eq(9)
expect(tag.attribute('srcset').value.split(',').size).to eq(8)
end
end

Expand All @@ -259,7 +254,7 @@ def get_standard_widths
end

it 'generates the expected number of srcset values' do
expect(tag.attribute('srcset').value.split(',').size).to eq(2)
expect(tag.attribute('srcset').value.split(',').size).to eq(1)
end
end
end
Expand Down

0 comments on commit 8458c72

Please sign in to comment.