query_diet 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/.gitignore +5 -0
  2. data/README.rdoc +20 -10
  3. data/Rakefile +36 -23
  4. data/lib/query_diet/active_record_ext.rb +4 -4
  5. data/lib/query_diet/logger.rb +6 -5
  6. data/lib/query_diet/rack/reset_logger.rb +26 -0
  7. data/lib/query_diet/version.rb +3 -0
  8. data/lib/query_diet/widget.rb +14 -13
  9. data/lib/query_diet.rb +1 -2
  10. data/query_diet.gemspec +15 -64
  11. data/spec/rails-2.3/Gemfile +9 -0
  12. data/spec/rails-2.3/Rakefile +11 -0
  13. data/spec/rails-2.3/app_root/config/database.yml +4 -0
  14. data/spec/{spec.opts → rails-2.3/spec.opts} +1 -0
  15. data/spec/{spec_helper.rb → rails-2.3/spec_helper.rb} +5 -2
  16. data/spec/rails-3.0/.rspec +2 -0
  17. data/spec/rails-3.0/Gemfile +9 -0
  18. data/spec/rails-3.0/Rakefile +10 -0
  19. data/spec/rails-3.0/app_root/.gitignore +4 -0
  20. data/spec/rails-3.0/app_root/config/application.rb +32 -0
  21. data/spec/rails-3.0/app_root/config/boot.rb +13 -0
  22. data/spec/rails-3.0/app_root/config/database.yml +4 -0
  23. data/spec/rails-3.0/app_root/config/environment.rb +5 -0
  24. data/spec/rails-3.0/app_root/config/environments/test.rb +35 -0
  25. data/spec/rails-3.0/app_root/config/initializers/backtrace_silencers.rb +7 -0
  26. data/spec/rails-3.0/app_root/config/initializers/inflections.rb +10 -0
  27. data/spec/rails-3.0/app_root/config/initializers/mime_types.rb +5 -0
  28. data/spec/rails-3.0/app_root/config/initializers/secret_token.rb +7 -0
  29. data/spec/rails-3.0/app_root/config/initializers/session_store.rb +8 -0
  30. data/spec/rails-3.0/app_root/config/routes.rb +58 -0
  31. data/spec/rails-3.0/app_root/script/rails +6 -0
  32. data/spec/rails-3.0/spec_helper.rb +27 -0
  33. data/spec/rails-3.2/.rspec +2 -0
  34. data/spec/rails-3.2/Gemfile +10 -0
  35. data/spec/rails-3.2/Rakefile +10 -0
  36. data/spec/rails-3.2/app_root/.gitignore +4 -0
  37. data/spec/rails-3.2/app_root/config/application.rb +32 -0
  38. data/spec/rails-3.2/app_root/config/boot.rb +13 -0
  39. data/spec/rails-3.2/app_root/config/database.yml +4 -0
  40. data/spec/rails-3.2/app_root/config/environment.rb +5 -0
  41. data/spec/rails-3.2/app_root/config/environments/test.rb +35 -0
  42. data/spec/rails-3.2/app_root/config/initializers/backtrace_silencers.rb +7 -0
  43. data/spec/rails-3.2/app_root/config/initializers/inflections.rb +10 -0
  44. data/spec/rails-3.2/app_root/config/initializers/mime_types.rb +5 -0
  45. data/spec/rails-3.2/app_root/config/initializers/secret_token.rb +7 -0
  46. data/spec/rails-3.2/app_root/config/initializers/session_store.rb +8 -0
  47. data/spec/rails-3.2/app_root/config/routes.rb +58 -0
  48. data/spec/rails-3.2/app_root/log/.gitignore +1 -0
  49. data/spec/rails-3.2/rcov.opts +2 -0
  50. data/spec/rails-3.2/spec_helper.rb +25 -0
  51. data/spec/shared/app_root/app/controllers/query_diet_controller.rb +13 -0
  52. data/spec/{app_root → shared/app_root}/app/views/layouts/screen.html.erb +1 -0
  53. data/spec/shared/app_root/db/.gitignore +1 -0
  54. data/spec/shared/query_diet/helpers/widget_spec.rb +32 -0
  55. data/spec/shared/query_diet/integration/widget_spec.rb +23 -0
  56. data/spec/{logger_spec.rb → shared/query_diet/logger_spec.rb} +3 -3
  57. metadata +135 -39
  58. data/Gemfile +0 -10
  59. data/Gemfile.lock +0 -51
  60. data/lib/query_diet/action_controller_ext.rb +0 -20
  61. data/spec/app_root/app/controllers/query_diet_controller.rb +0 -21
  62. data/spec/app_root/config/database.yml +0 -21
  63. data/spec/app_root/config/environments/sqlite.rb +0 -0
  64. data/spec/app_root/config/environments/sqlite3.rb +0 -0
  65. data/spec/app_root/lib/console_with_fixtures.rb +0 -4
  66. data/spec/app_root/script/console +0 -7
  67. data/spec/controllers/query_diet_controller_spec.rb +0 -40
  68. /data/spec/{app_root → rails-2.3/app_root}/config/boot.rb +0 -0
  69. /data/spec/{app_root → rails-2.3/app_root}/config/environment.rb +0 -0
  70. /data/spec/{app_root/config/environments/in_memory.rb → rails-2.3/app_root/config/environments/test.rb} +0 -0
  71. /data/spec/{app_root → rails-2.3/app_root}/config/routes.rb +0 -0
  72. /data/spec/{app_root → rails-2.3/app_root}/log/.gitignore +0 -0
  73. /data/spec/{app_root/config/environments/mysql.rb → rails-3.0/app_root/lib/tasks/.gitkeep} +0 -0
  74. /data/spec/{app_root/config/environments/postgresql.rb → rails-3.0/app_root/log/.gitkeep} +0 -0
  75. /data/spec/{support → rails-3.0}/rcov.opts +0 -0
  76. /data/spec/{app_root → shared/app_root}/app/controllers/application_controller.rb +0 -0
  77. /data/spec/{app_root → shared/app_root}/app/models/movie.rb +0 -0
  78. /data/spec/{app_root → shared/app_root}/app/views/query_diet/no_query.html.erb +0 -0
  79. /data/spec/{app_root → shared/app_root}/app/views/query_diet/two_queries.html.erb +0 -0
  80. /data/spec/{app_root → shared/app_root}/db/migrate/001_create_movies.rb +0 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ doc
