about summary refs log tree commit diff
path: root/spec/controllers/admin
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/admin')
-rw-r--r--spec/controllers/admin/accounts_controller_spec.rb55
-rw-r--r--spec/controllers/admin/settings_controller_spec.rb8
2 files changed, 58 insertions, 5 deletions
diff --git a/spec/controllers/admin/accounts_controller_spec.rb b/spec/controllers/admin/accounts_controller_spec.rb
index 305260475..8be27d866 100644
--- a/spec/controllers/admin/accounts_controller_spec.rb
+++ b/spec/controllers/admin/accounts_controller_spec.rb
@@ -3,11 +3,64 @@ require 'rails_helper'
 RSpec.describe Admin::AccountsController, type: :controller do
   render_views
 
+  let(:user) { Fabricate(:user, admin: true) }
+
   before do
-    sign_in Fabricate(:user, admin: true), scope: :user
+    sign_in user, scope: :user
   end
 
   describe 'GET #index' do
+    around do |example|
+      default_per_page = Account.default_per_page
+      Account.paginates_per 1
+      example.run
+      Account.paginates_per default_per_page
+    end
+
+    it 'filters with parameters' do
+      new = AccountFilter.method(:new)
+
+      expect(AccountFilter).to receive(:new) do |params|
+        h = params.to_h
+
+        expect(h[:local]).to eq '1'
+        expect(h[:remote]).to eq '1'
+        expect(h[:by_domain]).to eq 'domain'
+        expect(h[:silenced]).to eq '1'
+        expect(h[:recent]).to eq '1'
+        expect(h[:suspended]).to eq '1'
+        expect(h[:username]).to eq 'username'
+        expect(h[:display_name]).to eq 'display name'
+        expect(h[:email]).to eq 'local-part@domain'
+        expect(h[:ip]).to eq '0.0.0.42'
+
+        new.call({})
+      end
+
+      get :index, params: {
+        local: '1',
+        remote: '1',
+        by_domain: 'domain',
+        silenced: '1',
+        recent: '1',
+        suspended: '1',
+        username: 'username',
+        display_name: 'display name',
+        email: 'local-part@domain',
+        ip: '0.0.0.42'
+      }
+    end
+
+    it 'paginates accounts' do
+      Fabricate(:account)
+
+      get :index, params: { page: 2 }
+
+      accounts = assigns(:accounts)
+      expect(accounts.count).to eq 1
+      expect(accounts.klass).to be Account
+    end
+
     it 'returns http success' do
       get :index
       expect(response).to have_http_status(:success)
diff --git a/spec/controllers/admin/settings_controller_spec.rb b/spec/controllers/admin/settings_controller_spec.rb
index d9dde3c92..609bc762b 100644
--- a/spec/controllers/admin/settings_controller_spec.rb
+++ b/spec/controllers/admin/settings_controller_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe Admin::SettingsController, type: :controller do
         it 'cannot create a setting value for a non-admin key' do
           expect(Setting.new_setting_key).to be_blank
 
-          patch :update, params: { new_setting_key: 'New key value' }
+          patch :update, params: { form_admin_settings: { new_setting_key: 'New key value' } }
 
           expect(response).to redirect_to(edit_admin_settings_path)
           expect(Setting.new_setting_key).to be_nil
@@ -40,7 +40,7 @@ RSpec.describe Admin::SettingsController, type: :controller do
         it 'creates a settings value that didnt exist before for eligible key' do
           expect(Setting.site_extended_description).to be_blank
 
-          patch :update, params: { site_extended_description: 'New key value' }
+          patch :update, params: { form_admin_settings: { site_extended_description: 'New key value' } }
 
           expect(response).to redirect_to(edit_admin_settings_path)
           expect(Setting.site_extended_description).to eq 'New key value'
@@ -56,7 +56,7 @@ RSpec.describe Admin::SettingsController, type: :controller do
 
         it 'updates a settings value' do
           Setting.site_title = 'Original'
-          patch :update, params: { site_title: 'New title' }
+          patch :update, params: { form_admin_settings: { site_title: 'New title' } }
 
           expect(response).to redirect_to(edit_admin_settings_path)
           expect(Setting.site_title).to eq 'New title'
@@ -72,7 +72,7 @@ RSpec.describe Admin::SettingsController, type: :controller do
 
         it 'typecasts open_registrations to boolean' do
           Setting.open_registrations = false
-          patch :update, params: { open_registrations: 'true' }
+          patch :update, params: { form_admin_settings: { open_registrations: '1' } }
 
           expect(response).to redirect_to(edit_admin_settings_path)
           expect(Setting.open_registrations).to eq true