diff --git a/app/models/profile.rb b/app/models/profile.rb index 390de94..1586920 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -15,7 +15,7 @@ class Profile < ActiveRecord::Base acts_as_design -# acts_as_ferret :fields => [ :name ] + acts_as_ferret :fields => [ :name ] # Valid identifiers must match this format. IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ @@ -42,7 +42,7 @@ class Profile < ActiveRecord::Base has_many :role_assignments, :as => :resource - has_many :articles + has_many :articles, :dependent => :destroy belongs_to :home_page, :class_name => Article.name, :foreign_key => 'home_page_id' has_one :image, :as => :owner @@ -113,13 +113,13 @@ class Profile < ActiveRecord::Base self.user ? self.user.email : nil end - # gets recent documents in this profile. + # gets recent documents in this profile, ordered from the most recent to the + # oldest. # # +limit+ is the maximum number of documents to be returned. It defaults to # 10. def recent_documents(limit = 10) - # FIXME not like this anymore - raise 'needs to be rewritten' + self.articles.recent(self, limit) end def superior_instance diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 0606e1f..16b5502 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -94,8 +94,15 @@ class ProfileTest < Test::Unit::TestCase assert ! Profile.search('not_wanted').include?(p) end - def test_should_remove_pages_when_removing_profile - flunk 'pending' + should 'remove pages when removing profile' do + profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') + first = profile.articles.build(:name => 'first'); first.save! + second = profile.articles.build(:name => 'second'); second.save! + third = profile.articles.build(:name => 'third'); third.save! + + n = Article.count + profile.destroy + assert_equal n - 3, Article.count end def test_should_define_info @@ -112,12 +119,14 @@ class ProfileTest < Test::Unit::TestCase assert_invalid_identifier 'test' end - def test_should_provide_recent_documents - flunk 'pending' - end + should 'provide recent documents' do + profile = Profile.create!(:name => 'testing profile', :identifier => 'testingprofile') + first = profile.articles.build(:name => 'first'); first.save! + second = profile.articles.build(:name => 'second'); second.save! + third = profile.articles.build(:name => 'third'); third.save! - def test_should_provide_most_recent_documents - flunk 'pending' + assert_equal [first,second], profile.recent_documents(2) + assert_equal [first,second,third], profile.recent_documents end should 'affiliate and provide a list of the affiliated users' do @@ -180,6 +189,19 @@ class ProfileTest < Test::Unit::TestCase assert_not_same list, other_list end + should 'be able to find profiles by their names with ferret' do + small = Profile.create!(:name => 'A small profile for testing ', :identifier => 'smallprofilefortesting') + big = Profile.create!(:name => 'A big profile for testing', :identifier => 'bigprofilefortesting') + + assert Profile.find_by_contents('small').include?(small) + assert Profile.find_by_contents('big').include?(big) + + both = Profile.find_by_contents('profile testing') + assert both.include?(small) + assert both.include?(big) + end + + private def assert_invalid_identifier(id) -- libgit2 0.21.2