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