mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Merge 7c82fdde38
into de09e33c92
This commit is contained in:
commit
a3a8084e76
|
@ -49,8 +49,8 @@ module Admin
|
||||||
|
|
||||||
def export_data
|
def export_data
|
||||||
CSV.generate(headers: export_headers, write_headers: true) do |content|
|
CSV.generate(headers: export_headers, write_headers: true) do |content|
|
||||||
DomainAllow.allowed_domains.each do |instance|
|
DomainAllow.allowed_domains.each do |domain|
|
||||||
content << [instance.domain]
|
content << [domain]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ class DomainAllow < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def allowed_domains
|
def allowed_domains
|
||||||
select(:domain)
|
pluck(:domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
def rule_for(domain)
|
def rule_for(domain)
|
||||||
|
|
|
@ -17,17 +17,6 @@ RSpec.describe Admin::ExportDomainAllowsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #export' do
|
|
||||||
it 'renders instances' do
|
|
||||||
Fabricate(:domain_allow, domain: 'good.domain')
|
|
||||||
Fabricate(:domain_allow, domain: 'better.domain')
|
|
||||||
|
|
||||||
get :export, params: { format: :csv }
|
|
||||||
expect(response).to have_http_status(200)
|
|
||||||
expect(response.body).to eq(domain_allows_csv_file)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'POST #import' do
|
describe 'POST #import' do
|
||||||
it 'allows imported domains' do
|
it 'allows imported domains' do
|
||||||
post :import, params: { admin_import: { data: fixture_file_upload('domain_allows.csv') } }
|
post :import, params: { admin_import: { data: fixture_file_upload('domain_allows.csv') } }
|
||||||
|
@ -50,10 +39,4 @@ RSpec.describe Admin::ExportDomainAllowsController do
|
||||||
expect(flash[:error]).to eq(I18n.t('admin.export_domain_allows.no_file'))
|
expect(flash[:error]).to eq(I18n.t('admin.export_domain_allows.no_file'))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def domain_allows_csv_file
|
|
||||||
File.read(File.join(file_fixture_path, 'domain_allows.csv'))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,4 +12,19 @@ RSpec.describe DomainAllow do
|
||||||
it { is_expected.to_not allow_value('xn--r9j5b5b').for(:domain) }
|
it { is_expected.to_not allow_value('xn--r9j5b5b').for(:domain) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.allowed_domains' do
|
||||||
|
subject { described_class.allowed_domains }
|
||||||
|
|
||||||
|
context 'without domain allows' do
|
||||||
|
it { is_expected.to be_an(Array).and(be_empty) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with domain allows' do
|
||||||
|
let!(:allowed_domain) { Fabricate :domain_allow }
|
||||||
|
let!(:other_allowed_domain) { Fabricate :domain_allow }
|
||||||
|
|
||||||
|
it { is_expected.to contain_exactly(allowed_domain.domain, other_allowed_domain.domain) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe 'Admin Export Domain Allows' do
|
RSpec.describe 'Admin Export Domain Allows' do
|
||||||
describe 'POST /admin/export_domain_allows/import' do
|
before { sign_in Fabricate(:admin_user) }
|
||||||
before { sign_in Fabricate(:admin_user) }
|
|
||||||
|
|
||||||
|
describe 'POST /admin/export_domain_allows/import' do
|
||||||
it 'gracefully handles invalid nested params' do
|
it 'gracefully handles invalid nested params' do
|
||||||
post import_admin_export_domain_allows_path(admin_import: 'invalid')
|
post import_admin_export_domain_allows_path(admin_import: 'invalid')
|
||||||
|
|
||||||
|
@ -13,4 +13,28 @@ RSpec.describe 'Admin Export Domain Allows' do
|
||||||
.to redirect_to(admin_instances_path)
|
.to redirect_to(admin_instances_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'GET /admin/export_domain_allows/export.csv' do
|
||||||
|
before do
|
||||||
|
Fabricate(:domain_allow, domain: 'good.domain')
|
||||||
|
Fabricate(:domain_allow, domain: 'better.domain')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns CSV response with instance domain values' do
|
||||||
|
get export_admin_export_domain_allows_path(format: :csv)
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(200)
|
||||||
|
expect(response.body)
|
||||||
|
.to eq(domain_allows_csv_file)
|
||||||
|
expect(response.media_type)
|
||||||
|
.to eq('text/csv')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def domain_allows_csv_file
|
||||||
|
File.read(File.join(file_fixture_path, 'domain_allows.csv'))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user