diff --git a/app/models/profile.rb b/app/models/profile.rb index 3c3085a..6ceabcd 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -298,7 +298,7 @@ class Profile < ActiveRecord::Base validate :valid_template def valid_template - if template_id.present? and !template.is_template + if template_id.present? && template && !template.is_template errors.add(:template, _('is not a template.')) end end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index c574fb8..310fdfb 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1379,6 +1379,16 @@ class ProfileTest < ActiveSupport::TestCase assert_not_includes Profile.templates(Environment.default), profile end + should 'not crash on a profile update with a destroyed template' do + template = fast_create(Profile, :is_template => true) + profile = fast_create(Profile, :template_id => template.id) + template.destroy + + assert_nothing_raised do + Profile.find(profile.id).save! + end + end + should 'provide URL to leave' do profile = build(Profile, :identifier => 'testprofile') assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave', :reload => false}, profile.leave_url) -- libgit2 0.21.2