users_spec.rb 978 B

12345678910111213141516171819202122232425262728293031323334353637
  1. require 'rails_helper'
  2. describe User do
  3. describe "validations" do
  4. describe "invitation_code" do
  5. context "when configured to use invitation codes" do
  6. before do
  7. stub(User).using_invitation_code? {true}
  8. end
  9. it "only accepts valid invitation codes" do
  10. User::INVITATION_CODES.each do |v|
  11. should allow_value(v).for(:invitation_code)
  12. end
  13. end
  14. it "can reject invalid invitation codes" do
  15. %w['foo', 'bar'].each do |v|
  16. should_not allow_value(v).for(:invitation_code)
  17. end
  18. end
  19. end
  20. context "when configured not to use invitation codes" do
  21. before do
  22. stub(User).using_invitation_code? {false}
  23. end
  24. it "skips this validation" do
  25. %w['foo', 'bar', nil, ''].each do |v|
  26. should allow_value(v).for(:invitation_code)
  27. end
  28. end
  29. end
  30. end
  31. end
  32. end