aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-08-10 18:29:20 +0200
committerJosé Valim <jose.valim@gmail.com>2009-08-10 18:29:20 +0200
commit5f7cfffc5377824e03432d7773ed8864a872b18c (patch)
tree53907e2e794798763c800ece8c3c9db8526ef80e /railties/test
parent600a89f2082beadf4af9fe140a1a2ae56386cd49 (diff)
downloadrails-5f7cfffc5377824e03432d7773ed8864a872b18c.tar.gz
rails-5f7cfffc5377824e03432d7773ed8864a872b18c.tar.bz2
rails-5f7cfffc5377824e03432d7773ed8864a872b18c.zip
Use less strict rules in generators lookup, so people can lay their generators wherever they want.
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb2
-rw-r--r--railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb (renamed from railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb)0
-rw-r--r--railties/test/generators/generators_test_helper.rb7
-rw-r--r--railties/test/generators/session_migration_generator_test.rb13
-rw-r--r--railties/test/generators_test.rb19
5 files changed, 29 insertions, 12 deletions
diff --git a/railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb b/railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb
new file mode 100644
index 0000000000..cd477eb4c9
--- /dev/null
+++ b/railties/test/fixtures/vendor/another_gem_path/xspec/lib/generators/xspec_generator.rb
@@ -0,0 +1,2 @@
+class XspecGenerator < Rails::Generators::NamedBase
+end
diff --git a/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb b/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb
index 191bdbf2fc..191bdbf2fc 100644
--- a/railties/test/fixtures/vendor/gems/gems/mspec/lib/generators/mspec_generator.rb
+++ b/railties/test/fixtures/vendor/plugins/mspec/lib/generators/mspec_generator.rb
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index 9444a9ed4b..a258574dce 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -8,9 +8,12 @@ else
RAILS_ROOT = fixtures
end
-$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib"
+$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../actionpack/lib"
require 'generators'
+require 'activerecord'
+require 'action_dispatch'
CURRENT_PATH = File.expand_path(Dir.pwd)
Rails::Generators.no_color!
@@ -19,7 +22,7 @@ class GeneratorsTestCase < Test::Unit::TestCase
include FileUtils
def destination_root
- @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
+ @destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
'..', 'fixtures', 'tmp'))
end
diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb
index 57bd755a9a..293b903b87 100644
--- a/railties/test/generators/session_migration_generator_test.rb
+++ b/railties/test/generators/session_migration_generator_test.rb
@@ -2,16 +2,6 @@ require 'abstract_unit'
require 'generators/generators_test_helper'
require 'generators/rails/session_migration/session_migration_generator'
-module ActiveRecord
- module SessionStore
- class Session
- class << self
- attr_accessor :table_name
- end
- end
- end
-end
-
class SessionMigrationGeneratorTest < GeneratorsTestCase
def test_session_migration_with_default_name
@@ -31,7 +21,10 @@ class SessionMigrationGeneratorTest < GeneratorsTestCase
assert_match /class AddSessionsTable < ActiveRecord::Migration/, migration
assert_match /create_table :custom_table_name/, migration
end
+ ensure
+ ActiveRecord::SessionStore::Session.table_name = "sessions"
end
+
protected
def run_generator(args=[])
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 89d52dd170..4cc0b33521 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -4,6 +4,11 @@ require 'generators/test_unit/model/model_generator'
require 'mocha'
class GeneratorsTest < GeneratorsTestCase
+ def setup
+ Rails::Generators.instance_variable_set(:@load_paths, nil)
+ Gem.stubs(:respond_to?).with(:loaded_specs).returns(false)
+ end
+
def test_invoke_when_generator_is_not_found
output = capture(:stdout){ Rails::Generators.invoke :unknown }
assert_equal "Could not find generator unknown.\n", output
@@ -70,6 +75,20 @@ class GeneratorsTest < GeneratorsTestCase
assert_equal "mspec", klass.namespace
end
+ def test_find_by_namespace_lookup_with_gem_specification
+ assert_nil Rails::Generators.find_by_namespace(:xspec)
+ Rails::Generators.instance_variable_set(:@load_paths, nil)
+
+ spec = Gem::Specification.new
+ spec.expects(:full_gem_path).returns(File.join(RAILS_ROOT, 'vendor', 'another_gem_path', 'xspec'))
+ Gem.expects(:respond_to?).with(:loaded_specs).returns(true)
+ Gem.expects(:loaded_specs).returns(:spec => spec)
+
+ klass = Rails::Generators.find_by_namespace(:xspec)
+ assert klass
+ assert_equal "xspec", klass.namespace
+ end
+
def test_builtin_generators
assert Rails::Generators.builtin.include? %w(rails model)
end