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.

43 lines
1.1 KiB

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