Create HoudIDs for stringy ids
This commit is contained in:
parent
a7a4ce1f50
commit
e806d8764f
16 changed files with 71 additions and 44 deletions
|
@ -4,7 +4,7 @@
|
|||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class CampaignGiftOption < ApplicationRecord
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :cgo
|
||||
# :amount_one_time, #int (cents)
|
||||
# :amount_recurring, #int (cents)
|
||||
# :amount_dollars, #str, gets converted to amount
|
||||
|
|
|
@ -4,14 +4,21 @@
|
|||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
module ObjectEvent::ModelExtensions
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
|
||||
# Adds the to_event method to a model. Requires `to_builder` method for creating
|
||||
# the Jbuilder object
|
||||
def object_eventable
|
||||
def object_eventable(prefix)
|
||||
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||
def object_prefix
|
||||
:#{prefix.to_s}
|
||||
end
|
||||
|
||||
|
||||
def to_event(event_type, *expand)
|
||||
Jbuilder.new do |event|
|
||||
event.id SecureRandom.uuid
|
||||
event.id "objevt_" + SecureRandom.alphanumeric(22)
|
||||
event.object 'object_event'
|
||||
event.type event_type
|
||||
event.data do
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class EventDiscount < ApplicationRecord
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :evtdisc
|
||||
# :code,
|
||||
# :event_id,
|
||||
# :name,
|
||||
|
|
|
@ -180,7 +180,7 @@ class Supporter < ApplicationRecord
|
|||
# we do something custom here since Supporter and SupporterAddress are in the same model
|
||||
def to_event(event_type, *expand)
|
||||
Jbuilder.new do |event|
|
||||
event.id SecureRandom.uuid
|
||||
event.id "objevt_" + SecureRandom.alphanumeric(22)
|
||||
event.object 'object_event'
|
||||
event.type event_type
|
||||
event.data do
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class SupporterNote < ApplicationRecord
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :suppnote
|
||||
# :content,
|
||||
# :supporter_id, :supporter
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class TagMaster < ApplicationRecord
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :tagmstr
|
||||
# TODO replace with Discard gem
|
||||
define_model_callbacks :discard
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
||||
class TicketLevel < ApplicationRecord
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :tktlvl
|
||||
# :amount, #integer
|
||||
# :amount_dollars, #accessor, string
|
||||
# :name, #string
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// License: LGPL-3.0-or-later
|
||||
import type { Amount, HoudiniObject, IdType, UuidType } from "../common";
|
||||
import type { Amount, HoudiniObject, IdType, HoudID } from "../common";
|
||||
import type Nonprofit from './';
|
||||
|
||||
|
||||
export interface Transaction extends HoudiniObject<UuidType> {
|
||||
export interface Transaction extends HoudiniObject<HoudID> {
|
||||
amount: Amount;
|
||||
nonprofit: IdType | Nonprofit;
|
||||
object: 'transaction';
|
||||
|
|
|
@ -9,7 +9,7 @@ export type IdType = number;
|
|||
/**
|
||||
* an identifier for HoudiniObjects which is unique among all HoudiniObjects.
|
||||
*/
|
||||
export type UuidType = string;
|
||||
export type HoudID = string;
|
||||
|
||||
/**
|
||||
* Describes a monetary value in the minimum unit for this current. Corresponds to Money class in
|
||||
|
@ -60,7 +60,7 @@ export type RecurrenceRule = {
|
|||
* Every object controlled by the Houdini event publisher must meet this standard interface
|
||||
* and will inherit from it.
|
||||
*/
|
||||
export interface HoudiniObject<Id extends IdType|UuidType=IdType> {
|
||||
export interface HoudiniObject<Id extends IdType|HoudID=IdType> {
|
||||
/**
|
||||
* An IdType which unique which uniquely identifies this object
|
||||
* from all other similar objects
|
||||
|
@ -73,7 +73,7 @@ export interface HoudiniObject<Id extends IdType|UuidType=IdType> {
|
|||
}
|
||||
|
||||
|
||||
type HoudiniObjectOfAllIds = HoudiniObject<IdType> | HoudiniObject<UuidType>;
|
||||
type HoudiniObjectOfAllIds = HoudiniObject<IdType> | HoudiniObject<HoudID>;
|
||||
/**
|
||||
* An event published by Houdini
|
||||
*
|
||||
|
@ -90,9 +90,9 @@ export interface HoudiniEvent<EventType extends string, DataObject extends Houdi
|
|||
object: DataObject;
|
||||
};
|
||||
/**
|
||||
* A UUID uniquely representing the event
|
||||
* A HoudID uniquely representing the event
|
||||
*/
|
||||
id: string;
|
||||
id: HoudID;
|
||||
object: 'object_event';
|
||||
/** The type of event that this is */
|
||||
type: EventType;
|
||||
|
|
|
@ -43,7 +43,7 @@ RSpec.describe CampaignGiftOption, type: :model do
|
|||
it 'announces create for first example' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'campaign_gift_option.created',
|
||||
'data' => {
|
||||
|
@ -84,7 +84,7 @@ RSpec.describe CampaignGiftOption, type: :model do
|
|||
it 'announces create for second example' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'campaign_gift_option.created',
|
||||
'data' => {
|
||||
|
@ -146,7 +146,7 @@ RSpec.describe CampaignGiftOption, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'campaign_gift_option.updated',
|
||||
'data' => {
|
||||
|
@ -191,7 +191,7 @@ RSpec.describe CampaignGiftOption, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'campaign_gift_option.updated',
|
||||
'data' => {
|
||||
|
@ -238,7 +238,7 @@ RSpec.describe CampaignGiftOption, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'campaign_gift_option.deleted',
|
||||
'data' => {
|
||||
|
@ -285,7 +285,7 @@ RSpec.describe CampaignGiftOption, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_create, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:campaign_gift_option_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'campaign_gift_option.deleted',
|
||||
'data' => {
|
||||
|
|
|
@ -9,12 +9,12 @@ RSpec.describe ObjectEvent::ModelExtensions do
|
|||
let(:event_type) {'model.event_name'}
|
||||
class ClassWithoutToBuilder
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :cwotb
|
||||
end
|
||||
|
||||
class ClassWithToBuilder
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
object_eventable :cwtb
|
||||
|
||||
def to_builder(*expand)
|
||||
Jbuilder.new do |json|
|
||||
|
@ -23,15 +23,19 @@ RSpec.describe ObjectEvent::ModelExtensions do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
it 'raises NotImplementedError when no to_builder is defined by developer' do
|
||||
obj = ClassWithoutToBuilder.new
|
||||
expect(obj.object_prefix).to eq :cwotb
|
||||
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.object_prefix).to eq :cwtb
|
||||
expect(obj.to_event event_type).to eq({
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => event_type,
|
||||
'data' => {
|
||||
|
@ -41,4 +45,19 @@ RSpec.describe ObjectEvent::ModelExtensions do
|
|||
}
|
||||
})
|
||||
end
|
||||
|
||||
it 'raises without object_prefix' do
|
||||
expect do
|
||||
class ClassWithoutEventablePrefix
|
||||
include ObjectEvent::ModelExtensions
|
||||
object_eventable
|
||||
|
||||
def to_builder(*expand)
|
||||
Jbuilder.new do |json|
|
||||
json.id 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end.to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
|
@ -54,7 +54,7 @@ RSpec.describe EventDiscount, type: :model do
|
|||
it 'announces create' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:event_discount_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'event_discount.created',
|
||||
'data' => {
|
||||
|
@ -116,7 +116,7 @@ RSpec.describe EventDiscount, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:event_discount_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:event_discount_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'event_discount.updated',
|
||||
'data' => {
|
||||
|
@ -179,7 +179,7 @@ RSpec.describe EventDiscount, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:event_discount_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:event_discount_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'event_discount.deleted',
|
||||
'data' => {
|
||||
|
|
|
@ -34,7 +34,7 @@ RSpec.describe SupporterNote, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter_note.created',
|
||||
'data' => {
|
||||
|
@ -65,7 +65,7 @@ RSpec.describe SupporterNote, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter_note.updated',
|
||||
'data' => {
|
||||
|
@ -98,7 +98,7 @@ RSpec.describe SupporterNote, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything)
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_note_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter_note.deleted',
|
||||
'data' => {
|
||||
|
|
|
@ -61,7 +61,7 @@ RSpec.describe Supporter, type: :model do
|
|||
})
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter.created',
|
||||
'data' => {
|
||||
|
@ -89,7 +89,7 @@ RSpec.describe Supporter, type: :model do
|
|||
})
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter.deleted',
|
||||
'data' => {
|
||||
|
@ -111,7 +111,7 @@ RSpec.describe Supporter, type: :model do
|
|||
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter_address.created',
|
||||
'data' => {
|
||||
|
@ -139,7 +139,7 @@ RSpec.describe Supporter, type: :model do
|
|||
})
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter_address.deleted',
|
||||
'data' => {
|
||||
|
@ -157,7 +157,8 @@ RSpec.describe Supporter, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything).ordered
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_updated, { 'id' => kind_of(String),
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_updated, {
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter.updated',
|
||||
'data' => {
|
||||
|
@ -180,7 +181,7 @@ RSpec.describe Supporter, type: :model do
|
|||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_created, anything).ordered
|
||||
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:supporter_address_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'supporter_address.updated',
|
||||
'data' => {
|
||||
|
|
|
@ -15,7 +15,7 @@ RSpec.describe TagMaster, type: :model do
|
|||
|
||||
it 'announces create' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:tag_master_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'tag_master.created',
|
||||
'data' => {
|
||||
|
@ -35,7 +35,7 @@ RSpec.describe TagMaster, type: :model do
|
|||
it 'announces deleted' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:tag_master_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:tag_master_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'tag_master.deleted',
|
||||
'data' => {
|
||||
|
|
|
@ -44,7 +44,7 @@ RSpec.describe TicketLevel, type: :model do
|
|||
|
||||
it 'announces create' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'ticket_level.created',
|
||||
'data' => {
|
||||
|
@ -85,7 +85,7 @@ RSpec.describe TicketLevel, type: :model do
|
|||
|
||||
it 'announces create' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'ticket_level.created',
|
||||
'data' => {
|
||||
|
@ -131,7 +131,7 @@ RSpec.describe TicketLevel, type: :model do
|
|||
it 'announces updated' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'ticket_level.updated',
|
||||
'data' => {
|
||||
|
@ -177,7 +177,7 @@ RSpec.describe TicketLevel, type: :model do
|
|||
it 'announces updated' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_updated, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'ticket_level.updated',
|
||||
'data' => {
|
||||
|
@ -226,7 +226,7 @@ RSpec.describe TicketLevel, type: :model do
|
|||
it 'announces deleted' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'ticket_level.deleted',
|
||||
'data' => {
|
||||
|
@ -268,7 +268,7 @@ RSpec.describe TicketLevel, type: :model do
|
|||
it 'announces deleted' do
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_created, anything).ordered
|
||||
expect(Houdini.event_publisher).to receive(:announce).with(:ticket_level_deleted, {
|
||||
'id' => kind_of(String),
|
||||
'id' => match(/objevt_[a-zA-Z0-9]{22}/),
|
||||
'object' => 'object_event',
|
||||
'type' => 'ticket_level.deleted',
|
||||
'data' => {
|
||||
|
|
Loading…
Reference in a new issue