spec/event_spec.rb in reactor-0.11.4 vs spec/event_spec.rb in reactor-0.12.1
- old
+ new
@@ -27,10 +27,27 @@
describe Reactor::Event do
let(:model) { ArbitraryModel.create! }
let(:event_name) { :user_did_this }
+ describe 'encoding' do
+ let(:event) { Reactor::Event.new(thing_one: "\xAD", thing_two: "\xAB", money: "£900", emoji: "\u{1f4a9}") }
+
+ it 'strips bad characters' do
+ expect(event.thing_one).to eq('')
+ expect(event.thing_two).to eq('')
+ end
+
+ it 'allows valid multibyte UTF8' do
+ expect(event.money).to eq('£900')
+ end
+
+ it 'allows astral plane characters' do
+ expect(event.emoji).to eq("\u{1f4a9}")
+ end
+ end
+
describe 'publish' do
let!(:uuid) { 'uuid' }
before { allow(SecureRandom).to receive(:uuid).and_return(uuid) }
@@ -138,11 +155,11 @@
let(:cat) { MyModule::Cat.create }
let(:arbitrary_model) { ArbitraryModel.create }
let(:event_data) { {random: 'data', pet_id: cat.id, pet_type: cat.class.to_s, arbitrary_model: arbitrary_model } }
let(:event) { Reactor::Event.new(event_data) }
- describe 'data key fallthrough' do
+ describe 'data key interaction with internals' do
subject { event }
describe 'getters' do
context 'basic key value' do
its(:random) { is_expected.to eq('data') }
@@ -150,27 +167,45 @@
context 'foreign key and foreign type' do
its(:pet) { is_expected.to be_a MyModule::Cat }
its('pet.id') { is_expected.to eq(MyModule::Cat.last.id) }
end
+
+ context 'accessing the internal __data__' do
+ its(:__data__) do
+ is_expected.to eq ({
+ 'random' => 'data',
+ 'pet_id' => cat.id,
+ 'pet_type' => 'MyModule::Cat',
+ 'arbitrary_model_id' => arbitrary_model.id,
+ 'arbitrary_model_type' => arbitrary_model.class.name
+ })
+ end
+ end
+
+ context 'a key named "data"' do
+ let(:event_data) { {random: 'data', data: 'info' } }
+ its(:random) { is_expected.to eq('data') }
+ its(:data) { is_expected.to eq 'info' }
+ end
end
describe 'setters' do
it 'sets simple keys' do
event.simple = 'key'
- expect(event.data[:simple]).to eq('key')
+ expect(event.__data__[:simple]).to eq('key')
end
it 'sets active_record polymorphic keys' do
event.complex = cat = MyModule::Cat.create
event.complex_id = cat.id
event.complex_type = cat.class.to_s
end
end
end
- describe 'data' do
- let(:serialized_event) { event.data }
+ describe '__data__' do
+ let(:serialized_event) { event.__data__ }
specify { expect(serialized_event).to be_a Hash }
specify { expect(serialized_event[:random]).to eq('data') }
end
describe 'new' do