Upgraded to Rails 2.3.4 (#3597)

* Ran the Rails upgrade
* Upgraded to Rails Engines 2.3.2
* Added a plugin to let Engines override application views.
* Converted tests to use the new classes:
** ActionController::TestCase for functional
** ActiveSupport::TestCase for units
* Converted ActiveRecord::Error message to a string.
* ActiveRecord grouping returns an ordered hash which doesn't have #sort!
* Updated the I18n storage_units format.
* Added some default initializers from a fresh rails app
* Changed the order of check_box_tags and hidden_field_tags.  The hidden tag
  needs to appear first in Rails 2.3, otherwise it will override any value in
  the check_box_tag.
* Removed the custom handler for when the cookie store is tampered with.
  Rails 2.3 removed the TamperedWithCookie exception and instead Rails will not
  load the data from it when it's been tampered with (e.g. no user login).
* Fixed mail layouts, 2.3 has problems with implicit multipart emails that
  use layouts.  Also removed some custom Redmine mailer code.
* Fixed a bug that occurred in tests where the "required" span tag would be
  added to the :field_status translation.  This resulted in an email string of:

    <li>Status<span class="required"> *</span><span class="required"> *</span>

  Instead of:

    <li>Status: New</li>

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2887 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis
2009-09-13 17:14:35 +00:00
parent fb349dc4ab
commit 7b0cb6aba8
263 changed files with 1636 additions and 440 deletions
+54
View File
@@ -0,0 +1,54 @@
require File.dirname(__FILE__) + '/../test_helper'
class ActionMailerWithinApplicationTest < Test::Unit::TestCase
def test_normal_implicit_template
m = NotifyMail.create_signup("hello")
assert m.body =~ /^Signup template from application/
end
def test_action_mailer_can_get_helper
m = NotifyMail.create_signup('James')
assert m.body =~ /James/
assert m.body =~ /semaJ/ # from the helper
end
def test_multipart_mails_with_explicit_templates
m = NotifyMail.create_multipart
assert_equal 2, m.parts.length
assert_equal 'the html part of the email james', m.parts[0].body
assert_equal 'the plaintext part of the email', m.parts[1].body
end
def test_multipart_mails_with_implicit_templates
m = NotifyMail.create_implicit_multipart
assert_equal 2, m.parts.length
assert_equal 'the implicit plaintext part of the email', m.parts[0].body
assert_equal 'the implicit html part of the email james', m.parts[1].body
end
end
class ActionMailerWithinPluginsTest < Test::Unit::TestCase
def test_should_be_able_to_create_mails_from_plugin
m = PluginMail.create_mail_from_plugin("from_plugin")
assert_equal "from_plugin", m.body
end
def test_should_be_able_to_overload_views_within_the_application
m = PluginMail.create_mail_from_plugin_with_application_template("from_plugin")
assert_equal "from_plugin (from application)", m.body
end
def test_should_be_able_to_create_a_multipart_mail_from_within_plugin
m = PluginMail.create_multipart_from_plugin
assert_equal 2, m.parts.length
assert_equal 'html template', m.parts[0].body
assert_equal 'plain template', m.parts[1].body
end
def test_plugin_mailer_template_overriding
m = PluginMail.create_multipart_from_plugin_with_application_template
assert_equal 'plugin mail template loaded from application', m.parts[1].body
end
end
@@ -0,0 +1,41 @@
require File.dirname(__FILE__) + '/../test_helper'
class ArbitraryCodeMixingTest < Test::Unit::TestCase
def setup
Engines.code_mixing_file_types = %w(controller helper)
end
def test_should_allow_setting_of_different_code_mixing_file_types
assert_nothing_raised {
Engines.mix_code_from :things
}
end
def test_should_add_new_types_to_existing_code_mixing_file_types
Engines.mix_code_from :things
assert_equal ["controller", "helper", "thing"], Engines.code_mixing_file_types
Engines.mix_code_from :other
assert_equal ["controller", "helper", "thing", "other"], Engines.code_mixing_file_types
end
def test_should_allow_setting_of_multiple_types_at_once
Engines.mix_code_from :things, :other
assert_equal ["controller", "helper", "thing", "other"], Engines.code_mixing_file_types
end
def test_should_singularize_elements_to_be_mixed
# this is the only test using mocha, so let's try to work around it
# also, this seems to be already tested with the :things in the tests above
# arg = stub(:to_s => stub(:singularize => "element"))
Engines.mix_code_from :elements
assert Engines.code_mixing_file_types.include?("element")
end
# TODO doesn't seem to work as expected?
# def test_should_successfully_mix_custom_types
# Engines.mix_code_from :things
# assert_equal 'Thing (from app)', Thing.from_app
# assert_equal 'Thing (from test_code_mixing)', Thing.from_plugin
# end
end
+52
View File
@@ -0,0 +1,52 @@
require File.dirname(__FILE__) + '/../test_helper'
class AssetsTest < Test::Unit::TestCase
def setup
Engines::Assets.mirror_files_for Engines.plugins[:test_assets]
end
def teardown
FileUtils.rm_r(Engines.public_directory) if File.exist?(Engines.public_directory)
end
def test_engines_has_created_base_public_file
assert File.exist?(Engines.public_directory)
end
def test_engines_has_created_README_in_public_directory
assert File.exist?(File.join(Engines.public_directory, 'README'))
end
def test_public_files_have_been_copied_from_test_assets_plugin
assert File.exist?(File.join(Engines.public_directory, 'test_assets'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'file.txt'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'subfolder'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets', 'subfolder', 'file_in_subfolder.txt'))
end
def test_engines_has_not_created_duplicated_file_structure
assert !File.exists?(File.join(Engines.public_directory, "test_assets", RAILS_ROOT))
end
def test_public_files_have_been_copied_from_test_assets_with_assets_dir_plugin
Engines::Assets.mirror_files_for Engines.plugins[:test_assets_with_assets_directory]
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory', 'file.txt'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory', 'subfolder'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_assets_directory', 'subfolder', 'file_in_subfolder.txt'))
end
def test_public_files_have_been_copied_from_test_assets_with_no_subdirectory_plugin
Engines::Assets.mirror_files_for Engines.plugins[:test_assets_with_no_subdirectory]
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_no_subdirectory'))
assert File.exist?(File.join(Engines.public_directory, 'test_assets_with_no_subdirectory', 'file.txt'))
end
def test_public_files_have_NOT_been_copied_from_plugins_without_public_or_asset_directories
Engines::Assets.mirror_files_for Engines.plugins[:alpha_plugin]
assert !File.exist?(File.join(Engines.public_directory, 'alpha_plugin'))
end
end
@@ -0,0 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'
class BackwardsCompatibilityTest < Test::Unit::TestCase
def test_rails_module_plugin_method_should_delegate_to_engines_plugins
assert_nothing_raised { Rails.plugins }
assert_equal Engines.plugins, Rails.plugins
end
end
+58
View File
@@ -0,0 +1,58 @@
# Tests in this file ensure that:
#
# * the application /app/[controllers|helpers|models] and /lib
# paths preceed the corresponding plugin paths
# * the plugin paths are added to $LOAD_PATH in the order in which plugins are
# loaded
require File.dirname(__FILE__) + '/../test_helper'
class LoadPathTest < Test::Unit::TestCase
def setup
@load_path = expand_paths($LOAD_PATH)
end
# Not sure if these test actually make sense as this now essentially tests
# Rails core functionality. On the other hand Engines relies on this to some
# extend so this will choke if something important changes in Rails.
# the application app/... and lib/ directories should appear
# before any plugin directories
def test_application_app_libs_should_precede_all_plugin_app_libs
types = %w(app/controllers app/helpers app/models lib)
types.each do |t|
app_index = load_path_index(File.join(RAILS_ROOT, t))
assert_not_nil app_index, "#{t} is missing in $LOAD_PATH"
Engines.plugins.each do |plugin|
first_plugin_index = load_path_index(File.join(plugin.directory, t))
assert(app_index < first_plugin_index) unless first_plugin_index.nil?
end
end
end
# the engine directories should appear in the proper order based on
# the order they were started
def test_plugin_dirs_should_appear_in_reverse_plugin_loading_order
app_paths = %w(app/controllers/ app app/models app/helpers lib)
app_paths.map { |p| File.join(RAILS_ROOT, p)}
plugin_paths = Engines.plugins.reverse.collect { |plugin| plugin.load_paths.reverse }.flatten
expected_paths = expand_paths(app_paths + plugin_paths)
# only look at those paths that are also present in expected_paths so
# the only difference would be in the order of the paths
actual_paths = @load_path & expected_paths
assert_equal expected_paths, actual_paths
end
protected
def expand_paths(paths)
paths.collect { |p| File.expand_path(p) }
end
def load_path_index(dir)
@load_path.index(File.expand_path(dir))
end
end
+63
View File
@@ -0,0 +1,63 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'rails_generator'
require 'rails_generator/scripts/generate'
class MigrationsTest < Test::Unit::TestCase
@@migration_dir = "#{RAILS_ROOT}/db/migrate"
def setup
ActiveRecord::Migration.verbose = false
Engines.plugins[:test_migration].migrate(0)
end
def teardown
FileUtils.rm_r(@@migration_dir) if File.exist?(@@migration_dir)
end
def test_engine_migrations_can_run_down
assert !table_exists?('tests'), ActiveRecord::Base.connection.tables.inspect
assert !table_exists?('others'), ActiveRecord::Base.connection.tables.inspect
assert !table_exists?('extras'), ActiveRecord::Base.connection.tables.inspect
end
def test_engine_migrations_can_run_up
Engines.plugins[:test_migration].migrate(3)
assert table_exists?('tests')
assert table_exists?('others')
assert table_exists?('extras')
end
def test_engine_migrations_can_upgrade_incrementally
Engines.plugins[:test_migration].migrate(1)
assert table_exists?('tests')
assert !table_exists?('others')
assert !table_exists?('extras')
assert_equal 1, Engines::Plugin::Migrator.current_version(Engines.plugins[:test_migration])
Engines.plugins[:test_migration].migrate(2)
assert table_exists?('others')
assert_equal 2, Engines::Plugin::Migrator.current_version(Engines.plugins[:test_migration])
Engines.plugins[:test_migration].migrate(3)
assert table_exists?('extras')
assert_equal 3, Engines::Plugin::Migrator.current_version(Engines.plugins[:test_migration])
end
def test_generator_creates_plugin_migration_file
Rails::Generator::Scripts::Generate.new.run(['plugin_migration', 'test_migration'], :quiet => true)
assert migration_file, "migration file is missing"
end
private
def table_exists?(table)
ActiveRecord::Base.connection.tables.include?(table)
end
def migration_file
Dir["#{@@migration_dir}/*test_migration_to_version_3.rb"][0]
end
end
+37
View File
@@ -0,0 +1,37 @@
require File.dirname(__FILE__) + '/../test_helper'
class ModelAndLibTest < Test::Unit::TestCase
def test_WITH_a_model_defined_only_in_a_plugin_IT_should_load_the_model
assert_equal 'AlphaPluginModel (from alpha_plugin)', AlphaPluginModel.report_location
end
def test_WITH_a_model_defined_only_in_a_plugin_lib_dir_IT_should_load_the_model
assert_equal 'AlphaPluginLibModel (from alpha_plugin)', AlphaPluginLibModel.report_location
end
# app takes precedence over plugins
def test_WITH_a_model_defined_in_both_app_and_plugin_IT_should_load_the_one_in_app
assert_equal 'AppAndPluginModel (from app)', AppAndPluginModel.report_location
assert_raises(NoMethodError) { AppAndPluginLibModel.defined_only_in_alpha_engine_version }
end
def test_WITH_a_model_defined_in_both_app_and_plugin_lib_dirs_IT_should_load_the_one_in_app
assert_equal 'AppAndPluginLibModel (from lib)', AppAndPluginLibModel.report_location
assert_raises(NoMethodError) { AppAndPluginLibModel.defined_only_in_alpha_engine_version }
end
# subsequently loaded plugins take precendence over previously loaded plugins
# TODO
#
# this does work when we rely on $LOAD_PATH while it won't work when we use
# Dependency constant autoloading. This somewhat confusing difference has
# been there since at least Rails 1.2.x. See http://www.ruby-forum.com/topic/134529
def test_WITH_a_model_defined_in_two_plugins_IT_should_load_the_latter_of_both
require 'shared_plugin_model'
assert_equal SharedPluginModel.report_location, 'SharedPluginModel (from beta_plugin)'
end
end
+11
View File
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../test_helper'
class PluginsTest < Test::Unit::TestCase
def test_should_allow_access_to_plugins_by_strings_or_symbols
p = Engines.plugins["alpha_plugin"]
q = Engines.plugins[:alpha_plugin]
assert_kind_of Engines::Plugin, p
assert_equal p, q
end
end
@@ -0,0 +1,7 @@
require File.join(File.dirname(__FILE__), *%w[.. .. test_helper])
class OverrideTest < ActiveSupport::TestCase
def test_overrides_from_the_application_should_work
assert true, "overriding plugin tests from the application should work"
end
end
+19
View File
@@ -0,0 +1,19 @@
require File.dirname(__FILE__) + '/../test_helper'
class TestingTest < Test::Unit::TestCase
def setup
Engines::Testing.set_fixture_path
@filename = File.join(Engines::Testing.temporary_fixtures_directory, 'testing_fixtures.yml')
File.delete(@filename) if File.exists?(@filename)
end
def teardown
File.delete(@filename) if File.exists?(@filename)
end
def test_should_copy_fixtures_files_to_tmp_directory
assert !File.exists?(@filename)
Engines::Testing.setup_plugin_fixtures
assert File.exists?(@filename)
end
end