Commit 9e88d4990e8379244d8ad0f9fb65d75e98c65bad
1 parent
181e42bb
Exists in
master
and in
29 other branches
Fix crash in homepage with removed portal folder
(ActionItem1612)
Showing
2 changed files
with
15 additions
and
1 deletions
Show diff stats
app/models/environment.rb
... | ... | @@ -596,7 +596,7 @@ class Environment < ActiveRecord::Base |
596 | 596 | end |
597 | 597 | |
598 | 598 | def portal_folders |
599 | - (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(fid) } | |
599 | + (settings[:portal_folders] || []).map{|fid| portal_community.articles.find(:first, :conditions => { :id => fid }) }.compact | |
600 | 600 | end |
601 | 601 | |
602 | 602 | def portal_folders=(folders) | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -803,6 +803,20 @@ class EnvironmentTest < Test::Unit::TestCase |
803 | 803 | assert_equal [], e.portal_folders |
804 | 804 | end |
805 | 805 | |
806 | + should 'not crash when a portal folder is removed' do | |
807 | + e = Environment.default | |
808 | + | |
809 | + c = e.portal_community = fast_create(Community) | |
810 | + news_folder = fast_create(Folder, :name => 'news folder', :profile_id => c.id) | |
811 | + | |
812 | + e.portal_folders = [news_folder] | |
813 | + e.save!; e.reload | |
814 | + | |
815 | + news_folder.destroy | |
816 | + | |
817 | + assert_not_includes e.portal_folders, nil | |
818 | + end | |
819 | + | |
806 | 820 | should 'have roles with names independent of other environments' do |
807 | 821 | e1 = fast_create(Environment) |
808 | 822 | role1 = Role.create!(:name => 'test_role', :environment => e1) | ... | ... |