Merge pull request #133 from overovermind/master
Add functionality to count only specific messages
This commit is contained in:
commit
c8ed56b365
|
@ -124,6 +124,10 @@ Usage
|
||||||
|
|
||||||
@widget.impressionist_count(:filter=>:all)
|
@widget.impressionist_count(:filter=>:all)
|
||||||
|
|
||||||
|
9. Get impression count by message. This only counts impressions of the given message.
|
||||||
|
|
||||||
|
@widget.impressionist_count(:message=>"pageview", :filter=>:all)
|
||||||
|
|
||||||
Logging impressions for authenticated users happens automatically. If you have
|
Logging impressions for authenticated users happens automatically. If you have
|
||||||
a current_user helper or use @current_user in your before_filter to set your
|
a current_user helper or use @current_user in your before_filter to set your
|
||||||
authenticated user, current_user.id will be written to the user_id field in the
|
authenticated user, current_user.id will be written to the user_id field in the
|
||||||
|
|
|
@ -31,6 +31,10 @@ module Impressionist
|
||||||
# If a start_date is provided, finds impressions between then and the end_date. Otherwise returns all impressions
|
# If a start_date is provided, finds impressions between then and the end_date. Otherwise returns all impressions
|
||||||
imps = options[:start_date].blank? ? impressions : impressions.where("created_at >= ? and created_at <= ?", options[:start_date], options[:end_date])
|
imps = options[:start_date].blank? ? impressions : impressions.where("created_at >= ? and created_at <= ?", options[:start_date], options[:end_date])
|
||||||
|
|
||||||
|
if options[:message]
|
||||||
|
imps = imps.where("impressions.message = ?", options[:message])
|
||||||
|
end
|
||||||
|
|
||||||
# Count all distinct impressions unless the :all filter is provided.
|
# Count all distinct impressions unless the :all filter is provided.
|
||||||
distinct = options[:filter] != :all
|
distinct = options[:filter] != :all
|
||||||
if Rails::VERSION::MAJOR == 4
|
if Rails::VERSION::MAJOR == 4
|
||||||
|
|
|
@ -17,6 +17,14 @@ describe Impression do
|
||||||
@article.impressions.last.message.should eq "test message"
|
@article.impressions.last.message.should eq "test message"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should return the impression count for the message specified" do
|
||||||
|
@article.impressions.create(:message => "pageview")
|
||||||
|
@article.impressions.create(:message => "pageview")
|
||||||
|
@article.impressions.create(:message => "visit")
|
||||||
|
|
||||||
|
@article.impressionist_count(:message => "pageview", :filter => :all).should eq 2
|
||||||
|
end
|
||||||
|
|
||||||
it "should return the impression count for all with no date range specified" do
|
it "should return the impression count for all with no date range specified" do
|
||||||
@article.impressionist_count(:filter=>:all).should eq 11
|
@article.impressionist_count(:filter=>:all).should eq 11
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue