aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/gem_dependency_test.rb
diff options
context:
space:
mode:
authorMatt Jones <al2o3cr@gmail.com>2008-10-04 13:51:23 -0400
committerrick <technoweenie@gmail.com>2008-10-05 10:16:17 -0700
commit2bf58aa782d3b493f2d98f153324b93c5b058ba6 (patch)
tree53278af87e3590bb901754b2e2f8ce1d13d49d73 /railties/test/gem_dependency_test.rb
parent4f53db0096be4b167628a136044b0d1262215277 (diff)
downloadrails-2bf58aa782d3b493f2d98f153324b93c5b058ba6.tar.gz
rails-2bf58aa782d3b493f2d98f153324b93c5b058ba6.tar.bz2
rails-2bf58aa782d3b493f2d98f153324b93c5b058ba6.zip
Fix a number of errors in the config.gem mechanism.
* Rails::GemDependency was missing definitions for hash and eql?, causing Array#uniq to not work. * If several versions of a gem are unpacked in vendor, now chooses the highest if no version is specified. * streamlined add_load_path. Now sets up Rubygems correctly to allow 'gem' to find frozen gems, with gems frozen to vendor/gems and specifications in vendor/gems/<gem-name>/.specification * Rails::GemDependency#specification would return a spec for the highest installed version, even for frozen gems and/or previously loaded lower versions. See in part ticket #1123. * removed vendor from default_load_paths - it was causing autoloading to append Gems::Gems::<gem-dir> to constant names * added additional tests for loading frozen gems. * incorporates the fix from #1107 for vendor rails * defers to freeze:gems for handling the Rails framework. gems:unpack WILL NOT place a copy of Rails in vendor/gems. Should close #1123 completely. * incorporates, via using the gem loader for frozen gems, fixes corresponding to #227, #324, #362, #527, and #742. * gem plugins now work the same whether frozen or not. Correctness of the behavior is a matter for another ticket... Signed-off-by: rick <technoweenie@gmail.com>
Diffstat (limited to 'railties/test/gem_dependency_test.rb')
-rw-r--r--railties/test/gem_dependency_test.rb49
1 files changed, 44 insertions, 5 deletions
diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb
index c94c950455..89e25341d1 100644
--- a/railties/test/gem_dependency_test.rb
+++ b/railties/test/gem_dependency_test.rb
@@ -37,39 +37,78 @@ uses_mocha "Plugin Tests" do
end
def test_gem_with_version_unpack_install_command
+ # stub out specification method, or else test will fail if hpricot 0.6 isn't installed
+ mock_spec = mock()
+ mock_spec.stubs(:version).returns('0.6')
+ @gem_with_version.stubs(:specification).returns(mock_spec)
assert_equal ["unpack", "hpricot", "--version", '= 0.6'], @gem_with_version.unpack_command
end
def test_gem_adds_load_paths
- @gem.expects(:gem).with(@gem.name)
+ @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil))
@gem.add_load_paths
end
def test_gem_with_version_adds_load_paths
- @gem_with_version.expects(:gem).with(@gem_with_version.name, @gem_with_version.requirement.to_s)
+ @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s))
@gem_with_version.add_load_paths
end
def test_gem_loading
- @gem.expects(:gem).with(@gem.name)
+ @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil))
@gem.expects(:require).with(@gem.name)
@gem.add_load_paths
@gem.load
end
def test_gem_with_lib_loading
- @gem_with_lib.expects(:gem).with(@gem_with_lib.name)
+ @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil))
@gem_with_lib.expects(:require).with(@gem_with_lib.lib)
@gem_with_lib.add_load_paths
@gem_with_lib.load
end
def test_gem_without_lib_loading
- @gem_without_load.expects(:gem).with(@gem_without_load.name)
+ @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil))
@gem_without_load.expects(:require).with(@gem_without_load.lib).never
@gem_without_load.add_load_paths
@gem_without_load.load
end
+ def test_gem_dependencies_compare_for_uniq
+ gem1 = Rails::GemDependency.new "gem1"
+ gem1a = Rails::GemDependency.new "gem1"
+ gem2 = Rails::GemDependency.new "gem2"
+ gem2a = Rails::GemDependency.new "gem2"
+ gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1"
+ gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1"
+ gem4 = Rails::GemDependency.new "gem3"
+ gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4]
+ assert_equal 4, gems.uniq.size
+ end
+
+ def test_gem_load_frozen
+ dummy_gem = Rails::GemDependency.new "dummy-gem-a"
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_A_VERSION
+ end
+
+ def test_gem_load_frozen_specific_version
+ dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0'
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_B_VERSION
+ assert_equal '0.4.0', DUMMY_GEM_B_VERSION
+ end
+
+ def test_gem_load_frozen_minimum_version
+ dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0'
+ dummy_gem.add_load_paths
+ dummy_gem.load
+ assert_not_nil DUMMY_GEM_C_VERSION
+ assert_equal '0.6.0', DUMMY_GEM_C_VERSION
+ end
+
end
end