From c930ebc559cf9914817809930f3198da6bb8ea4b Mon Sep 17 00:00:00 2001 From: bedrock-adam Date: Sun, 14 Jan 2024 21:18:54 +1100 Subject: [PATCH] complete spec --- spec/outboxer/messageable_spec.rb | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spec/outboxer/messageable_spec.rb diff --git a/spec/outboxer/messageable_spec.rb b/spec/outboxer/messageable_spec.rb new file mode 100644 index 00000000..9f6c1948 --- /dev/null +++ b/spec/outboxer/messageable_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +RSpec.describe Outboxer::Messageable, type: :model do + before(:each) do + ActiveRecord::Schema.define do + create_table :events, force: true do |_t| + end + end + + class Event < ActiveRecord::Base + include Outboxer::Messageable + end + end + + after(:each) do + if ActiveRecord::Base.connection.table_exists?('events') + ActiveRecord::Migration.drop_table('events') + end + + Object.send(:remove_const, :Event) if Object.const_defined?(:Event) + end + + context 'when model created' do + let(:event) { Event.create! } + let(:outboxer_message) { event.outboxer_message } + + it 'creates outboxer message' do + expect(outboxer_message.status).to eq(Outboxer::Models::Message::STATUS[:unpublished]) + expect(outboxer_message.outboxer_messageable_type).to eq(event.class.to_s) + expect(outboxer_message.outboxer_messageable_id).to eq(event.id) + expect(outboxer_message.created_at).to be_present + expect(outboxer_message.updated_at).to be_present + end + end +end