Browse files

Merge branch 'rails'

Conflicts:
	actionmailer/lib/action_mailer.rb
	actionmailer/lib/action_mailer/delivery_method/smtp.rb
  • Loading branch information...
2 parents 5f23950 + b9d4ceb commit 186cd7bc530f705b889c27f3680ab48c7c10a6f3 @mikel mikel committed Dec 17, 2009
Showing with 3,352 additions and 2,751 deletions.
  1. +1 −7 .gitignore
  2. +3 −3 .gitmodules
  3. +13 −2 Rakefile
  4. +0 −1 actionmailer/Rakefile
  5. +19 −18 actionmailer/lib/action_mailer.rb
  6. +8 −4 actionmailer/lib/action_mailer/base.rb
  7. +1 −1 actionmailer/lib/action_mailer/delivery_method/file.rb
  8. +16 −14 actionmailer/lib/action_mailer/mail_helper.rb
  9. +2 −5 actionmailer/test/abstract_unit.rb
  10. +34 −0 actionmailer/test/mail_service_test.rb
  11. +22 −22 actionmailer/test/url_test.rb
  12. +0 −2 actionpack/Rakefile
  13. +1 −1 actionpack/actionpack.gemspec
  14. +17 −13 actionpack/lib/abstract_controller.rb
  15. +5 −1 actionpack/lib/abstract_controller/base.rb
  16. +0 −12 actionpack/lib/abstract_controller/exceptions.rb
  17. +16 −7 actionpack/lib/abstract_controller/rendering_controller.rb
  18. +67 −55 actionpack/lib/action_controller.rb
  19. +13 −5 actionpack/lib/action_controller/base.rb
  20. +4 −3 actionpack/lib/action_controller/caching.rb
  21. +0 −5 actionpack/lib/action_controller/dispatch/dispatcher.rb
  22. +2 −5 actionpack/lib/action_controller/metal/compatibility.rb
  23. +1 −10 actionpack/lib/action_controller/metal/exceptions.rb
  24. +13 −12 actionpack/lib/action_controller/metal/flash.rb
  25. +1 −1 actionpack/lib/action_controller/metal/helpers.rb
  26. +45 −56 actionpack/lib/action_controller/metal/render_options.rb
  27. 0 actionpack/lib/action_controller/metal/{rescuable.rb → rescue.rb}
  28. +15 −5 actionpack/lib/action_controller/metal/responder.rb
  29. +2 −1 actionpack/lib/action_controller/{testing → }/test_case.rb
  30. +0 −111 actionpack/lib/action_controller/testing/process.rb
  31. +2 −0 actionpack/lib/action_controller/vendor/html-scanner.rb
  32. +40 −30 actionpack/lib/action_dispatch.rb
  33. +2 −1 actionpack/lib/action_dispatch/http/request.rb
  34. +4 −8 actionpack/lib/action_dispatch/http/response.rb
  35. +0 −17 actionpack/lib/action_dispatch/http/status_codes.rb
  36. +5 −8 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
  37. +1 −1 actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
  38. +0 −68 actionpack/lib/action_dispatch/routing.rb
  39. +2 −2 actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
  40. +346 −219 actionpack/lib/action_dispatch/routing/mapper.rb
  41. +89 −112 actionpack/lib/action_dispatch/routing/route_set.rb
  42. +44 −4 actionpack/lib/action_dispatch/testing/assertions/routing.rb
  43. +16 −3 actionpack/lib/action_dispatch/testing/assertions/tag.rb
  44. +2 −6 actionpack/lib/action_dispatch/testing/integration.rb
  45. +13 −11 actionpack/lib/action_dispatch/testing/performance_test.rb
  46. +42 −0 actionpack/lib/action_dispatch/testing/test_process.rb
  47. +22 −21 actionpack/lib/action_view.rb
  48. +1 −1 actionpack/lib/action_view/base.rb
  49. +1 −1 actionpack/lib/action_view/paths.rb
  50. +10 −10 actionpack/lib/action_view/render/partials.rb
  51. +11 −4 actionpack/lib/action_view/{template → }/template.rb
  52. +80 −76 actionpack/lib/action_view/template/error.rb
  53. +26 −21 actionpack/lib/action_view/template/handler.rb
  54. +49 −47 actionpack/lib/action_view/template/handlers.rb
  55. +2 −2 actionpack/lib/action_view/template/handlers/builder.rb
  56. +2 −2 actionpack/lib/action_view/template/handlers/erb.rb
  57. +2 −2 actionpack/lib/action_view/template/handlers/rjs.rb
  58. +3 −3 actionpack/lib/action_view/template/resolver.rb
  59. +36 −34 actionpack/lib/action_view/template/text.rb
  60. +2 −3 actionpack/lib/action_view/test_case.rb
  61. +13 −13 actionpack/test/abstract/layouts_test.rb
  62. +1 −1 actionpack/test/abstract/render_test.rb
  63. +9 −10 actionpack/test/abstract_unit.rb
  64. +2 −6 actionpack/test/active_record_unit.rb
  65. +1 −1 actionpack/test/activerecord/active_record_store_test.rb
  66. +11 −11 actionpack/test/controller/action_pack_assertions_test.rb
  67. +3 −3 actionpack/test/controller/base_test.rb
  68. +7 −5 actionpack/test/controller/caching_test.rb
  69. +0 −13 actionpack/test/controller/dispatcher_test.rb
  70. +1 −1 actionpack/test/controller/helper_test.rb
  71. +1 −1 actionpack/test/controller/layout_test.rb
  72. +56 −11 actionpack/test/controller/mime_responds_test.rb
  73. +2 −2 actionpack/test/controller/redirect_test.rb
  74. +14 −0 actionpack/test/controller/render_other_test.rb
  75. +16 −16 actionpack/test/controller/render_test.rb
  76. +2 −2 actionpack/test/controller/render_xml_test.rb
  77. +4 −4 actionpack/test/controller/resources_test.rb
  78. +81 −224 actionpack/test/controller/routing_test.rb
  79. +7 −18 actionpack/test/controller/test_test.rb
  80. +5 −5 actionpack/test/controller/url_rewriter_test.rb
  81. +1 −3 actionpack/test/controller/webservice_test.rb
  82. +1 −1 actionpack/test/dispatch/request/multipart_params_parsing_test.rb
  83. +49 −50 actionpack/test/dispatch/routing_test.rb
  84. +12 −1 actionpack/test/lib/controller/fake_controllers.rb
  85. +6 −6 actionpack/test/template/ajax_test.rb
  86. +6 −6 actionpack/test/template/atom_feed_helper_test.rb
  87. +4 −4 actionpack/test/template/render_test.rb
  88. +2 −2 actionpack/test/template/test_case_test.rb
  89. +4 −4 actionpack/test/template/url_helper_test.rb
  90. +0 −1 activemodel/Rakefile
  91. +26 −22 activemodel/lib/active_model.rb
  92. +4 −0 activemodel/lib/active_model/attribute_methods.rb
  93. +3 −4 activemodel/test/cases/helper.rb
  94. +1 −0 activemodel/test/cases/tests_database.rb
  95. +4 −0 activerecord/CHANGELOG
  96. +58 −51 activerecord/lib/active_record.rb
  97. +2 −2 activerecord/lib/active_record/associations.rb
  98. +23 −0 activerecord/lib/active_record/base.rb
  99. +15 −0 activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
  100. +0 −1 activerecord/test/cases/associations/has_many_associations_test.rb
  101. +10 −0 activerecord/test/cases/associations_test.rb
  102. +10 −0 activerecord/test/cases/base_test.rb
  103. +2 −4 activerecord/test/cases/helper.rb
  104. +47 −0 activerecord/test/cases/migration_test.rb
  105. +11 −0 activerecord/test/cases/yaml_serialization_test.rb
  106. +0 −3 activeresource/Rakefile
  107. +15 −12 activeresource/lib/active_resource.rb
  108. +4 −5 activeresource/test/abstract_unit.rb
  109. +3 −3 activeresource/test/cases/base_test.rb
  110. +2 −0 activesupport/CHANGELOG
  111. +0 −1 activesupport/Rakefile
  112. +32 −1 activesupport/lib/active_support.rb
  113. +0 −28 activesupport/lib/active_support/autoload.rb
  114. +5 −1 activesupport/lib/active_support/core_ext/class/removal.rb
  115. +13 −2 activesupport/lib/active_support/core_ext/date_time/conversions.rb
  116. +5 −0 activesupport/lib/active_support/core_ext/enumerable.rb
  117. +2 −2 activesupport/lib/active_support/core_ext/logger.rb
  118. +40 −33 activesupport/lib/active_support/core_ext/object/extending.rb
  119. +1 −1 activesupport/lib/active_support/core_ext/object/to_param.rb
  120. +2 −2 activesupport/lib/active_support/core_ext/object/to_query.rb
  121. +7 −6 activesupport/lib/active_support/core_ext/string/output_safety.rb
  122. +49 −0 activesupport/lib/active_support/dependencies/autoload.rb
  123. +17 −151 activesupport/lib/active_support/notifications.rb
  124. +101 −0 activesupport/lib/active_support/notifications/fanout.rb
  125. +47 −0 activesupport/lib/active_support/notifications/instrumenter.rb
  126. +341 −337 activesupport/lib/active_support/testing/performance.rb
  127. +1 −1 activesupport/lib/active_support/whiny_nil.rb
  128. +80 −0 activesupport/test/autoload.rb
  129. +4 −0 activesupport/test/core_ext/date_time_ext_test.rb
  130. +5 −0 activesupport/test/core_ext/enumerable_test.rb
  131. +4 −4 activesupport/test/core_ext/object/to_query_test.rb
  132. +6 −0 activesupport/test/core_ext/time_with_zone_test.rb
  133. +1 −1 activesupport/test/deprecation_test.rb
  134. +2 −0 activesupport/test/fixtures/autoload/another_class.rb
  135. +2 −0 activesupport/test/fixtures/autoload/some_class.rb
  136. +121 −172 activesupport/test/notifications_test.rb
  137. +1 −0 rack
  138. +0 −1 rack-mount
  139. +3 −9 {railties → }/rails.gemspec
  140. +2 −2 railties/Rakefile
  141. +4 −3 railties/bin/rails
  142. +21 −1 railties/lib/rails.rb
  143. +87 −48 railties/lib/rails/application.rb
  144. +9 −5 railties/lib/rails/commands/console.rb
  145. +92 −79 railties/lib/rails/commands/dbconsole.rb
  146. +16 −3 railties/lib/rails/commands/server.rb
  147. +63 −21 railties/lib/rails/configuration.rb
  148. +1 −1 railties/lib/rails/console_app.rb
  149. +4 −3 railties/lib/rails/generators.rb
  150. +2 −2 railties/lib/rails/generators/actions.rb
  151. +9 −5 railties/lib/rails/generators/rails/app/app_generator.rb
  152. +1 −1 railties/lib/rails/generators/rails/app/templates/Rakefile
  153. +1 −1 railties/lib/rails/generators/rails/app/templates/config.ru
  154. +1 −1 railties/lib/rails/generators/rails/app/templates/config/application.rb
  155. +1 −1 railties/lib/rails/generators/rails/app/templates/config/environment.rb
  156. +37 −20 railties/lib/rails/generators/rails/app/templates/config/routes.rb
  157. +1 −1 railties/lib/rails/generators/rails/app/templates/script/{console → console.tt}
  158. +1 −0 railties/lib/rails/generators/rails/app/templates/script/{dbconsole → dbconsole.tt}
  159. +1 −1 railties/lib/rails/generators/rails/app/templates/script/{server → server.tt}
  160. +1 −1 railties/lib/rails/generators/rails/generator/templates/%file_name%_generator.rb.tt
  161. +0 −1 railties/lib/rails/generators/rails/plugin/templates/Rakefile
  162. +1 −1 railties/lib/rails/generators/rails/resource/resource_generator.rb
  163. +1 −1 railties/lib/rails/generators/rails/scaffold/USAGE
  164. +2 −24 railties/lib/rails/initializable.rb
  165. +0 −2 railties/lib/rails/initializer.rb
  166. +23 −2 railties/lib/rails/plugin.rb
  167. +1 −3 railties/lib/rails/rack/log_tailer.rb
  168. +0 −5 railties/lib/rails/tasks.rb
  169. +7 −1 railties/lib/rails/tasks/framework.rake
  170. +0 −4 railties/lib/rails/tasks/misc.rake
  171. +1 −10 railties/lib/rails/tasks/testing.rake
  172. +5 −0 railties/lib/rails/test_help.rb
  173. +0 −3 railties/lib/rails/vendor/thor-0.12.0/lib/thor/version.rb
  174. +2 −2 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/CHANGELOG.rdoc
  175. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/LICENSE
  176. +10 −10 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/README.rdoc
  177. +1 −1 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/Thorfile
  178. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor.rb
  179. +2 −2 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/actions.rb
  180. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/actions/create_file.rb
  181. +2 −4 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/actions/directory.rb
  182. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/actions/empty_directory.rb
  183. +8 −4 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/actions/file_manipulation.rb
  184. +1 −1 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/actions/inject_into_file.rb
  185. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/base.rb
  186. +1 −1 ...es/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/core_ext/hash_with_indifferent_access.rb
  187. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/core_ext/ordered_hash.rb
  188. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/error.rb
  189. +1 −1 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/group.rb
  190. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/invocation.rb
  191. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/parser.rb
  192. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/parser/argument.rb
  193. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/parser/arguments.rb
  194. +1 −1 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/parser/option.rb
  195. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/parser/options.rb
  196. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/rake_compat.rb
  197. +1 −1 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/runner.rb
  198. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/shell.rb
  199. +1 −1 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/shell/basic.rb
  200. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/shell/color.rb
  201. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/task.rb
  202. 0 railties/lib/rails/vendor/{thor-0.12.0 → thor-0.12.1}/lib/thor/util.rb
  203. +3 −0 railties/lib/rails/vendor/thor-0.12.1/lib/thor/version.rb
  204. +28 −0 railties/railties.gemspec
  205. +31 −1 railties/test/application/configuration_test.rb
  206. +17 −9 railties/test/application/generators_test.rb
  207. +4 −17 railties/test/application/initializer_test.rb
  208. +5 −17 railties/test/application/load_test.rb
  209. +6 −24 railties/test/application/notifications_test.rb
  210. +155 −0 railties/test/application/routing_test.rb
  211. +1 −1 railties/test/fixtures/plugins/engines/engine/config/routes.rb
  212. +1 −1 railties/test/generators/actions_test.rb
  213. +3 −3 railties/test/generators/resource_generator_test.rb
  214. +2 −2 railties/test/generators/scaffold_generator_test.rb
  215. +2 −5 railties/test/initializer/check_ruby_version_test.rb
  216. +36 −0 railties/test/plugins/configuration_test.rb
  217. +2 −1 railties/test/rails_info_controller_test.rb
