From 55e150352204bc790345cf81ef02bfcb1d7e0594 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 18 Apr 2017 15:09:07 -0400 Subject: Instances list in admin (#2095) * Add admin/instances index action * Add link to instances admin page * View lists instances * Instances, grouped by domain, ordered by count * Use Account.remote scope * Extract method: Account.by_domain_accounts --- spec/controllers/admin/instances_controller_spec.rb | 15 +++++++++++++++ spec/models/account_spec.rb | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 spec/controllers/admin/instances_controller_spec.rb (limited to 'spec') diff --git a/spec/controllers/admin/instances_controller_spec.rb b/spec/controllers/admin/instances_controller_spec.rb new file mode 100644 index 000000000..c50ea352f --- /dev/null +++ b/spec/controllers/admin/instances_controller_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe Admin::InstancesController, type: :controller do + before do + sign_in Fabricate(:user, admin: true), scope: :user + end + + describe 'GET #index' do + it 'returns http success' do + get :index + + expect(response).to have_http_status(:success) + end + end +end diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index c39e7986e..3edbc3253 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -410,6 +410,20 @@ RSpec.describe Account, type: :model do end end + describe 'by_domain_accounts' do + it 'returns accounts grouped by domain sorted by accounts' do + 2.times { Fabricate(:account, domain: 'example.com') } + Fabricate(:account, domain: 'example2.com') + + results = Account.by_domain_accounts + expect(results.length).to eq 2 + expect(results.first.domain).to eq 'example.com' + expect(results.first.accounts_count).to eq 2 + expect(results.last.domain).to eq 'example2.com' + expect(results.last.accounts_count).to eq 1 + end + end + describe 'local' do it 'returns an array of accounts who do not have a domain' do account_1 = Fabricate(:account, domain: nil) -- cgit