about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-12-18 16:55:15 +0100
committerThibaut Girka <thib@sitedethib.com>2018-12-18 16:55:15 +0100
commit034ffc079e40e0c723173b5998242803cc28dc50 (patch)
treefee1b208be2068cf372ab23f268a66ca51cc2dc3 /spec
parent36d27e289177fdec5332539c94b8192022a412f2 (diff)
parent5bf100f87be571e86305f3ab244183fc46f1ede2 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/controllers/admin/base_controller.rb
  Some refactoring made upstream, no real conflict.
- app/javascript/mastodon/features/compose/components/compose_form.js
  Updated using upstream's code but using maxChars instead of the
  hardcoded length of 500 characters per toot.
- app/javascript/styles/mastodon/components.scss
  Upstream redesigned the onboarding modal. Not sure why we had a
  conflict there.
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/accounts/pins_controller_spec.rb46
-rw-r--r--spec/controllers/api/v1/endorsements_controller_spec.rb17
-rw-r--r--spec/controllers/api/v1/instances/activity_controller_spec.rb21
-rw-r--r--spec/controllers/api/v1/instances/peers_controller_spec.rb21
-rw-r--r--spec/controllers/api/v1/timelines/direct_controller_spec.rb17
-rw-r--r--spec/controllers/concerns/accountable_concern_spec.rb26
-rw-r--r--spec/fixtures/requests/windows-1251.txt17
-rw-r--r--spec/services/fetch_link_card_service_spec.rb11
8 files changed, 176 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/accounts/pins_controller_spec.rb b/spec/controllers/api/v1/accounts/pins_controller_spec.rb
new file mode 100644
index 000000000..c71935df2
--- /dev/null
+++ b/spec/controllers/api/v1/accounts/pins_controller_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Api::V1::Accounts::PinsController, type: :controller do
+  let(:john)  { Fabricate(:user, account: Fabricate(:account, username: 'john')) }
+  let(:kevin) { Fabricate(:user, account: Fabricate(:account, username: 'kevin')) }
+  let(:token) { Fabricate(:accessible_access_token, resource_owner_id: john.id, scopes: 'write:accounts') }
+
+  before do
+    kevin.account.followers << john.account
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'POST #create' do
+    subject { post :create, params: { account_id: kevin.account.id } }
+
+    it 'returns 200' do
+      expect(response).to have_http_status(200)
+    end
+
+    it 'creates account_pin' do
+      expect do
+        subject
+      end.to change { AccountPin.where(account: john.account, target_account: kevin.account).count }.by(1)
+    end
+  end
+
+  describe 'DELETE #destroy' do
+    subject { delete :destroy, params: { account_id: kevin.account.id } }
+
+    before do
+      Fabricate(:account_pin, account: john.account, target_account: kevin.account)
+    end
+
+    it 'returns 200' do
+      expect(response).to have_http_status(200)
+    end
+
+    it 'destroys account_pin' do
+      expect do
+        subject
+      end.to change { AccountPin.where(account: john.account, target_account: kevin.account).count }.by(-1)
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/endorsements_controller_spec.rb b/spec/controllers/api/v1/endorsements_controller_spec.rb
new file mode 100644
index 000000000..ad5ff400f
--- /dev/null
+++ b/spec/controllers/api/v1/endorsements_controller_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Api::V1::EndorsementsController, type: :controller do
+  let(:user)  { Fabricate(:user) }
+  let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:accounts') }
+
+  describe 'GET #index' do
+    it 'returns 200' do
+      allow(controller).to receive(:doorkeeper_token) { token }
+      get :index
+
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/instances/activity_controller_spec.rb b/spec/controllers/api/v1/instances/activity_controller_spec.rb
new file mode 100644
index 000000000..159792ee0
--- /dev/null
+++ b/spec/controllers/api/v1/instances/activity_controller_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Api::V1::Instances::ActivityController, type: :controller do
+  describe 'GET #show' do
+    it 'returns 200' do
+      get :show
+      expect(response).to have_http_status(200)
+    end
+
+    context '!Setting.activity_api_enabled' do
+      it 'returns 404' do
+        Setting.activity_api_enabled = false
+
+        get :show
+        expect(response).to have_http_status(404)
+      end
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/instances/peers_controller_spec.rb b/spec/controllers/api/v1/instances/peers_controller_spec.rb
new file mode 100644
index 000000000..12a214a83
--- /dev/null
+++ b/spec/controllers/api/v1/instances/peers_controller_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Api::V1::Instances::PeersController, type: :controller do
+  describe 'GET #index' do
+    it 'returns 200' do
+      get :index
+      expect(response).to have_http_status(200)
+    end
+
+    context '!Setting.peers_api_enabled' do
+      it 'returns 404' do
+        Setting.peers_api_enabled = false
+
+        get :index
+        expect(response).to have_http_status(404)
+      end
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/timelines/direct_controller_spec.rb b/spec/controllers/api/v1/timelines/direct_controller_spec.rb
new file mode 100644
index 000000000..a22c2cbea
--- /dev/null
+++ b/spec/controllers/api/v1/timelines/direct_controller_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Api::V1::Timelines::DirectController, type: :controller do
+  let(:user)  { Fabricate(:user) }
+  let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:statuses') }
+
+  describe 'GET #show' do
+    it 'returns 200' do
+      allow(controller).to receive(:doorkeeper_token) { token }
+      get :show
+
+      expect(response).to have_http_status(200)
+    end
+  end
+end
diff --git a/spec/controllers/concerns/accountable_concern_spec.rb b/spec/controllers/concerns/accountable_concern_spec.rb
new file mode 100644
index 000000000..e3c06b494
--- /dev/null
+++ b/spec/controllers/concerns/accountable_concern_spec.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe AccountableConcern do
+  class Hoge
+    include AccountableConcern
+    attr_reader :current_account
+
+    def initialize(current_account)
+      @current_account = current_account
+    end
+  end
+
+  let(:user)   { Fabricate(:user, account: Fabricate(:account)) }
+  let(:target) { Fabricate(:user, account: Fabricate(:account)) }
+  let(:hoge)   { Hoge.new(user.account) }
+
+  describe '#log_action' do
+    it 'creates Admin::ActionLog' do
+      expect do
+        hoge.log_action(:create, target.account)
+      end.to change { Admin::ActionLog.count }.by(1)
+    end
+  end
+end
diff --git a/spec/fixtures/requests/windows-1251.txt b/spec/fixtures/requests/windows-1251.txt
new file mode 100644
index 000000000..f573e28b2
--- /dev/null
+++ b/spec/fixtures/requests/windows-1251.txt
@@ -0,0 +1,17 @@
+HTTP/1.1 200 OK

