Merge pull request #243 from charlotte-ruby/fix-counter-cache-not-updating
Fix counter cache not updating when no `unique` option is set
This commit is contained in:
commit
dab5ffce83
|
@ -8,7 +8,7 @@ module Impressionist
|
||||||
DEFAULT_CACHE ||= {
|
DEFAULT_CACHE ||= {
|
||||||
:counter_cache => false,
|
:counter_cache => false,
|
||||||
:column_name => :impressions_count,
|
:column_name => :impressions_count,
|
||||||
:unique => false
|
:unique => :all
|
||||||
}
|
}
|
||||||
|
|
||||||
def impressionist_counter_cache_options
|
def impressionist_counter_cache_options
|
||||||
|
|
|
@ -42,9 +42,17 @@ module Impressionist
|
||||||
# is_impressionable :counter_cache => true,
|
# is_impressionable :counter_cache => true,
|
||||||
# :unique => :any_other_filter
|
# :unique => :any_other_filter
|
||||||
def unique_filter
|
def unique_filter
|
||||||
Symbol === unique ?
|
# Support `is_impressionable :counter_cache => true, :unique => true`
|
||||||
unique :
|
# defaulting to `:ip_address` for counting unique impressions.
|
||||||
:ip_address
|
return :ip_address if unique == true
|
||||||
|
|
||||||
|
# Should a user try `is_impressionable :counter_cache => true, :unique => false`
|
||||||
|
# then support that as well
|
||||||
|
return :all if unique == false
|
||||||
|
|
||||||
|
# Otherwise set the filter to either what the user supplied as the `unique` option
|
||||||
|
# or the default (`:all`)
|
||||||
|
unique
|
||||||
end
|
end
|
||||||
|
|
||||||
def unique
|
def unique
|
||||||
|
|
Loading…
Reference in New Issue