Commit 427a2565737f761bff15e6cafdb963a9839b9402
1 parent
e449f210
Exists in
master
and in
28 other branches
Fix: Allowing profile update even if template was removed
(ActionItem2744)
Showing
2 changed files
with
11 additions
and
1 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -298,7 +298,7 @@ class Profile < ActiveRecord::Base |
298 | 298 | validate :valid_template |
299 | 299 | |
300 | 300 | def valid_template |
301 | - if template_id.present? and !template.is_template | |
301 | + if template_id.present? && template && !template.is_template | |
302 | 302 | errors.add(:template, _('is not a template.')) |
303 | 303 | end |
304 | 304 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -1379,6 +1379,16 @@ class ProfileTest < ActiveSupport::TestCase |
1379 | 1379 | assert_not_includes Profile.templates(Environment.default), profile |
1380 | 1380 | end |
1381 | 1381 | |
1382 | + should 'not crash on a profile update with a destroyed template' do | |
1383 | + template = fast_create(Profile, :is_template => true) | |
1384 | + profile = fast_create(Profile, :template_id => template.id) | |
1385 | + template.destroy | |
1386 | + | |
1387 | + assert_nothing_raised do | |
1388 | + Profile.find(profile.id).save! | |
1389 | + end | |
1390 | + end | |
1391 | + | |
1382 | 1392 | should 'provide URL to leave' do |
1383 | 1393 | profile = build(Profile, :identifier => 'testprofile') |
1384 | 1394 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave', :reload => false}, profile.leave_url) | ... | ... |