houdini/spec/models/concerns/model/eventable_spec.rb

42 lines
989 B
Ruby
Raw Normal View History

2021-01-14 18:36:40 +00:00
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
require 'rails_helper'
2021-02-02 21:04:53 +00:00
RSpec.describe Model::Eventable do
2021-01-14 18:36:40 +00:00
let(:event_type) {'model.event_name'}
class ClassWithoutToBuilder
2021-02-02 21:04:53 +00:00
include Model::Eventable
2021-01-14 18:36:40 +00:00
end
class ClassWithToBuilder
2021-02-02 21:04:53 +00:00
include Model::Eventable
2021-01-14 18:36:40 +00:00
def to_builder(*expand)
Jbuilder.new do |json|
json.id 1
end
end
end
it 'raises NotImplementedError when no to_builder is defined by developer' do
obj = ClassWithoutToBuilder.new
expect { obj.to_event event_type}.to raise_error(NotImplementedError)
end
it 'returns an proper event when to_builder is defined by developer' do
obj = ClassWithToBuilder.new
expect(obj.to_event event_type).to eq({
2021-01-21 22:15:24 +00:00
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
2021-01-14 18:36:40 +00:00
'object' => 'object_event',
'type' => event_type,
'data' => {
'object' => {
'id' => 1
}
}
})
end
end