spec/unit/models/presence_message_spec.rb in ably-1.1.6 vs spec/unit/models/presence_message_spec.rb in ably-1.1.7
- old
+ new
@@ -218,9 +218,58 @@
expect(json_object["encoding"]).to eql('base64')
end
end
end
+ describe '#size' do
+ let(:model) { subject.new({ action: 'enter', data: data, client_id: client_id }, protocol_message: protocol_message) }
+
+ context 'String (#TO3l8a)' do
+ let(:data) { 'example string data' }
+ let(:client_id) { '1' }
+
+ it 'should return 20 bytes' do
+ expect(model.size).to eq(20)
+ end
+ end
+
+ context 'Object (#TO3l8b)' do
+ let(:data) { Object.new }
+ let(:client_id) { '10' }
+
+ it 'should return 32 bytes' do
+ expect(model.size).to eq(32)
+ end
+ end
+
+ context 'Array (#TO3l8b)' do
+ let(:data) { [1, 'two', :three] }
+ let(:client_id) { '2' }
+
+ it 'should return 18 bytes' do
+ expect(model.size).to eq(18)
+ end
+ end
+
+ context 'extras (#TO3l8d)' do
+ let(:data) { { example: 'value', score: 1, hash: { test: true } } }
+ let(:client_id) { '3' }
+
+ it 'should return 51 bytes' do
+ expect(model.size).to eq(51)
+ end
+ end
+
+ context 'nil (#TO3l8e)' do
+ let(:data) { nil }
+ let(:client_id) { '4' }
+
+ it 'should return 1 bytes' do
+ expect(model.size).to eq(1)
+ end
+ end
+ end
+
context 'from REST request with embedded fields', :api_private do
let(:id) { random_str }
let(:message_time) { Time.now + 60 }
let(:timestamp) { as_since_epoch(message_time) }
let(:model) { subject.new(id: id, timestamp: timestamp) }