Commit 730ab70ddb3060d5bd19c0d4a999929e86858cdb

Authored by AntonioTerceiro
1 parent 263e47b2

ActionItem9: profile can be owner by an user



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@100 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile.rb
... ... @@ -15,6 +15,7 @@ class Profile < ActiveRecord::Base
15 15 has_many :domains, :as => :owner
16 16 has_many :boxes, :as => :owner
17 17 belongs_to :virtual_community
  18 + belongs_to :user
18 19  
19 20 validates_presence_of :identifier
20 21 validates_format_of :identifier, :with => /^[a-z][a-z0-9_]+[a-z0-9]$/
... ...
app/models/user.rb
1 1 require 'digest/sha1'
2 2 class User < ActiveRecord::Base
  3 +
  4 + before_create do |user|
  5 + # TODO
  6 + end
  7 + has_one :personal_profile, :class_name => Profile
  8 +
3 9 # Virtual attribute for the unencrypted password
4 10 attr_accessor :password
5 11  
... ...
db/migrate/002_create_profiles.rb
... ... @@ -4,6 +4,7 @@ class CreateProfiles &lt; ActiveRecord::Migration
4 4 t.column :name, :string
5 5 t.column :identifier, :string
6 6 t.column :virtual_community_id, :integer
  7 + t.column :user_id, :integer
7 8 t.column :template, :string, :default => "default"
8 9 t.column :theme, :string, :default => "default"
9 10 t.column :icons_theme, :string, :default => "default"
... ...
test/fixtures/profiles.yml
... ... @@ -4,7 +4,7 @@ johndoe:
4 4 name: 'John Doe'
5 5 identifier: johndoe
6 6 virtual_community_id: 1
7   - owner_id: 1
  7 + user_id: 1
8 8 template: 'default'
9 9 icons_theme: 'default'
10 10 theme: 'default'
... ... @@ -13,7 +13,15 @@ joerandomhacker:
13 13 name: 'Joe Random Hacker'
14 14 identifier: joerandomhacker
15 15 virtual_community_id: 1
16   - owner_id: 2
  16 + user_id: 2
  17 + template: 'simple'
  18 + icons_theme: 'simple'
  19 + theme: 'simple'
  20 +john_and_joe:
  21 + id: 3
  22 + name: "John and Joe's Production Cooperative"
  23 + identifier: john_and_joe
  24 + virtual_community_id: 1
17 25 template: 'simple'
18 26 icons_theme: 'simple'
19 27 theme: 'simple'
... ...
test/unit/profile_test.rb
... ... @@ -39,9 +39,15 @@ class ProfileTest &lt; Test::Unit::TestCase
39 39 assert_kind_of VirtualCommunity, p.virtual_community
40 40 end
41 41  
42   - def test_can_have_user_as_owner
  42 + def test_can_have_user
43 43 p = profiles(:johndoe)
44   - assert_kind_of User, p.owner
  44 + assert_kind_of User, p.user
  45 + end
  46 +
  47 + def test_may_have_no_user
  48 + p = profiles(:john_and_joe)
  49 + assert_nil p.user
  50 + assert p.valid?
45 51 end
46 52  
47 53 end
... ...