diff options
author | Xavier Noria <fxn@hashref.com> | 2010-05-01 02:23:47 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-05-01 02:23:47 -0700 |
commit | efba1d4227514a6ce4880910a6531b0a6c3c75aa (patch) | |
tree | daff4155b8c19b915125ac0b0da458279358e743 /railties/test | |
parent | 81807e0fe2879e08563c91ee6809ab6d1d0bd081 (diff) | |
parent | 6c280f3398966ffba45069500ff43d632513fe44 (diff) | |
download | rails-efba1d4227514a6ce4880910a6531b0a6c3c75aa.tar.gz rails-efba1d4227514a6ce4880910a6531b0a6c3c75aa.tar.bz2 rails-efba1d4227514a6ce4880910a6531b0a6c3c75aa.zip |
Merge commit 'rails/master'
Conflicts:
railties/guides/source/index.html.erb
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/middleware_test.rb | 7 | ||||
-rw-r--r-- | railties/test/application/model_initialization_test.rb | 33 | ||||
-rw-r--r-- | railties/test/application/paths_test.rb | 5 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 14 | ||||
-rw-r--r-- | railties/test/fixtures/lib/empty_builder.rb | 2 | ||||
-rw-r--r-- | railties/test/fixtures/lib/simple_builder.rb | 7 | ||||
-rw-r--r-- | railties/test/fixtures/lib/tweak_builder.rb | 7 | ||||
-rw-r--r-- | railties/test/generators/actions_test.rb | 2 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 135 | ||||
-rw-r--r-- | railties/test/generators/mailer_generator_test.rb | 3 |
10 files changed, 174 insertions, 41 deletions
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 27374dcb28..d08f04bddb 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -20,20 +20,21 @@ module ApplicationTests assert_equal [ "ActionDispatch::Static", "Rack::Lock", + "ActiveSupport::Cache::Strategy::LocalCache", "Rack::Runtime", "Rails::Rack::Logger", "ActionDispatch::ShowExceptions", "ActionDispatch::RemoteIp", "Rack::Sendfile", "ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement", + "ActiveRecord::QueryCache", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", "ActionDispatch::ParamsParser", "Rack::MethodOverride", - "ActionDispatch::Head", - "ActiveRecord::ConnectionAdapters::ConnectionManagement", - "ActiveRecord::QueryCache" + "ActionDispatch::Head" ], middleware end diff --git a/railties/test/application/model_initialization_test.rb b/railties/test/application/model_initialization_test.rb new file mode 100644 index 0000000000..6a22f8d8df --- /dev/null +++ b/railties/test/application/model_initialization_test.rb @@ -0,0 +1,33 @@ +require 'isolation/abstract_unit' + +class PostTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + def test_reload_should_reload_constants + app_file "app/models/post.rb", <<-MODEL + class Post < ActiveRecord::Base + validates_acceptance_of :title, :accept => "omg" + end + MODEL + + require "#{rails_root}/config/environment" + ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") + ActiveRecord::Migration.verbose = false + ActiveRecord::Schema.define(:version => 1) do + create_table :posts do |t| + t.string :title + end + end + + p = Post.create(:title => 'omg') + assert_equal 1, Post.count + assert_equal 'omg', p.title + p = Post.first + assert_equal 'omg', p.title + end +end diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb index 5ab558c026..978d677efc 100644 --- a/railties/test/application/paths_test.rb +++ b/railties/test/application/paths_test.rb @@ -48,7 +48,8 @@ module ApplicationTests assert_path @paths.tmp.cache, "tmp", "cache" assert_path @paths.config, "config" assert_path @paths.config.locales, "config", "locales", "en.yml" - assert_path @paths.config.environment, "config", "environments", "development.rb" + assert_path @paths.config.environment, "config", "environment.rb" + assert_path @paths.config.environments, "config", "environments", "development.rb" assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first end @@ -61,7 +62,7 @@ module ApplicationTests end test "environments has a glob equal to the current environment" do - assert_equal "#{Rails.env}.rb", @paths.config.environment.glob + assert_equal "#{Rails.env}.rb", @paths.config.environments.glob end test "load path includes each of the paths in config.paths as long as the directories exist" do diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index bf2da866f4..6b7a471494 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -19,5 +19,19 @@ module ApplicationTests ::Rails.application.load_tasks assert $task_loaded end + + def test_environment_is_required_in_rake_tasks + app_file "config/environment.rb", <<-RUBY + SuperMiddleware = Struct.new(:app) + + Rails::Application.configure do + config.middleware.use SuperMiddleware + end + + Rails::Application.initialize! + RUBY + + assert_match "SuperMiddleware", Dir.chdir(app_path){ `rake middleware` } + end end end
\ No newline at end of file diff --git a/railties/test/fixtures/lib/empty_builder.rb b/railties/test/fixtures/lib/empty_builder.rb new file mode 100644 index 0000000000..babd9c2461 --- /dev/null +++ b/railties/test/fixtures/lib/empty_builder.rb @@ -0,0 +1,2 @@ +class AppBuilder +end
\ No newline at end of file diff --git a/railties/test/fixtures/lib/simple_builder.rb b/railties/test/fixtures/lib/simple_builder.rb new file mode 100644 index 0000000000..47dcdc0d96 --- /dev/null +++ b/railties/test/fixtures/lib/simple_builder.rb @@ -0,0 +1,7 @@ +class AppBuilder + def configru + create_file "config.ru", <<-R.strip +run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] } + R + end +end
\ No newline at end of file diff --git a/railties/test/fixtures/lib/tweak_builder.rb b/railties/test/fixtures/lib/tweak_builder.rb new file mode 100644 index 0000000000..eed20ecc9b --- /dev/null +++ b/railties/test/fixtures/lib/tweak_builder.rb @@ -0,0 +1,7 @@ +class AppBuilder < Rails::AppBuilder + def configru + create_file "config.ru", <<-R.strip +run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] } + R + end +end
\ No newline at end of file diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index 44e0640552..e6fab93a87 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -209,7 +209,7 @@ class ActionsTest < Rails::Generators::TestCase def test_readme run_generator - Rails::Generators::AppGenerator.expects(:source_root).returns(destination_root) + Rails::Generators::AppGenerator.expects(:source_root).times(2).returns(destination_root) assert_match(/Welcome to Rails/, action(:readme, "README")) end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 24e6d541c2..1a93867013 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -2,6 +2,40 @@ require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/app/app_generator' +DEFAULT_APP_FILES = %w( + .gitignore + Gemfile + Rakefile + config.ru + app/controllers + app/helpers + app/models + app/views/layouts + config/environments + config/initializers + config/locales + db + doc + lib + lib/tasks + log + public/images + public/javascripts + public/stylesheets + script/rails + test/fixtures + test/functional + test/integration + test/performance + test/unit + vendor + vendor/plugins + tmp/sessions + tmp/sockets + tmp/cache + tmp/pids +) + class AppGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper arguments [destination_root] @@ -20,35 +54,7 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_application_skeleton_is_created run_generator - %w( - app/controllers - app/helpers - app/models - app/views/layouts - config/environments - config/initializers - config/locales - db - doc - lib - lib/tasks - log - public/images - public/javascripts - public/stylesheets - script/rails - test/fixtures - test/functional - test/integration - test/performance - test/unit - vendor - vendor/plugins - tmp/sessions - tmp/sockets - tmp/cache - tmp/pids - ).each{ |path| assert_file path } + DEFAULT_APP_FILES.each{ |path| assert_file path } end def test_application_controller_and_layout_files @@ -58,6 +64,11 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_file "public/stylesheets/application.css" end + def test_options_before_application_name_raises_an_error + content = capture(:stderr){ run_generator(["--skip-activerecord", destination_root]) } + assert_equal "Options should be given after the application name. For details run: rails --help\n", content + end + def test_name_collision_raises_an_error content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] } assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content @@ -152,7 +163,7 @@ class AppGeneratorTest < Rails::Generators::TestCase template = %{ say "It works!" } template.instance_eval "def read; self; end" # Make the string respond to read - generator([destination_root], :template => path).expects(:open).with(path).returns(template) + generator([destination_root], :template => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) assert_match /It works!/, silence(:stdout){ generator.invoke } end @@ -188,10 +199,66 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file 'Gemfile', /^gem\s+["']rails["'],\s+:git\s+=>\s+["']#{Regexp.escape("git://github.com/rails/rails.git")}["']$/ end - protected +protected - def action(*args, &block) - silence(:stdout){ generator.send(*args, &block) } - end + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end end + +class CustomAppGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + tests Rails::Generators::AppGenerator + + arguments [destination_root] + + def setup + super + Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) + @bundle_command = File.basename(Thor::Util.ruby_command).sub(/ruby/, 'bundle') + end + + def teardown + super + Rails::Generators::AppGenerator.instance_variable_set('@desc', nil) + Object.class_eval { remove_const :AppBuilder if const_defined?(:AppBuilder) } + end + + def test_builder_option_with_empty_app_builder + FileUtils.cd(Rails.root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/empty_builder.rb"]) + DEFAULT_APP_FILES.each{ |path| assert_no_file path } + end + + def test_builder_option_with_simple_app_builder + FileUtils.cd(Rails.root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/simple_builder.rb"]) + (DEFAULT_APP_FILES - ['config.ru']).each{ |path| assert_no_file path } + assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] + end + + def test_builder_option_with_tweak_app_builder + FileUtils.cd(Rails.root) + run_generator([destination_root, "-b", "#{Rails.root}/lib/tweak_builder.rb"]) + DEFAULT_APP_FILES.each{ |path| assert_file path } + assert_file "config.ru", %[run proc { |env| [200, { "Content-Type" => "text/html" }, ["Hello World"]] }] + end + + def test_builder_option_with_http + path = "http://gist.github.com/103208.txt" + template = "class AppBuilder; end" + template.instance_eval "def read; self; end" # Make the string respond to read + + generator([destination_root], :builder => path).expects(:open).with(path, 'Accept' => 'application/x-thor-template').returns(template) + capture(:stdout) { generator.invoke } + + DEFAULT_APP_FILES.each{ |path| assert_no_file path } + end + +protected + + def action(*args, &block) + silence(:stdout){ generator.send(*args, &block) } + end +end
\ No newline at end of file diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 81d6afa221..850b45ff74 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -1,5 +1,6 @@ require 'generators/generators_test_helper' -require 'rails/generators/rails/mailer/mailer_generator' +require 'rails/generators/mailer/mailer_generator' + class MailerGeneratorTest < Rails::Generators::TestCase include GeneratorsTestHelper |