You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::InvitesController do
  4. render_views
  5. let(:user) { Fabricate(:user, admin: true) }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe 'GET #index' do
  10. subject { get :index, params: { available: true } }
  11. let!(:invite) { Fabricate(:invite) }
  12. it 'renders index page' do
  13. expect(subject).to render_template :index
  14. expect(assigns(:invites)).to include invite
  15. end
  16. end
  17. describe 'POST #create' do
  18. subject { post :create, params: { invite: { max_uses: '10', expires_in: 1800 } } }
  19. it 'succeeds to create a invite' do
  20. expect { subject }.to change { Invite.count }.by(1)
  21. expect(subject).to redirect_to admin_invites_path
  22. expect(Invite.last).to have_attributes(user_id: user.id, max_uses: 10)
  23. end
  24. end
  25. describe 'DELETE #destroy' do
  26. let!(:invite) { Fabricate(:invite, expires_at: nil) }
  27. subject { delete :destroy, params: { id: invite.id } }
  28. it 'expires invite' do
  29. expect(subject).to redirect_to admin_invites_path
  30. expect(invite.reload).to be_expired
  31. end
  32. end
  33. describe 'POST #deactivate_all' do
  34. it 'expires all invites, then redirects to admin_invites_path' do
  35. invites = Fabricate.times(2, :invite, expires_at: nil)
  36. post :deactivate_all
  37. invites.each do |invite|
  38. expect(invite.reload).to be_expired
  39. end
  40. expect(response).to redirect_to admin_invites_path
  41. end
  42. end
  43. end