Merge pull request #44 from c42engineering/master
Avoid updating updated_at when counter_cache column is updated.
This commit is contained in:
commit
bdd7a05215
|
@ -38,7 +38,8 @@ module Impressionist
|
||||||
cache_options = self.class.impressionist_counter_cache_options
|
cache_options = self.class.impressionist_counter_cache_options
|
||||||
column_name = cache_options[:column_name].to_sym
|
column_name = cache_options[:column_name].to_sym
|
||||||
count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count
|
count = cache_options[:unique] ? impressionist_count(:filter => :ip_address) : impressionist_count
|
||||||
update_attribute(column_name, count)
|
old_count = send(column_name) || 0
|
||||||
|
self.class.update_counters(id, column_name => (count - old_count))
|
||||||
end
|
end
|
||||||
|
|
||||||
# OLD METHODS - DEPRECATE IN V0.5
|
# OLD METHODS - DEPRECATE IN V0.5
|
||||||
|
|
|
@ -38,6 +38,13 @@ describe Impression do
|
||||||
@widget.reload
|
@widget.reload
|
||||||
}.should change(@widget, :impressions_count).from(0).to(1)
|
}.should change(@widget, :impressions_count).from(0).to(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not update the timestamp on the impressable" do
|
||||||
|
lambda {
|
||||||
|
@widget.impressions.create(:request_hash => 'abcd1234')
|
||||||
|
@widget.reload
|
||||||
|
}.should_not change(@widget, :updated_at)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue