require 'test_helper' class MailEngine::MailTemplateTest < ActiveSupport::TestCase def self.should_process_file should "be able to extract files" do assert_equal 2, @template.mail_template_files.size @template.mail_template_files.map {|f| f.file.url}.each do |template_file_url| assert @template.body.include?(template_file_url), "don't include #{template_file_url}" end end should "remove the temp file after created" do assert_equal [".", ".."], Dir.entries(File.join(Rails.root, "tmp", "zip_processor_tmp_dir")) end end context "Template" do setup do @template = FactoryGirl.create(:system_mail_template, :format => "html") end should "have a correct full path" do assert_equal "user_mailer/notify.en.html.liquid", @template.full_path end should "have a correct template name" do assert_equal "notify", @template.template_name end should "have a correct filename" do assert_equal "user_mailer/notify", @template.filename @template.partial = true assert_equal "user_mailer/_notify", @template.filename end end context "Create by upload" do context "a dirzip file" do setup do @template = FactoryGirl.create(:dirzip_mail_template, :format => "html") end should_process_file end context "a filezip file" do setup do @template = FactoryGirl.create(:filezip_mail_template, :format => "html") end should_process_file end end context "Template duplication" do setup do @zipmail_template = FactoryGirl.create(:zip_mail_template_with_footer, :format => "html") @clone_template = @zipmail_template.duplicate end should "clone zip file" do assert_not_equal @clone_template.zip_file.path, @zipmail_template.zip_file.path end should "clone mail template files" do assert_equal @clone_template.mail_template_files.count, @zipmail_template.mail_template_files.count @clone_template.mail_template_files.each_with_index do |f, index| assert_equal f.file.path, @zipmail_template.mail_template_files[index] end end should "clone partial relation records" do assert_equal @clone_template.partials.count, @zipmail_template.partials.count end end end