diff --git a/lib/imgix/rails/tag.rb b/lib/imgix/rails/tag.rb index 673b8db..87f2026 100644 --- a/lib/imgix/rails/tag.rb +++ b/lib/imgix/rails/tag.rb @@ -16,16 +16,16 @@ def initialize(path, source: nil, tag_options: {}, url_params: {}, srcset_option protected - def srcset(source: @source, path: @path, url_params: @url_params, srcset_options: @srcset_options, tag_options: @tag_options) + def srcset(source: @source, path: @path, url_params: @url_params, srcset_options: @srcset_options) params = url_params.clone width_tolerance = ::Imgix::Rails.config.imgix[:srcset_width_tolerance] - min_width = @srcset_options[:min_width] - max_width = @srcset_options[:max_width] - widths = @srcset_options[:widths] - disable_variable_quality = @srcset_options[:disable_variable_quality] - options = { widths: widths, width_tolerance: width_tolerance, min_width: min_width, max_width: max_width, disable_variable_quality: disable_variable_quality} + min_width = srcset_options[:min_width] + max_width = srcset_options[:max_width] + widths = srcset_options[:widths] + disable_variable_quality = srcset_options[:disable_variable_quality] + options = {widths: widths, width_tolerance: width_tolerance, min_width: min_width, max_width: max_width, disable_variable_quality: disable_variable_quality} - ix_image_srcset(@source, @path, params, options) + ix_image_srcset(source, path, params, options) end end diff --git a/spec/imgix/rails_spec.rb b/spec/imgix/rails_spec.rb index bdd36f2..0954eff 100644 --- a/spec/imgix/rails_spec.rb +++ b/spec/imgix/rails_spec.rb @@ -610,6 +610,39 @@ expect(tag.children[1].attribute('src').value).not_to include('widths') end end + + context 'breakpoint overrides' do + let(:tag) do + picture_tag = helper.ix_picture_tag( + 'bertandernie.jpg', + srcset_options: { + widths: [100,200] + }, + breakpoints: { + "800px": { + srcset_options: { + widths: [600,700] + } + } + } + ) + Nokogiri::HTML.fragment(picture_tag).children[0] + end + + it 'uses base settings on img tag' do + expect(tag.children[1].attribute('srcset').value).to include('100w') + expect(tag.children[1].attribute('srcset').value).to include('200w') + expect(tag.children[1].attribute('srcset').value).not_to include('600w') + expect(tag.children[1].attribute('srcset').value).not_to include('700w') + end + + it 'uses breakpoint override on source tag' do + expect(tag.children[0].attribute('srcset').value).not_to include('100w') + expect(tag.children[0].attribute('srcset').value).not_to include('200w') + expect(tag.children[0].attribute('srcset').value).to include('600w') + expect(tag.children[0].attribute('srcset').value).to include('700w') + end + end end context 'with img_tag_options' do