2
+ pkg
3
+ *.gem
4
+ .idea
5
+ spec/**/Gemfile.lock
data/README.rdoc CHANGED
@@ -14,31 +14,41 @@ http://gem-session.com/files/query_diet_angry.png
14
14
 
15
15
  == Installation
16
16
 
17
- Install the gem with
18
- sudo gem install query_diet
17
+ Add it to your Gemfile with
18
+ gem 'query_diet'
19
19
 
20
- There is no further setup necessary after you add the <tt>query_diet</tt> dependency to your Rails application.
20
+
21
+ Now add the widget to your application layout, like
22
+
23
+ # app/views/layout/application.html.erb
24
+ # ...
25
+ <body>
26
+ <%= query_diet_widget if Rails.env.development? %>
27
+ <%= yield %>
28
+ </body>
29
+
21
30
 
22
31
  We recommend you only use the gem with the development environment.
23
32
 
24
33
  == Changing warning thresholds
25
34
 
26
35
  You can define when the counter turns into a red warning. The default threshold is 8 queries and 5000 miliseconds.
27
- To change the default, add the following to <tt>config/initializers/query_diet.rb</tt>:
36
+ To change the default, simply pass them to the `query_diet_widget` helper:
37
+
38
+ <%= query_diet_widget(:bad_count => 4, :bad_time => 2000) %>
28
39
 
29
- if defined?(QueryDiet)
30
- QueryDiet::Logger.bad_count = 8
31
- QueryDiet::Logger.bad_time = 5000
32
- end
33
40
 
34
- == Rails 3 compatibility
41
+ == Rails compatibility
42
+
43
+ The gem is tested to work with Rails 2.3, Rails 3.0 and Rails 3.2.
35
44
 
36
- We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released.
37
45
 
38
46
  === Credits
39
47
 
40
48
  Henning Koch
41
49
 
