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.

42 lines
1.3 KiB

  1. require 'rails_helper'
  2. RSpec.describe User, type: :model do
  3. let(:account) { Fabricate(:account, username: 'alice') }
  4. let(:password) { 'abcd1234' }
  5. describe 'blacklist' do
  6. it 'should allow a non-blacklisted user to be created' do
  7. user = User.new(email: 'foo@example.com', account: account, password: password)
  8. expect(user.valid?).to be_truthy
  9. end
  10. it 'should not allow a blacklisted user to be created' do
  11. user = User.new(email: 'foo@mvrht.com', account: account, password: password)
  12. expect(user.valid?).to be_falsey
  13. end
  14. end
  15. describe 'whitelist' do
  16. around(:each) do |example|
  17. old_whitelist = Rails.configuration.x.email_whitelist
  18. Rails.configuration.x.email_domains_whitelist = 'mastodon.space'
  19. example.run
  20. Rails.configuration.x.email_domains_whitelist = old_whitelist
  21. end
  22. it 'should not allow a user to be created unless they are whitelisted' do
  23. user = User.new(email: 'foo@example.com', account: account, password: password)
  24. expect(user.valid?).to be_falsey
  25. end
  26. it 'should allow a user to be created if they are whitelisted' do
  27. user = User.new(email: 'foo@mastodon.space', account: account, password: password)
  28. expect(user.valid?).to be_truthy
  29. end
  30. end
  31. end