about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChad Pytel <chad@thoughtbot.com>2017-04-07 14:19:16 -0400
committerChad Pytel <chad@thoughtbot.com>2017-04-07 14:23:18 -0400
commitad5ddd5e95062d0d5cd4bc56baff53698c598723 (patch)
tree4515ec60a05f2e8bf470b34bf035fb3eddf105b8
parent13c0077003288416b8cacd5d339f8796bc347f39 (diff)
Use I18n for media attachment validation errors
These are currently user facing errors, but are not localized. This adds the
ability for these messages to be localized.
-rw-r--r--app/services/post_status_service.rb4
-rw-r--r--config/locales/en.yml4
-rw-r--r--spec/services/post_status_service_spec.rb4
3 files changed, 8 insertions, 4 deletions
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index b8179f7dc..221aa42a3 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -37,11 +37,11 @@ class PostStatusService < BaseService
   def validate_media!(media_ids)
     return if media_ids.nil? || !media_ids.is_a?(Enumerable)
 
-    raise Mastodon::ValidationError, 'Cannot attach more than 4 files' if media_ids.size > 4
+    raise Mastodon::ValidationError, I18n.t('media_attachments.validations.too_many') if media_ids.size > 4
 
     media = MediaAttachment.where(status_id: nil).where(id: media_ids.take(4).map(&:to_i))
 
-    raise Mastodon::ValidationError, 'Cannot attach a video to a toot that already contains images' if media.size > 1 && media.find(&:video?)
+    raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if media.size > 1 && media.find(&:video?)
 
     media
   end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 742219df9..aa3a732f9 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -163,3 +163,7 @@ en:
     invalid_otp_token: Invalid two-factor code
   will_paginate:
     page_gap: "&hellip;"
+  media_attachments:
+    validations:
+      too_many: Cannot attach more than 4 files
+      images_and_video: Cannot attach a video to a status that already contains images
diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb
index 3fe878f63..0e39cd969 100644
--- a/spec/services/post_status_service_spec.rb
+++ b/spec/services/post_status_service_spec.rb
@@ -141,7 +141,7 @@ RSpec.describe PostStatusService do
       )
     end.to raise_error(
       Mastodon::ValidationError,
-      'Cannot attach more than 4 files',
+      I18n.t('media_attachments.validations.too_many'),
     )
   end
 
@@ -160,7 +160,7 @@ RSpec.describe PostStatusService do
       )
     end.to raise_error(
       Mastodon::ValidationError,
-      'Cannot attach a video to a toot that already contains images',
+      I18n.t('media_attachments.validations.images_and_video'),
     )
   end