Skip to content

Commit

Permalink
Ensure idempotent publishing is automatically enabled in future releases
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Nov 28, 2018
1 parent b80172c commit b8e1a3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/ably/rest/client.rb
Expand Up @@ -135,7 +135,7 @@ class Client
# @option options [Integer] :fallback_retry_timeout (600 seconds) amount of time in seconds a REST client will continue to use a working fallback host when the primary fallback host has previously failed
#
# @option options [Boolean] :add_request_ids (false) When true, adds a unique request_id to each request sent to Ably servers. This is handy when reporting issues, because you can refer to a specific request.
# @option options [Boolean] :idempotent_rest_publishing (false) When true, idempotent publishing is enabled for all messages published via REST
# @option options [Boolean] :idempotent_rest_publishing (false if ver < 1.2) When true, idempotent publishing is enabled for all messages published via REST
#
# @return [Ably::Rest::Client]
#
Expand Down Expand Up @@ -171,7 +171,8 @@ def initialize(options)
@custom_tls_port = options.delete(:tls_port)
@add_request_ids = options.delete(:add_request_ids)
@log_retries_as_info = options.delete(:log_retries_as_info)
@idempotent_rest_publishing = options.delete(:idempotent_rest_publishing)
@idempotent_rest_publishing = options.delete(:idempotent_rest_publishing) || Ably.major_minor_version_numeric > 1.1


if options[:fallback_hosts_use_default] && options[:fallback_jhosts]
raise ArgumentError, "fallback_hosts_use_default cannot be set to trye when fallback_jhosts is also provided"
Expand Down
5 changes: 5 additions & 0 deletions lib/ably/version.rb
Expand Up @@ -13,4 +13,9 @@ def self.lib_variant=(variant)
def self.lib_variant
@lib_variant
end

# @api private
def self.major_minor_version_numeric
VERSION.gsub(/\.\d+$/, '').to_f
end
end
8 changes: 7 additions & 1 deletion spec/acceptance/rest/message_spec.rb
Expand Up @@ -154,11 +154,17 @@
end
end

specify 'idempotent publishing is disabled by default (#TO3n)' do
specify 'idempotent publishing is disabled by default with 1.1 (#TO3n)' do
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'
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
let(:client_options) { default_client_options.merge(idempotent_rest_publishing: true, log_level: :error) }

Expand Down

0 comments on commit b8e1a3a

Please sign in to comment.