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

Add funding links to sidebar #2522

Merged
merged 2 commits into from Oct 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/concerns/rubygem_searchable.rb
Expand Up @@ -35,6 +35,7 @@ def as_indexed_json(_options = {}) # rubocop:disable Metrics/MethodLength
source_code_uri: versioned_links&.source_code_uri,
bug_tracker_uri: versioned_links&.bug_tracker_uri,
changelog_uri: versioned_links&.changelog_uri,
funding_uri: versioned_links&.funding_uri,
yanked: versions.none?(&:indexed?),
summary: latest_version&.summary,
description: latest_version&.description,
Expand Down
3 changes: 2 additions & 1 deletion app/models/links.rb
Expand Up @@ -8,7 +8,8 @@ class Links
"wiki" => "wiki_uri",
"mail" => "mailing_list_uri",
"bugs" => "bug_tracker_uri",
"download" => "download_uri"
"download" => "download_uri",
"funding" => "funding_uri"
}.freeze

# Links available for non-indexed gems
Expand Down
1 change: 1 addition & 0 deletions app/models/rubygem.rb
Expand Up @@ -187,6 +187,7 @@ def payload(version = versions.most_recent, protocol = Gemcutter::PROTOCOL, host
"source_code_uri" => versioned_links.source_code_uri,
"bug_tracker_uri" => versioned_links.bug_tracker_uri,
"changelog_uri" => versioned_links.changelog_uri,
"funding_uri" => versioned_links.funding_uri,
"dependencies" => {
"development" => deps.select { |r| r.rubygem && r.scope == "development" },
"runtime" => deps.select { |r| r.rubygem && r.scope == "runtime" }
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Expand Up @@ -36,6 +36,7 @@ de:
docs: Dokumentation URL
mail: Mailingliste URL
wiki: Wiki URL
funding:
session:
password: Passwort
who: E-Mail oder Benutzername
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -44,6 +44,7 @@ en:
docs: Documentation URL
mail: Mailing List URL
wiki: Wiki URL
funding: Funding URL
sonalkr132 marked this conversation as resolved.
Show resolved Hide resolved
session:
password: Password
who: Email or Username
Expand Down
1 change: 1 addition & 0 deletions config/locales/es.yml
Expand Up @@ -44,6 +44,7 @@ es:
docs: URL de la documentación
mail: URL de la lista de correo
wiki: URL de la Wiki
funding:
session:
password: Contraseña
who: Correo electrónico o usuario
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Expand Up @@ -36,6 +36,7 @@ fr:
docs: URL de la documentation
mail: URL de la liste de diffusion
wiki: URL du wiki
funding:
session:
password: Mot de passe
who: Email ou pseudonyme
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Expand Up @@ -36,6 +36,7 @@ ja:
docs: ドキュメントのURL
mail: メーリングリストのURL
wiki: WikiのURL
funding:
session:
password: パスワード
who: Email又はユーザー名
Expand Down
1 change: 1 addition & 0 deletions config/locales/nl.yml
Expand Up @@ -36,6 +36,7 @@ nl:
docs: Documentatie-URL
mail: Mailing-list-URL
wiki: Wiki URL
funding:
session:
password: Wachtwoord
who: E-mail of Gebruikersnaam
Expand Down
1 change: 1 addition & 0 deletions config/locales/pt-BR.yml
Expand Up @@ -36,6 +36,7 @@ pt-BR:
docs: URL da Documentação
mail: URL da Lista de Emails
wiki: URL da Wiki
funding:
session:
password: Senha
who: Email ou Usuário
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-CN.yml
Expand Up @@ -36,6 +36,7 @@ zh-CN:
docs: 文档 URL
mail: 邮件列表 URL
wiki: Wiki URL
funding:
session:
password: 密码
who: Email / 账号
Expand Down
1 change: 1 addition & 0 deletions config/locales/zh-TW.yml
Expand Up @@ -36,6 +36,7 @@ zh-TW:
docs: 文件 URL
mail: 郵件群組 URL
wiki: Wiki URL
funding:
session:
password: 密碼
who: Email / 帳號
Expand Down
1 change: 1 addition & 0 deletions lib/elastic_searcher.rb
Expand Up @@ -99,6 +99,7 @@ def api_source
wiki_uri
documentation_uri
mailing_list_uri
funding_uri
source_code_uri
bug_tracker_uri
changelog_uri]
Expand Down
31 changes: 31 additions & 0 deletions test/unit/links_test.rb
Expand Up @@ -55,4 +55,35 @@ class LinksTest < ActiveSupport::TestCase

assert links.homepage_uri
end

context "metadata includes non whitelisted uri key" do
setup do
metadata = {
"homepage_uri" => "https://example.com",
"source_code_uri" => "https://example.com",
"wiki_uri" => "https://example.com",
"mailing_list_uri" => "https://example.com",
"bug_tracker_uri" => "https://example.com",
"funding_uri" => "https://example.com",
"documentation_uri" => "https://example.com",
"changelog_uri" => "https://example.com",
"non_whitelisted_uri" => "https://example.com"
}

version = build(:version, metadata: metadata)
rubygem = build(:rubygem, versions: [version])
@links = rubygem.links(version)
end

should "create method for whitelisted keys" do
whitelisted_keys = Links::LINKS.values.reject! { |k| k == "download_uri" }
whitelisted_keys.each do |key|
assert_equal "https://example.com", @links.send(key), "value doesn't match for method: #{key}"
end
end

should "not create method for non whitelisted key" do
refute @links.respond_to?("non_whitelisted_uri")
end
end
end
1 change: 1 addition & 0 deletions test/unit/pusher_test.rb
Expand Up @@ -317,6 +317,7 @@ class PusherTest < ActiveSupport::TestCase
"source_code_uri" => "http://example.com",
"bug_tracker_uri" => "http://example.com",
"changelog_uri" => nil,
"funding_uri" => nil,
"yanked" => false,
"summary" => "old summary",
"description" => "Some awesome gem",
Expand Down
24 changes: 21 additions & 3 deletions test/unit/rubygem_searchable_test.rb
Expand Up @@ -15,7 +15,16 @@ class RubygemSearchableTest < ActiveSupport::TestCase
number: "1.0.1",
rubygem: @rubygem,
summary: "some summary",
description: "some description")
description: "some description",
metadata: {
"homepage_uri" => "http://example.com",
"source_code_uri" => "http://example.com",
"wiki_uri" => "http://example.com",
"mailing_list_uri" => "http://example.com",
"bug_tracker_uri" => "http://example.com",
"funding_uri" => "http://example.com",
"documentation_uri" => "http://example.com"
})
end

