about summary refs log tree commit diff
path: root/spec/validators
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-03-02 12:06:58 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-03-02 12:06:58 +0100
commitd8fdbb054e30f6e8e505bce63e5f150bf117cd8e (patch)
tree0a671ee6c8a7644e6613dd87798f661f4703e8fe /spec/validators
parent4aa860b65bd796b09dc0ceffa1fdd7de31060a34 (diff)
parent65db2625508c220fd3c0a1f37cdd2e13b6e02987 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `app/validators/status_length_validator.rb`:
  Upstream changes too close to glitch-soc MAX_CHARS changes, but not a real
  conflict.
  Applied upstream changes.
- `package.json`:
  glitch-soc-only dependency textually too close to a dependency updated
  upstream, not a real conflict.
  Applied upstream changes.
Diffstat (limited to 'spec/validators')
-rw-r--r--spec/validators/blacklisted_email_validator_spec.rb4
-rw-r--r--spec/validators/status_length_validator_spec.rb8
-rw-r--r--spec/validators/unreserved_username_validator_spec.rb8
3 files changed, 14 insertions, 6 deletions
diff --git a/spec/validators/blacklisted_email_validator_spec.rb b/spec/validators/blacklisted_email_validator_spec.rb
index f0708dc46..53b355a57 100644
--- a/spec/validators/blacklisted_email_validator_spec.rb
+++ b/spec/validators/blacklisted_email_validator_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do
       let(:blocked_email) { true }
 
       it 'calls errors.add' do
-        expect(errors).to have_received(:add).with(:email, I18n.t('users.blocked_email_provider'))
+        expect(errors).to have_received(:add).with(:email, :blocked)
       end
     end
 
@@ -25,7 +25,7 @@ RSpec.describe BlacklistedEmailValidator, type: :validator do
       let(:blocked_email) { false }
 
       it 'not calls errors.add' do
-        expect(errors).not_to have_received(:add).with(:email, I18n.t('users.blocked_email_provider'))
+        expect(errors).not_to have_received(:add).with(:email, :blocked)
       end
     end
   end
diff --git a/spec/validators/status_length_validator_spec.rb b/spec/validators/status_length_validator_spec.rb
index 62791cd2f..643ea6d22 100644
--- a/spec/validators/status_length_validator_spec.rb
+++ b/spec/validators/status_length_validator_spec.rb
@@ -47,6 +47,14 @@ describe StatusLengthValidator do
       expect(status.errors).to_not have_received(:add)
     end
 
+    it 'does not count non-autolinkable URLs as 23 characters flat' do
+      text   = ('a' * 476) + "http://#{'b' * 30}.com/example"
+      status = double(spoiler_text: '', text: text, errors: double(add: nil), local?: true, reblog?: false)
+
+      subject.validate(status)
+      expect(status.errors).to have_received(:add)
+    end
+
     it 'counts only the front part of remote usernames' do
       username = '@alice'
       chars = StatusLengthValidator::MAX_CHARS - 1 - username.length
diff --git a/spec/validators/unreserved_username_validator_spec.rb b/spec/validators/unreserved_username_validator_spec.rb
index 0187941b0..cabd6d386 100644
--- a/spec/validators/unreserved_username_validator_spec.rb
+++ b/spec/validators/unreserved_username_validator_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe UnreservedUsernameValidator, type: :validator do
     let(:account)   { double(username: username, errors: errors) }
     let(:errors )   { double(add: nil) }
 
-    context '@username.nil?' do
+    context '@username.blank?' do
       let(:username)  { nil }
 
       it 'not calls errors.add' do
@@ -21,14 +21,14 @@ RSpec.describe UnreservedUsernameValidator, type: :validator do
       end
     end
 
-    context '!@username.nil?' do
-      let(:username)  { '' }
+    context '!@username.blank?' do
+      let(:username)  { 'f' }
 
       context 'reserved_username?' do
         let(:reserved_username) { true }
 
         it 'calls erros.add' do
-          expect(errors).to have_received(:add).with(:username, I18n.t('accounts.reserved_username'))
+          expect(errors).to have_received(:add).with(:username, :reserved)
         end
       end