Commit a7f0469c7337982e342f96a521ae60ba23d7319a
Exists in
master
and in
27 other branches
Merge branch 'AI3268_template_management' into 'master'
Improve templates management Actually the templates management is very strange. You don't have how to define a template as default and when you create a community the first template is alwyas de default one. More details in http://noosfero.org/Development/ActionItem3268 See merge request !298
Showing
12 changed files
with
533 additions
and
44 deletions
Show diff stats
app/controllers/admin/templates_controller.rb
... | ... | @@ -40,8 +40,67 @@ class TemplatesController < AdminController |
40 | 40 | end |
41 | 41 | end |
42 | 42 | |
43 | + def set_community_as_default | |
44 | + begin | |
45 | + community = environment.communities.find(params[:template_id]) | |
46 | + rescue ActiveRecord::RecordNotFound | |
47 | + message = _('Community not found. The template could no be changed.') | |
48 | + community = nil | |
49 | + end | |
50 | + | |
51 | + message = _('%s defined as default') % community.name if set_as_default(community) | |
52 | + session[:notice] = message | |
53 | + | |
54 | + redirect_to :action => 'index' | |
55 | + end | |
56 | + | |
57 | + def set_person_as_default | |
58 | + begin | |
59 | + person = environment.people.find(params[:template_id]) | |
60 | + rescue ActiveRecord::RecordNotFound | |
61 | + message = _('Person not found. The template could no be changed.') | |
62 | + person = nil | |
63 | + end | |
64 | + | |
65 | + message = _('%s defined as default') % person.name if set_as_default(person) | |
66 | + session[:notice] = message | |
67 | + | |
68 | + redirect_to :action => 'index' | |
69 | + end | |
70 | + | |
71 | + def set_enterprise_as_default | |
72 | + begin | |
73 | + enterprise = environment.enterprises.find(params[:template_id]) | |
74 | + rescue ActiveRecord::RecordNotFound | |
75 | + message = _('Enterprise not found. The template could no be changed.') | |
76 | + enterprise = nil | |
77 | + end | |
78 | + | |
79 | + message = _('%s defined as default') % enterprise.name if set_as_default(enterprise) | |
80 | + session[:notice] = message | |
81 | + | |
82 | + redirect_to :action => 'index' | |
83 | + end | |
84 | + | |
43 | 85 | private |
44 | 86 | |
87 | + def set_as_default(obj) | |
88 | + return nil if obj.nil? | |
89 | + case obj.class.name | |
90 | + when 'Community' then | |
91 | + environment.community_default_template = obj | |
92 | + environment.save! | |
93 | + when 'Person' then | |
94 | + environment.person_default_template = obj | |
95 | + environment.save! | |
96 | + when 'Enterprise' then | |
97 | + environment.enterprise_default_template = obj | |
98 | + environment.save! | |
99 | + else | |
100 | + nil | |
101 | + end | |
102 | + end | |
103 | + | |
45 | 104 | def create_organization_template(klass) |
46 | 105 | identifier = params[:name].to_slug |
47 | 106 | template = klass.new(:name => params[:name], :identifier => identifier, :is_template => true) | ... | ... |
app/helpers/application_helper.rb
... | ... | @@ -1315,10 +1315,8 @@ module ApplicationHelper |
1315 | 1315 | return '' if templates.count == 0 |
1316 | 1316 | return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 |
1317 | 1317 | |
1318 | - counter = 0 | |
1319 | 1318 | radios = templates.map do |template| |
1320 | - counter += 1 | |
1321 | - content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, counter==1)) | |
1319 | + content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, environment.is_default_template?(template))) | |
1322 | 1320 | end.join("\n") |
1323 | 1321 | |
1324 | 1322 | content_tag('div', content_tag('label', _('Profile organization'), :for => 'template-options', :class => 'formlabel') + | ... | ... |
app/models/community.rb
app/models/enterprise.rb
app/models/environment.rb
... | ... | @@ -729,31 +729,50 @@ class Environment < ActiveRecord::Base |
729 | 729 | ] |
730 | 730 | end |
731 | 731 | |
732 | - def community_template | |
732 | + def is_default_template?(template) | |
733 | + is_default = template == community_default_template | |
734 | + is_default = is_default || template == person_default_template | |
735 | + is_default = is_default || template == enterprise_default_template | |
736 | + is_default | |
737 | + end | |
738 | + | |
739 | + def community_templates | |
740 | + self.communities.templates | |
741 | + end | |
742 | + | |
743 | + def community_default_template | |
733 | 744 | template = Community.find_by_id settings[:community_template_id] |
734 | - template if template && template.is_template | |
745 | + template if template && template.is_template? | |
735 | 746 | end |
736 | 747 | |
737 | - def community_template=(value) | |
738 | - settings[:community_template_id] = value.id | |
748 | + def community_default_template=(value) | |
749 | + settings[:community_template_id] = value.kind_of?(Community) ? value.id : value | |
739 | 750 | end |
740 | 751 | |
741 | - def person_template | |
752 | + def person_templates | |
753 | + self.people.templates | |
754 | + end | |
755 | + | |
756 | + def person_default_template | |
742 | 757 | template = Person.find_by_id settings[:person_template_id] |
743 | - template if template && template.is_template | |
758 | + template if template && template.is_template? | |
744 | 759 | end |
745 | 760 | |
746 | - def person_template=(value) | |
747 | - settings[:person_template_id] = value.id | |
761 | + def person_default_template=(value) | |
762 | + settings[:person_template_id] = value.kind_of?(Person) ? value.id : value | |
748 | 763 | end |
749 | 764 | |
750 | - def enterprise_template | |
765 | + def enterprise_templates | |
766 | + self.enterprises.templates | |
767 | + end | |
768 | + | |
769 | + def enterprise_default_template | |
751 | 770 | template = Enterprise.find_by_id settings[:enterprise_template_id] |
752 | - template if template && template.is_template | |
771 | + template if template && template.is_template? | |
753 | 772 | end |
754 | 773 | |
755 | - def enterprise_template=(value) | |
756 | - settings[:enterprise_template_id] = value.id | |
774 | + def enterprise_default_template=(value) | |
775 | + settings[:enterprise_template_id] = value.kind_of?(Enterprise) ? value.id : value | |
757 | 776 | end |
758 | 777 | |
759 | 778 | def inactive_enterprise_template |
... | ... | @@ -851,10 +870,10 @@ class Environment < ActiveRecord::Base |
851 | 870 | person_template.visible = false |
852 | 871 | person_template.save! |
853 | 872 | |
854 | - self.enterprise_template = enterprise_template | |
873 | + self.enterprise_default_template = enterprise_template | |
855 | 874 | self.inactive_enterprise_template = inactive_enterprise_template |
856 | - self.community_template = community_template | |
857 | - self.person_template = person_template | |
875 | + self.community_default_template = community_template | |
876 | + self.person_default_template = person_template | |
858 | 877 | self.save! |
859 | 878 | end |
860 | 879 | ... | ... |
app/models/person.rb
app/views/templates/index.html.erb
... | ... | @@ -2,10 +2,11 @@ |
2 | 2 | |
3 | 3 | <%= _('Manage the templates used on creation of profiles') %> |
4 | 4 | |
5 | -<% list_of_templates = [[_('Person') , environment.people.templates , 'person' ], | |
5 | +<% list_of_templates = [[_('Person') , environment.person_templates , 'person' ], | |
6 | 6 | [_('Community') , environment.communities.templates, 'community' ], |
7 | 7 | [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %> |
8 | 8 | |
9 | + | |
9 | 10 | <% list_of_templates.each do |title, templates, kind|%> |
10 | 11 | <div class='template-kind'> |
11 | 12 | <h2><%= title %></h2> |
... | ... | @@ -15,6 +16,11 @@ |
15 | 16 | <li> |
16 | 17 | <%= image_tag "icons-app/#{kind}-icon.png" %> |
17 | 18 | <%= link_to(template.name, {:controller => 'profile_editor', :profile => template.identifier}, :title => _('Edit template "%s"') % template.name ) %> |
19 | + <% if environment.is_default_template?(template) %> | |
20 | + <%= _('is the default template') %> | |
21 | + <% else %> | |
22 | + <%= link_to(_('Set as default'), {:action => "set_#{kind}_as_default", :template_id => template.id}, :title => _('Set %s template as default') % template.name ) %> | |
23 | + <% end %> | |
18 | 24 | </li> |
19 | 25 | <% end %> |
20 | 26 | </ul> | ... | ... |
test/functional/templates_controller_test.rb
... | ... | @@ -6,14 +6,17 @@ class TemplatesController; def rescue_action(e) raise e end; end |
6 | 6 | |
7 | 7 | class TemplatesControllerTest < ActionController::TestCase |
8 | 8 | |
9 | - all_fixtures | |
10 | 9 | def setup |
11 | 10 | @controller = TemplatesController.new |
12 | 11 | @request = ActionController::TestRequest.new |
13 | 12 | @response = ActionController::TestResponse.new |
14 | - login_as(create_admin_user(Environment.default)) | |
13 | + Environment.destroy_all | |
14 | + @environment = fast_create(Environment, :is_default => true) | |
15 | + login_as(create_admin_user(@environment)) | |
15 | 16 | end |
16 | 17 | |
18 | + attr_accessor :environment | |
19 | + | |
17 | 20 | should 'create person template' do |
18 | 21 | post :create_person_template, :name => 'Developer' |
19 | 22 | assert Person['developer'].is_template |
... | ... | @@ -28,5 +31,168 @@ class TemplatesControllerTest < ActionController::TestCase |
28 | 31 | post :create_enterprise_template, :name => 'Free Software Foundation' |
29 | 32 | assert Enterprise['free-software-foundation'].is_template |
30 | 33 | end |
34 | + | |
35 | + should 'set a community as default template' do | |
36 | + | |
37 | + c1= fast_create(Community, :is_template => true, :environment_id => environment.id) | |
38 | + environment.community_default_template= c1 | |
39 | + environment.save | |
40 | + | |
41 | + c3 = fast_create(Community, :is_template => true, :environment_id => environment.id) | |
42 | + | |
43 | + post :set_community_as_default, :template_id => c3.id | |
44 | + environment.reload | |
45 | + assert_equal c3, environment.community_default_template | |
46 | + end | |
47 | + | |
48 | + should 'set a person as default template' do | |
49 | + | |
50 | + p1= fast_create(Person, :is_template => true, :environment_id => environment.id) | |
51 | + environment.person_default_template= p1 | |
52 | + environment.save | |
53 | + | |
54 | + p3 = fast_create(Person, :is_template => true, :environment_id => environment.id) | |
55 | + | |
56 | + post :set_person_as_default, :template_id => p3.id | |
57 | + environment.reload | |
58 | + assert_equal p3, environment.person_default_template | |
59 | + end | |
60 | + | |
61 | + should 'set a enterprise as default template' do | |
62 | + | |
63 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
64 | + environment.enterprise_default_template= e1 | |
65 | + environment.save | |
66 | + | |
67 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
68 | + | |
69 | + post :set_enterprise_as_default, :template_id => e3.id | |
70 | + environment.reload | |
71 | + assert_equal e3, environment.enterprise_default_template | |
72 | + end | |
73 | + | |
74 | + should 'not allow set_community_as_default define a community template of another environment as default' do | |
75 | + c1= fast_create(Community, :is_template => true, :environment_id => environment.id) | |
76 | + environment.community_default_template= c1 | |
77 | + environment.save | |
78 | + | |
79 | + env2 = fast_create(Environment) | |
80 | + | |
81 | + c3 = fast_create(Community, :is_template => true, :environment_id => env2.id) | |
82 | + | |
83 | + post :set_community_as_default, :template_id => c3.id | |
84 | + environment.reload | |
85 | + assert_not_equal c3, environment.community_default_template | |
86 | + end | |
87 | + | |
88 | + should 'not allow set_person_as_default define a person template of another environment as default' do | |
89 | + p1= fast_create(Person, :is_template => true, :environment_id => environment.id) | |
90 | + environment.person_default_template= p1 | |
91 | + environment.save | |
92 | + | |
93 | + env2 = fast_create(Environment) | |
94 | + p3 = fast_create(Person, :is_template => true, :environment_id => env2.id) | |
95 | + | |
96 | + post :set_person_as_default, :template_id => p3.id | |
97 | + environment.reload | |
98 | + assert_not_equal p3, environment.person_default_template | |
99 | + | |
100 | + end | |
101 | + | |
102 | + should 'not allow set_enterprise_as_default define a enterprise of another environment as default' do | |
103 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
104 | + environment.enterprise_default_template= e1 | |
105 | + environment.save | |
106 | + | |
107 | + env2 = fast_create(Environment) | |
108 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env2.id) | |
109 | + | |
110 | + post :set_enterprise_as_default, :template_id => e3.id | |
111 | + environment.reload | |
112 | + assert_not_equal e3, environment.enterprise_default_template | |
113 | + end | |
114 | + | |
115 | + should 'display successfully notice message after define a community template as default' do | |
116 | + c3 = fast_create(Community, :is_template => true, :environment_id => environment) | |
117 | + | |
118 | + post :set_community_as_default, :template_id => c3.id | |
119 | + assert_equal "#{c3.name} defined as default", session[:notice] | |
120 | + end | |
121 | + | |
122 | + should 'display successfully notice message after define a person template as default' do | |
123 | + p3 = fast_create(Person, :is_template => true, :environment_id => environment) | |
124 | + | |
125 | + post :set_person_as_default, :template_id => p3.id | |
126 | + assert_equal "#{p3.name} defined as default", session[:notice] | |
127 | + end | |
128 | + | |
129 | + should 'display successfully notice message after define a enterprise template as default' do | |
130 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => environment) | |
131 | + | |
132 | + post :set_enterprise_as_default, :template_id => e3.id | |
133 | + assert_equal "#{e3.name} defined as default", session[:notice] | |
134 | + end | |
135 | + | |
136 | + should 'display unsuccessfully notice message when a community template could not be defined as default' do | |
137 | + env2 = fast_create(Environment) | |
138 | + c3 = fast_create(Community, :is_template => true, :environment_id => env2.id) | |
139 | + | |
140 | + post :set_community_as_default, :template_id => c3.id | |
141 | + assert_equal "Community not found. The template could no be changed.", session[:notice] | |
142 | + end | |
143 | + | |
144 | + should 'display unsuccessfully notice message when a person template could not be defined as default' do | |
145 | + env2 = fast_create(Environment) | |
146 | + p3 = fast_create(Person, :is_template => true, :environment_id => env2.id) | |
147 | + | |
148 | + post :set_person_as_default, :template_id => p3.id | |
149 | + assert_equal "Person not found. The template could no be changed.", session[:notice] | |
150 | + end | |
151 | + | |
152 | + should 'display unsuccessfully notice message when a enterprise template could not be defined as default' do | |
153 | + env2 = fast_create(Environment) | |
154 | + e3 = fast_create(Community, :is_template => true, :environment_id => env2.id) | |
155 | + | |
156 | + post :set_enterprise_as_default, :template_id => e3.id | |
157 | + assert_equal "Enterprise not found. The template could no be changed.", session[:notice] | |
158 | + end | |
159 | + | |
160 | + should 'display set as default link for non default community templates' do | |
161 | + c1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | |
162 | + c2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | |
163 | + | |
164 | + get :index | |
165 | + assert_tag :a, '', :attributes => {:href => "/admin/templates/set_community_as_default?template_id=#{c1.id}"} | |
166 | + assert_tag :a, '', :attributes => {:href => "/admin/templates/set_community_as_default?template_id=#{c2.id}"} | |
167 | + end | |
168 | + | |
169 | + should 'display set as default link for non default person templates' do | |
170 | + p1 = fast_create(Person, :is_template => true, :environment_id => environment.id) | |
171 | + p2 = fast_create(Person, :is_template => true, :environment_id => environment.id) | |
172 | + | |
173 | + get :index | |
174 | + assert_tag :a, '', :attributes => {:href => "/admin/templates/set_person_as_default?template_id=#{p1.id}"} | |
175 | + assert_tag :a, '', :attributes => {:href => "/admin/templates/set_person_as_default?template_id=#{p2.id}"} | |
176 | + end | |
177 | + | |
178 | + should 'display set as default link for non default enterprise templates' do | |
179 | + e1 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
180 | + e2 = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
181 | + | |
182 | + get :index | |
183 | + assert_tag :a, '', :attributes => {:href => "/admin/templates/set_enterprise_as_default?template_id=#{e1.id}"} | |
184 | + assert_tag :a, '', :attributes => {:href => "/admin/templates/set_enterprise_as_default?template_id=#{e2.id}"} | |
185 | + end | |
186 | + | |
187 | + should 'not display set as default link for default community template' do | |
188 | + c1 = fast_create(Community, :is_template => true, :environment_id => environment.id) | |
189 | + c2 = fast_create(Community, :is_template => true, :environment_id => environment.id) | |
190 | + environment.community_default_template= c1 | |
191 | + environment.save | |
192 | + | |
193 | + get :index | |
194 | + assert_no_tag :a, '', :attributes => {:href => "/admin/templates/set_community_as_default?template_id=#{c1.id}"} | |
195 | + end | |
196 | + | |
31 | 197 | end |
32 | 198 | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -254,6 +254,44 @@ class ApplicationHelperTest < ActionView::TestCase |
254 | 254 | end |
255 | 255 | end |
256 | 256 | |
257 | + should 'define the community default template as checked' do | |
258 | + environment = Environment.default | |
259 | + self.stubs(:environment).returns(environment) | |
260 | + community = fast_create(Community, :is_template => true, :environment_id => environment.id) | |
261 | + fast_create(Community, :is_template => true, :environment_id => environment.id) | |
262 | + environment.community_default_template= community | |
263 | + environment.save | |
264 | + | |
265 | + assert_tag_in_string template_options(:communities, 'community'), :tag => 'input', | |
266 | + :attributes => { :name => "community[template_id]", :value => community.id, :checked => true } | |
267 | + end | |
268 | + | |
269 | + should 'define the person default template as checked' do | |
270 | + environment = Environment.default | |
271 | + self.stubs(:environment).returns(environment) | |
272 | + person = fast_create(Person, :is_template => true, :environment_id => environment.id) | |
273 | + fast_create(Person, :is_template => true, :environment_id => environment.id) | |
274 | + environment.person_default_template= person | |
275 | + environment.save | |
276 | + | |
277 | + assert_tag_in_string template_options(:people, 'profile_data'), :tag => 'input', | |
278 | + :attributes => { :name => "profile_data[template_id]", :value => person.id, :checked => true } | |
279 | + end | |
280 | + | |
281 | + should 'define the enterprise default template as checked' do | |
282 | + environment = Environment.default | |
283 | + self.stubs(:environment).returns(environment) | |
284 | + enterprise = fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
285 | + fast_create(Enterprise, :is_template => true, :environment_id => environment.id) | |
286 | + | |
287 | + environment.enterprise_default_template= enterprise | |
288 | + environment.save | |
289 | + environment.reload | |
290 | + | |
291 | + assert_tag_in_string template_options(:enterprises, 'create_enterprise'), :tag => 'input', | |
292 | + :attributes => { :name => "create_enterprise[template_id]", :value => enterprise.id, :checked => true } | |
293 | + end | |
294 | + | |
257 | 295 | should 'return nil if disable_categories is enabled' do |
258 | 296 | env = fast_create(Environment, :name => 'env test') |
259 | 297 | stubs(:environment).returns(env) | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -169,7 +169,7 @@ class EnterpriseTest < ActiveSupport::TestCase |
169 | 169 | |
170 | 170 | e = Environment.default |
171 | 171 | e.replace_enterprise_template_when_enable = true |
172 | - e.enterprise_template = template | |
172 | + e.enterprise_default_template = template | |
173 | 173 | e.save! |
174 | 174 | |
175 | 175 | ent = fast_create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) |
... | ... | @@ -192,7 +192,7 @@ class EnterpriseTest < ActiveSupport::TestCase |
192 | 192 | |
193 | 193 | e = Environment.default |
194 | 194 | e.inactive_enterprise_template = inactive_template |
195 | - e.enterprise_template = active_template | |
195 | + e.enterprise_default_template = active_template | |
196 | 196 | e.save! |
197 | 197 | |
198 | 198 | ent = create(Enterprise, :name => 'test enteprise', :identifier => 'test_ent', :enabled => false) | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -506,32 +506,235 @@ class EnvironmentTest < ActiveSupport::TestCase |
506 | 506 | e.reload |
507 | 507 | |
508 | 508 | # the templates must be created |
509 | - assert_kind_of Enterprise, e.enterprise_template | |
509 | + assert_kind_of Enterprise, e.enterprise_default_template | |
510 | 510 | assert_kind_of Enterprise, e.inactive_enterprise_template |
511 | - assert_kind_of Community, e.community_template | |
512 | - assert_kind_of Person, e.person_template | |
511 | + assert_kind_of Community, e.community_default_template | |
512 | + assert_kind_of Person, e.person_default_template | |
513 | 513 | |
514 | 514 | # the templates must be private |
515 | - assert !e.enterprise_template.visible? | |
515 | + assert !e.enterprise_default_template.visible? | |
516 | 516 | assert !e.inactive_enterprise_template.visible? |
517 | - assert !e.community_template.visible? | |
518 | - assert !e.person_template.visible? | |
517 | + assert !e.community_default_template.visible? | |
518 | + assert !e.person_default_template.visible? | |
519 | 519 | end |
520 | 520 | |
521 | - should 'set templates' do | |
521 | + should 'person_templates return all templates of person' do | |
522 | 522 | e = fast_create(Environment) |
523 | 523 | |
524 | - comm = fast_create(Community, :is_template => true) | |
525 | - e.community_template = comm | |
526 | - assert_equal comm, e.community_template | |
524 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
525 | + p2 = fast_create(Person, :environment_id => e.id) | |
526 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
527 | + assert_equivalent [p1,p3], e.person_templates | |
528 | + end | |
529 | + | |
530 | + should 'person_templates return an empty array if there is no templates of person' do | |
531 | + e = fast_create(Environment) | |
532 | + | |
533 | + fast_create(Person, :environment_id => e.id) | |
534 | + fast_create(Person, :environment_id => e.id) | |
535 | + assert_equivalent [], e.person_templates | |
536 | + end | |
537 | + | |
538 | + should 'person_default_template return the template defined as default' do | |
539 | + e = fast_create(Environment) | |
540 | + | |
541 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
542 | + p2 = fast_create(Person, :environment_id => e.id) | |
543 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
544 | + | |
545 | + e.settings[:person_template_id]= p3.id | |
546 | + assert_equal p3, e.person_default_template | |
547 | + end | |
548 | + | |
549 | + should 'person_default_template not return a person if its not a template' do | |
550 | + e = fast_create(Environment) | |
551 | + | |
552 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
553 | + p2 = fast_create(Person, :environment_id => e.id) | |
554 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
555 | + | |
556 | + e.settings[:person_template_id]= p2.id | |
557 | + assert_nil e.person_default_template | |
558 | + end | |
559 | + | |
560 | + should 'person_default_template= define a person model passed as paremeter as default template' do | |
561 | + e = fast_create(Environment) | |
562 | + | |
563 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
564 | + p2 = fast_create(Person, :environment_id => e.id) | |
565 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
566 | + | |
567 | + e.person_default_template= p3 | |
568 | + assert_equal p3, e.person_default_template | |
569 | + end | |
570 | + | |
571 | + should 'person_default_template= define an id passed as paremeter as the default template' do | |
572 | + e = fast_create(Environment) | |
573 | + | |
574 | + p1= fast_create(Person, :is_template => true, :environment_id => e.id) | |
575 | + p2 = fast_create(Person, :environment_id => e.id) | |
576 | + p3 = fast_create(Person, :is_template => true, :environment_id => e.id) | |
577 | + | |
578 | + e.person_default_template= p3.id | |
579 | + assert_equal p3, e.person_default_template | |
580 | + end | |
581 | + | |
582 | + should 'community_templates return all templates of community' do | |
583 | + e = fast_create(Environment) | |
584 | + | |
585 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
586 | + c2 = fast_create(Community, :environment_id => e.id) | |
587 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
588 | + assert_equivalent [c1,c3], e.community_templates | |
589 | + end | |
590 | + | |
591 | + should 'community_templates return an empty array if there is no templates of community' do | |
592 | + e = fast_create(Environment) | |
593 | + | |
594 | + fast_create(Community, :environment_id => e.id) | |
595 | + fast_create(Community, :environment_id => e.id) | |
596 | + assert_equivalent [], e.community_templates | |
597 | + end | |
598 | + | |
599 | + should 'community_default_template return the template defined as default' do | |
600 | + e = fast_create(Environment) | |
601 | + | |
602 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
603 | + c2 = fast_create(Community, :environment_id => e.id) | |
604 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
605 | + | |
606 | + e.settings[:community_template_id]= c3.id | |
607 | + assert_equal c3, e.community_default_template | |
608 | + end | |
609 | + | |
610 | + should 'community_default_template not return a community if its not a template' do | |
611 | + e = fast_create(Environment) | |
612 | + | |
613 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
614 | + c2 = fast_create(Community, :environment_id => e.id) | |
615 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
616 | + | |
617 | + e.settings[:community_template_id]= c2.id | |
618 | + assert_nil e.community_default_template | |
619 | + end | |
620 | + | |
621 | + should 'community_default_template= define a community model passed as paremeter as default template' do | |
622 | + e = fast_create(Environment) | |
623 | + | |
624 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
625 | + c2 = fast_create(Community, :environment_id => e.id) | |
626 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
627 | + | |
628 | + e.community_default_template= c3 | |
629 | + assert_equal c3, e.community_default_template | |
630 | + end | |
631 | + | |
632 | + should 'community_default_template= define an id passed as paremeter as the default template' do | |
633 | + e = fast_create(Environment) | |
634 | + | |
635 | + c1= fast_create(Community, :is_template => true, :environment_id => e.id) | |
636 | + c2 = fast_create(Community, :environment_id => e.id) | |
637 | + c3 = fast_create(Community, :is_template => true, :environment_id => e.id) | |
638 | + | |
639 | + e.community_default_template= c3.id | |
640 | + assert_equal c3, e.community_default_template | |
641 | + end | |
642 | + | |
643 | + should 'enterprise_templates return all templates of enterprise' do | |
644 | + env = fast_create(Environment) | |
645 | + | |
646 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
647 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
648 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
649 | + assert_equivalent [e1,e3], env.enterprise_templates | |
650 | + end | |
651 | + | |
652 | + should 'enterprise_templates return an empty array if there is no templates of enterprise' do | |
653 | + env = fast_create(Environment) | |
654 | + | |
655 | + fast_create(Enterprise, :environment_id => env.id) | |
656 | + fast_create(Enterprise, :environment_id => env.id) | |
657 | + assert_equivalent [], env.enterprise_templates | |
658 | + end | |
659 | + | |
660 | + should 'enterprise_default_template return the template defined as default' do | |
661 | + env = fast_create(Environment) | |
662 | + | |
663 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
664 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
665 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
666 | + | |
667 | + env.settings[:enterprise_template_id]= e3.id | |
668 | + assert_equal e3, env.enterprise_default_template | |
669 | + end | |
670 | + | |
671 | + should 'enterprise_default_template not return a enterprise if its not a template' do | |
672 | + env = fast_create(Environment) | |
673 | + | |
674 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
675 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
676 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
677 | + | |
678 | + env.settings[:enterprise_template_id]= e2.id | |
679 | + assert_nil env.enterprise_default_template | |
680 | + end | |
681 | + | |
682 | + should 'enterprise_default_template= define a enterprise model passed as paremeter as default template' do | |
683 | + env = fast_create(Environment) | |
684 | + | |
685 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
686 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
687 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
688 | + | |
689 | + env.enterprise_default_template= e3 | |
690 | + assert_equal e3, env.enterprise_default_template | |
691 | + end | |
692 | + | |
693 | + should 'enterprise_default_template= define an id passed as paremeter as the default template' do | |
694 | + env = fast_create(Environment) | |
695 | + | |
696 | + e1= fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
697 | + e2 = fast_create(Enterprise, :environment_id => env.id) | |
698 | + e3 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
699 | + | |
700 | + env.enterprise_default_template= e3.id | |
701 | + assert_equal e3, env.enterprise_default_template | |
702 | + end | |
703 | + | |
704 | + should 'is_default_template? method identify a person default template as default' do | |
705 | + env = fast_create(Environment) | |
706 | + | |
707 | + p1 = fast_create(Person, :is_template => true, :environment_id => env.id) | |
708 | + env.person_default_template= p1.id | |
709 | + assert env.is_default_template?(p1) | |
710 | + | |
711 | + p2 = fast_create(Person, :is_template => true, :environment_id => env.id) | |
712 | + env.person_default_template= p2.id | |
713 | + assert !env.is_default_template?(p1) | |
714 | + end | |
715 | + | |
716 | + should 'is_default_template? method identify a community default template as default' do | |
717 | + env = fast_create(Environment) | |
718 | + | |
719 | + c1 = fast_create(Community, :is_template => true, :environment_id => env.id) | |
720 | + env.community_default_template= c1.id | |
721 | + assert env.is_default_template?(c1) | |
722 | + | |
723 | + c2 = fast_create(Community, :is_template => true, :environment_id => env.id) | |
724 | + env.community_default_template= c2.id | |
725 | + assert !env.is_default_template?(c1) | |
726 | + end | |
727 | + | |
728 | + should 'is_default_template? method identify a enterprise default template as default' do | |
729 | + env = fast_create(Environment) | |
527 | 730 | |
528 | - person = fast_create(Person, :is_template => true) | |
529 | - e.person_template = person | |
530 | - assert_equal person, e.person_template | |
731 | + e1 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
732 | + env.enterprise_default_template= e1.id | |
733 | + assert env.is_default_template?(e1) | |
531 | 734 | |
532 | - enterprise = fast_create(Enterprise, :is_template => true) | |
533 | - e.enterprise_template = enterprise | |
534 | - assert_equal enterprise, e.enterprise_template | |
735 | + e2 = fast_create(Enterprise, :is_template => true, :environment_id => env.id) | |
736 | + env.enterprise_default_template= e2.id | |
737 | + assert !env.is_default_template?(e1) | |
535 | 738 | end |
536 | 739 | |
537 | 740 | should 'have a layout template' do | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -883,7 +883,7 @@ class ProfileTest < ActiveSupport::TestCase |
883 | 883 | |
884 | 884 | should 'copy communities from person template' do |
885 | 885 | template = create_user('test_template').person |
886 | - Environment.any_instance.stubs(:person_template).returns(template) | |
886 | + Environment.any_instance.stubs(:person_default_template).returns(template) | |
887 | 887 | |
888 | 888 | c1 = fast_create(Community) |
889 | 889 | c2 = fast_create(Community) |
... | ... | @@ -1336,7 +1336,7 @@ class ProfileTest < ActiveSupport::TestCase |
1336 | 1336 | template = create_user('test_template').person |
1337 | 1337 | template.custom_footer = "footer customized" |
1338 | 1338 | template.custom_header = "header customized" |
1339 | - Environment.any_instance.stubs(:person_template).returns(template) | |
1339 | + Environment.any_instance.stubs(:person_default_template).returns(template) | |
1340 | 1340 | |
1341 | 1341 | person = create_user_full('mytestuser').person |
1342 | 1342 | assert_equal "footer customized", person.custom_footer | ... | ... |