aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-06-02 15:53:10 +0200
committerwycats <wycats@gmail.com>2010-06-02 15:53:10 +0200
commit26c5680bd01bd0e525eccc5d47a2e7126d9383f7 (patch)
treec655c56511ef89ba55c554a0aa7d82b1cd062f78 /railties
parentb870daba5ff71973b237616fb95f90bb321ae7fb (diff)
parent4b91daff13be43ed913a97ffc8ad1b3f77fd9690 (diff)
downloadrails-26c5680bd01bd0e525eccc5d47a2e7126d9383f7.tar.gz
rails-26c5680bd01bd0e525eccc5d47a2e7126d9383f7.tar.bz2
rails-26c5680bd01bd0e525eccc5d47a2e7126d9383f7.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/action_view_overview.textile2
-rw-r--r--railties/guides/source/active_support_core_extensions.textile33
-rw-r--r--railties/guides/source/activerecord_validations_callbacks.textile14
-rw-r--r--railties/guides/source/generators.textile12
-rw-r--r--railties/guides/source/getting_started.textile2
-rw-r--r--railties/guides/source/nested_model_forms.textile4
-rw-r--r--railties/lib/rails/application.rb11
-rw-r--r--railties/lib/rails/application/finisher.rb2
-rw-r--r--railties/lib/rails/commands/destroy.rb1
-rwxr-xr-xrailties/lib/rails/commands/generate.rb1
-rw-r--r--railties/lib/rails/generators.rb8
-rw-r--r--railties/test/application/initializers/load_path_test.rb17
-rw-r--r--railties/test/generators/generators_test_helper.rb7
13 files changed, 84 insertions, 30 deletions
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 43ebe87875..8b5eda0973 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -699,7 +699,7 @@ Creates a scope around a specific model object like form_for, but doesn‘t crea
First name: <%= person_form.text_field :first_name %>
Last name : <%= person_form.text_field :last_name %>
- <% fields_for @person.permission do |permission_fields| %>
+ <%= fields_for @person.permission do |permission_fields| %>
Admin? : <%= permission_fields.check_box :admin %>
<% end %>
<% end %>
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 08fddd2926..de82e871a6 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -1254,6 +1254,39 @@ There's also the destructive version +String#squish!+.
NOTE: Defined in +active_support/core_ext/string/filters.rb+.
+h4. +truncate+
+
+The method +truncate+ returns a copy of its receiver truncated after a given +length+:
+
+<ruby>
+"Oh dear! Oh dear! I shall be late!".truncate(20)
+# => "Oh dear! Oh dear!..."
+</ruby>
+
+Ellipsis can be customized with the +:omission+ option:
+
+<ruby>
+"Oh dear! Oh dear! I shall be late!".truncate(20, :omission => '&hellip;')
+# => "Oh dear! Oh &hellip;"
+</ruby>
+
+Note in particular that truncation takes into account the length of the omission string.
+
+Pass a +:separator+ to truncate the string at a natural break:
+
+<ruby>
+"Oh dear! Oh dear! I shall be late!".truncate(18)
+# => "Oh dear! Oh dea..."
+"Oh dear! Oh dear! I shall be late!".truncate(18, :separator => ' ')
+# => "Oh dear! Oh..."
+</ruby>
+
+In the above example "dear" gets cut first, but then +:separator+ prevents it.
+
+WARNING: The option +:separator+ can't be a regexp.
+
+NOTE: Defined in +active_support/core_ext/string/filters.rb+.
+
h4. Key-based Interpolation
In Ruby 1.9 the <tt>%</tt> string operator supports key-based interpolation, both formatted and unformatted:
diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile
index 857551c9d5..d83ea57864 100644
--- a/railties/guides/source/activerecord_validations_callbacks.textile
+++ b/railties/guides/source/activerecord_validations_callbacks.textile
@@ -879,32 +879,28 @@ Here is a list with all the available Active Record callbacks, listed in the sam
h4. Creating an Object
* +before_validation+
-* +before_validation_on_create+
* +after_validation+
-* +after_validation_on_create+
* +before_save+
+* +after_save+
* +before_create+
-* INSERT OPERATION
+* +around_create+
* +after_create+
-* +after_save+
h4. Updating an Object
* +before_validation+
-* +before_validation_on_update+
* +after_validation+
-* +after_validation_on_update+
* +before_save+
+* +after_save+
* +before_update+
-* UPDATE OPERATION
+* +around_update+
* +after_update+
-* +after_save+
h4. Destroying an Object
* +before_destroy+
-* DELETE OPERATION
* +after_destroy+
+* +around_destroy+
WARNING. +after_save+ runs both on create and update, but always _after_ the more specific callbacks +after_create+ and +after_update+, no matter the order in which the macro calls were executed.
diff --git a/railties/guides/source/generators.textile b/railties/guides/source/generators.textile
index d3757e9733..b77a2837c3 100644
--- a/railties/guides/source/generators.textile
+++ b/railties/guides/source/generators.textile
@@ -322,14 +322,10 @@ config.generators do |g|
g.template_engine :erb
g.test_framework :shoulda, :fixture => false
g.stylesheets false
-end
-</ruby>
-
-And at the end of the same file:
-<ruby>
-require 'rails/generators'
-Rails::Generators.fallbacks[:shoulda] = :test_unit
+ # Add a fallback!
+ g.fallbacks[:should] = :test_unit
+end
</ruby>
Now, if create a Comment scaffold, you will see that shoulda generators are being invoked, and at the end, they are just falling back to test unit generators:
@@ -361,7 +357,7 @@ $ rails generate scaffold Comment body:text
create test/unit/helpers/comments_helper_test.rb
</shell>
-Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of code duplication.
+Such tool allows your generators to have single responsibility, increasing the code reuse and reducing the amount of duplication.
h3. Changelog
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index fe623e969f..46e709d0f5 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -1342,7 +1342,7 @@ We also add a <tt>@post.tags.build</tt> at the top of this form, this is to make
Now create the folder <tt>app/views/tags</tt> and make a file in there called <tt>_form.html.erb</tt> which contains the form for the tag:
<erb>
-<% form.fields_for :tags do |tag_form| %>
+<%= form.fields_for :tags do |tag_form| %>
<div class="field">
<%= tag_form.label :name, 'Tag:' %>
<%= tag_form.text_field :name %>
diff --git a/railties/guides/source/nested_model_forms.textile b/railties/guides/source/nested_model_forms.textile
index 4a79902232..39b0c32f24 100644
--- a/railties/guides/source/nested_model_forms.textile
+++ b/railties/guides/source/nested_model_forms.textile
@@ -143,7 +143,7 @@ Now add a nested form for the +address+ association:
<%= form_for @person do |f| %>
<%= f.text_field :name %>
- <% f.fields_for :address do |af| %>
+ <%= f.fields_for :address do |af| %>
<%= f.text_field :street %>
<% end %>
<% end %>
@@ -184,7 +184,7 @@ The form code for an association collection is pretty similar to that of a singl
<%= form_for @person do |f| %>
<%= f.text_field :name %>
- <% f.fields_for :projects do |pf| %>
+ <%= f.fields_for :projects do |pf| %>
<%= f.text_field :name %>
<% end %>
<% end %>
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 7416e94eeb..85ae8cbbb1 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -67,6 +67,7 @@ module Rails
raise "You cannot have more than one Rails::Application" if Rails.application
super
Rails.application = base.instance
+ Rails.application.add_lib_to_load_paths!
ActiveSupport.run_load_hooks(:before_configuration, base.instance)
end
@@ -83,11 +84,21 @@ module Rails
delegate :middleware, :to => :config
+ def add_lib_to_load_paths!
+ path = config.root.join('lib').to_s
+ $LOAD_PATH.unshift(path) if File.exists?(path)
+ end
+
def require_environment!
environment = paths.config.environment.to_a.first
require environment if environment
end
+ def eager_load!
+ railties.all(&:eager_load!)
+ super
+ end
+
def routes
@routes ||= ActionDispatch::Routing::RouteSet.new
end
diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb
index fbab4d5515..d7ff489336 100644
--- a/railties/lib/rails/application/finisher.rb
+++ b/railties/lib/rails/application/finisher.rb
@@ -38,7 +38,7 @@ module Rails
initializer :eager_load! do
if config.cache_classes && !$rails_rake_task
ActiveSupport.run_load_hooks(:before_eager_load, self)
- railties.all(&:eager_load!)
+ eager_load!
end
end
diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb
index 9023c61bf2..db59cd8ad9 100644
--- a/railties/lib/rails/commands/destroy.rb
+++ b/railties/lib/rails/commands/destroy.rb
@@ -1,4 +1,5 @@
require 'rails/generators'
+Rails::Generators.configure!
if [nil, "-h", "--help"].include?(ARGV.first)
Rails::Generators.help 'destroy'
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index 7d05a30de8..1b3eef504a 100755
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -1,4 +1,5 @@
require 'rails/generators'
+Rails::Generators.configure!
if [nil, "-h", "--help"].include?(ARGV.first)
Rails::Generators.help 'generate'
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index fe8a6c0b94..af92757053 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -68,6 +68,7 @@ module Rails
options.deep_merge! config.options
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
+ templates_path.uniq!
end
def self.templates_path
@@ -328,10 +329,5 @@ module Rails
paths.uniq!
paths
end
-
end
-end
-
-# If the application was already defined, configure generators,
-# otherwise you have to configure it by hand.
-Rails::Generators.configure! if Rails.respond_to?(:application) && Rails.application
+end \ No newline at end of file
diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb
index b39b9ecaae..d31915e129 100644
--- a/railties/test/application/initializers/load_path_test.rb
+++ b/railties/test/application/initializers/load_path_test.rb
@@ -19,6 +19,23 @@ module ApplicationTests
assert $:.include?("#{app_path}/app/models")
end
+ test "initializing an application adds lib path on inheritance hook" do
+ app_file "lib/foo.rb", <<-RUBY
+ module Foo; end
+ RUBY
+
+ add_to_config <<-RUBY
+ require "foo"
+ raise "Expected Foo to be defined" unless defined?(Foo)
+ RUBY
+
+ assert_nothing_raised do
+ require "#{app_path}/config/environment"
+ end
+
+ assert $:.include?("#{app_path}/lib")
+ end
+
test "initializing an application eager load any path under app" do
app_file "app/anything/foo.rb", <<-RUBY
module Foo; end
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index d8bdb344f2..4a5a9b2932 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -1,4 +1,6 @@
require 'abstract_unit'
+require 'rails/generators'
+require 'rails/generators/test_case'
module Rails
def self.root
@@ -8,8 +10,9 @@ end
Rails.application.config.root = Rails.root
Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "templates")]
-require 'rails/generators'
-require 'rails/generators/test_case'
+# Call configure to load the settings from
+# Rails.application.config.generators to Rails::Generators
+Rails::Generators.configure!
require 'active_record'
require 'action_dispatch'