From 2e30180c9bbe114441ddc392d530e803eb4aa3bf Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Mon, 16 Dec 2013 04:22:46 -0300 Subject: [PATCH] profile-templates: remove environment parameter from profile templates named_scope --- app/helpers/application_helper.rb | 4 ++-- app/models/profile.rb | 4 ++-- app/views/account/_signup_form.rhtml | 2 +- app/views/enterprise_registration/basic_information.rhtml | 2 +- app/views/memberships/new_community.rhtml | 2 +- app/views/templates/index.html.erb | 6 +++--- test/unit/application_helper_test.rb | 2 +- test/unit/profile_test.rb | 16 +++++++++------- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 66a2e22..1eb48c6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1340,8 +1340,8 @@ module ApplicationHelper @plugins.dispatch("content_remove_#{action.to_s}", @page).include?(true) end - def template_options(klass, field_name) - templates = klass.templates(environment) + def template_options(kind, field_name) + templates = environment.send(kind).templates return '' if templates.count == 0 return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 diff --git a/app/models/profile.rb b/app/models/profile.rb index 8cc12dd..e225281 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -78,8 +78,8 @@ class Profile < ActiveRecord::Base #FIXME: these will work only if the subclass is already loaded named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } - named_scope :templates, lambda { |environment| { :conditions => {:is_template => true, :environment_id => environment.id} } } - named_scope :no_templates, lambda { |environment| { :conditions => {:is_template => false, :environment_id => environment.id} } } + named_scope :templates, {:conditions => {:is_template => true}} + named_scope :no_templates, {:conditions => {:is_template => false}} def members scopes = plugins.dispatch_scopes(:organization_members, self) diff --git a/app/views/account/_signup_form.rhtml b/app/views/account/_signup_form.rhtml index ee58cfa..9a91453 100644 --- a/app/views/account/_signup_form.rhtml +++ b/app/views/account/_signup_form.rhtml @@ -101,7 +101,7 @@ <%= @plugins.dispatch(:signup_extra_contents).collect { |content| instance_eval(&content) }.join("") %> - <%= template_options(Person, 'profile_data') %> + <%= template_options(:people, 'profile_data') %> <% unless @terms_of_use.blank? %>
diff --git a/app/views/enterprise_registration/basic_information.rhtml b/app/views/enterprise_registration/basic_information.rhtml index 8f375ab..6c7a6ba 100644 --- a/app/views/enterprise_registration/basic_information.rhtml +++ b/app/views/enterprise_registration/basic_information.rhtml @@ -34,7 +34,7 @@ <% end %> <% end %> - <%= template_options(Enterprise, 'create_enterprise')%> + <%= template_options(:enterprises, 'create_enterprise')%> <% button_bar do %> <%= submit_button('next', _('Next'), :cancel => {:profile => current_user.person.identifier, :action=>"enterprises", :controller=>"profile"}) %> diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml index b78e923..71c9e24 100644 --- a/app/views/memberships/new_community.rhtml +++ b/app/views/memberships/new_community.rhtml @@ -44,7 +44,7 @@
- <%= template_options(Community, 'community')%> + <%= template_options(:communities, 'community')%> <%= hidden_field_tag('back_to', @back_to) %> diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb index 1060a0c..2556c74 100644 --- a/app/views/templates/index.html.erb +++ b/app/views/templates/index.html.erb @@ -2,9 +2,9 @@ <%= _('Manage the templates used on creation of profiles') %> -<% list_of_templates = [[_('Person') , Person.templates(environment) , 'person' ], - [_('Community') , Community.templates(environment) , 'community' ], - [_('Enterprise'), Enterprise.templates(environment), 'enterprise']] %> +<% list_of_templates = [[_('Person') , environment.people.templates , 'person' ], + [_('Community') , environment.communities.templates, 'community' ], + [_('Enterprise'), environment.enterprises.templates, 'enterprise']] %> <% list_of_templates.each do |title, templates, kind|%>
diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 8a778f1..e50183c 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -256,7 +256,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase should 'not display templates options when there is no template' do self.stubs(:environment).returns(Environment.default) - [Person, Community, Enterprise].each do |klass| + [:people, :communities, :enterprises].each do |klass| assert_equal '', template_options(klass, 'profile_data') end end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 4e507fe..67ef9b0 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1370,25 +1370,27 @@ class ProfileTest < ActiveSupport::TestCase end should 'return a list of templates' do + environment = Environment.default t1 = fast_create(Profile, :is_template => true) t2 = fast_create(Profile, :is_template => true) profile = fast_create(Profile) - assert_includes Profile.templates(Environment.default), t1 - assert_includes Profile.templates(Environment.default), t2 - assert_not_includes Profile.templates(Environment.default), profile + assert_includes environment.profiles.templates, t1 + assert_includes environment.profiles.templates, t2 + assert_not_includes environment.profiles.templates, profile end should 'return a list of profiles that are not templates' do + environment = Environment.default p1 = fast_create(Profile, :is_template => false) p2 = fast_create(Profile, :is_template => false) t1 = fast_create(Profile, :is_template => true) t2 = fast_create(Profile, :is_template => true) - assert_includes Profile.no_templates(Environment.default), p1 - assert_includes Profile.no_templates(Environment.default), p2 - assert_not_includes Profile.no_templates(Environment.default), t1 - assert_not_includes Profile.no_templates(Environment.default), t2 + assert_includes environment.profiles.no_templates, p1 + assert_includes environment.profiles.no_templates, p2 + assert_not_includes environment.profiles.no_templates, t1 + assert_not_includes environment.profiles.no_templates, t2 end should 'not crash on a profile update with a destroyed template' do -- libgit2 0.21.2