Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken sort arrow svg in the resource table #687

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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