about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorJenkins <jenkins@jenkins.ninjawedding.org>2018-03-09 00:17:17 +0000
committerJenkins <jenkins@jenkins.ninjawedding.org>2018-03-09 00:17:17 +0000
commit447d7e612753d69f043e08ebb228b21e411c8b4a (patch)
tree80caebcff2b131898f620f89ad0858d44530d30f /spec
parent43a9a781a443a6b9296431fbcc4285b3ca6a1a57 (diff)
parentff44b2e92d496c6027b20157fea6ebd885906bea (diff)
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/concerns/localized_spec.rb53
-rw-r--r--spec/controllers/home_controller_spec.rb15
-rw-r--r--spec/helpers/instance_helper_spec.rb6
-rw-r--r--spec/lib/activitypub/activity/add_spec.rb29
-rw-r--r--spec/lib/activitypub/activity/create_spec.rb29
-rw-r--r--spec/lib/activitypub/activity/remove_spec.rb30
-rw-r--r--spec/lib/activitypub/activity/update_spec.rb1
7 files changed, 110 insertions, 53 deletions
diff --git a/spec/controllers/concerns/localized_spec.rb b/spec/controllers/concerns/localized_spec.rb
index c917ce85e..f71c96aff 100644
--- a/spec/controllers/concerns/localized_spec.rb
+++ b/spec/controllers/concerns/localized_spec.rb
@@ -16,49 +16,24 @@ describe ApplicationController, type: :controller do
   end
 
   shared_examples 'default locale' do
-    context 'when DEFAULT_LOCALE environment variable is set' do
-      around do |example|
-        ClimateControl.modify 'DEFAULT_LOCALE' => 'ca', &example.method(:run)
-        I18n.locale = I18n.default_locale
-      end
+    after { I18n.locale = I18n.default_locale }
 
-      it 'sets language specified by ENV if preferred' do
-        request.headers['Accept-Language'] = 'ca, fa'
-        get 'success'
-        expect(I18n.locale).to eq :ca
-      end
-
-      it 'sets available and preferred language if language specified by ENV is not preferred' do
-        request.headers['Accept-Language'] = 'ca-ES, fa'
-        get 'success'
-        expect(I18n.locale).to eq :fa
-      end
-
-      it 'sets language specified by ENV if it is compatible and none of available languages are preferred' do
-        request.headers['Accept-Language'] = 'ca-ES, fa-IR'
-        get 'success'
-        expect(I18n.locale).to eq :ca
-      end
-
-      it 'sets available and compatible langauge if language specified by ENV is not compatible none of available languages are preferred' do
-        request.headers['Accept-Language'] = 'fa-IR'
-        get 'success'
-        expect(I18n.locale).to eq :fa
-      end
+    it 'sets available and preferred language' do
+      request.headers['Accept-Language'] = 'ca-ES, fa'
+      get 'success'
+      expect(I18n.locale).to eq :fa
+    end
 
-      it 'sets language specified by ENV if none of available languages are compatible' do
-        request.headers['Accept-Language'] = ''
-        get 'success'
-        expect(I18n.locale).to eq :ca
-      end
+    it 'sets available and compatible langauge if none of available languages are preferred' do
+      request.headers['Accept-Language'] = 'fa-IR'
+      get 'success'
+      expect(I18n.locale).to eq :fa
     end
 
-    context 'when DEFAULT_LOCALE environment variable is not set' do
-      it 'sets default locale if none of available languages are compatible' do
-        request.headers['Accept-Language'] = ''
-        get 'success'
-        expect(I18n.locale).to eq :en
-      end
+    it 'sets default locale if none of available languages are compatible' do
+      request.headers['Accept-Language'] = ''
+      get 'success'
+      expect(I18n.locale).to eq :en
     end
   end
 
diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb
index 1077a7288..f43cf0c27 100644
--- a/spec/controllers/home_controller_spec.rb
+++ b/spec/controllers/home_controller_spec.rb
@@ -4,21 +4,24 @@ RSpec.describe HomeController, type: :controller do
   render_views
 
   describe 'GET #index' do
+    subject { get :index }
+
     context 'when not signed in' do
+      context 'when requested path is tag timeline' do
+        before { @request.path = '/web/timelines/tag/name' }
+        it { is_expected.to redirect_to '/tags/name' }
+      end
+
       it 'redirects to about page' do
         @request.path = '/'
-        get :index
-        expect(response).to redirect_to(about_path)
+        is_expected.to redirect_to(about_path)
       end
     end
 
     context 'when signed in' do
       let(:user) { Fabricate(:user) }
 
-      subject do
-        sign_in(user)
-        get :index
-      end
+      before { sign_in(user) }
 
       it 'assigns @body_classes' do
         subject
diff --git a/spec/helpers/instance_helper_spec.rb b/spec/helpers/instance_helper_spec.rb
index bc5950d91..c2e26dbed 100644
--- a/spec/helpers/instance_helper_spec.rb
+++ b/spec/helpers/instance_helper_spec.rb
@@ -15,12 +15,6 @@ describe InstanceHelper do
 
       expect(helper.site_title).to eq 'New site title'
     end
