spec/acceptance/rest/message_spec.rb in ably-1.1.8 vs spec/acceptance/rest/message_spec.rb in ably-1.2.0

- old
+ new

@@ -22,10 +22,61 @@ expect(message.name.encoding).to eql(Encoding::UTF_8) expect(message.name.encode(Encoding::ASCII_8BIT)).to eql(message_name) end end + context 'a single Message object (#RSL1a)' do + let(:name) { random_str } + let(:data) { random_str } + let(:message) { Ably::Models::Message.new(name: name, data: data) } + + it 'publishes the message' do + channel.publish(message) + expect(channel.history.items.length).to eql(1) + message = channel.history.items.first + expect(message.name).to eq(name) + expect(message.data).to eq(data) + end + end + + context 'an array of Message objects (#RSL1a)' do + let(:data) { random_str } + let(:message1) { Ably::Models::Message.new(name: random_str, data: data) } + let(:message2) { Ably::Models::Message.new(name: random_str, data: data) } + let(:message3) { Ably::Models::Message.new(name: random_str, data: data) } + + it 'publishes three messages' do + channel.publish([message1, message2, message3]) + expect(channel.history.items.length).to eql(3) + end + end + + context 'an array of hashes (#RSL1a)' do + let(:data) { random_str } + let(:message1) { { name: random_str, data: data } } + let(:message2) { { name: random_str, data: data } } + let(:message3) { { name: random_str, data: data } } + + it 'publishes three messages' do + channel.publish([message1, message2, message3]) + expect(channel.history.items.length).to eql(3) + end + end + + context 'a name with data payload (#RSL1a, #RSL1b)' do + let(:name) { random_str } + let(:data) { random_str } + + it 'publishes the message' do + channel.publish(name, data) + expect(channel.history.items.length).to eql(1) + message = channel.history.items.first + expect(message.name).to eq(name) + expect(message.data).to eq(data) + end + end + context 'with supported data payload content type' do context 'JSON Object (Hash)' do let(:data) { { 'Hash' => 'true' } } it 'is encoded and decoded to the same hash' do @@ -151,16 +202,23 @@ expect(channel.history.items[0].id).to eql("#{id}:2") expect(channel.history.items.length).to eql(3) end end - specify 'idempotent publishing is disabled by default with 1.1 (#TO3n)' do + specify 'idempotent publishing is disabled by default with <= 1.1 (#TO3n)' do + stub_const 'Ably::PROTOCOL_VERSION', '1.0' client = Ably::Rest::Client.new(key: api_key, protocol: protocol) expect(client.idempotent_rest_publishing).to be_falsey + stub_const 'Ably::PROTOCOL_VERSION', '1.1' + client = Ably::Rest::Client.new(key: api_key, protocol: protocol) + expect(client.idempotent_rest_publishing).to be_falsey end - specify 'idempotent publishing is enabled by default with 1.2 (#TO3n)' do - stub_const 'Ably::VERSION', '1.2.0' + specify 'idempotent publishing is enabled by default with >= 1.2 (#TO3n)' do + stub_const 'Ably::PROTOCOL_VERSION', '1.2' + client = Ably::Rest::Client.new(key: api_key, protocol: protocol) + expect(client.idempotent_rest_publishing).to be_truthy + stub_const 'Ably::PROTOCOL_VERSION', '1.3' client = Ably::Rest::Client.new(key: api_key, protocol: protocol) expect(client.idempotent_rest_publishing).to be_truthy end context 'when idempotent publishing is enabled in the client library ClientOptions (#TO3n)' do