Skip to content

Commit

Permalink
rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
jacklynhma committed Dec 15, 2024
1 parent 25412b2 commit 7680b1e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/helpers/url_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module UrlHelper
def append_https(url)
def prepend_https(url)
return "" if url.blank?
return url if url.start_with?("https://")
"https://#{url}"
Expand Down
6 changes: 3 additions & 3 deletions app/views/dashboards/_subject.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
<%= icon_tag("link", color: :primary, class: "w-6 text-orange mr-3") %>
<p class="text-neutral-800 dark:text-white"><%=
link_to(
truncate(append_https(user.homepage_url), length: 20),
h(append_https(user.homepage_url)),
truncate(prepend_https(user.homepage_url), length: 20),
h(prepend_https(user.homepage_url)),
rel: "nofollow",
data: { confirm: "You are about to be redirected #{h(append_https(user.homepage_url))}" }
data: { confirm: "You are about to be redirected #{h(prepend_https(user.homepage_url))}" }
)
%></p>
</div>
Expand Down
6 changes: 3 additions & 3 deletions app/views/profiles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
<p id="homepage-url">
<%=
link_to(
truncate(h(append_https(@user.homepage_url)),length: 20),
h(append_https(@user.homepage_url)),
truncate(h(prepend_https(@user.homepage_url)),length: 20),
h(prepend_https(@user.homepage_url)),
rel: "nofollow",
class: "profile__header__attribute t-link--black",
data: { confirm: "You are about to be redirected #{{h(append_https(user.homepage_url))}}" }
data: { confirm: "You are about to be redirected #{{h(prepend_https(user.homepage_url))}}" }
)
%>
</p>
Expand Down
10 changes: 5 additions & 5 deletions test/unit/helpers/url_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
require "test_helper"

class UrlHelperTest < ActionView::TestCase
context "append_https" do
context "prepend_https" do
should "return url if it begins with https" do
assert_equal "https://www.awesomesite.com", append_https("https://www.awesomesite.com")
assert_equal "https://www.awesomesite.com", prepend_https("https://www.awesomesite.com")
end
should "return empty string if url is empty" do
assert_equal "", append_https("")
assert_equal "", prepend_https("")
end

should "return link with https if it does not begin with https" do
assert_equal "https://javascript:alert('hello');", append_https("javascript:alert('hello');")
assert_equal "https://javascript:alert('hello');", prepend_https("javascript:alert('hello');")
end

should "return empty string if url is nil" do
assert_equal "", append_https(nil)
assert_equal "", prepend_https(nil)
end
end
end

0 comments on commit 7680b1e

Please sign in to comment.