Skip to content

Commit

Permalink
Display all gems if no gem scope specified on index
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshenny committed May 6, 2022
1 parent b9c7476 commit 50aa4be
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 17 deletions.
7 changes: 7 additions & 0 deletions app/helpers/api_keys_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module ApiKeysHelper
def gem_scope(api_key)
return if api_key.soft_deleted?

api_key.rubygem ? api_key.rubygem.name : t("api_keys.all_gems")
end
end
2 changes: 1 addition & 1 deletion app/views/api_keys/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<% end %>
</td>
<td class="owners__cell" data-title="Gem">
<%= api_key.rubygem&.name %>
<%= gem_scope(api_key) %>
</td>
<td class="owners__cell" data-title="Age">
<%= time_ago_in_words(api_key.created_at) %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ de:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ en:
enable_mfa: Enable MFA
rubygem_scope: Gem Scope
rubygem_scope_info: This scope restricts gem push/yank and owner add/remove commands to a specific gem.
all_gems: All Gems
reset:
success: "Deleted all API keys"
update:
Expand All @@ -106,8 +105,8 @@ en:
enable_mfa: Enable MFA
rubygem_scope: Gem Scope
rubygem_scope_info: This scope restricts gem push/yank and owner add/remove commands to a specific gem.
all_gems: All Gems
invalid_key: An invalid API key cannot be edited. Please delete it and create a new one.
all_gems: All Gems
clearance_mailer:
change_password:
title: CHANGE PASSWORD
Expand Down
3 changes: 1 addition & 2 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ es:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -111,8 +110,8 @@ es:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title: CAMBIAR CONTRASEÑA
Expand Down
3 changes: 1 addition & 2 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ fr:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -102,8 +101,8 @@ fr:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ ja:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -104,8 +103,8 @@ ja:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ nl:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -103,8 +102,8 @@ nl:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pt-BR:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -110,8 +109,8 @@ pt-BR:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ zh-CN:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -100,8 +99,8 @@ zh-CN:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 1 addition & 2 deletions config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ zh-TW:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
reset:
success:
update:
Expand All @@ -100,8 +99,8 @@ zh-TW:
enable_mfa:
rubygem_scope:
rubygem_scope_info:
all_gems:
invalid_key:
all_gems:
clearance_mailer:
change_password:
title:
Expand Down
3 changes: 3 additions & 0 deletions test/integration/api_keys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ApiKeysTest < SystemTest
click_button "Create"

assert page.has_content? "Note that we won't be able to show the key to you again. New API key:"
assert_equal @ownership.rubygem.name, page.find('.owners__cell[data-title="Gem"]').text
assert_equal @ownership.rubygem, @user.api_keys.last.rubygem
end

Expand Down Expand Up @@ -130,6 +131,7 @@ class ApiKeysTest < SystemTest
page.select "All Gems"
click_button "Update"

assert_equal "All Gems", page.find('.owners__cell[data-title="Gem"]').text
assert_nil api_key.reload.rubygem
end

Expand Down Expand Up @@ -250,6 +252,7 @@ class ApiKeysTest < SystemTest
assert_predicate api_key.reload, :soft_deleted?

refute page.has_button? "Edit"
assert_nil page.find('.owners__cell[data-title="Gem"]').text
visit_edit_profile_api_key_path(api_key)
assert page.has_content? "An invalid API key cannot be edited. Please delete it and create a new one."
assert_equal profile_api_keys_path, page.current_path
Expand Down
24 changes: 24 additions & 0 deletions test/unit/helpers/api_keys_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "test_helper"

class ApiKeysHelperTest < ActionView::TestCase
context "gem_scope" do
should "return gem name" do
@ownership = create(:ownership)
@api_key = create(:api_key, push_rubygem: true, user: @ownership.user, ownership: @ownership)

assert_equal @ownership.rubygem.name, gem_scope(@api_key)
end

should "return all gems if there is no scope specified" do
assert_equal "All Gems", gem_scope(create(:api_key))
end

should "return if key if gem ownership is removed" do
@ownership = create(:ownership)
@api_key = create(:api_key, push_rubygem: true, user: @ownership.user, ownership: @ownership)
@ownership.destroy!

assert_nil gem_scope(@api_key.reload)
end
end
end

0 comments on commit 50aa4be

Please sign in to comment.