Commit Graph

18243 Commits

Author SHA1 Message Date
Piotr Sarnacki
98ab4ded37 Set only helpers_path on inherited hook in action_controller/railtie.rb and use helper(:all) just after that 2010-09-03 22:59:13 +02:00
Piotr Sarnacki
8ec2175aee Added more tests for polymorphic_url with namespaced models and implemented missing use cases 2010-09-03 22:59:13 +02:00
Piotr Sarnacki
00874a2009 This was used only to clear warning in ActionMailer tests, it shouldn't be done like that 2010-09-03 22:59:13 +02:00
Piotr Sarnacki
e5af8b7d85 Moved ActionMailer and ActionController railties options to inherited hook
This change is needed, because we must take namespace into account and if
controller's/mailer's class is namespaced, engine's paths should be set
instead of application's ones.

The nice side effect of this is removing unneeded logic in
ActionController::Base.inherited - now the helpers_path should be set
correctly even for engine's controllers, so helper(:all) will always
include correct helpers.
2010-09-03 22:59:12 +02:00
Piotr Sarnacki
8fb9df535e Modified polymorphic_url to check for model's namespace
This change allows using namespaced models with polymorphic_url,
in the way that you would use them without namespace.

Let's say that you have Blog::Post model in namespaced Engine. When you use
polymorphic_path with Blog::Post instances, like in form_for(@post),
it will look for blog_posts_path named url helper. As we are inside Blog::Engine,
it's annoying to always use the prefix. With this commit, blog_ prefix will be
removed and posts_path will be called.
2010-09-03 22:59:12 +02:00
Piotr Sarnacki
8284fd3855 Get rid of static_paths method and instead configure paths for ActionDispatch::Static in initializers 2010-09-03 22:59:12 +02:00
Piotr Sarnacki
d812677277 We don't need to clear action_methods on inherited hook as they are cleaned on method_added hook 2010-09-03 22:59:12 +02:00
Piotr Sarnacki
56ef192374 ActionMailer should not depend on ActionDispatch 2010-09-03 22:59:12 +02:00
Piotr Sarnacki
f3c703a32f Refactor RoutesProxy to avoid using _with_routes in helpers 2010-09-03 22:59:12 +02:00
Piotr Sarnacki
434139f89f Documented mounted helpers 2010-09-03 22:59:12 +02:00
Piotr Sarnacki
1a161c75ed Document engine_name 2010-09-03 22:59:11 +02:00
Piotr Sarnacki
2e4e1e7d0c Added documentation for namespaced Engine 2010-09-03 22:59:11 +02:00
Piotr Sarnacki
db8a864e69 Add table_name_prefix to Engine's namespace automatically 2010-09-03 22:59:11 +02:00
Piotr Sarnacki
a7c6fe4c2a Rename isolated_engine_for to namespace 2010-09-03 22:59:11 +02:00
Piotr Sarnacki
79bd92b783 Refactor ActionMailer to not use hide_actions 2010-09-03 22:59:11 +02:00
Piotr Sarnacki
4131a2d804 Move ActionController::Railties::RoutesHelpers and ActionMailer::Railties::RoutesHelper to AbstractController::Railties::RoutesHelpers 2010-09-03 22:59:11 +02:00
Piotr Sarnacki
32baa27892 Include routes helpers only for inherited classes in ActionMailer 2010-09-03 22:59:10 +02:00
Piotr Sarnacki
befa77fc18 Fix generating urls with mounted helpers in view context
There were actually 2 problems with this one:
* script_name was added to options as a string and then it was used
  in RouteSet#url_for with usage of <<, which was changing the original
  script_name
* the second issue was with _with_routes method. It was called in RoutesProxy
  to modify _routes in view_context, but url_helpers in views is just delegating
  it to controller, so another _with_routes call is needed there
2010-09-03 22:59:10 +02:00
Piotr Sarnacki
e063879daf Fix copying migrations to empty directory 2010-09-03 22:59:10 +02:00
Piotr Sarnacki
c7664d112f Include application's helpers and router helpers by default, but include engine's ones for controllers inside isolated namespace 2010-09-03 22:59:10 +02:00
Piotr Sarnacki
9913193931 For view_context we need to initialize RoutesProxy in context of controller, not view, quick fix, I need to dig into it later 2010-09-03 22:59:10 +02:00
Piotr Sarnacki
8fdeff0fa5 mounted helpers should be included in ActionMailer 2010-09-03 22:59:10 +02:00
Piotr Sarnacki
2734d3819f This is not needed 2010-09-03 22:59:10 +02:00
Piotr Sarnacki
937f41919c Engine's assets are now served with ActionDispatch::Static 2010-09-03 22:59:09 +02:00
Piotr Sarnacki
401cd97923 Modified ActionDispatch::Static to allow passing multiple roots 2010-09-03 22:59:09 +02:00
Piotr Sarnacki
5b6553ebb5 Set asset_path to engine_name by default 2010-09-03 22:59:09 +02:00
Piotr Sarnacki
559979b984 Always convert railtie_name to string 2010-09-03 22:59:09 +02:00
Piotr Sarnacki
43a2aef316 rake db:copy_migrations task, which copies railties migrations into application's db/migrate directory 2010-09-03 22:59:09 +02:00
Piotr Sarnacki
75f8ac6ea7 Implemented ActiveRecord::Migrations#copy based on James Adam's idea
ActiveRecord::Migration#copy allows to copy migrations from one place
to another, changing migrations versions and adding scope to filename.

