From ff5e76a60bfb21f63f16e7e12c71754ff73d4b41 Mon Sep 17 00:00:00 2001 From: John McAliley Date: Fri, 3 Jun 2011 11:54:58 -0400 Subject: [PATCH] add new method that takes options hash, instead of using ugly method names. fix for postgres select bug upgrades in test_app Gemfile --- app/models/impressionist/impressionable.rb | 18 +- test_app/Gemfile | 36 ++-- test_app/Gemfile.lock | 194 +++++++++++---------- test_app/config/database.yml | 16 +- test_app/config/environments/pg_test.rb | 35 ++++ 5 files changed, 185 insertions(+), 114 deletions(-) create mode 100644 test_app/config/environments/pg_test.rb diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 20abb8f..57accfb 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -10,20 +10,30 @@ module Impressionist true end + def impressionist_count(options={}) + options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) + imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date]) + if options[:filter]!=:all + imps = imps.select(options[:filter]).group(options[:filter]) + end + imps.all.size + end + + # OLD METHODS - DEPRECATE IN V0.5 def impression_count(start_date=nil,end_date=Time.now) - start_date.blank? ? impressions.all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).all.size + impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=>:all}) end def unique_impression_count(start_date=nil,end_date=Time.now) - start_date.blank? ? impressions.group(:request_hash).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:request_hash).all.size + impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :request_hash}) end def unique_impression_count_ip(start_date=nil,end_date=Time.now) - start_date.blank? ? impressions.group(:ip_address).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:ip_address).all.size + impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :ip_address}) end def unique_impression_count_session(start_date=nil,end_date=Time.now) - start_date.blank? ? impressions.group(:session_hash).all.size : impressions.where("created_at>=? and created_at<=?",start_date,end_date).group(:session_hash).all.size + impressionist_count({:start_date=>start_date, :end_date=>end_date, :filter=> :session_hash}) end end end diff --git a/test_app/Gemfile b/test_app/Gemfile index 0be116a..cfc3afe 100644 --- a/test_app/Gemfile +++ b/test_app/Gemfile @@ -1,25 +1,23 @@ source 'http://rubygems.org' -gem 'rails', '3.0.4' +gem 'rails', '3.1.0.rc1' gem 'sqlite3-ruby', :require => 'sqlite3' gem 'impressionist', :path=>"#{File.dirname(__FILE__)}/../" +gem "pg" -if ENV['MY_BUNDLE_ENV'] == "dev" - group :development do - gem 'ZenTest' - gem 'autotest' - gem 'systemu' - gem "rspec" - gem "rspec-rails" - gem "mongrel", "1.2.0.pre2" - gem 'capybara' - gem 'database_cleaner' - gem 'cucumber-rails' - gem 'cucumber' - gem 'spork' - gem 'launchy' - gem 'autotest-notification' - #gem 'ruby-debug19' - end +group :development do + gem 'ZenTest' + gem 'autotest' + gem 'systemu' + gem "rspec" + gem "rspec-rails" + gem "mongrel", "1.2.0.pre2" + gem 'capybara' + gem 'database_cleaner' + gem 'cucumber-rails' + gem 'cucumber' + gem 'spork' + gem 'launchy' + gem 'autotest-notification' + #gem 'ruby-debug19' end - diff --git a/test_app/Gemfile.lock b/test_app/Gemfile.lock index bbae86d..b5676b2 100644 --- a/test_app/Gemfile.lock +++ b/test_app/Gemfile.lock @@ -1,85 +1,86 @@ PATH remote: /rails_plugins/mine/impressionist specs: - impressionist (0.2.5) + impressionist (0.3.2) GEM remote: http://rubygems.org/ specs: - ZenTest (4.4.2) - abstract (1.0.0) - actionmailer (3.0.4) - actionpack (= 3.0.4) - mail (~> 2.2.15) - actionpack (3.0.4) - activemodel (= 3.0.4) - activesupport (= 3.0.4) - builder (~> 2.1.2) - erubis (~> 2.6.6) - i18n (~> 0.4) - rack (~> 1.2.1) - rack-mount (~> 0.6.13) - rack-test (~> 0.5.7) - tzinfo (~> 0.3.23) - activemodel (3.0.4) - activesupport (= 3.0.4) - builder (~> 2.1.2) - i18n (~> 0.4) - activerecord (3.0.4) - activemodel (= 3.0.4) - activesupport (= 3.0.4) - arel (~> 2.0.2) - tzinfo (~> 0.3.23) - activeresource (3.0.4) - activemodel (= 3.0.4) - activesupport (= 3.0.4) - activesupport (3.0.4) - arel (2.0.8) + ZenTest (4.5.0) + actionmailer (3.1.0.rc1) + actionpack (= 3.1.0.rc1) + mail (~> 2.3.0) + actionpack (3.1.0.rc1) + activemodel (= 3.1.0.rc1) + activesupport (= 3.1.0.rc1) + builder (~> 3.0.0) + erubis (~> 2.7.0) + i18n (~> 0.6.0beta1) + rack (~> 1.3.0.beta2) + rack-cache (~> 1.0.1) + rack-mount (~> 0.8.1) + rack-test (~> 0.6.0) + sprockets (~> 2.0.0.beta.5) + tzinfo (~> 0.3.27) + activemodel (3.1.0.rc1) + activesupport (= 3.1.0.rc1) + bcrypt-ruby (~> 2.1.4) + builder (~> 3.0.0) + i18n (~> 0.6.0beta1) + activerecord (3.1.0.rc1) + activemodel (= 3.1.0.rc1) + activesupport (= 3.1.0.rc1) + arel (~> 2.1.1) + tzinfo (~> 0.3.27) + activeresource (3.1.0.rc1) + activemodel (= 3.1.0.rc1) + activesupport (= 3.1.0.rc1) + activesupport (3.1.0.rc1) + multi_json (~> 1.0) + arel (2.1.1) autotest (4.4.6) ZenTest (>= 4.4.1) autotest-notification (2.3.1) autotest (~> 4.3) - builder (2.1.2) - capybara (0.4.1.2) - celerity (>= 0.7.9) - culerity (>= 0.2.4) + bcrypt-ruby (2.1.4) + builder (3.0.0) + capybara (1.0.0.beta1) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) selenium-webdriver (>= 0.0.27) - xpath (~> 0.1.3) - celerity (0.8.7) - childprocess (0.1.6) - ffi (~> 0.6.3) + xpath (~> 0.1.4) + childprocess (0.1.9) + ffi (~> 1.0.6) configuration (1.2.0) - cucumber (0.10.0) + cucumber (0.10.3) builder (>= 2.1.2) - diff-lcs (~> 1.1.2) - gherkin (~> 2.3.2) - json (~> 1.4.6) - term-ansicolor (~> 1.0.5) - cucumber-rails (0.3.2) - cucumber (>= 0.8.0) - culerity (0.2.15) + diff-lcs (>= 1.1.2) + gherkin (>= 2.3.8) + json (>= 1.4.6) + term-ansicolor (>= 1.0.5) + cucumber-rails (0.5.1) + capybara (>= 1.0.0.beta1) + cucumber (>= 0.10.3) + nokogiri (>= 1.4.4) + rack-test (>= 0.5.7) daemons (1.0.10) - database_cleaner (0.6.3) + database_cleaner (0.6.7) diff-lcs (1.1.2) - erubis (2.6.6) - abstract (>= 1.0.0) - ffi (0.6.3) - rake (>= 0.8.7) + erubis (2.7.0) + ffi (1.0.9) gem_plugin (0.2.3) - gherkin (2.3.3) - json (~> 1.4.6) - i18n (0.5.0) - json (1.4.6) + gherkin (2.3.10) + json (>= 1.4.6) + hike (1.0.0) + i18n (0.6.0) + json (1.5.1) json_pure (1.5.1) - launchy (0.3.7) + launchy (0.4.0) configuration (>= 0.0.5) rake (>= 0.8.1) - mail (2.2.15) - activesupport (>= 2.3.6) + mail (2.3.0) i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -87,57 +88,69 @@ GEM mongrel (1.2.0.pre2) daemons (~> 1.0.10) gem_plugin (~> 0.2.3) + multi_json (1.0.3) nokogiri (1.4.4) + pg (0.11.0) polyglot (0.3.1) - rack (1.2.1) - rack-mount (0.6.13) + rack (1.3.0) + rack-cache (1.0.2) + rack (>= 0.4) + rack-mount (0.8.1) rack (>= 1.0.0) - rack-test (0.5.7) + rack-ssl (1.3.2) + rack + rack-test (0.6.0) rack (>= 1.0) - rails (3.0.4) - actionmailer (= 3.0.4) - actionpack (= 3.0.4) - activerecord (= 3.0.4) - activeresource (= 3.0.4) - activesupport (= 3.0.4) + rails (3.1.0.rc1) + actionmailer (= 3.1.0.rc1) + actionpack (= 3.1.0.rc1) + activerecord (= 3.1.0.rc1) + activeresource (= 3.1.0.rc1) + activesupport (= 3.1.0.rc1) bundler (~> 1.0) - railties (= 3.0.4) - railties (3.0.4) - actionpack (= 3.0.4) - activesupport (= 3.0.4) + railties (= 3.1.0.rc1) + railties (3.1.0.rc1) + actionpack (= 3.1.0.rc1) + activesupport (= 3.1.0.rc1) + rack-ssl (~> 1.3.2) rake (>= 0.8.7) - thor (~> 0.14.4) - rake (0.8.7) - rspec (2.5.0) - rspec-core (~> 2.5.0) - rspec-expectations (~> 2.5.0) - rspec-mocks (~> 2.5.0) - rspec-core (2.5.1) - rspec-expectations (2.5.0) + thor (~> 0.14.6) + rake (0.9.1) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.3) + rspec-expectations (2.6.0) diff-lcs (~> 1.1.2) - rspec-mocks (2.5.0) - rspec-rails (2.5.0) + rspec-mocks (2.6.0) + rspec-rails (2.6.1) actionpack (~> 3.0) activesupport (~> 3.0) railties (~> 3.0) - rspec (~> 2.5.0) + rspec (~> 2.6.0) rubyzip (0.9.4) - selenium-webdriver (0.1.2) - childprocess (~> 0.1.5) - ffi (~> 0.6.3) + selenium-webdriver (0.2.1) + childprocess (>= 0.1.7) + ffi (>= 1.0.7) json_pure rubyzip - spork (0.8.4) + spork (0.8.5) + sprockets (2.0.0.beta.9) + hike (~> 1.0) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.3) sqlite3-ruby (1.3.3) sqlite3 (>= 1.3.3) - systemu (1.2.0) + systemu (2.2.0) term-ansicolor (1.0.5) thor (0.14.6) + tilt (1.3.2) treetop (1.4.9) polyglot (>= 0.3.1) - tzinfo (0.3.24) - xpath (0.1.3) + tzinfo (0.3.27) + xpath (0.1.4) nokogiri (~> 1.3) PLATFORMS @@ -154,7 +167,8 @@ DEPENDENCIES impressionist! launchy mongrel (= 1.2.0.pre2) - rails (= 3.0.4) + pg + rails (= 3.1.0.rc1) rspec rspec-rails spork diff --git a/test_app/config/database.yml b/test_app/config/database.yml index 7551340..bccd3e9 100644 --- a/test_app/config/database.yml +++ b/test_app/config/database.yml @@ -9,12 +9,26 @@ development: # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. -test: &test +#test: &test +# adapter: sqlite3 +# database: db/test.sqlite3 +# pool: 5 +# timeout: 5000 + +test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000 +pg_test: + adapter: postgresql + database: impressionist_test + username: johnmcaliley + password: + host: localhost + encoding: UTF8 + production: adapter: sqlite3 database: db/production.sqlite3 diff --git a/test_app/config/environments/pg_test.rb b/test_app/config/environments/pg_test.rb new file mode 100644 index 0000000..d17c1ae --- /dev/null +++ b/test_app/config/environments/pg_test.rb @@ -0,0 +1,35 @@ +TestApp::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Use SQL instead of Active Record's schema dumper when creating the test database. + # This is necessary if your schema can't be completely dumped by the schema dumper, + # like if you have constraints or database-specific column types + # config.active_record.schema_format = :sql + + # Print deprecation notices to the stderr + config.active_support.deprecation = :stderr +end