about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-03 10:59:31 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-03 16:59:31 +0200
commit8c5ad23b24b17efc0660928d0b02ddbebc6f2939 (patch)
tree71177649c7f13ce16b80397f987a2ff9cfb97d65 /spec/lib
parent53384b0ffe4fd8cfcced4fe2945acd814c676088 (diff)
Language improvements, replace whatlanguage with CLD (#2753)
* add failing en specs

* add cld2 gem

* Replace WhatLanguage with CLD
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/language_detector_spec.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/spec/lib/language_detector_spec.rb b/spec/lib/language_detector_spec.rb
index 5fb19a1e7..bd4e65ef8 100644
--- a/spec/lib/language_detector_spec.rb
+++ b/spec/lib/language_detector_spec.rb
@@ -3,11 +3,17 @@ require 'rails_helper'
 
 describe LanguageDetector do
   describe 'to_iso_s' do
-    it 'detects english language' do
-      string = 'Hello and welcome to mastodon'
-      result = described_class.new(string).to_iso_s
-
-      expect(result).to eq :en
+    it 'detects english language for basic strings' do
+      strings = [
+        "Hello and welcome to mastodon",
+        "I'd rather not!",
+        "a lot of people just want to feel righteous all the time and that's all that matters",
+      ]
+      strings.each do |string|
+        result = described_class.new(string).to_iso_s
+
+        expect(result).to eq(:en), string
+      end
     end
 
     it 'detects spanish language' do
@@ -19,15 +25,15 @@ describe LanguageDetector do
 
     describe 'when language can\'t be detected' do
       it 'confirm language engine cant detect' do
-        result = WhatLanguage.new(:all).language_iso('')
-        expect(result).to be_nil
+        result = CLD.detect_language('')
+        expect(result[:reliable]).to be false
       end
 
       describe 'because of a URL' do
         it 'uses default locale when sent just a URL' do
           string = 'http://example.com/media/2kFTgOJLXhQf0g2nKB4'
-          wl_result = WhatLanguage.new(:all).language_iso(string)
-          expect(wl_result).not_to eq :en
+          cld_result = CLD.detect_language(string)[:code]
+          expect(cld_result).not_to eq :en
 
           result = described_class.new(string).to_iso_s