Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Run RailsMetrics using Rails 3.0.0.beta.

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

0 comments on commit 431fd2a

Please sign in to comment.
Something went wrong with that request. Please try again.