Error message for duplicate username; refactor User validation specs.
This commit is contained in:
parent
d3a62c7a45
commit
83b23a0ffe
3 changed files with 54 additions and 40 deletions
|
|
@ -6,6 +6,13 @@
|
||||||
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
||||||
|
|
||||||
en:
|
en:
|
||||||
|
activemodel:
|
||||||
|
errors:
|
||||||
|
models:
|
||||||
|
user:
|
||||||
|
attributes:
|
||||||
|
username:
|
||||||
|
taken: "is already taken."
|
||||||
hello: "Hello world"
|
hello: "Hello world"
|
||||||
application:
|
application:
|
||||||
helper:
|
helper:
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Factory.define :user do |u|
|
||||||
u.password_confirmation "bluepin7"
|
u.password_confirmation "bluepin7"
|
||||||
u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export
|
u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export
|
||||||
u.after_build do |user|
|
u.after_build do |user|
|
||||||
user.person = Factory(:person, :owner_id => user._id,
|
user.person = Factory.build(:person, :owner_id => user._id,
|
||||||
:serialized_public_key => user.encryption_key.public_key.export,
|
:serialized_public_key => user.encryption_key.public_key.export,
|
||||||
:diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
|
:diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,31 @@ describe User do
|
||||||
let(:user3) { Factory(:user) }
|
let(:user3) { Factory(:user) }
|
||||||
let(:aspect3) { user3.aspect(:name => 'stuff') }
|
let(:aspect3) { user3.aspect(:name => 'stuff') }
|
||||||
|
|
||||||
describe "validations" do
|
describe "validation" do
|
||||||
|
|
||||||
|
describe "of passwords" do
|
||||||
|
it "fails if password doesn't match confirmation" do
|
||||||
|
user = Factory.build(:user, :password => "password", :password_confirmation => "nope")
|
||||||
|
user.should_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "succeeds if password matches confirmation" do
|
||||||
|
user = Factory.build(:user, :password => "password", :password_confirmation => "password")
|
||||||
|
user.should be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "of username" do
|
||||||
it "requires a username" do
|
it "requires a username" do
|
||||||
user = Factory.build(:user, :username => nil)
|
user = Factory.build(:user, :username => nil)
|
||||||
user.should_not be_valid
|
user.should_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "requires a unique username" do
|
||||||
|
duplicate_user = Factory.build(:user, :username => user.username)
|
||||||
|
duplicate_user.should_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
it "downcases the username" do
|
it "downcases the username" do
|
||||||
user = Factory.build(:user, :username => "ALLUPPERCASE")
|
user = Factory.build(:user, :username => "ALLUPPERCASE")
|
||||||
user.valid?
|
user.valid?
|
||||||
|
|
@ -26,19 +46,6 @@ describe User do
|
||||||
user.valid?
|
user.valid?
|
||||||
user.username.should == "someuppercase"
|
user.username.should == "someuppercase"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "confirms the password" do
|
|
||||||
pending "I cannot figure out why this doesn't work. --Raphael"
|
|
||||||
user = User.instantiate!(
|
|
||||||
:email => "tom@tom.joindiaspora.com",
|
|
||||||
:username => "tom",
|
|
||||||
:password => "evankorth",
|
|
||||||
:password_confirmation => "potatoes",
|
|
||||||
:person => Person.new(
|
|
||||||
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
|
|
||||||
)
|
|
||||||
user.created_at.should be_nil
|
|
||||||
user.valid?.should be_false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue