diff --git a/app/models/generic_object.rb b/app/models/generic_object.rb index 5ff22b0f852..1cd9b60692a 100644 --- a/app/models/generic_object.rb +++ b/app/models/generic_object.rb @@ -6,6 +6,7 @@ class GenericObject < ApplicationRecord belongs_to :generic_object_definition has_one :picture, :through => :generic_object_definition + has_many :custom_button_events, -> { where(:type => "CustomButtonEvent") }, :class_name => "EventStream", :foreign_key => :target_id validates :name, :presence => true diff --git a/spec/models/generic_object_spec.rb b/spec/models/generic_object_spec.rb index d975a8d04b1..268b7bac932 100644 --- a/spec/models/generic_object_spec.rb +++ b/spec/models/generic_object_spec.rb @@ -376,5 +376,13 @@ go.custom_action_buttons end end + + describe '#custom_button_events' do + let(:cb_event) { FactoryGirl.create(:custom_button_event, :target => go) } + + it 'returns list of custom button events' do + expect(go.custom_button_events).to match_array([cb_event]) + end + end end end