should "return a hash" do
Expand All @@ -35,7 +44,15 @@ class RubygemSearchableTest < ActiveSupport::TestCase
authors: "Joe User",
info: "some description",
licenses: "MIT",
metadata: { "foo" => "bar" },
metadata: {
"homepage_uri" => "http://example.com",
"source_code_uri" => "http://example.com",
"wiki_uri" => "http://example.com",
"mailing_list_uri" => "http://example.com",
"bug_tracker_uri" => "http://example.com",
"funding_uri" => "http://example.com",
"documentation_uri" => "http://example.com"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you seem to have dropped the change for which we had to update metadata.

funding_uri: "HTTP://example.com"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you just tell me not to do that? #2522 (comment)

This test makes no sense to me, I'm sorry. Are you able to just push to this branch directly? I do not know anything about legacy metadata or broken tests, I just want to show a single link on an HTML page. 😭

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are testing if metadata uri keys are indexed to ES as expected. I have added some info about the key where the assert may fail.

sha: "b5d4045c3f466fa91fe2cc6abe79232a1a57cdf104f7a26e716e0a1e2789df78",
project_uri: "http://localhost/gems/example_gem",
gem_uri: "http://localhost/gems/example_gem-1.0.1.gem",
Expand All @@ -45,6 +62,7 @@ class RubygemSearchableTest < ActiveSupport::TestCase
mailing_list_uri: "http://example.com",
source_code_uri: "http://example.com",
bug_tracker_uri: "http://example.com",
sonalkr132 marked this conversation as resolved.
Show resolved Hide resolved
funding_uri: "http://example.com",
sonalkr132 marked this conversation as resolved.
Show resolved Hide resolved
yanked: false,
summary: "some summary",
description: "some description",
Expand All @@ -53,7 +71,7 @@ class RubygemSearchableTest < ActiveSupport::TestCase
}

expected_hash.each do |k, v|
assert_equal v, json[k]
assert_equal v, json[k], "value doesn't match for key: #{k}"
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion test/unit/rubygem_test.rb
Expand Up @@ -458,7 +458,8 @@ class RubygemTest < ActiveSupport::TestCase
"mailing_list_uri" => "http://example.com/mail",
"source_code_uri" => "http://example.com/code",
"bug_tracker_uri" => "http://example.com/bugs",
"changelog_uri" => "http://example.com/change"
"changelog_uri" => "http://example.com/change",
"funding_uri" => "http://example.com/funding"
}
)

Expand All @@ -471,6 +472,7 @@ class RubygemTest < ActiveSupport::TestCase
assert_equal "http://example.com/code", hash["source_code_uri"]
assert_equal "http://example.com/bugs", hash["bug_tracker_uri"]
assert_equal "http://example.com/change", hash["changelog_uri"]
assert_equal "http://example.com/funding", hash["funding_uri"]
end

should "return version documentation url if metadata and linkset docs is empty" do
Expand Down