diff --git a/app/models/miq_event_definition.rb b/app/models/miq_event_definition.rb index a7d4f5d8f0d..9ffcd9b995f 100644 --- a/app/models/miq_event_definition.rb +++ b/app/models/miq_event_definition.rb @@ -122,6 +122,7 @@ def self.seed end def self.seed_default_events + event_sets = MiqEventDefinitionSet.all.index_by(&:name) fname = File.join(FIXTURE_DIR, "#{to_s.pluralize.underscore}.csv") CSV.foreach(fname, :headers => true, :skip_lines => /^#/, :skip_blanks => true) do |csv_row| event = csv_row.to_hash @@ -139,7 +140,7 @@ def self.seed_default_events end end - es = MiqEventDefinitionSet.find_by(:name => set_type) + es = event_sets[set_type] rec.memberof.each { |old_set| rec.make_not_memberof(old_set) unless old_set == es } # handle changes in set membership es.add_member(rec) if es && !es.members.include?(rec) end diff --git a/spec/models/miq_event_definition_spec.rb b/spec/models/miq_event_definition_spec.rb index c23f30aa1a2..8da1063a5af 100644 --- a/spec/models/miq_event_definition_spec.rb +++ b/spec/models/miq_event_definition_spec.rb @@ -125,24 +125,29 @@ def create_set!(name) expect(event.definition).to be_nil end - it "won't update an event with a definition (keyed as a string)" do - described_class.seed_default_events - name = described_class.first.name - attributes = {"name" => name, "definition" => {:event => {:message => "`rm -rf /super/secret/file`"}}} + context 'with defaults in db' do + before do + MiqEventDefinitionSet.seed + described_class.seed_default_events + end - event, = described_class.import_from_hash(attributes) + it "won't update an event with a definition (keyed as a string)" do + name = described_class.first.name + attributes = {"name" => name, "definition" => {:event => {:message => "`rm -rf /super/secret/file`"}}} - expect(event.definition).to be_nil - end + event, = described_class.import_from_hash(attributes) - it "won't update an event with a definition (keyed as a symbol)" do - described_class.seed_default_events - name = described_class.first.name - attributes = {"name" => name, :definition => {:event => {:message => "`rm -rf /super/secret/file`"}}} + expect(event.definition).to be_nil + end - event, = described_class.import_from_hash(attributes) + it "won't update an event with a definition (keyed as a symbol)" do + name = described_class.first.name + attributes = {"name" => name, :definition => {:event => {:message => "`rm -rf /super/secret/file`"}}} - expect(event.definition).to be_nil + event, = described_class.import_from_hash(attributes) + + expect(event.definition).to be_nil + end end end end