about summary refs log tree commit diff
path: root/spec/controllers
diff options
context:
space:
mode:
authorkibigo! <marrus-sh@users.noreply.github.com>2017-10-11 10:43:10 -0700
committerkibigo! <marrus-sh@users.noreply.github.com>2017-10-11 10:43:10 -0700
commit8d6b9ba4946b5b159af0fbd130637a226a286796 (patch)
tree9def26711682d29338cfa1b081822029a01669eb /spec/controllers
parentf0a2a6c875e9294f0ea1d4c6bc90529e41a2dc37 (diff)
parent476e79b8e340c9103352a0799e102e4aca1a5593 (diff)
Merge upstream 2.0ish #165
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/admin/account_moderation_notes_controller_spec.rb4
-rw-r--r--spec/controllers/admin/email_domain_blocks_controller_spec.rb59
-rw-r--r--spec/controllers/api/salmon_controller_spec.rb4
-rw-r--r--spec/controllers/api/v1/apps/credentials_controller_spec.rb43
-rw-r--r--spec/controllers/api/v1/blocks_controller_spec.rb42
-rw-r--r--spec/controllers/api/v1/media_controller_spec.rb29
-rw-r--r--spec/controllers/manifests_controller_spec.rb4
-rw-r--r--spec/controllers/settings/follower_domains_controller_spec.rb67
-rw-r--r--spec/controllers/settings/notifications_controller_spec.rb37
-rw-r--r--spec/controllers/settings/preferences_controller_spec.rb6
-rw-r--r--spec/controllers/tags_controller_spec.rb42
11 files changed, 274 insertions, 63 deletions
diff --git a/spec/controllers/admin/account_moderation_notes_controller_spec.rb b/spec/controllers/admin/account_moderation_notes_controller_spec.rb
new file mode 100644
index 000000000..ca4e55c4d
--- /dev/null
+++ b/spec/controllers/admin/account_moderation_notes_controller_spec.rb
@@ -0,0 +1,4 @@
+require 'rails_helper'
+
+RSpec.describe Admin::AccountModerationNotesController, type: :controller do
+end
diff --git a/spec/controllers/admin/email_domain_blocks_controller_spec.rb b/spec/controllers/admin/email_domain_blocks_controller_spec.rb
new file mode 100644
index 000000000..295de9073
--- /dev/null
+++ b/spec/controllers/admin/email_domain_blocks_controller_spec.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe Admin::EmailDomainBlocksController, type: :controller do
+  render_views
+
+  before do
+    sign_in Fabricate(:user, admin: true), scope: :user
+  end
+
+  describe 'GET #index' do
+    around do |example|
+      default_per_page = EmailDomainBlock.default_per_page
+      EmailDomainBlock.paginates_per 1
+      example.run
+      EmailDomainBlock.paginates_per default_per_page
+    end
+
+    it 'renders email blacks' do
+      2.times { Fabricate(:email_domain_block) }
+
+      get :index, params: { page: 2 }
+
+      assigned = assigns(:email_domain_blocks)
+      expect(assigned.count).to eq 1
+      expect(assigned.klass).to be EmailDomainBlock
+      expect(response).to have_http_status(:success)
+    end
+  end
+
+  describe 'GET #new' do
+    it 'assigns a new email black' do
+      get :new
+
+      expect(assigns(:email_domain_block)).to be_instance_of(EmailDomainBlock)
+      expect(response).to have_http_status(:success)
+    end
+  end
+
+  describe 'POST #create' do
+    it 'blocks the domain when succeeded to save' do
+      post :create, params: { email_domain_block: { domain: 'example.com'} }
+
+      expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.created_msg')
+      expect(response).to redirect_to(admin_email_domain_blocks_path)
+    end
+  end
+
+  describe 'DELETE #destroy' do
+    it 'unblocks the domain' do
+      email_domain_block = Fabricate(:email_domain_block)
+      delete :destroy, params: { id: email_domain_block.id } 
+
+      expect(flash[:notice]).to eq I18n.t('admin.email_domain_blocks.destroyed_msg')
+      expect(response).to redirect_to(admin_email_domain_blocks_path)
+    end
+  end
+end
diff --git a/spec/controllers/api/salmon_controller_spec.rb b/spec/controllers/api/salmon_controller_spec.rb
index 3e4686200..323d85b61 100644
--- a/spec/controllers/api/salmon_controller_spec.rb
+++ b/spec/controllers/api/salmon_controller_spec.rb
@@ -46,8 +46,8 @@ RSpec.describe Api::SalmonController, type: :controller do
         post :update, params: { id: account.id }
       end
 
