-
danielvincent a rédigé
removed user#aspect method. all aspect creation should be scoped through the user -> aspect association proper: user.aspects.create(opts)
danielvincent a rédigéremoved user#aspect method. all aspect creation should be scoped through the user -> aspect association proper: user.aspects.create(opts)
user_spec.rb 7,90 Kio
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe User do
let(:user) { make_user }
let(:aspect) { user.aspects.create(:name => 'heroes') }
let(:user2) { make_user }
let(:aspect2) { user2.aspects.create(:name => 'stuff') }
it 'should have a key' do
user.encryption_key.should_not be nil
end
describe 'overwriting people' do
it 'does not overwrite old users with factory' do
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"
new_user = Factory.create(:user, :id => user.id)
new_user.persisted?.should be_true
new_user.id.should_not == user.id
end
it 'does not overwrite old users with create' do
pending "Why do you want to set ids directly? MONGOMAPPERRRRR!!!"
params = {:username => "ohai",
:email => "ohai@example.com",
:password => "password",
:password_confirmation => "password",
:person =>
{:profile =>
{:first_name => "O",
:last_name => "Hai"}
}
}
params[:id] = user.id
new_user = User.build(params)
new_user.save
new_user.persisted?.should be_true
new_user.id.should_not == user.id
end
end
describe "validation" do
describe "of associated person" do
it "fails if person is not valid" do
user = Factory.build(:user)
user.should be_valid
user.person.update_attribute(:serialized_public_key, nil)
user.person.should_not be_valid
user.should_not be_valid
user.errors.full_messages.count.should == 1
user.errors.full_messages.first.should =~ /Person is invalid/i
end
end
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