View
8 .gitignore
@@ -7,16 +7,9 @@ activerecord/doc
actionpack/doc
actionmailer/doc
activesupport/doc
-activemodel/pkg
-activeresource/pkg
-activerecord/pkg
-actionpack/pkg
activemodel/test/fixtures/fixture_database.sqlite3
-actionmailer/pkg
-activesupport/pkg
actionpack/test/tmp
activesupport/test/fixtures/isolation_test
-railties/pkg
railties/test/500.html
railties/test/fixtures/tmp
railties/test/initializer/root/log
@@ -31,3 +24,4 @@ railties/guides/output
bin
vendor/gems/
railties/tmp
+pkg
View
6 .gitmodules
@@ -1,6 +1,6 @@
[submodule "arel"]
path = arel
url = git://github.com/rails/arel.git
-[submodule "rack-mount"]
- path = rack-mount
- url = git://github.com/rails/rack-mount.git
+[submodule "rack"]
+ path = rack
+ url = git://github.com/rails/rack.git
View
15 Rakefile
@@ -1,9 +1,10 @@
require 'rake'
require 'rake/rdoctask'
+require 'rake/gempackagetask'
env = %(PKG_BUILD="#{ENV['PKG_BUILD']}") if ENV['PKG_BUILD']
-PROJECTS = %w(activesupport actionpack actionmailer activeresource activerecord activemodel railties)
+PROJECTS = %w(activesupport activemodel actionpack actionmailer activeresource activerecord railties)
Dir["#{File.dirname(__FILE__)}/*/lib/*/version.rb"].each do |version_path|
require version_path
@@ -23,11 +24,21 @@ task :default => %w(test test:isolated)
end
end
+spec = eval(File.read('rails.gemspec'))
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+end
+
task :install => :gem do
+ system %(cd arel && gem build arel.gemspec && gem install arel-0.2.pre.gem --no-ri --no-rdoc --ignore-dependencies)
+ system %(cd rack && rake gem VERSION=1.0.2.pre && gem install rack-1.0.2.pre.gem --no-ri --no-rdoc --ignore-dependencies)
(PROJECTS - ["railties"]).each do |project|
+ puts "INSTALLING #{project}"
system("gem install #{project}/pkg/#{project}-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
end
- system("gem install railties/pkg/rails-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
+ system("gem install railties/pkg/railties-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
+ system("gem install pkg/rails-#{ActionPack::VERSION::STRING}.gem --no-ri --no-rdoc")
end
desc "Generate documentation for the Rails framework"
View
1 actionmailer/Rakefile
@@ -23,7 +23,6 @@ task :default => [ :test ]
Rake::TestTask.new { |t|
t.libs << "test"
t.pattern = 'test/*_test.rb'
- t.verbose = true
t.warning = true
}
View
37 actionmailer/lib/action_mailer.rb
@@ -21,37 +21,38 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
-$:.unshift(actionpack_path) if File.directory?(actionpack_path)
+actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__)
+$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path)
+
require 'action_controller'
require 'action_view'
module ActionMailer
- def self.load_all!
- [Base, Part, ::Text::Format, ::Net::SMTP]
- end
-
- autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor'
- autoload :DeprecatedBody, 'action_mailer/deprecated_body'
- autoload :Base, 'action_mailer/base'
- autoload :DeliveryMethod, 'action_mailer/delivery_method'
- autoload :Part, 'action_mailer/part'
- autoload :PartContainer, 'action_mailer/part_container'
- autoload :Quoting, 'action_mailer/quoting'
- autoload :TestCase, 'action_mailer/test_case'
- autoload :TestHelper, 'action_mailer/test_helper'
-
+ extend ::ActiveSupport::Autoload
+
+ autoload :AdvAttrAccessor
+ autoload :DeprecatedBody
+ autoload :Base
+ autoload :DeliveryMethod
+ autoload :Part
+ autoload :PartContainer
+ autoload :Quoting
+ autoload :TestCase
+ autoload :TestHelper
end
module Text
+ extend ActiveSupport::Autoload
+
autoload :Format, 'action_mailer/vendor/text_format'
end
module Net
- autoload :SMTP, 'net/smtp'
+ extend ActiveSupport::Autoload
+
+ autoload :SMTP
end
-autoload :MailHelper, 'action_mailer/mail_helper'
gem 'mail', '>= 1.3.0'
require 'mail'
View
12 actionmailer/lib/action_mailer/base.rb
@@ -258,7 +258,7 @@ class Base
include AbstractController::Layouts
include AbstractController::Helpers
- helper MailHelper
+ helper ActionMailer::MailHelper
if Object.const_defined?(:ActionController)
include ActionController::UrlWriter
@@ -543,11 +543,15 @@ def initialize_defaults(method_name)
@headers ||= {}
@sent_on ||= Time.now
- super # Run deprecation hooks
+ ActiveSupport::Deprecation.silence do
+ super # Run deprecation hooks
+ end
end
def create_parts
- super # Run deprecation hooks
+ ActiveSupport::Deprecation.silence do
+ super # Run deprecation hooks
+ end
if String === response_body
@parts.unshift Mail::Part.new(
@@ -620,7 +624,7 @@ def create_mail
headers.each { |k, v| m[k] = v }
real_content_type, ctype_attrs = parse_content_type
-
+
if @parts.empty?
main_type, sub_type = split_content_type(real_content_type)
m.content_type([main_type, sub_type, ctype_attrs])
View
2 actionmailer/lib/action_mailer/delivery_method/file.rb
@@ -6,7 +6,7 @@ module DeliveryMethod
# A delivery method implementation which writes all mails to a file.
class File < Method
self.settings = {
- :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
+ :location => defined?(Rails.root) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails"
}
def perform_delivery(mail)
View
30 actionmailer/lib/action_mailer/mail_helper.rb
@@ -1,17 +1,19 @@
-module MailHelper
- # Uses Text::Format to take the text and format it, indented two spaces for
- # each line, and wrapped at 72 columns.
- def block_format(text)
- formatted = text.split(/\n\r\n/).collect { |paragraph|
- Text::Format.new(
- :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
- ).format
- }.join("\n")
+module ActionMailer
+ module MailHelper
+ # Uses Text::Format to take the text and format it, indented two spaces for
+ # each line, and wrapped at 72 columns.
+ def block_format(text)
+ formatted = text.split(/\n\r\n/).collect { |paragraph|
+ Text::Format.new(
+ :columns => 72, :first_indent => 2, :body_indent => 2, :text => paragraph
+ ).format
+ }.join("\n")
- # Make list points stand on their own line
- formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
- formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
+ # Make list points stand on their own line
+ formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" }
+ formatted.gsub!(/[ ]*([#]+) ([^#]*)/) { |s| " #{$1} #{$2.strip}\n" }
- formatted
+ formatted
+ end
end
-end
+end
View
7 actionmailer/test/abstract_unit.rb
@@ -1,12 +1,9 @@
-root = File.expand_path('../../..', __FILE__)
begin
- require "#{root}/vendor/gems/environment"
+ require File.expand_path('../../../vendor/gems/environment', __FILE__)
rescue LoadError
- $:.unshift("#{root}/activesupport/lib")
- $:.unshift("#{root}/actionpack/lib")
end
-lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
+lib = File.expand_path('../../lib', __FILE__)
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
require 'rubygems'
View
34 actionmailer/test/mail_service_test.rb
@@ -31,6 +31,18 @@ def cancelled_account(recipient)
render :text => "Goodbye, Mr. #{recipient}"
end
+ def from_with_name
+ from "System <system@loudthinking.com>"
+ recipients "root@loudthinking.com"
+ body "Nothing to see here."
+ end
+
+ def from_without_name
+ from "system@loudthinking.com"
+ recipients "root@loudthinking.com"
+ body "Nothing to see here."
+ end
+
def cc_bcc(recipient)
recipients recipient
subject "testing bcc/cc"
@@ -514,6 +526,28 @@ def test_cc_bcc
assert_equal expected.encoded, delivered.encoded
end
+ def test_from_without_name_for_smtp
+ ActionMailer::Base.delivery_method = :smtp
+ TestMailer.deliver_from_without_name
+
+ mail = MockSMTP.deliveries.first
+ assert_not_nil mail
+ mail, from, to = mail
+
+ assert_equal 'system@loudthinking.com', from.to_s
+ end
+
+ def test_from_with_name_for_smtp
+ ActionMailer::Base.delivery_method = :smtp
+ TestMailer.deliver_from_with_name
+
+ mail = MockSMTP.deliveries.first
+ assert_not_nil mail
+ mail, from, to = mail
+
+ assert_equal 'system@loudthinking.com', from.to_s
+ end
+
def test_reply_to
expected = new_mail
View
44 actionmailer/test/url_test.rb
@@ -1,7 +1,9 @@
require 'abstract_unit'
-class TestMailer < ActionMailer::Base
+class WelcomeController < ActionController::Base
+end
+class TestMailer < ActionMailer::Base
default_url_options[:host] = 'www.basecamphq.com'
def signed_up_with_url(recipient)
@@ -52,27 +54,25 @@ def teardown
end
def test_signed_up_with_url
- ActionController::Routing.use_controllers! ['welcome'] do
- ActionController::Routing::Routes.draw do |map|
- map.connect ':controller/:action/:id'
- map.welcome 'welcome', :controller=>"foo", :action=>"bar"
- end
-
- expected = new_mail
- expected.to = @recipient
- expected.subject = "[Signed up] Welcome #{@recipient}"
- expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img alt=\"Somelogo\" src=\"/images/somelogo.png\" />"
- expected.from = "system@loudthinking.com"
- expected.date = Time.local(2004, 12, 12)
-
- created = nil
- assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) }
- assert_not_nil created
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) }
- assert_not_nil ActionMailer::Base.deliveries.first
- assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
+ ActionController::Routing::Routes.draw do |map|
+ map.connect ':controller/:action/:id'
+ map.welcome 'welcome', :controller=>"foo", :action=>"bar"
end
+
+ expected = new_mail
+ expected.to = @recipient
+ expected.subject = "[Signed up] Welcome #{@recipient}"
+ expected.body = "Hello there, \n\nMr. #{@recipient}. Please see our greeting at http://example.com/welcome/greeting http://www.basecamphq.com/welcome\n\n<img alt=\"Somelogo\" src=\"/images/somelogo.png\" />"
+ expected.from = "system@loudthinking.com"
+ expected.date = Time.local(2004, 12, 12)
+
+ created = nil
+ assert_nothing_raised { created = TestMailer.create_signed_up_with_url(@recipient) }
+ assert_not_nil created
+ assert_equal expected.encoded, created.encoded
+
+ assert_nothing_raised { TestMailer.deliver_signed_up_with_url(@recipient) }
+ assert_not_nil ActionMailer::Base.deliveries.first
+ assert_equal expected.encoded, ActionMailer::Base.deliveries.first.encoded
end
end
View
2 actionpack/Rakefile
@@ -31,7 +31,6 @@ Rake::TestTask.new(:test_action_pack) do |t|
# this will not happen automatically and the tests (as a whole) will error
t.test_files = Dir.glob('test/{abstract,controller,dispatch,template}/**/*_test.rb').sort
- t.verbose = true
# t.warning = true
end
@@ -45,7 +44,6 @@ desc 'ActiveRecord Integration Tests'
Rake::TestTask.new(:test_active_record_integration) do |t|
t.libs << 'test'
t.test_files = Dir.glob("test/activerecord/*_test.rb")
- t.verbose = true
end
# Genereate the RDoc documentation
View
2 actionpack/actionpack.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency('activemodel', '= 3.0.pre')
s.add_dependency('rack', '~> 1.0.1')
s.add_dependency('rack-test', '~> 0.5.0')
- s.add_dependency('rack-mount', '~> 0.2.2')
+ s.add_dependency('rack-mount', '~> 0.3.2')
s.add_dependency('erubis', '~> 2.6.5')
s.require_path = 'lib'
View
30 actionpack/lib/abstract_controller.rb
@@ -1,16 +1,20 @@
-require "active_support/core_ext/module/attr_internal"
-require "active_support/core_ext/module/delegation"
+activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
+$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
+
+require 'active_support'
+require 'active_support/core_ext/module/attr_internal'
+require 'active_support/core_ext/module/delegation'
module AbstractController
- autoload :Base, "abstract_controller/base"
- autoload :Callbacks, "abstract_controller/callbacks"
- autoload :Helpers, "abstract_controller/helpers"
- autoload :Layouts, "abstract_controller/layouts"
- autoload :LocalizedCache, "abstract_controller/localized_cache"
- autoload :Logger, "abstract_controller/logger"
- autoload :RenderingController, "abstract_controller/rendering_controller"
- # === Exceptions
- autoload :ActionNotFound, "abstract_controller/exceptions"
- autoload :DoubleRenderError, "abstract_controller/exceptions"
- autoload :Error, "abstract_controller/exceptions"
+ extend ActiveSupport::Autoload
+
+ deferrable do
+ autoload :Base
+ autoload :Callbacks
+ autoload :Helpers
+ autoload :Layouts
+ autoload :LocalizedCache
+ autoload :Logger
+ autoload :RenderingController
+ end
end
View
6 actionpack/lib/abstract_controller/base.rb
@@ -1,4 +1,6 @@
module AbstractController
+ class Error < StandardError; end
+ class ActionNotFound < StandardError; end
class Base
attr_internal :response_body
@@ -74,7 +76,7 @@ def action_methods
abstract!
# Calls the action going through the entire action dispatch stack.
- #
+ #
# The actual method that is called is determined by calling
# #method_for_action. If no method can handle the action, then an
# ActionNotFound error is raised.
@@ -88,6 +90,8 @@ def process(action)
raise ActionNotFound, "The action '#{action}' could not be found"
end
+ @_response_body = nil
+
process_action(action_name)
end
View
12 actionpack/lib/abstract_controller/exceptions.rb
@@ -1,12 +0,0 @@
-module AbstractController
- class Error < StandardError; end
- class ActionNotFound < StandardError; end
-
- class DoubleRenderError < Error
- DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
-
- def initialize(message = nil)
- super(message || DEFAULT_MESSAGE)
- end
- end
-end
View
23 actionpack/lib/abstract_controller/rendering_controller.rb
@@ -1,6 +1,15 @@
+require "abstract_controller/base"
require "abstract_controller/logger"
module AbstractController
+ class DoubleRenderError < Error
+ DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
+
+ def initialize(message = nil)
+ super(message || DEFAULT_MESSAGE)
+ end
+ end
+
module RenderingController
extend ActiveSupport::Concern
@@ -21,7 +30,7 @@ def initialize(*) #:nodoc:
# An instance of a view class. The default view class is ActionView::Base
#
# The view class must have the following methods:
- # View.for_controller[controller] Create a new ActionView instance for a
+ # View.for_controller[controller] Create a new ActionView instance for a
# controller
# View#render_partial[options]
# - responsible for setting options[:_template]
@@ -115,7 +124,7 @@ def self.body_to_s(body)
# _partial<TrueClass, FalseClass>:: Whether or not the file to look up is a partial
def _determine_template(options)
if options.key?(:text)
- options[:_template] = ActionView::TextTemplate.new(options[:text], format_for_text)
+ options[:_template] = ActionView::Template::Text.new(options[:text], format_for_text)
elsif options.key?(:inline)
handler = ActionView::Template.handler_class_for_extension(options[:type] || "erb")
template = ActionView::Template.new(options[:inline], "inline #{options[:inline].inspect}", handler, {})
@@ -152,12 +161,12 @@ def format_for_text
module ClassMethods
def clear_template_caches!
end
-
+
# Append a path to the list of view paths for this controller.
#
# ==== Parameters
- # path<String, ViewPath>:: If a String is provided, it gets converted into
- # the default view path. You may also provide a custom view path
+ # path<String, ViewPath>:: If a String is provided, it gets converted into
+ # the default view path. You may also provide a custom view path
# (see ActionView::ViewPathSet for more information)
def append_view_path(path)
self.view_paths << path
@@ -166,8 +175,8 @@ def append_view_path(path)
# Prepend a path to the list of view paths for this controller.
#
# ==== Parameters
- # path<String, ViewPath>:: If a String is provided, it gets converted into
- # the default view path. You may also provide a custom view path
+ # path<String, ViewPath>:: If a String is provided, it gets converted into
+ # the default view path. You may also provide a custom view path
# (see ActionView::ViewPathSet for more information)
def prepend_view_path(path)
clear_template_caches!
View
122 actionpack/lib/action_controller.rb
@@ -1,66 +1,78 @@
+activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
+$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
+require 'active_support'
+
module ActionController
- autoload :Base, "action_controller/base"
- autoload :Benchmarking, "action_controller/metal/benchmarking"
- autoload :ConditionalGet, "action_controller/metal/conditional_get"
- autoload :Configuration, "action_controller/metal/configuration"
- autoload :Head, "action_controller/metal/head"
- autoload :Helpers, "action_controller/metal/helpers"
- autoload :HideActions, "action_controller/metal/hide_actions"
- autoload :Layouts, "action_controller/metal/layouts"
- autoload :Metal, "action_controller/metal"
- autoload :Middleware, "action_controller/middleware"
- autoload :RackConvenience, "action_controller/metal/rack_convenience"
- autoload :Rails2Compatibility, "action_controller/metal/compatibility"
- autoload :Redirector, "action_controller/metal/redirector"
- autoload :RenderingController, "action_controller/metal/rendering_controller"
- autoload :RenderOptions, "action_controller/metal/render_options"
- autoload :Rescue, "action_controller/metal/rescuable"
- autoload :Responder, "action_controller/metal/responder"
- autoload :Session, "action_controller/metal/session"
- autoload :Testing, "action_controller/metal/testing"
- autoload :UrlFor, "action_controller/metal/url_for"
+ extend ActiveSupport::Autoload
- autoload :Caching, 'action_controller/caching'
- autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
- autoload :Integration, 'action_controller/deprecated/integration_test'
- autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
- autoload :MimeResponds, 'action_controller/metal/mime_responds'
- autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
- autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
- autoload :RecordIdentifier, 'action_controller/record_identifier'
- autoload :Routing, 'action_controller/deprecated'
- autoload :SessionManagement, 'action_controller/metal/session_management'
- autoload :TestCase, 'action_controller/testing/test_case'
- autoload :TestProcess, 'action_controller/testing/process'
- autoload :UrlRewriter, 'action_controller/url_rewriter'
- autoload :UrlWriter, 'action_controller/url_rewriter'
+ deferrable do
+ autoload :Base
+ autoload :Caching
+ autoload :PolymorphicRoutes
+ autoload :Translation
+ autoload :Metal
+ autoload :Middleware
- autoload :Verification, 'action_controller/metal/verification'
- autoload :Flash, 'action_controller/metal/flash'
- autoload :RequestForgeryProtection, 'action_controller/metal/request_forgery_protection'
- autoload :Streaming, 'action_controller/metal/streaming'
- autoload :HttpAuthentication, 'action_controller/metal/http_authentication'
- autoload :FilterParameterLogging, 'action_controller/metal/filter_parameter_logging'
- autoload :Translation, 'action_controller/translation'
- autoload :Cookies, 'action_controller/metal/cookies'
+ autoload_under "metal" do
+ autoload :Benchmarking
+ autoload :ConditionalGet
+ autoload :Configuration
+ autoload :Head
+ autoload :Helpers
+ autoload :HideActions
+ autoload :Layouts
+ autoload :MimeResponds
+ autoload :RackConvenience
+ autoload :Compatibility
+ autoload :Redirector
+ autoload :RenderingController
+ autoload :RenderOptions
+ autoload :Rescue
+ autoload :Responder
+ autoload :Session
+ autoload :SessionManagement
+ autoload :UrlFor
+ autoload :Verification
+ autoload :Flash
+ autoload :RequestForgeryProtection
+ autoload :Streaming
+ autoload :HttpAuthentication
+ autoload :FilterParameterLogging
+ autoload :Cookies
+ end
- autoload :ActionControllerError, 'action_controller/metal/exceptions'
- autoload :RenderError, 'action_controller/metal/exceptions'
- autoload :RoutingError, 'action_controller/metal/exceptions'
- autoload :MethodNotAllowed, 'action_controller/metal/exceptions'
- autoload :NotImplemented, 'action_controller/metal/exceptions'
- autoload :UnknownController, 'action_controller/metal/exceptions'
- autoload :MissingFile, 'action_controller/metal/exceptions'
- autoload :RenderError, 'action_controller/metal/exceptions'
- autoload :SessionOverflowError, 'action_controller/metal/exceptions'
- autoload :UnknownHttpMethod, 'action_controller/metal/exceptions'
-end
+ autoload :Dispatcher, 'action_controller/dispatch/dispatcher'
+ autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
+ autoload :Routing, 'action_controller/deprecated'
+ autoload :Integration, 'action_controller/deprecated/integration_test'
+ autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
+ end
-autoload :HTML, 'action_controller/vendor/html-scanner'
-autoload :AbstractController, 'abstract_controller'
+ autoload :RecordIdentifier
+ autoload :UrlRewriter
+ autoload :UrlWriter, 'action_controller/url_rewriter'
+
+ # TODO: Don't autoload exceptions, setup explicit
+ # requires for files that need them
+ autoload_at "action_controller/metal/exceptions" do
+ autoload :ActionControllerError
+ autoload :RenderError
+ autoload :RoutingError
+ autoload :MethodNotAllowed
+ autoload :NotImplemented
+ autoload :UnknownController
+ autoload :MissingFile
+ autoload :RenderError
+ autoload :SessionOverflowError
+ autoload :UnknownHttpMethod
+ end
+end
+# All of these simply register additional autoloads
+require 'abstract_controller'
require 'action_dispatch'
require 'action_view'
+require 'action_controller/vendor/html-scanner'
# Common ActiveSupport usage in ActionController
require "active_support/concern"
View
18 actionpack/lib/action_controller/base.rb
@@ -19,12 +19,11 @@ class Base < Metal
# Legacy modules
include SessionManagement
- include ActionDispatch::StatusCodes
include ActionController::Caching
include ActionController::MimeResponds
# Rails 2.x compatibility
- include ActionController::Rails2Compatibility
+ include ActionController::Compatibility
include ActionController::Cookies
include ActionController::Session
@@ -91,7 +90,7 @@ def _normalize_options(action = nil, options = {}, &blk)
end
if options[:status]
- options[:status] = interpret_status(options[:status]).to_i
+ options[:status] = _interpret_status(options[:status])
end
options[:update] = blk if block_given?
@@ -140,9 +139,9 @@ def redirect_to(options = {}, response_status = {}) #:doc:
raise ActionControllerError.new("Cannot redirect to nil!") if options.nil?
status = if options.is_a?(Hash) && options.key?(:status)
- interpret_status(options.delete(:status))
+ _interpret_status(options.delete(:status))
elsif response_status.key?(:status)
- interpret_status(response_status[:status])
+ _interpret_status(response_status[:status])
else
302
end
@@ -164,5 +163,14 @@ def redirect_to(options = {}, response_status = {}) #:doc:
super(url, status)
end
+
+ private
+ def _interpret_status(status)
+ if status.is_a?(Symbol)
+ (ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[status] || 500)
+ else
+ status.to_i
+ end
+ end
end
end
View
7 actionpack/lib/action_controller/caching.rb
@@ -30,10 +30,11 @@ module ActionController #:nodoc:
# config.action_controller.cache_store = MyOwnStore.new("parameter")
module Caching
extend ActiveSupport::Concern
+ extend ActiveSupport::Autoload
- autoload :Actions, 'action_controller/caching/actions'
- autoload :Fragments, 'action_controller/caching/fragments'
- autoload :Pages, 'action_controller/caching/pages'
+ autoload :Actions
+ autoload :Fragments
+ autoload :Pages
autoload :Sweeper, 'action_controller/caching/sweeping'
autoload :Sweeping, 'action_controller/caching/sweeping'
View
5 actionpack/lib/action_controller/dispatch/dispatcher.rb
@@ -13,11 +13,6 @@ def define_dispatcher_callbacks(cache_classes)
# Run prepare callbacks before every request in development mode
self.prepare_each_request = true
- # Development mode callbacks
- ActionDispatch::Callbacks.before_dispatch do |app|
- ActionController::Routing::Routes.reload
- end
-
ActionDispatch::Callbacks.after_dispatch do
# Cleanup the application before processing the current request.
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
View
7 actionpack/lib/action_controller/metal/compatibility.rb
@@ -1,5 +1,5 @@
module ActionController
- module Rails2Compatibility
+ module Compatibility
extend ActiveSupport::Concern
class ::ActionController::ActionControllerError < StandardError #:nodoc:
@@ -46,11 +46,8 @@ class << self
cattr_accessor :use_accept_header
self.use_accept_header = true
- cattr_accessor :page_cache_directory
self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
- cattr_reader :cache_store
-
cattr_accessor :consider_all_requests_local
self.consider_all_requests_local = true
@@ -116,7 +113,7 @@ def _find_layout(name, details)
details[:prefix] = nil if name =~ /\blayouts/
super
end
-
+
# Move this into a "don't run in production" module
def _default_layout(details, require_layout = false)
super
View
11 actionpack/lib/action_controller/metal/exceptions.rb
@@ -18,18 +18,9 @@ class MethodNotAllowed < ActionControllerError #:nodoc:
def initialize(*allowed_methods)
super("Only #{allowed_methods.to_sentence(:locale => :en)} requests are allowed.")
- @allowed_methods = allowed_methods
- end
-
- def allowed_methods_header
- allowed_methods.map { |method_symbol| method_symbol.to_s.upcase } * ', '
- end
-
- def handle_response!(response)
- response.headers['Allow'] ||= allowed_methods_header
end
end
-
+
class NotImplemented < MethodNotAllowed #:nodoc:
end
View
25 actionpack/lib/action_controller/metal/flash.rb
@@ -133,10 +133,23 @@ def use(key = nil, used = true)
Array(key || keys).each { |k| used ? @used << k : @used.delete(k) }
return key ? self[key] : self
end
+ end
+
+ # Access the contents of the flash. Use <tt>flash["notice"]</tt> to
+ # read a notice you put there or <tt>flash["notice"] = "hello"</tt>
+ # to put a new one.
+ def flash #:doc:
+ unless @_flash
+ @_flash = session["flash"] || FlashHash.new
+ @_flash.sweep
end
+ @_flash
+ end
+
protected
def process_action(method_name)
+ @_flash = nil
super
@_flash.store(session) if @_flash
@_flash = nil
@@ -146,17 +159,5 @@ def reset_session
super
@_flash = nil
end
-
- # Access the contents of the flash. Use <tt>flash["notice"]</tt> to
- # read a notice you put there or <tt>flash["notice"] = "hello"</tt>
- # to put a new one.
- def flash #:doc:
- unless @_flash
- @_flash = session["flash"] || FlashHash.new
- @_flash.sweep
- end
-
- @_flash
- end
end
end
View
2 actionpack/lib/action_controller/metal/helpers.rb
@@ -52,7 +52,7 @@ module Helpers
included do
# Set the default directory for helpers
extlib_inheritable_accessor(:helpers_dir) do
- defined?(Rails) ? "#{Rails.root}/app/helpers" : "app/helpers"
+ defined?(Rails.root) ? "#{Rails.root}/app/helpers" : "app/helpers"
end
end
View
101 actionpack/lib/action_controller/metal/render_options.rb
@@ -1,19 +1,24 @@
module ActionController
+
+ def self.add_renderer(key, &block)
+ RenderOptions.add(key, &block)
+ end
+
module RenderOptions
extend ActiveSupport::Concern
included do
extlib_inheritable_accessor :_renderers
- self._renderers = []
+ self._renderers = {}
end
module ClassMethods
def _write_render_options
- renderers = _renderers.map do |r|
+ renderers = _renderers.map do |name, value|
<<-RUBY_EVAL
- if options.key?(:#{r})
+ if options.key?(:#{name})
_process_options(options)
- return render_#{r}(options[:#{r}], options)
+ return _render_option_#{name}(options[:#{name}], options)
end
RUBY_EVAL
end
@@ -25,79 +30,63 @@ def _handle_render_options(options)
RUBY_EVAL
end
- def _add_render_option(name)
- _renderers << name
+ def use_renderers(*args)
+ args.each do |key|
+ _renderers[key] = RENDERERS[key]
+ end
_write_render_options
end
+ alias use_renderer use_renderers
end
def render_to_body(options)
_handle_render_options(options) || super
end
- end
-
- module RenderOption #:nodoc:
- def self.extended(base)
- base.extend ActiveSupport::Concern
- base.send :include, ::ActionController::RenderOptions
- def base.register_renderer(name)
- included { _add_render_option(name) }
- end
+ RENDERERS = {}
+ def self.add(key, &block)
+ define_method("_render_option_#{key}", &block)
+ RENDERERS[key] = block
+ All._write_render_options
end
- end
- module RenderOptions
- module Json
- extend RenderOption
- register_renderer :json
+ module All
+ extend ActiveSupport::Concern
+ include RenderOptions
- def render_json(json, options)
- json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
- json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
- self.content_type ||= Mime::JSON
- self.response_body = json
+ INCLUDED = []
+ included do
+ self._renderers = RENDERERS
+ _write_render_options
+ INCLUDED << self
end
- end
-
- module Js
- extend RenderOption
- register_renderer :js
- def render_js(js, options)
- self.content_type ||= Mime::JS
- self.response_body = js.respond_to?(:to_js) ? js.to_js : js
+ def self._write_render_options
+ INCLUDED.each(&:_write_render_options)
end
end
- module Xml
- extend RenderOption
- register_renderer :xml
-
- def render_xml(xml, options)
- self.content_type ||= Mime::XML
- self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
- end
+ add :json do |json, options|
+ json = ActiveSupport::JSON.encode(json) unless json.respond_to?(:to_str)
+ json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
+ self.content_type ||= Mime::JSON
+ self.response_body = json
end
- module RJS
- extend RenderOption
- register_renderer :update
-
- def render_update(proc, options)
- generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
- self.content_type = Mime::JS
- self.response_body = generator.to_s
- end
+ add :js do |js, options|
+ self.content_type ||= Mime::JS
+ self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
- module All
- extend ActiveSupport::Concern
+ add :xml do |xml, options|
+ self.content_type ||= Mime::XML
+ self.response_body = xml.respond_to?(:to_xml) ? xml.to_xml : xml
+ end
- include ActionController::RenderOptions::Json
- include ActionController::RenderOptions::Js
- include ActionController::RenderOptions::Xml
- include ActionController::RenderOptions::RJS
+ add :update do |proc, options|
+ generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(view_context, &proc)
+ self.content_type = Mime::JS
+ self.response_body = generator.to_s
end
end
end
View
0 .../lib/action_controller/metal/rescuable.rb → ...ack/lib/action_controller/metal/rescue.rb
File renamed without changes.
View
20 actionpack/lib/action_controller/metal/responder.rb
@@ -80,6 +80,11 @@ module ActionController #:nodoc:
class Responder
attr_reader :controller, :request, :format, :resource, :resources, :options
+ ACTIONS_FOR_VERBS = {
+ :post => :new,
+ :put => :edit
+ }
+
def initialize(controller, resources, options={})
@controller = controller
@request = controller.request
@@ -102,9 +107,14 @@ def initialize(controller, resources, options={})
# not defined, call to_format.
#
def self.call(*args)
- responder = new(*args)
- method = :"to_#{responder.format}"
- responder.respond_to?(method) ? responder.send(method) : responder.to_format
+ new(*args).respond
+ end
+
+ # Main entry point for responder responsible to dispatch to the proper format.
+ #
+ def respond
+ method = :"to_#{format}"
+ respond_to?(method) ? send(method) : to_format
end
# HTML format does not render the resource, it always attempt to render a
@@ -133,7 +143,7 @@ def to_format
def navigation_behavior(error)
if get?
raise error
- elsif has_errors?
+ elsif has_errors? && default_action
render :action => default_action
else
redirect_to resource_location
@@ -204,7 +214,7 @@ def has_errors?
# the verb is post.
#
def default_action
- @action || (request.post? ? :new : :edit)
+ @action ||= ACTIONS_FOR_VERBS[request.method]
end
end
end
View
3 ...ib/action_controller/testing/test_case.rb → ...onpack/lib/action_controller/test_case.rb
@@ -1,5 +1,6 @@
require 'active_support/test_case'
require 'rack/session/abstract/id'
+require 'action_controller/metal/testing'
module ActionController
class TestRequest < ActionDispatch::TestRequest #:nodoc:
@@ -180,7 +181,7 @@ def initialize(session = {})
#
# assert_redirected_to page_url(:title => 'foo')
class TestCase < ActiveSupport::TestCase
- include TestProcess
+ include ActionDispatch::TestProcess
# Executes a request simulating GET HTTP method and set/volley the response
def get(action, parameters = nil, session = nil, flash = nil)
View
111 actionpack/lib/action_controller/testing/process.rb
@@ -1,111 +0,0 @@
-require 'active_support/core_ext/object/conversions'
-require "rack/test"
-
-module ActionController #:nodoc:
- # Essentially generates a modified Tempfile object similar to the object
- # you'd get from the standard library CGI module in a multipart
- # request. This means you can use an ActionController::TestUploadedFile
- # object in the params of a test request in order to simulate
- # a file upload.
- #
- # Usage example, within a functional test:
- # post :change_avatar, :avatar => ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + '/files/spongebob.png', 'image/png')
- #
- # Pass a true third parameter to ensure the uploaded file is opened in binary mode (only required for Windows):
- # post :change_avatar, :avatar => ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + '/files/spongebob.png', 'image/png', :binary)
- TestUploadedFile = Rack::Test::UploadedFile
-
- module TestProcess
- def assigns(key = nil)
- assigns = {}
- @controller.instance_variable_names.each do |ivar|
- next if ActionController::Base.protected_instance_variables.include?(ivar)
- assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar)
- end
-
- key.nil? ? assigns : assigns[key.to_s]
- end
-
- def session
- @request.session
- end
-
- def flash
- @request.flash
- end
-
- def cookies
- @request.cookies.merge(@response.cookies)
- end
-
- def redirect_to_url
- @response.redirect_url
- end
-
- def html_document
- xml = @response.content_type =~ /xml$/
- @html_document ||= HTML::Document.new(@response.body, false, xml)
- end
-
- def find_tag(conditions)
- html_document.find(conditions)
- end
-
- def find_all_tag(conditions)
- html_document.find_all(conditions)
- end
-
- def method_missing(selector, *args, &block)
- if @controller && ActionController::Routing::Routes.named_routes.helpers.include?(selector)
- @controller.send(selector, *args, &block)
- else
- super
- end
- end
-
- # Shortcut for <tt>ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + path, type)</tt>:
- #
- # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png')
- #
- # To upload binary files on Windows, pass <tt>:binary</tt> as the last parameter.
- # This will not affect other platforms:
- #
- # post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png', :binary)
- def fixture_file_upload(path, mime_type = nil, binary = false)
- fixture_path = ActionController::TestCase.send(:fixture_path) if ActionController::TestCase.respond_to?(:fixture_path)
- ActionController::TestUploadedFile.new("#{fixture_path}#{path}", mime_type, binary)
- end
-
- # A helper to make it easier to test different route configurations.
- # This method temporarily replaces ActionController::Routing::Routes
- # with a new RouteSet instance.
- #
- # The new instance is yielded to the passed block. Typically the block
- # will create some routes using <tt>map.draw { map.connect ... }</tt>:
- #
- # with_routing do |set|
- # set.draw do |map|
- # map.connect ':controller/:action/:id'
- # assert_equal(
- # ['/content/10/show', {}],
- # map.generate(:controller => 'content', :id => 10, :action => 'show')
- # end
- # end
- # end
- #
- def with_routing
- real_routes = ActionController::Routing::Routes
- ActionController::Routing.module_eval { remove_const :Routes }
-
- temporary_routes = ActionController::Routing::RouteSet.new
- ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
-
- yield temporary_routes
- ensure
- if ActionController::Routing.const_defined? :Routes
- ActionController::Routing.module_eval { remove_const :Routes }
- end
- ActionController::Routing.const_set(:Routes, real_routes) if real_routes
- end
- end
-end
View
2 actionpack/lib/action_controller/vendor/html-scanner.rb
@@ -1,6 +1,8 @@
$LOAD_PATH << "#{File.dirname(__FILE__)}/html-scanner"
module HTML
+ extend ActiveSupport::Autoload
+
autoload :CDATA, 'html/node'
autoload :Document, 'html/document'
autoload :FullSanitizer, 'html/sanitizer'
View
70 actionpack/lib/action_dispatch.rb
@@ -21,50 +21,60 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
+activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
+$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
+require 'active_support'
+
require 'rack'
module Rack
autoload :Test, 'rack/test'
end
module ActionDispatch
- autoload :Request, 'action_dispatch/http/request'
- autoload :Response, 'action_dispatch/http/response'
- autoload :StatusCodes, 'action_dispatch/http/status_codes'
- autoload :Utils, 'action_dispatch/http/utils'
+ extend ActiveSupport::Autoload
- autoload :Callbacks, 'action_dispatch/middleware/callbacks'
- autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
- autoload :ParamsParser, 'action_dispatch/middleware/params_parser'
- autoload :Rescue, 'action_dispatch/middleware/rescue'
- autoload :ShowExceptions, 'action_dispatch/middleware/show_exceptions'
- autoload :Static, 'action_dispatch/middleware/static'
- autoload :StringCoercion, 'action_dispatch/middleware/string_coercion'
+ autoload_under 'http' do
+ autoload :Request
+ autoload :Response
+ autoload :StatusCodes
+ autoload :Utils
+ end
- autoload :Routing, 'action_dispatch/routing'
+ deferrable do
+ autoload_under 'middleware' do
+ autoload :Callbacks
+ autoload :ParamsParser
+ autoload :Rescue
+ autoload :ShowExceptions
+ autoload :Static
+ autoload :StringCoercion
+ end
- autoload :Assertions, 'action_dispatch/testing/assertions'
- autoload :Integration, 'action_dispatch/testing/integration'
- autoload :IntegrationTest, 'action_dispatch/testing/integration'
- autoload :PerformanceTest, 'action_dispatch/testing/performance_test'
- autoload :TestRequest, 'action_dispatch/testing/test_request'
- autoload :TestResponse, 'action_dispatch/testing/test_response'
+ autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
+ autoload :Routing
- autoload :HTML, 'action_controller/vendor/html-scanner'
+ module Http
+ autoload :Headers, 'action_dispatch/http/headers'
+ end
- module Http
- autoload :Headers, 'action_dispatch/http/headers'
- end
+ module Session
+ autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
+ autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
+ autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
+ end
- module Session
- autoload :AbstractStore, 'action_dispatch/middleware/session/abstract_store'
- autoload :CookieStore, 'action_dispatch/middleware/session/cookie_store'
- autoload :MemCacheStore, 'action_dispatch/middleware/session/mem_cache_store'
+ autoload_under 'testing' do
+ autoload :Assertions
+ autoload :Integration
+ autoload :PerformanceTest
+ autoload :TestProcess
+ autoload :TestRequest
+ autoload :TestResponse
+ end
end
+
+ autoload :HTML, 'action_controller/vendor/html-scanner'
end
autoload :Mime, 'action_dispatch/http/mime_type'
-
-activesupport_path = "#{File.dirname(__FILE__)}/../../activesupport/lib"
-$:.unshift activesupport_path if File.directory?(activesupport_path)
-require 'active_support'
View
3 actionpack/lib/action_dispatch/http/request.rb
@@ -6,6 +6,7 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/access'
+require 'action_dispatch/http/headers'
module ActionDispatch
class Request < Rack::Request
@@ -117,7 +118,7 @@ def accepts
end
end
end
-
+
def if_modified_since
if since = env['HTTP_IF_MODIFIED_SINCE']
Time.rfc2822(since) rescue nil
View
12 actionpack/lib/action_dispatch/http/response.rb
@@ -33,7 +33,6 @@ module ActionDispatch # :nodoc:
# end
class Response < Rack::Response
attr_accessor :request, :blank
- attr_reader :cache_control
attr_writer :header, :sending_file
alias_method :headers=, :header=
@@ -50,19 +49,16 @@ def initialize
@body, @cookie = [], []
@sending_file = false
+ @blank = false
+ @etag = nil
+
yield self if block_given?
end
def cache_control
@cache_control ||= {}
end
- def write(str)
- s = str.to_s
- @writer.call s
- str
- end
-
def status=(status)
@status = status.to_i
end
@@ -277,7 +273,7 @@ def set_conditional_cache_control!
max_age = control[:max_age]
options = []
- options << "max-age=#{max_age}" if max_age
+ options << "max-age=#{max_age.to_i}" if max_age
options << (control[:public] ? "public" : "private")
options << "must-revalidate" if control[:must_revalidate]
options.concat(extras) if extras
View
17 actionpack/lib/action_dispatch/http/status_codes.rb
@@ -21,22 +21,5 @@ module StatusCodes #:nodoc:
hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
hash
}.freeze
-
- private
- # Given a status parameter, determine whether it needs to be converted
- # to a string. If it is a fixnum, use the STATUS_CODES hash to lookup
- # the default message. If it is a symbol, use the SYMBOL_TO_STATUS_CODE
- # hash to convert it.
- def interpret_status(status)
- case status
- when Fixnum then
- "#{status} #{STATUS_CODES[status]}".strip
- when Symbol then
- interpret_status(SYMBOL_TO_STATUS_CODE[status] ||
- "500 Unknown Status #{status.inspect}")
- else
- status.to_s
- end
- end
end
end
View
13 actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -2,8 +2,6 @@
module ActionDispatch
class ShowExceptions
- include StatusCodes
-
LOCALHOST = '127.0.0.1'.freeze
RESCUES_TEMPLATE_PATH = File.join(File.dirname(__FILE__), 'templates')
@@ -12,8 +10,7 @@ class ShowExceptions
@@rescue_responses = Hash.new(:internal_server_error)
@@rescue_responses.update({
'ActionController::RoutingError' => :not_found,
- # TODO: Clean this up after the switch
- ActionController::UnknownAction.name => :not_found,
+ 'AbstractController::ActionNotFound' => :not_found,
'ActiveRecord::RecordNotFound' => :not_found,
'ActiveRecord::StaleObjectError' => :conflict,
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
@@ -28,8 +25,8 @@ class ShowExceptions
@@rescue_templates.update({
'ActionView::MissingTemplate' => 'missing_template',
'ActionController::RoutingError' => 'routing_error',
- ActionController::UnknownAction.name => 'unknown_action',
- 'ActionView::TemplateError' => 'template_error'
+ 'AbstractController::ActionNotFound' => 'unknown_action',
+ 'ActionView::Template::Error' => 'template_error'
})
FAILSAFE_RESPONSE = [500, {'Content-Type' => 'text/html'},
@@ -104,7 +101,7 @@ def local_request?(request)
end
def status_code(exception)
- interpret_status(@@rescue_responses[exception.class.name]).to_i
+ ActionDispatch::StatusCodes::SYMBOL_TO_STATUS_CODE[@@rescue_responses[exception.class.name]]
end
def render(status, body)
@@ -119,7 +116,7 @@ def log_error(exception)
return unless logger
ActiveSupport::Deprecation.silence do
- if ActionView::TemplateError === exception
+ if ActionView::Template::Error === exception
logger.fatal(exception.to_s)
else
logger.fatal(
View
2 actionpack/lib/action_dispatch/middleware/templates/rescues/_trace.erb
@@ -7,7 +7,7 @@
names = traces.collect {|name, trace| name}
%>
-<p><code>RAILS_ROOT: <%= defined?(RAILS_ROOT) ? RAILS_ROOT : "unset" %></code></p>
+<p><code>Rails.root: <%= defined?(Rails) && Rails.respond_to?(:root) ? Rails.root : "unset" %></code></p>
<div id="traces">
<% names.each do |name| %>
View
68 actionpack/lib/action_dispatch/routing.rb
@@ -266,77 +266,9 @@ module Routing
SEPARATORS = %w( / . ? )
HTTP_METHODS = [:get, :head, :post, :put, :delete, :options]
- # The root paths which may contain controller files
- mattr_accessor :controller_paths
- self.controller_paths = []
-
# A helper module to hold URL related helpers.
module Helpers
include ActionController::PolymorphicRoutes
end
-
- class << self
- def controller_constraints
- @controller_constraints ||= Regexp.union(*possible_controllers.collect { |n| Regexp.escape(n) })
- end
-
- def clear_controller_cache!
- @controller_constraints = nil
- end
-
- private
- # Returns the array of controller names currently available to ActionController::Routing.
- def possible_controllers
- possible_controllers = []
-
- # Find any controller classes already in memory
- ActionController::Base.subclasses.each do |klass|
- controller_name = klass.underscore
- controller_name.gsub!(/_controller\Z/, '')
- possible_controllers << controller_name
- end
-
- # Find controllers in controllers/ directory
- paths = controller_paths.select { |path| File.directory?(path) && path != "." }
- seen_paths = Hash.new {|h, k| h[k] = true; false}
- normalize_paths(paths).each do |load_path|
- Dir["#{load_path}/**/*_controller.rb"].collect do |path|
- next if seen_paths[path.gsub(%r{^\.[/\\]}, "")]
-
- controller_name = path[(load_path.length + 1)..-1]
-
- controller_name.gsub!(/_controller\.rb\Z/, '')
- possible_controllers << controller_name
- end
- end
-
- # remove duplicates
- possible_controllers.uniq!
-
- possible_controllers
- end
-
- # Returns an array of paths, cleaned of double-slashes and relative path references.
- # * "\\\" and "//" become "\\" or "/".
- # * "/foo/bar/../config" becomes "/foo/config".
- # The returned array is sorted by length, descending.
- def normalize_paths(paths)
- # do the hokey-pokey of path normalization...
- paths = paths.collect do |path|
- path = path.
- gsub("//", "/"). # replace double / chars with a single
- gsub("\\\\", "\\"). # replace double \ chars with a single
- gsub(%r{(.)[\\/]$}, '\1') # drop final / or \ if path ends with it
-
- # eliminate .. paths where possible
- re = %r{[^/\\]+[/\\]\.\.[/\\]}
- path.gsub!(re, "") while path.match(re)
- path
- end
-
- # start with longest path, first
- paths = paths.uniq.sort_by { |path| - path.length }
- end
- end
end
end
View
4 actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
@@ -113,7 +113,7 @@ def connect(path, options = {})
end
end
- requirements[:controller] ||= Routing.controller_constraints
+ requirements[:controller] ||= @set.controller_constraints
if defaults[:controller]
defaults[:action] ||= 'index'
@@ -175,7 +175,7 @@ def optionalize_trailing_dynamic_segments(path, requirements, defaults) #:nodoc:
optional = false
elsif segment =~ /^:(\w+)$/
if defaults.has_key?($1.to_sym)
- defaults.delete($1.to_sym)
+ defaults.delete($1.to_sym) if defaults[$1.to_sym].nil?
else
optional = false
end
View
565 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1,153 +1,192 @@
module ActionDispatch
module Routing
class Mapper
- module Resources
- def resource(*resources, &block)
- options = resources.last.is_a?(Hash) ? resources.pop : {}
-
- if resources.length > 1
- raise ArgumentError if block_given?
- resources.each { |r| resource(r, options) }
- return self
+ class Constraints
+ def self.new(app, constraints = [])
+ if constraints.any?
+ super(app, constraints)
+ else
+ app
end
+ end
- resource = resources.pop
+ def initialize(app, constraints = [])
+ @app, @constraints = app, constraints
+ end
- if @scope[:scope_level] == :resources
- member do
- resource(resource, options, &block)
- end
- return self
- end
+ def call(env)
+ req = Rack::Request.new(env)
- singular = resource.to_s
- plural = singular.pluralize
+ @constraints.each { |constraint|
+ if constraint.respond_to?(:matches?) && !constraint.matches?(req)
+ return [417, {}, []]
+ elsif constraint.respond_to?(:call) && !constraint.call(req)
+ return [417, {}, []]