From 730ab70ddb3060d5bd19c0d4a999929e86858cdb Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 19 Jul 2007 18:13:53 +0000 Subject: [PATCH] ActionItem9: profile can be owner by an user --- app/models/profile.rb | 1 + app/models/user.rb | 6 ++++++ db/migrate/002_create_profiles.rb | 1 + test/fixtures/profiles.yml | 12 ++++++++++-- test/unit/profile_test.rb | 10 ++++++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 4ff768a..3da3062 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -15,6 +15,7 @@ class Profile < ActiveRecord::Base has_many :domains, :as => :owner has_many :boxes, :as => :owner belongs_to :virtual_community + belongs_to :user validates_presence_of :identifier validates_format_of :identifier, :with => /^[a-z][a-z0-9_]+[a-z0-9]$/ diff --git a/app/models/user.rb b/app/models/user.rb index a7905f1..b6e0ded 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,11 @@ require 'digest/sha1' class User < ActiveRecord::Base + + before_create do |user| + # TODO + end + has_one :personal_profile, :class_name => Profile + # Virtual attribute for the unencrypted password attr_accessor :password diff --git a/db/migrate/002_create_profiles.rb b/db/migrate/002_create_profiles.rb index 4a59e7a..16e32e0 100644 --- a/db/migrate/002_create_profiles.rb +++ b/db/migrate/002_create_profiles.rb @@ -4,6 +4,7 @@ class CreateProfiles < ActiveRecord::Migration t.column :name, :string t.column :identifier, :string t.column :virtual_community_id, :integer + t.column :user_id, :integer t.column :template, :string, :default => "default" t.column :theme, :string, :default => "default" t.column :icons_theme, :string, :default => "default" diff --git a/test/fixtures/profiles.yml b/test/fixtures/profiles.yml index c7f94ad..6f4a089 100644 --- a/test/fixtures/profiles.yml +++ b/test/fixtures/profiles.yml @@ -4,7 +4,7 @@ johndoe: name: 'John Doe' identifier: johndoe virtual_community_id: 1 - owner_id: 1 + user_id: 1 template: 'default' icons_theme: 'default' theme: 'default' @@ -13,7 +13,15 @@ joerandomhacker: name: 'Joe Random Hacker' identifier: joerandomhacker virtual_community_id: 1 - owner_id: 2 + user_id: 2 + template: 'simple' + icons_theme: 'simple' + theme: 'simple' +john_and_joe: + id: 3 + name: "John and Joe's Production Cooperative" + identifier: john_and_joe + virtual_community_id: 1 template: 'simple' icons_theme: 'simple' theme: 'simple' diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index e18ba36..d990ea9 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -39,9 +39,15 @@ class ProfileTest < Test::Unit::TestCase assert_kind_of VirtualCommunity, p.virtual_community end - def test_can_have_user_as_owner + def test_can_have_user p = profiles(:johndoe) - assert_kind_of User, p.owner + assert_kind_of User, p.user + end + + def test_may_have_no_user + p = profiles(:john_and_joe) + assert_nil p.user + assert p.valid? end end -- libgit2 0.21.2