Commit 34f625c4fa93f5fb1a97493f59b9fa6a715c67b5
1 parent
141fa98c
Exists in
master
and in
26 other branches
Add template reference when aplly template to profile
Showing
2 changed files
with
17 additions
and
10 deletions
Show diff stats
app/models/profile.rb
@@ -404,6 +404,7 @@ class Profile < ActiveRecord::Base | @@ -404,6 +404,7 @@ class Profile < ActiveRecord::Base | ||
404 | alias_method_chain :template, :default | 404 | alias_method_chain :template, :default |
405 | 405 | ||
406 | def apply_template(template, options = {:copy_articles => true}) | 406 | def apply_template(template, options = {:copy_articles => true}) |
407 | + self.template = template | ||
407 | copy_blocks_from(template) | 408 | copy_blocks_from(template) |
408 | copy_articles_from(template) if options[:copy_articles] | 409 | copy_articles_from(template) if options[:copy_articles] |
409 | self.apply_type_specific_template(template) | 410 | self.apply_type_specific_template(template) |
test/unit/profile_test.rb
@@ -901,6 +901,8 @@ class ProfileTest < ActiveSupport::TestCase | @@ -901,6 +901,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
901 | 901 | ||
902 | should 'copy set of articles from a template' do | 902 | should 'copy set of articles from a template' do |
903 | template = create_user('test_template').person | 903 | template = create_user('test_template').person |
904 | + template.is_template = true | ||
905 | + template.save | ||
904 | template.articles.destroy_all | 906 | template.articles.destroy_all |
905 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | 907 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
906 | a2 = fast_create(Article, :profile_id => template.id, :name => 'some child article', :parent_id => a1.id) | 908 | a2 = fast_create(Article, :profile_id => template.id, :name => 'some child article', :parent_id => a1.id) |
@@ -934,6 +936,8 @@ class ProfileTest < ActiveSupport::TestCase | @@ -934,6 +936,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
934 | 936 | ||
935 | should 'copy homepage from template' do | 937 | should 'copy homepage from template' do |
936 | template = create_user('test_template').person | 938 | template = create_user('test_template').person |
939 | + template.is_template = true | ||
940 | + template.save | ||
937 | template.articles.destroy_all | 941 | template.articles.destroy_all |
938 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | 942 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
939 | template.home_page = a1 | 943 | template.home_page = a1 |
@@ -949,6 +953,8 @@ class ProfileTest < ActiveSupport::TestCase | @@ -949,6 +953,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
949 | 953 | ||
950 | should 'not advertise the articles copied from templates' do | 954 | should 'not advertise the articles copied from templates' do |
951 | template = create_user('test_template').person | 955 | template = create_user('test_template').person |
956 | + template.is_template = true | ||
957 | + template.save | ||
952 | template.articles.destroy_all | 958 | template.articles.destroy_all |
953 | a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | 959 | a = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
954 | 960 | ||
@@ -962,7 +968,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -962,7 +968,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
962 | end | 968 | end |
963 | 969 | ||
964 | should 'copy set of boxes from profile template' do | 970 | should 'copy set of boxes from profile template' do |
965 | - template = fast_create(Profile) | 971 | + template = fast_create(Profile, :is_template => true) |
966 | template.boxes.destroy_all | 972 | template.boxes.destroy_all |
967 | template.boxes << Box.new | 973 | template.boxes << Box.new |
968 | template.boxes[0].blocks << Block.new | 974 | template.boxes[0].blocks << Block.new |
@@ -977,7 +983,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -977,7 +983,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
977 | end | 983 | end |
978 | 984 | ||
979 | should 'copy layout template when applying template' do | 985 | should 'copy layout template when applying template' do |
980 | - template = fast_create(Profile) | 986 | + template = fast_create(Profile, :is_template => true) |
981 | template.layout_template = 'leftbar' | 987 | template.layout_template = 'leftbar' |
982 | template.save! | 988 | template.save! |
983 | 989 | ||
@@ -989,7 +995,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -989,7 +995,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
989 | end | 995 | end |
990 | 996 | ||
991 | should 'copy blocks when applying template' do | 997 | should 'copy blocks when applying template' do |
992 | - template = fast_create(Profile) | 998 | + template = fast_create(Profile, :is_template => true) |
993 | template.boxes.destroy_all | 999 | template.boxes.destroy_all |
994 | template.boxes << Box.new | 1000 | template.boxes << Box.new |
995 | template.boxes[0].blocks << Block.new | 1001 | template.boxes[0].blocks << Block.new |
@@ -1004,7 +1010,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1004,7 +1010,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1004 | end | 1010 | end |
1005 | 1011 | ||
1006 | should 'copy articles when applying template' do | 1012 | should 'copy articles when applying template' do |
1007 | - template = fast_create(Profile) | 1013 | + template = fast_create(Profile, :is_template => true) |
1008 | template.articles.create(:name => 'template article') | 1014 | template.articles.create(:name => 'template article') |
1009 | template.save! | 1015 | template.save! |
1010 | 1016 | ||
@@ -1016,7 +1022,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1016,7 +1022,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1016 | end | 1022 | end |
1017 | 1023 | ||
1018 | should 'rename existing articles when applying template' do | 1024 | should 'rename existing articles when applying template' do |
1019 | - template = fast_create(Profile) | 1025 | + template = fast_create(Profile, :is_template => true) |
1020 | template.boxes.destroy_all | 1026 | template.boxes.destroy_all |
1021 | template.boxes << Box.new | 1027 | template.boxes << Box.new |
1022 | template.boxes[0].blocks << Block.new | 1028 | template.boxes[0].blocks << Block.new |
@@ -1033,7 +1039,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1033,7 +1039,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1033 | end | 1039 | end |
1034 | 1040 | ||
1035 | should 'copy header when applying template' do | 1041 | should 'copy header when applying template' do |
1036 | - template = fast_create(Profile) | 1042 | + template = fast_create(Profile, :is_template => true) |
1037 | template[:custom_header] = '{name}' | 1043 | template[:custom_header] = '{name}' |
1038 | template.save! | 1044 | template.save! |
1039 | 1045 | ||
@@ -1047,7 +1053,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1047,7 +1053,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1047 | end | 1053 | end |
1048 | 1054 | ||
1049 | should 'copy footer when applying template' do | 1055 | should 'copy footer when applying template' do |
1050 | - template = create(Profile, :address => 'Template address', :custom_footer => '{address}') | 1056 | + template = create(Profile, :address => 'Template address', :custom_footer => '{address}', :is_template => true) |
1051 | 1057 | ||
1052 | p = create(Profile, :address => 'Profile address') | 1058 | p = create(Profile, :address => 'Profile address') |
1053 | p.apply_template(template) | 1059 | p.apply_template(template) |
@@ -1058,7 +1064,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1058,7 +1064,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1058 | end | 1064 | end |
1059 | 1065 | ||
1060 | should 'ignore failing validation when applying template' do | 1066 | should 'ignore failing validation when applying template' do |
1061 | - template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header') | 1067 | + template = create(Profile, :layout_template => 'leftbar', :custom_footer => 'my custom footer', :custom_header => 'my custom header', :is_template => true) |
1062 | 1068 | ||
1063 | p = create(Profile) | 1069 | p = create(Profile) |
1064 | def p.validate | 1070 | def p.validate |
@@ -1074,7 +1080,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1074,7 +1080,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1074 | end | 1080 | end |
1075 | 1081 | ||
1076 | should 'copy homepage when applying template' do | 1082 | should 'copy homepage when applying template' do |
1077 | - template = fast_create(Profile) | 1083 | + template = fast_create(Profile, :is_template => true) |
1078 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') | 1084 | a1 = fast_create(Article, :profile_id => template.id, :name => 'some xyz article') |
1079 | template.home_page = a1 | 1085 | template.home_page = a1 |
1080 | template.save! | 1086 | template.save! |
@@ -1161,7 +1167,7 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1161,7 +1167,7 @@ class ProfileTest < ActiveSupport::TestCase | ||
1161 | end | 1167 | end |
1162 | 1168 | ||
1163 | should 'copy public/private setting from template' do | 1169 | should 'copy public/private setting from template' do |
1164 | - template = fast_create(Profile, :public_profile => false) | 1170 | + template = fast_create(Profile, :public_profile => false, :is_template => true) |
1165 | p = fast_create(Profile) | 1171 | p = fast_create(Profile) |
1166 | p.apply_template(template) | 1172 | p.apply_template(template) |
1167 | assert_equal false, p.public_profile | 1173 | assert_equal false, p.public_profile |