DB speedup in API:: controller/request specs (#25516)
		
	This commit is contained in:
		
					parent
					
						
							
								ecdb31d479
							
						
					
				
			
			
				commit
				
					
						fd9dea21d0
					
				
			
		
					 41 changed files with 181 additions and 746 deletions
				
			
		|  | @ -51,14 +51,9 @@ RSpec.describe 'Account actions' do | |||
|       it_behaves_like 'a successful notification delivery' | ||||
|       it_behaves_like 'a successful logged action', :disable, :user | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'disables the target account' do | ||||
|         expect { subject }.to change { target_account.reload.user_disabled? }.from(false).to(true) | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  | @ -70,14 +65,9 @@ RSpec.describe 'Account actions' do | |||
|       it_behaves_like 'a successful notification delivery' | ||||
|       it_behaves_like 'a successful logged action', :sensitive, :account | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'marks the target account as sensitive' do | ||||
|         expect { subject }.to change { target_account.reload.sensitized? }.from(false).to(true) | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  | @ -89,14 +79,9 @@ RSpec.describe 'Account actions' do | |||
|       it_behaves_like 'a successful notification delivery' | ||||
|       it_behaves_like 'a successful logged action', :silence, :account | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'marks the target account as silenced' do | ||||
|         expect { subject }.to change { target_account.reload.silenced? }.from(false).to(true) | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  | @ -108,14 +93,9 @@ RSpec.describe 'Account actions' do | |||
|       it_behaves_like 'a successful notification delivery' | ||||
|       it_behaves_like 'a successful logged action', :suspend, :account | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'marks the target account as suspended' do | ||||
|         expect { subject }.to change { target_account.reload.suspended? }.from(false).to(true) | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -92,15 +92,10 @@ RSpec.describe 'Canonical Email Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     context 'when the requested canonical email block exists' do | ||||
|       it 'returns http success' do | ||||
|       it 'returns the requested canonical email block data correctly', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns the requested canonical email block data correctly' do | ||||
|         subject | ||||
| 
 | ||||
|         json = body_as_json | ||||
| 
 | ||||
|         expect(json[:id]).to eq(canonical_email_block.id.to_s) | ||||
|  | @ -142,29 +137,19 @@ RSpec.describe 'Canonical Email Blocks' do | |||
|       context 'when there is a matching canonical email block' do | ||||
|         let!(:canonical_email_block) { CanonicalEmailBlock.create(params) } | ||||
| 
 | ||||
|         it 'returns http success' do | ||||
|         it 'returns the expected canonical email hash', :aggregate_failures do | ||||
|           subject | ||||
| 
 | ||||
|           expect(response).to have_http_status(200) | ||||
|         end | ||||
| 
 | ||||
|         it 'returns the expected canonical email hash' do | ||||
|           subject | ||||
| 
 | ||||
|           expect(body_as_json[0][:canonical_email_hash]).to eq(canonical_email_block.canonical_email_hash) | ||||
|         end | ||||
|       end | ||||
| 
 | ||||
|       context 'when there is no matching canonical email block' do | ||||
|         it 'returns http success' do | ||||
|         it 'returns an empty list', :aggregate_failures do | ||||
|           subject | ||||
| 
 | ||||
|           expect(response).to have_http_status(200) | ||||
|         end | ||||
| 
 | ||||
|         it 'returns an empty list' do | ||||
|           subject | ||||
| 
 | ||||
|           expect(body_as_json).to be_empty | ||||
|         end | ||||
|       end | ||||
|  | @ -183,15 +168,10 @@ RSpec.describe 'Canonical Email Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the canonical_email_hash correctly', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the canonical_email_hash correctly' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json[:canonical_email_hash]).to eq(canonical_email_block.canonical_email_hash) | ||||
|     end | ||||
| 
 | ||||
|  | @ -208,15 +188,10 @@ RSpec.describe 'Canonical Email Blocks' do | |||
|     context 'when the canonical_email_hash param is provided instead of email' do | ||||
|       let(:params) { { canonical_email_hash: 'dd501ce4e6b08698f19df96f2f15737e48a75660b1fa79b6ff58ea25ee4851a4' } } | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|       it 'returns the correct canonical_email_hash', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns the correct canonical_email_hash' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json[:canonical_email_hash]).to eq(params[:canonical_email_hash]) | ||||
|       end | ||||
|     end | ||||
|  | @ -224,15 +199,10 @@ RSpec.describe 'Canonical Email Blocks' do | |||
|     context 'when both email and canonical_email_hash params are provided' do | ||||
|       let(:params) { { email: 'example@email.com', canonical_email_hash: 'dd501ce4e6b08698f19df96f2f15737e48a75660b1fa79b6ff58ea25ee4851a4' } } | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|       it 'ignores the canonical_email_hash param', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'ignores the canonical_email_hash param' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json[:canonical_email_hash]).to eq(canonical_email_block.canonical_email_hash) | ||||
|       end | ||||
|     end | ||||
|  | @ -262,15 +232,10 @@ RSpec.describe 'Canonical Email Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes the canonical email block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes the canonical email block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(CanonicalEmailBlock.find_by(id: canonical_email_block.id)).to be_nil | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -75,15 +75,10 @@ RSpec.describe 'Domain Allows' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the expected allowed domain name', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the expected allowed domain name' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json[:domain]).to eq domain_allow.domain | ||||
|     end | ||||
| 
 | ||||
