From 986aec5dbbdfb578945e706cbe6a54c4f06640e5 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 17 Apr 2008 23:49:03 +0100 Subject: Refactor Dispatcher callbacks to remove unnecessary Dependencies checks in production environment. --- railties/test/console_app_test.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'railties/test') diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb index 7615d95498..6cfc907b80 100644 --- a/railties/test/console_app_test.rb +++ b/railties/test/console_app_test.rb @@ -13,17 +13,20 @@ require 'console_app' Test::Unit.run = false class ConsoleAppTest < Test::Unit::TestCase - def test_reload_should_fire_preparation_callbacks - a = b = c = nil + uses_mocha 'console reload test' do + 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 } + Dispatcher.to_prepare { a = b = c = 1 } + Dispatcher.to_prepare { b = c = 2 } + Dispatcher.to_prepare { c = 3 } + ActionController::Routing::Routes.expects(:reload) - reload! + reload! - assert_equal 1, a - assert_equal 2, b - assert_equal 3, c + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c + end end end -- cgit v1.2.3 From dfdb9f738e9842752c340634622624544efe18c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 18 Apr 2008 17:10:58 -0500 Subject: Cleanup generator tests by extracting repeated code into generator_test_helper. Add test for mailer generator. Signed-off-by: Joshua Peek --- railties/test/generators/generator_test_helper.rb | 159 ++++++++++---- .../test/generators/rails_mailer_generator_test.rb | 26 +++ .../test/generators/rails_model_generator_test.rb | 80 +------ .../generators/rails_resource_generator_test.rb | 78 +------ .../generators/rails_scaffold_generator_test.rb | 240 +++++++-------------- 5 files changed, 225 insertions(+), 358 deletions(-) create mode 100644 railties/test/generators/rails_mailer_generator_test.rb (limited to 'railties/test') diff --git a/railties/test/generators/generator_test_helper.rb b/railties/test/generators/generator_test_helper.rb index 4007cf16ca..190bc91d52 100644 --- a/railties/test/generators/generator_test_helper.rb +++ b/railties/test/generators/generator_test_helper.rb @@ -1,3 +1,51 @@ +require 'test/unit' +require 'fileutils' + +# 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 + +# 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 +FileUtils.mkdir_p RAILS_ROOT + +$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" require 'initializer' # Mocks out the configuration @@ -9,35 +57,62 @@ end require 'rails_generator' +class GeneratorTestCase < Test::Unit::TestCase + include FileUtils + + def setup + ActiveRecord::Base.pluralize_table_names = true + + mkdir_p "#{RAILS_ROOT}/app/views/layouts" + mkdir_p "#{RAILS_ROOT}/config" + mkdir_p "#{RAILS_ROOT}/db" + mkdir_p "#{RAILS_ROOT}/test/fixtures" + mkdir_p "#{RAILS_ROOT}/public/stylesheets" + + File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f| + f << "ActionController::Routing::Routes.draw do |map|\n\nend" + end + end -module GeneratorTestHelper + def teardown + rm_rf "#{RAILS_ROOT}/app" + rm_rf "#{RAILS_ROOT}/test" + rm_rf "#{RAILS_ROOT}/config" + rm_rf "#{RAILS_ROOT}/db" + rm_rf "#{RAILS_ROOT}/public" + end + + def test_truth + # don't complain, test/unit + end + # Instantiates the Generator - def build_generator(name,params) - Rails::Generator::Base.instance(name,params) + 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) + def run_generator(name, params) silence_generator do - build_generator(name,params).command(:create).invoke! + 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) + 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 + Rails::Generator::Base.logger = logger_original myout.string end # asserts that the given controller was generated. # It takes a name or symbol without the _controller 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| + 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 @@ -45,8 +120,8 @@ module GeneratorTestHelper # 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| + 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 @@ -63,7 +138,7 @@ module GeneratorTestHelper # asserts that the given functional test was generated. # It takes a name or symbol without the _controller_test 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="ActionController::TestCase") + def assert_generated_functional_test_for(name, parent = "ActionController::TestCase") assert_generated_class "test/functional/#{name.to_s.underscore}_controller_test",parent do |body| yield body if block_given? end @@ -72,8 +147,8 @@ module GeneratorTestHelper # asserts that the given unit test was generated. # It takes a name or symbol without the _test 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="ActiveSupport::TestCase") - assert_generated_class "test/unit/#{name.to_s.underscore}_test",parent do |body| + def assert_generated_unit_test_for(name, parent = "ActiveSupport::TestCase") + assert_generated_class "test/unit/#{name.to_s.underscore}_test", parent do |body| yield body if block_given? end end @@ -89,17 +164,18 @@ module GeneratorTestHelper # asserts that the given file exists def assert_file_exists(path) - assert File.exist?("#{RAILS_ROOT}/#{path}"),"The file '#{RAILS_ROOT}/#{path}' should exist" + assert File.exist?("#{RAILS_ROOT}/#{path}"), + "The file '#{RAILS_ROOT}/#{path}' should exist" end # asserts that the given class source file was generated. # It takes a path without the .rb 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 + 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" + assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class" yield body if block_given? end end @@ -108,10 +184,10 @@ module GeneratorTestHelper # It takes a path without the .rb part. # the contents of the class source file is passed to a block. def assert_generated_module(path) - path=~/\/?(\w+)$/ - module_name=$1.camelize + 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" + assert_match /module #{module_name}/, body, "the file '#{path}.rb' should be a module" yield body if block_given? end end @@ -130,7 +206,8 @@ module GeneratorTestHelper # 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) + yaml = YAML.load(body) + assert yaml, 'YAML data missing' yield yaml if block_given? end end @@ -147,23 +224,22 @@ module GeneratorTestHelper # 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) + 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| + assert_generated_file("app/views/#{name.to_s.underscore}/#{action}") do |body| yield body if block_given? end end end - def assert_generated_migration(name,parent="ActiveRecord::Migration") - file = - Dir.glob("#{RAILS_ROOT}/db/migrate/*_#{name.to_s.underscore}.rb").first - file = file.match(/db\/migrate\/[0-9]+_#{name.to_s.underscore}/).to_s - assert_generated_class file,parent do |body| - assert body=~/timestamps/, "should have timestamps defined" - yield body if block_given? - end + def assert_generated_migration(name, parent = "ActiveRecord::Migration") + file = Dir.glob("#{RAILS_ROOT}/db/migrate/*_#{name.to_s.underscore}.rb").first + file = file.match(/db\/migrate\/[0-9]+_\w+/).to_s + assert_generated_class file, parent do |body| + assert_match /timestamps/, body, "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. @@ -175,22 +251,23 @@ module GeneratorTestHelper # 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}" + assert_match /map.resources :#{name.to_s.underscore}/, body, + "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) + 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? + assert body =~ /^ def #{name}(\(.+\))?\n((\n| .*\n)*) end/, "should have method #{name}" + yield(name, $2) 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" + def assert_generated_column(body, name, type) + assert_match /t\.#{type.to_s} :#{name.to_s}/, body, "should have column #{name.to_s} defined" end end diff --git a/railties/test/generators/rails_mailer_generator_test.rb b/railties/test/generators/rails_mailer_generator_test.rb new file mode 100644 index 0000000000..9b5debbdb1 --- /dev/null +++ b/railties/test/generators/rails_mailer_generator_test.rb @@ -0,0 +1,26 @@ +require 'generators/generator_test_helper' + +class RailsMailerGeneratorTest < GeneratorTestCase + + def test_generates_mailer + run_generator('mailer', %w(Notifier reset_password)) + + assert_generated_model_for :notifier, 'ActionMailer::Base' do |model| + assert_has_method model, :reset_password do |name, body| + assert_equal [ + "@subject = 'Notifier#reset_password'", + "@body = {}", + "@recipients = ''", + "@from = ''", + "@sent_on = sent_at", + "@headers = {}" + ], + body.split("\n").map{|line| line.sub(' '*4, '') } + end + end + + assert_generated_views_for :notifier, 'reset_password.erb' + assert_generated_unit_test_for :notifier, 'ActionMailer::TestCase' + assert_generated_file "test/fixtures/notifier/reset_password" + end +end diff --git a/railties/test/generators/rails_model_generator_test.rb b/railties/test/generators/rails_model_generator_test.rb index 86ad9c4dc8..0bfc338566 100644 --- a/railties/test/generators/rails_model_generator_test.rb +++ b/railties/test/generators/rails_model_generator_test.rb @@ -1,84 +1,6 @@ -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 'generators/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 +class RailsModelGeneratorTest < GeneratorTestCase def test_model_generates_resources run_generator('model', %w(Product name:string)) diff --git a/railties/test/generators/rails_resource_generator_test.rb b/railties/test/generators/rails_resource_generator_test.rb index 511f1059c2..45e4850ef5 100644 --- a/railties/test/generators/rails_resource_generator_test.rb +++ b/railties/test/generators/rails_resource_generator_test.rb @@ -1,82 +1,6 @@ -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 'generators/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 +class RailsResourceGeneratorTest < GeneratorTestCase def test_resource_generates_resources run_generator('resource', %w(Product name:string)) diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb index 34a1ad2fe5..220f9e372e 100644 --- a/railties/test/generators/rails_scaffold_generator_test.rb +++ b/railties/test/generators/rails_scaffold_generator_test.rb @@ -1,189 +1,107 @@ -require 'abstract_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 +require 'generators/generator_test_helper' -# And what we need from ActionView -module ActionView - module Helpers - module ActiveRecordHelper; end - class InstanceTag; end +class RailsScaffoldGeneratorTest < GeneratorTestCase + + 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 -end + def test_scaffold_generates_resources -# 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" + run_generator('scaffold', %w(Product name:string)) -require 'generators/generator_test_helper' + assert_generated_controller_for :products do |f| -uses_mocha "Scaffold Generator Tests" do - 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" + assert_has_method f, :index do |name, m| + assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" 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 name:string)) - 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 + 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_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_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 - assert_generated_migration :create_products - assert_added_route_for :products end - def test_scaffold_skip_migration_skips_migration - run_generator('scaffold', %w(Product name:string --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 + 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" - def test_scaffold_generates_resources_with_attributes - run_generator('scaffold', %w(Product name:string supplier_id:integer created_at:timestamp)) + assert_generated_migration :create_products + assert_added_route_for :products + end - assert_generated_controller_for :products do |f| + def test_scaffold_skip_migration_skips_migration + run_generator('scaffold', %w(Product name:string --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 - assert_has_method f, :index do |name, m| - assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" - end + def test_scaffold_generates_resources_with_attributes + run_generator('scaffold', %w(Product name:string supplier_id:integer created_at:timestamp)) - 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_generated_controller_for :products do |f| - 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, :index do |name, m| + assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + 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 + 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_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 + 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 - assert_added_route_for :products 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 \ No newline at end of file + +end -- cgit v1.2.3 From 36eecda8d0b5ebd3341692868b8faeec8fbce9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 18 Apr 2008 17:13:15 -0500 Subject: Changed mailer generator to not use instance variables. Signed-off-by: Joshua Peek --- railties/test/generators/rails_mailer_generator_test.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/rails_mailer_generator_test.rb b/railties/test/generators/rails_mailer_generator_test.rb index 9b5debbdb1..3cf8cda442 100644 --- a/railties/test/generators/rails_mailer_generator_test.rb +++ b/railties/test/generators/rails_mailer_generator_test.rb @@ -8,12 +8,12 @@ class RailsMailerGeneratorTest < GeneratorTestCase assert_generated_model_for :notifier, 'ActionMailer::Base' do |model| assert_has_method model, :reset_password do |name, body| assert_equal [ - "@subject = 'Notifier#reset_password'", - "@body = {}", - "@recipients = ''", - "@from = ''", - "@sent_on = sent_at", - "@headers = {}" + "subject 'Notifier#reset_password'", + "recipients ''", + "from ''", + "sent_on sent_at", + "", + "body :action => 'reset_password'" ], body.split("\n").map{|line| line.sub(' '*4, '') } end -- cgit v1.2.3 From 69a5c1df8293fc8de2cec0fc9fa18181cb9ad469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 18 Apr 2008 17:19:28 -0500 Subject: Add example for default_url_options[:host] to generated mailers. Signed-off-by: Joshua Peek --- railties/test/generators/rails_mailer_generator_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/generators/rails_mailer_generator_test.rb b/railties/test/generators/rails_mailer_generator_test.rb index 3cf8cda442..03170c3b61 100644 --- a/railties/test/generators/rails_mailer_generator_test.rb +++ b/railties/test/generators/rails_mailer_generator_test.rb @@ -13,10 +13,13 @@ class RailsMailerGeneratorTest < GeneratorTestCase "from ''", "sent_on sent_at", "", - "body :action => 'reset_password'" + "body :greeting => 'Hi,'" ], body.split("\n").map{|line| line.sub(' '*4, '') } end + + assert_match /^ default_url_options\[:host\] = 'example.com'$/m, model, + 'model should include default_url_options :host declaration' end assert_generated_views_for :notifier, 'reset_password.erb' -- cgit v1.2.3 From 1a29a6717887ac1422bcce9067536987ee64f94d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 11:54:23 -0500 Subject: Mock RailsFCGIHandler and Dispatcher to stop mocha deprecation warnings. --- railties/test/fcgi_dispatcher_test.rb | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb index 6134211022..64d054d45c 100644 --- a/railties/test/fcgi_dispatcher_test.rb +++ b/railties/test/fcgi_dispatcher_test.rb @@ -124,6 +124,24 @@ end class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase + class ::RailsFCGIHandler + attr_accessor :signal + alias_method :old_gc_countdown, :gc_countdown + def gc_countdown + signal ? Process.kill(signal, $$) : old_gc_countdown + end + end + + class ::Dispatcher + class << self + attr_accessor :signal + alias_method :old_dispatch, :dispatch + def dispatch(cgi) + signal ? Process.kill(signal, $$) : old_dispatch + end + end + end + def setup @log = StringIO.new @handler = RailsFCGIHandler.new(@log) @@ -132,7 +150,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_interrupted_via_HUP_when_not_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - @handler.expects(:gc_countdown).returns(lambda { Process.kill 'HUP', $$ } ) + @handler.expects(:signal).times(2).returns('HUP') @handler.expects(:reload!).once @handler.expects(:close_connection).never @@ -145,7 +163,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_interrupted_via_HUP_when_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:dispatch).with(cgi).returns( lambda { Process.kill 'HUP', $$ } ) + Dispatcher.expects(:signal).times(2).returns('HUP') @handler.expects(:reload!).once @handler.expects(:close_connection).never @@ -158,7 +176,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_interrupted_via_USR1_when_not_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - @handler.expects(:gc_countdown).returns( lambda { Process.kill 'USR1', $$ } ) + @handler.expects(:signal).times(2).returns('USR1') @handler.expects(:exit_handler).never @handler.expects(:reload!).never @@ -172,7 +190,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_interrupted_via_USR1_when_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:dispatch).with(cgi).returns( lambda { Process.kill 'USR1', $$ } ) + Dispatcher.expects(:signal).times(2).returns('USR1') @handler.expects(:reload!).never @handler.expects(:close_connection).with(cgi).once @@ -185,7 +203,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_restart_via_USR2_when_in_request cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - @handler.expects(:gc_countdown).returns( lambda { Process.kill 'USR2', $$ } ) + @handler.expects(:signal).times(2).returns('USR2') @handler.expects(:exit_handler).never @handler.expects(:reload!).never @@ -200,7 +218,7 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_interrupted_via_TERM cgi = mock FCGI.expects(:each_cgi).once.yields(cgi) - Dispatcher.expects(:dispatch).with(cgi).returns(lambda { Process.kill 'TERM', $$ }) + Dispatcher.expects(:signal).times(2).returns('TERM') @handler.expects(:reload!).never @handler.expects(:close_connection).never -- cgit v1.2.3 From 1642b2362ecd627c5bdd9965ff3d527a95e2b244 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 12:23:15 -0500 Subject: Gem dependencies don't require a version. Also fixed up failing gem dependency tests. --- railties/test/gem_dependency_test.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 887ad53589..3ae0189327 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -1,5 +1,9 @@ require 'plugin_test_helper' +class Rails::GemDependency + public :install_command, :unpack_command +end + uses_mocha "Plugin Tests" do class GemDependencyTest < Test::Unit::TestCase def setup -- cgit v1.2.3 From eef9002968609a0d8d4a8006aebcd6f18f993f4a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 13:24:38 -0500 Subject: Update plugin loading tests to reflect changes in plugin fixtures. --- railties/test/initializer_test.rb | 49 ++++++++++---------- railties/test/plugin_loader_test.rb | 89 +++++++++++++++++------------------- railties/test/plugin_locator_test.rb | 27 +++++------ 3 files changed, 79 insertions(+), 86 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 0df0164ca6..31b3255610 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -38,27 +38,27 @@ class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::Te end config.after_initialize do $test_after_initialize_block2 = "congratulations" - end + end assert_nil $test_after_initialize_block1 - assert_nil $test_after_initialize_block2 + 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 + $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 @@ -69,7 +69,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit:: config.after_initialize # don't pass a block, this is what we're testing! config.after_initialize do $test_after_initialize_block2 = "congratulations" - end + end assert_nil $test_after_initialize_block1 Rails::Initializer.run(:after_initialize, config) @@ -77,7 +77,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit:: def teardown $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil + $test_after_initialize_block2 = nil end def test_should_have_called_the_first_after_initialize_block @@ -95,7 +95,7 @@ uses_mocha 'framework paths' do def setup @config = Rails::Configuration.new @config.frameworks.clear - + File.stubs(:directory?).returns(true) @config.stubs(:framework_root_path).returns('') end @@ -112,7 +112,7 @@ uses_mocha 'framework paths' do 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 @@ -162,7 +162,7 @@ uses_mocha "Initializer plugin loading tests" do end def test_only_the_specified_plugins_are_located_in_the_order_listed - plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon] + plugin_names = [:plugin_with_no_lib_dir] only_load_the_following_plugins! plugin_names load_plugins! assert_plugins plugin_names, @initializer.loaded_plugins @@ -171,27 +171,27 @@ uses_mocha "Initializer plugin loading tests" do 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 + assert_plugins [: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] + plugin_names = [:stubby, :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 + assert_plugins [:stubby, :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] + plugin_names = [:all, :stubby] 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 + assert_plugins [:plugin_with_no_lib_dir, :stubby], @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] + plugin_names = ['stubby', :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" @@ -204,22 +204,21 @@ uses_mocha "Initializer plugin loading tests" 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] + only_load_the_following_plugins! [:stubby] @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 + +end diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 30fcacbaa1..09d15a577a 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -11,18 +11,18 @@ 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') - + @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - + @loader = Rails::Plugin::Loader.new(@initializer) end @@ -34,109 +34,106 @@ uses_mocha "Plugin Loader Tests" do @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 - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.all_plugins.reverse, @failure_tip + assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.all_plugins.reverse, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [: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 - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [: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] + plugin_names = [: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] + plugin_names = [:stubby] only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins + 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] - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [: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] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + only_load_the_following_plugins! [:stubby, :all] + assert_plugins [:stubby, :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] - assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip + only_load_the_following_plugins! [:stubby, :all] + assert_plugins [:stubby, :plugin_with_no_lib_dir], @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] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + only_load_the_following_plugins! ['stubby', :plugin_with_no_lib_dir] + assert_plugins [:stubby, :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] + only_load_the_following_plugins! [:stubby] 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 - + end + def test_should_add_plugin_load_paths_to_Dependencies_load_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + only_load_the_following_plugins! [:stubby] @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] + only_load_the_following_plugins! [:stubby] @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 } + ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } end end - + end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index 5f1dd991ea..a7a76e1cd0 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -3,13 +3,13 @@ require '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]) @@ -17,12 +17,12 @@ uses_mocha "Plugin Locator Tests" do 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 @@ -39,25 +39,22 @@ uses_mocha "Plugin Locator Tests" do 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) + 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) + 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"].sort, @locator.plugins.map(&:name).sort + assert_equal ["plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort 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"].sort, @locator.plugins.map(&:name).sort - - @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] - assert_equal ["a"], @locator.plugins.map(&:name) + assert_equal ["plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort 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 -- cgit v1.2.3 From 1d09ccd949eb113601ee84c10a508d36c63c62b7 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 13:27:19 -0500 Subject: Revert "Update plugin loading tests to reflect changes in plugin fixtures." This reverts commit eef9002968609a0d8d4a8006aebcd6f18f993f4a. --- railties/test/initializer_test.rb | 49 ++++++++++---------- railties/test/plugin_loader_test.rb | 89 +++++++++++++++++++----------------- railties/test/plugin_locator_test.rb | 27 ++++++----- 3 files changed, 86 insertions(+), 79 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 31b3255610..0df0164ca6 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -38,27 +38,27 @@ class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::Te end config.after_initialize do $test_after_initialize_block2 = "congratulations" - end + end assert_nil $test_after_initialize_block1 - assert_nil $test_after_initialize_block2 + 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 + $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 @@ -69,7 +69,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit:: config.after_initialize # don't pass a block, this is what we're testing! config.after_initialize do $test_after_initialize_block2 = "congratulations" - end + end assert_nil $test_after_initialize_block1 Rails::Initializer.run(:after_initialize, config) @@ -77,7 +77,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit:: def teardown $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil + $test_after_initialize_block2 = nil end def test_should_have_called_the_first_after_initialize_block @@ -95,7 +95,7 @@ uses_mocha 'framework paths' do def setup @config = Rails::Configuration.new @config.frameworks.clear - + File.stubs(:directory?).returns(true) @config.stubs(:framework_root_path).returns('') end @@ -112,7 +112,7 @@ uses_mocha 'framework paths' do 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 @@ -162,7 +162,7 @@ uses_mocha "Initializer plugin loading tests" do end def test_only_the_specified_plugins_are_located_in_the_order_listed - plugin_names = [:plugin_with_no_lib_dir] + 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 @@ -171,27 +171,27 @@ uses_mocha "Initializer plugin loading tests" do 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 [:plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip + 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, :all] + 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, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + 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 = [:all, :stubby] + 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 [:plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip + 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', :plugin_with_no_lib_dir] + 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" @@ -204,21 +204,22 @@ uses_mocha "Initializer plugin loading tests" 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] + 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 + +end diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 09d15a577a..30fcacbaa1 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -11,18 +11,18 @@ 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') - + @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - + @loader = Rails::Plugin::Loader.new(@initializer) end @@ -34,106 +34,109 @@ uses_mocha "Plugin Loader Tests" do @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 - assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.all_plugins.reverse, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.all_plugins.reverse, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + 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 - assert_plugins [:plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + 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 = [:stubby] + 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] + plugin_names = [:stubby, :acts_as_chunky_bacon] only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins + 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] - assert_plugins [:plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + 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, :all] - assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] + 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] - assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] + 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', :plugin_with_no_lib_dir] - assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + 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] + 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 - end - + 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] + 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] + 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 } + ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } end end - + end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index a7a76e1cd0..5f1dd991ea 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -3,13 +3,13 @@ require '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]) @@ -17,12 +17,12 @@ uses_mocha "Plugin Locator Tests" do 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 @@ -39,22 +39,25 @@ uses_mocha "Plugin Locator Tests" do 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) + 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) + assert_nil @locator.send(:create_plugin, @empty_plugin_path) end - + def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + assert_equal ["a", "acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort 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 ["plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + assert_equal ["acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + + @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 -- cgit v1.2.3 From 4ac33de4d61efe27454bbced7aece88604508bf1 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 13:48:44 -0500 Subject: Add back empty plugin folders that were lost when we moved to git. --- .../test/fixtures/plugins/alternate/a/lib/a.rb | 0 .../lib/acts_as_chunky_bacon.rb | 0 .../test/fixtures/plugins/default/empty/README | 0 railties/test/plugin_loader_test.rb | 64 +++++++++++----------- 4 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 railties/test/fixtures/plugins/alternate/a/lib/a.rb create mode 100644 railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb create mode 100644 railties/test/fixtures/plugins/default/empty/README (limited to 'railties/test') diff --git a/railties/test/fixtures/plugins/alternate/a/lib/a.rb b/railties/test/fixtures/plugins/alternate/a/lib/a.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb b/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/plugins/default/empty/README b/railties/test/fixtures/plugins/default/empty/README new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 30fcacbaa1..41bd6ec7ea 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -11,18 +11,18 @@ 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') - + @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - + @loader = Rails::Plugin::Loader.new(@initializer) end @@ -34,27 +34,27 @@ uses_mocha "Plugin Loader Tests" do @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 - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.all_plugins.reverse, @failure_tip + assert_plugins [:stubby, :plugin_with_no_lib_dir, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched 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 assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip @@ -65,23 +65,23 @@ uses_mocha "Plugin Loader Tests" do 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 + 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] 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] 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] assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip @@ -91,52 +91,52 @@ uses_mocha "Plugin Loader Tests" do only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] 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 - + 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')) + 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')) + 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 } + ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } end end - + end -- cgit v1.2.3 From 4809dcc1b50330a04ec61dd1fef6cdba9892ac3d Mon Sep 17 00:00:00 2001 From: Cody Fauser Date: Mon, 21 Apr 2008 14:31:54 -0500 Subject: * Remove default_url_options from mailer generator * Improve mailer documentation regarding generating URLs * Add no_match to mailer generator to warn contributors about default_url_options Signed-off-by: Joshua Peek --- railties/test/generators/rails_mailer_generator_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/rails_mailer_generator_test.rb b/railties/test/generators/rails_mailer_generator_test.rb index 03170c3b61..de61e6736d 100644 --- a/railties/test/generators/rails_mailer_generator_test.rb +++ b/railties/test/generators/rails_mailer_generator_test.rb @@ -17,9 +17,9 @@ class RailsMailerGeneratorTest < GeneratorTestCase ], body.split("\n").map{|line| line.sub(' '*4, '') } end - - assert_match /^ default_url_options\[:host\] = 'example.com'$/m, model, - 'model should include default_url_options :host declaration' + + assert_no_match /(self.default_url_options =|default_url_options\[.*\] =)/, model, + 'individual mailer models should not set default_url_options because the options are shared by all mailers' end assert_generated_views_for :notifier, 'reset_password.erb' -- cgit v1.2.3 From 6ccfc0ebdedb53794c4981521c4299d842caf896 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 19:09:46 -0500 Subject: Add .empty files to empty directories so git preserves them. --- railties/test/fixtures/lib/generators/missing_class/templates/.empty | 0 railties/test/fixtures/lib/generators/missing_generator/templates/.empty | 0 railties/test/fixtures/lib/generators/missing_templates/.empty | 0 railties/test/fixtures/plugins/alternate/a/lib/.empty | 0 railties/test/fixtures/plugins/alternate/a/lib/a.rb | 0 .../test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.empty | 0 .../plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb | 0 railties/test/fixtures/plugins/default/empty/.empty | 0 railties/test/fixtures/plugins/default/empty/README | 0 9 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 railties/test/fixtures/lib/generators/missing_class/templates/.empty create mode 100644 railties/test/fixtures/lib/generators/missing_generator/templates/.empty create mode 100644 railties/test/fixtures/lib/generators/missing_templates/.empty create mode 100644 railties/test/fixtures/plugins/alternate/a/lib/.empty delete mode 100644 railties/test/fixtures/plugins/alternate/a/lib/a.rb create mode 100644 railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.empty delete mode 100644 railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb create mode 100644 railties/test/fixtures/plugins/default/empty/.empty delete mode 100644 railties/test/fixtures/plugins/default/empty/README (limited to 'railties/test') diff --git a/railties/test/fixtures/lib/generators/missing_class/templates/.empty b/railties/test/fixtures/lib/generators/missing_class/templates/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/lib/generators/missing_generator/templates/.empty b/railties/test/fixtures/lib/generators/missing_generator/templates/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/lib/generators/missing_templates/.empty b/railties/test/fixtures/lib/generators/missing_templates/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/plugins/alternate/a/lib/.empty b/railties/test/fixtures/plugins/alternate/a/lib/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/plugins/alternate/a/lib/a.rb b/railties/test/fixtures/plugins/alternate/a/lib/a.rb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.empty b/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb b/railties/test/fixtures/plugins/default/acts/acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/railties/test/fixtures/plugins/default/empty/.empty b/railties/test/fixtures/plugins/default/empty/.empty new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/fixtures/plugins/default/empty/README b/railties/test/fixtures/plugins/default/empty/README deleted file mode 100644 index e69de29bb2..0000000000 -- cgit v1.2.3 From de8b0087c61af6c8b1cab7c1760f2e326b996702 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 21 Apr 2008 19:14:37 -0500 Subject: Don't require generator_test_helper in RailsGeneratorTest. --- railties/test/rails_generator_test.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_generator_test.rb b/railties/test/rails_generator_test.rb index e1445e0a20..b2fc2f585d 100644 --- a/railties/test/rails_generator_test.rb +++ b/railties/test/rails_generator_test.rb @@ -33,7 +33,16 @@ else end $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib" -require 'generators/generator_test_helper' +require 'initializer' + +# Mocks out the configuration +module Rails + def self.configuration + Rails::Configuration.new + end +end + +require 'rails_generator' class RailsGeneratorTest < Test::Unit::TestCase BUILTINS = %w(controller integration_test mailer migration model observer plugin resource scaffold session_migration) @@ -44,9 +53,9 @@ class RailsGeneratorTest < Test::Unit::TestCase end def test_sources - expected = [:lib, :vendor, + expected = [:lib, :vendor, "plugins (vendor/plugins)".to_sym, # /generators and /rails_generators - :user, + :user, :RubyGems, :RubyGems, # gems named _generator, gems containing /rails_generator/ folder :builtin] expected.delete(:RubyGems) unless Object.const_defined?(:Gem) -- cgit v1.2.3 From bf1b1e0925085811f0b58bb4093e678438ea0236 Mon Sep 17 00:00:00 2001 From: Francesc Esplugas Date: Tue, 22 Apr 2008 15:44:13 -0500 Subject: Rails Edge info returns the latest git commit hash [#36 state:resolved] Signed-off-by: Joshua Peek --- railties/test/rails_info_test.rb | 70 ++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index a212046586..3e91e2f2ee 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -23,27 +23,21 @@ class InfoTest < Test::Unit::TestCase 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) + commit 420c4b3d8878156d04f45e47050ddc62ae00c68c + Author: David Heinemeier Hansson + Date: Sun Apr 13 17:33:27 2008 -0500 + Added Rails.public_path to control where HTML and assets are expected to be loaded from EOS end - - assert_property 'Test Edge Rails revision', '2881' + + assert_property 'Test Edge Rails revision', '420c4b3d8878156d04f45e47050ddc62ae00c68c' end - + def test_property_with_block_swallows_exceptions_and_ignores_property assert_nothing_raised do Rails::Info.module_eval do @@ -52,25 +46,25 @@ EOS 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('_', '') @@ -78,28 +72,28 @@ EOS end end -protected - def svn_info=(info) - Rails::Info.module_eval do - class << self - def svn_info - info + protected + def svn_info=(info) + Rails::Info.module_eval do + class << self + def svn_info + info + end 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 + 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 -- cgit v1.2.3