1
0

invites_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Invites' do
  4. include ActionView::RecordIdentifier
  5. let(:user) { Fabricate :user }
  6. before { sign_in user }
  7. describe 'Viewing invites' do
  8. it 'Lists existing user invites' do
  9. invite = Fabricate :invite, user: user
  10. visit invites_path
  11. within css_id(invite) do
  12. expect(page)
  13. .to have_content(invite.uses)
  14. .and have_private_cache_control
  15. expect(copyable_field.value)
  16. .to eq(public_invite_url(invite_code: invite.code))
  17. end
  18. end
  19. end
  20. describe 'Creating a new invite' do
  21. it 'Saves the invite for the user' do
  22. visit invites_path
  23. fill_invite_form
  24. expect { submit_form }
  25. .to change(user.invites, :count).by(1)
  26. end
  27. end
  28. describe 'Deleting an existing invite' do
  29. it 'Expires the invite' do
  30. invite = Fabricate :invite, user: user
  31. visit invites_path
  32. expect { delete_invite(invite) }
  33. .to change { invite.reload.expired? }.to(true)
  34. within css_id(invite) do
  35. expect(page).to have_content I18n.t('invites.expired')
  36. end
  37. end
  38. end
  39. private
  40. def copyable_field
  41. within '.input-copy' do
  42. find(:field, type: :text, readonly: true)
  43. end
  44. end
  45. def submit_form
  46. click_on I18n.t('invites.generate')
  47. end
  48. def delete_invite(invite)
  49. within css_id(invite) do
  50. click_on I18n.t('invites.delete')
  51. end
  52. end
  53. def fill_invite_form
  54. select I18n.t('invites.max_uses', count: 100),
  55. from: I18n.t('simple_form.labels.defaults.max_uses')
  56. select I18n.t("invites.expires_in.#{30.minutes.to_i}"),
  57. from: I18n.t('simple_form.labels.defaults.expires_in')
  58. check I18n.t('simple_form.labels.defaults.autofollow')
  59. end
  60. end