Sha256: 21fa5ee8419b666ed3d58a267e22f653513295feb2b296fdf67ff641110c6762

Contents?: true

Size: 1.68 KB

Versions: 12

Compression:

Stored size: 1.68 KB

Contents

require 'test_plugin_helper'

class PolicyMailerTest < ActiveSupport::TestCase
  setup do
    @user = User.current = users :admin

    FactoryGirl.create(:mail_notification,
                       :name => :openscap_policy_summary,
                       :description => N_('A summary of reports for OpenScap policies'),
                       :mailer => 'ForemanOpenscap::PolicyMailer',
                       :method => 'policy_summary',
                       :subscription_type => 'report',
                      )
    #just to have some content to send
    ForemanOpenscap::Policy.any_instance.stubs(:ensure_needed_puppetclasses).returns(true)
    host = FactoryGirl.create(:compliance_host)
    asset = FactoryGirl.create(:asset, :assetable_id => host.id)
    policy = FactoryGirl.create(:policy, :assets => [asset])
    arf_report = FactoryGirl.create(:arf_report, :policy => policy, :host_id => host.id)
    policy_arf_report = FactoryGirl.create(:policy_arf_report, :policy_id => policy.id, :arf_report_id => arf_report.id)

    @user.mail_notifications << MailNotification[:openscap_policy_summary]
    ActionMailer::Base.deliveries = []
    @user.user_mail_notifications.first.deliver
    @email = ActionMailer::Base.deliveries.first
  end

  test 'policy mailer should deliver summary' do
    assert @email.to.include?("admin@someware.com")
  end

  test 'policy mailer should contain body' do
    refute @email.body.nil?
  end

  test 'policy mailer should have a correct subject' do
    refute @email.subject.empty?
    assert @email.subject.include? Setting[:email_subject_prefix].first
  end

  test 'policy mailer sends Foreman URL in body' do
    assert @email.body.include? Setting[:foreman_url]
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
foreman_openscap-0.7.1 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.7 test/unit/policy_mailer_test.rb
foreman_openscap-0.7.0 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.6 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.5 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.4 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.3 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.2 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.1 test/unit/policy_mailer_test.rb
foreman_openscap-0.6.0 test/unit/policy_mailer_test.rb
foreman_openscap-0.5.4 test/unit/policy_mailer_test.rb
foreman_openscap-0.5.3 test/unit/policy_mailer_test.rb