about summary refs log tree commit diff
path: root/spec/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/feed_manager_spec.rb2
-rw-r--r--spec/lib/formatter_spec.rb13
-rw-r--r--spec/lib/language_detector_spec.rb12
-rw-r--r--spec/lib/ostatus/atom_serializer_spec.rb26
-rw-r--r--spec/lib/request_spec.rb2
5 files changed, 32 insertions, 23 deletions
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb
index a36ebad49..4c08e48ae 100644
--- a/spec/lib/feed_manager_spec.rb
+++ b/spec/lib/feed_manager_spec.rb
@@ -400,7 +400,7 @@ RSpec.describe FeedManager do
     end
 
     it 'sends push updates' do
-      status  = Fabricate(:status)
+      status = Fabricate(:status)
 
       FeedManager.instance.push_to_home(receiver, status)
 
diff --git a/spec/lib/formatter_spec.rb b/spec/lib/formatter_spec.rb
index 0c2248cae..ec4a6493d 100644
--- a/spec/lib/formatter_spec.rb
+++ b/spec/lib/formatter_spec.rb
@@ -170,12 +170,11 @@ RSpec.describe Formatter do
     end
   end
 
-
   describe '#format_spoiler' do
     subject { Formatter.instance.format_spoiler(status) }
 
     context 'given a post containing plain text' do
-      let(:status)  { Fabricate(:status, text: 'text', spoiler_text: 'Secret!', uri: nil) }
+      let(:status) { Fabricate(:status, text: 'text', spoiler_text: 'Secret!', uri: nil) }
 
       it 'Returns the spoiler text' do
         is_expected.to eq 'Secret!'
@@ -184,7 +183,7 @@ RSpec.describe Formatter do
 
     context 'given a post with an emoji shortcode at the start' do
       let!(:emoji) { Fabricate(:custom_emoji) }
-      let(:status)  { Fabricate(:status, text: 'text', spoiler_text: ':coolcat: Secret!', uri: nil) }
+      let(:status) { Fabricate(:status, text: 'text', spoiler_text: ':coolcat: Secret!', uri: nil) }
       let(:text) { ':coolcat: Beep boop' }
 
       it 'converts the shortcode to an image tag' do
@@ -207,7 +206,7 @@ RSpec.describe Formatter do
       end
 
       context 'given a post containing plain text' do
-        let(:status)  { Fabricate(:status, text: 'text', uri: nil) }
+        let(:status) { Fabricate(:status, text: 'text', uri: nil) }
 
         it 'paragraphizes the text' do
           is_expected.to eq '<p>text</p>'
@@ -215,7 +214,7 @@ RSpec.describe Formatter do
       end
 
       context 'given a post containing line feeds' do
-        let(:status)  { Fabricate(:status, text: "line\nfeed", uri: nil) }
+        let(:status) { Fabricate(:status, text: "line\nfeed", uri: nil) }
 
         it 'removes line feeds' do
           is_expected.not_to include "\n"
@@ -367,7 +366,7 @@ RSpec.describe Formatter do
     subject { Formatter.instance.plaintext(status) }
 
     context 'given a post with local status' do
-      let(:status)  { Fabricate(:status, text: '<p>a text by a nerd who uses an HTML tag in text</p>', uri: nil) }
+      let(:status) { Fabricate(:status, text: '<p>a text by a nerd who uses an HTML tag in text</p>', uri: nil) }
 
       it 'returns the raw text' do
         is_expected.to eq '<p>a text by a nerd who uses an HTML tag in text</p>'
@@ -375,7 +374,7 @@ RSpec.describe Formatter do
     end
 
     context 'given a post with remote status' do
-      let(:status)  { Fabricate(:status, account: remote_account, text: '<script>alert("Hello")</script>') }
+      let(:status) { Fabricate(:status, account: remote_account, text: '<script>alert("Hello")</script>') }
 
       it 'returns tag-stripped text' do
         is_expected.to eq ''
diff --git a/spec/lib/language_detector_spec.rb b/spec/lib/language_detector_spec.rb
index d00d2a0e6..0fa2a59ef 100644
--- a/spec/lib/language_detector_spec.rb
+++ b/spec/lib/language_detector_spec.rb
@@ -42,6 +42,7 @@ describe LanguageDetector do
 
   describe 'detect' do
     let(:account_without_user_locale) { Fabricate(:user, locale: nil).account }
