Permalink
Browse files

Run RailsMetrics using Rails 3.0.0.beta.

  • Loading branch information...
1 parent e70b379 commit 431fd2ae9c728e657b76f5410c8e257746b4f9c2 @josevalim josevalim committed Feb 8, 2010
View
2 .gitignore
@@ -5,5 +5,5 @@ coverage/*
*.sqlite3
rdoc/*
test/dummy/db/schema.rb
-rails_metrics.gemspec
pkg
+log/*
View
9 Gemfile
@@ -0,0 +1,9 @@
+source :gemcutter
+
+gem "rails", "3.0.0.beta"
+gem "mysql", "2.7"
+gem "webrat", "0.7.0"
+
+if RUBY_VERSION < '1.9'
+ gem "ruby-debug", ">= 0.10.3"
+end
View
38 Rakefile
@@ -1,39 +1,45 @@
# encoding: UTF-8
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-require File.join(File.dirname(__FILE__), 'lib', 'rails_metrics', 'version')
+require "rake"
+require "rake/testtask"
+require "rake/rdoctask"
+require "fileutils"
+require File.expand_path("../lib/rails_metrics/version", __FILE__)
-desc 'Default: run unit tests.'
+desc "Default: run unit tests."
task :default => :test
-desc 'Test RailsMetrics'
+task :prepare do
+ FileUtils.cd File.expand_path("../test/dummy", __FILE__)
+ system("RAILS_ENV=test rake db:create --trace & RAILS_ENV=test rake db:migrate --trace")
+end
+
+desc "Test RailsMetrics"
Rake::TestTask.new(:test) do |t|
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
+ t.libs << "test"
+ t.pattern = "test/**/*_test.rb"
t.verbose = true
end
-desc 'Generate documentation for RailsMetrics'
+desc "Generate documentation for RailsMetrics"
Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'RailsMetrics'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README.rdoc')
- rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_dir = "rdoc"
+ rdoc.title = "RailsMetrics"
+ rdoc.options << "--line-numbers" << "--inline-source"
+ rdoc.rdoc_files.include("README.rdoc")
+ rdoc.rdoc_files.include("lib/**/*.rb")
end
begin
- require 'jeweler'
+ require "jeweler"
Jeweler::Tasks.new do |s|
s.name = "rails_metrics"
s.version = RailsMetrics::VERSION
s.summary = "Metrics measurement for your app on top of ActiveSupport::Notifications"
s.email = "contact@engineyard.com"
s.homepage = "http://github.com/engineyard"
s.description = "Metrics measurement for your app on top of ActiveSupport::Notifications"
- s.authors = ['José Valim']
+ s.authors = ["José Valim"]
s.files = FileList["[A-Z]*", "{app,config,generators,lib}/**/*", "init.rb"]
end
View
2 lib/rails_metrics.rb
@@ -16,7 +16,7 @@ module ORM
end
class << self
- delegate :mute!, :mute_method!, :to => RailsMetrics::Mute
+ delegate :mute!, :mute_instance_method!, :mute_class_method!, :to => RailsMetrics::Mute
end
# Set which store to use in RailsMetrics.
View
9 lib/rails_metrics/mute.rb
@@ -14,9 +14,9 @@ def self.mute!
# Mute a given method in a specified object.
#
- # RailsMetric::Mute.mute_method!(ActiveRecord::Base.connection, :log)
+ # RailsMetric::Mute.mute_instance_method!(ActiveRecord::Base.connection, :log)
#
- def self.mute_method!(object, method)
+ def self.mute_instance_method!(object, method)
object.class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{method}_with_mute!(*args, &block)
RailsMetrics::Mute.mute!{ #{method}_without_mute!(*args, &block) }
@@ -25,6 +25,11 @@ def #{method}_with_mute!(*args, &block)
METHOD
end
+ # The same as mute_instance_method!, but mutes a class method.
+ def self.mute_class_method!(object, method)
+ mute_instance_method!(object.metaclass, method)
+ end
+
# Keeps a blacklist of instrumenters ids.
def self.blacklist
Thread.current[:rails_metrics_blacklist] ||= []
View
2 lib/rails_metrics/orm/active_record.rb
@@ -1,5 +1,5 @@
# Mute migration notifications.
-RailsMetrics.mute_method!(ActiveRecord::Migrator, :migrate)
+RailsMetrics.mute_class_method!(ActiveRecord::Migrator, :migrate)
# Setup to ignore any query which is not a SELECT, INSERT, UPDATE
# or DELETE and queries made by the own store.
View
15 test/dummy/config/application.rb
@@ -1,7 +1,18 @@
require File.expand_path('../boot', __FILE__)
+require "active_model/railtie"
+require "active_record/railtie"
+require "action_controller/railtie"
+require "action_view/railtie"
+require "action_mailer/railtie"
+
+Bundler.require
+require "rails_metrics"
+
module Dummy
class Application < Rails::Application
+ config.root = File.expand_path("../..", __FILE__)
+
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
@@ -35,6 +46,6 @@ class Application < Rails::Application
config.reload_engines = true
# Set RailsMetrics store.
- config.rails_metrics.set_store = lambda { Metric }
+ config.rails_metrics.set_store = lambda { ::Metric }
end
-end
+end
View
22 test/dummy/config/boot.rb
@@ -1,15 +1,9 @@
-require File.expand_path("../../../../rails/.bundle/environment", File.dirname(__FILE__))
-require 'rails/all'
+begin
+ require File.expand_path("../../../../.bundle/environment", __FILE__)
+rescue LoadError
+ require 'rubygems'
+ require 'bundler'
+ Bundler.setup
+end
-$:.unshift File.expand_path('../../../../lib', __FILE__)
-require 'rails_metrics'
-
-# To pick the frameworks you want, remove 'require "rails/all"'
-# and list the framework railties that you want:
-#
-# require "active_model/railtie"
-# require "active_record/railtie"
-# require "action_controller/railtie"
-# require "action_view/railtie"
-# require "action_mailer/railtie"
-# require "active_resource/railtie"
+$:.unshift File.expand_path('../../../../lib', __FILE__)
View
24 test/mute_test.rb
@@ -20,7 +20,7 @@ class MuteTest < ActiveSupport::TestCase
assert_equal "rails_metrics.something", MockStore.instances.last.args[0]
end
- test "mutes a given method for a given class" do
+ test "mutes a given instance method for a given class" do
notifier = Class.new do
def notify
ActiveSupport::Notifications.instrument("rails_metrics.something")
@@ -32,10 +32,30 @@ def notify
assert_equal "rails_metrics.something", MockStore.instances.last.args[0]
MockStore.instances.clear
- RailsMetrics.mute_method!(notifier, :notify)
+ RailsMetrics.mute_instance_method!(notifier, :notify)
notifier.new.notify
wait
assert MockStore.instances.empty?
end
+
+ test "mutes a given class method for a given class" do
+ notifier = Class.new do
+ def self.notify
+ ActiveSupport::Notifications.instrument("rails_metrics.something")
+ end
+ end
+
+ notifier.notify
+ wait
+ assert_equal "rails_metrics.something", MockStore.instances.last.args[0]
+
+ MockStore.instances.clear
+ RailsMetrics.mute_class_method!(notifier, :notify)
+
+ notifier.notify
+ wait
+ assert MockStore.instances.empty?
+ end
+
end
View
15 test/test_helper.rb
@@ -1,22 +1,19 @@
# Configure Rails Envinronment
ENV["RAILS_ENV"] = "test"
-require 'rubygems'
# To test RailsMetrics, you need to:
#
# 1) Install latest bundler with "gem install bundler"
-# 2) Clone rails in git://github.com/rails/rails
-# 3) Ensure rails checkout is in the same directory as rails_metrics' one
-# 4) Bundle rails repository requirements with "bundle install & bundle lock"
-# 5) Go to test/dummy directory and run "rake db:create:all & rake db:migrate"
-# 6) rake test
+# 2) bundle install
+# 3) rake prepare
+# 4) rake test
#
-require File.expand_path("dummy/config/environment.rb", File.dirname(__FILE__))
-require 'rails/test_help'
+require File.expand_path("../dummy/config/environment.rb", __FILE__)
+require "rails/test_help"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
-ActionMailer::Base.default_url_options[:host] = 'test.com'
+ActionMailer::Base.default_url_options[:host] = "test.com"
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

0 comments on commit 431fd2a

Please sign in to comment.