Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid updating updated_at when counter_cache column is updated. #44

Merged
merged 1 commit into from
Jul 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/impressionist/impressionable.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def update_impressionist_counter_cache
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
Expand Down
7 changes: 7 additions & 0 deletions test_app/spec/models/counter_caching_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
@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