diff --git a/lib/redis_counters/dumpers/destination.rb b/lib/redis_counters/dumpers/destination.rb index c479cb3..97f5090 100644 --- a/lib/redis_counters/dumpers/destination.rb +++ b/lib/redis_counters/dumpers/destination.rb @@ -183,7 +183,7 @@ def updating_expression case model.columns_hash[field.to_s].type when :datetime, :date "#{field} = source.#{field}" - when :string + when :text, :string "#{field} = array_to_string(ARRAY[source.#{field}, target.#{field}], '#{delimiter}')" else "#{field} = COALESCE(target.#{field}, 0) + source.#{field}" diff --git a/spec/lib/redis_counters/dumpers/engine_spec.rb b/spec/lib/redis_counters/dumpers/engine_spec.rb index 7daca1b..193cf1b 100644 --- a/spec/lib/redis_counters/dumpers/engine_spec.rb +++ b/spec/lib/redis_counters/dumpers/engine_spec.rb @@ -222,6 +222,43 @@ end end + context 'when incremented field class is text' do + let(:dumper) do + RedisCounters::Dumpers::Engine.build do + name :realtime_stats + fields record_id: :integer, + column_id: :integer, + value: :integer, + params: :text, + date: :timestamp + + destination do + model RealtimeStat + take :record_id, :column_id, :date, :hits, :params + key_fields :record_id, :column_id + increment_fields :hits, :params + map :hits, to: :value + condition 'target.date::date = :date::date' + end + end + end + + before do + counter.increment(date: date, record_id: 1, column_id: 100, subject: '', params: 'abc') + dumper.common_params = {date: date, params: 'abc'} + dumper.process!(counter, date: date) + + counter.increment(date: date, record_id: 1, column_id: 100, subject: '', params: 'xyz') + dumper.common_params = {date: date, params: 'xyz'} + dumper.process!(counter, date: date) + end + + it do + expect(RealtimeStat.count).to eq 1 + expect(RealtimeStat.first.params).to eq 'xyz,abc' + end + end + context 'when incremented field class is date or time' do let(:current_time) { Date.today.to_time } let(:dumper) do