diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index c9159bc..ef0b6c8 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -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 diff --git a/tests/test_app/spec/models/model_spec.rb b/tests/test_app/spec/models/model_spec.rb index d0c21e2..40a9e7f 100644 --- a/tests/test_app/spec/models/model_spec.rb +++ b/tests/test_app/spec/models/model_spec.rb @@ -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