From 2203c781a7dfa8b0c8b6c97cd318d941f9fbb26c Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Wed, 12 May 2010 23:04:17 +0200 Subject: defines prev_(month|year) in Date and Time to ease transition to 1.9, and deprecates last_(month|year) --- .../source/active_support_core_extensions.textile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index b7b5f47eef..fed0c25e8e 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -2660,13 +2660,13 @@ Active Support defines +Date.current+ to be today in the current time zone. That h5. Named dates -h6. +last_year+, +next_year+ +h6. +prev_year+, +next_year+ -The methods +last_year+ and +next_year+ return a date with the same day/month in the last or next year: +In Ruby 1.9 +prev_year+ and +next_year+ return a date with the same day/month in the last or next year: d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 -d.last_year # => Fri, 08 May 2009 +d.prev_year # => Fri, 08 May 2009 d.next_year # => Sun, 08 May 2011 @@ -2674,29 +2674,33 @@ If date is the 29th of February of a leap year, you obtain the 28th: d = Date.new(2000, 2, 29) # => Tue, 29 Feb 2000 -d.last_year # => Sun, 28 Feb 1999 +d.prev_year # => Sun, 28 Feb 1999 d.next_year # => Wed, 28 Feb 2001 -h6. +last_month+, +next_month+ +Active Support defines these methods as well for Ruby 1.8. -The methods +last_month+ and +next_month+ return the date with the same day in the last or next month: +h6. +prev_month+, +next_month+ + +In Ruby 1.9 +prev_month+ and +next_month+ return the date with the same day in the last or next month: d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 -d.last_month # => Thu, 08 Apr 2010 +d.prev_month # => Thu, 08 Apr 2010 d.next_month # => Tue, 08 Jun 2010 If such a day does not exist, the last day of the corresponding month is returned: -Date.new(2000, 5, 31).last_month # => Sun, 30 Apr 2000 -Date.new(2000, 3, 31).last_month # => Tue, 29 Feb 2000 +Date.new(2000, 5, 31).prev_month # => Sun, 30 Apr 2000 +Date.new(2000, 3, 31).prev_month # => Tue, 29 Feb 2000 Date.new(2000, 5, 31).next_month # => Fri, 30 Jun 2000 Date.new(2000, 1, 31).next_month # => Tue, 29 Feb 2000 +Active Support defines these methods as well for Ruby 1.8. + h6. +beginning_of_week+, +end_of_week+ The methods +beginning_of_week+ and +end_of_week+ return the dates for the beginning and end of week, assuming weeks start on Monday: -- cgit v1.2.3 From bcf5fea5e5a22edd5c7b27c29a53de0a4bedbc27 Mon Sep 17 00:00:00 2001 From: Adrian Sanchez Date: Wed, 5 May 2010 01:39:59 -0500 Subject: Bundler deprecated options in Gemfile with application template using method "gem" [#4534 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/generators/actions.rb | 3 ++- railties/test/generators/actions_test.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/actions.rb b/railties/lib/rails/generators/actions.rb index a31932906d..7af329bbf0 100644 --- a/railties/lib/rails/generators/actions.rb +++ b/railties/lib/rails/generators/actions.rb @@ -54,7 +54,8 @@ module Rails name, version = args # Deal with deprecated options - { :env => :only, :lib => :require_as }.each do |old, new| + { :env => :group, :only => :group, + :lib => :require, :require_as => :require }.each do |old, new| next unless options[old] options[new] = options.delete(old) ActiveSupport::Deprecation.warn "#{old.inspect} option in gem is deprecated, use #{new.inspect} instead" diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index e6fab93a87..65fbf61902 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -86,8 +86,13 @@ class ActionsTest < Rails::Generators::TestCase action :gem, 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com' end - assert_file 'Gemfile', /gem "mislav\-will\-paginate", :require_as => "will\-paginate"/ + assert_deprecated do + action :gem, 'thoughtbot-factory_girl', :require_as => 'factory_girl', :source => 'http://gems.github.com' + end + + assert_file 'Gemfile', /gem "mislav\-will\-paginate", :require => "will\-paginate"/ assert_file 'Gemfile', /source "http:\/\/gems\.github\.com"/ + assert_file 'Gemfile', /gem "thoughtbot-factory_girl", :require => "factory_girl"/ end def test_gem_with_env_should_include_all_dependencies_in_gemfile @@ -97,7 +102,12 @@ class ActionsTest < Rails::Generators::TestCase action :gem, 'rspec', :env => %w(development test) end - assert_file 'Gemfile', /gem "rspec", :only => \["development", "test"\]/ + assert_deprecated do + action :gem, 'rspec-rails', :only => %w(development test) + end + + assert_file 'Gemfile', /gem "rspec", :group => \["development", "test"\]/ + assert_file 'Gemfile', /gem "rspec-rails", :group => \["development", "test"\]/ end def test_gem_with_version_should_include_version_in_gemfile -- cgit v1.2.3 From 80fc6536bda191731e3963f1539c84a7b0c4e764 Mon Sep 17 00:00:00 2001 From: Jeroen van Dijk + Rodrigo Urubatan Date: Fri, 14 May 2010 23:54:13 +0200 Subject: Added Rake task rails:templates:copy to copy templates for customization [#4574 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/tasks/framework.rake | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/tasks/framework.rake b/railties/lib/rails/tasks/framework.rake index 738f7f5301..063a393bfc 100644 --- a/railties/lib/rails/tasks/framework.rake +++ b/railties/lib/rails/tasks/framework.rake @@ -30,6 +30,28 @@ namespace :rails do generator.apply template, :verbose => false end + namespace :templates do + desc "Copy all the templates from rails to the application directory for customization. Already existing local copies will be overwritten" + task :copy do + generators_lib = File.expand_path("../../generators", __FILE__) + project_templates = "#{Rails.root}/lib/templates" + + default_templates = { "erb" => %w{controller mailer scaffold}, + "rails" => %w{controller helper metal scaffold_controller stylesheets} } + + default_templates.each do |type, names| + local_template_type_dir = File.join(project_templates, type) + FileUtils.mkdir_p local_template_type_dir + + names.each do |name| + dst_name = File.join(local_template_type_dir, name) + src_name = File.join(generators_lib, type, name, "templates") + FileUtils.cp_r src_name, dst_name + end + end + end + end + namespace :update do def invoke_from_app_generator(method) app_generator.invoke(method) -- cgit v1.2.3 From 9cfeefb637b603ce41d3019c8baa95ea984620d7 Mon Sep 17 00:00:00 2001 From: wycats Date: Sat, 15 May 2010 06:08:55 -0700 Subject: Reorganized initializers a bit to enable better hooks for common cases without the need for Railtie. Specifically, the following hooks were added: * before_configuration: this hook is run immediately after the Application class comes into existence, but before the user has added any configuration. This is the appropriate place to set configuration for your plugin * before_initialize: This is run after all of the user's configuration has completed, but before any initializers have begun (in other words, it runs right after config/environments/{development,production,test}.rb) * after_initialize: This is run after all of the initializers have run. It is an appropriate place for forking in a preforking setup Each of these hooks may be used via ActiveSupport.on_load(name) { }. In all these cases, the context inside the block will be the Application object. This means that for simple cases, you can use these hooks without needing to create a Railtie. --- railties/guides/source/initialization.textile | 2 - railties/lib/rails/application.rb | 10 +++-- railties/lib/rails/application/bootstrap.rb | 8 ++-- railties/lib/rails/application/configuration.rb | 2 +- railties/lib/rails/application/finisher.rb | 6 +-- railties/lib/rails/engine.rb | 15 ++++--- railties/lib/rails/railtie/configuration.rb | 48 +++++++++++++++++++--- .../application/initializers/initializers_test.rb | 13 ------ 8 files changed, 65 insertions(+), 39 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/initialization.textile b/railties/guides/source/initialization.textile index 9ce27fa331..96d6998e1c 100644 --- a/railties/guides/source/initialization.textile +++ b/railties/guides/source/initialization.textile @@ -2379,7 +2379,6 @@ Now that we've referenced that class, it will be required for us. You'll notice * initialize_subscriber * set_clear_dependencies_hook * initialize_dependency_mechanism -* bootstrap_load_path These are all defined using the +initializer+ method: @@ -2930,7 +2929,6 @@ With +@@autoloads+ being * initialize_subscriber * set_clear_dependencies_hook * initialize_dependency_mechanism -* bootstrap_load_path h4. Active Support Initializers diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index d39f9a2ae9..9e18dccf69 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -12,7 +12,7 @@ module Rails # points to it. # # In other words, Rails::Application is Singleton and whenever you are accessing - # Rails::Application.config or YourApplication::Application.config, you are actually + # Rails::Application.config or YourApplication::Application.config, you are actually # accessing YourApplication::Application.instance.config. # # == Initialization @@ -40,7 +40,7 @@ module Rails # # The Application is also responsible for building the middleware stack and setting up # both application and engines metals. - # + # class Application < Engine autoload :Bootstrap, 'rails/application/bootstrap' autoload :Configurable, 'rails/application/configurable' @@ -69,6 +69,8 @@ module Rails raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance + + ActiveSupport.run_load_hooks(:before_configuration, base.instance) end def respond_to?(*args) @@ -82,7 +84,7 @@ module Rails end end - delegate :metal_loader, :to => :config + delegate :middleware, :metal_loader, :to => :config def require_environment! environment = paths.config.environment.to_a.first @@ -125,7 +127,7 @@ module Rails end def app - @app ||= middleware.build(routes) + @app ||= config.middleware.build(routes) end def call(env) diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 022e1a91d8..e62eed8a87 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -10,7 +10,8 @@ module Rails require environment if environment end - initializer :load_all_active_support do + initializer :load_active_support do + require 'active_support/dependencies' require "active_support/all" unless config.active_support.bare end @@ -18,7 +19,6 @@ module Rails # Used by Passenger to ensure everything's loaded before forking and # to avoid autoload race conditions in JRuby. initializer :preload_frameworks do - require 'active_support/dependencies' ActiveSupport::Autoload.eager_autoload! if config.preload_frameworks end @@ -66,8 +66,8 @@ module Rails ActiveSupport::Dependencies.mechanism = config.cache_classes ? :require : :load end - initializer :bootstrap_load_path do - # This is just an initializer used as hook so all load paths are loaded together + initializer :bootstrap_hook do |app| + ActiveSupport.run_load_hooks(:before_initialize, app) end end end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 1ad77fdfec..cd77f1adaf 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -33,7 +33,7 @@ module Rails end def middleware - @middleware ||= default_middleware_stack + @middleware ||= app_middleware.merge_into(default_middleware_stack) end def metal_loader diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 94507bb387..03bc270c81 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -35,10 +35,8 @@ module Rails app end - initializer :after_initialize do - config.after_initialize_blocks.each do |block| - block.call(self) - end + initializer :finisher_hook do |app| + ActiveSupport.run_load_hooks(:after_initialize, app) end # Disable dependency loading during request cycle diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index ab0ead65a9..652bd40ee4 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -45,7 +45,7 @@ module Rails # app.middleware.use MyEngine::Middleware # end # end - # + # # == Paths # # Since Rails 3.0, both your Application and Engines do not have hardcoded paths. @@ -125,7 +125,7 @@ module Rails end end - delegate :middleware, :paths, :root, :to => :config + delegate :paths, :root, :to => :config def load_tasks super @@ -133,7 +133,7 @@ module Rails end # Add configured load paths to ruby load paths and remove duplicates. - initializer :set_load_path, :before => :bootstrap_load_path do + initializer :set_load_path, :before => :bootstrap_hook do config.load_paths.reverse_each do |path| $LOAD_PATH.unshift(path) if File.directory?(path) end @@ -142,7 +142,10 @@ module Rails # Set the paths from which Rails will automatically load source files, # and the load_once paths. - initializer :set_autoload_paths, :before => :bootstrap_load_path do |app| + # + # This needs to be an initializer, since it needs to run once + # per engine and get the engine as a block parameter + initializer :set_autoload_paths, :before => :bootstrap_hook do |app| ActiveSupport::Dependencies.load_paths.unshift(*config.load_paths) if reloadable?(app) @@ -200,7 +203,9 @@ module Rails end end - initializer :load_app_classes do |app| + # This needs to be an initializer, since it needs to run once + # per engine and get the engine as a block parameter + initializer :load_app_classes, :before => :finisher_hook do |app| next if $rails_rake_task if app.config.cache_classes diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index 16eccaccc4..f57d82a3d8 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -3,10 +3,50 @@ require 'rails/configuration' module Rails class Railtie class Configuration + class MiddlewareStackProxy + def initialize + @operations = [] + end + + def insert_before(*args, &block) + @operations << [:insert_before, args, block] + end + + alias insert insert_before + + def insert_after(*args, &block) + @operations << [:insert_after, args, block] + end + + def swap(*args, &block) + @operations << [:swap, args, block] + end + + def use(*args, &block) + @operations << [:use, args, block] + end + + def merge_into(other) + @operations.each do |operation, args, block| + other.send(operation, *args, &block) + end + other + end + end + def initialize @@options ||= {} end + # This allows you to modify the application's middlewares from Engines. + # + # All operations you run on the app_middleware will be replayed on the + # application once it is defined and the default_middlewares are + # created + def app_middleware + @@app_middleware ||= MiddlewareStackProxy.new + end + # Holds generators configuration: # # config.generators do |g| @@ -28,12 +68,8 @@ module Rails end end - def after_initialize_blocks - @@after_initialize_blocks ||= [] - end - - def after_initialize(&blk) - after_initialize_blocks << blk if blk + def after_initialize(&block) + ActiveSupport.on_load(:after_initialize, :yield => true, &block) end def to_prepare_blocks diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb index 2e6a707175..eca42dada6 100644 --- a/railties/test/application/initializers/initializers_test.rb +++ b/railties/test/application/initializers/initializers_test.rb @@ -28,19 +28,6 @@ module ApplicationTests assert_equal "congratulations", $test_after_initialize_block2 end - test "after_initialize block works correctly when no block is passed" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.after_initialize { $test_after_initialize_block1 = "success" } - config.after_initialize # don't pass a block, this is what we're testing! - config.after_initialize { $test_after_initialize_block2 = "congratulations" } - RUBY - require "#{app_path}/config/environment" - - assert_equal "success", $test_after_initialize_block1 - assert_equal "congratulations", $test_after_initialize_block2 - end - test "after_initialize runs after frameworks have been initialized" do $activerecord_configurations = nil add_to_config <<-RUBY -- cgit v1.2.3 From 6f0ed7aa521e55bb2c12a29b86c0e8e68468cef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 15 May 2010 15:21:14 +0200 Subject: Update generators test. --- railties/test/generators_test.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'railties') diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 16f8f43b99..74a09d4bde 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -108,21 +108,10 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match /^ fixjour$/, output end - def test_rails_generators_does_not_show_activerecord_info_if_its_the_default - output = capture(:stdout){ Rails::Generators.help } - assert_no_match /ActiveRecord:/, output - assert_no_match /^ active_record:model$/, output - assert_no_match /^ active_record:fixjour$/, output - end - - def test_rails_generators_shows_activerecord_info_if_its_not_the_default - Rails::Generators.options[:rails][:orm] = :data_mapper + def test_rails_generators_does_not_show_activerecord_hooks output = capture(:stdout){ Rails::Generators.help } assert_match /ActiveRecord:/, output - assert_match /^ active_record:model$/, output assert_match /^ active_record:fixjour$/, output - ensure - Rails::Generators.options[:rails][:orm] = :active_record end def test_no_color_sets_proper_shell -- cgit v1.2.3 From 351816fab6dbe564b7bddbd877648edb06a2bfb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 15 May 2010 23:48:56 +0200 Subject: Ensure that eager_load actually takes place just after the middleware stack is built by using another pattern. Also create a engine_blank_point initializer to ensure any :before or :after hooks defined inside engines won't move the configuration initializers to other places. --- railties/lib/rails/application/finisher.rb | 10 ++++++++-- railties/lib/rails/engine.rb | 25 ++++++++++++------------- railties/lib/rails/railtie.rb | 3 +++ railties/test/railties/engine_test.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 15 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 03bc270c81..9d04f1ce38 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -35,8 +35,14 @@ module Rails app end - initializer :finisher_hook do |app| - ActiveSupport.run_load_hooks(:after_initialize, app) + initializer :eager_load! do + if config.cache_classes && !$rails_rake_task + railties.all(&:eager_load!) + end + end + + initializer :finisher_hook do + ActiveSupport.run_load_hooks(:after_initialize, self) end # Disable dependency loading during request cycle diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index 652bd40ee4..b44755820c 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -132,6 +132,15 @@ module Rails config.paths.lib.tasks.to_a.sort.each { |ext| load(ext) } end + def eager_load! + config.eager_load_paths.each do |load_path| + matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/ + Dir.glob("#{load_path}/**/*.rb").sort.each do |file| + require_dependency file.sub(matcher, '\1') + end + end + end + # Add configured load paths to ruby load paths and remove duplicates. initializer :set_load_path, :before => :bootstrap_hook do config.load_paths.reverse_each do |path| @@ -203,19 +212,9 @@ module Rails end end - # This needs to be an initializer, since it needs to run once - # per engine and get the engine as a block parameter - initializer :load_app_classes, :before => :finisher_hook do |app| - next if $rails_rake_task - - if app.config.cache_classes - config.eager_load_paths.each do |load_path| - matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/ - Dir.glob("#{load_path}/**/*.rb").sort.each do |file| - require_dependency file.sub(matcher, '\1') - end - end - end + initializer :engines_blank_point do + # We need this initializer so all extra initializers added in engines are + # consistently executed after all the initializers above across all engines. end protected diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb index b6b57bc5b5..1dba6e1538 100644 --- a/railties/lib/rails/railtie.rb +++ b/railties/lib/rails/railtie.rb @@ -197,6 +197,9 @@ module Rails end end + def eager_load! + end + def rake_tasks self.class.rake_tasks end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 40ac11fa03..b3f65fd00d 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -28,5 +28,31 @@ module RailtiesTest boot_rails assert !Rails::Engine.respond_to?(:config) end + + test "initializers are executed after application configuration initializers" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < ::Rails::Engine + initializer "dummy_initializer" do + end + end + end + RUBY + + boot_rails + + initializers = Rails.application.initializers + index = initializers.index { |i| i.name == "dummy_initializer" } + selection = initializers[(index-3)..(index)].map(&:name).map(&:to_s) + + assert_equal %w( + load_config_initializers + load_config_initializers + engines_blank_point + dummy_initializer + ), selection + + assert index < initializers.index { |i| i.name == :build_middleware_stack } + end end end -- cgit v1.2.3 From 3afdfc35e8aec7e6379e093dd1278cb3de54f21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 16 May 2010 00:34:54 +0200 Subject: Expose remaining hooks to minimize the need for a Railtie based on feedback from plugin developers. --- railties/lib/rails/application.rb | 1 - railties/lib/rails/application/finisher.rb | 1 + railties/lib/rails/railtie/configuration.rb | 12 +++ .../test/application/initializers/hooks_test.rb | 86 ++++++++++++++++++++++ .../application/initializers/initializers_test.rb | 68 ----------------- 5 files changed, 99 insertions(+), 69 deletions(-) create mode 100644 railties/test/application/initializers/hooks_test.rb delete mode 100644 railties/test/application/initializers/initializers_test.rb (limited to 'railties') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 9e18dccf69..a3b3a56bc8 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -69,7 +69,6 @@ module Rails raise "You cannot have more than one Rails::Application" if Rails.application super Rails.application = base.instance - ActiveSupport.run_load_hooks(:before_configuration, base.instance) end diff --git a/railties/lib/rails/application/finisher.rb b/railties/lib/rails/application/finisher.rb index 9d04f1ce38..fbab4d5515 100644 --- a/railties/lib/rails/application/finisher.rb +++ b/railties/lib/rails/application/finisher.rb @@ -37,6 +37,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!) end end diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index f57d82a3d8..c4a315708b 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -68,6 +68,18 @@ module Rails end end + def before_configuration(&block) + ActiveSupport.on_load(:before_configuration, :yield => true, &block) + end + + def before_eager_load(&block) + ActiveSupport.on_load(:before_eager_load, :yield => true, &block) + end + + def before_initialize(&block) + ActiveSupport.on_load(:before_initialize, :yield => true, &block) + end + def after_initialize(&block) ActiveSupport.on_load(:after_initialize, :yield => true, &block) end diff --git a/railties/test/application/initializers/hooks_test.rb b/railties/test/application/initializers/hooks_test.rb new file mode 100644 index 0000000000..1316bf6ee2 --- /dev/null +++ b/railties/test/application/initializers/hooks_test.rb @@ -0,0 +1,86 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class InitializersTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + test "load initializers" do + app_file "config/initializers/foo.rb", "$foo = true" + require "#{app_path}/config/environment" + assert $foo + end + + test "hooks block works correctly without cache classes (before_eager_load is not called)" do + add_to_config <<-RUBY + $initialization_callbacks = [] + config.root = "#{app_path}" + config.cache_classes = false + config.before_configuration { $initialization_callbacks << 1 } + config.before_initialize { $initialization_callbacks << 2 } + config.before_eager_load { Boom } + config.after_initialize { $initialization_callbacks << 3 } + RUBY + + require "#{app_path}/config/environment" + assert_equal [1,2,3], $initialization_callbacks + end + + test "hooks block works correctly with cache classes" do + add_to_config <<-RUBY + $initialization_callbacks = [] + config.root = "#{app_path}" + config.cache_classes = true + config.before_configuration { $initialization_callbacks << 1 } + config.before_initialize { $initialization_callbacks << 2 } + config.before_eager_load { $initialization_callbacks << 3 } + config.after_initialize { $initialization_callbacks << 4 } + RUBY + + require "#{app_path}/config/environment" + assert_equal [1,2,3,4], $initialization_callbacks + end + + test "after_initialize runs after frameworks have been initialized" do + $activerecord_configurations = nil + add_to_config <<-RUBY + config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations } + RUBY + + require "#{app_path}/config/environment" + assert $activerecord_configurations + assert $activerecord_configurations['development'] + end + + test "after_initialize happens after to_prepare in development" do + $order = [] + add_to_config <<-RUBY + config.cache_classes = false + config.after_initialize { $order << :after_initialize } + config.to_prepare { $order << :to_prepare } + RUBY + + require "#{app_path}/config/environment" + assert [:to_prepare, :after_initialize], $order + end + + test "after_initialize happens after to_prepare in production" do + $order = [] + add_to_config <<-RUBY + config.cache_classes = true + config.after_initialize { $order << :after_initialize } + config.to_prepare { $order << :to_prepare } + RUBY + + require "#{app_path}/config/application" + Rails.env.replace "production" + require "#{app_path}/config/environment" + assert [:to_prepare, :after_initialize], $order + end + end +end diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb deleted file mode 100644 index eca42dada6..0000000000 --- a/railties/test/application/initializers/initializers_test.rb +++ /dev/null @@ -1,68 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class InitializersTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" - end - - test "load initializers" do - app_file "config/initializers/foo.rb", "$foo = true" - require "#{app_path}/config/environment" - assert $foo - end - - test "after_initialize block works correctly" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.after_initialize { $test_after_initialize_block1 = "success" } - config.after_initialize { $test_after_initialize_block2 = "congratulations" } - RUBY - require "#{app_path}/config/environment" - - assert_equal "success", $test_after_initialize_block1 - assert_equal "congratulations", $test_after_initialize_block2 - end - - test "after_initialize runs after frameworks have been initialized" do - $activerecord_configurations = nil - add_to_config <<-RUBY - config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations } - RUBY - - require "#{app_path}/config/environment" - assert $activerecord_configurations - assert $activerecord_configurations['development'] - end - - test "after_initialize happens after to_prepare in development" do - $order = [] - add_to_config <<-RUBY - config.cache_classes = false - config.after_initialize { $order << :after_initialize } - config.to_prepare { $order << :to_prepare } - RUBY - - require "#{app_path}/config/environment" - assert [:to_prepare, :after_initialize], $order - end - - test "after_initialize happens after to_prepare in production" do - $order = [] - add_to_config <<-RUBY - config.cache_classes = true - config.after_initialize { $order << :after_initialize } - config.to_prepare { $order << :to_prepare } - RUBY - - require "#{app_path}/config/application" - Rails.env.replace "production" - require "#{app_path}/config/environment" - assert [:to_prepare, :after_initialize], $order - end - end -end -- cgit v1.2.3 From afe57dda26b8ca8484a90801a0fd378dad60e180 Mon Sep 17 00:00:00 2001 From: rohit Date: Sun, 16 May 2010 08:02:44 +0530 Subject: Fixed two failing tests in railties on 1.9.2-head [#4609 state:commited] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/test/application/initializers/hooks_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/application/initializers/hooks_test.rb b/railties/test/application/initializers/hooks_test.rb index 1316bf6ee2..198abbe861 100644 --- a/railties/test/application/initializers/hooks_test.rb +++ b/railties/test/application/initializers/hooks_test.rb @@ -66,7 +66,7 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert [:to_prepare, :after_initialize], $order + assert_equal [:to_prepare, :after_initialize], $order end test "after_initialize happens after to_prepare in production" do @@ -80,7 +80,7 @@ module ApplicationTests require "#{app_path}/config/application" Rails.env.replace "production" require "#{app_path}/config/environment" - assert [:to_prepare, :after_initialize], $order + assert_equal [:to_prepare, :after_initialize], $order end end end -- cgit v1.2.3 From 4750e61bfecd210e5c4d96546d638b5cd23bb09e Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Fri, 14 May 2010 22:14:49 +0200 Subject: using :time_select when the attribute type is :time in the scaffold generator. [#2377 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/generators/generated_attribute.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/generated_attribute.rb b/railties/lib/rails/generators/generated_attribute.rb index e962308585..f01934f946 100644 --- a/railties/lib/rails/generators/generated_attribute.rb +++ b/railties/lib/rails/generators/generated_attribute.rb @@ -9,12 +9,13 @@ module Rails def field_type @field_type ||= case type - when :integer, :float, :decimal then :text_field - when :datetime, :timestamp, :time then :datetime_select - when :date then :date_select - when :string then :text_field - when :text then :text_area - when :boolean then :check_box + when :integer, :float, :decimal then :text_field + when :time then :time_select + when :datetime, :timestamp then :datetime_select + when :date then :date_select + when :string then :text_field + when :text then :text_area + when :boolean then :check_box else :text_field end -- cgit v1.2.3 From 99b38f371a17eb3965f794227279e89fb6c694a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 16 May 2010 12:03:11 +0200 Subject: Move AD::Cascade to the bottom of the middleware stack. --- railties/lib/rails/application/configuration.rb | 4 +-- railties/lib/rails/configuration.rb | 31 +++++++++++++++++++++++ railties/lib/rails/railtie/configuration.rb | 33 +------------------------ 3 files changed, 34 insertions(+), 34 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index cd77f1adaf..9353fbefef 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -150,10 +150,10 @@ module Rails middleware.use('::ActionDispatch::Cookies') middleware.use(lambda { session_store }, lambda { session_options }) middleware.use('::ActionDispatch::Flash', :if => lambda { session_store }) - middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? }) - middleware.use('ActionDispatch::ParamsParser') + middleware.use('::ActionDispatch::ParamsParser') middleware.use('::Rack::MethodOverride') middleware.use('::ActionDispatch::Head') + middleware.use(lambda { metal_loader.build_middleware(metals) }, :if => lambda { metal_loader.metals.any? }) end end end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index bd404f4a14..ee0fca6592 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -5,6 +5,37 @@ require 'rails/rack' module Rails module Configuration + class MiddlewareStackProxy #:nodoc: + def initialize + @operations = [] + end + + def insert_before(*args, &block) + @operations << [:insert_before, args, block] + end + + alias :insert :insert_before + + def insert_after(*args, &block) + @operations << [:insert_after, args, block] + end + + def swap(*args, &block) + @operations << [:swap, args, block] + end + + def use(*args, &block) + @operations << [:use, args, block] + end + + def merge_into(other) + @operations.each do |operation, args, block| + other.send(operation, *args, &block) + end + other + end + end + class Generators #:nodoc: attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index c4a315708b..4e6f94c534 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -3,37 +3,6 @@ require 'rails/configuration' module Rails class Railtie class Configuration - class MiddlewareStackProxy - def initialize - @operations = [] - end - - def insert_before(*args, &block) - @operations << [:insert_before, args, block] - end - - alias insert insert_before - - def insert_after(*args, &block) - @operations << [:insert_after, args, block] - end - - def swap(*args, &block) - @operations << [:swap, args, block] - end - - def use(*args, &block) - @operations << [:use, args, block] - end - - def merge_into(other) - @operations.each do |operation, args, block| - other.send(operation, *args, &block) - end - other - end - end - def initialize @@options ||= {} end @@ -44,7 +13,7 @@ module Rails # application once it is defined and the default_middlewares are # created def app_middleware - @@app_middleware ||= MiddlewareStackProxy.new + @@app_middleware ||= Rails::Configuration::MiddlewareStackProxy.new end # Holds generators configuration: -- cgit v1.2.3 From 5ff6de0982c165bb9038258d867398c73c142084 Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Sun, 16 May 2010 11:20:11 +0200 Subject: Added assert_attribute_type to clean up GeneratedAttributeTest [#2377 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/generators/test_case.rb | 12 +++++++ .../test/generators/generated_attribute_test.rb | 40 ++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 railties/test/generators/generated_attribute_test.rb (limited to 'railties') diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 6b97c69d8d..24b57aabf9 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -189,6 +189,18 @@ module Rails end alias :assert_method :assert_instance_method + # Asserts the given field name gets translated to an attribute type + # properly. + # + # assert_attribute_type 'date', :date_select + # + def assert_attribute_type(name, attribute_type) + assert_equal( + Rails::Generators::GeneratedAttribute.new('test', name).field_type, + attribute_type + ) + end + # Runs the generator configured for this class. The first argument is an array like # command line arguments: # diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb new file mode 100644 index 0000000000..ccd0c65905 --- /dev/null +++ b/railties/test/generators/generated_attribute_test.rb @@ -0,0 +1,40 @@ +require 'generators/generators_test_helper' +require 'rails/generators/generated_attribute' + +class GeneratedAttributeTest < Rails::Generators::TestCase + include GeneratorsTestHelper + + def test_field_type_returns_text_field + %w(integer float decimal string).each do |name| + assert_attribute_type name, :text_field + end + end + + def test_field_type_returns_datetime_select + %w(datetime timestamp).each do |name| + assert_attribute_type name, :datetime_select + end + end + + def test_field_type_returns_time_select + assert_attribute_type 'time', :time_select + end + + def test_field_type_returns_date_select + assert_attribute_type 'date', :date_select + end + + def test_field_type_returns_text_area + assert_attribute_type 'text', :text_area + end + + def test_field_type_returns_check_box + assert_attribute_type 'boolean', :check_box + end + + def test_field_type_with_unknown_type_returns_text_field + %w(foo bar baz).each do |name| + assert_attribute_type name, :text_field + end + end +end -- cgit v1.2.3 From 1a2d556de7935588e04c541e6c0804b5533db6b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 16 May 2010 12:07:44 +0200 Subject: Rename assert_attribute_type to asser_field_type. --- railties/lib/rails/generators/test_case.rb | 6 +++--- railties/test/generators/generated_attribute_test.rb | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/test_case.rb b/railties/lib/rails/generators/test_case.rb index 24b57aabf9..952400e049 100644 --- a/railties/lib/rails/generators/test_case.rb +++ b/railties/lib/rails/generators/test_case.rb @@ -192,11 +192,11 @@ module Rails # Asserts the given field name gets translated to an attribute type # properly. # - # assert_attribute_type 'date', :date_select + # assert_field_type :date, :date_select # - def assert_attribute_type(name, attribute_type) + def assert_field_type(name, attribute_type) assert_equal( - Rails::Generators::GeneratedAttribute.new('test', name).field_type, + Rails::Generators::GeneratedAttribute.new('test', name.to_s).field_type, attribute_type ) end diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index ccd0c65905..dacb06fb13 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -6,35 +6,35 @@ class GeneratedAttributeTest < Rails::Generators::TestCase def test_field_type_returns_text_field %w(integer float decimal string).each do |name| - assert_attribute_type name, :text_field + assert_field_type name, :text_field end end def test_field_type_returns_datetime_select %w(datetime timestamp).each do |name| - assert_attribute_type name, :datetime_select + assert_field_type name, :datetime_select end end def test_field_type_returns_time_select - assert_attribute_type 'time', :time_select + assert_field_type 'time', :time_select end def test_field_type_returns_date_select - assert_attribute_type 'date', :date_select + assert_field_type 'date', :date_select end def test_field_type_returns_text_area - assert_attribute_type 'text', :text_area + assert_field_type 'text', :text_area end def test_field_type_returns_check_box - assert_attribute_type 'boolean', :check_box + assert_field_type 'boolean', :check_box end def test_field_type_with_unknown_type_returns_text_field %w(foo bar baz).each do |name| - assert_attribute_type name, :text_field + assert_field_type name, :text_field end end end -- cgit v1.2.3 From 3e84ea014e9f4d0f8d302c9bf8ad04240eec2804 Mon Sep 17 00:00:00 2001 From: Aleksandr Koss Date: Sat, 15 May 2010 20:15:23 +0700 Subject: Fix Hash#index deprecated warning in 1.9.x [#4600 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/tasks/routes.rake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 42e01d5e51..4bb94d39ea 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -3,7 +3,8 @@ task :routes => :environment do Rails::Application.reload_routes! all_routes = ENV['CONTROLLER'] ? Rails.application.routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : Rails.application.routes.routes routes = all_routes.collect do |route| - name = Rails.application.routes.named_routes.routes.index(route).to_s + key_method = Hash.method_defined?('key') ? 'key' : 'index' + name = Rails.application.routes.named_routes.routes.send(key_method, route).to_s reqs = route.requirements.empty? ? "" : route.requirements.inspect {:name => name, :verb => route.verb.to_s, :path => route.path, :reqs => reqs} end -- cgit v1.2.3 From 6cabc9a61fd78a7cbc06d083a59cb252794e5a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 16 May 2010 14:34:36 +0200 Subject: Add some comments related to Hash method check. --- railties/lib/rails/tasks/routes.rake | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties') diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 4bb94d39ea..41619bc1f8 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -3,6 +3,9 @@ task :routes => :environment do Rails::Application.reload_routes! all_routes = ENV['CONTROLLER'] ? Rails.application.routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : Rails.application.routes.routes routes = all_routes.collect do |route| + # TODO: The :index method is deprecated in 1.9 in favor of :key + # but we don't have :key in 1.8.7. We can remove this check when + # stop supporting 1.8.x key_method = Hash.method_defined?('key') ? 'key' : 'index' name = Rails.application.routes.named_routes.routes.send(key_method, route).to_s reqs = route.requirements.empty? ? "" : route.requirements.inspect -- cgit v1.2.3 From 6c69221985268ada25b4c32360fa4f2403f2156b Mon Sep 17 00:00:00 2001 From: Rizwan Reza Date: Sun, 16 May 2010 19:45:30 +0430 Subject: Takes out stale methods relating to edge_rails_version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/info.rb | 33 --------------------------------- railties/test/rails_info_test.rb | 21 --------------------- 2 files changed, 54 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/info.rb b/railties/lib/rails/info.rb index 5a496f6536..e9c3ebe685 100644 --- a/railties/lib/rails/info.rb +++ b/railties/lib/rails/info.rb @@ -35,20 +35,6 @@ module Rails end end - def edge_rails_revision(info = git_info) - info[/commit ([a-z0-9-]+)/, 1] || freeze_edge_version - end - - def freeze_edge_version - if File.exist?(rails_vendor_root) - begin - Dir[File.join(rails_vendor_root, 'REVISION_*')].first.scan(/_(\d+)$/).first.first - rescue - Dir[File.join(rails_vendor_root, 'TAG_*')].first.scan(/_(.+)$/).first.first rescue 'unknown' - end - end - end - def to_s column_width = properties.names.map {|name| name.length}.max info = properties.map do |name, value| @@ -75,20 +61,6 @@ module Rails table << '' end end - - protected - def rails_vendor_root - @rails_vendor_root ||= "#{Rails.root}/vendor/rails" - end - - def git_info - env_lang, ENV['LC_ALL'] = ENV['LC_ALL'], 'C' - Dir.chdir(rails_vendor_root) do - silence_stderr { `git log -n 1` } - end - ensure - ENV['LC_ALL'] = env_lang - end end # The Ruby version and platform, e.g. "1.8.2 (powerpc-darwin8.2.0)". @@ -120,11 +92,6 @@ module Rails Rails.configuration.middleware.active.map(&:inspect) end - # The Rails Git revision, if it's checked out into vendor/rails. - property 'Edge Rails revision' do - edge_rails_revision - end - # The application's location on the filesystem. property 'Application root' do File.expand_path(Rails.root) diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index fc28d7e912..1da66062aa 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -14,27 +14,6 @@ class InfoTest < ActiveSupport::TestCase silence_warnings { load 'rails/info.rb' } end - def test_edge_rails_revision_not_set_when_svn_info_is_empty - Rails::Info.property 'Test that this will not be defined' do - Rails::Info.edge_rails_revision '' - end - assert !property_defined?('Test that this will not be defined') - end - - def test_edge_rails_revision_extracted_from_svn_info - Rails::Info.property 'Test Edge Rails revision' do - Rails::Info.edge_rails_revision <<-EOS - commit 420c4b3d8878156d04f45e47050ddc62ae00c68c - Author: David Heinemeier Hansson - Date: Sun Apr 13 17:33:27 2008 -0500 - - Added Rails.public_path to control where HTML and assets are expected to be loaded from -EOS - end - - assert_property 'Test Edge Rails revision', '420c4b3d8878156d04f45e47050ddc62ae00c68c' - end - def test_property_with_block_swallows_exceptions_and_ignores_property assert_nothing_raised do Rails::Info.module_eval do -- cgit v1.2.3 From 621ee373cbd7f88b0c28d45259b9dc9c43d04e44 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Thu, 8 Apr 2010 18:05:12 +0200 Subject: I have updated the documentation according to ticket #4263 about fixtures and set_fixture_class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/guides/source/active_record_basics.textile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/active_record_basics.textile b/railties/guides/source/active_record_basics.textile index 226f1b134b..d81e461e63 100644 --- a/railties/guides/source/active_record_basics.textile +++ b/railties/guides/source/active_record_basics.textile @@ -104,6 +104,14 @@ class Product < ActiveRecord::Base set_table_name "PRODUCT" end +If you do so, you will have to define manually the class name that is hosting the fixtures (class_name.yml) using the +set_fixture_class+ method in your test definition: + +class FunnyJoke < ActiveSupport::TestCase + set_fixture_class :funny_jokes => 'Joke' + fixtures :funny_jokes + ... +end + It's also possible to override the column that should be used as the table's primary key. Use the +ActiveRecord::Base.set_primary_key+ method for that: @@ -201,4 +209,4 @@ Active Record callbacks allow you to attach code to certain events in the life-c h3. Migrations -Rails provides a domain-specific language for managing a database schema called migrations. Migrations are stored in files which are executed against any database that Active Record support using rake. Rails keeps track of which files have been committed to the database and provides rollback features. You can learn more about migrations in the "Active Record Migrations guide":migrations.html \ No newline at end of file +Rails provides a domain-specific language for managing a database schema called migrations. Migrations are stored in files which are executed against any database that Active Record support using rake. Rails keeps track of which files have been committed to the database and provides rollback features. You can learn more about migrations in the "Active Record Migrations guide":migrations.html -- cgit v1.2.3 From b7bdacf1abb71ec2b46ea54893fb881dea36cca8 Mon Sep 17 00:00:00 2001 From: Aleksandr Koss Date: Sun, 16 May 2010 17:52:25 +0100 Subject: Added rails command aliases (s g c db) to reserved words in app generator [#4602 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/generators/rails/app/app_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 0a0b033738..ee44acc2fa 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -149,7 +149,7 @@ module Rails # can change in Ruby 1.8.7 when we FileUtils.cd. RAILS_DEV_PATH = File.expand_path("../../../../../..", File.dirname(__FILE__)) - RESERVED_NAMES = %w[generate console server dbconsole + RESERVED_NAMES = %w[generate g console c server s dbconsole db application destroy benchmarker profiler plugin runner test] -- cgit v1.2.3 From 7be58b616337d28dc6f25e9dc26cca935437ec12 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Sun, 16 May 2010 17:52:59 +0100 Subject: Tests for new reserved words [#4602 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/test/generators/app_generator_test.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 8743defe82..3975a39ab1 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -70,8 +70,13 @@ class AppGeneratorTest < Rails::Generators::TestCase end def test_name_collision_raises_an_error - content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] } - assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content + reserved_words = %w[generate g console c server s dbconsole db + application destroy benchmarker profiler + plugin runner test] + reserved_words.each do |reserved| + content = capture(:stderr){ run_generator [File.join(destination_root, reserved)] } + assert_equal "Invalid application name #{reserved}. Please give a name which does not match one of the reserved rails words.\n", content + end end def test_invalid_database_option_raises_an_error -- cgit v1.2.3 From 64d109e3539ad600f58536d3ecabd2f87b67fd1c Mon Sep 17 00:00:00 2001 From: wycats Date: Sun, 16 May 2010 10:25:55 +0400 Subject: Significantly improved internal encoding heuristics and support. * Default Encoding.default_internal to UTF-8 * Eliminated the use of file-wide magic comments to coerce code evaluated inside the file * Read templates as BINARY, use default_external or template-wide magic comments inside the Template to set the initial encoding * This means that template handlers in Ruby 1.9 will receive Strings encoded in default_internal (UTF-8 by default) * Create a better Exception for encoding issues, and use it when the template source has bytes that are not compatible with the specified encoding * Allow template handlers to opt-into handling BINARY. If they do so, they need to do some of their own manual encoding work * Added a "Configuration Gotchas" section to the intro Rails Guide instructing users to use UTF-8 for everything * Use config.encoding= in Ruby 1.8, and raise if a value that is an invalid $KCODE value is used Also: * Fixed a few tests that were assert() rather than assert_equal() and were caught by Minitest requiring a String for the message * Fixed a test where an assert_select was misformed, also caught by Minitest being more restrictive * Fixed a test where a Rack response was returning a String rather than an Enumerable --- railties/guides/source/getting_started.textile | 21 +++++++++++++++++++++ railties/lib/rails.rb | 1 + railties/lib/rails/application/configuration.rb | 10 +++++++++- railties/test/application/configuration_test.rb | 3 ++- 4 files changed, 33 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 5da7ff7daa..b7301bff20 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1462,11 +1462,32 @@ Rails also comes with built-in help that you can generate using the rake command * Running +rake doc:guides+ will put a full copy of the Rails Guides in the +doc/guides+ folder of your application. Open +doc/guides/index.html+ in your web browser to explore the Guides. * Running +rake doc:rails+ will put a full copy of the API documentation for Rails in the +doc/api+ folder of your application. Open +doc/api/index.html+ in your web browser to explore the API documentation. +h3. Configuration Gotchas + +The easiest way to work with Rails is to store all external data as UTF-8. If you don't, Ruby libraries and Rails will often be able to convert your native data into UTF-8, but this doesn't always work reliably, so you're better off ensuring that all external data is UTF-8. + +If you have made a mistake in this area, the most common symptom is a black diamond with a question mark inside appearing in the browser. Another common symptom is characters like "ü" appearing instead of "ü". Rails takes a number of internal steps to mitigate common causes of these problems that can be automatically detected and corrected. However, if you have external data that is not stored as UTF-8, it can occasionally result in these kinds of issues that cannot be automatically detected by Rails and corrected. + +Two very common sources of data that are not UTF-8: +* Your text editor: Most text editors (such as Textmate), default to saving files as + UTF-8. If your text editor does not, this can result in special characters that you + enter in your templates (such as é) to appear as a diamond with a question mark inside + in the browser. This also applies to your I18N translation files. + Most editors that do not already default to UTF-8 (such as some versions of + Dreamweaver) offer a way to change the default to UTF-8. Do so. +* Your database. Rails defaults to converting data from your database into UTF-8 at + the boundary. However, if your database is not using UTF-8 internally, it may not + be able to store all characters that your users enter. For instance, if your database + is using Latin-1 internally, and your user enters a Russian, Hebrew, or Japanese + character, the data will be lost forever once it enters the database. If possible, + use UTF-8 as the internal storage of your database. h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2 +* May 16, 2010: Added a section on configuration gotchas to address common encoding + problems that people might have * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com * April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits:html#raasdnil * April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index 0611b2a9f5..be486ef2ac 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -23,6 +23,7 @@ if RUBY_VERSION < '1.9' $KCODE='u' else Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 end module Rails diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9353fbefef..8afe423973 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,4 +1,5 @@ require 'active_support/deprecation' +require 'active_support/core_ext/string/encoding' require 'rails/engine/configuration' module Rails @@ -27,8 +28,15 @@ module Rails def encoding=(value) @encoding = value - if defined?(Encoding) && Encoding.respond_to?(:default_external=) + if "ruby".encoding_aware? Encoding.default_external = value + Encoding.default_internal = value + else + $KCODE = value + if $KCODE == "NONE" + raise "The value you specified for config.encoding is " \ + "invalid. The possible values are UTF8, SJIS, or EUC" + end end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index dfc4e2359b..c08bd2ef22 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -180,7 +180,8 @@ module ApplicationTests require "#{app_path}/config/application" unless RUBY_VERSION < '1.9' - assert_equal Encoding.find("utf-8"), Encoding.default_external + assert_equal Encoding::UTF_8, Encoding.default_external + assert_equal Encoding::UTF_8, Encoding.default_internal end end -- cgit v1.2.3 From ade756fe42423033bae8e5aea8f58782f7a6c517 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 16 May 2010 13:52:51 -0700 Subject: Moved encoding work in progress to a feature branch. This reverts commits af0d1a88157942c6e6398dbf73891cff1e152405 and 64d109e3539ad600f58536d3ecabd2f87b67fd1c. --- railties/guides/source/getting_started.textile | 21 --------------------- railties/lib/rails.rb | 1 - railties/lib/rails/application/configuration.rb | 10 +--------- railties/test/application/configuration_test.rb | 3 +-- 4 files changed, 2 insertions(+), 33 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index b7301bff20..5da7ff7daa 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1462,32 +1462,11 @@ Rails also comes with built-in help that you can generate using the rake command * Running +rake doc:guides+ will put a full copy of the Rails Guides in the +doc/guides+ folder of your application. Open +doc/guides/index.html+ in your web browser to explore the Guides. * Running +rake doc:rails+ will put a full copy of the API documentation for Rails in the +doc/api+ folder of your application. Open +doc/api/index.html+ in your web browser to explore the API documentation. -h3. Configuration Gotchas - -The easiest way to work with Rails is to store all external data as UTF-8. If you don't, Ruby libraries and Rails will often be able to convert your native data into UTF-8, but this doesn't always work reliably, so you're better off ensuring that all external data is UTF-8. - -If you have made a mistake in this area, the most common symptom is a black diamond with a question mark inside appearing in the browser. Another common symptom is characters like "ü" appearing instead of "ü". Rails takes a number of internal steps to mitigate common causes of these problems that can be automatically detected and corrected. However, if you have external data that is not stored as UTF-8, it can occasionally result in these kinds of issues that cannot be automatically detected by Rails and corrected. - -Two very common sources of data that are not UTF-8: -* Your text editor: Most text editors (such as Textmate), default to saving files as - UTF-8. If your text editor does not, this can result in special characters that you - enter in your templates (such as é) to appear as a diamond with a question mark inside - in the browser. This also applies to your I18N translation files. - Most editors that do not already default to UTF-8 (such as some versions of - Dreamweaver) offer a way to change the default to UTF-8. Do so. -* Your database. Rails defaults to converting data from your database into UTF-8 at - the boundary. However, if your database is not using UTF-8 internally, it may not - be able to store all characters that your users enter. For instance, if your database - is using Latin-1 internally, and your user enters a Russian, Hebrew, or Japanese - character, the data will be lost forever once it enters the database. If possible, - use UTF-8 as the internal storage of your database. h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/2 -* May 16, 2010: Added a section on configuration gotchas to address common encoding - problems that people might have * April 30, 2010: Fixes, editing and updating of code samples by "Rohit Arondekar":http://rohitarondekar.com * April 25, 2010: Couple of more minor fixups "Mikel Lindsaar":credits:html#raasdnil * April 1, 2010: Fixed document to validate XHTML 1.0 Strict. "Jaime Iniesta":http://jaimeiniesta.com diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb index be486ef2ac..0611b2a9f5 100644 --- a/railties/lib/rails.rb +++ b/railties/lib/rails.rb @@ -23,7 +23,6 @@ if RUBY_VERSION < '1.9' $KCODE='u' else Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 end module Rails diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 8afe423973..9353fbefef 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -1,5 +1,4 @@ require 'active_support/deprecation' -require 'active_support/core_ext/string/encoding' require 'rails/engine/configuration' module Rails @@ -28,15 +27,8 @@ module Rails def encoding=(value) @encoding = value - if "ruby".encoding_aware? + if defined?(Encoding) && Encoding.respond_to?(:default_external=) Encoding.default_external = value - Encoding.default_internal = value - else - $KCODE = value - if $KCODE == "NONE" - raise "The value you specified for config.encoding is " \ - "invalid. The possible values are UTF8, SJIS, or EUC" - end end end diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c08bd2ef22..dfc4e2359b 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -180,8 +180,7 @@ module ApplicationTests require "#{app_path}/config/application" unless RUBY_VERSION < '1.9' - assert_equal Encoding::UTF_8, Encoding.default_external - assert_equal Encoding::UTF_8, Encoding.default_internal + assert_equal Encoding.find("utf-8"), Encoding.default_external end end -- cgit v1.2.3