lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb in ably-rest-1.0.0 vs lib/submodules/ably-ruby/spec/acceptance/rest/channel_spec.rb in ably-rest-1.0.5

- old
+ new

@@ -254,10 +254,29 @@ end end end end end + + context 'with a non ASCII channel name' do + let(:channel_name) { 'foo:¡€≤`☃' } + let(:channel_name_encoded) { 'foo%3A%C2%A1%E2%82%AC%E2%89%A4%60%E2%98%83' } + let(:endpoint) { client.endpoint } + let(:channel) { client.channels.get(channel_name) } + + context 'stubbed', :webmock do + let!(:get_stub) { + stub_request(:post, "#{endpoint}/channels/#{channel_name_encoded}/publish"). + to_return(:body => '{}', :headers => { 'Content-Type' => 'application/json' }) + } + + it 'correctly encodes the channel name' do + channel.publish('foo') + expect(get_stub).to have_been_requested + end + end + end end describe '#history' do let(:channel) { client.channel("persisted:#{random_str(4)}") } let(:expected_history) do @@ -322,11 +341,17 @@ expect(page_2.items.size).to eql(1) expect(page_2).to_not be_last # Page 3 expect(page_3.items.size).to eql(1) - expect(page_3).to be_last + # This test should be deterministic but it's not. + # Sometimes the backend, to avoid too much work, returns a `next` link that contains empty reults. + if page_3.next + expect(page_3.next.items.length).to eql(0) + else + expect(page_3).to be_last + end end context 'direction' do it 'returns paged history backwards by default' do items = channel.history.items @@ -372,10 +397,10 @@ [:start, :end].each do |option| describe ":#{option}", :webmock do let!(:history_stub) { query_params = default_history_options .merge(option => milliseconds).map { |k, v| "#{k}=#{v}" }.join('&') - stub_request(:get, "#{endpoint}/channels/#{Addressable::URI.encode(channel_name)}/messages?#{query_params}"). + stub_request(:get, "#{endpoint}/channels/#{URI.encode_www_form_component(channel_name)}/messages?#{query_params}"). to_return(:body => '{}', :headers => { 'Content-Type' => 'application/json' }) } before do channel.history(options)