added functionality to filter by message
This commit is contained in:
parent
a974bd85b3
commit
bad17466ee
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue