From cbcc0ca57b0ea713d7d32364b599d88f2bef6d92 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 24 Apr 2009 10:41:45 -0700 Subject: Use Symbol#to_proc in rails plugin internals --- railties/lib/rails/plugin.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties') diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index dd840ef058..63864058ee 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/kernel/reporting' +require 'active_support/core_ext/symbol' require 'active_support/dependencies' module Rails -- cgit v1.2.3 From cd9bb88eefdbd8a43f0bb15934ae32985fd19b6e Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Sun, 26 Apr 2009 11:22:03 -0500 Subject: Remove reference to Rack::RewindableInput, which has been removed a while ago. Signed-off-by: Joshua Peek --- railties/lib/initializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index a03be59a2b..b3b409dc4d 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -568,7 +568,7 @@ Run `rake gems:install` to install the missing gems. Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths configuration.middleware.insert_before( - :"ActionDispatch::RewindableInput", + :"ActionDispatch::ParamsParser", Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?) end -- cgit v1.2.3 From cecafc52ee0a4a53c903ddbaba95683261f88e5f Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 23 Apr 2009 15:58:38 -0700 Subject: Refactor ActionView::Template ActionView::Template is now completely independent from template storage, which allows different back ends such as the database. ActionView::Template's only responsibility is to take in the template source (passed in from ActionView::Path), compile it, and render it. --- railties/test/plugin_loader_test.rb | 4 ++-- railties/test/plugin_test_helper.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'railties') diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index b270748dd6..c647d7b478 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -132,8 +132,8 @@ class TestPluginLoader < Test::Unit::TestCase @loader.send :add_engine_view_paths - assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths - assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionMailer::Base.view_paths + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths.map { |p| p.to_s } + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionMailer::Base.view_paths.map { |p| p.to_s } end def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb index 93d50dc07f..55d1a1fa96 100644 --- a/railties/test/plugin_test_helper.rb +++ b/railties/test/plugin_test_helper.rb @@ -12,7 +12,7 @@ RAILS_ROOT = '.' unless defined?(RAILS_ROOT) class Test::Unit::TestCase private def plugin_fixture_root_path - File.join(File.dirname(__FILE__), 'fixtures', 'plugins') + File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'plugins')) end def only_load_the_following_plugins!(plugins) -- cgit v1.2.3 From 348d7f8a84ee1739ef54c4068263a7d36dd98fd1 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 28 Apr 2009 09:48:27 +0200 Subject: fixes redirect codes in layouts and rendering guide, thanks to Loren Norman --- railties/guides/source/layouts_and_rendering.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/layouts_and_rendering.textile b/railties/guides/source/layouts_and_rendering.textile index 809d2b2172..d7573e6314 100644 --- a/railties/guides/source/layouts_and_rendering.textile +++ b/railties/guides/source/layouts_and_rendering.textile @@ -447,7 +447,7 @@ redirect_to :back h5. Getting a Different Redirect Status Code -Rails uses HTTP status code 302 (permanent redirect) when you call +redirect_to+. If you'd like to use a different status code (perhaps 301, temporary redirect), you can do so by using the +:status+ option: +Rails uses HTTP status code 302 (temporary redirect) when you call +redirect_to+. If you'd like to use a different status code (perhaps 301, permanent redirect), you can do so by using the +:status+ option: redirect_to photos_path, :status => 301 -- cgit v1.2.3 From 8fa1235c2734a921b633cde498318dbafa959284 Mon Sep 17 00:00:00 2001 From: Dallas Taylor Date: Tue, 28 Apr 2009 12:40:06 +0100 Subject: changed sentence --- railties/guides/source/security.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile index 7b93fa7561..875c4ae6e5 100644 --- a/railties/guides/source/security.textile +++ b/railties/guides/source/security.textile @@ -967,7 +967,7 @@ Transfer-Encoding: chunked Content-Type: text/html -Under certain circumstances this would present the malicious HTML to the victim. However, this seems to work with Keep-Alive connections, only (and many browsers are using one-time connections). But you can't rely on this. _(highlight)In any case this is a serious bug, and you should update your Rails to version 2.0.5 or 2.1.2 to eliminate Header Injection (and thus response splitting) risks._ +Under certain circumstances this would present the malicious HTML to the victim. However, this only seems to work with Keep-Alive connections (and many browsers are using one-time connections). But you can't rely on this. _(highlight)In any case this is a serious bug, and you should update your Rails to version 2.0.5 or 2.1.2 to eliminate Header Injection (and thus response splitting) risks._ h3. Additional Resources -- cgit v1.2.3 From b825bef74cdde2a29ee050a5ddf4034633abcfe0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 28 Apr 2009 17:58:51 -0700 Subject: Fix missing core extension dependencies --- railties/lib/commands/server.rb | 1 - railties/lib/console_app.rb | 2 ++ railties/lib/rails/plugin.rb | 1 + railties/lib/tasks/misc.rake | 6 +++++- railties/test/abstract_unit.rb | 1 + railties/test/plugin_test_helper.rb | 1 + 6 files changed, 10 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb index ebe34a42cd..91ac7752ef 100644 --- a/railties/lib/commands/server.rb +++ b/railties/lib/commands/server.rb @@ -1,4 +1,3 @@ -require 'active_support' require 'action_controller' require 'fileutils' diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb index d7d01d703f..5c8302634a 100644 --- a/railties/lib/console_app.rb +++ b/railties/lib/console_app.rb @@ -1,3 +1,5 @@ +require 'active_support' +require 'active_support/core/all' require 'active_support/test_case' require 'action_controller' diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 63864058ee..bc28bec57e 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,3 +1,4 @@ +require 'active_support' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/symbol' require 'active_support/dependencies' diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake index 9e6f96db5b..a2c338aa5b 100644 --- a/railties/lib/tasks/misc.rake +++ b/railties/lib/tasks/misc.rake @@ -12,10 +12,10 @@ end desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.' task :secret do + require 'active_support/secure_random' puts ActiveSupport::SecureRandom.hex(64) end -require 'active_support' namespace :time do namespace :zones do desc 'Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6' @@ -30,6 +30,8 @@ namespace :time do desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time' task :local do + require 'active_support' + require 'active_support/core/time' jan_offset = Time.now.beginning_of_year.utc_offset jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset offset = jan_offset < jul_offset ? jan_offset : jul_offset @@ -38,6 +40,8 @@ namespace :time do # to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600 def build_time_zone_list(method, offset = ENV['OFFSET']) + require 'active_support' + require 'active_support/core/time' if offset offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/) sign = $1 == '-' ? -1 : 1 diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 0addcb8bf3..ffd60ee662 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -13,6 +13,7 @@ gem 'mocha', '>= 0.9.5' require 'mocha' require 'active_support' +require 'active_support/core/all' require 'active_support/test_case' if defined?(RAILS_ROOT) diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb index 55d1a1fa96..adb62de665 100644 --- a/railties/test/plugin_test_helper.rb +++ b/railties/test/plugin_test_helper.rb @@ -3,6 +3,7 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" require 'test/unit' require 'active_support' +require 'active_support/core/all' require 'initializer' require File.join(File.dirname(__FILE__), 'abstract_unit') -- cgit v1.2.3 From acd5db300b755d5abae2748f239441fb865c6b62 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 28 Apr 2009 18:21:03 -0700 Subject: Rejig active support dependencies to behave better with the boot process --- railties/lib/initializer.rb | 10 +++++++--- railties/lib/rails/backtrace_cleaner.rb | 3 +++ railties/lib/rails/plugin.rb | 5 ----- railties/test/boot_test.rb | 1 + railties/test/gem_dependency_test.rb | 1 + 5 files changed, 12 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b3b409dc4d..1bd7baed62 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -5,12 +5,9 @@ require 'pathname' $LOAD_PATH.unshift File.dirname(__FILE__) require 'railties_path' require 'rails/version' -require 'rails/plugin/locator' -require 'rails/plugin/loader' require 'rails/gem_dependency' require 'rails/rack' - RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) module Rails @@ -244,6 +241,7 @@ module Rails # Set the paths from which Rails will automatically load source files, and # the load_once paths. def set_autoload_paths + require 'active_support/dependencies' ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq @@ -263,6 +261,8 @@ module Rails # list. By default, all frameworks (Active Record, Active Support, # Action Pack, Action Mailer, and Active Resource) are loaded. def require_frameworks + require 'active_support' + require 'active_support/core/all' configuration.frameworks.each { |framework| require(framework.to_s) } rescue LoadError => e # Re-raise as RuntimeError because Mongrel would swallow LoadError. @@ -289,10 +289,12 @@ module Rails # Adds all load paths from plugins to the global set of load paths, so that # code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies). def add_plugin_load_paths + require 'active_support/dependencies' plugin_loader.add_plugin_load_paths end def add_gem_load_paths + require 'rails/gem_dependency' Rails::GemDependency.add_frozen_gem_path unless @configuration.gems.empty? require "rubygems" @@ -1037,12 +1039,14 @@ Run `rake gems:install` to install the missing gems. end def default_plugin_locators + require 'rails/plugin/locator' locators = [] locators << Plugin::GemLocator if defined? Gem locators << Plugin::FileSystemLocator end def default_plugin_loader + require 'rails/plugin/loader' Plugin::Loader end diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index 923ed8b31d..1605429e8b 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -1,3 +1,6 @@ +require 'active_support/backtrace_cleaner' +require 'rails/gem_dependency' + module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner ERB_METHOD_SIG = /:in `_run_erb_.*/ diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index bc28bec57e..0f924724cd 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -1,8 +1,3 @@ -require 'active_support' -require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/symbol' -require 'active_support/dependencies' - module Rails # The Plugin class should be an object which provides the following methods: # diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 08fcc82e6f..2dd68857c3 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' require 'initializer' require "#{File.dirname(__FILE__)}/../environments/boot" +require 'rails/gem_dependency' class BootTest < Test::Unit::TestCase def test_boot_returns_if_booted diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index d9cd5148a3..da7bda9bee 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -1,4 +1,5 @@ require 'plugin_test_helper' +require 'rails/gem_dependency' class Rails::GemDependency public :install_command, :unpack_command -- cgit v1.2.3 From 599f2cfb4a0e0ec4135265bf5c56b83f1450beea Mon Sep 17 00:00:00 2001 From: David Dollar Date: Wed, 29 Apr 2009 01:22:54 -0400 Subject: Attempt to deal with more cases of gems with native components. This commit adds a rudimentary check for 'unbuilt' gems, so that we can abort the application load if there are any gems that have native components that have not yet been built. The rake task gems:build has now only builds 'unbuilt' gems as a result. The rake task gems:build:force has been added to deal with cases of incomplete builds, or any case where you need to force the build of all of your gems. Changes the gems:build task to get its gem list by parsing directory entries in vendor/gems, which sidesteps the chicken/egg issues involved with having a gem unpacked into vendor/gems without before its native bits are compiled. [#2266 state:committed] Signed-off-by: Jeremy Kemper --- railties/lib/initializer.rb | 21 +++++++++++ railties/lib/rails/gem_dependency.rb | 21 ++++++++--- railties/lib/tasks/gems.rake | 18 ++++++++-- railties/test/gem_dependency_test.rb | 21 +++++++++++ .../vendor/gems/dummy-gem-i-1.0.0/.specification | 41 ++++++++++++++++++++++ .../dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile | 0 .../gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb | 1 + .../vendor/gems/dummy-gem-j-1.0.0/.specification | 41 ++++++++++++++++++++++ .../gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb | 1 + 9 files changed, 159 insertions(+), 6 deletions(-) create mode 100644 railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification create mode 100644 railties/test/vendor/gems/dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile create mode 100644 railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb create mode 100644 railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification create mode 100644 railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb (limited to 'railties') diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 1bd7baed62..71366a4480 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -156,6 +156,8 @@ module Rails add_support_load_paths + check_for_unbuilt_gems + load_gems load_plugins @@ -308,6 +310,25 @@ module Rails end end + def check_for_unbuilt_gems + unbuilt_gems = @configuration.gems.select(&:frozen?).reject(&:built?) + if unbuilt_gems.size > 0 + # don't print if the gems:build rake tasks are being run + unless $gems_build_rake_task + abort <<-end_error +The following gems have native components that need to be built + #{unbuilt_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "} + +You're running: + ruby #{Gem.ruby_version} at #{Gem.ruby} + rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '} + +Run `rake gems:build` to build the unbuilt gems. + end_error + end + end + end + def check_gem_dependencies unloaded_gems = @configuration.gems.reject { |g| g.loaded? } if unloaded_gems.size > 0 diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 3062a77104..ee3d0d81ba 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -29,6 +29,15 @@ module Rails end end + def self.from_directory_name(directory_name) + directory_name_parts = File.basename(directory_name).split('-') + name = directory_name_parts[0..-2].join('-') + version = directory_name_parts.last + self.new(name, :version => version) + rescue ArgumentError => e + raise "Unable to determine gem name and version from '#{directory_name}'" + end + def initialize(name, options = {}) require 'rubygems' unless Object.const_defined?(:Gem) @@ -101,8 +110,12 @@ module Rails end def built? - # TODO: If Rubygems ever gives us a way to detect this, we should use it - false + return false unless frozen? + specification.extensions.each do |ext| + makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile') + return false unless File.exists?(makefile) + end + true end def framework_gem? @@ -155,9 +168,9 @@ module Rails specification && File.exists?(unpacked_gem_directory) end - def build + def build(options={}) require 'rails/gem_builder' - unless built? + if options[:force] || !built? return unless File.exists?(unpacked_specification_filename) spec = YAML::load_file(unpacked_specification_filename) Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake index ed07bf2016..efadb1da3b 100644 --- a/railties/lib/tasks/gems.rake +++ b/railties/lib/tasks/gems.rake @@ -20,8 +20,16 @@ namespace :gems do desc "Build any native extensions for unpacked gems" task :build do $gems_build_rake_task = true - Rake::Task['gems:unpack'].invoke - current_gems.each &:build + frozen_gems.each &:build + end + + namespace :build do + desc "Force the build of all gems" + task :force do + $gems_build_rake_task = true + Rake::Task['gems:unpack'].invoke + current_gems.each { |gem| gem.build(:force => true) } + end end desc "Installs all required gems." @@ -53,6 +61,12 @@ def current_gems gems end +def frozen_gems + Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir| + Rails::GemDependency.from_directory_name(gem_dir) + end +end + def print_gem_status(gem, indent=1) code = case when gem.framework_gem? then 'R' diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index da7bda9bee..4ff4fe8d43 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -145,4 +145,25 @@ class GemDependencyTest < Test::Unit::TestCase end end + def test_gem_from_directory_name + dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1') + assert_equal 'dummy-gem', dummy_gem.name + assert_equal '= 1.1', dummy_gem.version_requirements.to_s + end + + def test_gem_from_invalid_directory_name + assert_raises RuntimeError do + dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem') + end + assert_raises RuntimeError do + dummy_gem = Rails::GemDependency.from_directory_name('dummy') + end + end + + def test_gem_determines_build_status + assert_equal true, Rails::GemDependency.new("dummy-gem-a").built? + assert_equal true, Rails::GemDependency.new("dummy-gem-i").built? + assert_equal false, Rails::GemDependency.new("dummy-gem-j").built? + end + end diff --git a/railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification new file mode 100644 index 0000000000..50b4969da5 --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-i-1.0.0/.specification @@ -0,0 +1,41 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-i +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: dummy-gem-i + type: :runtime + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +extensions: +- ext/dummy-gem-i/extconf.rb +files: +- lib +- lib/dummy-gem-i.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem G diff --git a/railties/test/vendor/gems/dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile b/railties/test/vendor/gems/dummy-gem-i-1.0.0/ext/dummy-gem-i/Makefile new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb b/railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb new file mode 100644 index 0000000000..2f9a376c2c --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-i-1.0.0/lib/dummy-gem-i.rb @@ -0,0 +1 @@ +DUMMY_GEM_I_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification new file mode 100644 index 0000000000..2c456546fc --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-j-1.0.0/.specification @@ -0,0 +1,41 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-j +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: dummy-gem-j + type: :runtime + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +extensions: +- ext/dummy-gem-j/extconf.rb +files: +- lib +- lib/dummy-gem-j.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem G diff --git a/railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb b/railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb new file mode 100644 index 0000000000..8ecd363ff8 --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-j-1.0.0/lib/dummy-gem-j.rb @@ -0,0 +1 @@ +DUMMY_GEM_J_VERSION="1.0.0" -- cgit v1.2.3 From 7149ddd2a109345f8c48c787b5541b9b31a8a6fa Mon Sep 17 00:00:00 2001 From: David Dollar Date: Wed, 29 Apr 2009 10:04:17 -0400 Subject: Additional tests for the gem subsystem * test_gem_ignores_development_dependencies * test_gem_guards_against_duplicate_unpacks * test_gem_does_not_unpack_framework_gems [#2236 state:committed] Signed-off-by: Jeremy Kemper --- railties/test/gem_dependency_test.rb | 21 ++++++++++ .../vendor/gems/dummy-gem-h-1.0.0/.specification | 29 +++++++++++++ .../gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb | 1 + .../vendor/gems/dummy-gem-k-1.0.0/.specification | 49 ++++++++++++++++++++++ .../gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb | 1 + 5 files changed, 101 insertions(+) create mode 100644 railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification create mode 100644 railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb create mode 100644 railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification create mode 100644 railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb (limited to 'railties') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 4ff4fe8d43..ff27af5572 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -145,6 +145,27 @@ class GemDependencyTest < Test::Unit::TestCase end end + def test_gem_ignores_development_dependencies + dummy_gem = Rails::GemDependency.new "dummy-gem-k" + dummy_gem.add_load_paths + dummy_gem.load + assert_equal 1, dummy_gem.dependencies.size + end + + def test_gem_guards_against_duplicate_unpacks + dummy_gem = Rails::GemDependency.new "dummy-gem-a" + dummy_gem.stubs(:frozen?).returns(true) + dummy_gem.expects(:unpack_base).never + dummy_gem.unpack + end + + def test_gem_does_not_unpack_framework_gems + dummy_gem = Rails::GemDependency.new "dummy-gem-a" + dummy_gem.stubs(:framework_gem?).returns(true) + dummy_gem.expects(:unpack_base).never + dummy_gem.unpack + end + def test_gem_from_directory_name dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1') assert_equal 'dummy-gem', dummy_gem.name diff --git a/railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification new file mode 100644 index 0000000000..b3f7930948 --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-h-1.0.0/.specification @@ -0,0 +1,29 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-h +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +files: +- lib +- lib/dummy-gem-h.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem H diff --git a/railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb b/railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb new file mode 100644 index 0000000000..0f91234936 --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-h-1.0.0/lib/dummy-gem-h.rb @@ -0,0 +1 @@ +DUMMY_GEM_H_VERSION="1.0.0" diff --git a/railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification new file mode 100644 index 0000000000..20edd0f856 --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-k-1.0.0/.specification @@ -0,0 +1,49 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-k +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: dummy-gem-k + type: :runtime + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +- !ruby/object:Gem::Dependency + name: dummy-gem-h + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +files: +- lib +- lib/dummy-gem-k.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem I diff --git a/railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb b/railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb new file mode 100644 index 0000000000..97fb1d69ce --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-k-1.0.0/lib/dummy-gem-k.rb @@ -0,0 +1 @@ +DUMMY_GEM_K_VERSION="1.0.0" -- cgit v1.2.3 From 30e6a8a83e65913f870b7b1dbb8fe7ef6f8f220e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 29 Apr 2009 18:19:27 +0100 Subject: More templates --- .../source/rails_application_templates.textile | 232 ++++++++++++++++++++- 1 file changed, 226 insertions(+), 6 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index 49cd5bf5f5..aeb77b0afa 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -1,18 +1,238 @@ h2. Rails Application Templates -This guide covers the Rails application templates, By referring to this guide, you will be able to: +Application templates are simple ruby files containing DSL for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project. + +By referring to this guide, you will be able to: -* Use existing templates to generate a customized Rails application -* Write your own reusable Rails application templates +* Use templates to generate/customize Rails applications +* Write your own reusable application templates using the Rails template API endprologue. -h3. Introduction +h3. Usage -Application templates are simple ruby files containing DSL for adding plugins/gems/initializers etc. to your freshly created Rails project or an existing Rails project. +To apply a template, you need to provide the Rails generator with the location of the template you wish to apply, using -m option : + + +$ rails blog -m ~/template.rb + + +It's also possible to apply a template using a URL : + + +$ rails blog -m http://gist.github.com/31208.txt + + +Alternatively, you can use the rake task +rails:template+ to apply a template to an existing Rails application : + + +$ rake rails:template LOCATION=~/template.rb + + +h3. Template API + +Rails templates API is very self explanatory and easy to understand. Here's an example of a typical Rails template : + + +# template.rb +run "rm public/index.html" +generate(:scaffold, "person name:string") +route "map.root :controller => 'people'" +rake("db:migrate") + +git :init +git :add => "." +git :commit => "-a -m 'Initial commit'" + + +The following sections outlines the primary methods provided by the API : + +h4. gem(name, options = {}) + +Adds a +config.gem+ entry for the supplied gem to generated application’s +config/environment.rb+. + +For example, if your application depends on +bj+ and +hpricot+ : + + +gem "bj" +gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net" + + +Please note that this will NOT install the gems for you. So you may want to run the +rake gems:install+ task too : + + +rake "gems:install" + + +And let Rails take care of installing the required gems if they’re not already installed. + +h4. plugin(name, options = {}) + +Installs a plugin to the generated application. + +Plugin can be installed from Git : + + +plugin 'authentication', :git => 'git://github.com/foor/bar.git' + + +You can even install plugins as git submodules : + + +plugin 'authentication', :git => 'git://github.com/foor/bar.git', + :submodule => true + + +Please note that you need to +git :init+ before you can install a plugin as a submodule. + +Or use plain old SVN : + + +plugin 'wtfsvn' :svn => 'svn://crap.com/wtf/trunk' + + +h4. vendor/lib/file/initializer(filename, data = nil, &block) + +Adds an initializer to the generated application’s +config/initializers+ directory. + +Lets say you like using +Object#not_nil?+ and +Object#not_blank?+ : + + +initializer 'bloatlol.rb', <<-CODE +class Object + def not_nil? + !nil? + end + + def not_blank? + !blank? + end +end +CODE + + +Similarly +lib()+ creates a file in the +lib/+ directory and +vendor()+ creates a file in the +vendor/+ directory. + +There is even +file()+, which accepts a relative path from +RAILS_ROOT+ and creates all the directories/file needed : + + +file 'app/components/foo.rb', <<-CODE +class Foo +end +CODE + + +That’ll create +app/components+ directory and put +foo.rb+ in there. + +h4. rakefile(filename, data = nil, &block) + +Creates a new rake file under +lib/tasks+ with the supplied tasks : + + +rakefile("bootstrap.rake") do + <<-TASK + namespace :boot do + task :strap do + puts "i like boots!" + end + end + TASK +end + + +The above creates +lib/tasks/bootstrap.rake+ with a +boot:strap+ rake task. + +h4. generate(what, args) + +Runs the supplied rails generator with given arguments. For example, I love to scaffold some whenever I’m playing with Rails : + + +generate(:scaffold, "person", "name:string", "address:text", "age:number") + + +h4. run(command) + +Executes an arbitrary command. Just like the backticks. Let's say you want to remove the +public/index.html+ file : + + +run "rm public/index.html" + + +h4. rake(command, options = {}) + +Runs the supplied rake tasks in the Rails application. Let's say you want to migrate the database : + + +rake "db:migrate" + + +You can also run rake tasks with a different Rails environment : + + +rake "db:migrate", :env => 'production' + + +Or even use sudo : + + +rake "gems:install", :sudo => true + + +h4. route(routing_code) + +This adds a routing entry to the +config/routes.rb+ file. In above steps, we generated a person scaffold and also removed +public/index.html+. Now to make +PeopleController#index+ as the default page for the application : + + +route "map.root :controller => :person" + + +h4. inside(dir) + +I have my edge rails lying at +~/commit-rails/rails+. So every time i have to manually symlink edge from my new app. But now : + + +inside('vendor') do + run "ln -s ~/commit-rails/rails rails" +end + + +So +inside()+ runs the command from the given directory. + +h4. ask(question) + ++ask()+ gives you a chance to get some feedback from the user and use it in your templates. Lets say you want your user to name the new shiny library you’re adding : + + +lib_name = ask("What do you want to call the shiny library ?") +lib_name << ".rb" unless lib_name.index(".rb") + +lib lib_name, <<-CODE +class Shiny +end +CODE + + +h4. yes?(question) or no?(question) + +These methods let you ask questions from templates and decide the flow based on the user’s answer. Lets say you want to freeze rails only if the user want to : + + +rake("rails:freeze:gems") if yes?("Freeze rails gems ?") +no?(question) acts just the opposite. + + +h4. git(:must => "-a love") + +Rails templates let you run any git command : + + +git :init +git :add => "." +git :commit => "-a -m 'Initial commit'" + h3. Changelog "Lighthouse ticket":http://rails.lighthouseapp.com/projects/16213-rails-guides/tickets/78 -* April 17, 2009: Initial version by "Pratik":credits.html#lifo +* April 29, 2009: Initial version by "Pratik":credits.html#lifo -- cgit v1.2.3 From 33b9d1aafd6c05920cec8a7bf386a5ec7a56c435 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Wed, 29 Apr 2009 12:50:30 -0500 Subject: Tweak to credits. --- railties/guides/source/credits.erb.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties') diff --git a/railties/guides/source/credits.erb.textile b/railties/guides/source/credits.erb.textile index b09a931fd6..512f4b0809 100644 --- a/railties/guides/source/credits.erb.textile +++ b/railties/guides/source/credits.erb.textile @@ -8,7 +8,7 @@ p. We'd like to thank the following people for their tireless contributions to t