-      it 'returns http success' do
-        expect(response).to have_http_status(202)
+      it 'returns http client error' do
+        expect(response).to have_http_status(400)
       end
     end
   end
diff --git a/spec/controllers/api/v1/apps/credentials_controller_spec.rb b/spec/controllers/api/v1/apps/credentials_controller_spec.rb
new file mode 100644
index 000000000..38f2a4e10
--- /dev/null
+++ b/spec/controllers/api/v1/apps/credentials_controller_spec.rb
@@ -0,0 +1,43 @@
+require 'rails_helper'
+
+describe Api::V1::Apps::CredentialsController do
+  render_views
+
+  let(:token) { Fabricate(:accessible_access_token, scopes: 'read', application: Fabricate(:application)) }
+
+  context 'with an oauth token' do
+    before do
+      allow(controller).to receive(:doorkeeper_token) { token }
+    end
+
+    describe 'GET #show' do
+      before do
+        get :show
+      end
+
+      it 'returns http success' do
+        expect(response).to have_http_status(:success)
+      end
+
+      it 'does not contain client credentials' do
+        json = body_as_json
+
+        expect(json).to_not have_key(:client_secret)
+        expect(json).to_not have_key(:client_id)
+      end
+    end
+  end
+
+  context 'without an oauth token' do
+    before do
+      allow(controller).to receive(:doorkeeper_token) { nil }
+    end
+
+    describe 'GET #show' do
+      it 'returns http unauthorized' do
+        get :show
+        expect(response).to have_http_status(:unauthorized)
+      end
+    end
+  end
+end
diff --git a/spec/controllers/api/v1/blocks_controller_spec.rb b/spec/controllers/api/v1/blocks_controller_spec.rb
index f25a7e878..9b2bbdf0e 100644
--- a/spec/controllers/api/v1/blocks_controller_spec.rb
+++ b/spec/controllers/api/v1/blocks_controller_spec.rb
@@ -6,15 +6,47 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
   let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
   let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'follow') }
 
-  before do
-    Fabricate(:block, account: user.account)
-    allow(controller).to receive(:doorkeeper_token) { token }
-  end
+  before { allow(controller).to receive(:doorkeeper_token) { token } }
 
   describe 'GET #index' do
-    it 'returns http success' do
+    it 'limits according to limit parameter' do
+      2.times.map { Fabricate(:block, account: user.account) }
       get :index, params: { limit: 1 }
+      expect(body_as_json.size).to eq 1
+    end
+
+    it 'queries blocks in range according to max_id' do
+      blocks = 2.times.map { Fabricate(:block, account: user.account) }
+
+      get :index, params: { max_id: blocks[1] }
+
+      expect(body_as_json.size).to eq 1
+      expect(body_as_json[0][:id]).to eq blocks[0].target_account_id.to_s
+    end
+
+    it 'queries blocks in range according to since_id' do
+      blocks = 2.times.map { Fabricate(:block, account: user.account) }
 
+      get :index, params: { since_id: blocks[0] }
+
+      expect(body_as_json.size).to eq 1
+      expect(body_as_json[0][:id]).to eq blocks[1].target_account_id.to_s
+    end
+
+    it 'sets pagination header for next path' do
+      blocks = 2.times.map { Fabricate(:block, account: user.account) }
+      get :index, params: { limit: 1, since_id: blocks[0] }
+      expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
+    end
+
+    it 'sets pagination header for previous path' do
+      block = Fabricate(:block, account: user.account)
+      get :index
+      expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block)
+    end
+
+    it 'returns http success' do
+      get :index
       expect(response).to have_http_status(:success)
     end
   end
diff --git a/spec/controllers/api/v1/media_controller_spec.rb b/spec/controllers/api/v1/media_controller_spec.rb
index baa22d7e4..0e494638f 100644
--- a/spec/controllers/api/v1/media_controller_spec.rb
+++ b/spec/controllers/api/v1/media_controller_spec.rb
@@ -101,4 +101,33 @@ RSpec.describe Api::V1::MediaController, type: :controller do
       end
     end
   end
