From bff217272dbdb17f366f9986496ef04e2599d2c2 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 17 Nov 2007 01:39:19 +0000 Subject: RAILS_GEM_VERSION may be set to any valid gem version specifier. Closes #10057. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 2 ++ railties/environments/boot.rb | 4 ++-- railties/test/boot_test.rb | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 86bad736ac..5b3bb07022 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* RAILS_GEM_VERSION may be set to any valid gem version specifier. #10057 [Chad Woolley, Chu Yeow] + * Load config/preinitializer.rb, if present, before loading the environment. #9943 [Chad Woolley] * FastCGI handler ignores unsupported signals like USR2 on Windows. [Grzegorz Derebecki] diff --git a/railties/environments/boot.rb b/railties/environments/boot.rb index 518a8883c1..b71c198db3 100644 --- a/railties/environments/boot.rb +++ b/railties/environments/boot.rb @@ -55,7 +55,7 @@ module Rails def load_rails_gem if version = self.class.gem_version - gem 'rails', "=#{version}" + gem 'rails', version else gem 'rails' end @@ -93,7 +93,7 @@ module Rails end def parse_gem_version(text) - $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([\d.]+)'/ + $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*'([!~<>=]*\s*[\d.]+)'/ end private diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 930a0d552a..375ce52e31 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -96,7 +96,7 @@ class GemBootTest < Test::Unit::TestCase GemBoot.stubs(:gem_version).returns('0.0.1') boot = GemBoot.new - boot.expects(:gem).with('rails', '=0.0.1') + boot.expects(:gem).with('rails', '0.0.1') boot.load_rails_gem end @@ -112,7 +112,7 @@ class GemBootTest < Test::Unit::TestCase GemBoot.stubs(:gem_version).returns('0.0.1') boot = GemBoot.new - boot.expects(:gem).with('rails', '=0.0.1').raises(Gem::LoadError, 'missing rails 0.0.1 gem') + boot.expects(:gem).with('rails', '0.0.1').raises(Gem::LoadError, 'missing rails 0.0.1 gem') STDERR.expects(:puts) boot.expects(:exit).with(1) boot.load_rails_gem @@ -155,6 +155,18 @@ class ParseGemVersionTest < Test::Unit::TestCase assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'\n# RAILS_GEM_VERSION = '9.8.7'") end + def test_should_allow_advanced_rubygems_version_specifications + # See http://rubygems.org/read/chapter/16 + assert_equal "=1.2.3", parse("RAILS_GEM_VERSION = '=1.2.3'") # equal sign + assert_equal "= 1.2.3", parse("RAILS_GEM_VERSION = '= 1.2.3'") # with space + assert_equal "!=1.2.3", parse("RAILS_GEM_VERSION = '!=1.2.3'") # not equal + assert_equal ">1.2.3", parse("RAILS_GEM_VERSION = '>1.2.3'") # greater than + assert_equal "<1.2.3", parse("RAILS_GEM_VERSION = '<1.2.3'") # less than + assert_equal ">=1.2.3", parse("RAILS_GEM_VERSION = '>=1.2.3'") # greater than or equal + assert_equal "<=1.2.3", parse("RAILS_GEM_VERSION = '<=1.2.3'") # less than or equal + assert_equal "~>1.2.3.0", parse("RAILS_GEM_VERSION = '~>1.2.3.0'") # approximately greater than + end + private def parse(text) Rails::GemBoot.parse_gem_version(text) -- cgit v1.2.3