+    let(:account_remote) { Fabricate(:account, domain: 'joinmastodon.org') }
 
     it 'detects english language for basic strings' do
       strings = [
@@ -90,7 +91,7 @@ describe LanguageDetector do
         end
 
         it 'uses nil when account is present but has no locale' do
-          result  = described_class.instance.detect('', account_without_user_locale)
+          result = described_class.instance.detect('', account_without_user_locale)
 
           expect(result).to eq nil
         end
@@ -104,6 +105,15 @@ describe LanguageDetector do
         end
       end
 
+      describe 'remote user' do
+        it 'nil for foreign user when language is not present' do
+          string = '안녕하세요'
+          result = described_class.instance.detect(string, account_remote)
+
+          expect(result).to eq nil
+        end
+      end
+
       describe 'with a non-`en` default locale' do
         around(:each) do |example|
           before = I18n.default_locale
diff --git a/spec/lib/ostatus/atom_serializer_spec.rb b/spec/lib/ostatus/atom_serializer_spec.rb
index 0bd22880e..891871c1c 100644
--- a/spec/lib/ostatus/atom_serializer_spec.rb
+++ b/spec/lib/ostatus/atom_serializer_spec.rb
@@ -728,9 +728,9 @@ RSpec.describe OStatus::AtomSerializer do
     it 'appends id element with unique tag' do
       block = Fabricate(:block)
 
-      time_before = Time.now
+      time_before = Time.zone.now
       block_salmon = OStatus::AtomSerializer.new.block_salmon(block)
-      time_after = Time.now
+      time_after = Time.zone.now
 
       expect(block_salmon.id.text).to(
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
@@ -815,9 +815,9 @@ RSpec.describe OStatus::AtomSerializer do
     it 'appends id element with unique tag' do
       block = Fabricate(:block)
 
-      time_before = Time.now
+      time_before = Time.zone.now
       unblock_salmon = OStatus::AtomSerializer.new.unblock_salmon(block)
-      time_after = Time.now
+      time_after = Time.zone.now
 
       expect(unblock_salmon.id.text).to(
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, block.id, 'Block'))
@@ -880,7 +880,7 @@ RSpec.describe OStatus::AtomSerializer do
 
       ProcessInteractionService.new.call(envelope, block.target_account)
 
-      expect{ block.reload }.to raise_error ActiveRecord::RecordNotFound
+      expect { block.reload }.to raise_error ActiveRecord::RecordNotFound
     end
   end
 
@@ -994,9 +994,9 @@ RSpec.describe OStatus::AtomSerializer do
     it 'appends id element with unique tag' do
       favourite = Fabricate(:favourite)
 
-      time_before = Time.now
+      time_before = Time.zone.now
       unfavourite_salmon = OStatus::AtomSerializer.new.unfavourite_salmon(favourite)
-      time_after = Time.now
+      time_after = Time.zone.now
 
       expect(unfavourite_salmon.id.text).to(
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, favourite.id, 'Favourite'))
@@ -1179,9 +1179,9 @@ RSpec.describe OStatus::AtomSerializer do
       follow = Fabricate(:follow)
       follow.destroy!
 
-      time_before = Time.now
+      time_before = Time.zone.now
       unfollow_salmon = OStatus::AtomSerializer.new.unfollow_salmon(follow)
-      time_after = Time.now
+      time_after = Time.zone.now
 
       expect(unfollow_salmon.id.text).to(
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow.id, 'Follow'))
@@ -1327,9 +1327,9 @@ RSpec.describe OStatus::AtomSerializer do
     it 'appends id element with unique tag' do
       follow_request = Fabricate(:follow_request)
 
-      time_before = Time.now
+      time_before = Time.zone.now
       authorize_follow_request_salmon = OStatus::AtomSerializer.new.authorize_follow_request_salmon(follow_request)
-      time_after = Time.now
+      time_after = Time.zone.now
 
       expect(authorize_follow_request_salmon.id.text).to(
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))
@@ -1396,9 +1396,9 @@ RSpec.describe OStatus::AtomSerializer do
     it 'appends id element with unique tag' do
       follow_request = Fabricate(:follow_request)
 
-      time_before = Time.now
+      time_before = Time.zone.now
       reject_follow_request_salmon = OStatus::AtomSerializer.new.reject_follow_request_salmon(follow_request)
-      time_after = Time.now
+      time_after = Time.zone.now
 
       expect(reject_follow_request_salmon.id.text).to(
         eq(OStatus::TagManager.instance.unique_tag(time_before.utc, follow_request.id, 'FollowRequest'))
diff --git a/spec/lib/request_spec.rb b/spec/lib/request_spec.rb
index 939ac006a..8cc5d90ce 100644
--- a/spec/lib/request_spec.rb
+++ b/spec/lib/request_spec.rb
@@ -84,7 +84,7 @@ describe Request do
         allow(Addrinfo).to receive(:foreach).with('example.com', nil, nil, :SOCK_STREAM)
                                             .and_yield(Addrinfo.new(["AF_INET", 0, "example.com", "0.0.0.0"], :PF_INET, :SOCK_STREAM))
                                             .and_yield(Addrinfo.new(["AF_INET6", 0, "example.com", "2001:db8::face"], :PF_INET6, :SOCK_STREAM))
-        expect{ subject.perform }.to raise_error Mastodon::ValidationError
+        expect { subject.perform }.to raise_error Mastodon::ValidationError
       end
     end
   end