Skip to content

Commit

Permalink
fix: add type text to updating expression
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPerminov committed Dec 24, 2018
1 parent 9894198 commit 6dd9509
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/redis_counters/dumpers/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
37 changes: 37 additions & 0 deletions spec/lib/redis_counters/dumpers/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6dd9509

Please sign in to comment.