50
+ Tobias Kraze
51
+
42
52
  {makandra.com}[http://makandra.com/]
43
53
 
44
54
  {gem-session.com}[http://gem-session.com/]
data/Rakefile CHANGED
@@ -1,31 +1,44 @@
1
1
  require 'rake'
2
- require 'rake/rdoctask'
3
- require 'spec/rake/spectask'
2
+ require 'bundler/gem_tasks'
4
3
 
5
- desc "Run all specs"
6
- Spec::Rake::SpecTask.new(){}
4
+ desc 'Default: Run all specs.'
5
+ task :default => 'all:spec'
7
6
 
8
- task :default => :spec
7
+ namespace :all do
8
+
9
+ desc "Run specs on all spec apps"
10
+ task :spec do
11
+ for_each_directory_of('spec/**/Rakefile') do |directory|
12
+ env = "SPEC=../../#{ENV['SPEC']} " if ENV['SPEC']
13
+ system("cd #{directory} && #{env} bundle exec rake spec")
14
+ end
15
+ end
16
+
17
+ namespace :bundle do
18
+
19
+ desc "Bundle all spec apps"
20
+ task :install do
21
+ for_each_directory_of('spec/**/Gemfile') do |directory|
22
+ system("cd #{directory} && bundle install")
23
+ end
24
+ end
25
+
26
+ desc "Update a gem given by the GEM environment variable"
27
+ task :update do
28
+ gem = ENV['GEM'] or raise "Name the gem you wish to update by setting a environment variable GEM"
29
+ for_each_directory_of('spec/**/Gemfile') do |directory|
30
+ system("cd #{directory} && bundle update #{gem}")
31
+ end
32
+ end
33
+
34
+ end
9
35
 
10
- desc 'Generate documentation for the query_diet gem.'
11
- Rake::RDocTask.new(:rdoc) do |rdoc|
12
- rdoc.rdoc_dir = 'rdoc'
13
- rdoc.title = 'query_diet'
14
- rdoc.options << '--line-numbers' << '--inline-source'
15
- rdoc.rdoc_files.include('README')
16
- rdoc.rdoc_files.include('lib/**/*.rb')
17
36
  end
18
37
 
19
- begin
20
- require 'jeweler'
21
- Jeweler::Tasks.new do |gemspec|
22
- gemspec.name = "query_diet"
23
- gemspec.summary = "Rails database query counter that stays out of your way"
24
- gemspec.email = "github@makandra.de"
25
- gemspec.homepage = "http://github.com/makandra/query_diet"
26
- gemspec.description = "Rails database query counter that stays out of your way"
27
- gemspec.authors = ["Henning Koch"]
38
+ def for_each_directory_of(path, &block)
39
+ Dir[path].sort.each do |rakefile|
40
+ directory = File.dirname(rakefile)
41
+ puts '', "\033[44m#{directory}\033[0m", ''
42
+ block.call(directory)
28
43
  end
29
- rescue LoadError
30
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
31
44
  end
@@ -1,11 +1,11 @@
1
- ActiveRecord::Base.connection.class.class_eval do
1
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
2
2
 
3
- def execute_with_query_diet(query, name = nil)
3
+ def log_with_query_diet(query, *args, &block)
4
4
  QueryDiet::Logger.log(query) do
5
- execute_without_query_diet(query, name)
5
+ log_without_query_diet(query, *args, &block)
6
6
  end
7
7
  end
8
8
 
9
- alias_method_chain :execute, :query_diet
9
+ alias_method_chain :log, :query_diet
10
10
 
11
11
  end
@@ -1,7 +1,9 @@
1
1
  module QueryDiet
2
2
  class Logger
3
+ DEFAULT_OPTIONS = { :bad_count => 8, :bad_time => 5000 }
4
+
3
5
  class << self
4
- attr_accessor :queries, :bad_count, :bad_time
6
+ attr_accessor :queries
5
7
 
6
8
  def reset
7
9
  self.queries = []
@@ -24,8 +26,9 @@ module QueryDiet
24
26
  queries.size
25
27
  end
26
28
 
27
- def bad?
28
- count >= bad_count or time >= bad_time
29
+ def bad?(options = {})
30
+ options = options.reverse_merge(DEFAULT_OPTIONS)
31
+ count >= options[:bad_count] or time >= options[:bad_time]
29
32
  end
30
33
 
31
34
  private
@@ -36,7 +39,5 @@ module QueryDiet
36
39
  end
37
40
 
38
41
  reset
39
- self.bad_count = 8
40
- self.bad_time = 5000
41
42
  end
42
43
  end
@@ -0,0 +1,26 @@
1
+ module QueryDiet
2
+ module Rack
3
+ class ResetLogger
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ QueryDiet::Logger.reset
11
+ @app.call(env)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
18
+ if defined?(Rails::Railtie)
19
+ class QueryDiet::Railtie < Rails::Railtie
20
+ initializer 'query_diet.insert_middleware' do |app|
21
+ app.config.middleware.use 'QueryDiet::Rack::ResetLogger'
22
+ end
23
+ end
24
+ else
25
+ ActionController::Dispatcher.middleware.use('QueryDiet::Rack::ResetLogger')
26
+ end
@@ -0,0 +1,3 @@
1
+ module QueryDiet
2
+ VERSION = '0.4.0'
3
+ end
@@ -1,17 +1,7 @@
1
1
  module QueryDiet
2
- class Widget
2
+ module Widget
3
3
  class << self
4
4
 
5
- def render(response)
6
- body = response.body
7
- if response.content_type == "text/html" && position = body.index('</body>')
8
- body.insert(position, css)
9
- body.insert(position, html)
10
- end
11
- end
12
-
13
- private
14
-
15
5
  def css
16
6
  <<-EOF
17
7
  <style type="text/css"><!--
@@ -41,14 +31,25 @@ module QueryDiet
41
31
  EOF
42
32
  end
43
33
 
44
- def html
34
+ def html(options)
45
35
  <<-EOF
46
- <div id="query_diet" class="#{QueryDiet::Logger.bad? ? 'bad' : 'good' }" onclick="this.parentNode.removeChild(this);">
36
+ <div id="query_diet" class="#{QueryDiet::Logger.bad?(options) ? 'bad' : 'good' }" onclick="this.parentNode.removeChild(this);">
47
37
  #{QueryDiet::Logger.count} / #{QueryDiet::Logger.time}ms
48
38
  </div>
49
39
  EOF
50
40
  end
51
41
 
52
42
  end
43
+
44
+ module Helper
45
+ def query_diet_widget(options = {})
46
+ html = Widget.css + Widget.html(options)
47
+ html.respond_to?(:html_safe) ? html.html_safe : html
48
+ end
49
+ end
50
+
53
51
  end
52
+
54
53
  end
54
+
55
+ ActionView::Base.send :include, QueryDiet::Widget::Helper
data/lib/query_diet.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'query_diet/logger'
2
2
  require 'query_diet/widget'
3
3
  require 'query_diet/active_record_ext'
4
- require 'query_diet/action_controller_ext'
5
-
4
+ require 'query_diet/rack/reset_logger'
data/query_diet.gemspec CHANGED
@@ -1,70 +1,21 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ $: << File.expand_path('../lib', __FILE__)
3
+ require 'query_diet/version'
5
4
 
6
- Gem::Specification.new do |s|
7
- s.name = "query_diet"
8
- s.version = "0.3.1"
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Henning Koch", "Tobias Kraze"]
7
+ gem.email = "github@makandra.de"
8
+ gem.description = "Rails database query counter that stays out of your way"
9
+ gem.summary = gem.description
10
+ gem.homepage = "https://github.com/makandra/query_diet"
9
11
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Henning Koch"]
12
- s.date = "2012-09-19"
13
- s.description = "Rails database query counter that stays out of your way"
14
- s.email = "github@makandra.de"
15
- s.extra_rdoc_files = [
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- "Gemfile",
20
- "Gemfile.lock",
21
- "MIT-LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/query_diet.rb",
26
- "lib/query_diet/action_controller_ext.rb",
27
- "lib/query_diet/active_record_ext.rb",
28
- "lib/query_diet/logger.rb",
29
- "lib/query_diet/widget.rb",
30
- "query_diet.gemspec",
31
- "spec/app_root/app/controllers/application_controller.rb",
32
- "spec/app_root/app/controllers/query_diet_controller.rb",
33
- "spec/app_root/app/models/movie.rb",
34
- "spec/app_root/app/views/layouts/screen.html.erb",
35
- "spec/app_root/app/views/query_diet/no_query.html.erb",
36
- "spec/app_root/app/views/query_diet/two_queries.html.erb",
37
- "spec/app_root/config/boot.rb",
38
- "spec/app_root/config/database.yml",
39
- "spec/app_root/config/environment.rb",
40
- "spec/app_root/config/environments/in_memory.rb",
41
- "spec/app_root/config/environments/mysql.rb",
42
- "spec/app_root/config/environments/postgresql.rb",
43
- "spec/app_root/config/environments/sqlite.rb",
44
- "spec/app_root/config/environments/sqlite3.rb",
45
- "spec/app_root/config/routes.rb",
46
- "spec/app_root/db/migrate/001_create_movies.rb",
47
- "spec/app_root/lib/console_with_fixtures.rb",
48
- "spec/app_root/log/.gitignore",
49
- "spec/app_root/script/console",
50
- "spec/controllers/query_diet_controller_spec.rb",
51
- "spec/logger_spec.rb",
52
- "spec/spec.opts",
53
- "spec/spec_helper.rb",
54
- "spec/support/rcov.opts"
55
- ]
56
- s.homepage = "http://github.com/makandra/query_diet"
57
- s.require_paths = ["lib"]
58
- s.rubygems_version = "1.8.21"
59
- s.summary = "Rails database query counter that stays out of your way"
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "query_diet"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = QueryDiet::VERSION
60
18
 
61
- if s.respond_to? :specification_version then
62
- s.specification_version = 3
63
-
64
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
- else
66
- end
67
- else
68
- end
19
+ gem.post_install_message = "Remember to put <%= query_diet_widget %> into your app layout."
69
20
  end
70
21
 
@@ -0,0 +1,9 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '~> 2.3'
4
+ gem 'rspec', '~> 1.3'
5
+ gem 'rspec-rails', '~> 1.3'
6
+ gem 'sqlite3'
7
+ gem 'query_diet', :path => '../..'
8
+ gem 'ruby-debug'
9
+ gem 'webrat'
@@ -0,0 +1,11 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: Run all specs for a specific rails version.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs for a specific rails version"
8
+ Spec::Rake::SpecTask.new() do |t|
9
+ t.spec_opts = ['--options', "\"spec.opts\""]
10
+ t.spec_files = defined?(SPEC) ? SPEC : FileList['**/*_spec.rb', '../shared/**/*_spec.rb']
11
+ end
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/query_diet_test.db
4
+ verbosity: quiet
@@ -2,3 +2,4 @@
2
2
  --format progress
3
3
  --loadby mtime
4
4
  --reverse
5
+ --debugger
@@ -1,7 +1,6 @@
1
1
  $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
2
 
3
- # Set the default environment to sqlite3's in_memory database
4
- ENV['RAILS_ENV'] ||= 'in_memory'
3
+ ENV['RAILS_ENV'] ||= 'test'
5
4
 
6
5
  # Load the Rails environment and testing framework
7
6
  require File.expand_path('../app_root/config/environment', __FILE__)
@@ -10,10 +9,13 @@ require 'query_diet'
10
9
  MissingSourceFile::REGEXPS << [/^cannot load such file -- (.+)$/i, 1] # Ruby 1.9 vs Rails 2.3 fix
11
10
 
12
11
  require 'spec/rails'
12
+ require 'webrat/integrations/rspec-rails'
13
13
 
14
14
  # Undo changes to RAILS_ENV
15
15
  silence_warnings {RAILS_ENV = ENV['RAILS_ENV']}
16
16
 
17
+ FileUtils.rm(Dir.glob("#{Rails.root}/db/*.db"), :force => true)
18
+
17
19
  # Run the migrations
18
20
  ActiveRecord::Migration.verbose = false
19
21
  ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
@@ -21,4 +23,5 @@ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate")
21
23
  Spec::Runner.configure do |config|
22
24
  config.use_transactional_fixtures = true
23
25
  config.use_instantiated_fixtures = false
26
+ config.include(Webrat::Matchers, :type => [:integration])
24
27
  end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format progress
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '=3.0.17'
5
+ gem 'rspec'
6
+ gem 'rspec-rails'
7
+ gem 'ruby-debug'
8
+ gem 'query_diet', :path => '../..'
9
+ gem 'webrat'
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: Run all specs for a specific rails version.'
5
+ task :default => :spec
6
+
7
+ desc "Run all specs for a specific rails version"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = defined?(SPEC) ? SPEC : ['**/*_spec.rb', '../shared/**/*_spec.rb']
10
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+
10
+ module HasDefaultSpecApp
11
+ class Application < Rails::Application
12
+ config.encoding = "utf-8"
13
+
14
+ config.cache_classes = true
15
+ config.whiny_nils = true
16
+
17
+ config.consider_all_requests_local = true
18
+ config.action_controller.perform_caching = false
19
+
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ config.action_controller.allow_forgery_protection = false
23
+
24
+ config.action_mailer.delivery_method = :test
25
+
26
+ config.active_support.deprecation = :stderr
27
+
28
+ config.root = File.expand_path('../..', __FILE__)
29
+
30
+ # railties.plugins << Rails::Plugin.new(File.expand_path('../../../../..', __FILE__))
31
+ end
32
+ end
@@ -0,0 +1,13 @@
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)
@@ -0,0 +1,4 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/query_diet_test.db
4
+ verbosity: quiet
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ HasDefaultSpecApp::Application.initialize!
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,7 @@
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!
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
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'
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,58 @@
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
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby1.8
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'