From 74598fe7e9097484c4029e2731e462c6c82836f9 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 25 Sep 2010 19:02:14 +0200 Subject: Do not overwrite _railtie method on namespace while creating isolated engine or application. In order to run Engine as standalone application, you will need Rails::Application instance in the same namespace that engine one. It's very important to leave _railtie bound to whatever used "namespace" method first. --- railties/test/railties/engine_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index a9dd7d4c1b..17bffe05e1 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -643,5 +643,25 @@ module RailtiesTest Bukkits::Engine.load_seed assert Bukkits::Engine.config.bukkits_seeds_loaded end + + test "using namespace more than once on one module should not overwrite _railtie method" do + @plugin.write "lib/bukkits.rb", <<-RUBY + module AppTemplate + class Engine < ::Rails::Engine + namespace(AppTemplate) + end + end + RUBY + + add_to_config "namespace AppTemplate" + + app_file "config/routes.rb", <<-RUBY + AppTemplate::Application.routes.draw do end + RUBY + + boot_rails + + assert_equal AppTemplate._railtie, AppTemplate::Engine + end end end -- cgit v1.2.3 From ec5d846ac6137e60d81257041e4fde82c0480b32 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sun, 26 Sep 2010 00:17:06 +0200 Subject: Properly reload routes defined in class definition Sometimes it's easier to define routes inside Engine or Application class definition (e.g. one file applications). The problem with such case is that if there is a plugin that has config/routes.rb file, it will trigger routes reload on application. Since routes definition for application is not in config/routes.rb file routes_reloader will fail to reload application's routes properly. With this commit you can pass routes definition as a block to routes method, which will allow to properly reload it: class MyApp::Application < Rails::Application routes do resources :users end end --- railties/test/railties/engine_test.rb | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 17bffe05e1..2b9d728b0c 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -663,5 +663,45 @@ module RailtiesTest assert_equal AppTemplate._railtie, AppTemplate::Engine end + + test "properly reload routes" do + # when routes are inside application class definition + # they should not be reloaded when engine's routes + # file has changed + add_to_config <<-RUBY + routes do + mount lambda{|env| [200, {}, ["foo"]]} => "/foo" + mount Bukkits::Engine => "/bukkits" + end + RUBY + + FileUtils.rm(File.join(app_path, "config/routes.rb")) + + @plugin.write "config/routes.rb", <<-RUBY + Bukkits::Engine.routes.draw do + mount lambda{|env| [200, {}, ["bar"]]} => "/bar" + end + RUBY + + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + namespace(Bukkits) + end + end + RUBY + + require 'rack/test' + extend Rack::Test::Methods + + boot_rails + + require "#{rails_root}/config/environment" + get "/foo" + assert_equal "foo", last_response.body + + get "/bukkits/bar" + assert_equal "bar", last_response.body + end end end -- cgit v1.2.3 From f851352318c7468db310e5fbea0d86dc8b731c6d Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 29 Sep 2010 17:41:30 +0200 Subject: Added config.app_generators to allow configuring application's generators from railties. With config.generators becomes a way to configure generators for current instance only. For example: module Blog class Engine < Rails::Engine config.generators do |g| g.orm :active_record end config.app_generators do |g| g.test_framework :rspec end end end such definition sets :active_record as orm for engine and :rspec as test_framework for application. The values set with app_generators can be overwritten in application using config.generators as you would normally do: module MyApp class Application < Rails::Application config.generators do |g| g.test_framework :test_unit end end end --- railties/test/railties/engine_test.rb | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'railties/test') diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 2b9d728b0c..c75639d740 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -703,5 +703,44 @@ module RailtiesTest get "/bukkits/bar" assert_equal "bar", last_response.body end + + test "setting generators for engine and overriding app generator's" do + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + config.generators do |g| + g.orm :datamapper + g.template_engine :haml + g.test_framework :rspec + end + + config.app_generators do |g| + g.orm :mongoid + g.template_engine :liquid + g.test_framework :shoulda + end + end + end + RUBY + + add_to_config <<-RUBY + config.generators do |g| + g.test_framework :test_unit + end + RUBY + + boot_rails + require "#{rails_root}/config/environment" + + app_generators = Rails.application.config.generators.options[:rails] + assert_equal :mongoid , app_generators[:orm] + assert_equal :liquid , app_generators[:template_engine] + assert_equal :test_unit, app_generators[:test_framework] + + generators = Bukkits::Engine.config.generators.options[:rails] + assert_equal :datamapper, generators[:orm] + assert_equal :haml , generators[:template_engine] + assert_equal :rspec , generators[:test_framework] + end end end -- cgit v1.2.3