Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'rails/master'

  • Loading branch information...
commit 4329f8133fee8e4f3e558787f67de59f0c4a4dd1 2 parents c37f7d6 + ebee77a
Xavier Noria fxn authored
Showing with 3,105 additions and 2,206 deletions.
  1. +1 −0  Gemfile
  2. +1 −0  actionmailer/lib/action_mailer/base.rb
  3. +22 −0 actionmailer/lib/action_mailer/log_subscriber.rb
  4. +0 −3  actionmailer/lib/action_mailer/railtie.rb
  5. +0 −22 actionmailer/lib/action_mailer/railties/log_subscriber.rb
  6. +4 −4 actionmailer/test/log_subscriber_test.rb
  7. +3 −3 actionmailer/test/old_base/mail_service_test.rb
  8. +8 −0 actionpack/CHANGELOG
  9. +1 −1  actionpack/actionpack.gemspec
  10. +2 −0  actionpack/lib/action_controller/base.rb
  11. +56 −0 actionpack/lib/action_controller/log_subscriber.rb
  12. +1 −1  actionpack/lib/action_controller/metal.rb
  13. +13 −5 actionpack/lib/action_controller/metal/responder.rb
  14. +0 −3  actionpack/lib/action_controller/railtie.rb
  15. +0 −56 actionpack/lib/action_controller/railties/log_subscriber.rb
  16. +15 −3 actionpack/lib/action_controller/test_case.rb
  17. +4 −1 actionpack/lib/action_dispatch/http/request.rb
  18. +9 −2 actionpack/lib/action_dispatch/middleware/flash.rb
  19. +113 −36 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
  20. +25 −18 actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
  21. +9 −0 actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
  22. +50 −33 actionpack/lib/action_dispatch/routing/mapper.rb
  23. +27 −4 actionpack/lib/action_dispatch/routing/route_set.rb
  24. +0 −1  actionpack/lib/action_dispatch/testing/assertions/routing.rb
  25. +19 −23 actionpack/lib/action_dispatch/testing/assertions/selector.rb
  26. +6 −1 actionpack/lib/action_view/base.rb
  27. +16 −2 actionpack/lib/action_view/helpers/active_model_helper.rb
  28. +14 −33 actionpack/lib/action_view/helpers/asset_tag_helper.rb
  29. +2 −2 actionpack/lib/action_view/helpers/date_helper.rb
  30. +14 −15 actionpack/lib/action_view/helpers/form_helper.rb
  31. +6 −8 actionpack/lib/action_view/helpers/prototype_helper.rb
  32. +2 −4 actionpack/lib/action_view/helpers/scriptaculous_helper.rb
  33. +27 −0 actionpack/lib/action_view/log_subscriber.rb
  34. +14 −3 actionpack/lib/action_view/railtie.rb
  35. +0 −27 actionpack/lib/action_view/railties/log_subscriber.rb
  36. +1 −1  actionpack/lib/action_view/template/resolver.rb
  37. +33 −13 actionpack/lib/action_view/test_case.rb
  38. +12 −2 actionpack/test/abstract/callbacks_test.rb
  39. +15 −0 actionpack/test/abstract_unit.rb
  40. +45 −2 actionpack/test/activerecord/active_record_store_test.rb
  41. +5 −5 actionpack/test/activerecord/controller_runtime_test.rb
  42. +17 −3 actionpack/test/controller/flash_test.rb
  43. +5 −5 actionpack/test/controller/log_subscriber_test.rb
  44. +38 −0 actionpack/test/controller/new_base/base_test.rb
  45. +9 −3 actionpack/test/controller/url_for_test.rb
  46. +185 −4 actionpack/test/dispatch/routing_test.rb
  47. +39 −4 actionpack/test/dispatch/session/cookie_store_test.rb
  48. +65 −2 actionpack/test/dispatch/session/mem_cache_store_test.rb
  49. +10 −0 actionpack/test/fixtures/session_autoload_test/session_autoload_test/foo.rb
  50. +7 −0 actionpack/test/template/active_model_helper_test.rb
  51. +7 −15 actionpack/test/template/asset_tag_helper_test.rb
  52. +15 −0 actionpack/test/template/form_helper_test.rb
  53. +5 −5 actionpack/test/template/log_subscriber_test.rb
  54. +36 −9 actionpack/test/template/test_case_test.rb
  55. +22 −0 actionpack/test/template/url_helper_test.rb
  56. +1 −1  activemodel/lib/active_model/deprecated_error_methods.rb
  57. +50 −24 activemodel/lib/active_model/errors.rb
  58. +0 −1  activemodel/lib/active_model/observing.rb
  59. +2 −2 activemodel/lib/active_model/validations/acceptance.rb
  60. +3 −3 activemodel/lib/active_model/validations/confirmation.rb
  61. +3 −2 activemodel/lib/active_model/validations/exclusion.rb
  62. +3 −3 activemodel/lib/active_model/validations/format.rb
  63. +3 −2 activemodel/lib/active_model/validations/inclusion.rb
  64. +6 −2 activemodel/lib/active_model/validations/length.rb
  65. +9 −4 activemodel/lib/active_model/validations/numericality.rb
  66. +1 −1  activemodel/lib/active_model/validations/presence.rb
  67. +0 −3  activemodel/lib/active_model/validations/with.rb
  68. +1 −0  activemodel/test/cases/helper.rb
  69. +2 −1  activemodel/test/cases/validations/callbacks_test.rb
  70. +41 −41 activemodel/test/cases/validations/i18n_generate_message_validation_test.rb
  71. +169 −338 activemodel/test/cases/validations/i18n_validation_test.rb
  72. +1 −1  activemodel/test/cases/validations/presence_validation_test.rb
  73. +33 −9 activemodel/test/cases/validations_test.rb
  74. +254 −254 activerecord/CHANGELOG
  75. +4 −1 activerecord/Rakefile
  76. +3 −3 activerecord/examples/performance.rb
  77. +2 −4 activerecord/lib/active_record/aggregations.rb
  78. +7 −7 activerecord/lib/active_record/associations/association_collection.rb
  79. +2 −2 activerecord/lib/active_record/autosave_association.rb
  80. +4 −10 activerecord/lib/active_record/base.rb
  81. +3 −1 activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
  82. +10 −0 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
  83. +48 −4 activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
  84. +4 −3 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  85. +1 −1  activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  86. +12 −15 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
  87. +7 −3 activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
  88. +5 −15 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  89. +32 −0 activerecord/lib/active_record/log_subscriber.rb
  90. +11 −8 activerecord/lib/active_record/nested_attributes.rb
  91. +0 −3  activerecord/lib/active_record/railtie.rb
  92. +0 −32 activerecord/lib/active_record/railties/log_subscriber.rb
  93. +10 −1 activerecord/lib/active_record/relation.rb
  94. +4 −4 activerecord/lib/active_record/relation/finder_methods.rb
  95. +1 −1  activerecord/lib/active_record/relation/predicate_builder.rb
  96. +97 −72 activerecord/lib/active_record/relation/query_methods.rb
  97. +8 −0 activerecord/lib/active_record/session_store.rb
  98. +1 −1  activerecord/lib/active_record/validations/associated.rb
  99. +1 −1  activerecord/lib/active_record/validations/uniqueness.rb
  100. +8 −6 activerecord/lib/rails/generators/active_record/migration/templates/migration.rb
  101. +1 −1  activerecord/lib/rails/generators/active_record/model/model_generator.rb
  102. 0  activerecord/test/cases/{connection_test_firebird.rb → adapters/firebird/connection_test.rb}
  103. 0  activerecord/test/cases/{default_test_firebird.rb → adapters/firebird/default_test.rb}
  104. 0  activerecord/test/cases/{migration_test_firebird.rb → adapters/firebird/migration_test.rb}
  105. +3 −3 activerecord/test/cases/{active_schema_test_mysql.rb → adapters/mysql/active_schema_test.rb}
  106. 0  activerecord/test/cases/{connection_test_mysql.rb → adapters/mysql/connection_test.rb}
  107. 0  activerecord/test/cases/{reserved_word_test_mysql.rb → adapters/mysql/reserved_word_test.rb}
  108. 0  activerecord/test/cases/{synonym_test_oracle.rb → adapters/oracle/synonym_test.rb}
  109. +4 −1 activerecord/test/cases/{active_schema_test_postgresql.rb → adapters/postgresql/active_schema_test.rb}
  110. +1 −1  activerecord/test/cases/{datatype_test_postgresql.rb → adapters/postgresql/datatype_test.rb}
  111. +1 −1  ...est/cases/{schema_authorization_test_postgresql.rb → adapters/postgresql/schema_authorization_test.rb}
  112. +4 −0 activerecord/test/cases/{schema_test_postgresql.rb → adapters/postgresql/schema_test.rb}
  113. 0  activerecord/test/cases/{copy_table_test_sqlite.rb → adapters/sqlite/copy_table_test.rb}
  114. +56 −0 activerecord/test/cases/adapters/sqlite/sqlite3_adapter_test.rb
  115. +0 −28 activerecord/test/cases/aggregations_test.rb
  116. +2 −2 activerecord/test/cases/associations/cascaded_eager_loading_test.rb
  117. +9 −1 activerecord/test/cases/base_test.rb
  118. +1 −1  activerecord/test/cases/calculations_test.rb
  119. +4 −5 activerecord/test/cases/log_subscriber_test.rb
  120. +5 −3 activerecord/test/cases/method_scoping_test.rb
  121. +108 −4 activerecord/test/cases/migration_test.rb
  122. +15 −13 activerecord/test/cases/nested_attributes_test.rb
  123. +5 −5 activerecord/test/cases/reflection_test.rb
  124. +52 −4 activerecord/test/cases/relations_test.rb
  125. +6 −6 activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
  126. +28 −22 activerecord/test/cases/validations/i18n_validation_test.rb
  127. +1 −1  activerecord/test/fixtures/topics.yml
  128. +1 −0  activerecord/test/schema/schema.rb
  129. +1 −0  activeresource/lib/active_resource/base.rb
  130. +14 −2 activeresource/lib/active_resource/http_mock.rb
  131. +15 −0 activeresource/lib/active_resource/log_subscriber.rb
  132. +0 −3  activeresource/lib/active_resource/railtie.rb
  133. +0 −15 activeresource/lib/active_resource/railties/log_subscriber.rb
  134. +1 −1  activeresource/lib/active_resource/validations.rb
  135. +12 −1 activeresource/test/cases/base_errors_test.rb
  136. +71 −0 activeresource/test/cases/http_mock_test.rb
  137. +4 −5 activeresource/test/cases/log_subscriber_test.rb
  138. +2 −0  activesupport/CHANGELOG
  139. +2 −1  activesupport/lib/active_support.rb
  140. +1 −0  activesupport/lib/active_support/all.rb
  141. +40 −25 activesupport/lib/active_support/cache.rb
  142. +2 −2 activesupport/lib/active_support/cache/mem_cache_store.rb
  143. +1 −0  activesupport/lib/active_support/core_ext/class.rb
  144. +1 −1  activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
  145. +0 −38 activesupport/lib/active_support/core_ext/logger.rb
  146. +4 −11 activesupport/lib/active_support/core_ext/string/conversions.rb
  147. +11 −0 activesupport/lib/active_support/core_ext/string/inflections.rb
  148. +27 −18 activesupport/lib/active_support/dependencies.rb
  149. +2 −2 activesupport/lib/active_support/file_update_checker.rb
  150. +14 −5 activesupport/lib/active_support/json/encoding.rb
  151. +43 −40 {railties/lib/rails → activesupport/lib/active_support}/log_subscriber.rb
  152. +9 −16 {railties/lib/rails → activesupport/lib/active_support}/log_subscriber/test_helper.rb
  153. +39 −40 activesupport/lib/active_support/multibyte/chars.rb
  154. +6 −0 activesupport/lib/active_support/ordered_hash.rb
  155. +11 −8 activesupport/lib/active_support/testing/isolation.rb
  156. +146 −148 activesupport/lib/active_support/values/time_zone.rb
  157. +3 −1 activesupport/test/abstract_unit.rb
  158. +8 −0 activesupport/test/core_ext/string_ext_test.rb
  159. +18 −18 activesupport/test/dependencies_test.rb
  160. +1 −1  activesupport/test/descendants_tracker_test.rb
  161. +17 −17 {railties → activesupport}/test/log_subscriber_test.rb
  162. +19 −0 activesupport/test/ordered_hash_test.rb
  163. +3 −0  railties/CHANGELOG
  164. +2 −2 railties/Rakefile
  165. +1 −1  railties/guides/source/initialization.textile
  166. +0 −1  railties/lib/rails.rb
  167. +3 −2 railties/lib/rails/application.rb
  168. +1 −1  railties/lib/rails/application/configuration.rb
  169. +6 −6 railties/lib/rails/application/finisher.rb
  170. +1 −0  railties/lib/rails/commands/runner.rb
  171. +1 −1  railties/lib/rails/commands/server.rb
  172. +0 −2  railties/lib/rails/console/app.rb
  173. +8 −8 railties/lib/rails/engine.rb
  174. +5 −5 railties/lib/rails/engine/configuration.rb
  175. +1 −2  railties/lib/rails/generators.rb
  176. +1 −1  railties/lib/rails/generators/base.rb
  177. +1 −6 railties/lib/rails/generators/erb/scaffold/scaffold_generator.rb
  178. +4 −4 railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
  179. +2 −2 railties/lib/rails/generators/erb/scaffold/templates/edit.html.erb
  180. +7 −7 railties/lib/rails/generators/erb/scaffold/templates/index.html.erb
  181. +1 −1  railties/lib/rails/generators/erb/scaffold/templates/new.html.erb
  182. +2 −2 railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
  183. +17 −1 railties/lib/rails/generators/named_base.rb
  184. +4 −3 railties/lib/rails/generators/rails/app/templates/Gemfile
  185. +1 −1  railties/lib/rails/generators/rails/app/templates/config/application.rb
  186. +1 −1  railties/lib/rails/generators/rails/model/USAGE
  187. +4 −14 railties/lib/rails/generators/rails/resource/resource_generator.rb
  188. +0 −2  railties/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb
  189. +27 −29 railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb
  190. +1 −1  railties/lib/rails/generators/resource_helpers.rb
  191. +1 −1  railties/lib/rails/generators/test_unit/model/model_generator.rb
  192. +0 −1  railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb
  193. +12 −14 railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb
  194. +3 −16 railties/lib/rails/initializable.rb
  195. +11 −13 railties/lib/rails/rack/logger.rb
  196. +2 −32 railties/lib/rails/railtie.rb
  197. +0 −156 railties/lib/rails/webrick_server.rb
  198. +0 −2  railties/test/abstract_unit.rb
  199. +6 −4 railties/test/application/initializers/frameworks_test.rb
  200. +11 −0 railties/test/application/middleware_test.rb
  201. +49 −0 railties/test/application/runner_test.rb
  202. +3 −3 railties/test/generators/actions_test.rb
  203. +0 −8 railties/test/generators/resource_generator_test.rb
  204. +0 −14 railties/test/generators/scaffold_controller_generator_test.rb
  205. +106 −0 railties/test/generators/scaffold_generator_test.rb
  206. +14 −25 railties/test/initializable_test.rb
  207. +1 −1  railties/test/railties/engine_test.rb
  208. +0 −9 railties/test/railties/railtie_test.rb
  209. +6 −2 tools/profile
  210. +1 −1  version.rb
