Allowed email checking no longer so ridiculous
This commit is contained in:
parent
15b2c23b51
commit
364cdfed22
2 changed files with 39 additions and 8 deletions
|
|
@ -17,23 +17,28 @@ class User
|
||||||
many :groups, :class_name => 'Group'
|
many :groups, :class_name => 'Group'
|
||||||
|
|
||||||
after_validation_on_create :setup_person
|
after_validation_on_create :setup_person
|
||||||
before_create :pivotal_or_diaspora_only
|
|
||||||
after_create :seed_groups
|
after_create :seed_groups
|
||||||
after_save :check_for_tommy
|
after_save :check_for_tommy
|
||||||
|
|
||||||
before_validation :do_bad_things
|
before_validation :do_bad_things
|
||||||
######## Making things work ########
|
######## Making things work ########
|
||||||
key :email, String
|
key :email, String
|
||||||
#validates_true_for :email, :logic => lambda {self.pivotal_email?}
|
validates_true_for :email, :logic => lambda {self.allowed_email?}
|
||||||
|
|
||||||
|
|
||||||
def self.allowed_email?(email)
|
def allowed_email?
|
||||||
email.include?('@pivotallabs.com') || email.include?("@joindiaspora.com")
|
allowed_emails = ["@pivotallabs.com", "@joindiaspora.com", "@sofaer.net",
|
||||||
|
"wchulley@gmail.com", "kimfuh@yahoo.com", "CJichi@yahoo.com",
|
||||||
|
"madkisso@mit.edu", "bribak@msn.com", "asykley@verizon.net",
|
||||||
|
"paulhaeberli@gmail.com","bondovatic@gmail.com", "dixon1e@yahoo.com"]
|
||||||
|
allowed_emails.each{|allowed|
|
||||||
|
if email.include?(allowed)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
}
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
def pivotal_or_diaspora_only
|
|
||||||
raise "pivotal only" unless User.allowed_email?(self.email)
|
|
||||||
end
|
|
||||||
ensure_index :email
|
ensure_index :email
|
||||||
|
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
|
|
@ -350,7 +355,10 @@ class User
|
||||||
end
|
end
|
||||||
|
|
||||||
def seed_groups
|
def seed_groups
|
||||||
group(:name => "Pivots")
|
group(:name => "Acquaintances")
|
||||||
|
group(:name => "Family")
|
||||||
|
group(:name => "Nemeses")
|
||||||
|
group(:name => "Work")
|
||||||
end
|
end
|
||||||
|
|
||||||
def groups_with_person person
|
def groups_with_person person
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,29 @@ describe User do
|
||||||
@user = Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
@group = @user.group(:name => 'heroes')
|
@group = @user.group(:name => 'heroes')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should create with pivotal or allowed emails' do
|
||||||
|
user1 = Factory.create(:user, :email => "kimfuh@yahoo.com")
|
||||||
|
user2 = Factory.create(:user, :email => "awesome@sofaer.net")
|
||||||
|
user3 = Factory.create(:user, :email => "steveellis@pivotallabs.com")
|
||||||
|
user1.created_at.nil?.should be false
|
||||||
|
user2.created_at.nil?.should be false
|
||||||
|
user3.created_at.nil?.should be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not create with disallowed emails' do
|
||||||
|
proc {
|
||||||
|
user1 = Factory.create(:user, :email => "kimuh@yahoo.com")
|
||||||
|
}.should raise_error /Validation failed/
|
||||||
|
|
||||||
|
proc {
|
||||||
|
user2 = Factory.create(:user, :email => "awesome@sobear.net")
|
||||||
|
}.should raise_error /Validation failed/
|
||||||
|
|
||||||
|
proc {
|
||||||
|
user3 = Factory.create(:user, :email => "steveellis@pivotalabs.com")
|
||||||
|
}.should raise_error /Validation failed/
|
||||||
|
end
|
||||||
|
|
||||||
describe 'profiles' do
|
describe 'profiles' do
|
||||||
it 'should be able to update their profile and send it to their friends' do
|
it 'should be able to update their profile and send it to their friends' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue