Commit 2e30180c9bbe114441ddc392d530e803eb4aa3bf
1 parent
6cc3ecdd
Exists in
master
and in
29 other branches
profile-templates: remove environment parameter from profile templates named_scope
Showing
8 changed files
with
20 additions
and
18 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -1340,8 +1340,8 @@ module ApplicationHelper | @@ -1340,8 +1340,8 @@ module ApplicationHelper | ||
1340 | @plugins.dispatch("content_remove_#{action.to_s}", @page).include?(true) | 1340 | @plugins.dispatch("content_remove_#{action.to_s}", @page).include?(true) |
1341 | end | 1341 | end |
1342 | 1342 | ||
1343 | - def template_options(klass, field_name) | ||
1344 | - templates = klass.templates(environment) | 1343 | + def template_options(kind, field_name) |
1344 | + templates = environment.send(kind).templates | ||
1345 | return '' if templates.count == 0 | 1345 | return '' if templates.count == 0 |
1346 | return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 | 1346 | return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 |
1347 | 1347 |
app/models/profile.rb
@@ -78,8 +78,8 @@ class Profile < ActiveRecord::Base | @@ -78,8 +78,8 @@ class Profile < ActiveRecord::Base | ||
78 | #FIXME: these will work only if the subclass is already loaded | 78 | #FIXME: these will work only if the subclass is already loaded |
79 | named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 79 | named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
80 | named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 80 | named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
81 | - named_scope :templates, lambda { |environment| { :conditions => {:is_template => true, :environment_id => environment.id} } } | ||
82 | - named_scope :no_templates, lambda { |environment| { :conditions => {:is_template => false, :environment_id => environment.id} } } | 81 | + named_scope :templates, {:conditions => {:is_template => true}} |
82 | + named_scope :no_templates, {:conditions => {:is_template => false}} | ||
83 | 83 | ||
84 | def members | 84 | def members |
85 | scopes = plugins.dispatch_scopes(:organization_members, self) | 85 | scopes = plugins.dispatch_scopes(:organization_members, self) |
app/views/account/_signup_form.rhtml
@@ -101,7 +101,7 @@ | @@ -101,7 +101,7 @@ | ||
101 | 101 | ||
102 | <%= @plugins.dispatch(:signup_extra_contents).collect { |content| instance_eval(&content) }.join("") %> | 102 | <%= @plugins.dispatch(:signup_extra_contents).collect { |content| instance_eval(&content) }.join("") %> |
103 | 103 | ||
104 | - <%= template_options(Person, 'profile_data') %> | 104 | + <%= template_options(:people, 'profile_data') %> |
105 | 105 | ||
106 | <% unless @terms_of_use.blank? %> | 106 | <% unless @terms_of_use.blank? %> |
107 | <div id='terms-of-use-box' class='formfieldline'> | 107 | <div id='terms-of-use-box' class='formfieldline'> |
app/views/enterprise_registration/basic_information.rhtml
@@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
34 | <% end %> | 34 | <% end %> |
35 | <% end %> | 35 | <% end %> |
36 | 36 | ||
37 | - <%= template_options(Enterprise, 'create_enterprise')%> | 37 | + <%= template_options(:enterprises, 'create_enterprise')%> |
38 | 38 | ||
39 | <% button_bar do %> | 39 | <% button_bar do %> |
40 | <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %> | 40 | <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %> |
app/views/memberships/new_community.rhtml
app/views/templates/index.html.erb
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | 2 | ||
3 | <%= _('Manage the templates used on creation of profiles') %> | 3 | <%= _('Manage the templates used on creation of profiles') %> |
4 | 4 | ||
5 | -<% list_of_templates = [[_('Person') , Person.templates(environment) , 'person' ], | ||
6 | - [_('Community') , Community.templates(environment) , 'community' ], | ||
7 | - [_('Enterprise'), Enterprise.templates(environment), 'enterprise']] %> | 5 | +<% list_of_templates = [[_('Person') , environment.people.templates , 'person' ], |
6 | + [_('Community') , environment.communities.templates, 'community' ], | ||
7 | + [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %> | ||
8 | 8 | ||
9 | <% list_of_templates.each do |title, templates, kind|%> | 9 | <% list_of_templates.each do |title, templates, kind|%> |
10 | <div class='template-kind'> | 10 | <div class='template-kind'> |
test/unit/application_helper_test.rb
@@ -256,7 +256,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase | @@ -256,7 +256,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase | ||
256 | 256 | ||
257 | should 'not display templates options when there is no template' do | 257 | should 'not display templates options when there is no template' do |
258 | self.stubs(:environment).returns(Environment.default) | 258 | self.stubs(:environment).returns(Environment.default) |
259 | - [Person, Community, Enterprise].each do |klass| | 259 | + [:people, :communities, :enterprises].each do |klass| |
260 | assert_equal '', template_options(klass, 'profile_data') | 260 | assert_equal '', template_options(klass, 'profile_data') |
261 | end | 261 | end |
262 | end | 262 | end |
test/unit/profile_test.rb
@@ -1370,25 +1370,27 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1370,25 +1370,27 @@ class ProfileTest < ActiveSupport::TestCase | ||
1370 | end | 1370 | end |
1371 | 1371 | ||
1372 | should 'return a list of templates' do | 1372 | should 'return a list of templates' do |
1373 | + environment = Environment.default | ||
1373 | t1 = fast_create(Profile, :is_template => true) | 1374 | t1 = fast_create(Profile, :is_template => true) |
1374 | t2 = fast_create(Profile, :is_template => true) | 1375 | t2 = fast_create(Profile, :is_template => true) |
1375 | profile = fast_create(Profile) | 1376 | profile = fast_create(Profile) |
1376 | 1377 | ||
1377 | - assert_includes Profile.templates(Environment.default), t1 | ||
1378 | - assert_includes Profile.templates(Environment.default), t2 | ||
1379 | - assert_not_includes Profile.templates(Environment.default), profile | 1378 | + assert_includes environment.profiles.templates, t1 |
1379 | + assert_includes environment.profiles.templates, t2 | ||
1380 | + assert_not_includes environment.profiles.templates, profile | ||
1380 | end | 1381 | end |
1381 | 1382 | ||
1382 | should 'return a list of profiles that are not templates' do | 1383 | should 'return a list of profiles that are not templates' do |
1384 | + environment = Environment.default | ||
1383 | p1 = fast_create(Profile, :is_template => false) | 1385 | p1 = fast_create(Profile, :is_template => false) |
1384 | p2 = fast_create(Profile, :is_template => false) | 1386 | p2 = fast_create(Profile, :is_template => false) |
1385 | t1 = fast_create(Profile, :is_template => true) | 1387 | t1 = fast_create(Profile, :is_template => true) |
1386 | t2 = fast_create(Profile, :is_template => true) | 1388 | t2 = fast_create(Profile, :is_template => true) |
1387 | 1389 | ||
1388 | - assert_includes Profile.no_templates(Environment.default), p1 | ||
1389 | - assert_includes Profile.no_templates(Environment.default), p2 | ||
1390 | - assert_not_includes Profile.no_templates(Environment.default), t1 | ||
1391 | - assert_not_includes Profile.no_templates(Environment.default), t2 | 1390 | + assert_includes environment.profiles.no_templates, p1 |
1391 | + assert_includes environment.profiles.no_templates, p2 | ||
1392 | + assert_not_includes environment.profiles.no_templates, t1 | ||
1393 | + assert_not_includes environment.profiles.no_templates, t2 | ||
1392 | end | 1394 | end |
1393 | 1395 | ||
1394 | should 'not crash on a profile update with a destroyed template' do | 1396 | should 'not crash on a profile update with a destroyed template' do |