Commit a98262bf1f8475a654d67b26d796c9833df614cd
1 parent
04bc7077
Exists in
master
and in
28 other branches
ActionItem6: test and fixtures fixed for the new model hierachy
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@200 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
58 additions
and
45 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -39,8 +39,8 @@ class Profile < ActiveRecord::Base |
39 | 39 | |
40 | 40 | # A profile_owner cannot have more than one profile, but many profiles can exist |
41 | 41 | # without being associated to a particular user. |
42 | - validates_uniqueness_of :profile_owner_id, :scope => :profile_owner_type, :if => (lambda do |profile| | |
43 | - ! profile.profile_owner_id.nil? | |
42 | + validates_uniqueness_of :user_id, :if => (lambda do |profile| | |
43 | + ! profile.user_id.nil? | |
44 | 44 | end) |
45 | 45 | |
46 | 46 | # creates a new Profile. By default, it is attached to the default | ... | ... |
db/migrate/002_create_profiles.rb
... | ... | @@ -2,6 +2,7 @@ class CreateProfiles < ActiveRecord::Migration |
2 | 2 | def self.up |
3 | 3 | create_table :profiles do |t| |
4 | 4 | t.column :name, :string |
5 | + t.column :type, :string | |
5 | 6 | t.column :identifier, :string |
6 | 7 | t.column :virtual_community_id, :integer |
7 | 8 | t.column :flexible_template_template, :string, :default => "default" | ... | ... |
test/fixtures/enterprises.yml
test/fixtures/profiles.yml
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | johndoe: |
3 | 3 | id: 1 |
4 | 4 | name: 'John Doe' |
5 | + type: 'Person' | |
5 | 6 | identifier: johndoe |
6 | 7 | virtual_community_id: 1 |
7 | 8 | user_id: 1 |
... | ... | @@ -11,6 +12,7 @@ johndoe: |
11 | 12 | joerandomhacker: |
12 | 13 | id: 2 |
13 | 14 | name: 'Joe Random Hacker' |
15 | + type: 'Person' | |
14 | 16 | identifier: joerandomhacker |
15 | 17 | virtual_community_id: 1 |
16 | 18 | user_id: 2 |
... | ... | @@ -20,6 +22,7 @@ joerandomhacker: |
20 | 22 | john_and_joe: |
21 | 23 | id: 3 |
22 | 24 | name: "John and Joe's Production Cooperative" |
25 | + type: 'Person' | |
23 | 26 | identifier: john_and_joe |
24 | 27 | virtual_community_id: 1 |
25 | 28 | flexible_template_template: 'simple' |
... | ... | @@ -28,6 +31,7 @@ john_and_joe: |
28 | 31 | ze: |
29 | 32 | id: 4 |
30 | 33 | name: "Zé" |
34 | + type: 'Person' | |
31 | 35 | identifier: ze |
32 | 36 | virtual_community_id: 1 |
33 | 37 | flexible_template_template: 'default' | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class PersonTest < Test::Unit::TestCase | |
4 | + fixtures :profiles, :users | |
5 | + | |
6 | + # Replace this with your real tests. | |
7 | + def test_truth | |
8 | + assert true | |
9 | + end | |
10 | + | |
11 | + def test_can_have_user | |
12 | + p = profiles(:johndoe) | |
13 | + assert_kind_of User, p.user | |
14 | + end | |
15 | + | |
16 | + def test_may_have_no_user | |
17 | + p = profiles(:john_and_joe) | |
18 | + assert_nil p.user | |
19 | + assert p.valid? | |
20 | + end | |
21 | + | |
22 | + def test_only_one_profile_per_user | |
23 | + p1 = profiles(:johndoe) | |
24 | + assert_equal users(:johndoe), p1.user | |
25 | + | |
26 | + p2 = Person.new | |
27 | + p2.user = users(:johndoe) | |
28 | + assert !p2.valid? | |
29 | + assert p2.errors.invalid?(:user_id) | |
30 | + end | |
31 | + | |
32 | + def test_several_profiles_without_user | |
33 | + p1 = profiles(:john_and_joe) | |
34 | + assert p1.valid? | |
35 | + assert_nil p1.user | |
36 | + | |
37 | + p2 = Person.new | |
38 | + assert !p2.valid? | |
39 | + assert !p2.errors.invalid?(:user_id) | |
40 | + end | |
41 | +end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -39,37 +39,6 @@ class ProfileTest < Test::Unit::TestCase |
39 | 39 | assert_kind_of VirtualCommunity, p.virtual_community |
40 | 40 | end |
41 | 41 | |
42 | - def test_can_have_user | |
43 | - p = profiles(:johndoe) | |
44 | - assert_kind_of User, p.profile_owner | |
45 | - end | |
46 | - | |
47 | - def test_may_have_no_user | |
48 | - p = profiles(:john_and_joe) | |
49 | - assert_nil p.profile_owner | |
50 | - assert p.valid? | |
51 | - end | |
52 | - | |
53 | - def test_only_one_profile_per_user | |
54 | - p1 = profiles(:johndoe) | |
55 | - assert_equal users(:johndoe), p1.profile_owner | |
56 | - | |
57 | - p2 = Profile.new | |
58 | - p2.profile_owner = users(:johndoe) | |
59 | - assert !p2.valid? | |
60 | - assert p2.errors.invalid?(:profile_owner_id) | |
61 | - end | |
62 | - | |
63 | - def test_several_profiles_without_user | |
64 | - p1 = profiles(:john_and_joe) | |
65 | - assert p1.valid? | |
66 | - assert_nil p1.profile_owner | |
67 | - | |
68 | - p2 = Profile.new | |
69 | - assert !p2.valid? | |
70 | - assert !p2.errors.invalid?(:profile_owner_id) | |
71 | - end | |
72 | - | |
73 | 42 | def test_cannot_rename |
74 | 43 | p1 = profiles(:johndoe) |
75 | 44 | assert_raise ArgumentError do | ... | ... |
test/unit/user_test.rb
... | ... | @@ -68,16 +68,16 @@ class UserTest < Test::Unit::TestCase |
68 | 68 | assert_nil users(:johndoe).remember_token |
69 | 69 | end |
70 | 70 | |
71 | - def test_should_create_profile | |
71 | + def test_should_create_person | |
72 | 72 | users_count = User.count |
73 | - profiles_count = Profile.count | |
73 | + person_count = Person.count | |
74 | 74 | |
75 | 75 | user = User.create!(:login => 'new_user', :email => 'new_user@example.com', :password => 'test', :password_confirmation => 'test') |
76 | 76 | |
77 | - assert Profile.exists?(['profile_owner_id = ? and profile_owner_type = ?', user.id, 'User']) | |
77 | + assert Person.exists?(['user_id = ?', user.id]) | |
78 | 78 | |
79 | 79 | assert_equal users_count + 1, User.count |
80 | - assert_equal profiles_count + 1, Profile.count | |
80 | + assert_equal person_count + 1, Person.count | |
81 | 81 | end |
82 | 82 | |
83 | 83 | def test_login_validation | ... | ... |