query_diet 0.5.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +86 -0
- data/lib/query_diet/active_record_ext.rb +6 -8
- data/lib/query_diet/rack/reset_logger.rb +2 -2
- data/lib/query_diet/version.rb +1 -1
- data/lib/query_diet/widget.rb +20 -5
- metadata +22 -172
- data/.gitignore +0 -4
- data/README.rdoc +0 -56
- data/Rakefile +0 -44
- data/query_diet.gemspec +0 -22
- data/spec/rails-2.3/Gemfile +0 -9
- data/spec/rails-2.3/Gemfile.lock +0 -60
- data/spec/rails-2.3/Rakefile +0 -11
- data/spec/rails-2.3/app_root/config/boot.rb +0 -114
- data/spec/rails-2.3/app_root/config/database.yml +0 -4
- data/spec/rails-2.3/app_root/config/environment.rb +0 -14
- data/spec/rails-2.3/app_root/config/environments/test.rb +0 -0
- data/spec/rails-2.3/app_root/config/routes.rb +0 -4
- data/spec/rails-2.3/app_root/log/.gitignore +0 -1
- data/spec/rails-2.3/spec.opts +0 -5
- data/spec/rails-2.3/spec_helper.rb +0 -27
- data/spec/rails-3.0/.rspec +0 -2
- data/spec/rails-3.0/Gemfile +0 -9
- data/spec/rails-3.0/Gemfile.lock +0 -116
- data/spec/rails-3.0/Rakefile +0 -10
- data/spec/rails-3.0/app_root/.gitignore +0 -4
- data/spec/rails-3.0/app_root/config/application.rb +0 -32
- data/spec/rails-3.0/app_root/config/boot.rb +0 -13
- data/spec/rails-3.0/app_root/config/database.yml +0 -4
- data/spec/rails-3.0/app_root/config/environment.rb +0 -5
- data/spec/rails-3.0/app_root/config/environments/test.rb +0 -35
- data/spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails-3.0/app_root/config/initializers/inflections.rb +0 -10
- data/spec/rails-3.0/app_root/config/initializers/mime_types.rb +0 -5
- data/spec/rails-3.0/app_root/config/initializers/secret_token.rb +0 -7
- data/spec/rails-3.0/app_root/config/initializers/session_store.rb +0 -8
- data/spec/rails-3.0/app_root/config/routes.rb +0 -58
- data/spec/rails-3.0/app_root/lib/tasks/.gitkeep +0 -0
- data/spec/rails-3.0/app_root/log/.gitkeep +0 -0
- data/spec/rails-3.0/app_root/script/rails +0 -6
- data/spec/rails-3.0/rcov.opts +0 -2
- data/spec/rails-3.0/spec_helper.rb +0 -31
- data/spec/rails-3.2/.rspec +0 -2
- data/spec/rails-3.2/Gemfile +0 -10
- data/spec/rails-3.2/Gemfile.lock +0 -127
- data/spec/rails-3.2/Rakefile +0 -10
- data/spec/rails-3.2/app_root/.gitignore +0 -4
- data/spec/rails-3.2/app_root/config/application.rb +0 -32
- data/spec/rails-3.2/app_root/config/boot.rb +0 -13
- data/spec/rails-3.2/app_root/config/database.yml +0 -4
- data/spec/rails-3.2/app_root/config/environment.rb +0 -5
- data/spec/rails-3.2/app_root/config/environments/test.rb +0 -35
- data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails-3.2/app_root/config/initializers/inflections.rb +0 -10
- data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +0 -5
- data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +0 -7
- data/spec/rails-3.2/app_root/config/initializers/session_store.rb +0 -8
- data/spec/rails-3.2/app_root/config/routes.rb +0 -58
- data/spec/rails-3.2/app_root/log/.gitignore +0 -1
- data/spec/rails-3.2/rcov.opts +0 -2
- data/spec/rails-3.2/spec_helper.rb +0 -31
- data/spec/shared/app_root/app/controllers/application_controller.rb +0 -2
- data/spec/shared/app_root/app/controllers/query_diet_controller.rb +0 -13
- data/spec/shared/app_root/app/models/movie.rb +0 -3
- data/spec/shared/app_root/app/views/layouts/screen.html.erb +0 -7
- data/spec/shared/app_root/app/views/query_diet/no_query.html.erb +0 -3
- data/spec/shared/app_root/app/views/query_diet/two_queries.html.erb +0 -3
- data/spec/shared/app_root/db/.gitignore +0 -1
- data/spec/shared/app_root/db/migrate/001_create_movies.rb +0 -14
- data/spec/shared/query_diet/helpers/widget_spec.rb +0 -32
- data/spec/shared/query_diet/integration/widget_spec.rb +0 -23
- data/spec/shared/query_diet/logger_spec.rb +0 -91
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
# Set up gems listed in the Gemfile.
|
4
|
-
gemfile = File.expand_path('../../Gemfile', __FILE__)
|
5
|
-
begin
|
6
|
-
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
-
require 'bundler'
|
8
|
-
Bundler.setup
|
9
|
-
rescue Bundler::GemNotFound => e
|
10
|
-
STDERR.puts e.message
|
11
|
-
STDERR.puts "Try running `bundle install`."
|
12
|
-
exit!
|
13
|
-
end if File.exist?(gemfile)
|
@@ -1,35 +0,0 @@
|
|
1
|
-
HasDefaultSpecApp::Application.configure do
|
2
|
-
# Settings specified here will take precedence over those in config/application.rb
|
3
|
-
|
4
|
-
# The test environment is used exclusively to run your application's
|
5
|
-
# test suite. You never need to work with it otherwise. Remember that
|
6
|
-
# your test database is "scratch space" for the test suite and is wiped
|
7
|
-
# and recreated between test runs. Don't rely on the data there!
|
8
|
-
config.cache_classes = true
|
9
|
-
|
10
|
-
# Log error messages when you accidentally call methods on nil.
|
11
|
-
config.whiny_nils = true
|
12
|
-
|
13
|
-
# Show full error reports and disable caching
|
14
|
-
config.consider_all_requests_local = true
|
15
|
-
config.action_controller.perform_caching = false
|
16
|
-
|
17
|
-
# Raise exceptions instead of rendering exception templates
|
18
|
-
config.action_dispatch.show_exceptions = false
|
19
|
-
|
20
|
-
# Disable request forgery protection in test environment
|
21
|
-
config.action_controller.allow_forgery_protection = false
|
22
|
-
|
23
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
-
# The :test delivery method accumulates sent emails in the
|
25
|
-
# ActionMailer::Base.deliveries array.
|
26
|
-
config.action_mailer.delivery_method = :test
|
27
|
-
|
28
|
-
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
-
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
-
# like if you have constraints or database-specific column types
|
31
|
-
# config.active_record.schema_format = :sql
|
32
|
-
|
33
|
-
# Print deprecation notices to the stderr
|
34
|
-
config.active_support.deprecation = :stderr
|
35
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
-
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
-
|
6
|
-
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
-
# Rails.backtrace_cleaner.remove_silencers!
|
@@ -1,10 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Add new inflection rules using the following format
|
4
|
-
# (all these examples are active by default):
|
5
|
-
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
-
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
-
# inflect.singular /^(ox)en/i, '\1'
|
8
|
-
# inflect.irregular 'person', 'people'
|
9
|
-
# inflect.uncountable %w( fish sheep )
|
10
|
-
# end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
# Your secret key for verifying the integrity of signed cookies.
|
4
|
-
# If you change this key, all old signed cookies will become invalid!
|
5
|
-
# Make sure the secret is at least 30 characters and all random,
|
6
|
-
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
HasDefaultSpecApp::Application.config.secret_token = 'cb014a08a45243e7143f31e04774c342c1fba329fd594ae1a480d8283b1a851f425dc08044311fb4be6d000b6e6681de7c76d19148419a5ffa0a9f84556d3b33'
|
@@ -1,8 +0,0 @@
|
|
1
|
-
# Be sure to restart your server when you modify this file.
|
2
|
-
|
3
|
-
HasDefaultSpecApp::Application.config.session_store :cookie_store, :key => '_app_root_session'
|
4
|
-
|
5
|
-
# Use the database for sessions instead of the cookie-based default,
|
6
|
-
# which shouldn't be used to store highly confidential information
|
7
|
-
# (create the session table with "rails generate session_migration")
|
8
|
-
# HasDefaultSpecApp::Application.config.session_store :active_record_store
|
@@ -1,58 +0,0 @@
|
|
1
|
-
HasDefaultSpecApp::Application.routes.draw do
|
2
|
-
# The priority is based upon order of creation:
|
3
|
-
# first created -> highest priority.
|
4
|
-
|
5
|
-
# Sample of regular route:
|
6
|
-
# match 'products/:id' => 'catalog#view'
|
7
|
-
# Keep in mind you can assign values other than :controller and :action
|
8
|
-
|
9
|
-
# Sample of named route:
|
10
|
-
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
-
|
13
|
-
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
-
# resources :products
|
15
|
-
|
16
|
-
# Sample resource route with options:
|
17
|
-
# resources :products do
|
18
|
-
# member do
|
19
|
-
# get 'short'
|
20
|
-
# post 'toggle'
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# collection do
|
24
|
-
# get 'sold'
|
25
|
-
# end
|
26
|
-
# end
|
27
|
-
|
28
|
-
# Sample resource route with sub-resources:
|
29
|
-
# resources :products do
|
30
|
-
# resources :comments, :sales
|
31
|
-
# resource :seller
|
32
|
-
# end
|
33
|
-
|
34
|
-
# Sample resource route with more complex sub-resources
|
35
|
-
# resources :products do
|
36
|
-
# resources :comments
|
37
|
-
# resources :sales do
|
38
|
-
# get 'recent', :on => :collection
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
|
42
|
-
# Sample resource route within a namespace:
|
43
|
-
# namespace :admin do
|
44
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
-
# # (app/controllers/admin/products_controller.rb)
|
46
|
-
# resources :products
|
47
|
-
# end
|
48
|
-
|
49
|
-
# You can have the root of your site routed with "root"
|
50
|
-
# just remember to delete public/index.html.
|
51
|
-
# root :to => "welcome#index"
|
52
|
-
|
53
|
-
# See how all your routes lay out with "rake routes"
|
54
|
-
|
55
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
56
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
57
|
-
match ':controller(/:action(/:id(.:format)))'
|
58
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
*.log
|
data/spec/rails-3.2/rcov.opts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
$: << File.join(File.dirname(__FILE__), "/../lib" )
|
2
|
-
|
3
|
-
# Set the default environment to sqlite3's in_memory database
|
4
|
-
ENV['RAILS_ENV'] ||= 'test'
|
5
|
-
ENV['RAILS_ROOT'] = 'app_root'
|
6
|
-
|
7
|
-
# Load the Rails environment and testing framework
|
8
|
-
require "#{File.dirname(__FILE__)}/app_root/config/environment"
|
9
|
-
require 'rspec/rails'
|
10
|
-
require 'database_cleaner'
|
11
|
-
|
12
|
-
FileUtils.rm(Dir.glob("#{Rails.root}/db/*.db"), :force => true)
|
13
|
-
|
14
|
-
# Run the migrations
|
15
|
-
print "\033[30m" # dark gray text
|
16
|
-
ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
|
17
|
-
print "\033[0m"
|
18
|
-
|
19
|
-
# For some reason the first time the SqliteAdapter fetches schema information it
|
20
|
-
# raises an error
|
21
|
-
Movie.create rescue nil
|
22
|
-
|
23
|
-
# Movie.reset_column_information
|
24
|
-
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.use_transactional_fixtures = false
|
27
|
-
config.use_instantiated_fixtures = false
|
28
|
-
config.before(:each) do
|
29
|
-
DatabaseCleaner.clean
|
30
|
-
end
|
31
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
*.db
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe QueryDiet::Widget::Helper, :type => :helper do
|
4
|
-
|
5
|
-
it "should be highlighted if the request was too intimate with the database" do
|
6
|
-
QueryDiet::Logger.stub :bad? => true
|
7
|
-
helper.query_diet_widget.should have_selector('div#query_diet.bad')
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should not be highlighted if the request spent little time in the database" do
|
11
|
-
QueryDiet::Logger.stub :bad? => false
|
12
|
-
helper.query_diet_widget.should have_selector('div#query_diet.good')
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should contain the number of requests and the duration spent running queries" do
|
16
|
-
QueryDiet::Logger.stub :count => 78, :time => 43500
|
17
|
-
helper.query_diet_widget.should have_selector('div#query_diet', :content => "78 / 43500ms")
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should allow to set the request threshold' do
|
21
|
-
QueryDiet::Logger.stub :count => 4, :time => 1000
|
22
|
-
helper.query_diet_widget.should have_selector('div#query_diet.good')
|
23
|
-
helper.query_diet_widget(:bad_count => 3).should have_selector('div#query_diet.bad')
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should allow to set the request threshold' do
|
27
|
-
QueryDiet::Logger.stub :count => 2, :time => 3000
|
28
|
-
helper.query_diet_widget.should have_selector('div#query_diet.good')
|
29
|
-
helper.query_diet_widget(:bad_time => 2000).should have_selector('div#query_diet.bad')
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'The widget', :type => defined?(RSpec) ? :request : :integration do
|
4
|
-
|
5
|
-
it "should be included via a helper" do
|
6
|
-
get 'query_diet/two_queries'
|
7
|
-
response.should have_selector('div#query_diet')
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should show the correct number of queries' do
|
11
|
-
get 'query_diet/no_query'
|
12
|
-
response.should have_selector('#query_diet', :content => '0 /')
|
13
|
-
get 'query_diet/two_queries'
|
14
|
-
response.should have_selector('#query_diet', :content => '2 /')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should reset the queries after each request' do
|
18
|
-
get 'query_diet/two_queries'
|
19
|
-
get 'query_diet/two_queries'
|
20
|
-
response.should have_selector('#query_diet', :content => '2 /')
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe QueryDiet::Logger do
|
4
|
-
|
5
|
-
before do
|
6
|
-
QueryDiet::Logger.reset
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "#reset" do
|
10
|
-
it "should reset count/time/queries" do
|
11
|
-
QueryDiet::Logger.count.should == 0
|
12
|
-
QueryDiet::Logger.time.should == 0
|
13
|
-
QueryDiet::Logger.queries.should == []
|
14
|
-
|
15
|
-
Benchmark.should_receive(:realtime).at_least(:once).and_return(5)
|
16
|
-
Movie.create
|
17
|
-
|
18
|
-
QueryDiet::Logger.count.should > 0
|
19
|
-
QueryDiet::Logger.time.should > 0
|
20
|
-
QueryDiet::Logger.queries.size.should > 0
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#count" do
|
25
|
-
it "should return the number of queries since the last reset" do
|
26
|
-
Movie.create
|
27
|
-
Movie.create
|
28
|
-
QueryDiet::Logger.count.should == 2
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#time" do
|
33
|
-
it "should return the number of miliseconds spent running database queries since the last reset" do
|
34
|
-
Benchmark.should_receive(:realtime).at_least(:once).and_return(5)
|
35
|
-
Movie.create
|
36
|
-
QueryDiet::Logger.time.should == 5000
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "#queries" do
|
41
|
-
it "should return the queries since last reset" do
|
42
|
-
Benchmark.should_receive(:realtime).at_least(:once).and_return(5.1234)
|
43
|
-
Movie.create
|
44
|
-
QueryDiet::Logger.queries.size.should == 1
|
45
|
-
query = QueryDiet::Logger.queries.first
|
46
|
-
query.size.should == 2
|
47
|
-
query[0].should include("INSERT INTO \"movies\"")
|
48
|
-
query[1].should == 5.1234
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "#paused" do
|
53
|
-
|
54
|
-
after :each do
|
55
|
-
QueryDiet::Logger.paused = false
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should be false by default" do
|
59
|
-
QueryDiet::Logger.paused.should be_false
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should pause the query count" do
|
63
|
-
Movie.create
|
64
|
-
Movie.create
|
65
|
-
QueryDiet::Logger.count.should == 2
|
66
|
-
|
67
|
-
QueryDiet::Logger.paused = true
|
68
|
-
Movie.create
|
69
|
-
QueryDiet::Logger.count.should == 2
|
70
|
-
|
71
|
-
QueryDiet::Logger.paused = false
|
72
|
-
Movie.create
|
73
|
-
QueryDiet::Logger.count.should == 3
|
74
|
-
end
|
75
|
-
|
76
|
-
# regression
|
77
|
-
it "should still execute queries if paused" do
|
78
|
-
Movie.delete_all
|
79
|
-
QueryDiet::Logger.paused = true
|
80
|
-
Movie.count.should == 0
|
81
|
-
Movie.create
|
82
|
-
Movie.count.should == 1
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should be false by default" do
|
86
|
-
QueryDiet::Logger.paused.should be_false
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|