aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2012-09-26 12:19:24 +0100
committerLouise Crow <louise.crow@gmail.com>2012-09-26 12:19:24 +0100
commitd4109a8506ec9fc5e78559989f6d0bc1d388fdc5 (patch)
tree57e4db45ca5d178c59f00d31a39433b149311415 /spec/models
parent8c0bea8841f05ec3318aee6f06be28c587c9128d (diff)
parenta7290f92d26e95588919c1ddeaeda3a56c7fee0d (diff)
Merge branch 'develop', remote-tracking branch 'origin' into feature/preview_emails
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/application_mailer_spec.rb156
-rw-r--r--spec/models/request_mailer_spec.rb5
2 files changed, 158 insertions, 3 deletions
diff --git a/spec/models/application_mailer_spec.rb b/spec/models/application_mailer_spec.rb
index 12527c6e8..a90f79c01 100644
--- a/spec/models/application_mailer_spec.rb
+++ b/spec/models/application_mailer_spec.rb
@@ -1,8 +1,160 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe ApplicationMailer, " when blah" do
- before do
+
+describe ApplicationMailer do
+
+ context 'when using plugins' do
+
+ def set_base_views
+ ApplicationMailer.class_eval do
+ @previous_view_paths = self.view_paths.dup
+ self.view_paths.clear
+ self.view_paths << File.join(Rails.root, 'spec', 'fixtures', 'theme_views', 'core')
+ end
+ end
+
+ def add_mail_methods(method_names)
+ method_names.each{ |method_name| ApplicationMailer.send(:define_method, method_name){} }
+ end
+
+ def remove_mail_methods(method_names)
+ method_names.each do |method_name|
+ if ApplicationMailer.respond_to?(method_name)
+ ApplicationMailer.send(:remove_method, method_name)
+ end
+ end
+ end
+
+ def prepend_theme_views(theme_name)
+ ApplicationMailer.class_eval do
+ view_paths.unshift File.join(Rails.root, 'spec', 'fixtures', 'theme_views', theme_name)
+ end
+ end
+
+ def append_theme_views(theme_name)
+ ApplicationMailer.class_eval do
+ view_paths << File.join(Rails.root, 'spec', 'fixtures', 'theme_views', theme_name)
+ end
+ end
+
+ def reset_views
+ ApplicationMailer.class_eval do
+ self.view_paths = @previous_view_paths
+ end
+ end
+
+ def create_multipart_method(method_name)
+ ApplicationMailer.send(:define_method, method_name) do
+ attachment :content_type => 'message/rfc822',
+ :body => 'xxx',
+ :filename => "original.eml",
+ :transfer_encoding => '7bit',
+ :content_disposition => 'inline'
+ end
+ end
+
+ before do
+ set_base_views
+ add_mail_methods(['simple', 'theme_only', 'core_only', 'neither'])
+ end
+
+ describe 'when a plugin prepends its mail templates to the view paths' do
+
+ it 'should render a theme template in preference to a core template' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_simple()
+ @mail.body.should match('Theme simple')
+ end
+
+ it 'should render the template provided by the theme if no template is available in core' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_theme_only()
+ @mail.body.should match('Theme only')
+ end
+
+ it 'should render the template provided by core if there is no theme template' do
+ prepend_theme_views('theme_one')
+ @mail = ApplicationMailer.create_core_only()
+ @mail.body.should match('Core only')
+ end
+
+ it 'should raise an error if the template is in neither core nor theme' do
+ prepend_theme_views('theme_one')
+ lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/theme_one:spec/fixtures/theme_views/core')
+ end
+
+ it 'should render a multipart email using a theme template' do
+ prepend_theme_views('theme_one')
+ create_multipart_method('multipart_theme_only')
+ @mail = ApplicationMailer.create_multipart_theme_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Theme multipart")
+ end
+
+ it 'should render a multipart email using a core template' do
+ prepend_theme_views('theme_one')
+ create_multipart_method('multipart_core_only')
+ @mail = ApplicationMailer.create_multipart_core_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Core multipart")
+ end
+
+ end
+
+ describe 'when a plugin appends its mail templates to the view paths' do
+
+ it 'should render a core template in preference to a theme template' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_simple()
+ @mail.body.should match('Core simple')
+ end
+
+ it 'should render the template provided by the theme if no template is available in core' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_theme_only()
+ @mail.body.should match('Theme only')
+ end
+
+ it 'should render the template provided by core if there is no theme template' do
+ append_theme_views('theme_one')
+ @mail = ApplicationMailer.create_core_only()
+ @mail.body.should match('Core only')
+ end
+
+ it 'should raise an error if the template is in neither core nor theme' do
+ append_theme_views('theme_one')
+ lambda{ ApplicationMailer.create_neither() }.should raise_error('Missing template application_mailer/neither.erb in view path spec/fixtures/theme_views/core:spec/fixtures/theme_views/theme_one')
+ end
+
+ it 'should render a multipart email using a core template' do
+ append_theme_views('theme_one')
+ create_multipart_method('multipart_core_only')
+ @mail = ApplicationMailer.create_multipart_core_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Core multipart")
+ end
+
+ it 'should render a multipart email using a theme template' do
+ append_theme_views('theme_one')
+ create_multipart_method('multipart_theme_only')
+ @mail = ApplicationMailer.create_multipart_theme_only()
+ @mail.parts.size.should == 2
+ message_part = @mail.parts[0].to_s
+ message_part.should match("Theme multipart")
+ end
+
+ end
+
+ after do
+ reset_views
+ remove_mail_methods(['simple', 'theme_only', 'core_only', 'neither', 'multipart'])
+ end
end
+
end
+
diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb
index 98681a9e9..eec362ad3 100644
--- a/spec/models/request_mailer_spec.rb
+++ b/spec/models/request_mailer_spec.rb
@@ -97,10 +97,12 @@ describe RequestMailer, " when receiving incoming mail" do
# check attached bounce is good copy of incoming-request-plain.email
mail.multipart?.should == true
mail.parts.size.should == 2
+ message_part = mail.parts[0].to_s
bounced_mail = TMail::Mail.parse(mail.parts[1].body)
bounced_mail.to.should == [ ir.incoming_email ]
bounced_mail.from.should == [ 'geraldinequango@localhost' ]
- bounced_mail.body.include?("That's so totally a rubbish question")
+ bounced_mail.body.include?("That's so totally a rubbish question").should be_true
+ message_part.include?("marked to no longer receive responses").should be_true
deliveries.clear
end
@@ -324,3 +326,4 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla
end
end
+