diff options
author | francis <francis> | 2008-01-23 01:48:14 +0000 |
---|---|---|
committer | francis <francis> | 2008-01-23 01:48:14 +0000 |
commit | 60eaae4f7df1f1dae91defb87d3707451c359cf4 (patch) | |
tree | e74835c37779a2f094e810960cda07b99a75330e /vendor/rails-2.0.2/railties/test | |
parent | 71d22c740302e1f83bbbd89b229734ea9c67493c (diff) |
Freeze in rails 2.0.2 (Am I going to regret having this beast in CVS?)
Diffstat (limited to 'vendor/rails-2.0.2/railties/test')
24 files changed, 2032 insertions, 0 deletions
diff --git a/vendor/rails-2.0.2/railties/test/abstract_unit.rb b/vendor/rails-2.0.2/railties/test/abstract_unit.rb new file mode 100644 index 000000000..e1ce32da6 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/abstract_unit.rb @@ -0,0 +1,24 @@ +$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" +$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" +$:.unshift File.dirname(__FILE__) + "/../lib" +$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" + +require 'test/unit' +require 'stringio' +require 'active_support' + +# Wrap tests that use Mocha and skip if unavailable. +def uses_mocha(test_name) + require 'rubygems' + gem 'mocha', '>= 0.5.5' + require 'mocha' + yield +rescue LoadError + $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." +end + +if defined?(RAILS_ROOT) + RAILS_ROOT.replace File.dirname(__FILE__) +else + RAILS_ROOT = File.dirname(__FILE__) +end diff --git a/vendor/rails-2.0.2/railties/test/boot_test.rb b/vendor/rails-2.0.2/railties/test/boot_test.rb new file mode 100644 index 000000000..36fae307c --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/boot_test.rb @@ -0,0 +1,179 @@ +require "#{File.dirname(__FILE__)}/abstract_unit" +require 'initializer' +require "#{File.dirname(__FILE__)}/../environments/boot" + +uses_mocha 'boot tests' do + +class BootTest < Test::Unit::TestCase + def test_boot_returns_if_booted + Rails.expects(:booted?).returns(true) + Rails.expects(:pick_boot).never + assert_nil Rails.boot! + end + + def test_boot_preinitializes_then_picks_and_runs_if_not_booted + Rails.expects(:booted?).returns(false) + Rails.expects(:preinitialize) + Rails.expects(:pick_boot).returns(mock(:run => 'result')) + assert_equal 'result', Rails.boot! + end + + def test_preinitialize_does_not_raise_exception_if_preinitializer_file_does_not_exist + Rails.stubs(:preinitializer_path).returns('/there/is/no/such/file') + + assert_nothing_raised { Rails.preinitialize } + end + + def test_load_preinitializer_loads_preinitializer_file + Rails.stubs(:preinitializer_path).returns("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb") + + assert_nil $initialize_test_set_from_env + Rails.preinitialize + assert_equal "success", $initialize_test_set_from_env + ensure + $initialize_test_set_from_env = nil + end + + def test_boot_vendor_rails_by_default + Rails.expects(:booted?).returns(false) + File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(true) + Rails::VendorBoot.any_instance.expects(:run).returns('result') + assert_equal 'result', Rails.boot! + end + + def test_boot_gem_rails_otherwise + Rails.expects(:booted?).returns(false) + File.expects(:exist?).with("#{RAILS_ROOT}/vendor/rails").returns(false) + Rails::GemBoot.any_instance.expects(:run).returns('result') + assert_equal 'result', Rails.boot! + end + + def test_run_loads_initializer_and_sets_load_path + boot = Rails::Boot.new + boot.expects(:load_initializer) + Rails::Initializer.expects(:run).with(:set_load_path) + boot.run + end +end + +class VendorBootTest < Test::Unit::TestCase + include Rails + + def test_load_initializer_requires_from_vendor_rails + boot = VendorBoot.new + boot.expects(:require).with("#{RAILS_ROOT}/vendor/rails/railties/lib/initializer") + boot.load_initializer + end +end + +class GemBootTest < Test::Unit::TestCase + include Rails + + def test_load_initializer_loads_rubygems_and_the_rails_gem + boot = GemBoot.new + GemBoot.expects(:load_rubygems) + boot.expects(:load_rails_gem) + boot.expects(:require).with('initializer') + boot.load_initializer + end + + def test_load_rubygems_exits_with_error_if_missing + GemBoot.expects(:require).with('rubygems').raises(LoadError, 'missing rubygems') + STDERR.expects(:puts) + GemBoot.expects(:exit).with(1) + GemBoot.load_rubygems + end + + def test_load_rubygems_exits_with_error_if_too_old + GemBoot.stubs(:rubygems_version).returns('0.0.1') + GemBoot.expects(:require).with('rubygems').returns(true) + STDERR.expects(:puts) + GemBoot.expects(:exit).with(1) + GemBoot.load_rubygems + end + + def test_load_rails_gem_activates_specific_gem_if_version_given + GemBoot.stubs(:gem_version).returns('0.0.1') + + boot = GemBoot.new + boot.expects(:gem).with('rails', '0.0.1') + boot.load_rails_gem + end + + def test_load_rails_gem_activates_latest_gem_if_no_version_given + GemBoot.stubs(:gem_version).returns(nil) + + boot = GemBoot.new + boot.expects(:gem).with('rails') + boot.load_rails_gem + end + + def test_load_rails_gem_exits_with_error_if_missing + 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') + STDERR.expects(:puts) + boot.expects(:exit).with(1) + boot.load_rails_gem + end +end + +end # uses_mocha + + +class ParseGemVersionTest < Test::Unit::TestCase + def test_should_return_nil_if_no_lines_are_passed + assert_equal nil, parse('') + assert_equal nil, parse(nil) + end + + def test_should_accept_either_single_or_double_quotes + assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'") + assert_equal "1.2.3", parse('RAILS_GEM_VERSION = "1.2.3"') + end + + def test_should_return_nil_if_no_lines_match + assert_equal nil, parse('nothing matches on this line\nor on this line') + end + + def test_should_parse_with_no_leading_space + assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION") + assert_equal "1.2.3", parse("RAILS_GEM_VERSION = '1.2.3'") + end + + def test_should_parse_with_any_number_of_leading_spaces + assert_equal nil, parse([]) + assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION") + assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION") + assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3'") + assert_equal "1.2.3", parse(" RAILS_GEM_VERSION = '1.2.3'") + end + + def test_should_ignore_unrelated_comments + assert_equal "1.2.3", parse("# comment\nRAILS_GEM_VERSION = '1.2.3'\n# comment") + end + + def test_should_ignore_commented_version_lines + assert_equal "1.2.3", parse("#RAILS_GEM_VERSION = '9.8.7'\nRAILS_GEM_VERSION = '1.2.3'") + assert_equal "1.2.3", parse("# RAILS_GEM_VERSION = '9.8.7'\nRAILS_GEM_VERSION = '1.2.3'") + 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) + end +end diff --git a/vendor/rails-2.0.2/railties/test/console_app_test.rb b/vendor/rails-2.0.2/railties/test/console_app_test.rb new file mode 100644 index 000000000..ac499e0f1 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/console_app_test.rb @@ -0,0 +1,29 @@ +require File.dirname(__FILE__) + '/abstract_unit' + +require 'action_controller' # console_app uses 'action_controller/integration' + +unless defined? ApplicationController + class ApplicationController < ActionController::Base; end +end + +require 'dispatcher' +require 'console_app' + +# console_app sets Test::Unit.run to work around the at_exit hook in test/unit, which kills IRB +Test::Unit.run = false + +class ConsoleAppTest < Test::Unit::TestCase + def test_reload_should_fire_preparation_callbacks + a = b = c = nil + + Dispatcher.to_prepare { a = b = c = 1 } + Dispatcher.to_prepare { b = c = 2 } + Dispatcher.to_prepare { c = 3 } + + reload! + + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c + end +end diff --git a/vendor/rails-2.0.2/railties/test/fcgi_dispatcher_test.rb b/vendor/rails-2.0.2/railties/test/fcgi_dispatcher_test.rb new file mode 100644 index 000000000..7949cb652 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fcgi_dispatcher_test.rb @@ -0,0 +1,265 @@ +require File.dirname(__FILE__) + "/abstract_unit" + +uses_mocha 'fcgi dispatcher tests' do + +require 'fcgi_handler' + +module ActionController; module Routing; module Routes; end end end + +class RailsFCGIHandlerTest < Test::Unit::TestCase + def setup + @log = StringIO.new + @handler = RailsFCGIHandler.new(@log) + end + + def test_process_restart + cgi = mock + FCGI.stubs(:each_cgi).yields(cgi) + + @handler.expects(:process_request).once + @handler.expects(:dispatcher_error).never + + @handler.expects(:when_ready).returns(:restart) + @handler.expects(:close_connection).with(cgi) + @handler.expects(:reload!).never + @handler.expects(:restart!) + + @handler.process! + end + + def test_process_exit + cgi = mock + FCGI.stubs(:each_cgi).yields(cgi) + + @handler.expects(:process_request).once + @handler.expects(:dispatcher_error).never + + @handler.expects(:when_ready).returns(:exit) + @handler.expects(:close_connection).with(cgi) + @handler.expects(:reload!).never + @handler.expects(:restart!).never + + @handler.process! + end + + def test_process_with_system_exit_exception + cgi = mock + FCGI.stubs(:each_cgi).yields(cgi) + + @handler.expects(:process_request).once.raises(SystemExit) + @handler.stubs(:dispatcher_log) + @handler.expects(:dispatcher_log).with(:info, regexp_matches(/^stopping/)) + @handler.expects(:dispatcher_error).never + + @handler.expects(:when_ready).never + @handler.expects(:close_connection).never + @handler.expects(:reload!).never + @handler.expects(:restart!).never + + @handler.process! + end + + def test_restart_handler + @handler.expects(:dispatcher_log).with(:info, "asked to restart ASAP") + + @handler.send(:restart_handler, nil) + assert_equal :restart, @handler.when_ready + end + + def test_install_signal_handler_should_log_on_bad_signal + @handler.stubs(:trap).raises(ArgumentError) + + @handler.expects(:dispatcher_log).with(:warn, "Ignoring unsupported signal CHEESECAKE.") + @handler.send(:install_signal_handler, "CHEESECAKE", nil) + end + + def test_reload + @handler.expects(:restore!) + @handler.expects(:dispatcher_log).with(:info, "reloaded") + + @handler.send(:reload!) + assert_nil @handler.when_ready + end + + + def test_reload_runs_gc_when_gc_request_period_set + @handler.expects(:run_gc!) + @handler.expects(:restore!) + @handler.expects(:dispatcher_log).with(:info, "reloaded") + @handler.gc_request_period = 10 + @handler.send(:reload!) + end + + def test_reload_doesnt_run_gc_if_gc_request_period_isnt_set + @handler.expects(:run_gc!).never + @handler.expects(:restore!) + @handler.expects(:dispatcher_log).with(:info, "reloaded") + @handler.send(:reload!) + end + + def test_restart! + @handler.expects(:dispatcher_log).with(:info, "restarted") + @handler.expects(:exec).returns('restarted') + assert_equal 'restarted', @handler.send(:restart!) + end + + def test_restore! + $".expects(:replace) + Dispatcher.expects(:reset_application!) + ActionController::Routing::Routes.expects(:reload) + @handler.send(:restore!) + end + + def test_uninterrupted_processing + cgi = mock + FCGI.expects(:each_cgi).yields(cgi) + @handler.expects(:process_request).with(cgi) + + @handler.process! + + assert_nil @handler.when_ready + end +end + + +class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase + def setup + @log = StringIO.new + @handler = RailsFCGIHandler.new(@log) + end + + def test_interrupted_via_HUP_when_not_in_request + cgi = mock + FCGI.expects(:each_cgi).once.yields(cgi) + @handler.expects(:gc_countdown).returns { Process.kill 'HUP', $$ } + + @handler.expects(:reload!).once + @handler.expects(:close_connection).never + @handler.expects(:exit).never + + @handler.process! + assert_equal :reload, @handler.when_ready + end + + def test_interrupted_via_HUP_when_in_request + cgi = mock + FCGI.expects(:each_cgi).once.yields(cgi) + Dispatcher.expects(:dispatch).with(cgi).returns { Process.kill 'HUP', $$ } + + @handler.expects(:reload!).once + @handler.expects(:close_connection).never + @handler.expects(:exit).never + + @handler.process! + assert_equal :reload, @handler.when_ready + end + + def test_interrupted_via_USR1_when_not_in_request + cgi = mock + FCGI.expects(:each_cgi).once.yields(cgi) + @handler.expects(:gc_countdown).returns { Process.kill 'USR1', $$ } + @handler.expects(:exit_handler).never + + @handler.expects(:reload!).never + @handler.expects(:close_connection).with(cgi).once + @handler.expects(:exit).never + + @handler.process! + assert_nil @handler.when_ready + end + + def test_interrupted_via_USR1_when_in_request + cgi = mock + FCGI.expects(:each_cgi).once.yields(cgi) + Dispatcher.expects(:dispatch).with(cgi).returns { Process.kill 'USR1', $$ } + + @handler.expects(:reload!).never + @handler.expects(:close_connection).with(cgi).once + @handler.expects(:exit).never + + @handler.process! + assert_equal :exit, @handler.when_ready + end + + def test_interrupted_via_TERM + cgi = mock + FCGI.expects(:each_cgi).once.yields(cgi) + Dispatcher.expects(:dispatch).with(cgi).returns { Process.kill 'TERM', $$ } + + @handler.expects(:reload!).never + @handler.expects(:close_connection).never + + @handler.process! + assert_nil @handler.when_ready + end + + def test_runtime_exception_in_fcgi + error = RuntimeError.new('foo') + FCGI.expects(:each_cgi).times(2).raises(error) + @handler.expects(:dispatcher_error).with(error, regexp_matches(/^retrying/)) + @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) + @handler.process! + end + + def test_runtime_error_in_dispatcher + cgi = mock + error = RuntimeError.new('foo') + FCGI.expects(:each_cgi).once.yields(cgi) + Dispatcher.expects(:dispatch).once.with(cgi).raises(error) + @handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/)) + @handler.process! + end + + def test_signal_exception_in_fcgi + error = SignalException.new('USR2') + FCGI.expects(:each_cgi).once.raises(error) + @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) + @handler.process! + end + + def test_signal_exception_in_dispatcher + cgi = mock + error = SignalException.new('USR2') + FCGI.expects(:each_cgi).once.yields(cgi) + Dispatcher.expects(:dispatch).once.with(cgi).raises(error) + @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) + @handler.process! + end +end + + +class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase + def setup + @log = StringIO.new + end + + def teardown + GC.enable + end + + def test_normal_gc + @handler = RailsFCGIHandler.new(@log) + assert_nil @handler.gc_request_period + + # When GC is enabled, GC.disable disables and returns false. + assert_equal false, GC.disable + end + + def test_periodic_gc + @handler = RailsFCGIHandler.new(@log, 10) + assert_equal 10, @handler.gc_request_period + + cgi = mock + FCGI.expects(:each_cgi).times(10).yields(cgi) + Dispatcher.expects(:dispatch).times(10).with(cgi) + + @handler.expects(:run_gc!).never + 9.times { @handler.process! } + @handler.expects(:run_gc!).once + @handler.process! + + assert_nil @handler.when_ready + end +end + +end # uses_mocha diff --git a/vendor/rails-2.0.2/railties/test/fixtures/environment_with_constant.rb b/vendor/rails-2.0.2/railties/test/fixtures/environment_with_constant.rb new file mode 100644 index 000000000..23e1f7afd --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fixtures/environment_with_constant.rb @@ -0,0 +1 @@ +$initialize_test_set_from_env = 'success' diff --git a/vendor/rails-2.0.2/railties/test/fixtures/lib/generators/missing_class/missing_class_generator.rb b/vendor/rails-2.0.2/railties/test/fixtures/lib/generators/missing_class/missing_class_generator.rb new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fixtures/lib/generators/missing_class/missing_class_generator.rb diff --git a/vendor/rails-2.0.2/railties/test/fixtures/lib/generators/working/working_generator.rb b/vendor/rails-2.0.2/railties/test/fixtures/lib/generators/working/working_generator.rb new file mode 100644 index 000000000..465b34319 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fixtures/lib/generators/working/working_generator.rb @@ -0,0 +1,2 @@ +class WorkingGenerator < Rails::Generator::NamedBase +end diff --git a/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb b/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/plugin_with_no_lib_dir/init.rb diff --git a/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/stubby/init.rb b/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/stubby/init.rb new file mode 100644 index 000000000..81beeb0d3 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/stubby/init.rb @@ -0,0 +1,7 @@ +# I have access to my directory and the Rails config. +raise 'directory expected but undefined in init.rb' unless defined? directory +raise 'config expected but undefined in init.rb' unless defined? config + +# My lib/ dir must be in the load path. +require 'stubby_mixin' +raise 'missing mixin from my lib/ dir' unless defined? StubbyMixin diff --git a/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb b/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb new file mode 100644 index 000000000..2d569e500 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb @@ -0,0 +1,2 @@ +module StubbyMixin +end diff --git a/vendor/rails-2.0.2/railties/test/generators/generator_test_helper.rb b/vendor/rails-2.0.2/railties/test/generators/generator_test_helper.rb new file mode 100644 index 000000000..3af5886a0 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/generators/generator_test_helper.rb @@ -0,0 +1,195 @@ +module GeneratorTestHelper + # Instantiates the Generator + def build_generator(name,params) + Rails::Generator::Base.instance(name,params) + end + + # Runs the create command (like the command line does) + def run_generator(name,params) + silence_generator do + build_generator(name,params).command(:create).invoke! + end + end + + # Silences the logger temporarily and returns the output as a String + def silence_generator + logger_original=Rails::Generator::Base.logger + myout=StringIO.new + Rails::Generator::Base.logger=Rails::Generator::SimpleLogger.new(myout) + yield if block_given? + Rails::Generator::Base.logger=logger_original + myout.string + end + + # asserts that the given controller was generated. + # It takes a name or symbol without the <tt>_controller</tt> part and an optional super class. + # The contents of the class source file is passed to a block. + def assert_generated_controller_for(name,parent="ApplicationController") + assert_generated_class "app/controllers/#{name.to_s.underscore}_controller",parent do |body| + yield body if block_given? + end + end + + # asserts that the given model was generated. + # It takes a name or symbol and an optional super class. + # the contents of the class source file is passed to a block. + def assert_generated_model_for(name,parent="ActiveRecord::Base") + assert_generated_class "app/models/#{name.to_s.underscore}",parent do |body| + yield body if block_given? + end + end + + # asserts that the given helper was generated. + # It takes a name or symbol without the <tt>_helper</tt> part + # the contents of the module source file is passed to a block. + def assert_generated_helper_for(name) + assert_generated_module "app/helpers/#{name.to_s.underscore}_helper" do |body| + yield body if block_given? + end + end + + # asserts that the given functional test was generated. + # It takes a name or symbol without the <tt>_controller_test</tt> part and an optional super class. + # the contents of the class source file is passed to a block. + def assert_generated_functional_test_for(name,parent="Test::Unit::TestCase") + assert_generated_class "test/functional/#{name.to_s.underscore}_controller_test",parent do |body| + yield body if block_given? + end + end + + # asserts that the given unit test was generated. + # It takes a name or symbol without the <tt>_test</tt> part and an optional super class. + # the contents of the class source file is passed to a block. + def assert_generated_unit_test_for(name,parent="Test::Unit::TestCase") + assert_generated_class "test/unit/#{name.to_s.underscore}_test",parent do |body| + yield body if block_given? + end + end + + # asserts that the given file was generated. + # the contents of the file is passed to a block. + def assert_generated_file(path) + assert_file_exists(path) + File.open("#{RAILS_ROOT}/#{path}") do |f| + yield f.read if block_given? + end + end + + # asserts that the given file exists + def assert_file_exists(path) + assert File.exist?("#{RAILS_ROOT}/#{path}"),"The file '#{path}' should exist" + end + + # asserts that the given class source file was generated. + # It takes a path without the <tt>.rb</tt> part and an optional super class. + # the contents of the class source file is passed to a block. + def assert_generated_class(path,parent=nil) + path=~/\/?(\d+_)?(\w+)$/ + class_name=$2.camelize + assert_generated_file("#{path}.rb") do |body| + assert body=~/class #{class_name}#{parent.nil? ? '':" < #{parent}"}/,"the file '#{path}.rb' should be a class" + yield body if block_given? + end + end + + # asserts that the given module source file was generated. + # It takes a path without the <tt>.rb</tt> part. + # the contents of the class source file is passed to a block. + def assert_generated_module(path) + path=~/\/?(\w+)$/ + module_name=$1.camelize + assert_generated_file("#{path}.rb") do |body| + assert body=~/module #{module_name}/,"the file '#{path}.rb' should be a module" + yield body if block_given? + end + end + + # asserts that the given css stylesheet file was generated. + # It takes a path without the <tt>.css</tt> part. + # the contents of the stylesheet source file is passed to a block. + def assert_generated_stylesheet(path) + assert_generated_file("public/stylesheets/#{path}.css") do |body| + yield body if block_given? + end + end + + # asserts that the given yaml file was generated. + # It takes a path without the <tt>.yml</tt> part. + # the parsed yaml tree is passed to a block. + def assert_generated_yaml(path) + assert_generated_file("#{path}.yml") do |body| + assert yaml=YAML.load(body) + yield yaml if block_given? + end + end + + # asserts that the given fixtures yaml file was generated. + # It takes a fixture name without the <tt>.yml</tt> part. + # the parsed yaml tree is passed to a block. + def assert_generated_fixtures_for(name) + assert_generated_yaml "test/fixtures/#{name.to_s.underscore}" do |yaml| + assert_generated_timestamps(yaml) + yield yaml if block_given? + end + end + + # asserts that the given views were generated. + # It takes a controller name and a list of views (including extensions). + # The body of each view is passed to a block + def assert_generated_views_for(name,*actions) + actions.each do |action| + assert_generated_file("app/views/#{name.to_s.underscore}/#{action.to_s}") do |body| + yield body if block_given? + end + end + end + + # asserts that the given migration file was generated. + # It takes the name of the migration as a parameter. + # The migration body is passed to a block. + def assert_generated_migration(name,parent="ActiveRecord::Migration") + assert_generated_class "db/migrate/001_#{name.to_s.underscore}",parent do |body| + assert body=~/timestamps/, "should have timestamps defined" + yield body if block_given? + end + end + + # Asserts that the given migration file was not generated. + # It takes the name of the migration as a parameter. + def assert_skipped_migration(name) + migration_file = "#{RAILS_ROOT}/db/migrate/001_#{name.to_s.underscore}.rb" + assert !File.exist?(migration_file), "should not create migration #{migration_file}" + end + + # asserts that the given resource was added to the routes. + def assert_added_route_for(name) + assert_generated_file("config/routes.rb") do |body| + assert body=~/map.resources :#{name.to_s.underscore}/,"should add route for :#{name.to_s.underscore}" + end + end + + # asserts that the given methods are defined in the body. + # This does assume standard rails code conventions with regards to the source code. + # The body of each individual method is passed to a block. + def assert_has_method(body,*methods) + methods.each do |name| + assert body=~/^ def #{name.to_s}\n((\n| .*\n)*) end/,"should have method #{name.to_s}" + yield( name, $1 ) if block_given? + end + end + + # asserts that the given column is defined in the migration + def assert_generated_column(body,name,type) + assert body=~/t\.#{type.to_s} :#{name.to_s}/, "should have column #{name.to_s} defined" + end + + private + # asserts that the default timestamps are created in the fixture + def assert_generated_timestamps(yaml) + yaml.values.each do |v| + ["created_at", "updated_at"].each do |field| + assert v.keys.include?(field), "should have #{field} field by default" + end + end + end +end diff --git a/vendor/rails-2.0.2/railties/test/generators/rails_model_generator_test.rb b/vendor/rails-2.0.2/railties/test/generators/rails_model_generator_test.rb new file mode 100644 index 000000000..a1637c4cd --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/generators/rails_model_generator_test.rb @@ -0,0 +1,109 @@ +require 'test/unit' + +# Optionally load RubyGems +begin + require 'rubygems' +rescue LoadError +end + +# Mock out what we need from AR::Base +module ActiveRecord + class Base + class << self + attr_accessor :pluralize_table_names + end + self.pluralize_table_names = true + end + + module ConnectionAdapters + class Column + attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale + def initialize(name, default, sql_type=nil) + @namename + @default=default + @type=@sql_type=sql_type + end + + def human_name + @name.humanize + end + end + end +end + +# Mock up necessities from ActionView +module ActionView + module Helpers + module ActionRecordHelper; end + class InstanceTag; end + end +end + +# Set RAILS_ROOT appropriately fixture generation +tmp_dir="#{File.dirname(__FILE__)}/../fixtures/tmp" +if defined?(RAILS_ROOT) + RAILS_ROOT.replace(tmp_dir) +else + RAILS_ROOT=tmp_dir +end +Dir.mkdir(RAILS_ROOT) unless File.exist?(RAILS_ROOT) + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" +require 'rails_generator' +require "#{File.dirname(__FILE__)}/generator_test_helper" + +class RailsModelGeneratorTest < Test::Unit::TestCase + include GeneratorTestHelper + + def setup + ActiveRecord::Base.pluralize_table_names = true + Dir.mkdir("#{RAILS_ROOT}/app") unless File.exist?("#{RAILS_ROOT}/app") + Dir.mkdir("#{RAILS_ROOT}/app/views") unless File.exist?("#{RAILS_ROOT}/app/views") + Dir.mkdir("#{RAILS_ROOT}/app/views/layouts") unless File.exist?("#{RAILS_ROOT}/app/views/layouts") + Dir.mkdir("#{RAILS_ROOT}/config") unless File.exist?("#{RAILS_ROOT}/config") + Dir.mkdir("#{RAILS_ROOT}/db") unless File.exist?("#{RAILS_ROOT}/db") + Dir.mkdir("#{RAILS_ROOT}/test") unless File.exist?("#{RAILS_ROOT}/test") + Dir.mkdir("#{RAILS_ROOT}/test/fixtures") unless File.exist?("#{RAILS_ROOT}/test/fixtures") + Dir.mkdir("#{RAILS_ROOT}/public") unless File.exist?("#{RAILS_ROOT}/public") + Dir.mkdir("#{RAILS_ROOT}/public/stylesheets") unless File.exist?("#{RAILS_ROOT}/public/stylesheets") + File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f| + f<<"ActionController::Routing::Routes.draw do |map|\n\nend\n" + end + end + + def teardown + FileUtils.rm_rf "#{RAILS_ROOT}/app" + FileUtils.rm_rf "#{RAILS_ROOT}/test" + FileUtils.rm_rf "#{RAILS_ROOT}/config" + FileUtils.rm_rf "#{RAILS_ROOT}/db" + FileUtils.rm_rf "#{RAILS_ROOT}/public" + end + + def test_model_generates_resources + run_generator('model', %w(Product)) + + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_generated_migration :create_products + end + + def test_model_skip_migration_skips_migration + run_generator('model', %w(Product --skip-migration)) + + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_skipped_migration :create_products + end + + def test_model_with_attributes_generates_resources_with_attributes + run_generator('model', %w(Product name:string supplier_id:integer created_at:timestamp)) + + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_generated_migration :create_products do |t| + assert_generated_column t, :name, :string + assert_generated_column t, :supplier_id, :integer + assert_generated_column t, :created_at, :timestamp + end + end +end diff --git a/vendor/rails-2.0.2/railties/test/generators/rails_resource_generator_test.rb b/vendor/rails-2.0.2/railties/test/generators/rails_resource_generator_test.rb new file mode 100644 index 000000000..63cd284d3 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/generators/rails_resource_generator_test.rb @@ -0,0 +1,106 @@ +require 'test/unit' + +# Optionally load RubyGems +begin + require 'rubygems' +rescue LoadError +end + +# Mock out what we need from AR::Base +module ActiveRecord + class Base + class << self + attr_accessor :pluralize_table_names + end + self.pluralize_table_names = true + end + + module ConnectionAdapters + class Column + attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale + def initialize(name, default, sql_type=nil) + @namename + @default=default + @type=@sql_type=sql_type + end + + def human_name + @name.humanize + end + end + end +end + +# Mock up necessities from ActionView +module ActionView + module Helpers + module ActionRecordHelper; end + class InstanceTag; end + end +end + +# Set RAILS_ROOT appropriately fixture generation +tmp_dir="#{File.dirname(__FILE__)}/../fixtures/tmp" +if defined?(RAILS_ROOT) + RAILS_ROOT.replace(tmp_dir) +else + RAILS_ROOT=tmp_dir +end +Dir.mkdir(RAILS_ROOT) unless File.exist?(RAILS_ROOT) + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" +require 'rails_generator' +require "#{File.dirname(__FILE__)}/generator_test_helper" + +class RailsResourceGeneratorTest < Test::Unit::TestCase + include GeneratorTestHelper + + def setup + ActiveRecord::Base.pluralize_table_names = true + Dir.mkdir("#{RAILS_ROOT}/app") unless File.exist?("#{RAILS_ROOT}/app") + Dir.mkdir("#{RAILS_ROOT}/app/views") unless File.exist?("#{RAILS_ROOT}/app/views") + Dir.mkdir("#{RAILS_ROOT}/app/views/layouts") unless File.exist?("#{RAILS_ROOT}/app/views/layouts") + Dir.mkdir("#{RAILS_ROOT}/config") unless File.exist?("#{RAILS_ROOT}/config") + Dir.mkdir("#{RAILS_ROOT}/db") unless File.exist?("#{RAILS_ROOT}/db") + Dir.mkdir("#{RAILS_ROOT}/test") unless File.exist?("#{RAILS_ROOT}/test") + Dir.mkdir("#{RAILS_ROOT}/test/fixtures") unless File.exist?("#{RAILS_ROOT}/test/fixtures") + Dir.mkdir("#{RAILS_ROOT}/public") unless File.exist?("#{RAILS_ROOT}/public") + Dir.mkdir("#{RAILS_ROOT}/public/stylesheets") unless File.exist?("#{RAILS_ROOT}/public/stylesheets") + File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f| + f<<"ActionController::Routing::Routes.draw do |map|\n\nend\n" + end + end + + def teardown + FileUtils.rm_rf "#{RAILS_ROOT}/app" + FileUtils.rm_rf "#{RAILS_ROOT}/test" + FileUtils.rm_rf "#{RAILS_ROOT}/config" + FileUtils.rm_rf "#{RAILS_ROOT}/db" + FileUtils.rm_rf "#{RAILS_ROOT}/public" + end + + def test_resource_generates_resources + run_generator('scaffold', %w(Product)) + + assert_generated_controller_for :products + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_generated_functional_test_for :products + assert_generated_helper_for :products + assert_generated_migration :create_products + assert_added_route_for :products + end + + def test_resource_skip_migration_skips_migration + run_generator('resource', %w(Product --skip-migration)) + + assert_generated_controller_for :products + assert_generated_model_for :product + assert_generated_fixtures_for :products + assert_generated_functional_test_for :products + assert_generated_helper_for :products + assert_skipped_migration :create_products + assert_added_route_for :products + end + +end diff --git a/vendor/rails-2.0.2/railties/test/generators/rails_scaffold_generator_test.rb b/vendor/rails-2.0.2/railties/test/generators/rails_scaffold_generator_test.rb new file mode 100644 index 000000000..16588affa --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/generators/rails_scaffold_generator_test.rb @@ -0,0 +1,185 @@ +require 'test/unit' + +# Optionally load RubyGems. +begin + require 'rubygems' +rescue LoadError +end + +# Mock out what we need from AR::Base. +module ActiveRecord + class Base + class << self + attr_accessor :pluralize_table_names + end + self.pluralize_table_names = true + end + + module ConnectionAdapters + class Column + attr_reader :name, :default, :type, :limit, :null, :sql_type, :precision, :scale + + def initialize(name, default, sql_type = nil) + @name=name + @default=default + @type=@sql_type=sql_type + end + + def human_name + @name.humanize + end + end + end +end + +# And what we need from ActionView +module ActionView + module Helpers + module ActiveRecordHelper; end + class InstanceTag; end + end +end + + +# Must set before requiring generator libs. +tmp_dir="#{File.dirname(__FILE__)}/../fixtures/tmp" +if defined?(RAILS_ROOT) + RAILS_ROOT.replace(tmp_dir) +else + RAILS_ROOT=tmp_dir +end +Dir.mkdir(RAILS_ROOT) unless File.exist?(RAILS_ROOT) + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" +require 'rails_generator' +require "#{File.dirname(__FILE__)}/generator_test_helper" + +class RailsScaffoldGeneratorTest < Test::Unit::TestCase + + include GeneratorTestHelper + + def setup + ActiveRecord::Base.pluralize_table_names = true + Dir.mkdir("#{RAILS_ROOT}/app") unless File.exist?("#{RAILS_ROOT}/app") + Dir.mkdir("#{RAILS_ROOT}/app/views") unless File.exist?("#{RAILS_ROOT}/app/views") + Dir.mkdir("#{RAILS_ROOT}/app/views/layouts") unless File.exist?("#{RAILS_ROOT}/app/views/layouts") + Dir.mkdir("#{RAILS_ROOT}/config") unless File.exist?("#{RAILS_ROOT}/config") + Dir.mkdir("#{RAILS_ROOT}/db") unless File.exist?("#{RAILS_ROOT}/db") + Dir.mkdir("#{RAILS_ROOT}/test") unless File.exist?("#{RAILS_ROOT}/test") + Dir.mkdir("#{RAILS_ROOT}/test/fixtures") unless File.exist?("#{RAILS_ROOT}/test/fixtures") + Dir.mkdir("#{RAILS_ROOT}/public") unless File.exist?("#{RAILS_ROOT}/public") + Dir.mkdir("#{RAILS_ROOT}/public/stylesheets") unless File.exist?("#{RAILS_ROOT}/public/stylesheets") + File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f| + f<<"ActionController::Routing::Routes.draw do |map|\n\nend\n" + end + end + + def teardown + FileUtils.rm_rf "#{RAILS_ROOT}/app" + FileUtils.rm_rf "#{RAILS_ROOT}/test" + FileUtils.rm_rf "#{RAILS_ROOT}/config" + FileUtils.rm_rf "#{RAILS_ROOT}/db" + FileUtils.rm_rf "#{RAILS_ROOT}/public" + end + + def test_scaffolded_names + g = Rails::Generator::Base.instance('scaffold', %w(ProductLine)) + assert_equal "ProductLines", g.controller_name + assert_equal "ProductLines", g.controller_class_name + assert_equal "ProductLine", g.controller_singular_name + assert_equal "product_lines", g.controller_plural_name + assert_equal "product_lines", g.controller_file_name + assert_equal "product_lines", g.controller_table_name + end + + def test_scaffold_generates_resources + + run_generator('scaffold', %w(Product)) + + assert_generated_controller_for :products do |f| + + assert_has_method f, :index do |name, m| + assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + end + + assert_has_method f, :show, :edit, :update, :destroy do |name, m| + assert_match /@product = Product\.find\(params\[:id\]\)/, m, "#{name.to_s} should query products table" + end + + assert_has_method f, :new do |name, m| + assert_match /@product = Product\.new/, m, "#{name.to_s} should instantiate a product" + end + + assert_has_method f, :create do |name, m| + assert_match /@product = Product\.new\(params\[:product\]\)/, m, "#{name.to_s} should instantiate a product" + assert_match /format.xml \{ render :xml => @product.errors, :status => :unprocessable_entity \}/, m, "#{name.to_s} should set status to :unprocessable_entity code for xml" + end + + end + + assert_generated_model_for :product + assert_generated_functional_test_for :products + assert_generated_unit_test_for :product + assert_generated_fixtures_for :products + assert_generated_helper_for :products + assert_generated_stylesheet :scaffold + assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb" + assert_generated_migration :create_products + assert_added_route_for :products + end + + def test_scaffold_skip_migration_skips_migration + run_generator('scaffold', %w(Product --skip-migration)) + + assert_generated_model_for :product + assert_generated_functional_test_for :products + assert_generated_unit_test_for :product + assert_generated_fixtures_for :products + assert_generated_helper_for :products + assert_generated_stylesheet :scaffold + assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" + assert_skipped_migration :create_products + assert_added_route_for :products + end + + def test_scaffold_generates_resources_with_attributes + run_generator('scaffold', %w(Product name:string supplier_id:integer created_at:timestamp)) + + assert_generated_controller_for :products do |f| + + assert_has_method f, :index do |name, m| + assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + end + + assert_has_method f, :show, :edit, :update, :destroy do |name, m| + assert_match /@product = Product\.find\(params\[:id\]\)/, m, "#{name.to_s} should query products table" + end + + assert_has_method f, :new do |name, m| + assert_match /@product = Product\.new/, m, "#{name.to_s} should instantiate a product" + end + + assert_has_method f, :create do |name, m| + assert_match /@product = Product\.new\(params\[:product\]\)/, m, "#{name.to_s} should instantiate a product" + assert_match /format.xml \{ render :xml => @product.errors, :status => :unprocessable_entity \}/, m, "#{name.to_s} should set status to :unprocessable_entity code for xml" + end + + end + + assert_generated_model_for :product + assert_generated_functional_test_for :products + assert_generated_unit_test_for :product + assert_generated_fixtures_for :products + assert_generated_helper_for :products + assert_generated_stylesheet :scaffold + assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb" + assert_generated_migration :create_products do |t| + assert_generated_column t, :name, :string + assert_generated_column t, :supplier_id, :integer + assert_generated_column t, :created_at, :timestamp + end + + assert_added_route_for :products + end + +end diff --git a/vendor/rails-2.0.2/railties/test/initializer_test.rb b/vendor/rails-2.0.2/railties/test/initializer_test.rb new file mode 100644 index 000000000..156f670e8 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/initializer_test.rb @@ -0,0 +1,218 @@ +require "#{File.dirname(__FILE__)}/abstract_unit" +require 'initializer' + +class ConfigurationMock < Rails::Configuration + attr_reader :environment_path + + def initialize(envpath) + super() + @environment_path = envpath + end +end + +class Initializer_load_environment_Test < Test::Unit::TestCase + + def test_load_environment_with_constant + config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb") + assert_nil $initialize_test_set_from_env + Rails::Initializer.run(:load_environment, config) + assert_equal "success", $initialize_test_set_from_env + ensure + $initialize_test_set_from_env = nil + end + +end + +class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase + def setup + config = ConfigurationMock.new("") + config.after_initialize do + $test_after_initialize_block1 = "success" + end + config.after_initialize do + $test_after_initialize_block2 = "congratulations" + end + assert_nil $test_after_initialize_block1 + assert_nil $test_after_initialize_block2 + + Rails::Initializer.run(:after_initialize, config) + end + + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil + end + + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1 + end + + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end +end + +class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase + + def setup + config = ConfigurationMock.new("") + config.after_initialize do + $test_after_initialize_block1 = "success" + end + config.after_initialize # don't pass a block, this is what we're testing! + config.after_initialize do + $test_after_initialize_block2 = "congratulations" + end + assert_nil $test_after_initialize_block1 + + Rails::Initializer.run(:after_initialize, config) + end + + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil + end + + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1, "should still get set" + end + + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end + +end + +uses_mocha 'framework paths' do + class ConfigurationFrameworkPathsTests < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks.clear + + File.stubs(:directory?).returns(true) + @config.stubs(:framework_root_path).returns('') + end + + def test_minimal + expected = %w( + /railties + /railties/lib + /activesupport/lib + ) + assert_equal expected, @config.framework_paths + end + + def test_actioncontroller_or_actionview_add_actionpack + @config.frameworks << :action_controller + assert_framework_path '/actionpack/lib' + + @config.frameworks = [:action_view] + assert_framework_path '/actionpack/lib' + end + + def test_paths_for_ar_ares_and_mailer + [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| + @config.frameworks = [framework] + assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib" + end + end + + def test_unknown_framework_raises_error + @config.frameworks << :action_foo + initializer = Rails::Initializer.new @config + initializer.expects(:require).raises(LoadError) + + assert_raise RuntimeError do + initializer.send :require_frameworks + end + end + + protected + + def assert_framework_path(path) + assert @config.framework_paths.include?(path), + "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" + end + end +end + +uses_mocha "Initializer plugin loading tests" do + require File.dirname(__FILE__) + '/plugin_test_helper' + + class InitializerPluginLoadingTests < Test::Unit::TestCase + def setup + @configuration = Rails::Configuration.new + @configuration.plugin_paths << plugin_fixture_root_path + @initializer = Rails::Initializer.new(@configuration) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') + end + + def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list + only_load_the_following_plugins! [] + @initializer.load_plugins + assert_equal [], @initializer.loaded_plugins + end + + def test_only_the_specified_plugins_are_located_in_the_order_listed + plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] + only_load_the_following_plugins! plugin_names + load_plugins! + assert_plugins plugin_names, @initializer.loaded_plugins + end + + def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + load_plugins! + assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip + end + + def test_all_plugins_loaded_when_all_is_used + plugin_names = [:stubby, :acts_as_chunky_bacon, :all] + only_load_the_following_plugins! plugin_names + load_plugins! + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + end + + def test_all_plugins_loaded_after_all + plugin_names = [:stubby, :all, :acts_as_chunky_bacon] + only_load_the_following_plugins! plugin_names + load_plugins! + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip + end + + def test_plugin_names_may_be_strings + plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + only_load_the_following_plugins! plugin_names + load_plugins! + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins plugin_names, @initializer.loaded_plugins, failure_tip + end + + def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error + only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin] + assert_raises(LoadError) do + load_plugins! + end + end + + def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + + @initializer.add_plugin_load_paths + + assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end + + private + + def load_plugins! + @initializer.add_plugin_load_paths + @initializer.load_plugins + end + end + +end diff --git a/vendor/rails-2.0.2/railties/test/mocks/routes.rb b/vendor/rails-2.0.2/railties/test/mocks/routes.rb new file mode 100644 index 000000000..ea1286368 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/mocks/routes.rb @@ -0,0 +1,6 @@ +module ActionController + module Routing + class Routes + end + end +end diff --git a/vendor/rails-2.0.2/railties/test/plugin_loader_test.rb b/vendor/rails-2.0.2/railties/test/plugin_loader_test.rb new file mode 100644 index 000000000..fe77de447 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/plugin_loader_test.rb @@ -0,0 +1,140 @@ +require File.dirname(__FILE__) + '/plugin_test_helper' + +uses_mocha "Plugin Loader Tests" do + + class TestPluginLoader < Test::Unit::TestCase + ORIGINAL_LOAD_PATH = $LOAD_PATH.dup + + def setup + reset_load_path! + + @configuration = Rails::Configuration.new + @configuration.plugin_paths << plugin_fixture_root_path + @initializer = Rails::Initializer.new(@configuration) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') + + @loader = Rails::Plugin::Loader.new(@initializer) + end + + def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result + locator_1 = stub(:plugins => [:a, :b, :c]) + locator_2 = stub(:plugins => [:d, :e, :f]) + locator_class_1 = stub(:new => locator_1) + locator_class_2 = stub(:new => locator_2) + @configuration.plugin_locators = [locator_class_1, locator_class_2] + assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins) + end + + def test_should_memoize_the_result_of_locate_plugins_as_all_plugins + plugin_list = [:a, :b, :c] + @loader.expects(:locate_plugins).once.returns(plugin_list) + assert_equal plugin_list, @loader.all_plugins + assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again + end + + def test_should_return_empty_array_if_configuration_plugins_is_empty + @configuration.plugins = [] + assert_equal [], @loader.plugins + end + + def test_should_find_all_availble_plugins_and_return_as_all_plugins + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.all_plugins, failure_tip + end + + def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, failure_tip + end + + def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil + @configuration.plugins = nil + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, failure_tip + end + + def test_should_return_specific_plugins_named_in_config_plugins_array_if_set + plugin_names = [:acts_as_chunky_bacon, :stubby] + only_load_the_following_plugins! plugin_names + assert_plugins plugin_names, @loader.plugins + end + + def test_should_respect_the_order_of_plugins_given_in_configuration + plugin_names = [:stubby, :acts_as_chunky_bacon] + only_load_the_following_plugins! plugin_names + assert_plugins plugin_names, @loader.plugins + end + + def test_should_load_all_plugins_in_natural_order_when_all_is_used + only_load_the_following_plugins! [:all] + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, failure_tip + end + + def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, failure_tip + end + + def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all + only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, failure_tip + end + + def test_should_accept_plugin_names_given_as_strings + only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, failure_tip + end + + def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + stubbed_application_lib_index_in_LOAD_PATHS = 5 + @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) + + @loader.add_plugin_load_paths + + assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS + assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS + end + + def test_should_add_plugin_load_paths_to_Dependencies_load_paths + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + + @loader.add_plugin_load_paths + + assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end + + def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + + @loader.add_plugin_load_paths + + assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end + + def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array + plugin_load_paths = ["a", "b"] + plugin = stub(:load_paths => plugin_load_paths) + @loader.stubs(:plugins).returns([plugin]) + + @loader.add_plugin_load_paths + + plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) } + end + + private + + def reset_load_path! + $LOAD_PATH.clear + ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } + end + end + +end
\ No newline at end of file diff --git a/vendor/rails-2.0.2/railties/test/plugin_locator_test.rb b/vendor/rails-2.0.2/railties/test/plugin_locator_test.rb new file mode 100644 index 000000000..ccd270dd1 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/plugin_locator_test.rb @@ -0,0 +1,69 @@ +require File.dirname(__FILE__) + '/plugin_test_helper' + +uses_mocha "Plugin Locator Tests" do + + class PluginLocatorTest < Test::Unit::TestCase + + def test_should_require_subclasses_to_implement_the_plugins_method + assert_raises(RuntimeError) do + Rails::Plugin::Locator.new(nil).plugins + end + end + + def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each + locator = Rails::Plugin::Locator.new(nil) + locator.stubs(:plugins).returns([:a, :b, :c]) + plugin_consumer = mock + plugin_consumer.expects(:consume).with(:a) + plugin_consumer.expects(:consume).with(:b) + plugin_consumer.expects(:consume).with(:c) + + locator.each do |plugin| + plugin_consumer.consume(plugin) + end + end + + end + + + class PluginFileSystemLocatorTest < Test::Unit::TestCase + def setup + @configuration = Rails::Configuration.new + # We need to add our testing plugin directory to the plugin paths so + # the locator knows where to look for our plugins + @configuration.plugin_paths << plugin_fixture_root_path + @initializer = Rails::Initializer.new(@configuration) + @locator = Rails::Plugin::FileSystemLocator.new(@initializer) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') + end + + def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory + assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path) + end + + def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory + assert_nil @locator.send(:create_plugin, @empty_plugin_path) + end + + def test_should_return_all_plugins_found_under_the_set_plugin_paths + assert_equal ["a", "acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"], @locator.plugins.map(&:name) + end + + def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration + @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")] + assert_equal ["acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"], @locator.plugins.map(&:name) + + @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] + assert_equal ["a"], @locator.plugins.map(&:name) + end + + def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist + @configuration.plugin_paths = ["some_missing_directory"] + assert_nothing_raised do + assert @locator.plugins.empty? + end + end + end + +end # uses_mocha
\ No newline at end of file diff --git a/vendor/rails-2.0.2/railties/test/plugin_test.rb b/vendor/rails-2.0.2/railties/test/plugin_test.rb new file mode 100644 index 000000000..0f08c314d --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/plugin_test.rb @@ -0,0 +1,141 @@ +require File.dirname(__FILE__) + '/plugin_test_helper' + +uses_mocha "Plugin Tests" do + + class PluginTest < Test::Unit::TestCase + + def setup + @initializer = Rails::Initializer.new(Rails::Configuration.new) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') + end + + def test_should_determine_plugin_name_from_the_directory_of_the_plugin + assert_equal 'stubby', plugin_for(@valid_plugin_path).name + assert_equal 'empty', plugin_for(@empty_plugin_path).name + end + + def test_should_not_be_loaded_when_created + assert !plugin_for(@valid_plugin_path).loaded? + end + + def test_should_be_marked_as_loaded_when_load_is_called + plugin = plugin_for(@valid_plugin_path) + assert !plugin.loaded? + plugin.stubs(:evaluate_init_rb) + assert_nothing_raised do + plugin.send(:load, anything) + end + assert plugin.loaded? + end + + def test_should_determine_validity_of_given_path + # This is a plugin path, with a lib dir + assert plugin_for(@valid_plugin_path).valid? + # This just has an init.rb and no lib dir + assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid? + # This would be a plugin path, but the directory is empty + assert !plugin_for(plugin_fixture_path('default/empty')).valid? + # This is a non sense path + assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid? + end + + def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory + assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths + end + + def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory + expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib') + assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths + end + + def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin + assert_nothing_raised do + plugin_for(@valid_plugin_path).load_paths + end + + assert_raises(LoadError) do + plugin_for(@empty_plugin_path).load_paths + end + + assert_raises(LoadError) do + plugin_for('this_is_not_a_plugin_directory').load_paths + end + end + + def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin + # This path is fine so nothing is raised + assert_nothing_raised do + plugin = plugin_for(@valid_plugin_path) + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) + end + + # This is an empty path so it raises + assert_raises(LoadError) do + plugin = plugin_for(@empty_plugin_path) + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) + end + + assert_raises(LoadError) do + plugin = plugin_for('this_is_not_a_plugin_directory') + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) + end + end + + def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin + # This path is fine so nothing is raised + assert_nothing_raised do + plugin_for(@valid_plugin_path).load_paths + end + + # This is an empty path so it raises + assert_raises(LoadError) do + plugin_for(@empty_plugin_path).load_paths + end + + assert_raises(LoadError) do + plugin_for('this_is_not_a_plugin_directory').load_paths + end + end + + def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs + failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already." + assert !defined?(StubbyMixin), failure_tip + plugin = plugin_for(@valid_plugin_path) + plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) } + # The init.rb of this plugin raises if it doesn't have access to all the things it needs + assert_nothing_raised do + plugin.load(@initializer) + end + assert defined?(StubbyMixin) + end + + def test_should_sort_naturally_by_name + a = plugin_for("path/a") + b = plugin_for("path/b") + z = plugin_for("path/z") + assert_equal [a, b, z], [b, z, a].sort + end + + def test_should_only_be_loaded_once + plugin = plugin_for(@valid_plugin_path) + assert !plugin.loaded? + plugin.expects(:evaluate_init_rb) + assert_nothing_raised do + plugin.send(:load, @initializer) + plugin.send(:load, @initializer) + end + assert plugin.loaded? + end + + private + + def plugin_for(path) + Rails::Plugin.new(path) + end + end + +end # uses_mocha
\ No newline at end of file diff --git a/vendor/rails-2.0.2/railties/test/plugin_test_helper.rb b/vendor/rails-2.0.2/railties/test/plugin_test_helper.rb new file mode 100644 index 000000000..f8c094d19 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/plugin_test_helper.rb @@ -0,0 +1,29 @@ +$:.unshift File.dirname(__FILE__) + "/../lib" +$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" + +require 'test/unit' +require 'active_support' +require 'initializer' +require File.join(File.dirname(__FILE__), 'abstract_unit') + +# We need to set RAILS_ROOT if it isn't already set +RAILS_ROOT = '.' unless defined?(RAILS_ROOT) + +class Test::Unit::TestCase + private + def plugin_fixture_root_path + File.join(File.dirname(__FILE__), 'fixtures', 'plugins') + end + + def only_load_the_following_plugins!(plugins) + @initializer.configuration.plugins = plugins + end + + def plugin_fixture_path(path) + File.join(plugin_fixture_root_path, path) + end + + def assert_plugins(list_of_names, array_of_plugins, message=nil) + assert_equal list_of_names.map(&:to_s), array_of_plugins.map(&:name), message + end +end
\ No newline at end of file diff --git a/vendor/rails-2.0.2/railties/test/rails_generator_test.rb b/vendor/rails-2.0.2/railties/test/rails_generator_test.rb new file mode 100644 index 000000000..51d02312b --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/rails_generator_test.rb @@ -0,0 +1,137 @@ +require 'test/unit' + +# Optionally load RubyGems. +begin + require 'rubygems' +rescue LoadError +end + +# Mock out what we need from AR::Base. +module ActiveRecord + class Base + class << self + attr_accessor :pluralize_table_names + end + self.pluralize_table_names = true + end +end + +# And what we need from ActionView +module ActionView + module Helpers + module ActiveRecordHelper; end + class InstanceTag; end + end +end + + +# Must set before requiring generator libs. +if defined?(RAILS_ROOT) + RAILS_ROOT.replace "#{File.dirname(__FILE__)}/fixtures" +else + RAILS_ROOT = "#{File.dirname(__FILE__)}/fixtures" +end + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" +require 'rails_generator' + + +class RailsGeneratorTest < Test::Unit::TestCase + BUILTINS = %w(controller integration_test mailer migration model observer plugin resource scaffold session_migration) + CAPITALIZED_BUILTINS = BUILTINS.map { |b| b.capitalize } + + def setup + ActiveRecord::Base.pluralize_table_names = true + end + + def test_sources + expected = [:lib, :vendor, + :plugins, :plugins, # <plugin>/generators and <plugin>/rails_generators + :user, + :RubyGems, :RubyGems, # gems named <x>_generator, gems containing /rails_generator/ folder + :builtin] + expected.delete(:RubyGems) unless Object.const_defined?(:Gem) + assert_equal expected, Rails::Generator::Base.sources.map { |s| s.label } + end + + def test_lookup_builtins + (BUILTINS + CAPITALIZED_BUILTINS).each do |name| + assert_nothing_raised do + spec = Rails::Generator::Base.lookup(name) + assert_not_nil spec + assert_kind_of Rails::Generator::Spec, spec + + klass = spec.klass + assert klass < Rails::Generator::Base + assert_equal spec, klass.spec + end + end + end + + def test_autolookup + assert_nothing_raised { ControllerGenerator } + assert_nothing_raised { ModelGenerator } + end + + def test_lookup_missing_generator + assert_raise(MissingSourceFile) { + Rails::Generator::Base.lookup('missing_generator').klass + } + end + + def test_lookup_missing_class + spec = nil + assert_nothing_raised { spec = Rails::Generator::Base.lookup('missing_class') } + assert_not_nil spec + assert_kind_of Rails::Generator::Spec, spec + assert_raise(NameError) { spec.klass } + end + + def test_generator_usage + (BUILTINS - ["session_migration"]).each do |name| + assert_raise(Rails::Generator::UsageError, "Generator '#{name}' should raise an error without arguments") { + Rails::Generator::Base.instance(name) + } + end + end + + def test_generator_spec + spec = Rails::Generator::Base.lookup('working') + assert_equal 'working', spec.name + assert_equal "#{RAILS_ROOT}/lib/generators/working", spec.path + assert_equal :lib, spec.source + assert_nothing_raised { assert_match(/WorkingGenerator$/, spec.klass.name) } + end + + def test_named_generator_attributes + g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz)) + assert_equal 'admin/foo', g.name + assert_equal %w(admin), g.class_path + assert_equal 'Admin', g.class_nesting + assert_equal 'Admin::Foo', g.class_name + assert_equal 'foo', g.singular_name + assert_equal 'foos', g.plural_name + assert_equal g.singular_name, g.file_name + assert_equal "admin_#{g.plural_name}", g.table_name + assert_equal %w(bar baz), g.args + end + + def test_named_generator_attributes_without_pluralized + ActiveRecord::Base.pluralize_table_names = false + g = Rails::Generator::Base.instance('working', %w(admin/foo bar baz)) + assert_equal "admin_#{g.singular_name}", g.table_name + end + + def test_session_migration_generator_with_pluralization + g = Rails::Generator::Base.instance('session_migration') + assert_equal 'session'.pluralize, g.send(:default_session_table_name) + ActiveRecord::Base.pluralize_table_names = false + assert_equal 'session', g.send(:default_session_table_name) + end + + def test_scaffold_controller_name + # Default behaviour is use the model name + g = Rails::Generator::Base.instance('scaffold', %w(Product)) + assert_equal "Products", g.controller_name + end +end diff --git a/vendor/rails-2.0.2/railties/test/rails_info_controller_test.rb b/vendor/rails-2.0.2/railties/test/rails_info_controller_test.rb new file mode 100644 index 000000000..b73ce5a09 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/rails_info_controller_test.rb @@ -0,0 +1,48 @@ +require "#{File.dirname(__FILE__)}/abstract_unit" +require 'action_controller' +require 'action_controller/test_process' + +module Rails; end +require 'rails/info' +require 'rails/info_controller' + +class Rails::InfoController < ActionController::Base + @local_request = false + class << self + cattr_accessor :local_request + end + + # Re-raise errors caught by the controller. + def rescue_action(e) raise e end; + +protected + def local_request? + self.class.local_request + end +end + +ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' +end + +class Rails::InfoControllerTest < Test::Unit::TestCase + def setup + @controller = Rails::InfoController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_rails_info_properties_table_rendered_for_local_request + Rails::InfoController.local_request = true + get :properties + assert_tag :tag => 'table' + assert_response :success + end + + def test_rails_info_properties_error_rendered_for_non_local_request + Rails::InfoController.local_request = false + get :properties + assert_tag :tag => 'p' + assert_response 500 + end +end diff --git a/vendor/rails-2.0.2/railties/test/rails_info_test.rb b/vendor/rails-2.0.2/railties/test/rails_info_test.rb new file mode 100644 index 000000000..a21204658 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/rails_info_test.rb @@ -0,0 +1,105 @@ +$:.unshift File.dirname(__FILE__) + "/../lib" +$:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" +$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" + +require 'test/unit' +require 'active_support' + +unless defined?(Rails) && defined?(Rails::Info) + module Rails + class Info; end + end +end + +class InfoTest < Test::Unit::TestCase + def setup + Rails.send :remove_const, :Info + 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 +Path: . +URL: http://www.rubyonrails.com/svn/rails/trunk +Repository UUID: 5ecf4fe2-1ee6-0310-87b1-e25e094e27de +Revision: 2881 +Node Kind: directory +Schedule: normal +Last Changed Author: sam +Last Changed Rev: 2881 +Last Changed Date: 2005-11-04 21:04:41 -0600 (Fri, 04 Nov 2005) +Properties Last Updated: 2005-10-28 19:30:00 -0500 (Fri, 28 Oct 2005) + +EOS + end + + assert_property 'Test Edge Rails revision', '2881' + end + + def test_property_with_block_swallows_exceptions_and_ignores_property + assert_nothing_raised do + Rails::Info.module_eval do + property('Bogus') {raise} + end + end + assert !property_defined?('Bogus') + end + + def test_property_with_string + Rails::Info.module_eval do + property 'Hello', 'World' + end + assert_property 'Hello', 'World' + end + + def test_property_with_block + Rails::Info.module_eval do + property('Goodbye') {'World'} + end + assert_property 'Goodbye', 'World' + end + + def test_component_version + assert_property 'Active Support version', ActiveSupport::VERSION::STRING + end + + def test_components_exist + Rails::Info.components.each do |component| + dir = File.dirname(__FILE__) + "/../../" + component.gsub('_', '') + assert File.directory?(dir), "#{component.classify} does not exist" + end + end + +protected + def svn_info=(info) + Rails::Info.module_eval do + class << self + def svn_info + info + end + end + end + end + + def properties + Rails::Info.properties + end + + def property_defined?(property_name) + properties.names.include? property_name + end + + def assert_property(property_name, value) + raise "Property #{property_name.inspect} not defined" unless + property_defined? property_name + assert_equal value, properties.value_for(property_name) + end +end diff --git a/vendor/rails-2.0.2/railties/test/secret_key_generation_test.rb b/vendor/rails-2.0.2/railties/test/secret_key_generation_test.rb new file mode 100644 index 000000000..093436889 --- /dev/null +++ b/vendor/rails-2.0.2/railties/test/secret_key_generation_test.rb @@ -0,0 +1,35 @@ +require 'test/unit' + +# Must set before requiring generator libs. +if defined?(RAILS_ROOT) + RAILS_ROOT.replace "#{File.dirname(__FILE__)}/fixtures" +else + RAILS_ROOT = "#{File.dirname(__FILE__)}/fixtures" +end + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" + +require 'rails_generator' +require 'rails_generator/secret_key_generator' +require 'rails_generator/generators/applications/app/app_generator' + +class SecretKeyGenerationTest < Test::Unit::TestCase + SECRET_KEY_MIN_LENGTH = 128 + APP_NAME = "foo" + + def setup + @generator = Rails::SecretKeyGenerator.new(APP_NAME) + end + + def test_secret_key_generation + assert @generator.generate_secret.length >= SECRET_KEY_MIN_LENGTH + end + + Rails::SecretKeyGenerator::GENERATORS.each do |generator| + if Rails::SecretKeyGenerator.send("supports_#{generator}?") + define_method("test_secret_key_generation_with_#{generator}") do + assert @generator.send("generate_secret_with_#{generator}").length >= SECRET_KEY_MIN_LENGTH + end + end + end +end |