Commit dc4ccf34aba0f09727009b2cc983dc3a4b039c69
1 parent
28a544fd
Exists in
master
and in
22 other branches
Cleanup after destroying environment and people
Showing
6 changed files
with
40 additions
and
7 deletions
Show diff stats
app/models/environment.rb
@@ -696,4 +696,11 @@ class Environment < ActiveRecord::Base | @@ -696,4 +696,11 @@ class Environment < ActiveRecord::Base | ||
696 | self.save! | 696 | self.save! |
697 | end | 697 | end |
698 | 698 | ||
699 | + after_destroy :destroy_templates | ||
700 | + def destroy_templates | ||
701 | + [enterprise_template, community_template, person_template].compact.each do |template| | ||
702 | + template.destroy | ||
703 | + end | ||
704 | + end | ||
705 | + | ||
699 | end | 706 | end |
app/models/person.rb
@@ -12,6 +12,11 @@ class Person < Profile | @@ -12,6 +12,11 @@ class Person < Profile | ||
12 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } | 12 | Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } |
13 | end | 13 | end |
14 | 14 | ||
15 | + after_destroy :destroy_user | ||
16 | + def destroy_user | ||
17 | + self.user.destroy if self.user | ||
18 | + end | ||
19 | + | ||
15 | # Sets the identifier for this person. Raises an exception when called on a | 20 | # Sets the identifier for this person. Raises an exception when called on a |
16 | # existing person (since peoples' identifiers cannot be changed) | 21 | # existing person (since peoples' identifiers cannot be changed) |
17 | def identifier=(value) | 22 | def identifier=(value) |
app/sweepers/article_sweeper.rb
@@ -18,10 +18,12 @@ protected | @@ -18,10 +18,12 @@ protected | ||
18 | a.touch | 18 | a.touch |
19 | end | 19 | end |
20 | end | 20 | end |
21 | - blocks = (article.profile.blocks + article.profile.environment.blocks).select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} | 21 | + blocks = article.profile.blocks |
22 | + blocks += article.profile.environment.blocks if article.profile.environment | ||
23 | + blocks = blocks.select{|b|[RecentDocumentsBlock, BlogArchivesBlock].any?{|c| b.kind_of?(c)}} | ||
22 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} | 24 | blocks.map(&:cache_keys).each{|ck|expire_timeout_fragment(ck)} |
23 | env = article.profile.environment | 25 | env = article.profile.environment |
24 | - if env.portal_community == article.profile | 26 | + if env && (env.portal_community == article.profile) |
25 | expire_fragment(env.portal_news_cache_key) | 27 | expire_fragment(env.portal_news_cache_key) |
26 | end | 28 | end |
27 | end | 29 | end |
test/unit/create_enterprise_test.rb
@@ -93,8 +93,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -93,8 +93,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
93 | 93 | ||
94 | should 'actually create an enterprise when finishing the task and associate the task requestor as its owner through the "user" association' do | 94 | should 'actually create an enterprise when finishing the task and associate the task requestor as its owner through the "user" association' do |
95 | 95 | ||
96 | - Environment.destroy_all | ||
97 | - environment = Environment.create!(:name => "My environment", :contact_email => 'test@localhost.localdomain', :is_default => true) | 96 | + environment = Environment.create!(:name => "My environment", :contact_email => 'test@localhost.localdomain') |
98 | region = Region.create!(:name => 'My region', :environment_id => environment.id) | 97 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
99 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | 98 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
100 | region.validators << validator | 99 | region.validators << validator |
@@ -170,8 +169,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -170,8 +169,7 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
170 | end | 169 | end |
171 | 170 | ||
172 | should 'validate that eveything is ok but the validator (target)' do | 171 | should 'validate that eveything is ok but the validator (target)' do |
173 | - Environment.destroy_all | ||
174 | - environment = Environment.create!(:name => "My environment", :contact_email => 'test@localhost.localdomain', :is_default => true) | 172 | + environment = Environment.create!(:name => "My environment", :contact_email => 'test@localhost.localdomain') |
175 | region = Region.create!(:name => 'My region', :environment_id => environment.id) | 173 | region = Region.create!(:name => 'My region', :environment_id => environment.id) |
176 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) | 174 | validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) |
177 | region.validators << validator | 175 | region.validators << validator |
test/unit/environment_test.rb
@@ -272,7 +272,21 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -272,7 +272,21 @@ class EnvironmentTest < Test::Unit::TestCase | ||
272 | assert_equal boxes - env_boxes, Box.count | 272 | assert_equal boxes - env_boxes, Box.count |
273 | assert_equal blocks - env_blocks, Block.count | 273 | assert_equal blocks - env_blocks, Block.count |
274 | end | 274 | end |
275 | - | 275 | + |
276 | + should 'destroy templates' do | ||
277 | + env = fast_create(Environment) | ||
278 | + templates = [mock, mock, mock] | ||
279 | + templates.each do |item| | ||
280 | + item.expects(:destroy) | ||
281 | + end | ||
282 | + | ||
283 | + env.stubs(:person_template).returns(templates[0]) | ||
284 | + env.stubs(:community_template).returns(templates[1]) | ||
285 | + env.stubs(:enterprise_template).returns(templates[2]) | ||
286 | + | ||
287 | + env.destroy | ||
288 | + end | ||
289 | + | ||
276 | should 'have boxes and blocks upon creation' do | 290 | should 'have boxes and blocks upon creation' do |
277 | Environment.any_instance.stubs(:create_templates) # avoid creating templates, it's expensive | 291 | Environment.any_instance.stubs(:create_templates) # avoid creating templates, it's expensive |
278 | environment = Environment.create!(:name => 'a test environment') | 292 | environment = Environment.create!(:name => 'a test environment') |
test/unit/person_test.rb
@@ -263,6 +263,13 @@ class PersonTest < Test::Unit::TestCase | @@ -263,6 +263,13 @@ class PersonTest < Test::Unit::TestCase | ||
263 | assert_not_includes p2.friends(true), p1 | 263 | assert_not_includes p2.friends(true), p1 |
264 | end | 264 | end |
265 | 265 | ||
266 | + should 'destroy use when person is destroyed' do | ||
267 | + person = create_user('testuser').person | ||
268 | + assert_difference User, :count, -1 do | ||
269 | + person.destroy | ||
270 | + end | ||
271 | + end | ||
272 | + | ||
266 | should 'return info name instead of name when info is setted' do | 273 | should 'return info name instead of name when info is setted' do |
267 | p = create_user('ze_maria').person | 274 | p = create_user('ze_maria').person |
268 | assert_equal 'ze_maria', p.name | 275 | assert_equal 'ze_maria', p.name |