+
+  describe 'PUT #update' do
+    context 'when somebody else\'s' do
+      let(:media) { Fabricate(:media_attachment, status: nil) }
+
+      it 'returns http not found' do
+        put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
+        expect(response).to have_http_status(:not_found)
+      end
+    end
+
+    context 'when not attached to a status' do
+      let(:media) { Fabricate(:media_attachment, status: nil, account: user.account) }
+
+      it 'updates the description' do
+        put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
+        expect(media.reload.description).to eq 'Lorem ipsum!!!'
+      end
+    end
+
+    context 'when attached to a status' do
+      let(:media) { Fabricate(:media_attachment, status: Fabricate(:status), account: user.account) }
+
+      it 'returns http not found' do
+        put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
+        expect(response).to have_http_status(:not_found)
+      end
+    end
+  end
 end
diff --git a/spec/controllers/manifests_controller_spec.rb b/spec/controllers/manifests_controller_spec.rb
index 6f188fa35..71967e4f0 100644
--- a/spec/controllers/manifests_controller_spec.rb
+++ b/spec/controllers/manifests_controller_spec.rb
@@ -8,10 +8,6 @@ describe ManifestsController do
       get :show, format: :json
     end
 
-    it 'assigns @instance_presenter' do
-      expect(assigns(:instance_presenter)).to be_kind_of InstancePresenter
-    end
-
     it 'returns http success' do
       expect(response).to have_http_status(:success)
     end
diff --git a/spec/controllers/settings/follower_domains_controller_spec.rb b/spec/controllers/settings/follower_domains_controller_spec.rb
index d48c3e68c..333223c61 100644
--- a/spec/controllers/settings/follower_domains_controller_spec.rb
+++ b/spec/controllers/settings/follower_domains_controller_spec.rb
@@ -5,15 +5,41 @@ describe Settings::FollowerDomainsController do
 
   let(:user) { Fabricate(:user) }
 
-  before do
-    sign_in user, scope: :user
+  shared_examples 'authenticate user' do
+    it 'redirects when not signed in' do
+      is_expected.to redirect_to '/auth/sign_in'
+    end
   end
 
   describe 'GET #show' do
+    subject { get :show, params: { page: 2 } }
+
+    it 'assigns @account' do
+      sign_in user, scope: :user
+      subject
+      expect(assigns(:account)).to eq user.account
+    end
+
+    it 'assigns @domains' do
+      Fabricate(:account, domain: 'old').follow!(user.account)
+      Fabricate(:account, domain: 'recent').follow!(user.account)
+
+      sign_in user, scope: :user
+      subject
+
+      assigned = assigns(:domains).per(1).to_a
+      expect(assigned.size).to eq 1
+      expect(assigned[0].accounts_from_domain).to eq 1
+      expect(assigned[0].domain).to eq 'old'
+    end
+
     it 'returns http success' do
-      get :show
+      sign_in user, scope: :user
+      subject
       expect(response).to have_http_status(:success)
     end
+
+    include_examples 'authenticate user'
   end
 
   describe 'PATCH #update' do
@@ -21,16 +47,39 @@ describe Settings::FollowerDomainsController do
 
     before do
       stub_request(:post, 'http://example.com/salmon').to_return(status: 200)
-      poopfeast.follow!(user.account)
-      patch :update, params: { select: ['example.com'] }
     end
 
-    it 'redirects back to followers page' do
-      expect(response).to redirect_to(settings_follower_domains_path)
+    shared_examples 'redirects back to followers page' do |notice|
+      it 'redirects back to followers page' do
+        poopfeast.follow!(user.account)
+
+        sign_in user, scope: :user
+        subject
+
+        expect(flash[:notice]).to eq notice
+        expect(response).to redirect_to(settings_follower_domains_path)
+      end
+    end
+
+    context 'when select parameter is not provided' do
+      subject { patch :update }
+      include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from 0 domains...'
     end
 
-    it 'soft-blocks followers from selected domains' do
-      expect(poopfeast.following?(user.account)).to be false
+    context 'when select parameter is provided' do
+      subject { patch :update, params: { select: ['example.com'] } }
+
+      it 'soft-blocks followers from selected domains' do
+        poopfeast.follow!(user.account)
+
+        sign_in user, scope: :user
+        subject
+
+        expect(poopfeast.following?(user.account)).to be false
+      end
+
+      include_examples 'authenticate user'
+      include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from one domain...'
     end
   end
 end
