diff --git a/app/models/profile.rb b/app/models/profile.rb index 6977f46..66d901a 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -11,6 +11,11 @@ class Profile < ActiveRecord::Base homepage.save! end + after_destroy do |profile| + Comatose::Page.find_by_path(profile.identifier).destroy + end + + # Valid identifiers must match this format. IDENTIFIER_FORMAT = /^[a-z][a-z0-9_]*[a-z0-9]$/ diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index dbb8983..301d3d9 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -85,4 +85,12 @@ class ProfileTest < Test::Unit::TestCase assert Profile.search('bla').include?(p) assert ! Profile.search('not_wanted').include?(p) end + + def test_should_remove_pages_when_removing_profile + profile = Profile.create(:name => 'To bee removed', :identifier => 'to_be_removed') + assert Comatose::Page.find_by_path('to_be_removed') + profile.destroy + assert !Comatose::Page.find_by_path('to_be_removed') + end + end -- libgit2 0.21.2