+server: nginx

+date: Wed, 12 Dec 2018 13:14:03 GMT

+content-type: text/html

+content-length: 190

+accept-ranges: bytes

+

+<!DOCTYPE html>

+<html>

+<head>

+  <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />

+  <title> </title>

+</head>

+<body>

+  <p> </p>

+</body>

+</html>

diff --git a/spec/services/fetch_link_card_service_spec.rb b/spec/services/fetch_link_card_service_spec.rb
index 88c5339db..50c60aafd 100644
--- a/spec/services/fetch_link_card_service_spec.rb
+++ b/spec/services/fetch_link_card_service_spec.rb
@@ -17,6 +17,8 @@ RSpec.describe FetchLinkCardService, type: :service do
     stub_request(:head, 'https://github.com/qbi/WannaCry').to_return(status: 404)
     stub_request(:head, 'http://example.com/test-').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
     stub_request(:get, 'http://example.com/test-').to_return(request_fixture('idn.txt'))
+    stub_request(:head, 'http://example.com/windows-1251').to_return(status: 200, headers: { 'Content-Type' => 'text/html' })
+    stub_request(:get, 'http://example.com/windows-1251').to_return(request_fixture('windows-1251.txt'))
 
     subject.call(status)
   end
@@ -58,6 +60,15 @@ RSpec.describe FetchLinkCardService, type: :service do
     end
 
     context do
+      let(:status) { Fabricate(:status, text: 'Check out http://example.com/windows-1251') }
+
+      it 'works with windows-1251' do
+        expect(a_request(:get, 'http://example.com/windows-1251')).to have_been_made.at_least_once
+        expect(status.preview_cards.first.title).to eq('сэмпл текст')
+      end
+    end
+
+    context do
       let(:status) { Fabricate(:status, text: 'テストhttp://example.com/日本語') }
 
       it 'works with Japanese path string' do