Commit 2e30180c9bbe114441ddc392d530e803eb4aa3bf

Authored by Rodrigo Souto
1 parent 6cc3ecdd

profile-templates: remove environment parameter from profile templates named_scope

app/helpers/application_helper.rb
... ... @@ -1340,8 +1340,8 @@ module ApplicationHelper
1340 1340 @plugins.dispatch("content_remove_#{action.to_s}", @page).include?(true)
1341 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 1345 return '' if templates.count == 0
1346 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 78 #FIXME: these will work only if the subclass is already loaded
79 79 named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} }
80 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 84 def members
85 85 scopes = plugins.dispatch_scopes(:organization_members, self)
... ...
app/views/account/_signup_form.rhtml
... ... @@ -101,7 +101,7 @@
101 101  
102 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 106 <% unless @terms_of_use.blank? %>
107 107 <div id='terms-of-use-box' class='formfieldline'>
... ...
app/views/enterprise_registration/basic_information.rhtml
... ... @@ -34,7 +34,7 @@
34 34 <% end %>
35 35 <% end %>
36 36  
37   - <%= template_options(Enterprise, 'create_enterprise')%>
  37 + <%= template_options(:enterprises, 'create_enterprise')%>
38 38  
39 39 <% button_bar do %>
40 40 <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %>
... ...
app/views/memberships/new_community.rhtml
... ... @@ -44,7 +44,7 @@
44 44 </div>
45 45 </div>
46 46  
47   - <%= template_options(Community, 'community')%>
  47 + <%= template_options(:communities, 'community')%>
48 48  
49 49 <%= hidden_field_tag('back_to', @back_to) %>
50 50  
... ...
app/views/templates/index.html.erb
... ... @@ -2,9 +2,9 @@
2 2  
3 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 9 <% list_of_templates.each do |title, templates, kind|%>
10 10 <div class='template-kind'>
... ...
test/unit/application_helper_test.rb
... ... @@ -256,7 +256,7 @@ class ApplicationHelperTest &lt; ActiveSupport::TestCase
256 256  
257 257 should 'not display templates options when there is no template' do
258 258 self.stubs(:environment).returns(Environment.default)
259   - [Person, Community, Enterprise].each do |klass|
  259 + [:people, :communities, :enterprises].each do |klass|
260 260 assert_equal '', template_options(klass, 'profile_data')
261 261 end
262 262 end
... ...
test/unit/profile_test.rb
... ... @@ -1370,25 +1370,27 @@ class ProfileTest &lt; ActiveSupport::TestCase
1370 1370 end
1371 1371  
1372 1372 should 'return a list of templates' do
  1373 + environment = Environment.default
1373 1374 t1 = fast_create(Profile, :is_template => true)
1374 1375 t2 = fast_create(Profile, :is_template => true)
1375 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 1381 end
1381 1382  
1382 1383 should 'return a list of profiles that are not templates' do
  1384 + environment = Environment.default
1383 1385 p1 = fast_create(Profile, :is_template => false)
1384 1386 p2 = fast_create(Profile, :is_template => false)
1385 1387 t1 = fast_create(Profile, :is_template => true)
1386 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 1394 end
1393 1395  
1394 1396 should 'not crash on a profile update with a destroyed template' do
... ...