Skip to content

Commit

Permalink
Fix broken sort arrow svg in the resource table
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangzinh authored and nickcharlton committed Mar 7, 2017
1 parent 74e490d commit e2ffce6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
10 changes: 6 additions & 4 deletions app/helpers/administrate/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 20 additions & 4 deletions spec/helpers/administrate/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e2ffce6

Please sign in to comment.