diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c71ee1a..da3f83a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1330,11 +1330,12 @@ module ApplicationHelper end def template_options(klass, field_name) - return '' if klass.templates.count == 0 - return hidden_field_tag("#{field_name}[template_id]", klass.templates.first.id) if klass.templates.count == 1 + templates = klass.templates(environment.id) + return '' if templates.count == 0 + return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 counter = 0 - radios = klass.templates.map do |template| + radios = templates.map do |template| counter += 1 content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, counter==1)) end.join("\n") diff --git a/app/models/profile.rb b/app/models/profile.rb index 4a11192..5f4b393 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -68,7 +68,7 @@ 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, :conditions => {:is_template => true} + named_scope :templates, lambda { |environment_id| { :conditions => {:is_template => true, :environment_id => environment_id} } } def members scopes = plugins.dispatch_scopes(:organization_members, self) diff --git a/app/views/templates/index.html.erb b/app/views/templates/index.html.erb index afe0f7c..48f165a 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 , 'person' ], - [_('Community') , Community.templates , 'community' ], - [_('Enterprise'), Enterprise.templates, 'enterprise']] %> +<% list_of_templates = [[_('Person') , Person.templates(environment.id) , 'person' ], + [_('Community') , Community.templates(environment.id) , 'community' ], + [_('Enterprise'), Enterprise.templates(environment.id), 'enterprise']] %> <% list_of_templates.each do |title, templates, kind|%>
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 6e2cf09..76756f2 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -579,6 +579,21 @@ class AccountControllerTest < ActionController::TestCase assert_equal 1, assigns(:user).person.boxes[0].blocks.size end + should 'display only templates of the current environment' do + env2 = fast_create(Environment) + + template1 = fast_create(Person, :name => 'template1', :environment_id => Environment.default.id, :is_template => true) + template2 = fast_create(Person, :name => 'template2', :environment_id => Environment.default.id, :is_template => true) + template3 = fast_create(Person, :name => 'template3', :environment_id => env2.id, :is_template => true) + + get :signup + assert_select '#template-options' do |elements| + assert_match /template1/, elements[0].to_s + assert_match /template2/, elements[0].to_s + assert_no_match /template3/, elements[0].to_s + end + end + should 'render person partial' do Environment.any_instance.expects(:signup_person_fields).returns(['contact_phone']).at_least_once get :signup diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 0efbddf..8337349 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -243,6 +243,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase end should 'not display templates options when there is no template' do + self.stubs(:environment).returns(Environment.default) [Person, Community, Enterprise].each do |klass| assert_equal '', template_options(klass, 'profile_data') end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 9c4dcca..6106968 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1444,9 +1444,9 @@ class ProfileTest < ActiveSupport::TestCase t2 = fast_create(Profile, :is_template => true) profile = fast_create(Profile) - assert_includes Profile.templates, t1 - assert_includes Profile.templates, t2 - assert_not_includes Profile.templates, profile + assert_includes Profile.templates(Environment.default.id), t1 + assert_includes Profile.templates(Environment.default.id), t2 + assert_not_includes Profile.templates(Environment.default.id), profile end should 'provide URL to leave' do -- libgit2 0.21.2