Rails Documentation Team

<% author('Mike Gunderloy', 'mgunderloy') do %> - Mike Gunderloy is a consultant with "ActionRails":http://www.actionrails.com and also a member of the "Rails activism team":http://rubyonrails.org/activists . He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at "A Fresh Cup":http://afreshcup.com and he "twitters":http://twitter.com/MikeG1 too much. + Mike Gunderloy is a consultant with "ActionRails":http://www.actionrails.com. He brings 25 years of experience in a variety of languages to bear on his current work with Rails. His near-daily links and other blogging can be found at "A Fresh Cup":http://afreshcup.com and he "twitters":http://twitter.com/MikeG1 too much. <% end %> <% author('Pratik Naik', 'lifo') do %> -- cgit v1.2.3 From 35ca877abc889d863747726e3da6e359ba928506 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 30 Apr 2009 13:29:13 +0100 Subject: Minor edits --- railties/guides/source/rails_application_templates.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties') diff --git a/railties/guides/source/rails_application_templates.textile b/railties/guides/source/rails_application_templates.textile index aeb77b0afa..3068d0fd7f 100644 --- a/railties/guides/source/rails_application_templates.textile +++ b/railties/guides/source/rails_application_templates.textile @@ -49,9 +49,9 @@ The following sections outlines the primary methods provided by the API : h4. gem(name, options = {}) -Adds a +config.gem+ entry for the supplied gem to generated application’s +config/environment.rb+. +Adds a +config.gem+ entry for the supplied gem to the generated application’s +config/environment.rb+. -For example, if your application depends on +bj+ and +hpricot+ : +For example, if your application depends on the gems +bj+ and +hpricot+ : gem "bj" -- cgit v1.2.3