Skip to content

Commit 6dd9509

Browse files
committed
fix: add type text to updating expression
https://jira.railsc.ru/browse/CRM-4532
1 parent 9894198 commit 6dd9509

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/redis_counters/dumpers/destination.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def updating_expression
183183
case model.columns_hash[field.to_s].type
184184
when :datetime, :date
185185
"#{field} = source.#{field}"
186-
when :string
186+
when :text, :string
187187
"#{field} = array_to_string(ARRAY[source.#{field}, target.#{field}], '#{delimiter}')"
188188
else
189189
"#{field} = COALESCE(target.#{field}, 0) + source.#{field}"

spec/lib/redis_counters/dumpers/engine_spec.rb

+37
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,43 @@
222222
end
223223
end
224224

225+
context 'when incremented field class is text' do
226+
let(:dumper) do
227+
RedisCounters::Dumpers::Engine.build do
228+
name :realtime_stats
229+
fields record_id: :integer,
230+
column_id: :integer,
231+
value: :integer,
232+
params: :text,
233+
date: :timestamp
234+
235+
destination do
236+
model RealtimeStat
237+
take :record_id, :column_id, :date, :hits, :params
238+
key_fields :record_id, :column_id
239+
increment_fields :hits, :params
240+
map :hits, to: :value
241+
condition 'target.date::date = :date::date'
242+
end
243+
end
244+
end
245+
246+
before do
247+
counter.increment(date: date, record_id: 1, column_id: 100, subject: '', params: 'abc')
248+
dumper.common_params = {date: date, params: 'abc'}
249+
dumper.process!(counter, date: date)
250+
251+
counter.increment(date: date, record_id: 1, column_id: 100, subject: '', params: 'xyz')
252+
dumper.common_params = {date: date, params: 'xyz'}
253+
dumper.process!(counter, date: date)
254+
end
255+
256+
it do
257+
expect(RealtimeStat.count).to eq 1
258+
expect(RealtimeStat.first.params).to eq 'xyz,abc'
259+
end
260+
end
261+
225262
context 'when incremented field class is date or time' do
226263
let(:current_time) { Date.today.to_time }
227264
let(:dumper) do

0 commit comments

Comments
 (0)