-
-    it 'returns empty string when Setting.site_title is nil' do
-      Setting.site_title = nil
-
-      expect(helper.site_title).to eq 'cb6e6126.ngrok.io'
-    end
   end
 
   describe 'site_hostname' do
diff --git a/spec/lib/activitypub/activity/add_spec.rb b/spec/lib/activitypub/activity/add_spec.rb
new file mode 100644
index 000000000..3ebab4e37
--- /dev/null
+++ b/spec/lib/activitypub/activity/add_spec.rb
@@ -0,0 +1,29 @@
+require 'rails_helper'
+
+RSpec.describe ActivityPub::Activity::Add do
+  let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
+  let(:status) { Fabricate(:status, account: sender) }
+
+  let(:json) do
+    {
+      '@context': 'https://www.w3.org/ns/activitystreams',
+      id: 'foo',
+      type: 'Add',
+      actor: ActivityPub::TagManager.instance.uri_for(sender),
+      object: ActivityPub::TagManager.instance.uri_for(status),
+      target: sender.featured_collection_url,
+    }.with_indifferent_access
+  end
+
+  describe '#perform' do
+    subject { described_class.new(json, sender) }
+
+    before do
+      subject.perform
+    end
+
+    it 'creates a pin' do
+      expect(sender.pinned?(status)).to be true
+    end
+  end
+end
diff --git a/spec/lib/activitypub/activity/create_spec.rb b/spec/lib/activitypub/activity/create_spec.rb
index 51f54a398..62b9db8c2 100644
--- a/spec/lib/activitypub/activity/create_spec.rb
+++ b/spec/lib/activitypub/activity/create_spec.rb
@@ -202,7 +202,7 @@ RSpec.describe ActivityPub::Activity::Create do
           attachment: [
             {
               type: 'Document',
-              mime_type: 'image/png',
+              mediaType: 'image/png',
               url: 'http://example.com/attachment.png',
             },
           ],
@@ -217,6 +217,31 @@ RSpec.describe ActivityPub::Activity::Create do
       end
     end
 
+    context 'with media attachments with focal points' do
+      let(:object_json) do
+        {
+          id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
+          type: 'Note',
+          content: 'Lorem ipsum',
+          attachment: [
+            {
+              type: 'Document',
+              mediaType: 'image/png',
+              url: 'http://example.com/attachment.png',
+              focalPoint: [0.5, -0.7],
+            },
+          ],
+        }
+      end
+
+      it 'creates status' do
+        status = sender.statuses.first
+
+        expect(status).to_not be_nil
+        expect(status.media_attachments.map(&:focus)).to include('0.5,-0.7')
+      end
+    end
+
     context 'with media attachments missing url' do
       let(:object_json) do
         {
@@ -226,7 +251,7 @@ RSpec.describe ActivityPub::Activity::Create do
           attachment: [
             {
               type: 'Document',
-              mime_type: 'image/png',
+              mediaType: 'image/png',
             },
           ],
         }
diff --git a/spec/lib/activitypub/activity/remove_spec.rb b/spec/lib/activitypub/activity/remove_spec.rb
new file mode 100644
index 000000000..4209dfde2
--- /dev/null
+++ b/spec/lib/activitypub/activity/remove_spec.rb
@@ -0,0 +1,30 @@
+require 'rails_helper'
+
+RSpec.describe ActivityPub::Activity::Remove do
+  let(:sender) { Fabricate(:account, featured_collection_url: 'https://example.com/featured') }
+  let(:status) { Fabricate(:status, account: sender) }
+
+  let(:json) do
+    {
+      '@context': 'https://www.w3.org/ns/activitystreams',
+      id: 'foo',
+      type: 'Add',
+      actor: ActivityPub::TagManager.instance.uri_for(sender),
+      object: ActivityPub::TagManager.instance.uri_for(status),
+      target: sender.featured_collection_url,
+    }.with_indifferent_access
+  end
+
+  describe '#perform' do
+    subject { described_class.new(json, sender) }
+
+    before do
+      StatusPin.create!(account: sender, status: status)
+      subject.perform
+    end
+
+    it 'removes a pin' do
+      expect(sender.pinned?(status)).to be false
+    end
+  end
+end
diff --git a/spec/lib/activitypub/activity/update_spec.rb b/spec/lib/activitypub/activity/update_spec.rb
index ea308e35c..fbfc585cf 100644
--- a/spec/lib/activitypub/activity/update_spec.rb
+++ b/spec/lib/activitypub/activity/update_spec.rb
@@ -7,6 +7,7 @@ RSpec.describe ActivityPub::Activity::Update do
     stub_request(:get, actor_json[:outbox]).to_return(status: 404)
     stub_request(:get, actor_json[:followers]).to_return(status: 404)
     stub_request(:get, actor_json[:following]).to_return(status: 404)
+    stub_request(:get, actor_json[:featured]).to_return(status: 404)
 
     sender.update!(uri: ActivityPub::TagManager.instance.uri_for(sender))
   end