Skip to content

Commit

Permalink
Use superscript star for a rubygem version with a tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
nvasilevski committed Aug 23, 2022
1 parent 894d5a0 commit 2f4b7bd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 9 additions & 1 deletion app/helpers/versions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def version_date_tag(version)
if version.rely_on_built_at?
klass << "tooltip__text"
data.merge!(tooltip: t("versions.index.imported_gem_version_notice", import_date: nice_date_for(Version::RUBYGEMS_IMPORT_DATE)))
text << " [?]"
end

content_tag(:small, text, class: klass, data: data)
Expand All @@ -15,4 +14,13 @@ def version_date_tag(version)
def version_authored_date(version)
"- #{nice_date_for(version.authored_at)}"
end

def version_number(version)
return version.number unless version.rely_on_built_at?

content_tag(:div) do
concat version.number
concat content_tag(:sup, "*")
end
end
end
2 changes: 1 addition & 1 deletion app/views/versions/_version.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<li class="gem__version-wrap">
<%= link_to version.number, rubygem_version_path(version.rubygem, version.slug), :class => 't-list__item' %>
<%= link_to version_number(version), rubygem_version_path(version.rubygem, version.slug), :class => 't-list__item gem__version__number' %>
<%= version_date_tag(version) %>
<% if version.platformed? %>
<span class="gem__version__date platform"><%= version.platform %></span>
Expand Down
9 changes: 6 additions & 3 deletions test/functional/versions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,22 @@ class VersionsControllerTest < ActionController::TestCase
setup do
@built_at = Date.parse("2000-01-01")
rubygem = create(:rubygem)
create(:version, rubygem: rubygem, created_at: Version::RUBYGEMS_IMPORT_DATE, built_at: @built_at)
create(:version, number: "1.1.2", rubygem: rubygem, created_at: Version::RUBYGEMS_IMPORT_DATE, built_at: @built_at)
get :index, params: { rubygem_id: rubygem.name }
end

should respond_with :success

should "show imported versions authored_at dates with an asterisk" do
should "show imported version number with an superscript asterisk and a tooltip" do
tooltip_text = <<~NOTICE.squish
This gem version was imported to RubyGems.org on July 25, 2009.
The date displayed was specified by the author in the gemspec.
NOTICE

assert_select ".gem__version__date", text: "- January 01, 2000 [?]", count: 1 do |elements|
assert_select ".gem__version__number", text: "1.1.2*", count: 1
assert_select ".gem__version__number sup", text: "*", count: 1

assert_select ".gem__version__date", text: "- January 01, 2000", count: 1 do |elements|
version = elements.first
assert_equal(tooltip_text, version["data-tooltip"])
end
Expand Down

0 comments on commit 2f4b7bd

Please sign in to comment.