Commit 9253c083771c2caf0a2e8838ea7739ac1fa9cae6
1 parent
44950287
Exists in
master
and in
29 other branches
ActionItem93: making profile tests pass again
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@994 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
34 additions
and
12 deletions
Show diff stats
app/models/profile.rb
@@ -15,7 +15,7 @@ class Profile < ActiveRecord::Base | @@ -15,7 +15,7 @@ class Profile < ActiveRecord::Base | ||
15 | 15 | ||
16 | acts_as_design | 16 | acts_as_design |
17 | 17 | ||
18 | -# acts_as_ferret :fields => [ :name ] | 18 | + acts_as_ferret :fields => [ :name ] |
19 | 19 | ||
20 | # Valid identifiers must match this format. | 20 | # Valid identifiers must match this format. |
21 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ | 21 | IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ |
@@ -42,7 +42,7 @@ class Profile < ActiveRecord::Base | @@ -42,7 +42,7 @@ class Profile < ActiveRecord::Base | ||
42 | 42 | ||
43 | has_many :role_assignments, :as => :resource | 43 | has_many :role_assignments, :as => :resource |
44 | 44 | ||
45 | - has_many :articles | 45 | + has_many :articles, :dependent => :destroy |
46 | belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' | 46 | belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' |
47 | 47 | ||
48 | has_one :image, :as => :owner | 48 | has_one :image, :as => :owner |
@@ -113,13 +113,13 @@ class Profile < ActiveRecord::Base | @@ -113,13 +113,13 @@ class Profile < ActiveRecord::Base | ||
113 | self.user ? self.user.email : nil | 113 | self.user ? self.user.email : nil |
114 | end | 114 | end |
115 | 115 | ||
116 | - # gets recent documents in this profile. | 116 | + # gets recent documents in this profile, ordered from the most recent to the |
117 | + # oldest. | ||
117 | # | 118 | # |
118 | # +limit+ is the maximum number of documents to be returned. It defaults to | 119 | # +limit+ is the maximum number of documents to be returned. It defaults to |
119 | # 10. | 120 | # 10. |
120 | def recent_documents(limit = 10) | 121 | def recent_documents(limit = 10) |
121 | - # FIXME not like this anymore | ||
122 | - raise 'needs to be rewritten' | 122 | + self.articles.recent(self, limit) |
123 | end | 123 | end |
124 | 124 | ||
125 | def superior_instance | 125 | def superior_instance |
test/unit/profile_test.rb
@@ -94,8 +94,15 @@ class ProfileTest < Test::Unit::TestCase | @@ -94,8 +94,15 @@ class ProfileTest < Test::Unit::TestCase | ||
94 | assert ! Profile.search('not_wanted').include?(p) | 94 | assert ! Profile.search('not_wanted').include?(p) |
95 | end | 95 | end |
96 | 96 | ||
97 | - def test_should_remove_pages_when_removing_profile | ||
98 | - flunk 'pending' | 97 | + should 'remove pages when removing profile' do |
98 | + profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') | ||
99 | + first = profile.articles.build(:name => 'first'); first.save! | ||
100 | + second = profile.articles.build(:name => 'second'); second.save! | ||
101 | + third = profile.articles.build(:name => 'third'); third.save! | ||
102 | + | ||
103 | + n = Article.count | ||
104 | + profile.destroy | ||
105 | + assert_equal n - 3, Article.count | ||
99 | end | 106 | end |
100 | 107 | ||
101 | def test_should_define_info | 108 | def test_should_define_info |
@@ -112,12 +119,14 @@ class ProfileTest < Test::Unit::TestCase | @@ -112,12 +119,14 @@ class ProfileTest < Test::Unit::TestCase | ||
112 | assert_invalid_identifier 'test' | 119 | assert_invalid_identifier 'test' |
113 | end | 120 | end |
114 | 121 | ||
115 | - def test_should_provide_recent_documents | ||
116 | - flunk 'pending' | ||
117 | - end | 122 | + should 'provide recent documents' do |
123 | + profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') | ||
124 | + first = profile.articles.build(:name => 'first'); first.save! | ||
125 | + second = profile.articles.build(:name => 'second'); second.save! | ||
126 | + third = profile.articles.build(:name => 'third'); third.save! | ||
118 | 127 | ||
119 | - def test_should_provide_most_recent_documents | ||
120 | - flunk 'pending' | 128 | + assert_equal [first,second], profile.recent_documents(2) |
129 | + assert_equal [first,second,third], profile.recent_documents | ||
121 | end | 130 | end |
122 | 131 | ||
123 | should 'affiliate and provide a list of the affiliated users' do | 132 | should 'affiliate and provide a list of the affiliated users' do |
@@ -180,6 +189,19 @@ class ProfileTest < Test::Unit::TestCase | @@ -180,6 +189,19 @@ class ProfileTest < Test::Unit::TestCase | ||
180 | assert_not_same list, other_list | 189 | assert_not_same list, other_list |
181 | end | 190 | end |
182 | 191 | ||
192 | + should 'be able to find profiles by their names with ferret' do | ||
193 | + small = Profile.create!(:name => 'A small profile for testing ', :identifier => 'smallprofilefortesting') | ||
194 | + big = Profile.create!(:name => 'A big profile for testing', :identifier => 'bigprofilefortesting') | ||
195 | + | ||
196 | + assert Profile.find_by_contents('small').include?(small) | ||
197 | + assert Profile.find_by_contents('big').include?(big) | ||
198 | + | ||
199 | + both = Profile.find_by_contents('profile testing') | ||
200 | + assert both.include?(small) | ||
201 | + assert both.include?(big) | ||
202 | + end | ||
203 | + | ||
204 | + | ||
183 | private | 205 | private |
184 | 206 | ||
185 | def assert_invalid_identifier(id) | 207 | def assert_invalid_identifier(id) |