added functionality to filter by message

This commit is contained in:
Hannes Staffler 2013-12-13 10:20:20 +01:00
parent a974bd85b3
commit bad17466ee
2 changed files with 12 additions and 0 deletions

View File

@ -31,6 +31,10 @@ module Impressionist
# 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])
if options[:message]
imps = imps.where("impressions.message = ?", options[:message])
end
# Count all distinct impressions unless the :all filter is provided.
distinct = options[:filter] != :all
if Rails::VERSION::MAJOR == 4

View File

@ -17,6 +17,14 @@ describe Impression do
@article.impressions.last.message.should eq "test message"
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
@article.impressionist_count(:filter=>:all).should eq 11
end