1  Gemfile
View
@@ -1,6 +1,7 @@
source 'http://rubygems.org'
gem "arel", :git => "git://github.com/rails/arel.git"
+gem "rack-mount", :git => "git://github.com/rails/rack-mount.git"
gem "rails", :path => File.dirname(__FILE__)
gem "rake", ">= 0.8.7"
1  actionmailer/lib/action_mailer/base.rb
View
@@ -4,6 +4,7 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/proc'
+require 'action_mailer/log_subscriber'
module ActionMailer #:nodoc:
# Action Mailer allows you to send email from your application using a mailer model and views.
22 actionmailer/lib/action_mailer/log_subscriber.rb
View
@@ -0,0 +1,22 @@
+require 'active_support/core_ext/array/wrap'
+
+module ActionMailer
+ class LogSubscriber < ActiveSupport::LogSubscriber
+ def deliver(event)
+ recipients = Array.wrap(event.payload[:to]).join(', ')
+ info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
+ debug(event.payload[:mail])
+ end
+
+ def receive(event)
+ info("\nReceived mail (%.1fms)" % event.duration)
+ debug(event.payload[:mail])
+ end
+
+ def logger
+ ActionMailer::Base.logger
+ end
+ end
+end
+
+ActionMailer::LogSubscriber.attach_to :action_mailer
3  actionmailer/lib/action_mailer/railtie.rb
View
@@ -5,9 +5,6 @@ module ActionMailer
class Railtie < Rails::Railtie
config.action_mailer = ActiveSupport::OrderedOptions.new
- require "action_mailer/railties/log_subscriber"
- log_subscriber :action_mailer, ActionMailer::Railties::LogSubscriber.new
-
initializer "action_mailer.logger" do
ActiveSupport.on_load(:action_mailer) { self.logger ||= Rails.logger }
end
22 actionmailer/lib/action_mailer/railties/log_subscriber.rb
View
@@ -1,22 +0,0 @@
-require 'active_support/core_ext/array/wrap'
-
-module ActionMailer
- module Railties
- class LogSubscriber < Rails::LogSubscriber
- def deliver(event)
- recipients = Array.wrap(event.payload[:to]).join(', ')
- info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
- debug(event.payload[:mail])
- end
-
- def receive(event)
- info("\nReceived mail (%.1fms)" % event.duration)
- debug(event.payload[:mail])
- end
-
- def logger
- ActionMailer::Base.logger
- end
- end
- end
-end
8 actionmailer/test/log_subscriber_test.rb
View
@@ -1,13 +1,13 @@
require "abstract_unit"
-require "rails/log_subscriber/test_helper"
-require "action_mailer/railties/log_subscriber"
+require "active_support/log_subscriber/test_helper"
+require "action_mailer/log_subscriber"
class AMLogSubscriberTest < ActionMailer::TestCase
- include Rails::LogSubscriber::TestHelper
+ include ActiveSupport::LogSubscriber::TestHelper
def setup
super
- Rails::LogSubscriber.add(:action_mailer, ActionMailer::Railties::LogSubscriber.new)
+ ActionMailer::LogSubscriber.attach_to :action_mailer
end
class TestMailer < ActionMailer::Base
6 actionmailer/test/old_base/mail_service_test.rb
View
@@ -674,7 +674,7 @@ def test_unquote_quoted_printable_subject
EOF
mail = Mail.new(msg)
assert_equal "testing testing \326\244", mail.subject
- assert_equal "Subject: testing testing =?UTF-8?Q?_=D6=A4=?=\r\n", mail[:subject].encoded
+ assert_equal "Subject: =?UTF-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
end
def test_unquote_7bit_subject
@@ -863,7 +863,7 @@ def test_multipart_with_mime_version
def test_multipart_with_utf8_subject
mail = TestMailer.multipart_with_utf8_subject(@recipient)
- regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
+ regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=')
assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü"
assert_match(string, mail.subject)
@@ -871,7 +871,7 @@ def test_multipart_with_utf8_subject
def test_implicitly_multipart_with_utf8
mail = TestMailer.implicitly_multipart_with_utf8
- regex = Regexp.escape('Subject: Foo =?UTF-8?Q?=C3=A1=C3=AB=C3=B4=?= =?UTF-8?Q?_=C3=AE=C3=BC=?=')
+ regex = Regexp.escape('Subject: =?UTF-8?Q?Foo_=C3=A1=C3=AB=C3=B4_=C3=AE=C3=BC?=')
assert_match(/#{regex}/, mail.encoded)
string = "Foo áëô îü"
assert_match(string, mail.subject)
8 actionpack/CHANGELOG
View
@@ -1,5 +1,13 @@
*Rails 3.0.0 [Release Candidate] (unreleased)*
+* Allow :path to be given to match/get/post/put/delete instead of :path_names in the new router [Carlos Antônio da Silva]
+
+* Added resources_path_names to the new router DSL [José Valim]
+
+* Allow options to be given to the namespace method in the new router [Carlos Antônio da Silva]
+
+* Deprecate :name_prefix in the new router DSL [José Valim]
+
* Add shallow routes back to the new router [Diego Carrion, Andrew White]
resources :posts do
2  actionpack/actionpack.gemspec
View
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
s.add_dependency('i18n', '~> 0.4.1')
s.add_dependency('rack', '~> 1.1.0')
s.add_dependency('rack-test', '~> 0.5.4')
- s.add_dependency('rack-mount', '~> 0.6.4')
+ s.add_dependency('rack-mount', '~> 0.6.5')
s.add_dependency('tzinfo', '~> 0.3.16')
s.add_dependency('erubis', '~> 2.6.5')
end
2  actionpack/lib/action_controller/base.rb
View
@@ -1,3 +1,5 @@
+require "action_controller/log_subscriber"
+
module ActionController
class Base < Metal
abstract!
56 actionpack/lib/action_controller/log_subscriber.rb
View
@@ -0,0 +1,56 @@
+require 'active_support/core_ext/object/blank'
+
+module ActionController
+ class LogSubscriber < ActiveSupport::LogSubscriber
+ INTERNAL_PARAMS = %w(controller action format _method only_path)
+
+ def start_processing(event)
+ payload = event.payload
+ params = payload[:params].except(*INTERNAL_PARAMS)
+
+ info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
+ info " Parameters: #{params.inspect}" unless params.empty?
+ end
+
+ def process_action(event)
+ payload = event.payload
+ additions = ActionController::Base.log_process_action(payload)
+
+ message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration
+ message << " (#{additions.join(" | ")})" unless additions.blank?
+
+ info(message)
+ end
+
+ def send_file(event)
+ message = "Sent file %s"
+ message << " (%.1fms)"
+ info(message % [event.payload[:path], event.duration])
+ end
+
+ def redirect_to(event)
+ info "Redirected to #{event.payload[:location]}"
+ end
+
+ def send_data(event)
+ info("Sent data %s (%.1fms)" % [event.payload[:filename], event.duration])
+ end
+
+ %w(write_fragment read_fragment exist_fragment?
+ expire_fragment expire_page write_page).each do |method|
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
+ def #{method}(event)
+ key_or_path = event.payload[:key] || event.payload[:path]
+ human_name = #{method.to_s.humanize.inspect}
+ info("\#{human_name} \#{key_or_path} (%.1fms)" % event.duration)
+ end
+ METHOD
+ end
+
+ def logger
+ ActionController::Base.logger
+ end
+ end
+end
+
+ActionController::LogSubscriber.attach_to :action_controller
2  actionpack/lib/action_controller/metal.rb
View
@@ -61,7 +61,7 @@ class Metal < AbstractController::Base
# ==== Returns
# String
def self.controller_name
- @controller_name ||= controller_path.split("/").last
+ @controller_name ||= self.name.demodulize.sub(/Controller$/, '').underscore
end
# Delegates to the class' #controller_name
18 actionpack/lib/action_controller/metal/responder.rb
View
@@ -89,9 +89,7 @@ class Responder
def initialize(controller, resources, options={})
@controller = controller
- @request = controller.request
- @format = controller.formats.first
- @resource = resources.is_a?(Array) ? resources.last : resources
+ @resource = resources.last
@resources = resources
@options = options
@action = options.delete(:action)
@@ -101,6 +99,14 @@ def initialize(controller, resources, options={})
delegate :head, :render, :redirect_to, :to => :controller
delegate :get?, :post?, :put?, :delete?, :to => :request
+ def request
+ @request ||= @controller.request
+ end
+
+ def format
+ @format ||= @controller.formats.first
+ end
+
# Undefine :to_json and :to_yaml since it's defined on Object
undef_method(:to_json) if method_defined?(:to_json)
undef_method(:to_yaml) if method_defined?(:to_yaml)
@@ -147,7 +153,7 @@ def navigation_behavior(error)
elsif has_errors? && default_action
render :action => default_action
else
- redirect_to resource_location
+ redirect_to navigation_location
end
end
@@ -160,7 +166,7 @@ def api_behavior(error)
elsif has_errors?
display resource.errors, :status => :unprocessable_entity
elsif post?
- display resource, :status => :created, :location => resource_location
+ display resource, :status => :created, :location => api_location
else
head :ok
end
@@ -178,6 +184,8 @@ def resourceful?
def resource_location
options[:location] || resources
end
+ alias :navigation_location :resource_location
+ alias :api_location :resource_location
# If a given response block was given, use it, otherwise call render on
# controller.
3  actionpack/lib/action_controller/railtie.rb
View
@@ -6,7 +6,6 @@
require "active_support/deprecation/proxy_wrappers"
require "active_support/deprecation"
-require "action_controller/railties/log_subscriber"
require "action_controller/railties/url_helpers"
module ActionController
@@ -35,8 +34,6 @@ class Railtie < Rails::Railtie
end
end
- log_subscriber :action_controller, ActionController::Railties::LogSubscriber.new
-
initializer "action_controller.set_configs" do |app|
paths = app.config.paths
ac = app.config.action_controller
56 actionpack/lib/action_controller/railties/log_subscriber.rb
View
@@ -1,56 +0,0 @@
-require 'active_support/core_ext/object/blank'
-
-module ActionController
- module Railties
- class LogSubscriber < Rails::LogSubscriber
- INTERNAL_PARAMS = %w(controller action format _method only_path)
-
- def start_processing(event)
- payload = event.payload
- params = payload[:params].except(*INTERNAL_PARAMS)
-
- info " Processing by #{payload[:controller]}##{payload[:action]} as #{payload[:formats].first.to_s.upcase}"
- info " Parameters: #{params.inspect}" unless params.empty?
- end
-
- def process_action(event)
- payload = event.payload
- additions = ActionController::Base.log_process_action(payload)
-
- message = "Completed #{payload[:status]} #{Rack::Utils::HTTP_STATUS_CODES[payload[:status]]} in %.0fms" % event.duration
- message << " (#{additions.join(" | ")})" unless additions.blank?
-
- info(message)
- end
-
- def send_file(event)
- message = "Sent file %s"
- message << " (%.1fms)"
- info(message % [event.payload[:path], event.duration])
- end
-
- def redirect_to(event)
- info "Redirected to #{event.payload[:location]}"
- end
-
- def send_data(event)
- info("Sent data %s (%.1fms)" % [event.payload[:filename], event.duration])
- end
-
- %w(write_fragment read_fragment exist_fragment?
- expire_fragment expire_page write_page).each do |method|
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
- def #{method}(event)
- key_or_path = event.payload[:key] || event.payload[:path]
- human_name = #{method.to_s.humanize.inspect}
- info("\#{human_name} \#{key_or_path} (%.1fms)" % event.duration)
- end
- METHOD
- end
-
- def logger
- ActionController::Base.logger
- end
- end
- end
-end
18 actionpack/lib/action_controller/test_case.rb
View
@@ -40,7 +40,7 @@ def teardown_subscriptions
ActiveSupport::Notifications.unsubscribe("!render_template.action_view")
end
- # Asserts that the request was rendered with the appropriate template file or partials
+ # Asserts that the request was rendered with the appropriate template file or partials.
#
# ==== Examples
#
@@ -53,6 +53,12 @@ def teardown_subscriptions
# # assert that no partials were rendered
# assert_template :partial => false
#
+ # In a view test case, you can also assert that specific locals are passed
+ # to partials:
+ #
+ # # assert that the "_customer" partial was rendered with a specific object
+ # assert_template :partial => '_customer', :locals => { :customer => @customer }
+ #
def assert_template(options = {}, message = nil)
validate_request!
@@ -72,9 +78,13 @@ def assert_template(options = {}, message = nil)
end
when Hash
if expected_partial = options[:partial]
- if expected_count = options[:count]
+ if expected_locals = options[:locals]
+ actual_locals = @locals[expected_partial.to_s.sub(/^_/,'')]
+ expected_locals.each_pair do |k,v|
+ assert_equal(v, actual_locals[k])
+ end
+ elsif expected_count = options[:count]
actual_count = @partials[expected_partial]
- # actual_count = found.nil? ? 0 : found[1]
msg = build_message(message,
"expecting ? to be rendered ? time(s) but rendered ? time(s)",
expected_partial, expected_count, actual_count)
@@ -183,6 +193,8 @@ def initialize(session = {})
replace(session.stringify_keys)
@loaded = true
end
+
+ def exists?; true; end
end
# Superclass for ActionController functional tests. Functional tests allow you to
5 actionpack/lib/action_dispatch/http/request.rb
View
@@ -194,9 +194,12 @@ def body_stream #:nodoc:
@env['rack.input']
end
+ # TODO This should be broken apart into AD::Request::Session and probably
+ # be included by the session middleware.
def reset_session
- self.session_options.delete(:id)
+ session.destroy if session
self.session = {}
+ @env['action_dispatch.request.flash_hash'] = nil
end
def session=(session) #:nodoc:
11 actionpack/lib/action_dispatch/middleware/flash.rb
View
@@ -4,7 +4,7 @@ class Request
# read a notice you put there or <tt>flash["notice"] = "hello"</tt>
# to put a new one.
def flash
- session['flash'] ||= Flash::FlashHash.new
+ @env['action_dispatch.request.flash_hash'] ||= (session["flash"] || Flash::FlashHash.new)
end
end
@@ -176,7 +176,14 @@ def call(env)
@app.call(env)
ensure
- if (session = env['rack.session']) && session.key?('flash') && session['flash'].empty?
+ session = env['rack.session'] || {}
+ flash_hash = env['action_dispatch.request.flash_hash']
+
+ if flash_hash && (!flash_hash.empty? || session.key?('flash'))
+ session["flash"] = flash_hash
+ end
+
+ if session.key?('flash') && session['flash'].empty?
session.delete('flash')
end
end
149 actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
View
@@ -12,6 +12,35 @@ class AbstractStore
ENV_SESSION_KEY = 'rack.session'.freeze
ENV_SESSION_OPTIONS_KEY = 'rack.session.options'.freeze
+ # thin wrapper around Hash that allows us to lazily
+ # load session id into session_options
+ class OptionsHash < Hash
+ def initialize(by, env, default_options)
+ @by = by
+ @env = env
+ @session_id_loaded = false
+ merge!(default_options)
+ end
+
+ def [](key)
+ if key == :id
+ load_session_id! unless super(:id) || has_session_id?
+ end
+ super(key)
+ end
+
+ private
+
+ def has_session_id?
+ @session_id_loaded
+ end
+
+ def load_session_id!
+ self[:id] = @by.send(:extract_session_id, @env)
+ @session_id_loaded = true
+ end
+ end
+
class SessionHash < Hash
def initialize(by, env)
super()
@@ -21,66 +50,75 @@ def initialize(by, env)
end
def [](key)
- load! unless @loaded
+ load_for_read!
+ super(key.to_s)
+ end
+
+ def has_key?(key)
+ load_for_read!
super(key.to_s)
end
def []=(key, value)
- load! unless @loaded
+ load_for_write!
super(key.to_s, value)
end
def to_hash
+ load_for_read!
h = {}.replace(self)
h.delete_if { |k,v| v.nil? }
h
end
def update(hash)
- load! unless @loaded
+ load_for_write!
super(hash.stringify_keys)
end
def delete(key)
- load! unless @loaded
+ load_for_write!
super(key.to_s)
end
def inspect
- load! unless @loaded
+ load_for_read!
super
end
+ def exists?
+ return @exists if instance_variable_defined?(:@exists)
+ @exists = @by.send(:exists?, @env)
+ end
+
def loaded?
@loaded
end
+ def destroy
+ clear
+ @by.send(:destroy, @env) if @by
+ @env[ENV_SESSION_OPTIONS_KEY][:id] = nil if @env && @env[ENV_SESSION_OPTIONS_KEY]
+ @loaded = false
+ end
+
private
- def load!
- stale_session_check! do
- id, session = @by.send(:load_session, @env)
- (@env[ENV_SESSION_OPTIONS_KEY] ||= {})[:id] = id
- replace(session.stringify_keys)
- @loaded = true
- end
+
+ def load_for_read!
+ load! if !loaded? && exists?
end
- def stale_session_check!
- yield
- rescue ArgumentError => argument_error
- if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
- begin
- # Note that the regexp does not allow $1 to end with a ':'
- $1.constantize
- rescue LoadError, NameError => const_error
- raise ActionDispatch::Session::SessionRestoreError, "Session contains objects whose class definition isn't available.\nRemember to require the classes for all objects kept in the session.\n(Original exception: #{const_error.message} [#{const_error.class}])\n"
- end
-
- retry
- else
- raise
- end
+ def load_for_write!
+ load! unless loaded?
+ end
+
+ def load!
+ id, session = @by.send(:load_session, @env)
+ @env[ENV_SESSION_OPTIONS_KEY][:id] = id
+ replace(session.stringify_keys)
+ @loaded = true
end
+
end
DEFAULT_OPTIONS = {
@@ -108,8 +146,8 @@ def call(env)
session_data = env[ENV_SESSION_KEY]
options = env[ENV_SESSION_OPTIONS_KEY]
- if !session_data.is_a?(AbstractStore::SessionHash) || session_data.send(:loaded?) || options[:expire_after]
- session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.send(:loaded?)
+ if !session_data.is_a?(AbstractStore::SessionHash) || session_data.loaded? || options[:expire_after]
+ session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.loaded?
sid = options[:id] || generate_sid
session_data = session_data.to_hash
@@ -133,7 +171,7 @@ def call(env)
def prepare!(env)
env[ENV_SESSION_KEY] = SessionHash.new(self, env)
- env[ENV_SESSION_OPTIONS_KEY] = @default_options.dup
+ env[ENV_SESSION_OPTIONS_KEY] = OptionsHash.new(self, env, @default_options)
end
def generate_sid
@@ -141,15 +179,30 @@ def generate_sid
end
def set_cookie(request, options)
- request.cookie_jar[@key] = options
+ if request.cookie_jar[@key] != options[:value] || !options[:expires].nil?
+ request.cookie_jar[@key] = options
+ end
end
def load_session(env)
- request = Rack::Request.new(env)
- sid = request.cookies[@key]
- sid ||= request.params[@key] unless @cookie_only
- sid, session = get_session(env, sid)
- [sid, session]
+ stale_session_check! do
+ sid = current_session_id(env)
+ sid, session = get_session(env, sid)
+ [sid, session]
+ end
+ end
+
+ def extract_session_id(env)
+ stale_session_check! do
+ request = ActionDispatch::Request.new(env)
+ sid = request.cookies[@key]
+ sid ||= request.params[@key] unless @cookie_only
+ sid
+ end
+ end
+
+ def current_session_id(env)
+ env[ENV_SESSION_OPTIONS_KEY][:id]
end
def ensure_session_key!
@@ -161,6 +214,26 @@ def ensure_session_key!
end
end
+ def stale_session_check!
+ yield
+ rescue ArgumentError => argument_error
+ if argument_error.message =~ %r{undefined class/module ([\w:]*\w)}
+ begin
+ # Note that the regexp does not allow $1 to end with a ':'
+ $1.constantize
+ rescue LoadError, NameError => const_error
+ raise ActionDispatch::Session::SessionRestoreError, "Session contains objects whose class definition isn't available.\nRemember to require the classes for all objects kept in the session.\n(Original exception: #{const_error.message} [#{const_error.class}])\n"
+ end
+ retry
+ else
+ raise
+ end
+ end
+
+ def exists?(env)
+ current_session_id(env).present?
+ end
+
def get_session(env, sid)
raise '#get_session needs to be implemented.'
end
@@ -169,6 +242,10 @@ def set_session(env, sid, session_data)
raise '#set_session needs to be implemented and should return ' <<
'the value to be stored in the cookie (usually the sid)'
end
+
+ def destroy(env)
+ raise '#destroy needs to be implemented.'
+ end
end
end
end
43 actionpack/lib/action_dispatch/middleware/session/cookie_store.rb
View
@@ -39,16 +39,6 @@ module Session
#
# Note that changing digest or secret invalidates all existing sessions!
class CookieStore < AbstractStore
- class OptionsHash < Hash
- def initialize(by, env, default_options)
- @session_data = env[AbstractStore::ENV_SESSION_KEY]
- merge!(default_options)
- end
-
- def [](key)
- key == :id ? @session_data[:session_id] : super(key)
- end
- end
def initialize(app, options = {})
super(app, options.merge!(:cookie_only => true))
@@ -57,19 +47,32 @@ def initialize(app, options = {})
private
- def prepare!(env)
- env[ENV_SESSION_KEY] = SessionHash.new(self, env)
- env[ENV_SESSION_OPTIONS_KEY] = OptionsHash.new(self, env, @default_options)
- end
-
def load_session(env)
- request = ActionDispatch::Request.new(env)
- data = request.cookie_jar.signed[@key]
+ data = unpacked_cookie_data(env)
data = persistent_session_id!(data)
- data.stringify_keys!
[data["session_id"], data]
end
+ def extract_session_id(env)
+ if data = unpacked_cookie_data(env)
+ data["session_id"]
+ else
+ nil
+ end
+ end
+
+ def unpacked_cookie_data(env)
+ env["action_dispatch.request.unsigned_session_cookie"] ||= begin
+ stale_session_check! do
+ request = ActionDispatch::Request.new(env)
+ if data = request.cookie_jar.signed[@key]
+ data.stringify_keys!
+ end
+ data || {}
+ end
+ end
+ end
+
def set_cookie(request, options)
request.cookie_jar.signed[@key] = options
end
@@ -78,6 +81,10 @@ def set_session(env, sid, session_data)
persistent_session_id!(session_data, sid)
end
+ def destroy(env)
+ # session data is stored on client; nothing to do here
+ end
+
def persistent_session_id!(data, sid=nil)
data ||= {}
data["session_id"] ||= sid || generate_sid
9 actionpack/lib/action_dispatch/middleware/session/mem_cache_store.rb
View
@@ -42,6 +42,15 @@ def set_session(env, sid, session_data)
rescue MemCache::MemCacheError, Errno::ECONNREFUSED
false
end
+
+ def destroy(env)
+ if sid = current_session_id(env)
+ @pool.delete(sid)
+ end
+ rescue MemCache::MemCacheError, Errno::ECONNREFUSED
+ false
+ end
+
end
end
end
83 actionpack/lib/action_dispatch/routing/mapper.rb
View
@@ -55,7 +55,7 @@ def extract_path_and_options(args)
path = args.first
end
- if @scope[:module] && options[:to]
+ if @scope[:module] && options[:to] && !options[:to].is_a?(Proc)
if options[:to].to_s.include?("#")
options[:to] = "#{@scope[:module]}/#{options[:to]}"
elsif @scope[:controller].nil?
@@ -194,7 +194,7 @@ def default_controller
# for root cases, where the latter is the correct one.
def self.normalize_path(path)
path = Rack::Mount::Utils.normalize_path(path)
- path.sub!(%r{/(\(+)/?:}, '\1/:') unless path =~ %r{^/\(+:.*\)$}
+ path.gsub!(%r{/(\(+)/?}, '\1/') unless path =~ %r{^/\(+[^/]+\)$}
path
end
@@ -299,6 +299,11 @@ def scope(*args)
options = args.extract_options!
options = options.dup
+ if name_prefix = options.delete(:name_prefix)
+ options[:as] ||= name_prefix
+ ActiveSupport::Deprecation.warn ":name_prefix was deprecated in the new router syntax. Use :as instead.", caller
+ end
+
case args.first
when String
options[:path] = args.first
@@ -341,9 +346,11 @@ def controller(controller)
scope(controller.to_sym) { yield }
end
- def namespace(path)
+ def namespace(path, options = {})
path = path.to_s
- scope(:path => path, :name_prefix => path, :module => path, :shallow_path => path, :shallow_prefix => path) { yield }
+ options = { :path => path, :as => path, :module => path,
+ :shallow_path => path, :shallow_prefix => path }.merge!(options)
+ scope(options) { yield }
end
def constraints(constraints = {})
@@ -359,10 +366,10 @@ def match(*args)
options = (@scope[:options] || {}).merge(options)
- if @scope[:name_prefix] && !options[:as].blank?
- options[:as] = "#{@scope[:name_prefix]}_#{options[:as]}"
- elsif @scope[:name_prefix] && options[:as] == ""
- options[:as] = @scope[:name_prefix].to_s
+ if @scope[:as] && !options[:as].blank?
+ options[:as] = "#{@scope[:as]}_#{options[:as]}"
+ elsif @scope[:as] && options[:as] == ""
+ options[:as] = @scope[:as].to_s
end
args.push(options)
@@ -382,7 +389,7 @@ def merge_shallow_path_scope(parent, child)
Mapper.normalize_path("#{parent}/#{child}")
end
- def merge_name_prefix_scope(parent, child)
+ def merge_as_scope(parent, child)
parent ? "#{parent}_#{child}" : child
end
@@ -411,7 +418,9 @@ def merge_defaults_scope(parent, child)
end
def merge_blocks_scope(parent, child)
- (parent || []) + [child]
+ merged = parent ? parent.dup : []
+ merged << child if child
+ merged
end
def merge_options_scope(parent, child)
@@ -434,7 +443,8 @@ def self.default_actions
def initialize(entities, options = {})
@name = entities.to_s
@path = options.delete(:path) || @name
- @controller = options.delete(:controller) || @name.to_s.pluralize
+ @controller = (options.delete(:controller) || @name).to_s
+ @as = options.delete(:as)
@options = options
end
@@ -453,7 +463,7 @@ def actions
end
def name
- options[:as] || @name
+ @as || @name
end
def plural
@@ -505,7 +515,7 @@ def nested_path
def nested_options
{}.tap do |opts|
- opts[:name_prefix] = member_name
+ opts[:as] = member_name
opts["#{singular}_id".to_sym] = id_constraint if id_constraint?
opts[:options] = { :shallow => shallow? } unless options[:shallow].nil?
end
@@ -537,14 +547,18 @@ def self.default_actions
[:show, :create, :update, :destroy, :new, :edit]
end
- def initialize(entity, options = {})
- super
+ def initialize(entities, options)
+ @name = entities.to_s
+ @path = options.delete(:path) || @name
+ @controller = (options.delete(:controller) || @name.to_s.pluralize).to_s
+ @as = options.delete(:as)
+ @options = options
end
def member_name
name
end
- alias_method :collection_name, :member_name
+ alias :collection_name :member_name
def nested_path
path
@@ -552,7 +566,7 @@ def nested_path
def nested_options
{}.tap do |opts|
- opts[:name_prefix] = member_name
+ opts[:as] = member_name
opts[:options] = { :shallow => shallow? } unless @options[:shallow].nil?
end
end
@@ -571,6 +585,10 @@ def initialize(*args) #:nodoc:
@scope[:path_names] = @set.resources_path_names
end
+ def resources_path_names(options)
+ @scope[:path_names].merge!(options)
+ end
+
def resource(*resources, &block)
options = resources.extract_options!
options = (@scope[:options] || {}).merge(options)
@@ -673,7 +691,7 @@ def nested
if @scope[:shallow_path].blank?
scope(*parent_resource.nested_scope) { yield }
else
- scope(@scope[:shallow_path], :name_prefix => @scope[:shallow_prefix]) do
+ scope(@scope[:shallow_path], :as => @scope[:shallow_prefix]) do
scope(*parent_resource.nested_scope) { yield }
end
end
@@ -684,7 +702,7 @@ def nested
end
end
- def namespace(path)
+ def namespace(path, options = {})
if resource_scope?
nested { super }
else
@@ -726,10 +744,10 @@ def match(*args)
return member { match(*args) }
end
- path_names = options.delete(:path_names)
+ path = options.delete(:path)
if args.first.is_a?(Symbol)
- path = path_for_action(args.first, path_names)
+ path = path_for_action(args.first, path)
options = options_for_action(args.first, options)
with_exclusive_scope do
@@ -758,7 +776,7 @@ def match(*args)
def root(options={})
if @scope[:scope_level] == :resources
with_scope_level(:nested) do
- scope(parent_resource.path, :name_prefix => parent_resource.collection_name) do
+ scope(parent_resource.path, :as => parent_resource.collection_name) do
super(options)
end
end
@@ -806,14 +824,14 @@ def resource_method_scope?
def with_exclusive_scope
begin
- old_name_prefix, old_path = @scope[:name_prefix], @scope[:path]
- @scope[:name_prefix], @scope[:path] = nil, nil
+ old_name_prefix, old_path = @scope[:as], @scope[:path]
+ @scope[:as], @scope[:path] = nil, nil
with_scope_level(:exclusive) do
yield
end
ensure
- @scope[:name_prefix], @scope[:path] = old_name_prefix, old_path
+ @scope[:as], @scope[:path] = old_name_prefix, old_path
end
end
@@ -850,7 +868,7 @@ def member_scope
end
end
- def path_for_action(action, path_names)
+ def path_for_action(action, path)
case action
when :index, :create
"#{@scope[:path]}(.:format)"
@@ -871,12 +889,12 @@ def path_for_action(action, path_names)
else
case @scope[:scope_level]
when :collection, :new
- "#{@scope[:path]}/#{action_path(action)}(.:format)"
+ "#{@scope[:path]}/#{action_path(action, path)}(.:format)"
else
if parent_resource.shallow?
- "#{@scope[:shallow_path]}/#{parent_resource.path}/:id/#{action_path(action)}(.:format)"
+ "#{@scope[:shallow_path]}/#{parent_resource.path}/:id/#{action_path(action, path)}(.:format)"
else
- "#{@scope[:path]}/#{action_path(action)}(.:format)"
+ "#{@scope[:path]}/#{action_path(action, path)}(.:format)"
end
end
end
@@ -895,9 +913,8 @@ def path_for_custom_action
end
end
- def action_path(name, path_names = nil)
- path_names ||= @scope[:path_names]
- path_names[name.to_sym] || name.to_s
+ def action_path(name, path = nil)
+ path || @scope[:path_names][name.to_sym] || name.to_s
end
def options_for_action(action, options)
@@ -908,7 +925,7 @@ def options_for_action(action, options)
end
def name_for_action(action)
- name_prefix = @scope[:name_prefix].blank? ? "" : "#{@scope[:name_prefix]}_"
+ name_prefix = @scope[:as].blank? ? "" : "#{@scope[:as]}_"
shallow_prefix = @scope[:shallow_prefix].blank? ? "" : "#{@scope[:shallow_prefix]}_"
case action
31 actionpack/lib/action_dispatch/routing/route_set.rb
View
@@ -185,7 +185,7 @@ def #{selector}(*args)
end
end
- attr_accessor :routes, :named_routes
+ attr_accessor :set, :routes, :named_routes
attr_accessor :disable_clear_and_finalize, :resources_path_names
attr_accessor :default_url_options, :request_class
@@ -296,6 +296,7 @@ def initialize(options, recall, set, extras = false)
@extras = extras
normalize_options!
+ normalize_recall!
normalize_controller_action_id!
use_relative_controller!
controller.sub!(%r{^/}, '') if controller
@@ -336,6 +337,15 @@ def normalize_options!
end
end
+ def normalize_recall!
+ # If the target route is not a standard route then remove controller and action
+ # from the options otherwise they will appear in the url parameters
+ if block_or_proc_route_target?
+ recall.delete(:controller) unless segment_keys.include?(:controller)
+ recall.delete(:action) unless segment_keys.include?(:action)
+ end
+ end
+
# This pulls :controller, :action, and :id out of the recall.
# The recall key is only used if there is no key in the options
# or if the key in the options is identical. If any of
@@ -371,7 +381,7 @@ def handle_nil_action!
def generate
error = ActionController::RoutingError.new("No route matches #{options.inspect}")
- path, params = @set.generate(:path_info, named_route, options, recall, opts)
+ path, params = @set.set.generate(:path_info, named_route, options, recall, opts)
raise error unless path
@@ -402,6 +412,19 @@ def different_controller?
return false unless current_controller
controller.to_param != current_controller.to_param
end
+
+ private
+ def named_route_exists?
+ named_route && set.named_routes[named_route]
+ end
+
+ def block_or_proc_route_target?
+ named_route_exists? && !set.named_routes[named_route].app.is_a?(Dispatcher)
+ end
+
+ def segment_keys
+ named_route_exists? ? set.named_routes[named_route].segment_keys : []
+ end
end
# Generate the path indicated by the arguments, and return an array of
@@ -415,7 +438,7 @@ def generate_extras(options, recall={})
end
def generate(options, recall = {}, extras = false)
- Generator.new(options, recall, @set, extras).generate
+ Generator.new(options, recall, self, extras).generate
end
RESERVED_OPTIONS = [:anchor, :params, :only_path, :host, :protocol, :port, :trailing_slash]
@@ -447,7 +470,7 @@ def url_for(options)
# ROUTES TODO: This can be called directly, so script_name should probably be set in the router
rewritten_url << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
- rewritten_url << "##{Rack::Utils.escape(options[:anchor].to_param.to_s)}" if options[:anchor]
+ rewritten_url << "##{Rack::Mount::Utils.escape_uri(options[:anchor].to_param.to_s)}" if options[:anchor]
rewritten_url
end
1  actionpack/lib/action_dispatch/testing/assertions/routing.rb
View
@@ -53,7 +53,6 @@ def assert_recognizes(expected_options, path, extras={}, message=nil)
extras.each_key { |key| expected_options.delete key } unless extras.nil?
expected_options.stringify_keys!
- routing_diff = expected_options.diff(request.path_parameters)
msg = build_message(message, "The recognized options <?> did not match <?>, difference: <?>",
request.path_parameters, expected_options, expected_options.diff(request.path_parameters))
assert_block(msg) { request.path_parameters == expected_options }
42 actionpack/lib/action_dispatch/testing/assertions/selector.rb
View
@@ -7,9 +7,7 @@
module ActionDispatch
module Assertions
- unless const_defined?(:NO_STRIP)
- NO_STRIP = %w{pre script style textarea}
- end
+ NO_STRIP = %w{pre script style textarea}
# Adds the +assert_select+ method for use in Rails functional
# test cases, which can be used to make assertions on the response HTML of a controller
@@ -581,27 +579,25 @@ def assert_select_email(&block)
end
protected
- unless const_defined?(:RJS_STATEMENTS)
- RJS_PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
- RJS_ANY_ID = "\"([^\"])*\""
- RJS_STATEMENTS = {
- :chained_replace => "\\$\\(#{RJS_ANY_ID}\\)\\.replace\\(#{RJS_PATTERN_HTML}\\)",
- :chained_replace_html => "\\$\\(#{RJS_ANY_ID}\\)\\.update\\(#{RJS_PATTERN_HTML}\\)",
- :replace_html => "Element\\.update\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
- :replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
- :redirect => "window.location.href = #{RJS_ANY_ID}"
- }
- [:remove, :show, :hide, :toggle].each do |action|
- RJS_STATEMENTS[action] = "Element\\.#{action}\\(#{RJS_ANY_ID}\\)"
- end
- RJS_INSERTIONS = ["top", "bottom", "before", "after"]
- RJS_INSERTIONS.each do |insertion|
- RJS_STATEMENTS["insert_#{insertion}".to_sym] = "Element.insert\\(#{RJS_ANY_ID}, \\{ #{insertion}: #{RJS_PATTERN_HTML} \\}\\)"
- end
- RJS_STATEMENTS[:insert_html] = "Element.insert\\(#{RJS_ANY_ID}, \\{ (#{RJS_INSERTIONS.join('|')}): #{RJS_PATTERN_HTML} \\}\\)"
- RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
- RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
+ RJS_PATTERN_HTML = "\"((\\\\\"|[^\"])*)\""
+ RJS_ANY_ID = "\"([^\"])*\""
+ RJS_STATEMENTS = {
+ :chained_replace => "\\$\\(#{RJS_ANY_ID}\\)\\.replace\\(#{RJS_PATTERN_HTML}\\)",
+ :chained_replace_html => "\\$\\(#{RJS_ANY_ID}\\)\\.update\\(#{RJS_PATTERN_HTML}\\)",
+ :replace_html => "Element\\.update\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
+ :replace => "Element\\.replace\\(#{RJS_ANY_ID}, #{RJS_PATTERN_HTML}\\)",
+ :redirect => "window.location.href = #{RJS_ANY_ID}"
+ }
+ [:remove, :show, :hide, :toggle].each do |action|
+ RJS_STATEMENTS[action] = "Element\\.#{action}\\(#{RJS_ANY_ID}\\)"
+ end
+ RJS_INSERTIONS = ["top", "bottom", "before", "after"]
+ RJS_INSERTIONS.each do |insertion|
+ RJS_STATEMENTS["insert_#{insertion}".to_sym] = "Element.insert\\(#{RJS_ANY_ID}, \\{ #{insertion}: #{RJS_PATTERN_HTML} \\}\\)"
end
+ RJS_STATEMENTS[:insert_html] = "Element.insert\\(#{RJS_ANY_ID}, \\{ (#{RJS_INSERTIONS.join('|')}): #{RJS_PATTERN_HTML} \\}\\)"
+ RJS_STATEMENTS[:any] = Regexp.new("(#{RJS_STATEMENTS.values.join('|')})")
+ RJS_PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
# +assert_select+ and +css_select+ call this to obtain the content in the HTML
# page, or from all the RJS statements, depending on the type of response.
7 actionpack/lib/action_view/base.rb
View
@@ -3,6 +3,7 @@
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/array/wrap'
require 'active_support/ordered_options'
+require 'action_view/log_subscriber'
module ActionView #:nodoc:
class NonConcattingString < ActiveSupport::SafeBuffer
@@ -204,8 +205,12 @@ def self.process_view_paths(value)
value.dup : ActionView::PathSet.new(Array.wrap(value))
end
+ def assign(new_assigns) # :nodoc:
+ self.assigns = new_assigns.each { |key, value| instance_variable_set("@#{key}", value) }
+ end
+
def initialize(lookup_context = nil, assigns_for_first_render = {}, controller = nil, formats = nil) #:nodoc:
- self.assigns = assigns_for_first_render.each { |key, value| instance_variable_set("@#{key}", value) }
+ assign(assigns_for_first_render)
self.helpers = self.class.helpers || Module.new
if @_controller = controller
18 actionpack/lib/action_view/helpers/active_model_helper.rb
View
@@ -36,12 +36,16 @@ def object
end
end
- %w(tag content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth|
+ %w(content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth|
module_eval "def #{meth}(*) error_wrapping(super) end", __FILE__, __LINE__
end
+ def tag(type, options, *)
+ tag_generate_errors?(options) ? error_wrapping(super) : super
+ end
+
def error_wrapping(html_tag)
- if object.respond_to?(:errors) && object.errors.respond_to?(:full_messages) && object.errors[@method_name].any?
+ if object_has_errors?
Base.field_error_proc.call(html_tag, self)
else
html_tag
@@ -51,6 +55,16 @@ def error_wrapping(html_tag)
def error_message
object.errors[@method_name]
end
+
+ private
+
+ def object_has_errors?
+ object.respond_to?(:errors) && object.errors.respond_to?(:full_messages) && error_message.any?
+ end
+
+ def tag_generate_errors?(options)
+ options['type'] != 'hidden'
+ end
end
class FormBuilder
47 actionpack/lib/action_view/helpers/asset_tag_helper.rb
View
@@ -194,7 +194,19 @@ module Helpers #:nodoc:
# RewriteEngine On
# RewriteRule ^/release-\d+/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L]
module AssetTagHelper
- JAVASCRIPT_DEFAULT_SOURCES = ['prototype', 'effects', 'dragdrop', 'controls', 'rails'].freeze unless const_defined?(:JAVASCRIPT_DEFAULT_SOURCES)
+ mattr_reader :javascript_expansions
+ @@javascript_expansions = { }
+
+ mattr_reader :stylesheet_expansions
+ @@stylesheet_expansions = {}
+
+ # You can enable or disable the asset tag timestamps cache.
+ # With the cache enabled, the asset tag helper methods will make fewer
+ # expensive file system calls. However this prevents you from modifying
+ # any asset files while the server is running.
+ #
+ # ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
+ mattr_accessor :cache_asset_timestamps
# Returns a link tag that browsers and news readers can use to auto-detect
# an RSS or ATOM feed. The +type+ can either be <tt>:rss</tt> (default) or
@@ -351,8 +363,6 @@ def javascript_include_tag(*sources)
end
end
- @@javascript_expansions = { :defaults => JAVASCRIPT_DEFAULT_SOURCES.dup }
-
# Register one or more javascript files to be included when <tt>symbol</tt>
# is passed to <tt>javascript_include_tag</tt>. This method is typically intended
# to be called from plugin initialization to register javascript files
@@ -368,8 +378,6 @@ def self.register_javascript_expansion(expansions)
@@javascript_expansions.merge!(expansions)
end
- @@stylesheet_expansions = {}
-
# Register one or more stylesheet files to be included when <tt>symbol</tt>
# is passed to <tt>stylesheet_link_tag</tt>. This method is typically intended
# to be called from plugin initialization to register stylesheet files
@@ -385,18 +393,6 @@ def self.register_stylesheet_expansion(expansions)
@@stylesheet_expansions.merge!(expansions)
end
- # Register one or more additional JavaScript files to be included when
- # <tt>javascript_include_tag :defaults</tt> is called. This method is
- # typically intended to be called from plugin initialization to register additional
- # .js files that the plugin installed in <tt>public/javascripts</tt>.
- def self.register_javascript_include_default(*sources)
- @@javascript_expansions[:defaults].concat(sources)
- end
-
- def self.reset_javascript_include_default #:nodoc:
- @@javascript_expansions[:defaults] = JAVASCRIPT_DEFAULT_SOURCES.dup
- end
-
# Computes the path to a stylesheet asset in the public stylesheets directory.
# If the +source+ filename has no extension, <tt>.css</tt> will be appended (except for explicit URIs).
# Full paths from the document root will be passed through.
@@ -707,23 +703,8 @@ def audio_tag(source, options = {})
tag("audio", options)
end
- def self.cache_asset_timestamps
- @@cache_asset_timestamps
- end
-
- # You can enable or disable the asset tag timestamps cache.
- # With the cache enabled, the asset tag helper methods will make fewer
- # expensive file system calls. However this prevents you from modifying
- # any asset files while the server is running.
- #
- # ActionView::Helpers::AssetTagHelper.cache_asset_timestamps = false
- def self.cache_asset_timestamps=(value)
- @@cache_asset_timestamps = value
- end
-
- @@cache_asset_timestamps = true
-
private
+
def rewrite_extension?(source, dir, ext)
source_ext = File.extname(source)[1..-1]
ext && (source_ext.blank? || (ext != source_ext && File.exist?(File.join(config.assets_dir, dir, "#{source}.#{ext}"))))
4 actionpack/lib/action_view/helpers/date_helper.rb
View
@@ -582,10 +582,10 @@ class DateTimeSelector #:nodoc:
extend ActiveSupport::Memoizable
include ActionView::Helpers::TagHelper
- DEFAULT_PREFIX = 'date'.freeze unless const_defined?('DEFAULT_PREFIX')
+ DEFAULT_PREFIX = 'date'.freeze
POSITION = {
:year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6
- }.freeze unless const_defined?('POSITION')
+ }.freeze
def initialize(datetime, options = {}, html_options = {})
@options = options.dup
29 actionpack/lib/action_view/helpers/form_helper.rb
View
@@ -124,7 +124,6 @@ module FormHelper
# model:
#
# <%= form_for :person do |f| %>
- # <%= f.error_messages %>
# First name: <%= f.text_field :first_name %><br />
# Last name : <%= f.text_field :last_name %><br />
# Biography : <%= f.text_area :biography %><br />
@@ -221,15 +220,15 @@ module FormHelper
# <% end %>
#
# === Unobtrusive JavaScript
- #
- # Specifying:
- #
+ #
+ # Specifying:
+ #
# :remote => true
#
# in the options hash creates a form that will allow the unobtrusive JavaScript drivers to modify its
- # behaviour. The expected default behaviour is an XMLHttpRequest in the background instead of the regular
+ # behaviour. The expected default behaviour is an XMLHttpRequest in the background instead of the regular
# POST arrangement, but ultimately the behaviour is the choice of the JavaScript driver implementor.
- # Even though it's using JavaScript to serialize the form elements, the form submission will work just like
+ # Even though it's using JavaScript to serialize the form elements, the form submission will work just like
# a regular submission as viewed by the receiving side (all elements available in <tt>params</tt>).
#
# Example:
@@ -839,9 +838,9 @@ module InstanceTagMethods #:nodoc:
attr_reader :method_name, :object_name
- DEFAULT_FIELD_OPTIONS = { "size" => 30 }.freeze unless const_defined?(:DEFAULT_FIELD_OPTIONS)
- DEFAULT_RADIO_OPTIONS = { }.freeze unless const_defined?(:DEFAULT_RADIO_OPTIONS)
- DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }.freeze unless const_defined?(:DEFAULT_TEXT_AREA_OPTIONS)
+ DEFAULT_FIELD_OPTIONS = { "size" => 30 }.freeze
+ DEFAULT_RADIO_OPTIONS = { }.freeze
+ DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }.freeze
def initialize(object_name, method_name, template_object, object = nil)
@object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
@@ -898,7 +897,7 @@ def to_input_field_tag(field_type, options = {})
options.delete("size")
end
options["type"] ||= field_type
- options["value"] ||= value_before_type_cast(object) unless field_type == "file"
+ options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
options["value"] &&= html_escape(options["value"])
add_default_name_and_id(options)
tag("input", options)
@@ -1031,7 +1030,7 @@ def radio_button_checked?(value, checked_value)
private
def add_default_name_and_id_for_value(tag_value, options)
unless tag_value.nil?
- pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase
+ pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/[^-\w]/, "").downcase
specified_id = options["id"]
add_default_name_and_id(options)
options["id"] += "_#{pretty_tag_value}" if specified_id.blank? && options["id"].present?
@@ -1043,14 +1042,14 @@ def add_default_name_and_id_for_value(tag_value, options)
def add_default_name_and_id(options)
if options.has_key?("index")
options["name"] ||= tag_name_with_index(options["index"])
- options["id"] = options.fetch("id", tag_id_with_index(options["index"]))
+ options["id"] = options.fetch("id"){ tag_id_with_index(options["index"]) }
options.delete("index")
elsif defined?(@auto_index)
options["name"] ||= tag_name_with_index(@auto_index)
- options["id"] = options.fetch("id", tag_id_with_index(@auto_index))
+ options["id"] = options.fetch("id"){ tag_id_with_index(@auto_index) }
else
options["name"] ||= tag_name + (options.has_key?('multiple') ? '[]' : '')
- options["id"] = options.fetch("id", tag_id)
+ options["id"] = options.fetch("id"){ tag_id }
end
end
@@ -1181,7 +1180,7 @@ def hidden_field(method, options = {})
# <%= form_for @post do |f| %>
# <%= f.submit %>
# <% end %>
- #
+ #
# In the example above, if @post is a new record, it will use "Create Post" as
# submit button label, otherwise, it uses "Update Post".
#
14 actionpack/lib/action_view/helpers/prototype_helper.rb
View
@@ -95,14 +95,12 @@ module Helpers
# See JavaScriptGenerator for information on updating multiple elements
# on the page in an Ajax response.
module PrototypeHelper
- unless const_defined? :CALLBACKS
- CALLBACKS = Set.new([ :create, :uninitialized, :loading, :loaded,
- :interactive, :complete, :failure, :success ] +
- (100..599).to_a)
- AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
- :asynchronous, :method, :insertion, :position,
- :form, :with, :update, :script, :type ]).merge(CALLBACKS)
- end
+ CALLBACKS = Set.new([ :create, :uninitialized, :loading, :loaded,
+ :interactive, :complete, :failure, :success ] +
+ (100..599).to_a)
+ AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
+ :asynchronous, :method, :insertion, :position,
+ :form, :with, :update, :script, :type ]).merge(CALLBACKS)
# Returns the JavaScript needed for a remote function.
# Takes the same arguments as link_to_remote.
6 actionpack/lib/action_view/helpers/scriptaculous_helper.rb
View
@@ -4,7 +4,7 @@
module ActionView
# = Action View Scriptaculous Helpers
module Helpers
- # Provides a set of helpers for calling Scriptaculous[http://script.aculo.us/]
+ # Provides a set of helpers for calling Scriptaculous[http://script.aculo.us/]
# JavaScript functions, including those which create Ajax controls and visual
# effects.
#
@@ -18,9 +18,7 @@ module Helpers
# See the documentation at http://script.aculo.us for more information on
# using these helpers in your application.
module ScriptaculousHelper
- unless const_defined? :TOGGLE_EFFECTS
- TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind]
- end
+ TOGGLE_EFFECTS = [:toggle_appear, :toggle_slide, :toggle_blind]
# Returns a JavaScript snippet to be used on the Ajax callbacks for
# starting visual effects.
27 actionpack/lib/action_view/log_subscriber.rb
View
@@ -0,0 +1,27 @@
+module ActionView
+ # = Action View Log Subscriber
+ #
+ # Provides functionality so that Rails can output logs from Action View.
+ class LogSubscriber < ActiveSupport::LogSubscriber
+ def render_template(event)
+ message = "Rendered #{from_rails_root(event.payload[:identifier])}"
+ message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
+ message << (" (%.1fms)" % event.duration)
+ info(message)
+ end
+ alias :render_partial :render_template
+ alias :render_collection :render_template
+
+ def logger
+ ActionController::Base.logger
+ end
+
+ protected
+
+ def from_rails_root(string)
+ string.sub("#{Rails.root}/", "").sub(/^app\/views\//, "")
+ end
+ end
+end
+
+ActionView::LogSubscriber.attach_to :action_view
17 actionpack/lib/action_view/railtie.rb
View
@@ -5,9 +5,8 @@ module ActionView
# = Action View Railtie
class Railtie < Rails::Railtie
config.action_view = ActiveSupport::OrderedOptions.new
-
- require "action_view/railties/log_subscriber"
- log_subscriber :action_view, ActionView::Railties::LogSubscriber.new
+ config.action_view.stylesheet_expansions = {}
+ config.action_view.javascript_expansions = { :defaults => ['prototype', 'effects', 'dragdrop', 'controls', 'rails'] }
initializer "action_view.cache_asset_timestamps" do |app|
unless app.config.cache_classes
@@ -17,6 +16,18 @@ class Railtie < Rails::Railtie
end
end
+ initializer "action_view.javascript_expansions" do |app|
+ ActiveSupport.on_load(:action_view) do
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion(
+ app.config.action_view.delete(:javascript_expansions)
+ )
+
+ ActionView::Helpers::AssetTagHelper.register_stylesheet_expansion(
+ app.config.action_view.delete(:stylesheet_expansions)
+ )
+ end
+ end
+
initializer "action_view.set_configs" do |app|
ActiveSupport.on_load(:action_view) do
app.config.action_view.each do |k,v|
27 actionpack/lib/action_view/railties/log_subscriber.rb
View
@@ -1,27 +0,0 @@
-module ActionView
- # = Action View Log Subscriber
- #
- # Provides functionality so that Rails can output logs from Action View.
- module Railties
- class LogSubscriber < Rails::LogSubscriber
- def render_template(event)
- message = "Rendered #{from_rails_root(event.payload[:identifier])}"
- message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
- message << (" (%.1fms)" % event.duration)
- info(message)
- end
- alias :render_partial :render_template
- alias :render_collection :render_template
-
- def logger
- ActionController::Base.logger
- end
-
- protected
-
- def from_rails_root(string)
- string.sub("#{Rails.root}/", "").sub(/^app\/views\//, "")
- end
- end
- end
-end
2  actionpack/lib/action_view/template/resolver.rb
View
@@ -99,7 +99,7 @@ class FileSystemResolver < PathResolver
def initialize(path)
raise ArgumentError, "path already is a Resolver class" if path.is_a?(Resolver)
super()
- @path = Pathname.new(path).expand_path
+ @path = File.expand_path(path)
end
def eql?(resolver)
46 actionpack/lib/action_view/test_case.rb
View
@@ -99,10 +99,15 @@ def config
end
def render(options = {}, local_assigns = {}, &block)
- @rendered << output = _view.render(options, local_assigns, &block)
+ view.assign(_assigns)
+ @rendered << output = view.render(options, local_assigns, &block)
output
end
+ def locals
+ @locals ||= {}
+ end
+
included do
setup :setup_with_controller
end
@@ -132,36 +137,51 @@ def make_test_case_available_to_view!
end
end
- def _view
- @_view ||= begin
- view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
+ module Locals
+ attr_accessor :locals
+
+ def _render_partial(options)
+ locals[options[:partial]] = options[:locals]
+ super(options)
+ end
+ end
+
+ # The instance of ActionView::Base that is used by +render+.
+ def view
+ @view ||= begin
+ view = ActionView::Base.new(ActionController::Base.view_paths, {}, @controller)
view.singleton_class.send :include, _helpers
view.singleton_class.send :include, @controller._router.url_helpers
view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
+ view.extend(Locals)
+ view.locals = self.locals
view.output_buffer = self.output_buffer
view
end
end
+ alias_method :_view, :view
+
EXCLUDE_IVARS = %w{
+ @_assertion_wrapped
@_result
+ @controller
+ @layouts
+ @locals
+ @method_name
@output_buffer
+ @partials
@rendered
+ @request
+ @routes
@templates
- @view_context_class
- @layouts
- @partials
- @controller
-
- @method_name
- @fixture_cache
- @loaded_fixtures
@test_passed
+ @view
+ @view_context_class
}
def _instance_variables
instance_variables - EXCLUDE_IVARS
- instance_variables
end
def _assigns
14 actionpack/test/abstract/callbacks_test.rb
View
@@ -47,8 +47,12 @@ def aroundz
end
def index
- self.response_body = @text
- end
+ self.response_body = @text.to_s
+ end
+ end
+
+ class Callback2Overwrite < Callback2
+ before_filter :first, :except => :index
end
class TestCallbacks2 < ActiveSupport::TestCase
@@ -70,6 +74,12 @@ def setup
@controller.process(:index)
assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz")
end
+
+ test "before_filter with overwritten condition" do
+ @controller = Callback2Overwrite.new
+ result = @controller.process(:index)
+ assert_equal "", @controller.response_body
+ end
end
class Callback3 < ControllerWithCallbacks
15 actionpack/test/abstract_unit.rb
View
@@ -202,6 +202,21 @@ def with_routing(&block)
self.class.app = old_app
silence_warnings { Object.const_set(:SharedTestRoutes, old_routes) }
end
+
+ def with_autoload_path(path)
+ path = File.join(File.dirname(__FILE__), "fixtures", path)
+ if ActiveSupport::Dependencies.autoload_paths.include?(path)
+ yield
+ else
+ begin
+ ActiveSupport::Dependencies.autoload_paths << path
+ yield
+ ensure
+ ActiveSupport::Dependencies.autoload_paths.reject! {|p| p == path}
+ ActiveSupport::Dependencies.clear
+ end
+ end
+ end
end
# Temporary base class
47 actionpack/test/activerecord/active_record_store_test.rb
View
@@ -17,7 +17,6 @@ def get_session_value
end