diff --git a/app/models/environment.rb b/app/models/environment.rb index 2fa53a5..c65f32e 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -596,7 +596,7 @@ class Environment < ActiveRecord::Base end def portal_folders - (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(fid) } + (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(:first, :conditions => { :id => fid }) }.compact end def portal_folders=(folders) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index a19568d..df7e435 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -803,6 +803,20 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal [], e.portal_folders end + should 'not crash when a portal folder is removed' do + e = Environment.default + + c = e.portal_community = fast_create(Community) + news_folder = fast_create(Folder, :name => 'news folder', :profile_id => c.id) + + e.portal_folders = [news_folder] + e.save!; e.reload + + news_folder.destroy + + assert_not_includes e.portal_folders, nil + end + should 'have roles with names independent of other environments' do e1 = fast_create(Environment) role1 = Role.create!(:name => 'test_role', :environment => e1) -- libgit2 0.21.2