aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorMikel Lindsaar <raasdnil@gmail.com>2010-02-02 13:30:08 +1100
committerMikel Lindsaar <raasdnil@gmail.com>2010-02-02 13:30:08 +1100
commit535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81 (patch)
treedcbd2acf8e83493eea719bf0a0c51a9c121bf194 /railties
parent49a26c533366eff63acd3c99ed0dffc04f85f55c (diff)
parent9b5dae7af5757769c1e69d74a59ff036adc1f30f (diff)
downloadrails-535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81.tar.gz
rails-535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81.tar.bz2
rails-535ae3b946b387af7eb6cb4bb4aed3d5cac1cf81.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'railties')
-rw-r--r--railties/Rakefile5
-rw-r--r--railties/builtin/rails_info/rails/info_controller.rb8
-rw-r--r--railties/guides/rails_guides/generator.rb14
-rw-r--r--railties/guides/source/active_support_core_extensions.textile37
-rw-r--r--railties/guides/source/layout.html.erb2
-rw-r--r--railties/guides/source/rails_application_templates.textile2
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb12
-rw-r--r--railties/lib/generators/rails/app/templates/Gemfile10
-rw-r--r--railties/lib/generators/rails/app/templates/config/boot.rb25
-rw-r--r--railties/lib/rails/application/configuration.rb6
-rw-r--r--railties/lib/rails/configuration.rb7
-rw-r--r--railties/lib/rails/generators.rb1
-rw-r--r--railties/lib/rails/generators/test_case.rb7
-rw-r--r--railties/test/abstract_unit.rb12
-rw-r--r--railties/test/application/configuration_test.rb2
-rw-r--r--railties/test/application/generators_test.rb13
-rw-r--r--railties/test/application/middleware_test.rb2
-rw-r--r--railties/test/initializable_test.rb2
-rw-r--r--railties/test/isolation/abstract_unit.rb26
-rw-r--r--railties/test/rails_info_controller_test.rb8
20 files changed, 127 insertions, 74 deletions
diff --git a/railties/Rakefile b/railties/Rakefile
index b8f5e81b85..ea0b8ef8fb 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -1,7 +1,4 @@
-begin
- require File.expand_path('../../vendor/gems/environment', __FILE__)
-rescue LoadError
-end
+require File.expand_path('../../load_paths', __FILE__)
require 'rake'
require 'rake/testtask'
diff --git a/railties/builtin/rails_info/rails/info_controller.rb b/railties/builtin/rails_info/rails/info_controller.rb
index 47e87c5bf5..196eeb4a6c 100644
--- a/railties/builtin/rails_info/rails/info_controller.rb
+++ b/railties/builtin/rails_info/rails/info_controller.rb
@@ -1,9 +1,15 @@
class Rails::InfoController < ActionController::Base
def properties
- if consider_all_requests_local || local_request?
+ if consider_all_requests_local? || local_request?
render :inline => Rails::Info.to_html
else
render :text => '<p>For security purposes, this information is only available to local requests.</p>', :status => :forbidden
end
end
+
+ protected
+
+ def consider_all_requests_local?
+ Rails.application.config.consider_all_requests_local
+ end
end
diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb
index bd25111405..6a41bde9f6 100644
--- a/railties/guides/rails_guides/generator.rb
+++ b/railties/guides/rails_guides/generator.rb
@@ -1,11 +1,5 @@
require 'set'
-class String
- def html_safe!
- self
- end unless "post 9415935902f120a9bac0bfce7129725a0db38ed3".respond_to?(:html_safe!)
-end
-
module RailsGuides
class Generator
attr_reader :output, :view_path, :view, :guides_dir
@@ -61,7 +55,7 @@ module RailsGuides
body = set_header_section(body, @view)
body = set_index(body, @view)
- result = view.render(:layout => 'layout', :text => textile(body).html_safe!)
+ result = view.render(:layout => 'layout', :text => textile(body).html_safe)
f.write result
warn_about_broken_links(result) if ENV.key?("WARN_BROKEN_LINKS")
end
@@ -77,8 +71,8 @@ module RailsGuides
header = textile(header)
- view.content_for(:page_title) { page_title.html_safe! }
- view.content_for(:header_section) { header.html_safe! }
+ view.content_for(:page_title) { page_title.html_safe }
+ view.content_for(:header_section) { header.html_safe }
new_body
end
@@ -109,7 +103,7 @@ module RailsGuides
index << '</ol>'
index << '</div>'
- view.content_for(:index_section) { index.html_safe! }
+ view.content_for(:index_section) { index.html_safe }
i.result
end
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 562bc76135..fb4c42f118 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -496,7 +496,42 @@ The class method +delegate+
h3. Extensions to +Class+
-h4. Class Attribute Accessors
+h4. Class Attributes
+
+The method +Class#class_attribute+ declares one or more inheritable class attributes that can be overriden at any level down the hierarchy:
+
+<ruby>
+class A
+ class_attribute :x
+end
+
+class B < A; end
+
+class C < B; end
+
+A.x = :a
+B.x # => :a
+C.x # => :a
+
+B.x = :b
+A.x # => :a
+C.x # => :b
+
+C.x = :c
+A.x # => :a
+B.x # => :b
+</ruby>
+
+For example that's the way the +allow_forgery_protection+ flag is implemented for controllers:
+
+<ruby>
+class_attribute :allow_forgery_protection
+self.allow_forgery_protection = true
+</ruby>
+
+For convenience +class_attribute+ defines also a predicate, so that declaration also generates +allow_forgery_protection?+. Such predicate returns the double boolean negation of the value.
+
+NOTE: Defined in +active_support/core_ext/class/attribute.rb+
The macros +cattr_reader+, +cattr_writer+, and +cattr_accessor+ are analogous to their +attr_*+ counterparts but for classes. They initialize a class variable to +nil+ unless it already exists, and generate the corresponding class methods to access it:
diff --git a/railties/guides/source/layout.html.erb b/railties/guides/source/layout.html.erb
index 7dfcf4a507..5f324ece60 100644
--- a/railties/guides/source/layout.html.erb
+++ b/railties/guides/source/layout.html.erb
@@ -87,7 +87,7 @@
<div id="container">
<div class="wrapper">
<div id="mainCol">
- <%= yield.html_safe! %>
+ <%= yield.html_safe %>
</div>
</div>
</div>
diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile
index fc178fa44b..579b1a5538 100644
--- a/railties/guides/source/rails_application_templates.textile
+++ b/railties/guides/source/rails_application_templates.textile
@@ -88,7 +88,7 @@ Please note that you need to +git :init+ before you can install a plugin as a su
Or use plain old SVN :
<ruby>
-plugin 'wtfsvn', :svn => 'svn://crap.com/wtf/trunk'
+plugin 'usingsvn', :svn => 'svn://example.com/usingsvn/trunk'
</ruby>
h4. vendor/lib/file/initializer(filename, data = nil, &block)
diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index 2e34992b3b..918bb98db8 100644
--- a/railties/lib/generators/rails/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
@@ -90,6 +90,18 @@ module Rails::Generators
template "config/boot.rb"
end
+ def gem_for_database
+ # %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
+ case options[:database]
+ when "mysql" then "mysql"
+ when "oracle" then "ruby-oci8"
+ when "postgresql" then "pg"
+ when "sqlite3" then "sqlite3-ruby"
+ when "frontbase" then "ruby-frontbase"
+ when "ibm_db" then "ibm_db"
+ end
+ end
+
def create_activerecord_files
return if options[:skip_activerecord]
template "config/databases/#{options[:database]}.yml", "config/database.yml"
diff --git a/railties/lib/generators/rails/app/templates/Gemfile b/railties/lib/generators/rails/app/templates/Gemfile
index 7b5c89c3e2..50f1a6a414 100644
--- a/railties/lib/generators/rails/app/templates/Gemfile
+++ b/railties/lib/generators/rails/app/templates/Gemfile
@@ -1,4 +1,6 @@
# Edit this Gemfile to bundle your application's dependencies.
+source :gemcutter
+
<% if !dev_or_edge? %>
gem "rails", "<%= Rails::VERSION::STRING %>"
<% end -%>
@@ -11,6 +13,14 @@ gem "rails", "<%= Rails::VERSION::STRING %>"
<%= "# " unless options.edge? %>gem "rails", :git => "git://github.com/rails/rails.git"
<%- end -%>
+<% unless options[:skip_activerecord] -%>
+<% if options[:database] == 'sqlite3' -%>
+# ActiveRecord requires a database adapter. By default,
+# Rails has selected sqlite3.
+<% end -%>
+gem "<%= gem_for_database %>"
+<% end -%>
+
## Bundle the gems you use:
# gem "bj"
# gem "hpricot", "0.6"
diff --git a/railties/lib/generators/rails/app/templates/config/boot.rb b/railties/lib/generators/rails/app/templates/config/boot.rb
index 7fc1aeaeb8..70bd40bc4c 100644
--- a/railties/lib/generators/rails/app/templates/config/boot.rb
+++ b/railties/lib/generators/rails/app/templates/config/boot.rb
@@ -1,16 +1,19 @@
# Use Bundler (preferred)
-environment = File.expand_path('../../vendor/gems/environment', __FILE__)
-if File.exist?("#{environment}.rb")
- require environment
-
-# Use 2.x style vendor/rails and RubyGems
-else
- vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
- if File.exist?(vendor_rails)
- Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
- end
-
+begin
+ require File.expand_path('../../vendor/environment', __FILE__)
+rescue LoadError
require 'rubygems'
+ require 'bundler'
+ Bundler.setup
+
+ # To use 2.x style vendor/rails and RubyGems
+ #
+ # vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
+ # if File.exist?(vendor_rails)
+ # Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
+ # end
+ #
+ # require 'rubygems'
end
<% unless options[:skip_activerecord] -%>
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index 31787b5cc9..d6ad045294 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -5,7 +5,7 @@ module Rails
class Configuration < ::Rails::Engine::Configuration
include ::Rails::Configuration::Deprecated
- attr_accessor :cache_classes, :cache_store, :colorize_logging,
+ attr_accessor :allow_concurrency, :cache_classes, :cache_store, :colorize_logging,
:consider_all_requests_local, :dependency_loading,
:filter_parameters, :log_level, :logger, :metals,
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
@@ -13,11 +13,13 @@ module Rails
def initialize(*)
super
+ @allow_concurrency = false
@colorize_logging = true
@filter_parameters = []
@dependency_loading = true
@serve_static_assets = true
@time_zone = "UTC"
+ @consider_all_requests_local = true
end
def paths
@@ -50,7 +52,7 @@ module Rails
self.preload_frameworks = true
self.cache_classes = true
self.dependency_loading = false
- self.action_controller.allow_concurrency = true if respond_to?(:action_controller)
+ self.allow_concurrency = true
self
end
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 6a4ebe883b..7887a5d25f 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -8,10 +8,10 @@ module Rails
def middleware
@@default_middleware_stack ||= ActionDispatch::MiddlewareStack.new.tap do |middleware|
middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { Rails.application.config.serve_static_assets })
- middleware.use('::Rack::Lock', :if => lambda { !ActionController::Base.allow_concurrency })
+ middleware.use('::Rack::Lock', :if => lambda { !Rails.application.config.allow_concurrency })
middleware.use('::Rack::Runtime')
middleware.use('::Rails::Rack::Logger')
- middleware.use('::ActionDispatch::ShowExceptions', lambda { ActionController::Base.consider_all_requests_local })
+ middleware.use('::ActionDispatch::ShowExceptions', lambda { Rails.application.config.consider_all_requests_local })
middleware.use('::ActionDispatch::Callbacks', lambda { !Rails.application.config.cache_classes })
middleware.use('::ActionDispatch::Cookies')
middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
@@ -88,11 +88,12 @@ module Rails
end
class Generators #:nodoc:
- attr_accessor :aliases, :options, :colorize_logging
+ attr_accessor :aliases, :options, :fallbacks, :colorize_logging
def initialize
@aliases = Hash.new { |h,k| h[k] = {} }
@options = Hash.new { |h,k| h[k] = {} }
+ @fallbacks = {}
@colorize_logging = true
end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 90b513fcb4..8c54014fcb 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -67,6 +67,7 @@ module Rails
no_color! unless config.colorize_logging
aliases.deep_merge! config.aliases
options.deep_merge! config.options
+ fallbacks.merge! config.fallbacks
end
def self.aliases #:nodoc:
diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb
index 38a3cbb035..6b97c69d8d 100644
--- a/railties/lib/rails/generators/test_case.rb
+++ b/railties/lib/rails/generators/test_case.rb
@@ -1,4 +1,5 @@
-require 'active_support/core_ext/class/inheritable_attributes'
+require 'active_support/core_ext/class/attribute'
+require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/hash/reverse_merge'
require 'rails/generators'
require 'fileutils'
@@ -28,8 +29,8 @@ module Rails
class TestCase < ActiveSupport::TestCase
include FileUtils
- extlib_inheritable_accessor :destination_root, :current_path, :generator_class,
- :default_arguments, :instance_writer => false
+ class_attribute :destination_root, :current_path, :generator_class, :default_arguments
+ delegate :destination_root, :current_path, :generator_class, :default_arguments, :to => :'self.class'
# Generators frequently change the current path using +FileUtils.cd+.
# So we need to store the path at file load and revert back to it after each test.
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 77ef82856a..aa66dbb9be 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -1,15 +1,7 @@
ORIG_ARGV = ARGV.dup
-root = File.expand_path('../../..', __FILE__)
-begin
- require "#{root}/vendor/gems/environment"
-rescue LoadError
- %w(activesupport activemodel activerecord actionpack actionmailer activeresource railties).each do |lib|
- $:.unshift "#{root}/#{lib}/lib"
- end
-end
-
-$:.unshift "#{root}/railties/builtin/rails_info"
+require File.expand_path("../../../load_paths", __FILE__)
+$:.unshift File.expand_path("../../builtin/rails_info", __FILE__)
require 'stringio'
require 'test/unit'
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 60d644bd59..56f45582c8 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -93,7 +93,7 @@ module ApplicationTests
RUBY
require "#{app_path}/config/application"
- assert AppTemplate::Application.config.action_controller.allow_concurrency
+ assert AppTemplate::Application.config.allow_concurrency
end
test "the application can be marked as threadsafe when there are no frameworks" do
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index e54edea07c..25fa100275 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -30,6 +30,7 @@ module ApplicationTests
assert_equal(true, c.generators.colorize_logging)
assert_equal({}, c.generators.aliases)
assert_equal({}, c.generators.options)
+ assert_equal({}, c.generators.fallbacks)
end
end
@@ -51,11 +52,20 @@ module ApplicationTests
end
end
- test "generators aliases and options on initialization" do
+ test "generators set rails fallbacks" do
+ with_config do |c|
+ c.generators.fallbacks[:shoulda] = :test_unit
+ expected = { :shoulda => :test_unit }
+ assert_equal expected, c.generators.fallbacks
+ end
+ end
+
+ test "generators aliases, options and fallbacks on initialization" do
add_to_config <<-RUBY
config.generators.rails :aliases => { :test_framework => "-w" }
config.generators.orm :datamapper
config.generators.test_framework :rspec
+ config.generators.fallbacks[:shoulda] = :test_unit
RUBY
# Initialize the application
@@ -65,6 +75,7 @@ module ApplicationTests
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
+ assert_equal :test_unit, Rails::Generators.fallbacks[:shoulda]
end
test "generators no color on initialization" do
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 0b92cdba54..ce9cd510a3 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -39,7 +39,7 @@ module ApplicationTests
end
test "removes lock if allow concurrency is set" do
- add_to_config "config.action_controller.allow_concurrency = true"
+ add_to_config "config.allow_concurrency = true"
boot!
assert !middleware.include?("Rack::Lock")
end
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
index 6a7e4dcc25..74301a5dc5 100644
--- a/railties/test/initializable_test.rb
+++ b/railties/test/initializable_test.rb
@@ -10,7 +10,7 @@ module InitializableTests
attr_accessor :foo, :bar
end
- initializer :omg do
+ initializer :start do
@foo ||= 0
@foo += 1
end
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 940585836c..ff4ee6332b 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -183,23 +183,7 @@ module TestHelpers
end
def boot_rails
- root = File.expand_path('../../../..', __FILE__)
- begin
- require "#{root}/vendor/gems/environment"
- rescue LoadError
- %w(
- actionmailer/lib
- actionpack/lib
- activemodel/lib
- activerecord/lib
- activeresource/lib
- activesupport/lib
- railties/lib
- railties
- ).reverse_each do |path|
- $:.unshift "#{root}/#{path}"
- end
- end
+ require File.expand_path('../../../../load_paths', __FILE__)
end
end
end
@@ -220,14 +204,18 @@ Module.new do
end
FileUtils.mkdir(tmp_path)
- environment = File.expand_path('../../../../vendor/gems/environment', __FILE__)
+ environment = File.expand_path('../../../../load_paths', __FILE__)
if File.exist?("#{environment}.rb")
require_environment = "-r #{environment}"
end
`#{Gem.ruby} #{require_environment} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}`
File.open("#{tmp_path}/app_template/config/boot.rb", 'w') do |f|
- f.puts "require '#{environment}'" if require_environment
+ if require_environment
+ f.puts "Dir.chdir('#{File.dirname(environment)}') do"
+ f.puts " require '#{environment}'"
+ f.puts "end"
+ end
f.puts "require 'rails/all'"
end
end
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index edab27465e..4163fb2c6d 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -17,23 +17,23 @@ class InfoControllerTest < ActionController::TestCase
ActionController::Routing::Routes.draw do |map|
match ':controller/:action'
end
- @controller.stubs(:consider_all_requests_local => false, :local_request? => true)
+ @controller.stubs(:consider_all_requests_local? => false, :local_request? => true)
end
test "info controller does not allow remote requests" do
- @controller.stubs(:consider_all_requests_local => false, :local_request? => false)
+ @controller.stubs(:consider_all_requests_local? => false, :local_request? => false)
get :properties
assert_response :forbidden
end
test "info controller renders an error message when request was forbidden" do
- @controller.stubs(:consider_all_requests_local => false, :local_request? => false)
+ @controller.stubs(:consider_all_requests_local? => false, :local_request? => false)
get :properties
assert_select 'p'
end
test "info controller allows requests when all requests are considered local" do
- @controller.stubs(:consider_all_requests_local => true, :local_request? => false)
+ @controller.stubs(:consider_all_requests_local? => true, :local_request? => false)
get :properties
assert_response :success
end