From c89c3d4f78a3a2536e4047acf9af58f9bd68c20e Mon Sep 17 00:00:00 2001 From: Shayon Mukherjee Date: Wed, 31 Aug 2022 12:07:38 -0400 Subject: [PATCH] Use Array#max for @max_length By using using min, we would always get the default MAX_LENGTH, which is 50 if we would want to process more items in buffer. This fix now uses .max, to also align with the variable and constant naming intentions --- lib/mixpanel-ruby/consumer.rb | 2 +- spec/mixpanel-ruby/consumer_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mixpanel-ruby/consumer.rb b/lib/mixpanel-ruby/consumer.rb index 3078f66..006ec1c 100644 --- a/lib/mixpanel-ruby/consumer.rb +++ b/lib/mixpanel-ruby/consumer.rb @@ -183,7 +183,7 @@ class BufferedConsumer # the constructor, the *_endpoint constructor arguments are # ignored. def initialize(events_endpoint=nil, update_endpoint=nil, import_endpoint=nil, max_buffer_length=MAX_LENGTH, &block) - @max_length = [max_buffer_length, MAX_LENGTH].min + @max_length = [max_buffer_length, MAX_LENGTH].max @buffers = { :event => [], :profile_update => [], diff --git a/spec/mixpanel-ruby/consumer_spec.rb b/spec/mixpanel-ruby/consumer_spec.rb index 941f256..2d024e9 100644 --- a/spec/mixpanel-ruby/consumer_spec.rb +++ b/spec/mixpanel-ruby/consumer_spec.rb @@ -104,6 +104,11 @@ def request(*args) context 'Default BufferedConsumer' do subject { Mixpanel::BufferedConsumer.new(nil, nil, nil, max_length) } + it 'should use the max for max_length' do + consumer = Mixpanel::BufferedConsumer.new(nil, nil, nil, 100) + expect(consumer.instance_variable_get(:@max_length)).to eq(100) + end + it 'should not send a request for a single message until flush is called' do stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'}) subject.send!(:event, {'data' => 'TEST EVENT 1'}.to_json)