Commit 009e101d6698acc2a4feb573215b17deeb4f7857
Exists in
master
and in
29 other branches
Merge commit 'refs/merge-requests/349' of git://gitorious.org/noosfero/noosfero …
…into merge-requests/349
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,7 +298,7 @@ class Profile < ActiveRecord::Base | ||
| 298 | validate :valid_template | 298 | validate :valid_template |
| 299 | 299 | ||
| 300 | def valid_template | 300 | def valid_template |
| 301 | - if template_id.present? and !template.is_template | 301 | + if template_id.present? && template && !template.is_template |
| 302 | errors.add(:template, _('is not a template.')) | 302 | errors.add(:template, _('is not a template.')) |
| 303 | end | 303 | end |
| 304 | end | 304 | end |
test/unit/profile_test.rb
| @@ -1379,6 +1379,16 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1379,6 +1379,16 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 1379 | assert_not_includes Profile.templates(Environment.default), profile | 1379 | assert_not_includes Profile.templates(Environment.default), profile |
| 1380 | end | 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 | should 'provide URL to leave' do | 1392 | should 'provide URL to leave' do |
| 1383 | profile = build(Profile, :identifier => 'testprofile') | 1393 | profile = build(Profile, :identifier => 'testprofile') |
| 1384 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave', :reload => false}, profile.leave_url) | 1394 | assert_equal({ :profile => 'testprofile', :controller => 'profile', :action => 'leave', :reload => false}, profile.leave_url) |