For example:
ActiveRecord::Migration.copy("db/migrate",
        :blog_engine => "vendor/gems/blog/db/migrate")

will copy all migrations from vendor/gems/blog/db/migrate to db/migrate
with such format:

Versions of copied migrations will be reversioned to be appended after
migrations that already exists in db/migrate
2010-09-03 22:59:09 +02:00
Piotr Sarnacki
2068b8cb6a Added tests for railtie_name and aliased it in engine as engine_name 2010-09-03 22:59:09 +02:00
Piotr Sarnacki
bfccbc6df9 Add Rails::Railtie.railtie_name method to allow setting custom name for railtie 2010-09-03 22:59:08 +02:00
Piotr Sarnacki
b52dfc6726 Added Rails.application.config.paths.db.migrate to remove hardcoded db/migrate paths 2010-09-03 22:59:08 +02:00
Piotr Sarnacki
0c1cd15470 to_param shoul return a string 2010-09-03 22:59:08 +02:00
Piotr Sarnacki
4cd6f77526 We don't need delegating polymorphic_url and polymorphic_path anymore 2010-09-03 22:59:08 +02:00
Piotr Sarnacki
a132229d7b Added ability to set asset_path for engines 2010-09-03 22:59:08 +02:00
Piotr Sarnacki
abeb0ff2cc Ensure that Rails.application.initialize! is called only once 2010-09-03 22:59:07 +02:00
Piotr Sarnacki
153df92f9f Added documentation on endpoint, middeware stack and routes for Engine 2010-09-03 22:59:07 +02:00
Piotr Sarnacki
ccd422f792 We don't need that initializer in tests 2010-09-03 22:59:07 +02:00
Piotr Sarnacki
1e6612ef80 Ensure that url_helpers included after application's ones have higher priority 2010-09-03 22:59:07 +02:00
Piotr Sarnacki
6c95e0f879 Add mounted_helpers to routes
mounted_helpers are a bit similar to url_helpers. They're automatically
included in controllers for Rails.application and each of mounted
Engines. Mounted helper allows to call url_for and named helpers for
given application.

Given Blog::Engine mounted as blog_engine, there are 2 helpers defined:
app and blog_engine. You can call routes for app and engine using those
helpers:

app.root_url
app.url_for(:controller => "foo")
blog_engine.posts_path
blog_engine.url_for(@post)
2010-09-03 22:59:07 +02:00
Piotr Sarnacki
e9791bec82 Routes refactoring:
* added more tests for prefix generation
* fixed bug with generating host for both prefix and url
* refactored url_for method
* organized tests for prefix generation
2010-09-03 22:59:07 +02:00
Piotr Sarnacki
229a868264 Use new url_for API instead of including routes.url_helpers 2010-09-03 22:59:06 +02:00
Piotr Sarnacki
233be6572c Ensure that env is always available in controllers 2010-09-03 22:59:06 +02:00
Piotr Sarnacki
b53efd2105 Extended url_for to handle specifying which router should be used.
A few examples:
url_for Blog::Engine, :posts_path
url_for Blog::Engine, @post
url_for Blog::Engine, :action => "main", :controller => "index"
2010-09-03 22:59:06 +02:00
Piotr Sarnacki
b697ba9fd7 Added some more tests for url generation between Engine and Application 2010-09-03 22:59:06 +02:00
Piotr Sarnacki
8a077089d9 Get rid of :skip_prefix options in routes 2010-09-03 22:59:06 +02:00
Piotr Sarnacki
b1e5e233fa Refactored tests for prefix generation and added test for url generation in regular class with default_url_options[:script_name] set 2010-09-03 22:59:05 +02:00
Piotr Sarnacki
eedbf87d15 New way of generating urls for Application from Engine.
It's based specifying application's script_name with:
Rails.application.default_url_options = {:script_name => "/foo"}

default_url_options method is delegated to routes. If router
used to generate url differs from the router passed via env
it always overwrites :script_name with this value.
2010-09-03 22:59:05 +02:00
Piotr Sarnacki
177a4bd5b7 Fix url generation for mounted Engine
I added integration tests for generating urls in Engine and application
and tweaked Engines to fully cooparate with new router's behavior:
* Rails.application now sets ORIGINAL_SCRIPT_NAME
* Rails.application also sets its routes as env['action_dispatch.parent_routes']
* Engine implements responds_to? class method to respond to all the
  instance methods, like #routes
2010-09-03 22:59:05 +02:00
Piotr Sarnacki
451c9942bb Allow to generate Application routes inside Engine
This requires knowledge about original SCRIPT_NAME and
the parent router. It should be pass through the env
as ORIGIAL_SCRIPT_NAME and action_dispatch.parent_routes
2010-09-03 22:59:05 +02:00