charlotte-ruby / impressionist

Rails Plugin that tracks impressions and page views
MIT License
1.54k stars 313 forks source link

Unique Impressions not working, but counter cache is. #134

Open jarrettgreen opened 10 years ago

jarrettgreen commented 10 years ago

In Show Action:

    @post = PostDecorator.decorate(Post.friendly.find(params[:id]))
    impressionist(@post, request.env['HTTP_USER_AGENT'], :unique => [:impressionable_type, :impressionable_id, :session_hash])

In Model:

  is_impressionable :counter_cache => true, :column_name => :total_impressions

Checking the DB,

screen shot 2013-12-15 at 11 32 47 am

Now the 'total_impressions' counter_cache seems to be working for pulling 'most popular' posts, but I thought the idea behind unique was to not have duplicate DB records. Am I wrong?

alexeckermann commented 9 years ago

I believe I have identified this bug since uncovering it myself. Here is the failing test case with a pretty reasonable expectation, what we have both requested: https://github.com/alexeckermann/impressionist/commit/e180c2844311899eac00c1037881a870e3f6b7fa

Will try and nut out a solution and submit a PR.

alexeckermann commented 9 years ago

https://github.com/alexeckermann/impressionist/commit/169127250acb44e9f6e4f973bf812b6dacd06632 Not exactly a short solution, line wise, but definitely less than an overhaul to track the impressionable as a shared property.

Will that line need some kind of diet before a PR or a different approach?