mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-20 03:25:17 +01:00
Convert admin/invites
controller specs to system specs (#32450)
This commit is contained in:
parent
9258ee8847
commit
41e342a88f
@ -1,4 +1,4 @@
|
||||
%tr
|
||||
%tr{ id: dom_id(invite) }
|
||||
%td
|
||||
.input-copy
|
||||
.input-copy__wrapper
|
||||
|
@ -1,59 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::InvitesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
subject { get :index, params: { available: true } }
|
||||
|
||||
let!(:invite) { Fabricate(:invite) }
|
||||
|
||||
it 'renders index page' do
|
||||
expect(subject).to render_template :index
|
||||
expect(response.body)
|
||||
.to include(invite.code)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } }
|
||||
|
||||
it 'succeeds to create a invite' do
|
||||
expect { subject }.to change(Invite, :count).by(1)
|
||||
expect(subject).to redirect_to admin_invites_path
|
||||
expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
subject { delete :destroy, params: { id: invite.id } }
|
||||
|
||||
let!(:invite) { Fabricate(:invite, expires_at: nil) }
|
||||
|
||||
it 'expires invite' do
|
||||
expect(subject).to redirect_to admin_invites_path
|
||||
expect(invite.reload).to be_expired
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #deactivate_all' do
|
||||
before { Fabricate(:invite, expires_at: nil) }
|
||||
|
||||
it 'expires all invites, then redirects to admin_invites_path' do
|
||||
expect { post :deactivate_all }
|
||||
.to change { Invite.exists?(expires_at: nil) }
|
||||
.from(true)
|
||||
.to(false)
|
||||
|
||||
expect(response).to redirect_to admin_invites_path
|
||||
end
|
||||
end
|
||||
end
|
63
spec/system/admin/invites_spec.rb
Normal file
63
spec/system/admin/invites_spec.rb
Normal file
@ -0,0 +1,63 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Invites' do
|
||||
describe 'Invite interaction' do
|
||||
let!(:invite) { Fabricate(:invite, expires_at: nil) }
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before { sign_in user }
|
||||
|
||||
it 'allows invite listing and creation' do
|
||||
visit admin_invites_path
|
||||
|
||||
expect(page)
|
||||
.to have_title(I18n.t('admin.invites.title'))
|
||||
for_invite(invite) do
|
||||
expect(find('input').value)
|
||||
.to include(invite.code)
|
||||
end
|
||||
|
||||
select I18n.t('invites.max_uses', count: 10), from: max_use_field
|
||||
|
||||
expect { generate_invite }
|
||||
.to change(Invite, :count).by(1)
|
||||
expect(user.invites.last)
|
||||
.to have_attributes(max_uses: 10)
|
||||
end
|
||||
|
||||
it 'allows invite expiration' do
|
||||
visit admin_invites_path
|
||||
|
||||
for_invite(invite) do
|
||||
expect { expire_invite }
|
||||
.to change { invite.reload.expired? }.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'allows invite deactivation' do
|
||||
visit admin_invites_path
|
||||
|
||||
expect { click_on I18n.t('admin.invites.deactivate_all') }
|
||||
.to change { Invite.exists?(expires_at: nil) }.from(true).to(false)
|
||||
end
|
||||
|
||||
def for_invite(invite, &block)
|
||||
within("#invite_#{invite.id}", &block)
|
||||
end
|
||||
|
||||
def expire_invite
|
||||
click_on I18n.t('invites.delete')
|
||||
end
|
||||
|
||||
def generate_invite
|
||||
click_on I18n.t('invites.generate')
|
||||
end
|
||||
|
||||
def max_use_field
|
||||
I18n.t('simple_form.labels.defaults.max_uses')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user