Commit 2c76259315d468c50e51599ab25394f207eb0f32
1 parent
fc9326ee
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Display available templates filtered by owner type
Showing
3 changed files
with
27 additions
and
13 deletions
Show diff stats
app/controllers/my_profile/email_templates_controller.rb
app/models/email_template.rb
... | ... | @@ -18,13 +18,17 @@ class EmailTemplate < ActiveRecord::Base |
18 | 18 | @parsed_subject ||= parse(subject, params) |
19 | 19 | end |
20 | 20 | |
21 | + def self.available_types | |
22 | + { | |
23 | + :task_rejection => {:description => _('Task Rejection'), :owner_type => Profile}, | |
24 | + :task_acceptance => {:description => _('Task Acceptance'), :owner_type => Profile}, | |
25 | + :organization_members => {:description => _('Organization Members'), :owner_type => Profile}, | |
26 | + :user_activation => {:description => _('User Activation'), :unique => true, :owner_type => Environment} | |
27 | + } | |
28 | + end | |
29 | + | |
21 | 30 | def available_types |
22 | - HashWithIndifferentAccess.new ({ | |
23 | - :task_rejection => {:description => _('Task Rejection')}, | |
24 | - :task_acceptance => {:description => _('Task Acceptance')}, | |
25 | - :organization_members => {:description => _('Organization Members')}, | |
26 | - :user_activation => {:description => _('User Activation'), :unique => true} | |
27 | - }) | |
31 | + HashWithIndifferentAccess.new EmailTemplate.available_types.select {|k, v| owner.kind_of?(v[:owner_type])} | |
28 | 32 | end |
29 | 33 | |
30 | 34 | def unique_by_type? | ... | ... |
test/unit/email_template_test.rb
... | ... | @@ -20,24 +20,34 @@ class EmailTemplateTest < ActiveSupport::TestCase |
20 | 20 | end |
21 | 21 | |
22 | 22 | should 'not create template with the same name of other' do |
23 | - template1 = EmailTemplate.new(:template_type => :type1, :name => 'template') | |
24 | - template2 = EmailTemplate.new(:template_type => :type1, :name => 'template') | |
23 | + template1 = EmailTemplate.new(:template_type => :type1, :name => 'template', :owner => Environment.default) | |
24 | + template2 = EmailTemplate.new(:template_type => :type1, :name => 'template', :owner => Environment.default) | |
25 | 25 | assert template1.save |
26 | 26 | assert !template2.save |
27 | 27 | end |
28 | 28 | |
29 | 29 | should 'not create duplicated template when template type is unique' do |
30 | - template1 = EmailTemplate.new(:template_type => :user_activation, :name => 'template1') | |
31 | - template2 = EmailTemplate.new(:template_type => :user_activation, :name => 'template2') | |
30 | + template1 = EmailTemplate.new(:template_type => :user_activation, :name => 'template1', :owner => Environment.default) | |
31 | + template2 = EmailTemplate.new(:template_type => :user_activation, :name => 'template2', :owner => Environment.default) | |
32 | 32 | assert template1.save |
33 | 33 | assert !template2.save |
34 | 34 | end |
35 | 35 | |
36 | 36 | should 'create duplicated template when template type is not unique' do |
37 | - template1 = EmailTemplate.new(:template_type => :task_rejection, :name => 'template1') | |
38 | - template2 = EmailTemplate.new(:template_type => :task_rejection, :name => 'template2') | |
37 | + template1 = EmailTemplate.new(:template_type => :task_rejection, :name => 'template1', :owner => Environment.default) | |
38 | + template2 = EmailTemplate.new(:template_type => :task_rejection, :name => 'template2', :owner => Environment.default) | |
39 | 39 | assert template1.save |
40 | 40 | assert template2.save |
41 | 41 | end |
42 | 42 | |
43 | + should 'return available types when the owner is an environment' do | |
44 | + template = EmailTemplate.new(:owner => Environment.default) | |
45 | + assert_equal [:user_activation], template.available_types.symbolize_keys.keys | |
46 | + end | |
47 | + | |
48 | + should 'return available types when the owner is a profile' do | |
49 | + template = EmailTemplate.new(:owner => Profile.new) | |
50 | + assert_equal [:task_rejection, :task_acceptance, :organization_members], template.available_types.symbolize_keys.keys | |
51 | + end | |
52 | + | |
43 | 53 | end | ... | ... |