diff --git a/app/helpers/administrate/application_helper.rb b/app/helpers/administrate/application_helper.rb index 56367390c4..d2c13c7ee4 100644 --- a/app/helpers/administrate/application_helper.rb +++ b/app/helpers/administrate/application_helper.rb @@ -20,13 +20,15 @@ def display_resource_name(resource_name) def svg_tag(asset, svg_id, options = {}) svg_attributes = { "xlink:href".freeze => "#{asset_url(asset)}##{svg_id}", - height: options[:height], - width: options[:width], - }.delete_if { |_key, value| value.nil? } + height: "100%", + width: "100%", + } xml_attributes = { "xmlns".freeze => "http://www.w3.org/2000/svg".freeze, "xmlns:xlink".freeze => "http://www.w3.org/1999/xlink".freeze, - } + height: options[:height], + width: options[:width], + }.delete_if { |_key, value| value.nil? } content_tag :svg, xml_attributes do content_tag :use, nil, svg_attributes diff --git a/spec/helpers/administrate/application_helper_spec.rb b/spec/helpers/administrate/application_helper_spec.rb index c424fa5f93..ad85de4583 100644 --- a/spec/helpers/administrate/application_helper_spec.rb +++ b/spec/helpers/administrate/application_helper_spec.rb @@ -50,18 +50,34 @@ expect(use_tag[0].attributes["xlink:href"].value).to eq("/logo.svg#logo") end + it "returns use tag with 100% height" do + svg_tag = build_svg_tag + use_tag = svg_tag.xpath("//svg//use['height']") + attribute = use_tag[0].attributes["height"] + + expect(attribute.value).to eq("100%") + end + + it "returns use tag with 100% width" do + svg_tag = build_svg_tag + use_tag = svg_tag.xpath("//svg//use['width']") + attribute = use_tag[0].attributes["width"] + + expect(attribute.value).to eq("100%") + end + context "with size attributes" do - it "returns use tag with height" do + it "returns svg tag with height" do svg_tag = build_svg_tag(height: 15) - use_tag = svg_tag.xpath("//svg//use['height']") + use_tag = svg_tag.xpath("//svg") attribute = use_tag[0].attributes["height"] expect(attribute.value).to eq("15") end - it "returns use tag with width" do + it "returns svg tag with width" do svg_tag = build_svg_tag(width: 20) - use_tag = svg_tag.xpath("//svg//use['width']") + use_tag = svg_tag.xpath("//svg") attribute = use_tag[0].attributes["width"] expect(attribute.value).to eq("20")