[Git][noosfero/noosfero][master] 2 commits: Adds a validation when applying profile templates
Rodrigo Souto
gitlab at mg.gitlab.com
Mon Jun 26 10:12:26 BRT 2017
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
f8318b7f by Gabriel Silva at 2017-06-21T15:12:15+00:00
Adds a validation when applying profile templates
Signed-off-by: Gabriel Silva <gabriel93.silva at gmail.com>
- - - - -
c5d818e7 by Rodrigo Souto at 2017-06-26T13:11:46+00:00
Merge branch 'template_validation' into 'master'
Adds a validation when applying profile templates
Closes #191
See merge request !1253
- - - - -
2 changed files:
- app/models/profile.rb
- test/unit/profile_test.rb
Changes:
=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -557,6 +557,8 @@ class Profile < ApplicationRecord
alias_method_chain :template, :default
def apply_template(template, options = {:copy_articles => true})
+ raise "#{template.identifier} is not a template" if !template.is_template
+
self.template = template
copy_blocks_from(template)
copy_articles_from(template) if options[:copy_articles]
=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1235,6 +1235,18 @@ class ProfileTest < ActiveSupport::TestCase
assert_equal false, p.public_profile
end
+ should 'not apply a template that is not a template' do
+ not_a_template = fast_create(Profile, :is_template => false)
+ not_a_template.layout_template = 'leftbar'
+ not_a_template.save!
+
+ p = fast_create(Profile)
+ assert_raise RuntimeError do
+ p.apply_template(not_a_template)
+ end
+ assert_equal 'default', p.layout_template
+ end
+
should 'destroy tasks requested to it when destroyed' do
p = Profile.create!(:name => 'test_profile', :identifier => 'test_profile')
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/dc57ad0888bf9ecd14b8daf266a34164ced3198c...c5d818e7f42922cb0582976983ce747a9c84e9ba
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/dc57ad0888bf9ecd14b8daf266a34164ced3198c...c5d818e7f42922cb0582976983ce747a9c84e9ba
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170626/e8c39e39/attachment-0001.html>
More information about the Noosfero-dev
mailing list