diff options
author | jessib <jessib@riseup.net> | 2013-09-05 14:00:50 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-09-05 14:00:50 -0700 |
commit | 3ef22b5a856e1f576fb0a6a589b6b7ab41e1dd18 (patch) | |
tree | b10e99e842a232686872606cd16f631b8397f279 | |
parent | 8e8f5ddda08a883842a8c3e2ffa994e12b25dd39 (diff) |
For moment, have identity's address handle aliased from login so we can use LoginFormatValidation. However, this is not how we will want it eventually.
One issue is that the errors messages are set on login, rather than the appropriate field.
-rw-r--r-- | users/app/models/identity.rb | 6 | ||||
-rw-r--r-- | users/app/models/login_format_validation.rb | 8 | ||||
-rw-r--r-- | users/test/unit/identity_test.rb | 8 |
3 files changed, 19 insertions, 3 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb index e197c9c..91345a0 100644 --- a/users/app/models/identity.rb +++ b/users/app/models/identity.rb @@ -1,4 +1,5 @@ class Identity < CouchRest::Model::Base + include LoginFormatValidation use_database :identities @@ -64,6 +65,11 @@ class Identity < CouchRest::Model::Base write_attribute('keys', keys.merge(type => value)) end + # for LoginFormatValidation + def login + self.address.handle + end + protected def unique_forward diff --git a/users/app/models/login_format_validation.rb b/users/app/models/login_format_validation.rb index 1d02bd1..c1fcf70 100644 --- a/users/app/models/login_format_validation.rb +++ b/users/app/models/login_format_validation.rb @@ -1,19 +1,21 @@ module LoginFormatValidation extend ActiveSupport::Concern + #TODO: Probably will replace this. Playing with using it for aliases too, but won't want it connected to login field. + included do # Have multiple regular expression validations so we can get specific error messages: validates :login, :format => { :with => /\A.{2,}\z/, - :message => "Login must have at least two characters"} + :message => "Must have at least two characters"} validates :login, :format => { :with => /\A[a-z\d_\.-]+\z/, :message => "Only lowercase letters, digits, . - and _ allowed."} validates :login, :format => { :with => /\A[a-z].*\z/, - :message => "Login must begin with a lowercase letter"} + :message => "Must begin with a lowercase letter"} validates :login, :format => { :with => /\A.*[a-z\d]\z/, - :message => "Login must end with a letter or digit"} + :message => "Must end with a letter or digit"} end end diff --git a/users/test/unit/identity_test.rb b/users/test/unit/identity_test.rb index a77613a..b3918f1 100644 --- a/users/test/unit/identity_test.rb +++ b/users/test/unit/identity_test.rb @@ -76,6 +76,14 @@ class IdentityTest < ActiveSupport::TestCase assert_match /needs to end in/, id.errors[:address].first end + test "only lowercase alias" do + id = Identity.create_for @user, address: alias_name.capitalize + assert !id.valid? + #hacky way to do this, but okay for now: + assert id.errors.messages.flatten(2).include? "Must begin with a lowercase letter" + assert id.errors.messages.flatten(2).include? "Only lowercase letters, digits, . - and _ allowed." + end + def alias_name @alias_name ||= Faker::Internet.user_name |