Skip to content

Commit

Permalink
AO3-4820-AO3-3810 i18n and tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
weeklies committed Apr 16, 2024
1 parent bb15e87 commit 6b452c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/models/skin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def clean_media
validate :valid_media
def valid_media
if media && media.is_a?(Array) && media.any? {|m| !MEDIA.include?(m)}
errors.add(:base, ts("We don't currently support the media type %{media}, sorry! If we should, please let Support know.", media: media.join(', ')))
errors.add(:base, :invalid_media, media: media.join(', '))

Check warning on line 96 in app/models/skin.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: app/models/skin.rb:96:59: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end
end

Expand All @@ -103,15 +103,15 @@ def valid_media
validate :valid_public_preview
def valid_public_preview
return true if (self.official? || !self.public? || self.icon_file_name)
errors.add(:base, ts("You need to upload a screencap if you want to share your skin."))
errors.add(:base, :no_public_preview)
end

validates :title, presence: true, uniqueness: { message: ts("must be unique"), case_sensitive: true }
validates :title, presence: true, uniqueness: { case_sensitive: true }

Check warning on line 109 in app/models/skin.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Uniqueness validation should have a unique index on the database column. Raw Output: app/models/skin.rb:109:3: C: Rails/UniqueValidationWithoutIndex: Uniqueness validation should have a unique index on the database column.
validate :allowed_title
def allowed_title
return true if (!self.title.match(/archive/i) || User.current_user.is_a?(Admin))
return true if !self.title.match(/archive/i) || User.current_user.is_a?(Admin)

errors.add(:base, ts("You can't use the word 'Archive' in your skin title, sorry! (We have to reserve it for official skins.)"))
errors.add(:base, :archive_in_title)
end

validates_numericality_of :margin, :base_em, allow_nil: true
Expand Down
9 changes: 9 additions & 0 deletions config/locales/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ en:
not_work: Only a link to a work can be listed as an inspiration.
protected: You can't use the related works function to cite works by the protected user %{login}.
format: "%{message}"
skin:
attributes:
base:
archive_in_title: You can't use the word 'Archive' in your skin title, sorry! (We have to reserve it for official skins.)
format: "%{message}"
invalid_media: We don't currently support the media type %{media}, sorry! If we should, please let Support know.
no_public_preview: You need to upload a screencap if you want to share your skin.
title:
taken: must be unique
skin/skin_parents:
attributes:
base:
Expand Down
2 changes: 1 addition & 1 deletion features/admins/admin_skins.feature
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Feature: Admin manage skins
Then I should not see "{ text-decoration: blink; }" in the page style

Scenario: Admin can edit a skin with the word "archive" in the title
Given the approved public skin "official archive skin" that has reserved words in the title
Given the approved public skin "official archive skin" has reserved words in the title
And I am logged in as a "superadmin" admin
When I go to "official archive skin" skin page
And I follow "Edit"
Expand Down
10 changes: 5 additions & 5 deletions features/step_definitions/skin_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@
Skin.load_site_css
end

Given /^the approved public skin "([^"]*)" with css "([^"]*)"$/ do |skin_name, css|
step "the unapproved public skin \"#{skin_name}\" with css \"#{css}\""
step "I approve the skin \"#{skin_name}\""
Given "the approved public skin {string} with css {string}" do |skin_name, css|
step %{the unapproved public skin "#{skin_name}" with css "#{css}"}
step %{I approve the skin "#{skin_name}"}
step "I am logged out"
end

Given /^the approved public skin "([^"]*)"$/ do |skin_name|
step "the approved public skin \"#{skin_name}\" with css #{DEFAULT_CSS}"
end

Given /^the approved public skin "(.*?)" that has reserved words in the title$/ do |skin_name|
Given "the approved public skin {string} has reserved words in the title" do |skin_name|
# Admins can't create skins, so we have to create it this way.
FactoryBot.build(:skin, title: skin_name, public: true).save!(validate: false)

step "I approve the skin \"#{skin_name}\""
step %{I approve the skin "#{skin_name}"}
step "I am logged out"
end

Expand Down

0 comments on commit 6b452c1

Please sign in to comment.