Commit e9d696527e0d86a554ec4916cc1ad19dcaa89904
1 parent
d5b832ec
Exists in
master
and in
29 other branches
ActionItem153: putting Person in the same environment as User
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1276 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
17 additions
and
1 deletions
Show diff stats
app/models/user.rb
... | ... | @@ -7,11 +7,18 @@ class User < ActiveRecord::Base |
7 | 7 | N_('User|Password') |
8 | 8 | N_('User|Password confirmation') |
9 | 9 | |
10 | + before_create do |user| | |
11 | + if user.environment.nil? | |
12 | + user.environment = Environment.default | |
13 | + end | |
14 | + end | |
15 | + | |
10 | 16 | after_create do |user| |
11 | - Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) | |
17 | + Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id, :environment_id => user.environment_id) | |
12 | 18 | end |
13 | 19 | |
14 | 20 | has_one :person, :dependent => :destroy |
21 | + belongs_to :environment | |
15 | 22 | |
16 | 23 | # Virtual attribute for the unencrypted password |
17 | 24 | attr_accessor :password | ... | ... |
db/migrate/006_create_users.rb
test/unit/user_test.rb
... | ... | @@ -148,6 +148,13 @@ class UserTest < Test::Unit::TestCase |
148 | 148 | assert Person.find_by_identifier('lalala') |
149 | 149 | end |
150 | 150 | |
151 | + should 'set the same environment for user and person objects' do | |
152 | + env = Environment.create!(:name => 'my test environment') | |
153 | + user = create_user(:environment_id => env.id) | |
154 | + assert_equal env, user.environment | |
155 | + assert_equal env, user.person.environment | |
156 | + end | |
157 | + | |
151 | 158 | def test_should_destroy_person_when_destroying_user |
152 | 159 | user = create_user(:login => 'lalala', :email => 'lalala@example.com') |
153 | 160 | assert Person.find_by_identifier('lalala') | ... | ... |