Skip to content

Commit

Permalink
Merge pull request #7794 from guilleiguaran/extract-rack-cache
Browse files Browse the repository at this point in the history
Use Rack::Cache middleware only if is in Gemfile
  • Loading branch information
spastorino committed Oct 2, 2012
2 parents f934aec + f4a6f1d commit 037e50e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -6,6 +6,7 @@ gem 'arel', github: 'rails/arel', branch: 'master'


gem 'mocha', '>= 0.11.2', :require => false gem 'mocha', '>= 0.11.2', :require => false
gem 'rack-test', github: 'brynary/rack-test' gem 'rack-test', github: 'brynary/rack-test'
gem 'rack-cache', "~> 1.2"
gem 'bcrypt-ruby', '~> 3.0.0' gem 'bcrypt-ruby', '~> 3.0.0'
gem 'jquery-rails' gem 'jquery-rails'


Expand Down
1 change: 0 additions & 1 deletion actionpack/actionpack.gemspec
Expand Up @@ -18,7 +18,6 @@ Gem::Specification.new do |s|
s.requirements << 'none' s.requirements << 'none'


s.add_dependency('activesupport', version) s.add_dependency('activesupport', version)
s.add_dependency('rack-cache', '~> 1.2')
s.add_dependency('builder', '~> 3.1.0') s.add_dependency('builder', '~> 3.1.0')
s.add_dependency('rack', '~> 1.4.1') s.add_dependency('rack', '~> 1.4.1')
s.add_dependency('rack-test', '~> 0.6.1') s.add_dependency('rack-test', '~> 0.6.1')
Expand Down
6 changes: 6 additions & 0 deletions railties/lib/rails/application.rb
Expand Up @@ -282,6 +282,12 @@ def default_middleware_stack #:nodoc:
ActionDispatch::MiddlewareStack.new.tap do |middleware| ActionDispatch::MiddlewareStack.new.tap do |middleware|
app = self app = self
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
begin
require 'rack/cache'
rescue LoadError => error
error.message << ' Be sure to add rack-cache to your Gemfile'
raise
end
require "action_dispatch/http/rack_cache" require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache middleware.use ::Rack::Cache, rack_cache
end end
Expand Down
4 changes: 4 additions & 0 deletions railties/lib/rails/generators/rails/app/templates/Gemfile
Expand Up @@ -9,6 +9,10 @@ source 'https://rubygems.org'
<%= assets_gemfile_entry %> <%= assets_gemfile_entry %>
<%= javascript_gemfile_entry %> <%= javascript_gemfile_entry %>
# Puts a simple HTTP cache in front of your app.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish, or squid.
gem 'rack-cache', '~> 1.2'
# To use ActiveModel has_secure_password # To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0' # gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
5 changes: 5 additions & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -300,6 +300,11 @@ def test_inclusion_of_debugger
assert_file "Gemfile", /# gem 'debugger'/ assert_file "Gemfile", /# gem 'debugger'/
end end


def test_inclusion_of_rack_cache
run_generator
assert_file "Gemfile", /gem 'rack-cache'/
end

def test_template_from_dir_pwd def test_template_from_dir_pwd
FileUtils.cd(Rails.root) FileUtils.cd(Rails.root)
assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]))
Expand Down

0 comments on commit 037e50e

Please sign in to comment.