Sha256: 401aa06bbd9405d8d19e4312bbbb9688c02ba8380ad9c65a4fa22b2dc72bec6f

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

require 'spec_helper'
require 'flapjack/data/migration'
require 'flapjack/data/notification_rule'

describe Flapjack::Data::Migration, :redis => true do

  it "fixes a notification rule wih no contact association" do
    contact = Flapjack::Data::Contact.add( {
        'id'         => 'c362',
        'first_name' => 'John',
        'last_name'  => 'Johnson',
        'email'      => 'johnj@example.com',
        'media'      => {
          'pagerduty' => {
            'service_key' => '123456789012345678901234',
            'subdomain'   => 'flpjck',
            'username'    => 'flapjack',
            'password'    => 'very_secure'
          },
        },
      },
      :redis => @redis)

    rule = contact.add_notification_rule(
     :tags               => ["database","physical"],
     :entities           => ["foo-app-01.example.com"],
     :time_restrictions  => [],
     :unknown_media      => [],
     :warning_media      => ["email"],
     :critical_media     => ["sms", "email"],
     :unknown_blackhole  => false,
     :warning_blackhole  => false,
     :critical_blackhole => false
    )

    rule_id = rule.id

    # degrade as the bug had previously
    @redis.hset("notification_rule:#{rule.id}", 'contact_id', '')

    rule = Flapjack::Data::NotificationRule.find_by_id(rule_id, :redis => @redis)
    expect(rule).not_to be_nil
    expect(rule.contact_id).to be_empty

    Flapjack::Data::Migration.correct_notification_rule_contact_linkages(:redis => @redis)

    rule = Flapjack::Data::NotificationRule.find_by_id(rule_id, :redis => @redis)
    expect(rule).not_to be_nil
    expect(rule.contact_id).to eq(contact.id)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flapjack-1.2.1 spec/lib/flapjack/data/migration_spec.rb
flapjack-1.2.1rc3 spec/lib/flapjack/data/migration_spec.rb
flapjack-1.2.1rc2 spec/lib/flapjack/data/migration_spec.rb
flapjack-1.2.1rc1 spec/lib/flapjack/data/migration_spec.rb
flapjack-1.2.0 spec/lib/flapjack/data/migration_spec.rb