diff options
author | Gonçalo Silva <goncalossilva@gmail.com> | 2011-04-17 17:08:49 +0100 |
---|---|---|
committer | Gonçalo Silva <goncalossilva@gmail.com> | 2011-04-17 17:08:49 +0100 |
commit | 1c2b2233c3a7ec76c0a0eddf5b8be45c489be133 (patch) | |
tree | 56f2b767c3a4f1f14c51606bf2cbb714a98c5f89 /railties/test | |
parent | 8d558cb1b069410c8f693295c9c4e2ffc9661e06 (diff) | |
parent | b6843f22ac42b503f6b8ac00105ca0679049be7d (diff) | |
download | rails-1c2b2233c3a7ec76c0a0eddf5b8be45c489be133.tar.gz rails-1c2b2233c3a7ec76c0a0eddf5b8be45c489be133.tar.bz2 rails-1c2b2233c3a7ec76c0a0eddf5b8be45c489be133.zip |
Merge branch 'master' of https://github.com/rails/rails into performance_test
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/configuration_test.rb | 87 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 72 | ||||
-rw-r--r-- | railties/test/generators/assets_generator_test.rb | 26 | ||||
-rw-r--r-- | railties/test/generators/controller_generator_test.rb | 6 | ||||
-rw-r--r-- | railties/test/generators/plugin_new_generator_test.rb | 49 | ||||
-rw-r--r-- | railties/test/generators/scaffold_controller_generator_test.rb | 18 | ||||
-rw-r--r-- | railties/test/generators/scaffold_generator_test.rb | 52 | ||||
-rw-r--r-- | railties/test/generators/stylesheets_generator_test.rb | 17 | ||||
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 3 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 258 | ||||
-rw-r--r-- | railties/test/railties/shared_tests.rb | 42 |
11 files changed, 262 insertions, 368 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 044fd2a278..62697b1bf9 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,5 +1,18 @@ require "isolation/abstract_unit" +class ::MyMailInterceptor + def self.delivering_email(email); email; end +end + +class ::MyOtherMailInterceptor < ::MyMailInterceptor; end + +class ::MyMailObserver + def self.delivered_email(email); email; end +end + +class ::MyOtherMailObserver < ::MyMailObserver; end + + module ApplicationTests class ConfigurationTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation @@ -245,6 +258,80 @@ module ApplicationTests assert_equal res, last_response.body # value should be unchanged end + test "registers interceptors with ActionMailer" do + add_to_config <<-RUBY + config.action_mailer.interceptors = MyMailInterceptor + RUBY + + require "#{app_path}/config/environment" + require "mail" + + ActionMailer::Base + + assert_equal [::MyMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors") + end + + test "registers multiple interceptors with ActionMailer" do + add_to_config <<-RUBY + config.action_mailer.interceptors = [MyMailInterceptor, "MyOtherMailInterceptor"] + RUBY + + require "#{app_path}/config/environment" + require "mail" + + ActionMailer::Base + + assert_equal [::MyMailInterceptor, ::MyOtherMailInterceptor], ::Mail.send(:class_variable_get, "@@delivery_interceptors") + end + + test "registers observers with ActionMailer" do + add_to_config <<-RUBY + config.action_mailer.observers = MyMailObserver + RUBY + + require "#{app_path}/config/environment" + require "mail" + + ActionMailer::Base + + assert_equal [::MyMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers") + end + + test "registers multiple observers with ActionMailer" do + add_to_config <<-RUBY + config.action_mailer.observers = [MyMailObserver, "MyOtherMailObserver"] + RUBY + + require "#{app_path}/config/environment" + require "mail" + + ActionMailer::Base + + assert_equal [::MyMailObserver, ::MyOtherMailObserver], ::Mail.send(:class_variable_get, "@@delivery_notification_observers") + end + + test "valid timezone is setup correctly" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.time_zone = "Wellington" + RUBY + + require "#{app_path}/config/environment" + + assert_equal "Wellington", Rails.application.config.time_zone + end + + test "raises when an invalid timezone is defined in the config" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.time_zone = "That big hill over yonder hill" + RUBY + + assert_raise(ArgumentError) do + require "#{app_path}/config/environment" + end + end + test "config.action_controller.perform_caching = false" do make_basic_app do |app| app.config.action_controller.perform_caching = false diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 018c2fa6bf..3ef06c7f25 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -8,6 +8,8 @@ DEFAULT_APP_FILES = %w( Gemfile Rakefile config.ru + app/assets/javascripts + app/assets/stylesheets app/controllers app/helpers app/mailers @@ -22,8 +24,6 @@ DEFAULT_APP_FILES = %w( lib/tasks log public/images - public/javascripts - public/stylesheets script/rails test/fixtures test/functional @@ -31,11 +31,9 @@ DEFAULT_APP_FILES = %w( test/performance test/unit vendor + vendor/assets vendor/plugins - tmp/sessions - tmp/sockets tmp/cache - tmp/pids ) class AppGeneratorTest < Rails::Generators::TestCase @@ -49,8 +47,9 @@ class AppGeneratorTest < Rails::Generators::TestCase def test_application_controller_and_layout_files run_generator - assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag :all/ - assert_no_file "public/stylesheets/application.css" + assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag\s+"application"/ + assert_file "app/views/layouts/application.html.erb", /javascript_include_tag\s+"application"/ + assert_file "app/assets/stylesheets/application.css" end def test_invalid_application_name_raises_an_error @@ -146,43 +145,40 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "config/application.rb", /#\s+require\s+["']active_record\/railtie["']/ end - def test_prototype_and_test_unit_are_added_by_default + def test_jquery_and_test_unit_are_added_by_default run_generator - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(jquery rails\)/ - assert_file "public/javascripts/application.js" - assert_file "public/javascripts/prototype.js" - assert_file "public/javascripts/rails.js" - assert_file "public/javascripts/controls.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/effects.js" + assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ + assert_file "app/assets/javascripts/application.js" + assert_file "vendor/assets/javascripts/jquery.js" + assert_file "vendor/assets/javascripts/jquery_ujs.js" assert_file "test" end def test_javascript_is_skipped_if_required run_generator [destination_root, "--skip-javascript"] assert_file "config/application.rb", /^\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/ - assert_file "public/javascripts/application.js" - assert_no_file "public/javascripts/prototype.js" - assert_no_file "public/javascripts/rails.js" + assert_file "app/assets/javascripts/application.js" + assert_no_file "vendor/assets/javascripts/jquery.js" + assert_no_file "vendor/assets/javascripts/jquery_ujs.js" end def test_config_prototype_javascript_library run_generator [destination_root, "-j", "prototype"] - assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(jquery rails\)/ - assert_file "public/javascripts/application.js" - assert_file "public/javascripts/prototype.js" - assert_file "public/javascripts/controls.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/effects.js" - assert_file "public/javascripts/rails.js", /prototype/ + assert_file "config/application.rb", /^\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ + assert_file "app/assets/javascripts/application.js" + assert_file "vendor/assets/javascripts/prototype.js" + assert_file "vendor/assets/javascripts/effects.js" + assert_file "vendor/assets/javascripts/dragdrop.js" + assert_file "vendor/assets/javascripts/controls.js" + assert_file "vendor/assets/javascripts/prototype_ujs.js", /prototype/ end def test_config_jquery_javascript_library run_generator [destination_root, "-j", "jquery"] - assert_file "config/application.rb", /^\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(jquery rails\)/ - assert_file "public/javascripts/application.js" - assert_file "public/javascripts/jquery.js" - assert_file "public/javascripts/rails.js", /jQuery/ + assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype effects dragdrop controls rails\)/ + assert_file "app/assets/javascripts/application.js" + assert_file "vendor/assets/javascripts/jquery.js" + assert_file "vendor/assets/javascripts/jquery_ujs.js", /jQuery/ end def test_template_from_dir_pwd @@ -216,6 +212,24 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_new_hash_style + run_generator [destination_root] + assert_file "config/initializers/session_store.rb" do |file| + if RUBY_VERSION < "1.9" + assert_match /config.session_store :cookie_store, :key => '_.+_session'/, file + else + assert_match /config.session_store :cookie_store, key: '_.+_session'/, file + end + end + end + + def test_force_old_style_hash + run_generator [destination_root, "--old-style-hash"] + assert_file "config/initializers/session_store.rb" do |file| + assert_match /config.session_store :cookie_store, :key => '_.+_session'/, file + end + end + protected def action(*args, &block) diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb new file mode 100644 index 0000000000..e99f0f092a --- /dev/null +++ b/railties/test/generators/assets_generator_test.rb @@ -0,0 +1,26 @@ +require 'generators/generators_test_helper' +require 'rails/generators/rails/assets/assets_generator' + +# FOXME: Silence the 'Could not find task "using_coffee?"' message in tests due to the public stub +class AssetsGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + arguments %w(posts) + + def test_assets + run_generator + assert_file "app/assets/javascripts/posts.js.coffee" + assert_file "app/assets/stylesheets/posts.css.scss" + end + + def test_skipping_assets + content = run_generator ["posts", "--no-stylesheets", "--no-javascripts"] + assert_no_file "app/assets/javascripts/posts.js.coffee" + assert_no_file "app/assets/stylesheets/posts.css.scss" + end + + def test_vanilla_assets + run_generator ["posts", "--no-javascript-engine", "--no-stylesheet-engine"] + assert_file "app/assets/javascripts/posts.js" + assert_file "app/assets/stylesheets/posts.css" + end +end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index be99dc068d..655d8ad450 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -37,6 +37,12 @@ class ControllerGeneratorTest < Rails::Generators::TestCase assert_no_file "test/unit/helpers/account_helper_test.rb" end + def test_invokes_assets + run_generator + assert_file "app/assets/javascripts/account.js" + assert_file "app/assets/stylesheets/account.css" + end + def test_invokes_default_test_framework run_generator assert_file "test/functional/account_controller_test.rb" diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb index 3c11c8dbaf..d20335ad95 100644 --- a/railties/test/generators/plugin_new_generator_test.rb +++ b/railties/test/generators/plugin_new_generator_test.rb @@ -95,41 +95,33 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_skipping_javascripts_without_mountable_option run_generator - assert_no_file "public/javascripts/prototype.js" - assert_no_file "public/javascripts/rails.js" - assert_no_file "public/javascripts/controls.js" - assert_no_file "public/javascripts/dragdrop.js" - assert_no_file "public/javascripts/dragdrop.js" - assert_no_file "public/javascripts/application.js" + assert_no_file "app/assets/javascripts/application.js" + assert_no_file "vendor/assets/javascripts/jquery.js" + assert_no_file "vendor/assets/javascripts/jquery_ujs.js" end def test_javascripts_generation run_generator [destination_root, "--mountable"] - assert_file "public/javascripts/rails.js" - assert_file "public/javascripts/prototype.js" - assert_file "public/javascripts/controls.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/dragdrop.js" - assert_file "public/javascripts/application.js" + assert_file "app/assets/javascripts/application.js" + assert_file "vendor/assets/javascripts/jquery.js" + assert_file "vendor/assets/javascripts/jquery_ujs.js" end def test_skip_javascripts run_generator [destination_root, "--skip-javascript", "--mountable"] - assert_no_file "public/javascripts/prototype.js" - assert_no_file "public/javascripts/rails.js" - assert_no_file "public/javascripts/controls.js" - assert_no_file "public/javascripts/dragdrop.js" - assert_no_file "public/javascripts/dragdrop.js" + assert_no_file "app/assets/javascripts/application.js" + assert_no_file "vendor/assets/javascripts/jquery.js" + assert_no_file "vendor/assets/javascripts/jquery_ujs.js" end - def test_ensure_that_javascript_option_is_passed_to_app_generator - run_generator [destination_root, "--javascript", "jquery"] - assert_file "test/dummy/public/javascripts/jquery.js" - end - - def test_ensure_that_skip_javascript_option_is_passed_to_app_generator - run_generator [destination_root, "--skip_javascript"] - assert_no_file "test/dummy/public/javascripts/prototype.js" + def test_config_prototype_javascript_library + run_generator [destination_root, "-j", "prototype", "--mountable"] + assert_file "app/assets/javascripts/application.js" + assert_file "vendor/assets/javascripts/prototype.js" + assert_file "vendor/assets/javascripts/effects.js" + assert_file "vendor/assets/javascripts/dragdrop.js" + assert_file "vendor/assets/javascripts/controls.js" + assert_file "vendor/assets/javascripts/prototype_ujs.js", /prototype/ end def test_template_from_dir_pwd @@ -153,6 +145,12 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase def test_creating_engine_in_full_mode run_generator [destination_root, "--full"] + assert_file "app/assets/javascripts" + assert_file "app/assets/stylesheets" + assert_file "app/models" + assert_file "app/controllers" + assert_file "app/views" + assert_file "app/helpers" assert_file "config/routes.rb", /Rails.application.routes.draw do/ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/ assert_file "lib/bukkits.rb", /require "bukkits\/engine"/ @@ -227,3 +225,4 @@ protected silence(:stdout){ generator.send(*args, &block) } end end + diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index d55ed22975..c7f45a807d 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -122,4 +122,22 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase ensure Unknown::Generators.send :remove_const, :ActiveModel end + + def test_new_hash_style + run_generator + assert_file "app/controllers/users_controller.rb" do |content| + if RUBY_VERSION < "1.9" + assert_match /\{ render :action => "new" \}/, content + else + assert_match /\{ render action: "new" \}/, content + end + end + end + + def test_force_old_style_hash + run_generator ["User", "--old-style-hash"] + assert_file "app/controllers/users_controller.rb" do |content| + assert_match /\{ render :action => "new" \}/, content + end + end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index df787f61ba..4b07f8bcbe 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -79,8 +79,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/helpers/product_lines_helper.rb" assert_file "test/unit/helpers/product_lines_helper_test.rb" - # Stylesheets - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/javascripts/product_lines.js.coffee" + assert_file "app/assets/stylesheets/product_lines.css.scss" end def test_scaffold_on_revoke @@ -110,8 +112,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "app/helpers/product_lines_helper.rb" assert_no_file "test/unit/helpers/product_lines_helper_test.rb" - # Stylesheets (should not be removed) - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_no_file "app/assets/javascripts/product_lines.js.coffee" + assert_no_file "app/assets/stylesheets/product_lines.css.scss" end def test_scaffold_with_namespace_on_invoke @@ -184,8 +188,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "app/helpers/admin/roles_helper.rb" assert_file "test/unit/helpers/admin/roles_helper_test.rb" - # Stylesheets - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/ + assert_file "app/assets/javascripts/admin/roles.js.coffee" + assert_file "app/assets/stylesheets/admin/roles.css.scss" end def test_scaffold_with_namespace_on_revoke @@ -216,8 +222,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_no_file "app/helpers/admin/roles_helper.rb" assert_no_file "test/unit/helpers/admin/roles_helper_test.rb" - # Stylesheets (should not be removed) - assert_file "public/stylesheets/scaffold.css" + # Assets + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/javascripts/admin/roles.js.coffee" + assert_no_file "app/assets/stylesheets/admin/roles.css.scss" end def test_scaffold_generator_on_revoke_does_not_mutilate_legacy_map_parameter @@ -235,6 +243,34 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase assert_file "config/routes.rb", /\.routes\.draw do\s*\|map\|\s*$/ end + def test_scaffold_generator_no_assets + run_generator [ "posts", "--no-assets" ] + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/javascripts/posts.js.coffee" + assert_no_file "app/assets/stylesheets/posts.css.scss" + end + + def test_scaffold_generator_no_stylesheets + run_generator [ "posts", "--no-stylesheets" ] + assert_no_file "app/assets/stylesheets/scaffold.css.scss" + assert_file "app/assets/javascripts/posts.js.coffee" + assert_no_file "app/assets/stylesheets/posts.css.scss" + end + + def test_scaffold_generator_no_javascripts + run_generator [ "posts", "--no-javascripts" ] + assert_file "app/assets/stylesheets/scaffold.css.scss" + assert_no_file "app/assets/javascripts/posts.js.coffee" + assert_file "app/assets/stylesheets/posts.css.scss" + end + + def test_scaffold_generator_no_negines + run_generator [ "posts", "--no-javascript-engine", "--no-stylesheet-engine" ] + assert_file "app/assets/stylesheets/scaffold.css" + assert_file "app/assets/javascripts/posts.js" + assert_file "app/assets/stylesheets/posts.css" + end + def test_scaffold_generator_outputs_error_message_on_missing_attribute_type content = capture(:stderr) { run_generator ["post", "title:string", "body"]} assert_match(/Missing type for attribute 'body'/, content) diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb deleted file mode 100644 index aaeb686daa..0000000000 --- a/railties/test/generators/stylesheets_generator_test.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'generators/generators_test_helper' -require 'rails/generators/rails/stylesheets/stylesheets_generator' - -class StylesheetsGeneratorTest < Rails::Generators::TestCase - include GeneratorsTestHelper - - def test_copy_stylesheets - run_generator - assert_file "public/stylesheets/scaffold.css" - end - - def test_stylesheets_are_not_deleted_on_revoke - run_generator - run_generator [], :behavior => :revoke - assert_file "public/stylesheets/scaffold.css" - end -end diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index c5b1cb9a80..f2261540ca 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -90,6 +90,7 @@ module TestHelpers end module Generation + # Build an application by invoking the generator and going through the whole stack. def build_app(options = {}) FileUtils.rm_rf(app_path) FileUtils.cp_r(tmp_path('app_template'), app_path) @@ -115,6 +116,8 @@ module TestHelpers add_to_config 'config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"; config.session_store :cookie_store, :key => "_myapp_session"; config.active_support.deprecation = :log' end + # Make a very basic app, without creating the whole directory structure. + # This is faster and simpler than the method above. def make_basic_app require "rails" require "action_controller/railtie" diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 20797a2b0c..7605984684 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1,8 +1,7 @@ require "isolation/abstract_unit" require "railties/shared_tests" -require 'stringio' -require 'rack/test' -require 'rack/file' +require "stringio" +require "rack/test" module RailtiesTest class EngineTest < Test::Unit::TestCase @@ -188,6 +187,7 @@ module RailtiesTest end RUBY + require "rack/file" boot_rails env = Rack::MockRequest.env_for("/") @@ -199,194 +199,6 @@ module RailtiesTest assert_equal Rails.application.routes, env['action_dispatch.routes'] end - test "it allows to set asset_path" do - @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits - class Engine < ::Rails::Engine - end - end - RUBY - - - @plugin.write "config/routes.rb", <<-RUBY - Bukkits::Engine.routes.draw do - match "/foo" => "foo#index" - end - RUBY - - @plugin.write "app/controllers/foo_controller.rb", <<-RUBY - class FooController < ActionController::Base - def index - render :index - end - end - RUBY - - @plugin.write "app/views/foo/index.html.erb", <<-ERB - <%= image_path("foo.png") %> - <%= javascript_include_tag("foo") %> - <%= stylesheet_link_tag("foo") %> - ERB - - app_file "config/routes.rb", <<-RUBY - Rails.application.routes.draw do - mount Bukkits::Engine => "/bukkits" - end - RUBY - - add_to_config 'config.asset_path = "/omg%s"' - - boot_rails - - # should set asset_path with engine name by default - assert_equal "/bukkits_engine%s", ::Bukkits::Engine.config.asset_path - - ::Bukkits::Engine.config.asset_path = "/bukkits%s" - - get("/bukkits/foo") - stripped_body = last_response.body.split("\n").map(&:strip).join - - expected = "/omg/bukkits/images/foo.png" + - "<script src=\"/omg/bukkits/javascripts/foo.js\" type=\"text/javascript\"></script>" + - "<link href=\"/omg/bukkits/stylesheets/foo.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />" - assert_equal expected, stripped_body - end - - test "default application's asset_path" do - @plugin.write "config/routes.rb", <<-RUBY - Bukkits::Engine.routes.draw do - match "/foo" => "foo#index" - end - RUBY - - @plugin.write "app/controllers/foo_controller.rb", <<-RUBY - class FooController < ActionController::Base - def index - render :inline => '<%= image_path("foo.png") %>' - end - end - RUBY - - app_file "config/routes.rb", <<-RUBY - AppTemplate::Application.routes.draw do - mount Bukkits::Engine => "/bukkits" - end - RUBY - - boot_rails - - get("/bukkits/foo") - assert_equal "/bukkits/images/foo.png", last_response.body.strip - end - - test "engine's files are served via ActionDispatch::Static" do - add_to_config "config.serve_static_assets = true" - - @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits - class Engine < ::Rails::Engine - engine_name :bukkits - end - end - RUBY - - @plugin.write "public/bukkits.html", "/bukkits/bukkits.html" - app_file "public/app.html", "/app.html" - app_file "public/bukkits/file_from_app.html", "/bukkits/file_from_app.html" - - boot_rails - - get("/app.html") - assert_equal File.read(File.join(app_path, "public/app.html")), last_response.body - - get("/bukkits/bukkits.html") - assert_equal File.read(File.join(@plugin.path, "public/bukkits.html")), last_response.body - - get("/bukkits/file_from_app.html") - assert_equal File.read(File.join(app_path, "public/bukkits/file_from_app.html")), last_response.body - end - - test "an applications files are given priority over an engines files when served via ActionDispatch::Static" do - add_to_config "config.serve_static_assets = true" - - @plugin.write "lib/bukkits.rb", <<-RUBY - class Bukkits - class Engine < ::Rails::Engine - engine_name :bukkits - end - end - RUBY - - app_file "config/routes.rb", <<-RUBY - AppTemplate::Application.routes.draw do - mount Bukkits::Engine => "/bukkits" - end - RUBY - - @plugin.write "public/bukkits.html", "in engine" - - app_file "public/bukkits/bukkits.html", "in app" - - boot_rails - - get('/bukkits/bukkits.html') - - assert_equal 'in app', last_response.body.strip - end - - test "shared engine should include application's helpers and own helpers" do - app_file "config/routes.rb", <<-RUBY - AppTemplate::Application.routes.draw do - match "/foo" => "bukkits/foo#index", :as => "foo" - match "/foo/show" => "bukkits/foo#show" - match "/foo/bar" => "bukkits/foo#bar" - end - RUBY - - app_file "app/helpers/some_helper.rb", <<-RUBY - module SomeHelper - def something - "Something... Something... Something..." - end - end - RUBY - - @plugin.write "app/helpers/bar_helper.rb", <<-RUBY - module BarHelper - def bar - "It's a bar." - end - end - RUBY - - @plugin.write "app/controllers/bukkits/foo_controller.rb", <<-RUBY - class Bukkits::FooController < ActionController::Base - def index - render :inline => "<%= something %>" - end - - def show - render :text => foo_path - end - - def bar - render :inline => "<%= bar %>" - end - end - RUBY - - boot_rails - - get("/foo") - assert_equal "Something... Something... Something...", last_response.body - - get("/foo/show") - assert_equal "/foo", last_response.body - - get("/foo/bar") - assert_equal "It's a bar.", last_response.body - end - test "isolated engine should include only its own routes and helpers" do @plugin.write "lib/bukkits.rb", <<-RUBY module Bukkits @@ -772,70 +584,6 @@ module RailtiesTest assert_equal Bukkits::Engine.instance, Rails::Engine.find(engine_path) end - test "ensure that engine properly sets assets directories" do - add_to_config("config.action_dispatch.show_exceptions = false") - add_to_config("config.serve_static_assets = true") - - @plugin.write "lib/bukkits.rb", <<-RUBY - module Bukkits - class Engine < ::Rails::Engine - isolate_namespace Bukkits - end - end - RUBY - - @plugin.write "public/stylesheets/foo.css", "" - @plugin.write "public/javascripts/foo.js", "" - - @plugin.write "app/views/layouts/bukkits/application.html.erb", <<-RUBY - <%= stylesheet_link_tag :all %> - <%= javascript_include_tag :all %> - <%= yield %> - RUBY - - @plugin.write "app/controllers/bukkits/home_controller.rb", <<-RUBY - module Bukkits - class HomeController < ActionController::Base - def index - render :text => "Good morning!", :layout => "bukkits/application" - end - end - end - RUBY - - @plugin.write "config/routes.rb", <<-RUBY - Bukkits::Engine.routes.draw do - match "/home" => "home#index" - end - RUBY - - app_file "config/routes.rb", <<-RUBY - Rails.application.routes.draw do - mount Bukkits::Engine => "/bukkits" - end - RUBY - - require 'rack/test' - extend Rack::Test::Methods - - boot_rails - - require "#{rails_root}/config/environment" - - assert_equal File.join(@plugin.path, "public"), Bukkits::HomeController.assets_dir - assert_equal File.join(@plugin.path, "public/stylesheets"), Bukkits::HomeController.stylesheets_dir - assert_equal File.join(@plugin.path, "public/javascripts"), Bukkits::HomeController.javascripts_dir - - assert_equal File.join(app_path, "public"), ActionController::Base.assets_dir - assert_equal File.join(app_path, "public/stylesheets"), ActionController::Base.stylesheets_dir - assert_equal File.join(app_path, "public/javascripts"), ActionController::Base.javascripts_dir - - get "/bukkits/home" - - assert_match %r{bukkits/stylesheets/foo.css}, last_response.body - assert_match %r{bukkits/javascripts/foo.js}, last_response.body - end - private def app Rails.application diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 3eb79d57c8..b2b18938ae 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -10,42 +10,16 @@ module RailtiesTest @app ||= Rails.application end - def test_install_migrations_and_assets - @plugin.write "public/javascripts/foo.js", "doSomething()" + def test_serving_sprockets_assets + @plugin.write "app/assets/javascripts/engine.js.coffee", "square = (x) -> x * x" - @plugin.write "db/migrate/1_create_users.rb", <<-RUBY - class CreateUsers < ActiveRecord::Migration - end - RUBY - - app_file "db/migrate/1_create_sessions.rb", <<-RUBY - class CreateSessions < ActiveRecord::Migration - end - RUBY - - add_to_config "ActiveRecord::Base.timestamped_migrations = false" - - Dir.chdir(app_path) do - `rake bukkits:install` - assert File.exists?("#{app_path}/db/migrate/2_create_users.rb") - assert File.exists?(app_path("public/bukkits/javascripts/foo.js")) - end - end - - def test_copying_assets - @plugin.write "public/javascripts/foo.js", "doSomething()" - @plugin.write "public/stylesheets/foo.css", "h1 { font-size: 10000px }" - @plugin.write "public/images/img.png", "" - - Dir.chdir(app_path) do - `rake bukkits:install:assets --trace` + boot_rails + require 'rack/test' + require 'coffee_script' + extend Rack::Test::Methods - assert File.exists?(app_path("public/bukkits/javascripts/foo.js")) - assert_equal "doSomething()\n", File.read(app_path("public/bukkits/javascripts/foo.js")) - assert File.exists?(app_path("public/bukkits/stylesheets/foo.css")) - assert_equal "h1 { font-size: 10000px }\n", File.read(app_path("public/bukkits/stylesheets/foo.css")) - assert File.exists?(app_path("public/bukkits/images/img.png")) - end + get "/assets/engine.js" + assert_match "square = function(x) {", last_response.body end def test_copying_migrations |