diff --git a/spec/controllers/settings/notifications_controller_spec.rb b/spec/controllers/settings/notifications_controller_spec.rb
new file mode 100644
index 000000000..0bd993448
--- /dev/null
+++ b/spec/controllers/settings/notifications_controller_spec.rb
@@ -0,0 +1,37 @@
+require 'rails_helper'
+
+describe Settings::NotificationsController do
+  render_views
+
+  let(:user) { Fabricate(:user) }
+
+  before do
+    sign_in user, scope: :user
+  end
+
+  describe 'GET #show' do
+    it 'returns http success' do
+      get :show
+      expect(response).to have_http_status(:success)
+    end
+  end
+
+  describe 'PUT #update' do
+    it 'updates notifications settings' do
+      user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
+      user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
+
+      put :update, params: {
+        user: {
+          notification_emails: { follow: '1' },
+          interactions: { must_be_follower: '0' },
+        }
+      }
+
+      expect(response).to redirect_to(settings_notifications_path)
+      user.reload
+      expect(user.settings['notification_emails']['follow']).to be true
+      expect(user.settings['interactions']['must_be_follower']).to be false
+    end
+  end
+end
diff --git a/spec/controllers/settings/preferences_controller_spec.rb b/spec/controllers/settings/preferences_controller_spec.rb
index 60fa42302..0f9431673 100644
--- a/spec/controllers/settings/preferences_controller_spec.rb
+++ b/spec/controllers/settings/preferences_controller_spec.rb
@@ -29,15 +29,11 @@ describe Settings::PreferencesController do
     it 'updates user settings' do
       user.settings['boost_modal'] = false
       user.settings['delete_modal'] = true
-      user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
-      user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
 
       put :update, params: {
         user: {
           setting_boost_modal: '1',
           setting_delete_modal: '0',
-          notification_emails: { follow: '1' },
-          interactions: { must_be_follower: '0' },
         }
       }
 
@@ -45,8 +41,6 @@ describe Settings::PreferencesController do
       user.reload
       expect(user.settings['boost_modal']).to be true
       expect(user.settings['delete_modal']).to be false
-      expect(user.settings['notification_emails']['follow']).to be true
-      expect(user.settings['interactions']['must_be_follower']).to be false
     end
   end
 end
diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb
index 3f46c14c0..b04666c0f 100644
--- a/spec/controllers/tags_controller_spec.rb
+++ b/spec/controllers/tags_controller_spec.rb
@@ -5,9 +5,9 @@ RSpec.describe TagsController, type: :controller do
 
   describe 'GET #show' do
     let!(:tag)     { Fabricate(:tag, name: 'test') }
-    let!(:local)  { Fabricate(:status, tags: [ tag ], text: 'local #test') }
-    let!(:remote) { Fabricate(:status, tags: [ tag ], text: 'remote #test', account: Fabricate(:account, domain: 'remote')) }
-    let!(:late)  { Fabricate(:status, tags: [ tag ], text: 'late #test') }
+    let!(:local)   { Fabricate(:status, tags: [tag], text: 'local #test') }
+    let!(:remote)  { Fabricate(:status, tags: [tag], text: 'remote #test', account: Fabricate(:account, domain: 'remote')) }
+    let!(:late)    { Fabricate(:status, tags: [tag], text: 'late #test') }
 
     context 'when tag exists' do
       it 'returns http success' do
@@ -15,41 +15,9 @@ RSpec.describe TagsController, type: :controller do
         expect(response).to have_http_status(:success)
       end
 
-      it 'renders public layout' do
+      it 'renders application layout' do
         get :show, params: { id: 'test', max_id: late.id }
-        expect(response).to render_template layout: 'public'
-      end
-
-      it 'renders only local statuses if local parameter is specified' do
-        get :show, params: { id: 'test', local: true, max_id: late.id }
-
-        expect(assigns(:tag)).to eq tag
-        statuses = assigns(:statuses).to_a
-        expect(statuses.size).to eq 1
-        expect(statuses[0]).to eq local
-      end
-
-      it 'renders local and remote statuses if local parameter is not specified' do
-        get :show, params: { id: 'test', max_id: late.id }
-
-        expect(assigns(:tag)).to eq tag
-        statuses = assigns(:statuses).to_a
-        expect(statuses.size).to eq 2
-        expect(statuses[0]).to eq remote
-        expect(statuses[1]).to eq local
-      end
-
-      it 'filters statuses by the current account' do
-        user = Fabricate(:user)
-        user.account.block!(remote.account)
-
-        sign_in(user)
-        get :show, params: { id: 'test', max_id: late.id }
-
-        expect(assigns(:tag)).to eq tag
-        statuses = assigns(:statuses).to_a
-        expect(statuses.size).to eq 1
-        expect(statuses[0]).to eq local
+        expect(response).to render_template layout: 'application'
       end
     end