|  | @ -108,21 +103,11 @@ RSpec.describe 'Domain Allows' do | |||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     context 'with a valid domain name' do | ||||
|       it 'returns http success' do | ||||
|       it 'returns the expected domain name', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns the expected domain name' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json[:domain]).to eq 'foo.bar.com' | ||||
|       end | ||||
| 
 | ||||
|       it 'creates a domain allow' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(DomainAllow.find_by(domain: 'foo.bar.com')).to be_present | ||||
|       end | ||||
|     end | ||||
|  | @ -171,15 +156,10 @@ RSpec.describe 'Domain Allows' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes the allowed domain', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes the allowed domain' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(DomainAllow.find_by(id: domain_allow.id)).to be_nil | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -89,15 +89,10 @@ RSpec.describe 'Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the expected domain block content', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the expected domain block content' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to eq( | ||||
|         { | ||||
|           id: domain_block.id.to_s, | ||||
|  | @ -133,27 +128,18 @@ RSpec.describe 'Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns expected domain name and severity' do | ||||
|     it 'returns expected domain name and severity', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       body = body_as_json | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|       expect(body).to match a_hash_including( | ||||
|         { | ||||
|           domain: 'foo.bar.com', | ||||
|           severity: 'silence', | ||||
|         } | ||||
|       ) | ||||
|     end | ||||
| 
 | ||||
|     it 'creates a domain block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(DomainBlock.find_by(domain: 'foo.bar.com')).to be_present | ||||
|     end | ||||
|  | @ -163,15 +149,10 @@ RSpec.describe 'Domain Blocks' do | |||
|         Fabricate(:domain_block, domain: 'bar.com', severity: :suspend) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns http unprocessable entity' do | ||||
|       it 'returns existing domain block in error', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(422) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns existing domain block in error' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json[:existing_domain_block][:domain]).to eq('bar.com') | ||||
|       end | ||||
|     end | ||||
|  | @ -199,15 +180,10 @@ RSpec.describe 'Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the updated domain block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the updated domain block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to match a_hash_including( | ||||
|         { | ||||
|           id: domain_block.id.to_s, | ||||
|  | @ -241,15 +217,10 @@ RSpec.describe 'Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes the domain block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes the domain block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(DomainBlock.find_by(id: domain_block.id)).to be_nil | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -93,15 +93,10 @@ RSpec.describe 'Email Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     context 'when email domain block exists' do | ||||
|       it 'returns http success' do | ||||
|       it 'returns the correct blocked domain', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns the correct blocked domain' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json[:domain]).to eq(email_domain_block.domain) | ||||
|       end | ||||
|     end | ||||
|  | @ -126,15 +121,10 @@ RSpec.describe 'Email Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the correct blocked email domain', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the correct blocked email domain' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json[:domain]).to eq(params[:domain]) | ||||
|     end | ||||
| 
 | ||||
|  | @ -182,21 +172,11 @@ RSpec.describe 'Email Domain Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes email domain block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns an empty body' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to be_empty | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes email domain block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(EmailDomainBlock.find_by(id: email_domain_block.id)).to be_nil | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -84,15 +84,10 @@ RSpec.describe 'IP Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the correct ip block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the correct ip block' do | ||||
|       subject | ||||
| 
 | ||||
|       json = body_as_json | ||||
| 
 | ||||
|       expect(json[:ip]).to eq("#{ip_block.ip}/#{ip_block.ip.prefix}") | ||||
|  | @ -119,15 +114,10 @@ RSpec.describe 'IP Blocks' do | |||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
|     it_behaves_like 'forbidden for wrong role', 'Moderator' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the correct ip block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the correct ip block' do | ||||
|       subject | ||||
| 
 | ||||
|       json = body_as_json | ||||
| 
 | ||||
|       expect(json[:ip]).to eq("#{params[:ip]}/32") | ||||
|  | @ -186,15 +176,10 @@ RSpec.describe 'IP Blocks' do | |||
|     let!(:ip_block) { IpBlock.create(ip: '185.200.13.3', severity: 'no_access', comment: 'Spam', expires_in: 48.hours) } | ||||
|     let(:params)    { { severity: 'sign_up_requires_approval', comment: 'Decreasing severity' } } | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the correct ip block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the correct ip block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to match(hash_including({ | ||||
|         ip: "#{ip_block.ip}/#{ip_block.ip.prefix}", | ||||
|         severity: 'sign_up_requires_approval', | ||||
|  | @ -226,21 +211,11 @@ RSpec.describe 'IP Blocks' do | |||
| 
 | ||||
|     let!(:ip_block) { IpBlock.create(ip: '185.200.13.3', severity: 'no_access') } | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes the ip block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns an empty body' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to be_empty | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes the ip block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(IpBlock.find_by(id: ip_block.id)).to be_nil | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -122,15 +122,10 @@ RSpec.describe 'Reports' do | |||
|     it_behaves_like 'forbidden for wrong scope', 'write:statuses' | ||||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the requested report content', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the requested report content' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to include( | ||||
|         { | ||||
|           id: report.id.to_s, | ||||
|  | @ -155,18 +150,10 @@ RSpec.describe 'Reports' do | |||
|     let!(:report) { Fabricate(:report, category: :other) } | ||||
|     let(:params)  { { category: 'spam' } } | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
|     it 'updates the report category', :aggregate_failures do | ||||
|       expect { subject }.to change { report.reload.category }.from('other').to('spam') | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'updates the report category' do | ||||
|       expect { subject }.to change { report.reload.category }.from('other').to('spam') | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the updated report content' do | ||||
|       subject | ||||
| 
 | ||||
|       report.reload | ||||
| 
 | ||||
|  | @ -196,14 +183,9 @@ RSpec.describe 'Reports' do | |||
|     it_behaves_like 'forbidden for wrong scope', 'write:statuses' | ||||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'marks report as resolved' do | ||||
|     it 'marks report as resolved', :aggregate_failures do | ||||
|       expect { subject }.to change { report.reload.unresolved? }.from(true).to(false) | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|  | @ -217,14 +199,9 @@ RSpec.describe 'Reports' do | |||
|     it_behaves_like 'forbidden for wrong scope', 'write:statuses' | ||||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'marks report as unresolved' do | ||||
|     it 'marks report as unresolved', :aggregate_failures do | ||||
|       expect { subject }.to change { report.reload.unresolved? }.from(false).to(true) | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|  | @ -238,14 +215,9 @@ RSpec.describe 'Reports' do | |||
|     it_behaves_like 'forbidden for wrong scope', 'write:statuses' | ||||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'assigns report to the requesting user' do | ||||
|     it 'assigns report to the requesting user', :aggregate_failures do | ||||
|       expect { subject }.to change { report.reload.assigned_account_id }.from(nil).to(user.account.id) | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|  | @ -259,14 +231,9 @@ RSpec.describe 'Reports' do | |||
|     it_behaves_like 'forbidden for wrong scope', 'write:statuses' | ||||
|     it_behaves_like 'forbidden for wrong role', '' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'unassigns report from assignee' do | ||||
|     it 'unassigns report from assignee', :aggregate_failures do | ||||
|       expect { subject }.to change { report.reload.assigned_account_id }.from(user.account.id).to(nil) | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
|   end | ||||
| end | ||||
|  |  | |||
|  | @ -12,14 +12,10 @@ describe 'Credentials' do | |||
|       let(:token)   { Fabricate(:accessible_access_token, scopes: 'read', application: Fabricate(:application)) } | ||||
|       let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|       it 'returns the app information correctly', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns the app information correctly' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json).to match( | ||||
|           a_hash_including( | ||||
|  |  | |||
|  | @ -23,20 +23,11 @@ RSpec.describe 'Apps' do | |||
|     end | ||||
| 
 | ||||
|     context 'with valid params' do | ||||
|       it 'returns http success' do | ||||
|       it 'creates an OAuth app', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'creates an OAuth app' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(Doorkeeper::Application.find_by(name: client_name)).to be_present | ||||
|       end | ||||
| 
 | ||||
|       it 'returns client ID and client secret' do | ||||
|         subject | ||||
| 
 | ||||
|         body = body_as_json | ||||
| 
 | ||||
|  | @ -58,15 +49,10 @@ RSpec.describe 'Apps' do | |||
|     context 'with many duplicate scopes' do | ||||
|       let(:scopes) { (%w(read) * 40).join(' ') } | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|       it 'only saves the scope once', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'only saves the scope once' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(Doorkeeper::Application.find_by(name: client_name).scopes.to_s).to eq 'read' | ||||
|       end | ||||
|     end | ||||
|  |  | |||
|  | @ -22,15 +22,10 @@ RSpec.describe 'Domain blocks' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'write:blocks' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the domains blocked by the requesting user', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the domains blocked by the requesting user' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to match_array(blocked_domains) | ||||
|     end | ||||
| 
 | ||||
|  | @ -54,15 +49,10 @@ RSpec.describe 'Domain blocks' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:blocks' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'creates a domain block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'creates a domain block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(user.account.domain_blocking?(params[:domain])).to be(true) | ||||
|     end | ||||
| 
 | ||||
|  | @ -100,15 +90,10 @@ RSpec.describe 'Domain blocks' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:blocks' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes the specified domain block', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes the specified domain block' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(user.account.domain_blocking?('example.com')).to be(false) | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -32,15 +32,10 @@ RSpec.describe 'Follow requests' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'write write:follows' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the expected content from accounts requesting to follow', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the expected content from accounts requesting to follow' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to match_array(expected_response) | ||||
|     end | ||||
| 
 | ||||
|  | @ -68,19 +63,9 @@ RSpec.describe 'Follow requests' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:follows' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'allows the requesting follower to follow' do | ||||
|     it 'allows the requesting follower to follow', :aggregate_failures do | ||||
|       expect { subject }.to change { follower.following?(user.account) }.from(false).to(true) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns JSON with followed_by set to true' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|       expect(body_as_json[:followed_by]).to be true | ||||
|     end | ||||
|   end | ||||
|  | @ -98,21 +83,11 @@ RSpec.describe 'Follow requests' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:follows' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'removes the follow request', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'removes the follow request' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(FollowRequest.where(target_account: user.account, account: follower)).to_not exist | ||||
|     end | ||||
| 
 | ||||
|     it 'returns JSON with followed_by set to false' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json[:followed_by]).to be false | ||||
|     end | ||||
|   end | ||||
|  |  | |||
|  | @ -39,15 +39,10 @@ RSpec.describe 'Lists' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'write write:lists' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the expected lists', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the expected lists' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to match_array(expected_response) | ||||
|     end | ||||
|   end | ||||
|  | @ -61,15 +56,10 @@ RSpec.describe 'Lists' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'write write:lists' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the requested list correctly', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the requested list correctly' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to eq({ | ||||
|         id: list.id.to_s, | ||||
|         title: list.title, | ||||
|  | @ -106,21 +96,11 @@ RSpec.describe 'Lists' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:lists' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the new list', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the new list' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(body_as_json).to match(a_hash_including(title: 'my list', replies_policy: 'none', exclusive: true)) | ||||
|     end | ||||
| 
 | ||||
|     it 'creates a list' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(List.where(account: user.account).count).to eq(1) | ||||
|     end | ||||
| 
 | ||||
|  | @ -155,15 +135,10 @@ RSpec.describe 'Lists' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:lists' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'returns the updated list', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'returns the updated list' do | ||||
|       subject | ||||
| 
 | ||||
|       list.reload | ||||
| 
 | ||||
|       expect(body_as_json).to eq({ | ||||
|  | @ -214,15 +189,10 @@ RSpec.describe 'Lists' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:lists' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'deletes the list', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'deletes the list' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(List.where(id: list.id)).to_not exist | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
|  | @ -17,15 +17,10 @@ RSpec.describe 'Tags' do | |||
|       let!(:tag) { Fabricate(:tag) } | ||||
|       let(:name) { tag.name } | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|       it 'returns the tag', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'returns the tag' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(body_as_json[:name]).to eq(name) | ||||
|       end | ||||
|     end | ||||
|  | @ -62,15 +57,10 @@ RSpec.describe 'Tags' do | |||
|     it_behaves_like 'forbidden for wrong scope', 'read read:follows' | ||||
| 
 | ||||
|     context 'when the tag exists' do | ||||
|       it 'returns http success' do | ||||
|       it 'creates follow', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(:success) | ||||
|       end | ||||
| 
 | ||||
|       it 'creates follow' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(TagFollow.where(tag: tag, account: user.account)).to exist | ||||
|       end | ||||
|     end | ||||
|  | @ -78,21 +68,11 @@ RSpec.describe 'Tags' do | |||
|     context 'when the tag does not exist' do | ||||
|       let(:name) { 'hoge' } | ||||
| 
 | ||||
|       it 'returns http success' do | ||||
|       it 'creates a new tag with the specified name', :aggregate_failures do | ||||
|         subject | ||||
| 
 | ||||
|         expect(response).to have_http_status(200) | ||||
|       end | ||||
| 
 | ||||
|       it 'creates a new tag with the specified name' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(Tag.where(name: name)).to exist | ||||
|       end | ||||
| 
 | ||||
|       it 'creates follow' do | ||||
|         subject | ||||
| 
 | ||||
|         expect(TagFollow.where(tag: Tag.find_by(name: name), account: user.account)).to exist | ||||
|       end | ||||
|     end | ||||
|  | @ -133,15 +113,10 @@ RSpec.describe 'Tags' do | |||
| 
 | ||||
|     it_behaves_like 'forbidden for wrong scope', 'read read:follows' | ||||
| 
 | ||||
|     it 'returns http success' do | ||||
|     it 'removes the follow', :aggregate_failures do | ||||
|       subject | ||||
| 
 | ||||
|       expect(response).to have_http_status(200) | ||||
|     end | ||||
| 
 | ||||
|     it 'removes the follow' do | ||||
|       subject | ||||
| 
 | ||||
|       expect(TagFollow.where(tag: tag, account: user.account)).to_not exist | ||||
|     end | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue