spec/acceptance/rest/channel_spec.rb in ably-1.1.2 vs spec/acceptance/rest/channel_spec.rb in ably-1.1.3

- old
+ new

@@ -38,11 +38,11 @@ let(:client_id) { random_str } let(:client_options) { default_options.merge(client_id: client_id) } it 'publishes the message without a client_id' do expect(client).to receive(:post). - with("/channels/#{channel_name}/publish", hash_excluding(client_id: client_id)). + with("/channels/#{channel_name}/publish", hash_excluding(client_id: client_id), {}). and_return(double('response', status: 201)) expect(channel.publish(name, data)).to eql(true) end @@ -80,10 +80,48 @@ expect(channel.history.items.map(&:name)).to match_array(messages.map(&:name)) expect(channel.history.items.map(&:data)).to match_array(messages.map(&:data)) end end + context 'with a Message object' do + let(:name) { random_str } + + let(:message) do + Ably::Models::Message(name: name, data: data) + end + + it 'publishes the message' do + expect(client).to receive(:post).once.and_call_original + expect(channel.publish(message)).to eql(true) + expect(channel.history.items.first.name).to eql(name) + end + end + + context 'with a Message object and query params' do + let(:message) do + Ably::Models::Message(name: name, data: data) + end + + it 'should fail to publish the message (RSL1l1)' do + expect(client).to receive(:post).once.and_call_original + expect { channel.publish(message, { _forceNack: 'true' }) }.to raise_error(Ably::Exceptions::InvalidRequest, /40099/) + end + end + + context 'with Messages and query params' do + let(:messages) do + 10.times.map do |index| + { name: index.to_s, data: { "index" => index + 10 } } + end + end + + it 'should fail to publish the message (RSL1l1)' do + expect(client).to receive(:post).once.and_call_original + expect { channel.publish(messages, { _forceNack: 'true' }) }.to raise_error(Ably::Exceptions::InvalidRequest, /40099/) + end + end + context 'without adequate permissions on the channel' do let(:capability) { { onlyChannel: ['subscribe'] } } let(:client_options) { default_options.merge(use_token_auth: true, default_token_params: { capability: capability }) } it 'raises a permission error when publishing' do @@ -94,32 +132,32 @@ context 'null attributes' do context 'when name is null' do let(:data) { random_str } it 'publishes the message without a name attribute in the payload' do - expect(client).to receive(:post).with(anything, { "data" => data }).once.and_call_original + expect(client).to receive(:post).with(anything, { "data" => data }, {}).once.and_call_original expect(channel.publish(nil, data)).to eql(true) expect(channel.history.items.first.name).to be_nil expect(channel.history.items.first.data).to eql(data) end end context 'when data is null' do let(:name) { random_str } it 'publishes the message without a data attribute in the payload' do - expect(client).to receive(:post).with(anything, { "name" => name }).once.and_call_original + expect(client).to receive(:post).with(anything, { "name" => name }, {}).once.and_call_original expect(channel.publish(name)).to eql(true) expect(channel.history.items.first.name).to eql(name) expect(channel.history.items.first.data).to be_nil end end context 'with neither name or data attributes' do let(:name) { random_str } it 'publishes the message without any attributes in the payload' do - expect(client).to receive(:post).with(anything, {}).once.and_call_original + expect(client).to receive(:post).with(anything, {}, {}).once.and_call_original expect(channel.publish(nil)).to eql(true) expect(channel.history.items.first.name).to be_nil expect(channel.history.items.first.data).to be_nil end end