aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile16
-rw-r--r--README.rdoc50
-rw-r--r--actionmailer/README.rdoc2
-rwxr-xr-xactionmailer/Rakefile4
-rw-r--r--actionmailer/lib/action_mailer.rb2
-rw-r--r--actionmailer/lib/action_mailer/adv_attr_accessor.rb28
-rw-r--r--actionmailer/lib/action_mailer/base.rb54
-rw-r--r--actionmailer/lib/action_mailer/old_api.rb255
-rw-r--r--actionmailer/lib/action_mailer/tmail_compat.rb37
-rw-r--r--actionmailer/test/log_subscriber_test.rb14
-rw-r--r--actionmailer/test/old_base/adv_attr_test.rb41
-rw-r--r--actionmailer/test/old_base/mail_render_test.rb134
-rw-r--r--actionmailer/test/old_base/mail_service_test.rb1097
-rw-r--r--actionmailer/test/old_base/tmail_compat_test.rb42
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/README.rdoc2
-rwxr-xr-xactionpack/Rakefile4
-rw-r--r--actionpack/actionpack.gemspec6
-rw-r--r--actionpack/lib/abstract_controller/base.rb2
-rw-r--r--actionpack/lib/abstract_controller/helpers.rb2
-rw-r--r--actionpack/lib/action_controller.rb13
-rw-r--r--actionpack/lib/action_controller/caching/actions.rb4
-rw-r--r--actionpack/lib/action_controller/metal/data_streaming.rb6
-rw-r--r--actionpack/lib/action_controller/metal/force_ssl.rb6
-rw-r--r--actionpack/lib/action_controller/metal/http_authentication.rb4
-rw-r--r--actionpack/lib/action_controller/metal/instrumentation.rb2
-rw-r--r--actionpack/lib/action_controller/metal/request_forgery_protection.rb8
-rw-r--r--actionpack/lib/action_controller/test_case.rb2
-rw-r--r--actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb2
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb4
-rw-r--r--actionpack/lib/action_dispatch/http/request.rb14
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb26
-rw-r--r--actionpack/lib/action_dispatch/middleware/callbacks.rb3
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb4
-rw-r--r--actionpack/lib/action_dispatch/middleware/session/abstract_store.rb10
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb14
-rw-r--r--actionpack/lib/action_dispatch/routing/route.rb7
-rw-r--r--actionpack/lib/action_dispatch/routing/url_for.rb2
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions.rb13
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/response.rb7
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/routing.rb18
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb2
-rw-r--r--actionpack/lib/action_view/helpers.rb2
-rw-r--r--actionpack/lib/action_view/helpers/asset_paths.rb13
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helper.rb18
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb11
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb8
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb8
-rw-r--r--actionpack/lib/action_view/helpers/capture_helper.rb4
-rw-r--r--actionpack/lib/action_view/helpers/date_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb20
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb8
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/sanitize_helper.rb10
-rw-r--r--actionpack/lib/action_view/helpers/sprockets_helper.rb69
-rw-r--r--actionpack/lib/action_view/helpers/tag_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb4
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb12
-rw-r--r--actionpack/lib/action_view/template.rb1
-rw-r--r--actionpack/lib/action_view/template/handler.rb49
-rw-r--r--actionpack/lib/action_view/template/handlers.rb6
-rw-r--r--actionpack/lib/action_view/template/handlers/erb.rb2
-rw-r--r--actionpack/lib/action_view/test_case.rb6
-rw-r--r--actionpack/lib/sprockets/helpers.rb5
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb107
-rw-r--r--actionpack/lib/sprockets/railtie.rb32
-rw-r--r--actionpack/test/activerecord/controller_runtime_test.rb26
-rw-r--r--actionpack/test/controller/caching_test.rb3
-rw-r--r--actionpack/test/controller/deprecation/deprecated_base_methods_test.rb26
-rw-r--r--actionpack/test/controller/helper_test.rb2
-rw-r--r--actionpack/test/controller/mime_responds_test.rb6
-rw-r--r--actionpack/test/controller/render_test.rb7
-rw-r--r--actionpack/test/controller/request_forgery_protection_test.rb6
-rw-r--r--actionpack/test/controller/view_paths_test.rb8
-rw-r--r--actionpack/test/dispatch/response_body_is_proc_test.rb37
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb2
-rw-r--r--actionpack/test/fixtures/sprockets/app/javascripts/application.js1
-rw-r--r--actionpack/test/fixtures/sprockets/app/stylesheets/application.css1
-rw-r--r--actionpack/test/fixtures/test/deprecated_nested_layout.erb3
-rw-r--r--actionpack/test/template/form_helper_test.rb125
-rw-r--r--actionpack/test/template/number_helper_test.rb9
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb42
-rw-r--r--actionpack/test/template/streaming_render_test.rb4
-rw-r--r--actionpack/test/template/test_case_test.rb16
-rw-r--r--actionpack/test/template/url_helper_test.rb2
-rwxr-xr-xactivemodel/Rakefile4
-rw-r--r--activemodel/activemodel.gemspec2
-rw-r--r--activemodel/lib/active_model/callbacks.rb2
-rw-r--r--activemodel/lib/active_model/errors.rb6
-rw-r--r--activemodel/lib/active_model/mass_assignment_security.rb14
-rw-r--r--activemodel/lib/active_model/mass_assignment_security/permission_set.rb8
-rw-r--r--activemodel/lib/active_model/mass_assignment_security/sanitizer.rb24
-rw-r--r--activemodel/lib/active_model/observer_array.rb6
-rw-r--r--activemodel/lib/active_model/secure_password.rb2
-rw-r--r--activemodel/lib/active_model/serialization.rb2
-rw-r--r--activemodel/lib/active_model/serializers/xml.rb4
-rw-r--r--activemodel/lib/active_model/validations.rb2
-rw-r--r--activemodel/lib/active_model/validations/acceptance.rb2
-rw-r--r--activemodel/lib/active_model/validations/confirmation.rb2
-rw-r--r--activemodel/lib/active_model/validations/exclusion.rb4
-rw-r--r--activemodel/lib/active_model/validations/format.rb4
-rw-r--r--activemodel/lib/active_model/validations/inclusion.rb4
-rw-r--r--activemodel/lib/active_model/validations/length.rb6
-rw-r--r--activemodel/lib/active_model/validations/numericality.rb4
-rw-r--r--activemodel/test/cases/helper.rb1
-rw-r--r--activemodel/test/cases/mass_assignment_security/black_list_test.rb8
-rw-r--r--activemodel/test/cases/mass_assignment_security/sanitizer_test.rb13
-rw-r--r--activemodel/test/cases/mass_assignment_security/white_list_test.rb9
-rw-r--r--activemodel/test/cases/mass_assignment_security_test.rb20
-rw-r--r--activerecord/CHANGELOG8
-rw-r--r--activerecord/README.rdoc2
-rwxr-xr-xactiverecord/Rakefile4
-rw-r--r--activerecord/activerecord.gemspec2
-rw-r--r--activerecord/lib/active_record/aggregations.rb2
-rw-r--r--activerecord/lib/active_record/associations.rb68
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb22
-rw-r--r--activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb4
-rw-r--r--activerecord/lib/active_record/associations/builder/singular_association.rb13
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb24
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb2
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb10
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb2
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb2
-rw-r--r--activerecord/lib/active_record/autosave_association.rb2
-rw-r--r--activerecord/lib/active_record/base.rb48
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb4
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb35
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb8
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb22
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql_adapter.rb25
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb5
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb7
-rw-r--r--activerecord/lib/active_record/counter_cache.rb2
-rw-r--r--activerecord/lib/active_record/fixtures.rb89
-rw-r--r--activerecord/lib/active_record/fixtures/file.rb55
-rw-r--r--activerecord/lib/active_record/locking/pessimistic.rb2
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb12
-rw-r--r--activerecord/lib/active_record/persistence.rb8
-rw-r--r--activerecord/lib/active_record/railtie.rb4
-rw-r--r--activerecord/lib/active_record/railties/controller_runtime.rb4
-rw-r--r--activerecord/lib/active_record/railties/databases.rake8
-rw-r--r--activerecord/lib/active_record/reflection.rb17
-rw-r--r--activerecord/lib/active_record/relation.rb47
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb8
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb2
-rw-r--r--activerecord/lib/active_record/result.rb2
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb2
-rw-r--r--activerecord/lib/active_record/serialization.rb8
-rw-r--r--activerecord/lib/active_record/serializers/xml_serializer.rb2
-rw-r--r--activerecord/lib/active_record/session_store.rb18
-rw-r--r--activerecord/lib/active_record/test_case.rb2
-rw-r--r--activerecord/lib/active_record/validations.rb2
-rw-r--r--activerecord/lib/active_record/validations/associated.rb4
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb4
-rw-r--r--activerecord/test/cases/associations/eager_test.rb58
-rw-r--r--activerecord/test/cases/associations/habtm_join_table_test.rb9
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb10
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb7
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb42
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb9
-rw-r--r--activerecord/test/cases/associations_test.rb12
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb8
-rw-r--r--activerecord/test/cases/base_test.rb7
-rw-r--r--activerecord/test/cases/fixtures/file_test.rb83
-rw-r--r--activerecord/test/cases/fixtures_test.rb6
-rw-r--r--activerecord/test/cases/helper.rb4
-rw-r--r--activerecord/test/cases/json_serialization_test.rb9
-rw-r--r--activerecord/test/cases/migration/command_recorder_test.rb12
-rw-r--r--activerecord/test/cases/reflection_test.rb11
-rw-r--r--activerecord/test/cases/relation_scoping_test.rb8
-rw-r--r--activerecord/test/fixtures/categories_ordered.yml2
-rw-r--r--activerecord/test/fixtures/parrots.yml2
-rw-r--r--activerecord/test/models/author.rb3
-rw-r--r--activerecord/test/models/developer.rb50
-rw-r--r--activerecord/test/models/post.rb6
-rw-r--r--activeresource/README.rdoc24
-rwxr-xr-xactiveresource/Rakefile4
-rw-r--r--activeresource/activeresource.gemspec2
-rw-r--r--activeresource/lib/active_resource/http_mock.rb2
-rw-r--r--activeresource/test/abstract_unit.rb6
-rw-r--r--activesupport/CHANGELOG9
-rw-r--r--activesupport/README.rdoc2
-rwxr-xr-xactivesupport/Rakefile4
-rw-r--r--activesupport/activesupport.gemspec9
-rw-r--r--activesupport/lib/active_support.rb5
-rw-r--r--activesupport/lib/active_support/benchmarkable.rb11
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb2
-rw-r--r--activesupport/lib/active_support/cache/compressed_mem_cache_store.rb13
-rw-r--r--activesupport/lib/active_support/cache/file_store.rb14
-rw-r--r--activesupport/lib/active_support/cache/synchronized_memory_store.rb11
-rw-r--r--activesupport/lib/active_support/core_ext/class.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb178
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/file/atomic.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/kernel.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/agnostics.rb4
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/debugger.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/kernel/requires.rb26
-rw-r--r--activesupport/lib/active_support/core_ext/module.rb1
-rw-r--r--activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb31
-rw-r--r--activesupport/lib/active_support/core_ext/object/blank.rb2
-rw-r--r--activesupport/lib/active_support/dependencies.rb25
-rw-r--r--activesupport/lib/active_support/i18n.rb2
-rw-r--r--activesupport/lib/active_support/json/encoding.rb11
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb1
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb6
-rw-r--r--activesupport/lib/active_support/secure_random.rb6
-rw-r--r--activesupport/lib/active_support/testing/performance/jruby.rb2
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb4
-rw-r--r--activesupport/lib/active_support/xml_mini.rb6
-rw-r--r--activesupport/lib/active_support/xml_mini/jdom.rb21
-rw-r--r--activesupport/test/benchmarkable_test.rb11
-rw-r--r--activesupport/test/caching_test.rb44
-rw-r--r--activesupport/test/class_cache_test.rb43
-rw-r--r--activesupport/test/core_ext/class/class_inheritable_attributes_test.rb230
-rw-r--r--activesupport/test/core_ext/kernel_test.rb46
-rw-r--r--activesupport/test/core_ext/module/attr_accessor_with_default_test.rb39
-rw-r--r--activesupport/test/dependencies_test.rb2
-rw-r--r--activesupport/test/load_paths_test.rb3
-rw-r--r--activesupport/test/message_encryptor_test.rb2
-rw-r--r--activesupport/test/notifications_test.rb2
-rw-r--r--activesupport/test/ordered_hash_test.rb23
-rw-r--r--activesupport/test/secure_random_test.rb19
-rw-r--r--activesupport/test/xml_mini/jdom_engine_test.rb164
-rw-r--r--railties/CHANGELOG7
-rwxr-xr-xrailties/Rakefile4
-rw-r--r--railties/guides/source/3_0_release_notes.textile42
-rw-r--r--railties/guides/source/action_mailer_basics.textile8
-rw-r--r--railties/guides/source/action_view_overview.textile2
-rw-r--r--railties/guides/source/active_record_validations_callbacks.textile151
-rw-r--r--railties/guides/source/active_support_core_extensions.textile14
-rw-r--r--railties/guides/source/asset_pipeline.textile29
-rw-r--r--railties/guides/source/configuring.textile2
-rw-r--r--railties/guides/source/form_helpers.textile2
-rw-r--r--railties/guides/source/getting_started.textile2
-rw-r--r--railties/guides/source/plugins.textile41
-rw-r--r--railties/guides/source/routing.textile2
-rw-r--r--railties/guides/source/ruby_on_rails_guides_guidelines.textile4
-rw-r--r--railties/guides/source/security.textile10
-rw-r--r--railties/lib/rails/application.rb25
-rw-r--r--railties/lib/rails/code_statistics.rb2
-rw-r--r--railties/lib/rails/commands.rb6
-rw-r--r--railties/lib/rails/commands/application.rb1
-rw-r--r--railties/lib/rails/commands/console.rb3
-rw-r--r--railties/lib/rails/commands/destroy.rb2
-rw-r--r--railties/lib/rails/commands/generate.rb2
-rw-r--r--railties/lib/rails/commands/plugin_new.rb5
-rw-r--r--railties/lib/rails/commands/server.rb1
-rw-r--r--railties/lib/rails/configuration.rb6
-rw-r--r--railties/lib/rails/engine.rb8
-rw-r--r--railties/lib/rails/generators.rb22
-rw-r--r--railties/lib/rails/generators/app_base.rb4
-rw-r--r--railties/lib/rails/generators/css/assets/assets_generator.rb13
-rw-r--r--railties/lib/rails/generators/css/assets/templates/stylesheet.css (renamed from railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss)3
-rw-r--r--railties/lib/rails/generators/css/scaffold/scaffold_generator.rb16
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb2
-rw-r--r--railties/lib/rails/generators/rails/app/templates/Gemfile4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb13
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt5
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt6
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt4
-rw-r--r--railties/lib/rails/generators/rails/assets/assets_generator.rb11
-rw-r--r--railties/lib/rails/generators/rails/plugin/USAGE13
-rw-r--r--railties/lib/rails/generators/rails/plugin/plugin_generator.rb54
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt20
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/README.tt13
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt23
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/init.rb1
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/install.rb1
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt1
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt4
-rw-r--r--railties/lib/rails/generators/rails/plugin/templates/uninstall.rb1
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb4
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec5
-rwxr-xr-xrailties/lib/rails/generators/rails/plugin_new/templates/Rakefile11
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb2
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt1
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb13
-rw-r--r--railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss58
-rw-r--r--railties/lib/rails/paths.rb33
-rw-r--r--railties/lib/rails/rack/debugger.rb7
-rw-r--r--railties/lib/rails/railtie.rb14
-rw-r--r--railties/lib/rails/railtie/configuration.rb5
-rw-r--r--railties/lib/rails/tasks/assets.rake2
-rw-r--r--railties/lib/rails/tasks/documentation.rake10
-rw-r--r--railties/lib/rails/tasks/misc.rake4
-rw-r--r--railties/lib/rails/test_help.rb1
-rw-r--r--railties/test/application/console_test.rb7
-rw-r--r--railties/test/application/generators_test.rb6
-rw-r--r--railties/test/application/initializers/notifications_test.rb2
-rw-r--r--railties/test/application/middleware/cache_test.rb4
-rw-r--r--railties/test/application/middleware_test.rb13
-rw-r--r--railties/test/application/paths_test.rb2
-rw-r--r--railties/test/application/rack/logger_test.rb6
-rw-r--r--railties/test/application/rake_test.rb18
-rw-r--r--railties/test/generators/app_generator_test.rb7
-rw-r--r--railties/test/generators/assets_generator_test.rb6
-rw-r--r--railties/test/generators/controller_generator_test.rb2
-rw-r--r--railties/test/generators/generators_test_helper.rb2
-rw-r--r--railties/test/generators/namespaced_generators_test.rb8
-rw-r--r--railties/test/generators/plugin_generator_test.rb71
-rw-r--r--railties/test/generators/plugin_new_generator_test.rb30
-rw-r--r--railties/test/generators/scaffold_generator_test.rb32
-rw-r--r--railties/test/generators_test.rb7
-rw-r--r--railties/test/isolation/abstract_unit.rb3
-rw-r--r--railties/test/paths_test.rb53
-rw-r--r--railties/test/rails_info_controller_test.rb1
-rw-r--r--railties/test/railties/railtie_test.rb4
-rw-r--r--railties/test/railties/shared_tests.rb2
310 files changed, 1813 insertions, 4172 deletions
diff --git a/Gemfile b/Gemfile
index e3cfd12133..b4e85eafd3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,4 @@
-source 'http://rubygems.org'
+source "http://rubygems.org"
gemspec
@@ -32,19 +32,19 @@ end
platforms :mri_19 do
# TODO: Remove the conditional when ruby-debug19 supports Ruby >= 1.9.3
- gem "ruby-debug19", :require => 'ruby-debug' if RUBY_VERSION < "1.9.3"
+ gem "ruby-debug19", :require => "ruby-debug" if RUBY_VERSION < "1.9.3"
end
platforms :ruby do
if ENV["RB_FSEVENT"]
- gem 'rb-fsevent'
+ gem "rb-fsevent"
end
- gem 'json'
- gem 'yajl-ruby'
+ gem "json"
+ gem "yajl-ruby"
gem "nokogiri", ">= 1.4.4"
group :test do
- gem 'ruby-prof'
+ gem "ruby-prof"
end
# AR
gem "sqlite3", "~> 1.3.3"
@@ -75,10 +75,10 @@ end
# gems that are necessary for ActiveRecord tests with Oracle database
if ENV['ORACLE_ENHANCED_PATH'] || ENV['ORACLE_ENHANCED']
platforms :ruby do
- gem 'ruby-oci8', ">= 2.0.4"
+ gem "ruby-oci8", ">= 2.0.4"
end
if ENV['ORACLE_ENHANCED_PATH']
- gem 'activerecord-oracle_enhanced-adapter', :path => ENV['ORACLE_ENHANCED_PATH']
+ gem "activerecord-oracle_enhanced-adapter", :path => ENV['ORACLE_ENHANCED_PATH']
else
gem "activerecord-oracle_enhanced-adapter", :git => "git://github.com/rsim/oracle-enhanced.git"
end
diff --git a/README.rdoc b/README.rdoc
index 143fdfeb75..5abc6f927c 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,30 +1,35 @@
== Welcome to Rails
Rails is a web-application framework that includes everything needed to create
-database-backed web applications according to the Model-View-Control pattern.
-
-This pattern splits the view (also called the presentation) into "dumb"
-templates that are primarily responsible for inserting pre-built data in between
-HTML tags. The model contains the "smart" domain objects (such as Account,
-Product, Person, Post) that holds all the business logic and knows how to
-persist themselves to a database. The controller handles the incoming requests
-(such as Save New Account, Update Product, Show Post) by manipulating the model
-and directing data to the view.
-
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in its
+database-backed web applications according to the Model-View-Controller pattern.
+
+Understanding the MVC pattern is key to understanding Rails. MVC divides your application
+into three layers, each with a specific responsibility.
+
+The View layer is composed of "templates" that are responsible for providing
+appropriate representations of your application's resources. Templates
+can come in a variety of formats, but most view templates are HTML with embedded Ruby
+code (.erb files).
+
+The Model layer represents your domain model (such as Account, Product, Person, Post)
+and encapsulates the business logic that is specific to your application. In Rails,
+database-backed model classes are derived from ActiveRecord::Base. ActiveRecord allows
+you to present the data from database rows as objects and embellish these data objects
+with business logic methods. Although most Rails models are backed by a database, models
+can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as
+provided by the ActiveModel module. You can read more about Active Record in its
{README}[link:files/activerecord/README_rdoc.html].
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in its
-{README}[link:files/actionpack/README_rdoc.html].
+The Controller layer is responsible for handling incoming HTTP requests and providing a
+suitable response. Usually this means returning HTML, but Rails controllers can also
+generate XML, JSON, PDFs, mobile-specific views, and more. Controllers manipulate models
+and render view templates in order to generate the appropriate HTTP response.
+In Rails, the Controller and View layers are handled together by Action Pack.
+These two layers are bundled in a single package due to their heavy interdependence.
+This is unlike the relationship between the Active Record and Action Pack which are
+independent. Each of these packages can be used independently outside of Rails. You
+can read more about Action Pack in its {README}[link:files/actionpack/README_rdoc.html].
== Getting Started
@@ -60,9 +65,10 @@ Rails. You can read more about Action Pack in its
== Contributing
We encourage you to contribute to Ruby on Rails! Please check out the {Contributing to Rails
-guide}[http://edgeguides.rubyonrails.org/contributing_to_rails.html] for guidelines about how
+guide}[http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html] for guidelines about how
to proceed. {Join us}[http://contributors.rubyonrails.org]!
== License
Ruby on Rails is released under the MIT license.
+
diff --git a/actionmailer/README.rdoc b/actionmailer/README.rdoc
index 2806531dfa..63e3893316 100644
--- a/actionmailer/README.rdoc
+++ b/actionmailer/README.rdoc
@@ -153,7 +153,7 @@ Action Mailer is released under the MIT license.
API documentation is at
-* http://api.rubyonrails.com
+* http://api.rubyonrails.org
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
diff --git a/actionmailer/Rakefile b/actionmailer/Rakefile
index df996acbc2..e7d8ee299d 100755
--- a/actionmailer/Rakefile
+++ b/actionmailer/Rakefile
@@ -1,7 +1,7 @@
#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
desc "Default Task"
task :default => [ :test ]
@@ -24,7 +24,7 @@ end
spec = eval(File.read('actionmailer.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb
index b9e682b711..9bd73dd740 100644
--- a/actionmailer/lib/action_mailer.rb
+++ b/actionmailer/lib/action_mailer.rb
@@ -40,12 +40,10 @@ require 'active_support/lazy_load_hooks'
module ActionMailer
extend ::ActiveSupport::Autoload
- autoload :AdvAttrAccessor
autoload :Collector
autoload :Base
autoload :DeliveryMethods
autoload :MailHelper
- autoload :OldApi
autoload :TestCase
autoload :TestHelper
end
diff --git a/actionmailer/lib/action_mailer/adv_attr_accessor.rb b/actionmailer/lib/action_mailer/adv_attr_accessor.rb
deleted file mode 100644
index c1aa8021ce..0000000000
--- a/actionmailer/lib/action_mailer/adv_attr_accessor.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-module ActionMailer
- module AdvAttrAccessor #:nodoc:
- def adv_attr_accessor(name, deprecation=nil)
- ivar = "@#{name}"
- deprecation ||= "Please pass :#{name} as hash key to mail() instead"
-
- class_eval <<-ACCESSORS, __FILE__, __LINE__ + 1
- def #{name}=(value)
- ActiveSupport::Deprecation.warn "#{name}= is deprecated. #{deprecation}"
- #{ivar} = value
- end
-
- def #{name}(*args)
- raise ArgumentError, "expected 0 or 1 parameters" unless args.length <= 1
- if args.empty?
- ActiveSupport::Deprecation.warn "#{name}() is deprecated and will be removed in future versions."
- #{ivar} if instance_variable_names.include?(#{ivar.inspect})
- else
- ActiveSupport::Deprecation.warn "#{name}(value) is deprecated. #{deprecation}"
- #{ivar} = args.first
- end
- end
- ACCESSORS
-
- self.protected_instance_variables << ivar if self.respond_to?(:protected_instance_variables)
- end
- end
-end
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index f00a0c8ae0..3afdbea42a 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -1,5 +1,4 @@
require 'mail'
-require 'action_mailer/tmail_compat'
require 'action_mailer/collector'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
@@ -23,16 +22,16 @@ module ActionMailer #:nodoc:
#
# Examples:
#
- # class Notifier < ActionMailer::Base
- # default :from => 'no-reply@example.com',
+ # class Notifier < ActionMailer::Base
+ # default :from => 'no-reply@example.com',
# :return_path => 'system@example.com'
#
- # def welcome(recipient)
- # @account = recipient
- # mail(:to => recipient.email_address_with_name,
- # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
- # end
- # end
+ # def welcome(recipient)
+ # @account = recipient
+ # mail(:to => recipient.email_address_with_name,
+ # :bcc => ["bcc@example.com", "Order Watcher <watcher@example.com>"])
+ # end
+ # end
#
# Within the mailer method, you have access to the following methods:
#
@@ -131,9 +130,6 @@ module ActionMailer #:nodoc:
#
# config.action_mailer.default_url_options = { :host => "example.com" }
#
- # Setting <tt>ActionMailer::Base.default_url_options</tt> directly is now deprecated, use the configuration
- # option mentioned above to set the default host.
- #
# If you do decide to set a default <tt>:host</tt> for your mailers you want to use the
# <tt>:only_path => false</tt> option when using <tt>url_for</tt>. This will ensure that absolute URLs are
# generated because the <tt>url_for</tt> view helper will, by default, generate relative URLs when a
@@ -216,7 +212,7 @@ module ActionMailer #:nodoc:
#
# = Observing and Intercepting Mails
#
- # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
+ # Action Mailer provides hooks into the Mail observer and interceptor methods. These allow you to
# register objects that are called during the mail delivery life cycle.
#
# An observer object must implement the <tt>:delivered_email(message)</tt> method which will be
@@ -224,7 +220,7 @@ module ActionMailer #:nodoc:
#
# An interceptor object must implement the <tt>:delivering_email(message)</tt> method which will be
# called before the email is sent, allowing you to make modifications to the email before it hits
- # the delivery agents. Your object should make any needed modifications directly to the passed
+ # the delivery agents. Your object should make any needed modifications directly to the passed
# in Mail::Message instance.
#
# = Default Hash
@@ -297,9 +293,9 @@ module ActionMailer #:nodoc:
# information and a cryptographic Message Digest 5 algorithm to hash important information)
# * <tt>:enable_starttls_auto</tt> - When set to true, detects if STARTTLS is enabled in your SMTP server
# and starts to use it.
- # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is
- # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name
- # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the
+ # * <tt>:openssl_verify_mode</tt> - When using TLS, you can set how OpenSSL checks the certificate. This is
+ # really useful if you need to validate a self-signed and/or a wildcard certificate. You can use the name
+ # of an OpenSSL verify constant ('none', 'peer', 'client_once','fail_if_no_peer_cert') or directly the
# constant (OpenSSL::SSL::VERIFY_NONE, OpenSSL::SSL::VERIFY_PEER,...).
#
# * <tt>sendmail_settings</tt> - Allows you to override options for the <tt>:sendmail</tt> delivery method.
@@ -315,29 +311,16 @@ module ActionMailer #:nodoc:
#
# * <tt>delivery_method</tt> - Defines a delivery method. Possible values are <tt>:smtp</tt> (default),
# <tt>:sendmail</tt>, <tt>:test</tt>, and <tt>:file</tt>. Or you may provide a custom delivery method
- # object eg. MyOwnDeliveryMethodClass.new. See the Mail gem documentation on the interface you need to
+ # object eg. MyOwnDeliveryMethodClass.new. See the Mail gem documentation on the interface you need to
# implement for a custom delivery agent.
#
# * <tt>perform_deliveries</tt> - Determines whether emails are actually sent from Action Mailer when you
- # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can
+ # call <tt>.deliver</tt> on an mail message or on an Action Mailer method. This is on by default but can
# be turned off to aid in functional testing.
#
# * <tt>deliveries</tt> - Keeps an array of all the emails sent out through the Action Mailer with
# <tt>delivery_method :test</tt>. Most useful for unit and functional testing.
#
- # * <tt>default_charset</tt> - This is now deprecated, use the +default+ method above to
- # set the default +:charset+.
- #
- # * <tt>default_content_type</tt> - This is now deprecated, use the +default+ method above
- # to set the default +:content_type+.
- #
- # * <tt>default_mime_version</tt> - This is now deprecated, use the +default+ method above
- # to set the default +:mime_version+.
- #
- # * <tt>default_implicit_parts_order</tt> - This is now deprecated, use the +default+ method above
- # to set the default +:parts_order+. Parts Order is used when a message is built implicitly
- # (i.e. multiple parts are assembled from templates which specify the content type in their
- # filenames) this variable controls how the parts are ordered.
class Base < AbstractController::Base
include DeliveryMethods
abstract!
@@ -352,7 +335,6 @@ module ActionMailer #:nodoc:
self.protected_instance_variables = %w(@_action_has_layout)
helper ActionMailer::MailHelper
- include ActionMailer::OldApi
private_class_method :new #:nodoc:
@@ -384,7 +366,7 @@ module ActionMailer #:nodoc:
end
# Register an Inteceptor which will be called before mail is sent.
- # Either a class or a string can be passed in as the Observer. If a string is passed in
+ # Either a class or a string can be passed in as the Interceptor. If a string is passed in
# it will be <tt>constantize</tt>d.
def register_interceptor(interceptor)
delivery_interceptor = (interceptor.is_a?(String) ? interceptor.constantize : interceptor)
@@ -567,8 +549,8 @@ module ActionMailer #:nodoc:
# method.
#
# When a <tt>:return_path</tt> is specified as header, that value will be used as the 'envelope from'
- # address for the Mail message. Setting this is useful when you want delivery notifications
- # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
+ # address for the Mail message. Setting this is useful when you want delivery notifications
+ # sent to a different address than the one in <tt>:from</tt>. Mail will actually use the
# <tt>:return_path</tt> in preference to the <tt>:sender</tt> in preference to the <tt>:from</tt>
# field for the 'envelope from' value.
#
diff --git a/actionmailer/lib/action_mailer/old_api.rb b/actionmailer/lib/action_mailer/old_api.rb
deleted file mode 100644
index bfa9499764..0000000000
--- a/actionmailer/lib/action_mailer/old_api.rb
+++ /dev/null
@@ -1,255 +0,0 @@
-require 'active_support/concern'
-require 'active_support/core_ext/object/try'
-require 'active_support/core_ext/object/blank'
-
-module ActionMailer
- module OldApi #:nodoc:
- extend ActiveSupport::Concern
-
- included do
- extend ActionMailer::AdvAttrAccessor
- self.protected_instance_variables.concat %w(@parts @mail_was_called @headers)
-
- # Specify the BCC addresses for the message
- adv_attr_accessor :bcc
-
- # Specify the CC addresses for the message.
- adv_attr_accessor :cc
-
- # Specify the charset to use for the message. This defaults to the
- # +default_charset+ specified for ActionMailer::Base.
- adv_attr_accessor :charset
-
- # Specify the content type for the message. This defaults to <tt>text/plain</tt>
- # in most cases, but can be automatically set in some situations.
- adv_attr_accessor :content_type
-
- # Specify the from address for the message.
- adv_attr_accessor :from
-
- # Specify the address (if different than the "from" address) to direct
- # replies to this message.
- adv_attr_accessor :reply_to
-
- # Specify the order in which parts should be sorted, based on content-type.
- # This defaults to the value for the +default_implicit_parts_order+.
- adv_attr_accessor :implicit_parts_order
-
- # Defaults to "1.0", but may be explicitly given if needed.
- adv_attr_accessor :mime_version
-
- # The recipient addresses for the message, either as a string (for a single
- # address) or an array (for multiple addresses).
- adv_attr_accessor :recipients, "Please pass :to as hash key to mail() instead"
-
- # The date on which the message was sent. If not set (the default), the
- # header will be set by the delivery agent.
- adv_attr_accessor :sent_on, "Please pass :date as hash key to mail() instead"
-
- # Specify the subject of the message.
- adv_attr_accessor :subject
-
- # Specify the template name to use for current message. This is the "base"
- # template name, without the extension or directory, and may be used to
- # have multiple mailer methods share the same template.
- adv_attr_accessor :template, "Please pass :template_name or :template_path as hash key to mail() instead"
-
- # Define the body of the message. This is either a Hash (in which case it
- # specifies the variables to pass to the template when it is rendered),
- # or a string, in which case it specifies the actual text of the message.
- adv_attr_accessor :body
- end
-
- def process(method_name, *args)
- initialize_defaults(method_name)
- super
- unless @mail_was_called
- create_parts
- create_mail
- end
- @_message
- end
-
- # Add a part to a multipart message, with the given content-type. The
- # part itself is yielded to the block so that other properties (charset,
- # body, headers, etc.) can be set on it.
- def part(params)
- ActiveSupport::Deprecation.warn "part() is deprecated and will be removed in future versions. " <<
- "Please pass a block to mail() instead."
- params = {:content_type => params} if String === params
-
- if custom_headers = params.delete(:headers)
- params.merge!(custom_headers)
- end
-
- part = Mail::Part.new(params)
-
- yield part if block_given?
- @parts << part
- end
-
- # Add an attachment to a multipart message. This is simply a part with the
- # content-disposition set to "attachment".
- def attachment(params, &block)
- ActiveSupport::Deprecation.warn "attachment() is deprecated and will be removed in future versions. " <<
- "Please use the attachments[] API instead."
- params = { :content_type => params } if String === params
-
- params[:content] ||= params.delete(:data) || params.delete(:body)
-
- if params[:filename]
- params = normalize_file_hash(params)
- else
- params = normalize_nonfile_hash(params)
- end
-
- part(params, &block)
- end
-
- protected
-
- def normalize_nonfile_hash(params)
- content_disposition = "attachment;"
-
- mime_type = params.delete(:mime_type)
-
- if content_type = params.delete(:content_type)
- content_type = "#{mime_type || content_type};"
- end
-
- params[:body] = params.delete(:data) if params[:data]
-
- { :content_type => content_type,
- :content_disposition => content_disposition }.merge(params)
- end
-
- def normalize_file_hash(params)
- filename = File.basename(params.delete(:filename))
- content_disposition = "attachment; filename=\"#{File.basename(filename)}\""
-
- mime_type = params.delete(:mime_type)
-
- if (content_type = params.delete(:content_type)) && (content_type !~ /filename=/)
- content_type = "#{mime_type || content_type}; filename=\"#{filename}\""
- end
-
- params[:body] = params.delete(:data) if params[:data]
-
- { :content_type => content_type,
- :content_disposition => content_disposition }.merge(params)
- end
-
- def create_mail
- m = @_message
-
- set_fields!({:subject => @subject, :to => @recipients, :from => @from,
- :bcc => @bcc, :cc => @cc, :reply_to => @reply_to}, @charset)
-
- m.mime_version = @mime_version if @mime_version
- m.date = @sent_on.to_time rescue @sent_on if @sent_on
-
- @headers.each { |k, v| m[k] = v }
-
- real_content_type, ctype_attrs = parse_content_type
- main_type, sub_type = split_content_type(real_content_type)
-
- if @parts.size == 1 && @parts.first.parts.empty?
- m.content_type([main_type, sub_type, ctype_attrs])
- m.body = @parts.first.body.encoded
- else
- @parts.each do |p|
- m.add_part(p)
- end
-
- m.body.set_sort_order(@implicit_parts_order)
- m.body.sort_parts!
-
- if real_content_type =~ /multipart/
- ctype_attrs.delete "charset"
- m.content_type([main_type, sub_type, ctype_attrs])
- end
- end
-
- wrap_delivery_behavior!
- m.content_transfer_encoding = '8bit' unless m.body.only_us_ascii?
-
- @_message
- end
-
- # Set up the default values for the various instance variables of this
- # mailer. Subclasses may override this method to provide different
- # defaults.
- def initialize_defaults(method_name)
- @charset ||= self.class.default[:charset].try(:dup)
- @content_type ||= self.class.default[:content_type].try(:dup)
- @implicit_parts_order ||= self.class.default[:parts_order].try(:dup)
- @mime_version ||= self.class.default[:mime_version].try(:dup)
-
- @cc, @bcc, @reply_to, @subject, @from, @recipients = nil, nil, nil, nil, nil, nil
-
- @mailer_name ||= self.class.mailer_name.dup
- @template ||= method_name
- @mail_was_called = false
-
- @parts ||= []
- @headers ||= {}
- @sent_on ||= Time.now
- @body ||= {}
- end
-
- def create_parts
- if String === @body
- @parts.unshift create_inline_part(@body)
- elsif @parts.empty? || @parts.all? { |p| p.content_disposition =~ /^attachment/ }
- lookup_context.find_all(@template, [@mailer_name]).each do |template|
- self.formats = template.formats
- @parts << create_inline_part(render(:template => template), template.mime_type)
- end
-
- if @parts.size > 1
- @content_type = "multipart/alternative" if @content_type !~ /^multipart/
- end
-
- # If this is a multipart e-mail add the mime_version if it is not
- # already set.
- @mime_version ||= "1.0" unless @parts.empty?
- end
- end
-
- def create_inline_part(body, mime_type=nil)
- ct = mime_type || "text/plain"
- main_type, sub_type = split_content_type(ct.to_s)
-
- Mail::Part.new(
- :content_type => [main_type, sub_type, {:charset => charset}],
- :content_disposition => "inline",
- :body => body
- )
- end
-
- def set_fields!(headers, charset) #:nodoc:
- m = @_message
- m.charset = charset
- m.subject ||= headers.delete(:subject) if headers[:subject]
- m.to ||= headers.delete(:to) if headers[:to]
- m.from ||= headers.delete(:from) if headers[:from]
- m.cc ||= headers.delete(:cc) if headers[:cc]
- m.bcc ||= headers.delete(:bcc) if headers[:bcc]
- m.reply_to ||= headers.delete(:reply_to) if headers[:reply_to]
- end
-
- def split_content_type(ct)
- ct.to_s.split("/")
- end
-
- def parse_content_type
- if @content_type.blank?
- [ nil, {} ]
- else
- ctype, *attrs = @content_type.split(/;\s*/)
- attrs = Hash[attrs.map { |attr| attr.split(/=/, 2) }]
- [ctype, {"charset" => @charset}.merge!(attrs)]
- end
- end
- end
-end
diff --git a/actionmailer/lib/action_mailer/tmail_compat.rb b/actionmailer/lib/action_mailer/tmail_compat.rb
deleted file mode 100644
index 1b2cdcfb27..0000000000
--- a/actionmailer/lib/action_mailer/tmail_compat.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-module Mail
- class Message
-
- def set_content_type(*args)
- message = 'Message#set_content_type is deprecated, please just call ' <<
- 'Message#content_type with the same arguments'
- ActiveSupport::Deprecation.warn(message, caller[0,2])
- content_type(*args)
- end
-
- alias :old_transfer_encoding :transfer_encoding
- def transfer_encoding(value = nil)
- if value
- message = 'Message#transfer_encoding is deprecated, ' <<
- 'please call Message#content_transfer_encoding with the same arguments'
- ActiveSupport::Deprecation.warn(message, caller[0,2])
- content_transfer_encoding(value)
- else
- old_transfer_encoding
- end
- end
-
- def transfer_encoding=(value)
- message = 'Message#transfer_encoding= is deprecated, ' <<
- 'please call Message#content_transfer_encoding= with the same arguments'
- ActiveSupport::Deprecation.warn(message, caller[0,2])
- self.content_transfer_encoding = value
- end
-
- def original_filename
- message = 'Message#original_filename is deprecated, please call Message#filename'
- ActiveSupport::Deprecation.warn(message, caller[0,2])
- filename
- end
-
- end
-end
diff --git a/actionmailer/test/log_subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb
index ba9b4d6500..5f52a1bd69 100644
--- a/actionmailer/test/log_subscriber_test.rb
+++ b/actionmailer/test/log_subscriber_test.rb
@@ -1,4 +1,5 @@
require "abstract_unit"
+require 'mailers/base_mailer'
require "active_support/log_subscriber/test_helper"
require "action_mailer/log_subscriber"
@@ -11,13 +12,6 @@ class AMLogSubscriberTest < ActionMailer::TestCase
end
class TestMailer < ActionMailer::Base
- def basic
- recipients "somewhere@example.com"
- subject "basic"
- from "basic@example.com"
- body "Hello world"
- end
-
def receive(mail)
# Do nothing
end
@@ -28,12 +22,12 @@ class AMLogSubscriberTest < ActionMailer::TestCase
end
def test_deliver_is_notified
- TestMailer.basic.deliver
+ BaseMailer.welcome.deliver
wait
assert_equal(1, @logger.logged(:info).size)
- assert_match(/Sent mail to somewhere@example.com/, @logger.logged(:info).first)
+ assert_match(/Sent mail to system@test.lindsaar.net/, @logger.logged(:info).first)
assert_equal(1, @logger.logged(:debug).size)
- assert_match(/Hello world/, @logger.logged(:debug).first)
+ assert_match(/Welcome/, @logger.logged(:debug).first)
end
def test_receive_is_notified
diff --git a/actionmailer/test/old_base/adv_attr_test.rb b/actionmailer/test/old_base/adv_attr_test.rb
deleted file mode 100644
index c5a6b6d88b..0000000000
--- a/actionmailer/test/old_base/adv_attr_test.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require 'abstract_unit'
-require 'action_mailer/adv_attr_accessor'
-
-class AdvAttrTest < ActiveSupport::TestCase
- class Person
- cattr_reader :protected_instance_variables
- @@protected_instance_variables = []
-
- extend ActionMailer::AdvAttrAccessor
- adv_attr_accessor :name
- end
-
- def setup
- ActiveSupport::Deprecation.silenced = true
- @person = Person.new
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- end
-
- def test_adv_attr
- assert_nil @person.name
- @person.name 'Bob'
- assert_equal 'Bob', @person.name
- end
-
- def test_adv_attr_writer
- assert_nil @person.name
- @person.name = 'Bob'
- assert_equal 'Bob', @person.name
- end
-
- def test_raise_an_error_with_multiple_args
- assert_raise(ArgumentError) { @person.name('x', 'y') }
- end
-
- def test_ivar_is_added_to_protected_instnace_variables
- assert Person.protected_instance_variables.include?('@name')
- end
-end
diff --git a/actionmailer/test/old_base/mail_render_test.rb b/actionmailer/test/old_base/mail_render_test.rb
deleted file mode 100644
index 3a1d3184f4..0000000000
--- a/actionmailer/test/old_base/mail_render_test.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-require 'abstract_unit'
-
-class RenderMailer < ActionMailer::Base
- def inline_template
- recipients 'test@localhost'
- subject "using helpers"
- from "tester@example.com"
-
- @world = "Earth"
- body render(:inline => "Hello, <%= @world %>")
- end
-
- def file_template
- recipients 'test@localhost'
- subject "using helpers"
- from "tester@example.com"
-
- @recipient = 'test@localhost'
- body render(:file => "templates/signed_up")
- end
-
- def no_instance_variable
- recipients 'test@localhost'
- subject "No Instance Variable"
- from "tester@example.com"
-
- silence_warnings do
- body render(:inline => "Look, subject.nil? is <%= @subject.nil? %>!")
- end
- end
-
- def multipart_alternative
- recipients 'test@localhost'
- subject 'multipart/alternative'
- from 'tester@example.com'
-
- build_multipart_message(:foo => "bar")
- end
-
- private
- def build_multipart_message(assigns = {})
- content_type "multipart/alternative"
-
- part "text/plain" do |p|
- p.body = build_body_part('plain', assigns, :layout => false)
- end
-
- part "text/html" do |p|
- p.body = build_body_part('html', assigns)
- end
- end
-
- def build_body_part(content_type, assigns, options = {})
- ActiveSupport::Deprecation.silence do
- render "#{template}.#{content_type}", :body => assigns
- end
- end
-end
-
-class FirstMailer < ActionMailer::Base
- def share
- recipients 'test@localhost'
- subject "using helpers"
- from "tester@example.com"
- end
-end
-
-class SecondMailer < ActionMailer::Base
- def share
- recipients 'test@localhost'
- subject "using helpers"
- from "tester@example.com"
- end
-end
-
-# CHANGED: Those tests were changed because body returns an object now
-# Instead of mail.body.strip, we should mail.body.to_s.strip
-class RenderHelperTest < Test::Unit::TestCase
- def setup
- set_delivery_method :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries.clear
- ActiveSupport::Deprecation.silenced = true
-
- @recipient = 'test@localhost'
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- restore_delivery_method
- end
-
- def test_inline_template
- mail = RenderMailer.inline_template
- assert_equal "Hello, Earth", mail.body.to_s.strip
- end
-
- def test_file_template
- mail = RenderMailer.file_template
- assert_equal "Hello there,\n\nMr. test@localhost", mail.body.to_s.strip
- end
-
- def test_no_instance_variable
- mail = RenderMailer.no_instance_variable.deliver
- assert_equal "Look, subject.nil? is true!", mail.body.to_s.strip
- end
-end
-
-class FirstSecondHelperTest < Test::Unit::TestCase
- def setup
- set_delivery_method :test
- ActiveSupport::Deprecation.silenced = true
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.deliveries.clear
-
- @recipient = 'test@localhost'
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- restore_delivery_method
- end
-
- def test_ordering
- mail = FirstMailer.share
- assert_equal "first mail", mail.body.to_s.strip
- mail = SecondMailer.share
- assert_equal "second mail", mail.body.to_s.strip
- mail = FirstMailer.share
- assert_equal "first mail", mail.body.to_s.strip
- mail = SecondMailer.share
- assert_equal "second mail", mail.body.to_s.strip
- end
-end
diff --git a/actionmailer/test/old_base/mail_service_test.rb b/actionmailer/test/old_base/mail_service_test.rb
deleted file mode 100644
index 0b5b0b2da3..0000000000
--- a/actionmailer/test/old_base/mail_service_test.rb
+++ /dev/null
@@ -1,1097 +0,0 @@
-# encoding: utf-8
-require 'abstract_unit'
-
-class FunkyPathMailer < ActionMailer::Base
- self.view_paths = "#{File.dirname(__FILE__)}/../fixtures/path.with.dots"
-
- def multipart_with_template_path_with_dots(recipient)
- recipients recipient
- subject "This path has dots"
- from "Chad Fowler <chad@chadfowler.com>"
- attachment :content_type => "text/plain",
- :data => "dots dots dots..."
- end
-end
-
-class TestMailer < ActionMailer::Base
- def signed_up(recipient)
- recipients recipient
- subject "[Signed up] Welcome #{recipient}"
- from "system@loudthinking.com"
-
- @recipient = recipient
- end
-
- def cancelled_account(recipient)
- recipients recipient
- subject "[Cancelled] Goodbye #{recipient}"
- from "system@loudthinking.com"
- sent_on Time.local(2004, 12, 12)
- body "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"
- from "system@loudthinking.com"
- sent_on Time.local(2004, 12, 12)
- cc "nobody@loudthinking.com"
- bcc "root@loudthinking.com"
-
- body "Nothing to see here."
- end
-
- def different_reply_to(recipient)
- recipients recipient
- subject "testing reply_to"
- from "system@loudthinking.com"
- sent_on Time.local(2008, 5, 23)
- reply_to "atraver@gmail.com"
-
- body "Nothing to see here."
- end
-
- def iso_charset(recipient)
- recipients recipient
- subject "testing isø charsets"
- from "system@loudthinking.com"
- sent_on Time.local(2004, 12, 12)
- cc "nobody@loudthinking.com"
- bcc "root@loudthinking.com"
- charset "iso-8859-1"
-
- body "Nothing to see here."
- end
-
- def unencoded_subject(recipient)
- recipients recipient
- subject "testing unencoded subject"
- from "system@loudthinking.com"
- sent_on Time.local(2004, 12, 12)
- cc "nobody@loudthinking.com"
- bcc "root@loudthinking.com"
-
- body "Nothing to see here."
- end
-
- def extended_headers(recipient)
- recipients recipient
- subject "testing extended headers"
- from "Grytøyr <stian1@example.net>"
- sent_on Time.local(2004, 12, 12)
- cc "Grytøyr <stian2@example.net>"
- bcc "Grytøyr <stian3@example.net>"
- charset "iso-8859-1"
-
- body "Nothing to see here."
- end
-
- def utf8_body(recipient)
- recipients recipient
- subject "testing utf-8 body"
- from "Foo áëô îü <extended@example.net>"
- sent_on Time.local(2004, 12, 12)
- cc "Foo áëô îü <extended@example.net>"
- bcc "Foo áëô îü <extended@example.net>"
- charset "UTF-8"
-
- body "åœö blah"
- end
-
- def multipart_with_mime_version(recipient)
- recipients recipient
- subject "multipart with mime_version"
- from "test@example.com"
- sent_on Time.local(2004, 12, 12)
- mime_version "1.1"
- content_type "multipart/alternative"
-
- part "text/plain" do |p|
- p.body = render(:text => "blah")
- end
-
- part "text/html" do |p|
- p.body = render(:inline => "<%= content_tag(:b, 'blah') %>")
- end
- end
-
- def multipart_with_utf8_subject(recipient)
- recipients recipient
- subject "Foo áëô îü"
- from "test@example.com"
- charset "UTF-8"
-
- part "text/plain" do |p|
- p.body = "blah"
- end
-
- part "text/html" do |p|
- p.body = "<b>blah</b>"
- end
- end
-
- def explicitly_multipart_example(recipient, ct=nil)
- recipients recipient
- subject "multipart example"
- from "test@example.com"
- sent_on Time.local(2004, 12, 12)
- content_type ct if ct
-
- part "text/html" do |p|
- p.charset = "iso-8859-1"
- p.body = "blah"
- end
-
- attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "foo.jpg"),
- :data => "123456789"
-
- body "plain text default"
- end
-
- def implicitly_multipart_example(recipient, cs = nil, order = nil)
- recipients recipient
- subject "multipart example"
- from "test@example.com"
- sent_on Time.local(2004, 12, 12)
-
- @charset = cs if cs
- @recipient = recipient
- @implicit_parts_order = order if order
- end
-
- def implicitly_multipart_with_utf8
- recipients "no.one@nowhere.test"
- subject "Foo áëô îü"
- from "some.one@somewhere.test"
- template "implicitly_multipart_example"
-
- @recipient = "no.one@nowhere.test"
- end
-
- def html_mail(recipient)
- recipients recipient
- subject "html mail"
- from "test@example.com"
- content_type "text/html"
-
- body "<em>Emphasize</em> <strong>this</strong>"
- end
-
- def html_mail_with_underscores(recipient)
- subject "html mail with underscores"
- body %{<a href="http://google.com" target="_blank">_Google</a>}
- end
-
- def custom_template(recipient)
- recipients recipient
- subject "[Signed up] Welcome #{recipient}"
- from "system@loudthinking.com"
- sent_on Time.local(2004, 12, 12)
- template "signed_up"
-
- @recipient = recipient
- end
-
- def custom_templating_extension(recipient)
- recipients recipient
- subject "[Signed up] Welcome #{recipient}"
- from "system@loudthinking.com"
- sent_on Time.local(2004, 12, 12)
-
- @recipient = recipient
- end
-
- def various_newlines(recipient)
- recipients recipient
- subject "various newlines"
- from "test@example.com"
-
- body "line #1\nline #2\rline #3\r\nline #4\r\r" +
- "line #5\n\nline#6\r\n\r\nline #7"
- end
-
- def various_newlines_multipart(recipient)
- recipients recipient
- subject "various newlines multipart"
- from "test@example.com"
- content_type "multipart/alternative"
-
- part :content_type => "text/plain", :body => "line #1\nline #2\rline #3\r\nline #4\r\r"
- part :content_type => "text/html", :body => "<p>line #1</p>\n<p>line #2</p>\r<p>line #3</p>\r\n<p>line #4</p>\r\r"
- end
-
- def nested_multipart(recipient)
- recipients recipient
- subject "nested multipart"
- from "test@example.com"
- content_type "multipart/mixed"
-
- part :content_type => "multipart/alternative", :content_disposition => "inline", "foo" => "bar" do |p|
- p.part :content_type => "text/plain", :body => "test text\nline #2"
- p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>\nline #2"
- end
-
- attachment :content_type => "application/octet-stream", :filename => "test.txt", :data => "test abcdefghijklmnopqstuvwxyz"
- end
-
- def nested_multipart_with_body(recipient)
- recipients recipient
- subject "nested multipart with body"
- from "test@example.com"
- content_type "multipart/mixed"
-
- part :content_type => "multipart/alternative", :content_disposition => "inline", :body => "Nothing to see here." do |p|
- p.part :content_type => "text/html", :body => "<b>test</b> HTML<br/>"
- end
- end
-
- def attachment_with_custom_header(recipient)
- recipients recipient
- subject "custom header in attachment"
- from "test@example.com"
- content_type "multipart/related"
- part :content_type => "text/html", :body => 'yo'
- attachment :content_type => "image/jpeg", :filename => File.join(File.dirname(__FILE__), "fixtures", "attachments", "test.jpg"), :data => "i am not a real picture", 'Content-ID' => '<test@test.com>'
- end
-
- def unnamed_attachment(recipient)
- recipients recipient
- subject "nested multipart"
- from "test@example.com"
- content_type "multipart/mixed"
- part :content_type => "text/plain", :body => "hullo"
- attachment :content_type => "application/octet-stream", :data => "test abcdefghijklmnopqstuvwxyz"
- end
-
- def headers_with_nonalpha_chars(recipient)
- recipients recipient
- subject "nonalpha chars"
- from "One: Two <test@example.com>"
- cc "Three: Four <test@example.com>"
- bcc "Five: Six <test@example.com>"
- body "testing"
- end
-
- def custom_content_type_attributes
- recipients "no.one@nowhere.test"
- subject "custom content types"
- from "some.one@somewhere.test"
- content_type "text/plain; format=flowed"
- body "testing"
- end
-
- def return_path
- recipients "no.one@nowhere.test"
- subject "return path test"
- from "some.one@somewhere.test"
- headers["return-path"] = "another@somewhere.test"
- body "testing"
- end
-
- def subject_with_i18n(recipient)
- recipients recipient
- from "system@loudthinking.com"
- body "testing"
- end
-
- class << self
- attr_accessor :received_body
- end
-
- def receive(mail)
- self.class.received_body = mail.body
- end
-end
-
-class ActionMailerTest < Test::Unit::TestCase
-
- def encode( text, charset="UTF-8" )
- Mail::Encodings.q_value_encode( text, charset )
- end
-
- def new_mail( charset="UTF-8" )
- mail = Mail.new
- mail.charset = charset
- mail.mime_version = "1.0"
- mail
- end
-
- def setup
- set_delivery_method :test
- ActionMailer::Base.perform_deliveries = true
- ActionMailer::Base.raise_delivery_errors = true
- ActionMailer::Base.deliveries.clear
- ActiveSupport::Deprecation.silenced = true
-
- @recipient = 'test@localhost'
-
- TestMailer.delivery_method = :test
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- restore_delivery_method
- end
-
- def test_nested_parts
- created = nil
- assert_nothing_raised { created = TestMailer.nested_multipart(@recipient)}
- assert_equal 2, created.parts.size
- assert_equal 2, created.parts.first.parts.size
-
- assert_equal "multipart/mixed", created.mime_type
- assert_equal "multipart/alternative", created.parts[0].mime_type
- assert_equal "bar", created.parts[0].header['foo'].to_s
- assert_not_nil created.parts[0].charset
- assert_equal "text/plain", created.parts[0].parts[0].mime_type
- assert_equal "text/html", created.parts[0].parts[1].mime_type
- assert_equal "application/octet-stream", created.parts[1].mime_type
-
- end
-
- def test_nested_parts_with_body
- created = nil
- TestMailer.nested_multipart_with_body(@recipient)
- assert_nothing_raised { created = TestMailer.nested_multipart_with_body(@recipient)}
-
- assert_equal 1,created.parts.size
- assert_equal 2,created.parts.first.parts.size
-
- assert_equal "multipart/mixed", created.mime_type
- assert_equal "multipart/alternative", created.parts.first.mime_type
- assert_equal "text/plain", created.parts.first.parts.first.mime_type
- assert_equal "Nothing to see here.", created.parts.first.parts.first.body.to_s
- assert_equal "text/html", created.parts.first.parts.second.mime_type
- assert_equal "<b>test</b> HTML<br/>", created.parts.first.parts.second.body.to_s
- end
-
- def test_attachment_with_custom_header
- created = nil
- assert_nothing_raised { created = TestMailer.attachment_with_custom_header(@recipient) }
- assert created.parts.any? { |p| p.header['content-id'].to_s == "<test@test.com>" }
- end
-
- def test_signed_up
- TestMailer.delivery_method = :test
-
- Time.stubs(:now => Time.now)
-
- expected = new_mail
- expected.to = @recipient
- expected.subject = "[Signed up] Welcome #{@recipient}"
- expected.body = "Hello there,\n\nMr. #{@recipient}"
- expected.from = "system@loudthinking.com"
- expected.date = Time.now
-
- created = nil
- assert_nothing_raised { created = TestMailer.signed_up(@recipient) }
- assert_not_nil created
-
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
-
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
-
- delivered = ActionMailer::Base.deliveries.first
- assert_not_nil delivered
-
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_custom_template
- expected = new_mail
- expected.to = @recipient
- expected.subject = "[Signed up] Welcome #{@recipient}"
- expected.body = "Hello there,\n\nMr. #{@recipient}"
- expected.from = "system@loudthinking.com"
- expected.date = Time.local(2004, 12, 12)
-
- created = nil
- assert_nothing_raised { created = TestMailer.custom_template(@recipient) }
- assert_not_nil created
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
- assert_equal expected.encoded, created.encoded
- end
-
- def test_custom_templating_extension
- assert ActionView::Template.template_handler_extensions.include?("haml"), "haml extension was not registered"
-
- # N.b., custom_templating_extension.text.plain.haml is expected to be in fixtures/test_mailer directory
- expected = new_mail
- expected.to = @recipient
- expected.subject = "[Signed up] Welcome #{@recipient}"
- expected.body = "Hello there, \n\nMr. #{@recipient}"
- expected.from = "system@loudthinking.com"
- expected.date = Time.local(2004, 12, 12)
-
- # Now that the template is registered, there should be one part. The text/plain part.
- created = nil
- assert_nothing_raised { created = TestMailer.custom_templating_extension(@recipient) }
- assert_not_nil created
- assert_equal 2, created.parts.length
- assert_equal 'text/plain', created.parts[0].mime_type
- assert_equal 'text/html', created.parts[1].mime_type
- end
-
- def test_cancelled_account
- expected = new_mail
- expected.to = @recipient
- expected.subject = "[Cancelled] Goodbye #{@recipient}"
- expected.body = "Goodbye, Mr. #{@recipient}"
- expected.from = "system@loudthinking.com"
- expected.date = Time.local(2004, 12, 12)
-
- created = nil
- assert_nothing_raised { created = TestMailer.cancelled_account(@recipient) }
- assert_not_nil created
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised { TestMailer.cancelled_account(@recipient).deliver }
- assert_not_nil ActionMailer::Base.deliveries.first
- delivered = ActionMailer::Base.deliveries.first
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_cc_bcc
- expected = new_mail
- expected.to = @recipient
- expected.subject = "testing bcc/cc"
- expected.body = "Nothing to see here."
- expected.from = "system@loudthinking.com"
- expected.cc = "nobody@loudthinking.com"
- expected.bcc = "root@loudthinking.com"
- expected.date = Time.local 2004, 12, 12
-
- created = nil
- assert_nothing_raised do
- created = TestMailer.cc_bcc @recipient
- end
- assert_not_nil created
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised do
- TestMailer.cc_bcc(@recipient).deliver
- end
-
- assert_not_nil ActionMailer::Base.deliveries.first
- delivered = ActionMailer::Base.deliveries.first
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_from_without_name_for_smtp
- TestMailer.delivery_method = :smtp
- TestMailer.from_without_name.deliver
-
- 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
- TestMailer.delivery_method = :smtp
- TestMailer.from_with_name.deliver
-
- mail = MockSMTP.deliveries.first
- assert_not_nil mail
- mail, from, to = mail
-
- assert_equal 'system@loudthinking.com', from
- end
-
- def test_reply_to
- TestMailer.delivery_method = :test
-
- expected = new_mail
-
- expected.to = @recipient
- expected.subject = "testing reply_to"
- expected.body = "Nothing to see here."
- expected.from = "system@loudthinking.com"
- expected.reply_to = "atraver@gmail.com"
- expected.date = Time.local 2008, 5, 23
-
- created = nil
- assert_nothing_raised do
- created = TestMailer.different_reply_to @recipient
- end
- assert_not_nil created
-
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
-
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised do
- TestMailer.different_reply_to(@recipient).deliver
- end
-
- delivered = ActionMailer::Base.deliveries.first
- assert_not_nil delivered
-
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_iso_charset
- TestMailer.delivery_method = :test
- expected = new_mail( "iso-8859-1" )
- expected.to = @recipient
- expected.subject = encode "testing isø charsets", "iso-8859-1"
- expected.body = "Nothing to see here."
- expected.from = "system@loudthinking.com"
- expected.cc = "nobody@loudthinking.com"
- expected.bcc = "root@loudthinking.com"
- expected.date = Time.local 2004, 12, 12
-
- created = nil
- assert_nothing_raised do
- created = TestMailer.iso_charset @recipient
- end
- assert_not_nil created
-
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
-
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised do
- TestMailer.iso_charset(@recipient).deliver
- end
-
- delivered = ActionMailer::Base.deliveries.first
- assert_not_nil delivered
-
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_unencoded_subject
- TestMailer.delivery_method = :test
- expected = new_mail
- expected.to = @recipient
- expected.subject = "testing unencoded subject"
- expected.body = "Nothing to see here."
- expected.from = "system@loudthinking.com"
- expected.cc = "nobody@loudthinking.com"
- expected.bcc = "root@loudthinking.com"
- expected.date = Time.local 2004, 12, 12
-
- created = nil
- assert_nothing_raised do
- created = TestMailer.unencoded_subject @recipient
- end
- assert_not_nil created
-
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
-
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised do
- TestMailer.unencoded_subject(@recipient).deliver
- end
-
- delivered = ActionMailer::Base.deliveries.first
- assert_not_nil delivered
-
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_deliveries_array
- assert_not_nil ActionMailer::Base.deliveries
- assert_equal 0, ActionMailer::Base.deliveries.size
- TestMailer.signed_up(@recipient).deliver
- assert_equal 1, ActionMailer::Base.deliveries.size
- assert_not_nil ActionMailer::Base.deliveries.first
- end
-
- def test_perform_deliveries_flag
- ActionMailer::Base.perform_deliveries = false
- TestMailer.signed_up(@recipient).deliver
- assert_equal 0, ActionMailer::Base.deliveries.size
- ActionMailer::Base.perform_deliveries = true
- TestMailer.signed_up(@recipient).deliver
- assert_equal 1, ActionMailer::Base.deliveries.size
- end
-
- def test_doesnt_raise_errors_when_raise_delivery_errors_is_false
- ActionMailer::Base.raise_delivery_errors = false
- Mail::TestMailer.any_instance.expects(:deliver!).raises(Exception)
- assert_nothing_raised { TestMailer.signed_up(@recipient).deliver }
- end
-
- def test_performs_delivery_via_sendmail
- IO.expects(:popen).once.with('/usr/sbin/sendmail -i -t -f "system@loudthinking.com" test@localhost', 'w+')
- TestMailer.delivery_method = :sendmail
- TestMailer.signed_up(@recipient).deliver
- end
-
- def test_unquote_quoted_printable_subject
- msg = <<EOF
-From: me@example.com
-Subject: =?UTF-8?Q?testing_testing_=D6=A4?=
-Content-Type: text/plain; charset=iso-8859-1
-
-The body
-EOF
- mail = Mail.new(msg)
- assert_equal "testing testing \326\244", mail.subject
- assert_equal "Subject: =?UTF-8?Q?testing_testing_=D6=A4?=\r\n", mail[:subject].encoded
- end
-
- def test_unquote_7bit_subject
- msg = <<EOF
-From: me@example.com
-Subject: this == working?
-Content-Type: text/plain; charset=iso-8859-1
-
-The body
-EOF
- mail = Mail.new(msg)
- assert_equal "this == working?", mail.subject
- assert_equal "Subject: this == working?\r\n", mail[:subject].encoded
- end
-
- def test_unquote_7bit_body
- msg = <<EOF
-From: me@example.com
-Subject: subject
-Content-Type: text/plain; charset=iso-8859-1
-Content-Transfer-Encoding: 7bit
-
-The=3Dbody
-EOF
- mail = Mail.new(msg)
- assert_equal "The=3Dbody", mail.body.to_s.strip
- assert_equal "The=3Dbody", mail.body.encoded.strip
- end
-
- def test_unquote_quoted_printable_body
- msg = <<EOF
-From: me@example.com
-Subject: subject
-Content-Type: text/plain; charset=iso-8859-1
-Content-Transfer-Encoding: quoted-printable
-
-The=3Dbody
-EOF
- mail = Mail.new(msg)
- assert_equal "The=body", mail.body.to_s.strip
- assert_equal "The=3Dbody=", mail.body.encoded.strip
- end
-
- def test_unquote_base64_body
- msg = <<EOF
-From: me@example.com
-Subject: subject
-Content-Type: text/plain; charset=iso-8859-1
-Content-Transfer-Encoding: base64
-
-VGhlIGJvZHk=
-EOF
- mail = Mail.new(msg)
- assert_equal "The body", mail.body.to_s.strip
- assert_equal "VGhlIGJvZHk=", mail.body.encoded.strip
- end
-
- def test_extended_headers
- @recipient = "Grytøyr <test@localhost>"
-
- expected = new_mail "iso-8859-1"
- expected.to = @recipient
- expected.subject = "testing extended headers"
- expected.body = "Nothing to see here."
- expected.from = "Grytøyr <stian1@example.net>"
- expected.cc = "Grytøyr <stian2@example.net>"
- expected.bcc = "Grytøyr <stian3@example.net>"
- expected.date = Time.local 2004, 12, 12
-
- created = nil
- assert_nothing_raised do
- created = TestMailer.extended_headers @recipient
- end
-
- assert_not_nil created
- expected.message_id = '<123@456>'
- created.message_id = '<123@456>'
-
- assert_equal expected.encoded, created.encoded
-
- assert_nothing_raised do
- TestMailer.extended_headers(@recipient).deliver
- end
-
- delivered = ActionMailer::Base.deliveries.first
- assert_not_nil delivered
-
- expected.message_id = '<123@456>'
- delivered.message_id = '<123@456>'
-
- assert_equal expected.encoded, delivered.encoded
- end
-
- def test_utf8_body_is_not_quoted
- @recipient = "Foo áëô îü <extended@example.net>"
- expected = new_mail "UTF-8"
- expected.to = @recipient
- expected.subject = "testing UTF-8 body"
- expected.body = "åœö blah"
- expected.from = @recipient
- expected.cc = @recipient
- expected.bcc = @recipient
- expected.date = Time.local 2004, 12, 12
-
- created = TestMailer.utf8_body @recipient
- assert_match(/åœö blah/, created.decoded)
- end
-
- def test_multiple_utf8_recipients
- @recipient = ["\"Foo áëô îü\" <extended@example.net>", "\"Example Recipient\" <me@example.com>"]
- expected = new_mail "UTF-8"
- expected.to = @recipient
- expected.subject = "testing UTF-8 body"
- expected.body = "åœö blah"
- expected.from = @recipient.first
- expected.cc = @recipient
- expected.bcc = @recipient
- expected.date = Time.local 2004, 12, 12
-
- created = TestMailer.utf8_body @recipient
- from_regexp = Regexp.escape('From: Foo =?UTF-8?B?w6HDq8O0?= =?UTF-8?B?IMOuw7w=?=')
- assert_match(/#{from_regexp}/m, created.encoded)
-
- to_regexp = Regexp.escape("To: =?UTF-8?B?Rm9vIMOhw6vDtCDDrsO8?= <extended@example.net>")
- assert_match(/#{to_regexp}/m, created.encoded)
- end
-
- def test_receive_decodes_base64_encoded_mail
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email")
- TestMailer.receive(fixture)
- assert_match(/Jamis/, TestMailer.received_body.to_s)
- end
-
- def test_receive_attachments
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email2")
- mail = Mail.new(fixture)
- attachment = mail.attachments.last
- assert_equal "smime.p7s", attachment.filename
- assert_equal "application/pkcs7-signature", mail.parts.last.mime_type
- end
-
- def test_decode_attachment_without_charset
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email3")
- mail = Mail.new(fixture)
- attachment = mail.attachments.last
- assert_equal 1026, attachment.read.length
- end
-
- def test_attachment_using_content_location
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email12")
- mail = Mail.new(fixture)
- assert_equal 1, mail.attachments.length
- assert_equal "Photo25.jpg", mail.attachments.first.filename
- end
-
- def test_attachment_with_text_type
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email13")
- mail = Mail.new(fixture)
- assert mail.has_attachments?
- assert_equal 1, mail.attachments.length
- assert_equal "hello.rb", mail.attachments.first.filename
- end
-
- def test_decode_part_without_content_type
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email4")
- mail = Mail.new(fixture)
- assert_nothing_raised { mail.body }
- end
-
- def test_decode_message_without_content_type
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email5")
- mail = Mail.new(fixture)
- assert_nothing_raised { mail.body }
- end
-
- def test_decode_message_with_incorrect_charset
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email6")
- mail = Mail.new(fixture)
- assert_nothing_raised { mail.body }
- end
-
- def test_multipart_with_mime_version
- mail = TestMailer.multipart_with_mime_version(@recipient)
- assert_equal "1.1", mail.mime_version
- end
-
- def test_multipart_with_utf8_subject
- mail = TestMailer.multipart_with_utf8_subject(@recipient)
- 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)
- end
-
- def test_implicitly_multipart_with_utf8
- mail = TestMailer.implicitly_multipart_with_utf8
- 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)
- end
-
- def test_explicitly_multipart_messages
- mail = TestMailer.explicitly_multipart_example(@recipient)
- assert_equal 3, mail.parts.length
- assert_equal 'multipart/mixed', mail.mime_type
- assert_equal "text/plain", mail.parts[0].mime_type
-
- assert_equal "text/html", mail.parts[1].mime_type
- assert_equal "iso-8859-1", mail.parts[1].charset
-
- assert_equal "image/jpeg", mail.parts[2].mime_type
-
- assert_equal "attachment", mail.parts[2][:content_disposition].disposition_type
- assert_equal "foo.jpg", mail.parts[2][:content_disposition].filename
- assert_equal "foo.jpg", mail.parts[2][:content_type].filename
- assert_nil mail.parts[2].charset
- end
-
- def test_explicitly_multipart_with_content_type
- mail = TestMailer.explicitly_multipart_example(@recipient, "multipart/alternative")
- assert_equal 3, mail.parts.length
- assert_equal "multipart/alternative", mail.mime_type
- end
-
- def test_explicitly_multipart_with_invalid_content_type
- mail = TestMailer.explicitly_multipart_example(@recipient, "text/xml")
- assert_equal 3, mail.parts.length
- assert_equal 'multipart/mixed', mail.mime_type
- end
-
- def test_implicitly_multipart_messages
- assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
-
- mail = TestMailer.implicitly_multipart_example(@recipient)
- assert_equal 3, mail.parts.length
- assert_equal "1.0", mail.mime_version.to_s
- assert_equal "multipart/alternative", mail.mime_type
- assert_equal "text/plain", mail.parts[0].mime_type
- assert_equal "UTF-8", mail.parts[0].charset
- assert_equal "text/html", mail.parts[1].mime_type
- assert_equal "UTF-8", mail.parts[1].charset
- assert_equal "application/x-yaml", mail.parts[2].mime_type
- assert_equal "UTF-8", mail.parts[2].charset
- end
-
- def test_implicitly_multipart_messages_with_custom_order
- assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered"
-
- mail = TestMailer.implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"])
- assert_equal 3, mail.parts.length
- assert_equal "application/x-yaml", mail.parts[0].mime_type
- assert_equal "text/plain", mail.parts[1].mime_type
- assert_equal "text/html", mail.parts[2].mime_type
- end
-
- def test_implicitly_multipart_messages_with_charset
- mail = TestMailer.implicitly_multipart_example(@recipient, 'iso-8859-1')
-
- assert_equal "multipart/alternative", mail.header['content-type'].content_type
-
- assert_equal 'iso-8859-1', mail.parts[0].content_type_parameters[:charset]
- assert_equal 'iso-8859-1', mail.parts[1].content_type_parameters[:charset]
- assert_equal 'iso-8859-1', mail.parts[2].content_type_parameters[:charset]
- end
-
- def test_html_mail
- mail = TestMailer.html_mail(@recipient)
- assert_equal "text/html", mail.mime_type
- end
-
- def test_html_mail_with_underscores
- mail = TestMailer.html_mail_with_underscores(@recipient)
- assert_equal %{<a href="http://google.com" target="_blank">_Google</a>}, mail.body.to_s
- end
-
- def test_various_newlines
- mail = TestMailer.various_newlines(@recipient)
- assert_equal("line #1\nline #2\nline #3\nline #4\n\n" +
- "line #5\n\nline#6\n\nline #7", mail.body.to_s)
- end
-
- def test_various_newlines_multipart
- mail = TestMailer.various_newlines_multipart(@recipient)
- assert_equal "line #1\nline #2\nline #3\nline #4\n\n", mail.parts[0].body.to_s
- assert_equal "<p>line #1</p>\n<p>line #2</p>\n<p>line #3</p>\n<p>line #4</p>\n\n", mail.parts[1].body.to_s
- assert_equal "line #1\r\nline #2\r\nline #3\r\nline #4\r\n\r\n", mail.parts[0].body.encoded
- assert_equal "<p>line #1</p>\r\n<p>line #2</p>\r\n<p>line #3</p>\r\n<p>line #4</p>\r\n\r\n", mail.parts[1].body.encoded
- end
-
- def test_headers_removed_on_smtp_delivery
- TestMailer.delivery_method = :smtp
- TestMailer.cc_bcc(@recipient).deliver
- assert MockSMTP.deliveries[0][2].include?("root@loudthinking.com")
- assert MockSMTP.deliveries[0][2].include?("nobody@loudthinking.com")
- assert MockSMTP.deliveries[0][2].include?(@recipient)
- assert_match %r{^Cc: nobody@loudthinking.com}, MockSMTP.deliveries[0][0]
- assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
- assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
- end
-
- def test_file_delivery_should_create_a_file
- TestMailer.delivery_method = :file
- tmp_location = TestMailer.file_settings[:location]
-
- result = TestMailer.cc_bcc(@recipient).deliver
- assert File.exists?(tmp_location)
- assert File.directory?(tmp_location)
- assert File.exists?(File.join(tmp_location, @recipient))
- assert File.exists?(File.join(tmp_location, 'nobody@loudthinking.com'))
- assert File.exists?(File.join(tmp_location, 'root@loudthinking.com'))
- end
-
- def test_recursive_multipart_processing
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email7")
- mail = Mail.new(fixture)
- assert_equal(2, mail.parts.length)
- assert_equal(4, mail.parts.first.parts.length)
- assert_equal("This is the first part.", mail.parts.first.parts.first.body.to_s)
- assert_equal("test.rb", mail.parts.first.parts.second.filename)
- assert_equal("flowed", mail.parts.first.parts.fourth.content_type_parameters[:format])
- assert_equal('smime.p7s', mail.parts.second.filename)
- end
-
- def test_decode_encoded_attachment_filename
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email8")
- mail = Mail.new(fixture)
- attachment = mail.attachments.last
-
- expected = "01 Quien Te Dij\212at. Pitbull.mp3"
-
- if expected.respond_to?(:force_encoding)
- result = attachment.filename.dup
- expected.force_encoding(Encoding::ASCII_8BIT)
- result.force_encoding(Encoding::ASCII_8BIT)
- assert_equal expected, result
- else
- assert_equal expected, attachment.filename
- end
- end
-
- def test_decode_message_with_unknown_charset
- fixture = File.read(File.dirname(__FILE__) + "/../fixtures/raw_email10")
- mail = Mail.new(fixture)
- assert_nothing_raised { mail.body }
- end
-
- def test_empty_header_values_omitted
- result = TestMailer.unnamed_attachment(@recipient).encoded
- assert_match %r{Content-Type: application/octet-stream}, result
- assert_match %r{Content-Disposition: attachment}, result
- end
-
- def test_headers_with_nonalpha_chars
- mail = TestMailer.headers_with_nonalpha_chars(@recipient)
- assert !mail.from_addrs.empty?
- assert !mail.cc_addrs.empty?
- assert !mail.bcc_addrs.empty?
- assert_match(/:/, mail[:from].decoded)
- assert_match(/:/, mail[:cc].decoded)
- assert_match(/:/, mail[:bcc].decoded)
- end
-
- def test_with_mail_object_deliver
- TestMailer.delivery_method = :test
- mail = TestMailer.headers_with_nonalpha_chars(@recipient)
- assert_nothing_raised { mail.deliver }
- assert_equal 1, TestMailer.deliveries.length
- end
-
- def test_multipart_with_template_path_with_dots
- mail = FunkyPathMailer.multipart_with_template_path_with_dots(@recipient)
- assert_equal 2, mail.parts.length
- assert_equal "text/plain", mail.parts[0].mime_type
- assert_equal "text/html", mail.parts[1].mime_type
- assert_equal "UTF-8", mail.parts[1].charset
- end
-
- def test_custom_content_type_attributes
- mail = TestMailer.custom_content_type_attributes
- assert_match %r{format=flowed}, mail.content_type
- assert_match %r{charset=UTF-8}, mail.content_type
- end
-
- def test_return_path_with_create
- mail = TestMailer.return_path
- assert_equal "another@somewhere.test", mail.return_path
- end
-
- def test_return_path_with_deliver
- TestMailer.delivery_method = :smtp
- TestMailer.return_path.deliver
- assert_match %r{^Return-Path: <another@somewhere.test>}, MockSMTP.deliveries[0][0]
- assert_equal "another@somewhere.test", MockSMTP.deliveries[0][1].to_s
- end
-
- def test_starttls_is_enabled_if_supported
- TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
- MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(true)
- MockSMTP.any_instance.expects(:enable_starttls_auto)
- TestMailer.delivery_method = :smtp
- TestMailer.signed_up(@recipient).deliver
- end
-
- def test_starttls_is_disabled_if_not_supported
- TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
- MockSMTP.any_instance.expects(:respond_to?).with(:enable_starttls_auto).returns(false)
- MockSMTP.any_instance.expects(:enable_starttls_auto).never
- TestMailer.delivery_method = :smtp
- TestMailer.signed_up(@recipient).deliver
- end
-
- def test_starttls_is_not_enabled
- TestMailer.smtp_settings.merge!(:enable_starttls_auto => false)
- MockSMTP.any_instance.expects(:respond_to?).never
- TestMailer.delivery_method = :smtp
- TestMailer.signed_up(@recipient).deliver
- ensure
- TestMailer.smtp_settings.merge!(:enable_starttls_auto => true)
- end
-end
diff --git a/actionmailer/test/old_base/tmail_compat_test.rb b/actionmailer/test/old_base/tmail_compat_test.rb
deleted file mode 100644
index 51558c2bfa..0000000000
--- a/actionmailer/test/old_base/tmail_compat_test.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-require 'abstract_unit'
-
-class TmailCompatTest < ActiveSupport::TestCase
- def setup
- @silence = ActiveSupport::Deprecation.silenced
- ActiveSupport::Deprecation.silenced = false
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = @silence
- end
-
- def test_set_content_type_raises_deprecation_warning
- mail = Mail.new
- assert_deprecated do
- assert_nothing_raised do
- mail.set_content_type "text/plain"
- end
- end
- assert_equal mail.mime_type, "text/plain"
- end
-
- def test_transfer_encoding_raises_deprecation_warning
- mail = Mail.new
- assert_deprecated do
- assert_nothing_raised do
- mail.transfer_encoding "base64"
- end
- end
- assert_equal mail.content_transfer_encoding, "base64"
- end
-
- def test_transfer_encoding_setter_raises_deprecation_warning
- mail = Mail.new
- assert_deprecated do
- assert_nothing_raised do
- mail.transfer_encoding = "base64"
- end
- end
- assert_equal mail.content_transfer_encoding, "base64"
- end
-end
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 15abfb8369..48b3e5bfff 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.1.0 (unreleased)*
+* Added 'ActionView::Helpers::FormHelper.fields_for_with_index', similar to fields_for but allows to have access to the current iteration index [Jorge Bejar]
+
* Warn if we cannot verify CSRF token authenticity [José Valim]
* Allow AM/PM format in datetime selectors [Aditya Sanghi]
diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc
index 5919b5c6d4..c494d78415 100644
--- a/actionpack/README.rdoc
+++ b/actionpack/README.rdoc
@@ -334,7 +334,7 @@ Action Pack is released under the MIT license.
API documentation is at
-* http://api.rubyonrails.com
+* http://api.rubyonrails.org
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 9030db9f7a..66dd88f0c6 100755
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -1,7 +1,7 @@
#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
desc "Default Task"
task :default => :test
@@ -36,7 +36,7 @@ end
spec = eval(File.read('actionpack.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 02a65bf468..d7c8aeadd3 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -20,11 +20,11 @@ Gem::Specification.new do |s|
s.add_dependency('activemodel', version)
s.add_dependency('rack-cache', '~> 1.0.1')
s.add_dependency('builder', '~> 3.0.0')
- s.add_dependency('i18n', '~> 0.6.0beta1')
- s.add_dependency('rack', '~> 1.3.0.beta2')
+ s.add_dependency('i18n', '~> 0.6')
+ s.add_dependency('rack', '~> 1.3.0')
s.add_dependency('rack-test', '~> 0.6.0')
s.add_dependency('rack-mount', '~> 0.8.1')
- s.add_dependency('sprockets', '~> 2.0.0.beta.5')
+ s.add_dependency('sprockets', '~> 2.0.0.beta.8')
s.add_dependency('tzinfo', '~> 0.3.27')
s.add_dependency('erubis', '~> 2.7.0')
end
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb
index f67d0e558e..fd6a46fbec 100644
--- a/actionpack/lib/abstract_controller/base.rb
+++ b/actionpack/lib/abstract_controller/base.rb
@@ -10,7 +10,7 @@ module AbstractController
# <tt>AbstractController::Base</tt> is a low-level API. Nobody should be
# using it directly, and subclasses (like ActionController::Base) are
# expected to provide their own +render+ method, since rendering means
- # different things depending on the context.
+ # different things depending on the context.
class Base
attr_internal :response_body
attr_internal :action_name
diff --git a/actionpack/lib/abstract_controller/helpers.rb b/actionpack/lib/abstract_controller/helpers.rb
index dc9778a416..77cc4c07d9 100644
--- a/actionpack/lib/abstract_controller/helpers.rb
+++ b/actionpack/lib/abstract_controller/helpers.rb
@@ -67,7 +67,7 @@ module AbstractController
# helper FooHelper # => includes FooHelper
#
# When the argument is a string or symbol, the method will provide the "_helper" suffix, require the file
- # and include the module in the template class. The second form illustrates how to include custom helpers
+ # and include the module in the template class. The second form illustrates how to include custom helpers
# when working with namespaced controllers, or other cases where the file containing the helper definition is not
# in one of Rails' standard load paths:
# helper :foo # => requires 'foo_helper' and includes FooHelper
diff --git a/actionpack/lib/action_controller.rb b/actionpack/lib/action_controller.rb
index eba5e9377b..f13fd71050 100644
--- a/actionpack/lib/action_controller.rb
+++ b/actionpack/lib/action_controller.rb
@@ -37,12 +37,13 @@ module ActionController
autoload :UrlFor
end
- autoload :Integration, 'action_controller/deprecated/integration_test'
- autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
- autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
- autoload :UrlWriter, 'action_controller/deprecated'
- autoload :Routing, 'action_controller/deprecated'
- autoload :TestCase, 'action_controller/test_case'
+ autoload :Integration, 'action_controller/deprecated/integration_test'
+ autoload :IntegrationTest, 'action_controller/deprecated/integration_test'
+ autoload :PerformanceTest, 'action_controller/deprecated/performance_test'
+ autoload :UrlWriter, 'action_controller/deprecated'
+ autoload :Routing, 'action_controller/deprecated'
+ autoload :TestCase, 'action_controller/test_case'
+ autoload :TemplateAssertions, 'action_controller/test_case'
eager_autoload do
autoload :RecordIdentifier
diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb
index 5fc6956266..667ba15cc9 100644
--- a/actionpack/lib/action_controller/caching/actions.rb
+++ b/actionpack/lib/action_controller/caching/actions.rb
@@ -39,8 +39,8 @@ module ActionController #:nodoc:
# <tt>:action => 'list', :format => :xml</tt>.
#
# You can set modify the default action cache path by passing a
- # <tt>:cache_path</tt> option. This will be passed directly to
- # <tt>ActionCachePath.path_for</tt>. This is handy for actions with
+ # <tt>:cache_path</tt> option. This will be passed directly to
+ # <tt>ActionCachePath.path_for</tt>. This is handy for actions with
# multiple possible routes that should be cached differently. If a
# block is given, it is called with the current controller instance.
#
diff --git a/actionpack/lib/action_controller/metal/data_streaming.rb b/actionpack/lib/action_controller/metal/data_streaming.rb
index 997bc6e958..623a9873fc 100644
--- a/actionpack/lib/action_controller/metal/data_streaming.rb
+++ b/actionpack/lib/action_controller/metal/data_streaming.rb
@@ -37,7 +37,7 @@ module ActionController #:nodoc:
#
# The default Content-Type and Content-Disposition headers are
# set to download arbitrary binary files in as many browsers as
- # possible. IE versions 4, 5, 5.5, and 6 are all known to have
+ # possible. IE versions 4, 5, 5.5, and 6 are all known to have
# a variety of quirks (especially when downloading over SSL).
#
# Simple download:
@@ -58,8 +58,8 @@ module ActionController #:nodoc:
#
# Also be aware that the document may be cached by proxies and browsers.
# The Pragma and Cache-Control headers declare how the file may be cached
- # by intermediaries. They default to require clients to validate with
- # the server before releasing cached responses. See
+ # by intermediaries. They default to require clients to validate with
+ # the server before releasing cached responses. See
# http://www.mnot.net/cache_docs/ for an overview of web caching and
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
# for the Cache-Control header spec.
diff --git a/actionpack/lib/action_controller/metal/force_ssl.rb b/actionpack/lib/action_controller/metal/force_ssl.rb
index eb8ed7dfbd..ed693c5967 100644
--- a/actionpack/lib/action_controller/metal/force_ssl.rb
+++ b/actionpack/lib/action_controller/metal/force_ssl.rb
@@ -1,12 +1,12 @@
module ActionController
- # This module provides a method which will redirects browser to use HTTPS
+ # This module provides a method which will redirect browser to use HTTPS
# protocol. This will ensure that user's sensitive information will be
# transferred safely over the internet. You _should_ always force browser
# to use HTTPS when you're transferring sensitive information such as
# user authentication, account information, or credit card information.
#
- # Note that if you really concern about your application safety, you might
- # consider using +config.force_ssl+ in your configuration config file instead.
+ # Note that if you are really concerned about your application security,
+ # you might consider using +config.force_ssl+ in your config file instead.
# That will ensure all the data transferred via HTTPS protocol and prevent
# user from getting session hijacked when accessing the site under unsecured
# HTTP protocol.
diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb
index 1d6df89007..2ad571b2b5 100644
--- a/actionpack/lib/action_controller/metal/http_authentication.rb
+++ b/actionpack/lib/action_controller/metal/http_authentication.rb
@@ -400,7 +400,7 @@ module ActionController
# the present token and options.
#
# controller - ActionController::Base instance for the current request.
- # login_procedure - Proc to call if a token is present. The Proc should
+ # login_procedure - Proc to call if a token is present. The Proc should
# take 2 arguments:
# authenticate(controller) { |token, options| ... }
#
@@ -413,7 +413,7 @@ module ActionController
end
end
- # Parses the token and options out of the token authorization header. If
+ # Parses the token and options out of the token authorization header. If
# the header looks like this:
# Authorization: Token token="abc", nonce="def"
# Then the returned token is "abc", and the options is {:nonce => "def"}
diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb
index 16cbbce2fb..85d0f5f699 100644
--- a/actionpack/lib/action_controller/metal/instrumentation.rb
+++ b/actionpack/lib/action_controller/metal/instrumentation.rb
@@ -19,7 +19,7 @@ module ActionController
:controller => self.class.name,
:action => self.action_name,
:params => request.filtered_parameters,
- :format => request.format.ref,
+ :format => request.format.try(:ref),
:method => request.method,
:path => (request.fullpath rescue "unknown")
}
diff --git a/actionpack/lib/action_controller/metal/request_forgery_protection.rb b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
index 13044a7450..2080e9b5b9 100644
--- a/actionpack/lib/action_controller/metal/request_forgery_protection.rb
+++ b/actionpack/lib/action_controller/metal/request_forgery_protection.rb
@@ -63,7 +63,7 @@ module ActionController #:nodoc:
#
# Valid Options:
#
- # * <tt>:only/:except</tt> - Passed to the <tt>before_filter</tt> call. Set which actions are verified.
+ # * <tt>:only/:except</tt> - Passed to the <tt>before_filter</tt> call. Set which actions are verified.
def protect_from_forgery(options = {})
self.request_forgery_protection_token ||= :authenticity_token
prepend_before_filter :verify_authenticity_token, options
@@ -71,7 +71,7 @@ module ActionController #:nodoc:
end
protected
- # The actual before_filter that is used. Modify this to change how you handle unverified requests.
+ # The actual before_filter that is used. Modify this to change how you handle unverified requests.
def verify_authenticity_token
unless verified_request?
logger.debug "WARNING: Can't verify CSRF token authenticity" if logger
@@ -83,7 +83,7 @@ module ActionController #:nodoc:
reset_session
end
- # Returns true or false if a request is verified. Checks:
+ # Returns true or false if a request is verified. Checks:
#
# * is it a GET request? Gets should be safe and idempotent
# * Does the form_authenticity_token match the given token value from the params?
@@ -96,7 +96,7 @@ module ActionController #:nodoc:
# Sets the token value for the current session.
def form_authenticity_token
- session[:_csrf_token] ||= ActiveSupport::SecureRandom.base64(32)
+ session[:_csrf_token] ||= SecureRandom.base64(32)
end
# The form's authenticity parameter. Override to provide your own.
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 639e24c995..bfb820fcdf 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -130,7 +130,7 @@ module ActionController
super
self.session = TestSession.new
- self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => ActiveSupport::SecureRandom.hex(16))
+ self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => SecureRandom.hex(16))
end
class Result < ::Array #:nodoc:
diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
index 91a97c02ff..eaefdc0f15 100644
--- a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
+++ b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
@@ -103,7 +103,7 @@ module HTML
# Specifies the default Set of allowed shorthand css properties for the #sanitize and #sanitize_css helpers.
self.shorthand_css_properties = Set.new(%w(background border margin padding))
- # Sanitizes a block of css code. Used by #sanitize when it comes across a style attribute
+ # Sanitizes a block of css code. Used by #sanitize when it comes across a style attribute
def sanitize_css(style)
# disallow urls
style = style.to_s.gsub(/url\s*\(\s*[^\s)]+?\s*\)\s*/, ' ')
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index 7c9ebe7c7b..fa2948c8db 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -47,7 +47,7 @@ module Mime
cattr_reader :html_types
# These are the content types which browsers can generate without using ajax, flash, etc
- # i.e. following a link, getting an image or posting a form. CSRF protection
+ # i.e. following a link, getting an image or posting a form. CSRF protection
# only needs to protect against these types.
@@browser_generated_types = Set.new [:html, :url_encoded_form, :multipart_form, :text]
cattr_reader :browser_generated_types
@@ -246,7 +246,7 @@ module Mime
end
end
- # Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
+ # Returns true if Action Pack should check requests using this Mime Type for possible request forgery. See
# ActionController::RequestForgeryProtection.
def verify_request?
@@browser_generated_types.include?(to_sym)
diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb
index ccb866f4f7..b22d426c1f 100644
--- a/actionpack/lib/action_dispatch/http/request.rb
+++ b/actionpack/lib/action_dispatch/http/request.rb
@@ -2,7 +2,6 @@ require 'tempfile'
require 'stringio'
require 'strscan'
-require 'active_support/core_ext/module/deprecation'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/string/access'
require 'active_support/inflector'
@@ -26,7 +25,7 @@ module ActionDispatch
HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM
HTTP_NEGOTIATE HTTP_PRAGMA ].freeze
-
+
ENV_METHODS.each do |env|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{env.sub(/^HTTP_/n, '').downcase}
@@ -134,11 +133,6 @@ module ActionDispatch
@fullpath ||= super
end
- def forgery_whitelisted?
- get?
- end
- deprecate :forgery_whitelisted? => "it is just an alias for 'get?' now, update your code"
-
def media_type
content_mime_type.to_s
end
@@ -172,10 +166,10 @@ module ActionDispatch
)\.
}x
- # Determines originating IP address. REMOTE_ADDR is the standard
- # but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
+ # Determines originating IP address. REMOTE_ADDR is the standard
+ # but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
# HTTP_X_FORWARDED_FOR are set by proxies so check for these if
- # REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma-
+ # REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma-
# delimited list in the case of multiple chained proxies; the last
# address which is not trusted is the originating IP.
def remote_ip
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 3a6b1da4fd..f1e85559a3 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -33,7 +33,8 @@ module ActionDispatch # :nodoc:
# end
# end
class Response
- attr_accessor :request, :header, :status
+ attr_accessor :request, :header
+ attr_reader :status
attr_writer :sending_file
alias_method :headers=, :header=
@@ -115,32 +116,9 @@ module ActionDispatch # :nodoc:
EMPTY = " "
- class BodyBuster #:nodoc:
- def initialize(response)
- @response = response
- @body = ""
- end
-
- def bust(body)
- body.call(@response, self)
- body.close if body.respond_to?(:close)
- @body
- end
-
- def write(string)
- @body << string.to_s
- end
- end
-
def body=(body)
@blank = true if body == EMPTY
- if body.respond_to?(:call)
- ActiveSupport::Deprecation.warn "Setting a Proc or an object that responds to call " \
- "in response_body is no longer supported", caller
- body = BodyBuster.new(self).bust(body)
- end
-
# Explicitly check for strings. This is *wrong* theoretically
# but if we don't check this, the performance on string bodies
# is bad on Ruby 1.8 (because strings responds to each then).
diff --git a/actionpack/lib/action_dispatch/middleware/callbacks.rb b/actionpack/lib/action_dispatch/middleware/callbacks.rb
index 1bb2ad7f67..8c0f4052ec 100644
--- a/actionpack/lib/action_dispatch/middleware/callbacks.rb
+++ b/actionpack/lib/action_dispatch/middleware/callbacks.rb
@@ -19,8 +19,7 @@ module ActionDispatch
set_callback(:call, :after, *args, &block)
end
- def initialize(app, unused = nil)
- ActiveSupport::Deprecation.warn "Passing a second argument to ActionDispatch::Callbacks.new is deprecated." unless unused.nil?
+ def initialize(app)
@app = app
end
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 0057f64dd3..47c4bad489 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -59,7 +59,7 @@ module ActionDispatch
# The option symbols for setting cookies are:
#
# * <tt>:value</tt> - The cookie's value or list of values (as an array).
- # * <tt>:path</tt> - The path for which this cookie applies. Defaults to the root
+ # * <tt>:path</tt> - The path for which this cookie applies. Defaults to the root
# of the application.
# * <tt>:domain</tt> - The domain for which this cookie applies so you can
# restrict to the domain level. If you use a schema like www.example.com
@@ -305,7 +305,7 @@ module ActionDispatch
if secret.length < SECRET_MIN_LENGTH
raise ArgumentError, "Secret should be something secure, " +
- "like \"#{ActiveSupport::SecureRandom.hex(16)}\". The value you " +
+ "like \"#{SecureRandom.hex(16)}\". The value you " +
"provided, \"#{secret}\", is shorter than the minimum length " +
"of #{SECRET_MIN_LENGTH} characters"
end
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
index 1a811ce1b1..a70d814749 100644
--- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
+++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb
@@ -29,7 +29,7 @@ module ActionDispatch
end
def generate_sid
- sid = ActiveSupport::SecureRandom.hex(16)
+ sid = SecureRandom.hex(16)
sid.encode!('UTF-8') if sid.respond_to?(:encode!)
sid
end
@@ -73,13 +73,7 @@ module ActionDispatch
include StaleSessionCheck
def destroy_session(env, sid, options)
- ActiveSupport::Deprecation.warn "Implementing #destroy in session stores is deprecated. " <<
- "Please implement destroy_session(env, session_id, options) instead."
- destroy(env)
- end
-
- def destroy(env)
- raise '#destroy needs to be implemented.'
+ raise '#destroy_session needs to be implemented.'
end
end
end
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index c25f8c90bc..3999bd0a5e 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -335,7 +335,7 @@ module ActionDispatch
#
# [:on]
# Shorthand for wrapping routes in a specific RESTful context. Valid
- # values are +:member+, +:collection+, and +:new+. Only use within
+ # values are +:member+, +:collection+, and +:new+. Only use within
# <tt>resource(s)</tt> block. For example:
#
# resource :bar do
@@ -578,8 +578,8 @@ module ActionDispatch
# end
#
# This generates helpers such as +account_projects_path+, just like +resources+ does.
- # The difference here being that the routes generated are like /rails/projects/2,
- # rather than /accounts/rails/projects/2.
+ # The difference here being that the routes generated are like /:account_id/projects,
+ # rather than /accounts/:account_id/projects.
#
# === Options
#
@@ -1094,11 +1094,11 @@ module ActionDispatch
# [:shallow_path]
# Prefixes nested shallow routes with the specified path.
#
- # scope :shallow_path => "sekret" do
- # resources :posts do
- # resources :comments, :shallow => true
+ # scope :shallow_path => "sekret" do
+ # resources :posts do
+ # resources :comments, :shallow => true
+ # end
# end
- # end
#
# The +comments+ resource here will have the following routes generated for it:
#
diff --git a/actionpack/lib/action_dispatch/routing/route.rb b/actionpack/lib/action_dispatch/routing/route.rb
index a049510182..10b3d38346 100644
--- a/actionpack/lib/action_dispatch/routing/route.rb
+++ b/actionpack/lib/action_dispatch/routing/route.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/module/deprecation'
-
module ActionDispatch
module Routing
class Route #:nodoc:
@@ -47,11 +45,6 @@ module ActionDispatch
@segment_keys ||= conditions[:path_info].names.compact.map { |key| key.to_sym }
end
- def to_a
- [@app, @conditions, @defaults, @name]
- end
- deprecate :to_a
-
def to_s
@to_s ||= begin
"%-6s %-40s %s" % [(verb || :any).to_s.upcase, path, requirements.inspect]
diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb
index 5893f86798..480144fe9d 100644
--- a/actionpack/lib/action_dispatch/routing/url_for.rb
+++ b/actionpack/lib/action_dispatch/routing/url_for.rb
@@ -108,7 +108,7 @@ module ActionDispatch
end
# Generate a url based on the options provided, default_url_options and the
- # routes defined in routes.rb. The following options are supported:
+ # routes defined in routes.rb. The following options are supported:
#
# * <tt>:only_path</tt> - If true, the relative url is returned. Defaults to +false+.
# * <tt>:protocol</tt> - The protocol to connect to. Defaults to 'http'.
diff --git a/actionpack/lib/action_dispatch/testing/assertions.rb b/actionpack/lib/action_dispatch/testing/assertions.rb
index 822150b768..226baf9ad0 100644
--- a/actionpack/lib/action_dispatch/testing/assertions.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions.rb
@@ -8,12 +8,11 @@ module ActionDispatch
extend ActiveSupport::Concern
- included do
- include DomAssertions
- include ResponseAssertions
- include RoutingAssertions
- include SelectorAssertions
- include TagAssertions
- end
+ include DomAssertions
+ include ResponseAssertions
+ include RoutingAssertions
+ include SelectorAssertions
+ include TagAssertions
end
end
+
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb
index 3335742d47..606b01893e 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/response.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -6,13 +6,6 @@ module ActionDispatch
module ResponseAssertions
extend ActiveSupport::Concern
- included do
- # TODO: Need to pull in AV::Template monkey patches that track which
- # templates are rendered. assert_template should probably be part
- # of AV instead of AD.
- require 'action_view/test_case'
- end
-
# Asserts that the response is one of the following types:
#
# * <tt>:success</tt> - Status code was 200
diff --git a/actionpack/lib/action_dispatch/testing/assertions/routing.rb b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
index b760db42e2..57a24a1bd9 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/routing.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/routing.rb
@@ -7,18 +7,18 @@ module ActionDispatch
# Suite of assertions to test routes generated by \Rails and the handling of requests made to them.
module RoutingAssertions
# Asserts that the routing of the given +path+ was handled correctly and that the parsed options (given in the +expected_options+ hash)
- # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
+ # match +path+. Basically, it asserts that \Rails recognizes the route given by +expected_options+.
#
- # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
- # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
+ # Pass a hash in the second argument (+path+) to specify the request method. This is useful for routes
+ # requiring a specific HTTP method. The hash should contain a :path with the incoming request path
# and a :method containing the required HTTP verb.
#
# # assert that POSTing to /items will call the create action on ItemsController
# assert_recognizes({:controller => 'items', :action => 'create'}, {:path => 'items', :method => :post})
#
- # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
- # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
- # extras argument, appending the query string on the path directly will not work. For example:
+ # You can also pass in +extras+ with a hash containing URL parameters that would normally be in the query string. This can be used
+ # to assert that values in the query string string will end up in the params hash correctly. To test query strings you must use the
+ # extras argument, appending the query string on the path directly will not work. For example:
#
# # assert that a path of '/items/list/1?view=print' returns the correct options
# assert_recognizes({:controller => 'items', :action => 'list', :id => '1', :view => 'print'}, 'items/list/1', { :view => "print" })
@@ -49,7 +49,7 @@ module ActionDispatch
assert_equal(expected_options, request.path_parameters, msg)
end
- # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
+ # Asserts that the provided options can be used to generate the provided path. This is the inverse of +assert_recognizes+.
# The +extras+ parameter is used to tell the request the names and values of additional request parameters that would be in
# a query string. The +message+ parameter allows you to specify a custom error message for assertion failures.
#
@@ -92,10 +92,10 @@ module ActionDispatch
end
# Asserts that path and options match both ways; in other words, it verifies that <tt>path</tt> generates
- # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
+ # <tt>options</tt> and then that <tt>options</tt> generates <tt>path</tt>. This essentially combines +assert_recognizes+
# and +assert_generates+ into one step.
#
- # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
+ # The +extras+ hash allows you to specify options that would normally be provided as a query string to the action. The
# +message+ parameter allows you to specify a custom error message to display upon failure.
#
# ==== Examples
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 7d707d03a9..9791ba58e2 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -62,7 +62,7 @@ module ActionDispatch
#
# The request_method is +:get+, +:post+, +:put+, +:delete+ or +:head+; the
# parameters are +nil+, a hash, or a url-encoded or multipart string;
- # the headers are a hash. Keys are automatically upcased and prefixed
+ # the headers are a hash. Keys are automatically upcased and prefixed
# with 'HTTP_' if not already.
def xml_http_request(request_method, path, parameters = nil, headers = nil)
headers ||= {}
diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb
index 78a68db282..262e0f1010 100644
--- a/actionpack/lib/action_view/helpers.rb
+++ b/actionpack/lib/action_view/helpers.rb
@@ -22,7 +22,6 @@ module ActionView #:nodoc:
autoload :RecordTagHelper
autoload :RenderingHelper
autoload :SanitizeHelper
- autoload :SprocketsHelper
autoload :TagHelper
autoload :TextHelper
autoload :TranslationHelper
@@ -53,7 +52,6 @@ module ActionView #:nodoc:
include RecordTagHelper
include RenderingHelper
include SanitizeHelper
- include SprocketsHelper
include TagHelper
include TextHelper
include TranslationHelper
diff --git a/actionpack/lib/action_view/helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_paths.rb
index 38810eea2e..9a99c3cf52 100644
--- a/actionpack/lib/action_view/helpers/asset_paths.rb
+++ b/actionpack/lib/action_view/helpers/asset_paths.rb
@@ -44,7 +44,12 @@ module ActionView
raise NotImplementedError
end
+ def rewrite_relative_url_root(source, relative_url_root)
+ relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source
+ end
+
def rewrite_host_and_protocol(source, has_request)
+ source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request
host = compute_asset_host(source)
if has_request && host && !is_uri?(host)
host = "#{controller.request.protocol}#{host}"
@@ -55,11 +60,11 @@ module ActionView
# Pick an asset host for this source. Returns +nil+ if no host is set,
# the host if no wildcard is set, the host interpolated with the
# numbers 0-3 if it contains <tt>%d</tt> (the number is the source hash mod 4),
- # or the value returned from invoking the proc if it's a proc or the value from
- # invoking call if it's an object responding to call.
+ # or the value returned from invoking call on an object responding to call
+ # (proc or otherwise).
def compute_asset_host(source)
if host = config.asset_host
- if host.is_a?(Proc) || host.respond_to?(:call)
+ if host.respond_to?(:call)
case host.is_a?(Proc) ? host.arity : host.method(:call).arity
when 2
request = controller.respond_to?(:request) && controller.request
@@ -75,4 +80,4 @@ module ActionView
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
index 9bc847a1ab..7970176d37 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb
@@ -274,11 +274,7 @@ module ActionView
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
# plugin authors are encouraged to do so.
def image_path(source)
- if config.use_sprockets
- asset_path(source)
- else
- asset_paths.compute_public_path(source, 'images')
- end
+ asset_paths.compute_public_path(source, 'images')
end
alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
@@ -293,11 +289,7 @@ module ActionView
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
# video_path("http://www.example.com/vid/hd.avi") # => http://www.example.com/vid/hd.avi
def video_path(source)
- if config.use_sprockets
- asset_path(source)
- else
- asset_paths.compute_public_path(source, 'videos')
- end
+ asset_paths.compute_public_path(source, 'videos')
end
alias_method :path_to_video, :video_path # aliased to avoid conflicts with a video_path named route
@@ -312,11 +304,7 @@ module ActionView
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
# audio_path("http://www.example.com/sounds/horse.wav") # => http://www.example.com/sounds/horse.wav
def audio_path(source)
- if config.use_sprockets
- asset_path(source)
- else
- asset_paths.compute_public_path(source, 'audios')
- end
+ asset_paths.compute_public_path(source, 'audios')
end
alias_method :path_to_audio, :audio_path # aliased to avoid conflicts with an audio_path named route
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb
index cd0f8c8878..2d49823412 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb
@@ -85,17 +85,8 @@ module ActionView
end
end
end
-
- def rewrite_relative_url_root(source, relative_url_root)
- relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source
- end
-
- def rewrite_host_and_protocol(source, has_request)
- source = rewrite_relative_url_root(source, controller.config.relative_url_root) if has_request
- super(source, has_request)
- end
end
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
index e1ee0d0e1a..0f8a63901e 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
@@ -187,12 +187,8 @@ module ActionView
#
# javascript_include_tag :all, :cache => true, :recursive => true
def javascript_include_tag(*sources)
- if config.use_sprockets
- sprockets_javascript_include_tag(*sources)
- else
- @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths)
- @javascript_include.include_tag(*sources)
- end
+ @javascript_include ||= JavascriptIncludeTag.new(config, asset_paths)
+ @javascript_include.include_tag(*sources)
end
end
end
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
index a95eb221be..e4f11c9bc7 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
@@ -137,12 +137,8 @@ module ActionView
# stylesheet_link_tag :all, :concat => true
#
def stylesheet_link_tag(*sources)
- if config.use_sprockets
- sprockets_stylesheet_link_tag(*sources)
- else
- @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths)
- @stylesheet_include.include_tag(*sources)
- end
+ @stylesheet_include ||= StylesheetIncludeTag.new(config, asset_paths)
+ @stylesheet_include.include_tag(*sources)
end
end
diff --git a/actionpack/lib/action_view/helpers/capture_helper.rb b/actionpack/lib/action_view/helpers/capture_helper.rb
index 3b5f4e694f..62f95379cd 100644
--- a/actionpack/lib/action_view/helpers/capture_helper.rb
+++ b/actionpack/lib/action_view/helpers/capture_helper.rb
@@ -27,7 +27,7 @@ module ActionView
# "The current timestamp is #{Time.now}."
# end
#
- # You can then use that variable anywhere else. For example:
+ # You can then use that variable anywhere else. For example:
#
# <html>
# <head><title><%= @greeting %></title></head>
@@ -76,7 +76,7 @@ module ActionView
#
# <%= stored_content %>
#
- # You can use the <tt>yield</tt> syntax alongside an existing call to <tt>yield</tt> in a layout. For example:
+ # You can use the <tt>yield</tt> syntax alongside an existing call to <tt>yield</tt> in a layout. For example:
#
# <%# This is the layout %>
# <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb
index c78c03a5eb..56e3af683b 100644
--- a/actionpack/lib/action_view/helpers/date_helper.rb
+++ b/actionpack/lib/action_view/helpers/date_helper.rb
@@ -517,7 +517,7 @@ module ActionView
# # that is named 'due' rather than 'day'.
# select_day(my_time, :field_name => 'due')
#
- # # Generates a select field for days with a custom prompt. Use <tt>:prompt => true</tt> for a
+ # # Generates a select field for days with a custom prompt. Use <tt>:prompt => true</tt> for a
# # generic prompt.
# select_day(5, :prompt => 'Choose day')
#
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 07e2c8d341..cb1c13912a 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -555,6 +555,19 @@ module ActionView
# ...
# <% end %>
#
+ # In addition, you may want to have access to the current iteration index.
+ # In that case, you can use a similar method called fields_for_with_index
+ # which receives a block with an extra parameter:
+ #
+ # <%= form_for @person do |person_form| %>
+ # ...
+ # <%= person_form.fields_for_with_index :projects do |project_fields, index| %>
+ # Position: <%= index %>
+ # Name: <%= project_fields.text_field :name %>
+ # <% end %>
+ # ...
+ # <% end %>
+ #
# When projects is already an association on Person you can use
# +accepts_nested_attributes_for+ to define the writer method for you:
#
@@ -1216,6 +1229,13 @@ module ActionView
RUBY_EVAL
end
+ # Check +fields_for+ for docs and examples.
+ def fields_for_with_index(record_name, record_object = nil, fields_options = {}, &block)
+ index = fields_options[:index] || options[:child_index] || nested_child_index(@object_name)
+ block_with_index = Proc.new{ |obj| block.call(obj, index) }
+ fields_for(record_name, record_object, fields_options, &block_with_index)
+ end
+
def fields_for(record_name, record_object = nil, fields_options = {}, &block)
fields_options, record_object = record_object, nil if record_object.is_a?(Hash)
fields_options[:builder] ||= options[:builder]
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 0aaa690129..794132637c 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -125,7 +125,7 @@ module ActionView
# This allows the user to submit a form page more than once with the expected results of creating multiple records.
# In addition, this allows a single partial to be used to generate form inputs for both edit and create forms.
#
- # By default, <tt>post.person_id</tt> is the selected option. Specify <tt>:selected => value</tt> to use a different selection
+ # By default, <tt>post.person_id</tt> is the selected option. Specify <tt>:selected => value</tt> to use a different selection
# or <tt>:selected => nil</tt> to leave all options unselected. Similarly, you can specify values to be disabled in the option
# tags by specifying the <tt>:disabled</tt> option. This can either be a single value or an array of values to be disabled.
def select(object, method, choices, options = {}, html_options = {})
@@ -255,7 +255,7 @@ module ActionView
# Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container
# where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and
# the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values
- # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. +selected+
+ # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. +selected+
# may also be an array of values to be selected when using a multiple select.
#
# Examples (call, result):
@@ -406,13 +406,13 @@ module ActionView
# wraps them with <tt><optgroup></tt> tags.
#
# Parameters:
- # * +grouped_options+ - Accepts a nested array or hash of strings. The first value serves as the
+ # * +grouped_options+ - Accepts a nested array or hash of strings. The first value serves as the
# <tt><optgroup></tt> label while the second value must be an array of options. The second value can be a
# nested array of text-value pairs. See <tt>options_for_select</tt> for more info.
# Ex. ["North America",[["United States","US"],["Canada","CA"]]]
# * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
# which will have the +selected+ attribute set. Note: It is possible for this value to match multiple options
- # as you might have the same option in multiple groups. Each will then get <tt>selected="selected"</tt>.
+ # as you might have the same option in multiple groups. Each will then get <tt>selected="selected"</tt>.
# * +prompt+ - set to true or a prompt string. When the select element doesn't have a value yet, this
# prepends an option with a generic prompt - "Please select" - or the given prompt string.
#
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 65a98fb27a..a91e86f4db 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -204,7 +204,7 @@ module ActionView
text_field_tag(name, value, options.stringify_keys.update("type" => "hidden"))
end
- # Creates a file upload field. If you are using file uploads then you will also need
+ # Creates a file upload field. If you are using file uploads then you will also need
# to set the multipart option for the form tag:
#
# <%= form_tag '/upload', :multipart => true do %>
diff --git a/actionpack/lib/action_view/helpers/sanitize_helper.rb b/actionpack/lib/action_view/helpers/sanitize_helper.rb
index 841be0a567..bcc8f6fbcb 100644
--- a/actionpack/lib/action_view/helpers/sanitize_helper.rb
+++ b/actionpack/lib/action_view/helpers/sanitize_helper.rb
@@ -14,13 +14,13 @@ module ActionView
#
# It also strips href/src tags with invalid protocols, like javascript: especially.
# It does its best to counter any tricks that hackers may use, like throwing in
- # unicode/ascii/hex values to get past the javascript: filters. Check out
+ # unicode/ascii/hex values to get past the javascript: filters. Check out
# the extensive test suite.
#
# <%= sanitize @article.body %>
#
# You can add or remove tags/attributes if you want to customize it a bit.
- # See ActionView::Base for full docs on the available options. You can add
+ # See ActionView::Base for full docs on the available options. You can add
# tags/attributes for single uses of +sanitize+ by passing either the
# <tt>:attributes</tt> or <tt>:tags</tt> options:
#
@@ -66,7 +66,7 @@ module ActionView
self.class.white_list_sanitizer.sanitize_css(style)
end
- # Strips all HTML tags from the +html+, including comments. This uses the
+ # Strips all HTML tags from the +html+, including comments. This uses the
# html-scanner tokenizer and so its HTML parsing ability is limited by
# that of html-scanner.
#
@@ -142,7 +142,7 @@ module ActionView
white_list_sanitizer.protocol_separator = value
end
- # Gets the HTML::FullSanitizer instance used by +strip_tags+. Replace with
+ # Gets the HTML::FullSanitizer instance used by +strip_tags+. Replace with
# any object that responds to +sanitize+.
#
# class Application < Rails::Application
@@ -153,7 +153,7 @@ module ActionView
@full_sanitizer ||= HTML::FullSanitizer.new
end
- # Gets the HTML::LinkSanitizer instance used by +strip_links+. Replace with
+ # Gets the HTML::LinkSanitizer instance used by +strip_links+. Replace with
# any object that responds to +sanitize+.
#
# class Application < Rails::Application
diff --git a/actionpack/lib/action_view/helpers/sprockets_helper.rb b/actionpack/lib/action_view/helpers/sprockets_helper.rb
deleted file mode 100644
index ab98da9624..0000000000
--- a/actionpack/lib/action_view/helpers/sprockets_helper.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require 'uri'
-require 'action_view/helpers/asset_paths'
-
-module ActionView
- module Helpers
- module SprocketsHelper
- def asset_path(source, default_ext = nil)
- sprockets_asset_paths.compute_public_path(source, 'assets', default_ext, true)
- end
-
- def sprockets_javascript_include_tag(source, options = {})
- options = {
- 'type' => "text/javascript",
- 'src' => asset_path(source, 'js')
- }.merge(options.stringify_keys)
-
- content_tag 'script', "", options
- end
-
- def sprockets_stylesheet_link_tag(source, options = {})
- options = {
- 'rel' => "stylesheet",
- 'type' => "text/css",
- 'media' => "screen",
- 'href' => asset_path(source, 'css')
- }.merge(options.stringify_keys)
-
- tag 'link', options
- end
-
- private
-
- def sprockets_asset_paths
- @sprockets_asset_paths ||= begin
- config = self.config if respond_to?(:config)
- controller = self.controller if respond_to?(:controller)
- SprocketsHelper::AssetPaths.new(config, controller)
- end
- end
-
- class AssetPaths < ActionView::Helpers::AssetPaths #:nodoc:
- def rewrite_asset_path(source, dir)
- if source[0] == ?/
- source
- else
- assets.path(source, performing_caching?, dir)
- end
- end
-
- def rewrite_extension(source, dir, ext)
- if ext && File.extname(source).empty?
- "#{source}.#{ext}"
- else
- source
- end
- end
-
- def assets
- Rails.application.assets
- end
-
- # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
- def performing_caching?
- @config ? @config.perform_caching : Rails.application.config.action_controller.perform_caching
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb
index 786af5ca58..8c33ef09fa 100644
--- a/actionpack/lib/action_view/helpers/tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/tag_helper.rb
@@ -94,7 +94,7 @@ module ActionView
end
end
- # Returns a CDATA section with the given +content+. CDATA sections
+ # Returns a CDATA section with the given +content+. CDATA sections
# are used to escape blocks of text containing characters which would
# otherwise be recognized as markup. CDATA sections begin with the string
# <tt><![CDATA[</tt> and end with (and may not contain) the string <tt>]]></tt>.
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index ca09c77b5c..75422a343d 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -232,7 +232,7 @@ module ActionView
# considered as a linebreak and a <tt><br /></tt> tag is appended. This
# method does not remove the newlines from the +text+.
#
- # You can pass any HTML attributes into <tt>html_options</tt>. These
+ # You can pass any HTML attributes into <tt>html_options</tt>. These
# will be added to all created paragraphs.
#
# ==== Options
@@ -267,7 +267,7 @@ module ActionView
# Creates a Cycle object whose _to_s_ method cycles through elements of an
# array every time it is called. This can be used for example, to alternate
- # classes for table rows. You can use named cycles to allow nesting in loops.
+ # classes for table rows. You can use named cycles to allow nesting in loops.
# Passing a Hash as the last parameter with a <tt>:name</tt> key will create a
# named cycle. The default name for a cycle without a +:name+ key is
# <tt>"default"</tt>. You can manually reset a cycle by calling reset_cycle
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index 5488c752cc..25411856cb 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -160,7 +160,7 @@ module ActionView
#
# ==== Examples
# Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments
- # and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
+ # and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
# your application on resources and use
#
# link_to "Profile", profile_path(@profile)
@@ -348,7 +348,7 @@ module ActionView
# Creates a link tag of the given +name+ using a URL created by the set of
# +options+ unless the current request URI is the same as the links, in
# which case only the name is returned (or the given block is yielded, if
- # one exists). You can give +link_to_unless_current+ a block which will
+ # one exists). You can give +link_to_unless_current+ a block which will
# specialize the default behavior (e.g., show a "Start Here" link rather
# than the link's text).
#
@@ -375,7 +375,7 @@ module ActionView
# </ul>
#
# The implicit block given to +link_to_unless_current+ is evaluated if the current
- # action is the action given. So, if we had a comments page and wanted to render a
+ # action is the action given. So, if we had a comments page and wanted to render a
# "Go Back" link instead of a link to the comments page, we could do something like this...
#
# <%=
@@ -579,7 +579,7 @@ module ActionView
url_string = url_for(options)
# We ignore any extra parameters in the request_uri if the
- # submitted url doesn't have any either. This lets the function
+ # submitted url doesn't have any either. This lets the function
# work with things like ?order=asc
if url_string.index("?")
request_uri = request.fullpath
@@ -641,7 +641,7 @@ module ActionView
# Processes the +html_options+ hash, converting the boolean
# attributes from true/false form into the form required by
- # HTML/XHTML. (An attribute is considered to be boolean if
+ # HTML/XHTML. (An attribute is considered to be boolean if
# its name is listed in the given +bool_attrs+ array.)
#
# More specifically, for each boolean attribute in +html_options+
@@ -651,7 +651,7 @@ module ActionView
#
# if the associated +bool_value+ evaluates to true, it is
# replaced with the attribute's name; otherwise the attribute is
- # removed from the +html_options+ hash. (See the XHTML 1.0 spec,
+ # removed from the +html_options+ hash. (See the XHTML 1.0 spec,
# section 4.5 "Attribute Minimization" for more:
# http://www.w3.org/TR/xhtml1/#h-4.5)
#
diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index b99d24d281..10797c010f 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -91,7 +91,6 @@ module ActionView
eager_autoload do
autoload :Error
- autoload :Handler
autoload :Handlers
autoload :Text
end
diff --git a/actionpack/lib/action_view/template/handler.rb b/actionpack/lib/action_view/template/handler.rb
deleted file mode 100644
index 636f3ebbad..0000000000
--- a/actionpack/lib/action_view/template/handler.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require 'action_dispatch/http/mime_type'
-require 'active_support/core_ext/class/attribute'
-
-# Legacy TemplateHandler stub
-module ActionView
- class Template
- module Handlers #:nodoc:
- module Compilable
- def self.included(base)
- ActiveSupport::Deprecation.warn "Including Compilable in your template handler is deprecated. " <<
- "Since Rails 3, all the API your template handler needs to implement is to respond to #call."
- base.extend(ClassMethods)
- end
-
- module ClassMethods
- def call(template)
- new.compile(template)
- end
- end
-
- def compile(template)
- raise "Need to implement #{self.class.name}#compile(template)"
- end
- end
- end
-
- class Template::Handler
- class_attribute :default_format
- self.default_format = Mime::HTML
-
- def self.inherited(base)
- ActiveSupport::Deprecation.warn "Inheriting from ActionView::Template::Handler is deprecated. " <<
- "Since Rails 3, all the API your template handler needs to implement is to respond to #call."
- super
- end
-
- def self.call(template)
- raise "Need to implement #{self.class.name}#call(template)"
- end
-
- def render(template, local_assigns)
- raise "Need to implement #{self.class.name}#render(template, local_assigns)"
- end
- end
- end
-
- TemplateHandlers = Template::Handlers
- TemplateHandler = Template::Handler
-end
diff --git a/actionpack/lib/action_view/template/handlers.rb b/actionpack/lib/action_view/template/handlers.rb
index 959afa734e..aa693335e3 100644
--- a/actionpack/lib/action_view/template/handlers.rb
+++ b/actionpack/lib/action_view/template/handlers.rb
@@ -41,12 +41,6 @@ module ActionView #:nodoc:
@@default_template_handlers = klass
end
- def handler_class_for_extension(extension)
- ActiveSupport::Deprecation.warn "handler_class_for_extension is deprecated. " <<
- "Please use handler_for_extension instead", caller
- handler_for_extension(extension)
- end
-
def handler_for_extension(extension)
registered_template_handler(extension) || @@default_template_handlers
end
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb
index a1e3fd7768..77720e2bc8 100644
--- a/actionpack/lib/action_view/template/handlers/erb.rb
+++ b/actionpack/lib/action_view/template/handlers/erb.rb
@@ -1,5 +1,5 @@
+require 'action_dispatch/http/mime_type'
require 'active_support/core_ext/class/attribute_accessors'
-require 'action_view/template/handler'
require 'erubis'
module ActionView
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index d0317a148b..2cc85a9f69 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -218,12 +218,6 @@ module ActionView
end]
end
- def _assigns
- ActiveSupport::Deprecation.warn "ActionView::TestCase#_assigns is deprecated and will be removed in future versions. " <<
- "Please use view_assigns instead."
- view_assigns
- end
-
def _routes
@controller._routes if @controller.respond_to?(:_routes)
end
diff --git a/actionpack/lib/sprockets/helpers.rb b/actionpack/lib/sprockets/helpers.rb
new file mode 100644
index 0000000000..a952a55c5e
--- /dev/null
+++ b/actionpack/lib/sprockets/helpers.rb
@@ -0,0 +1,5 @@
+module Sprockets
+ module Helpers
+ autoload :RailsHelper, "sprockets/helpers/rails_helper"
+ end
+end
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb
new file mode 100644
index 0000000000..a99dcad81d
--- /dev/null
+++ b/actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -0,0 +1,107 @@
+require "action_view/helpers/asset_paths"
+require "action_view/helpers/asset_tag_helper"
+
+module Sprockets
+ module Helpers
+ module RailsHelper
+ extend ActiveSupport::Concern
+ include ActionView::Helpers::AssetTagHelper
+
+ def asset_paths
+ @asset_paths ||= begin
+ config = self.config if respond_to?(:config)
+ controller = self.controller if respond_to?(:controller)
+ RailsHelper::AssetPaths.new(config, controller)
+ end
+ end
+
+ def javascript_include_tag(source, options = {})
+ debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
+ body = options.key?(:body) ? options.delete(:body) : false
+
+ if debug && asset = asset_paths.asset_for(source, 'js')
+ asset.to_a.map { |dep|
+ javascript_include_tag(dep, :debug => false, :body => true)
+ }.join("\n").html_safe
+ else
+ options = {
+ 'type' => "text/javascript",
+ 'src' => asset_path(source, 'js', body)
+ }.merge(options.stringify_keys)
+
+ content_tag 'script', "", options
+ end
+ end
+
+ def stylesheet_link_tag(source, options = {})
+ debug = options.key?(:debug) ? options.delete(:debug) : debug_assets?
+ body = options.key?(:body) ? options.delete(:body) : false
+
+ if debug && asset = asset_paths.asset_for(source, 'css')
+ asset.to_a.map { |dep|
+ stylesheet_link_tag(dep, :debug => false, :body => true)
+ }.join("\n").html_safe
+ else
+ options = {
+ 'rel' => "stylesheet",
+ 'type' => "text/css",
+ 'media' => "screen",
+ 'href' => asset_path(source, 'css', body)
+ }.merge(options.stringify_keys)
+
+ tag 'link', options
+ end
+ end
+
+ private
+ def debug_assets?
+ params[:debug_assets] == '1' ||
+ params[:debug_assets] == 'true'
+ end
+
+ def asset_path(source, default_ext = nil, body = false)
+ source = source.logical_path if source.respond_to?(:logical_path)
+ path = asset_paths.compute_public_path(source, 'assets', default_ext, true)
+ body ? "#{path}?body=1" : path
+ end
+
+ class AssetPaths < ActionView::Helpers::AssetPaths #:nodoc:
+ def compute_public_path(source, dir, ext=nil, include_host=true)
+ super(source, 'assets', ext, include_host)
+ end
+
+ def asset_for(source, ext)
+ source = source.to_s
+ return nil if is_uri?(source)
+ source = rewrite_extension(source, nil, ext)
+ assets[source]
+ end
+
+ def rewrite_asset_path(source, dir)
+ if source[0] == ?/
+ source
+ else
+ assets.path(source, performing_caching?, dir)
+ end
+ end
+
+ def rewrite_extension(source, dir, ext)
+ if ext && File.extname(source).empty?
+ "#{source}.#{ext}"
+ else
+ source
+ end
+ end
+
+ def assets
+ Rails.application.assets
+ end
+
+ # When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
+ def performing_caching?
+ @config ? @config.perform_caching : Rails.application.config.action_controller.perform_caching
+ end
+ end
+ end
+ end
+end
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index 8cee3babe2..7b8a7ad3bb 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -1,5 +1,7 @@
module Sprockets
- class Railtie < Rails::Railtie
+ autoload :Helpers, "sprockets/helpers"
+
+ class Railtie < ::Rails::Railtie
def self.using_coffee?
require 'coffee-script'
defined?(CoffeeScript)
@@ -7,15 +9,7 @@ module Sprockets
false
end
- def self.using_scss?
- require 'sass'
- defined?(Sass)
- rescue LoadError
- false
- end
-
config.app_generators.javascript_engine :coffee if using_coffee?
- config.app_generators.stylesheet_engine :scss if using_scss?
# Configure ActionController to use sprockets.
initializer "sprockets.set_configs", :after => "action_controller.set_configs" do |app|
@@ -26,7 +20,8 @@ module Sprockets
# We need to configure this after initialization to ensure we collect
# paths from all engines. This hook is invoked exactly before routes
- # are compiled.
+ # are compiled, and so that other Railties have an opportunity to
+ # register compressors.
config.after_initialize do |app|
assets = app.config.assets
next unless assets.enabled
@@ -34,8 +29,10 @@ module Sprockets
app.assets = asset_environment(app)
ActiveSupport.on_load(:action_view) do
+ include ::Sprockets::Helpers::RailsHelper
+
app.assets.context_class.instance_eval do
- include ::ActionView::Helpers::SprocketsHelper
+ include ::Sprockets::Helpers::RailsHelper
end
end
@@ -57,8 +54,8 @@ module Sprockets
env.static_root = File.join(app.root.join("public"), assets.prefix)
env.paths.concat assets.paths
env.logger = Rails.logger
- env.js_compressor = expand_js_compressor(assets.js_compressor)
- env.css_compressor = expand_css_compressor(assets.css_compressor)
+ env.js_compressor = expand_js_compressor(assets.js_compressor) if assets.compress
+ env.css_compressor = expand_css_compressor(assets.css_compressor) if assets.compress
env
end
@@ -80,15 +77,6 @@ module Sprockets
def expand_css_compressor(sym)
case sym
- when :scss
- require 'sass'
- compressor = Object.new
- def compressor.compress(source)
- Sass::Engine.new(source,
- :syntax => :scss, :style => :compressed
- ).render
- end
- compressor
when :yui
require 'yui/compressor'
YUI::CssCompressor.new
diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb
index b87b9f9c47..2d789395ce 100644
--- a/actionpack/test/activerecord/controller_runtime_test.rb
+++ b/actionpack/test/activerecord/controller_runtime_test.rb
@@ -15,6 +15,17 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
def zero
render :inline => "Zero DB runtime"
end
+
+ def redirect
+ Project.all
+ redirect_to :action => 'show'
+ end
+
+ def db_after_render
+ render :inline => "Hello world"
+ Project.all
+ ActiveRecord::LogSubscriber.runtime += 100
+ end
end
include ActiveSupport::LogSubscriber::TestHelper
@@ -52,4 +63,19 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
assert_equal 2, @logger.logged(:info).size
assert_match(/\(Views: [\d.]+ms \| ActiveRecord: 0.0ms\)/, @logger.logged(:info)[1])
end
+
+ def test_log_with_active_record_when_redirecting
+ get :redirect
+ wait
+ assert_equal 3, @logger.logged(:info).size
+ assert_match(/\(ActiveRecord: [\d.]+ms\)/, @logger.logged(:info)[2])
+ end
+
+ def test_include_time_query_time_after_rendering
+ get :db_after_render
+ wait
+
+ assert_equal 2, @logger.logged(:info).size
+ assert_match(/\(Views: [\d.]+ms \| ActiveRecord: ([1-9][\d.]+)ms\)/, @logger.logged(:info)[1])
+ end
end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index fada0c7748..82c2c23607 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -187,6 +187,9 @@ class ActionCachingTestController < CachingController
rescue_from(ActiveRecord::RecordNotFound) { head :not_found }
end
+ # Eliminate uninitialized ivar warning
+ before_filter { @title = nil }
+
caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour
caches_action :show, :cache_path => 'http://test.host/custom/show'
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
diff --git a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb b/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
deleted file mode 100644
index 0c02afea36..0000000000
--- a/actionpack/test/controller/deprecation/deprecated_base_methods_test.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'abstract_unit'
-
-class DeprecatedBaseMethodsTest < ActionController::TestCase
- class Target < ActionController::Base
- def home_url(greeting)
- "http://example.com/#{greeting}"
- end
-
- def raises_name_error
- this_method_doesnt_exist
- end
-
- def rescue_action(e) raise e end
- end
-
- tests Target
-
- if defined? Test::Unit::Error
- def test_assertion_failed_error_silences_deprecation_warnings
- get :raises_name_error
- rescue => e
- error = Test::Unit::Error.new('testing ur doodz', e)
- assert_not_deprecated { error.message }
- end
- end
-end
diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb
index 9f0670ffdf..584d73668a 100644
--- a/actionpack/test/controller/helper_test.rb
+++ b/actionpack/test/controller/helper_test.rb
@@ -77,7 +77,7 @@ class HelperTest < ActiveSupport::TestCase
self.test_helper = LocalAbcHelper
end
- def test_deprecated_helper
+ def test_helper
assert_equal expected_helper_methods, missing_methods
assert_nothing_raised { @controller_class.helper TestHelper }
assert_equal [], missing_methods
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 4a5e597500..26270571cf 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -498,6 +498,12 @@ class RespondToControllerTest < ActionController::TestCase
assert_equal '<html><div id="iphone">Hello iPhone future from iPhone!</div></html>', @response.body
assert_equal "text/html", @response.content_type
end
+
+ def test_invalid_format
+ get :using_defaults, :format => "invalidformat"
+ assert_equal " ", @response.body
+ assert_equal "text/html", @response.content_type
+ end
end
class RespondWithController < ActionController::Base
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index e62f3155c5..be59da9105 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -1023,11 +1023,6 @@ class RenderTest < ActionController::TestCase
assert_equal " ", @response.body
end
- def test_render_to_string_not_deprecated
- assert_not_deprecated { get :hello_in_a_string }
- assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body
- end
-
def test_render_to_string_doesnt_break_assigns
get :render_to_string_with_assigns
assert_equal "i'm before the render", assigns(:before)
@@ -1106,7 +1101,7 @@ class RenderTest < ActionController::TestCase
end
def test_yield_content_for
- assert_not_deprecated { get :yield_content_for }
+ get :yield_content_for
assert_equal "<title>Putting stuff in the title!</title>\nGreat stuff!\n", @response.body
end
diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb
index dea80ed887..d94db7f5fb 100644
--- a/actionpack/test/controller/request_forgery_protection_test.rb
+++ b/actionpack/test/controller/request_forgery_protection_test.rb
@@ -80,7 +80,7 @@ module RequestForgeryProtectionTests
def setup
@token = "cf50faa3fe97702ca1ae"
- ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
+ SecureRandom.stubs(:base64).returns(@token)
ActionController::Base.request_forgery_protection_token = :custom_authenticity_token
end
@@ -184,7 +184,7 @@ class RequestForgeryProtectionControllerTest < ActionController::TestCase
end
test 'should emit a csrf-param meta tag and a csrf-token meta tag' do
- ActiveSupport::SecureRandom.stubs(:base64).returns(@token + '<=?')
+ SecureRandom.stubs(:base64).returns(@token + '<=?')
get :meta
assert_select 'meta[name=?][content=?]', 'csrf-param', 'custom_authenticity_token'
assert_select 'meta[name=?][content=?]', 'csrf-token', 'cf50faa3fe97702ca1ae&lt;=?'
@@ -207,7 +207,7 @@ class FreeCookieControllerTest < ActionController::TestCase
@response = ActionController::TestResponse.new
@token = "cf50faa3fe97702ca1ae"
- ActiveSupport::SecureRandom.stubs(:base64).returns(@token)
+ SecureRandom.stubs(:base64).returns(@token)
end
def test_should_not_render_form_with_token_tag
diff --git a/actionpack/test/controller/view_paths_test.rb b/actionpack/test/controller/view_paths_test.rb
index 3de1849db8..f5ac886c20 100644
--- a/actionpack/test/controller/view_paths_test.rb
+++ b/actionpack/test/controller/view_paths_test.rb
@@ -32,17 +32,11 @@ class ViewLoadPathsTest < ActionController::TestCase
@controller.send :assign_shortcuts, @request, @response
@controller.send :initialize_template_class, @response
- # Track the last warning.
- @old_behavior = ActiveSupport::Deprecation.behavior
- @last_message = nil
- ActiveSupport::Deprecation.behavior = Proc.new { |message, callback| @last_message = message }
-
@paths = TestController.view_paths
end
def teardown
TestController.view_paths = @paths
- ActiveSupport::Deprecation.behavior = @old_behavior
end
def expand(array)
@@ -179,7 +173,7 @@ class ViewLoadPathsTest < ActionController::TestCase
assert_nothing_raised { C.append_view_path 'c/path' }
assert_paths C, "c/path"
end
-
+
def test_lookup_context_accessor
assert_equal ["test"], TestController.new.lookup_context.prefixes
end
diff --git a/actionpack/test/dispatch/response_body_is_proc_test.rb b/actionpack/test/dispatch/response_body_is_proc_test.rb
deleted file mode 100644
index fd94832624..0000000000
--- a/actionpack/test/dispatch/response_body_is_proc_test.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require 'abstract_unit'
-
-class ResponseBodyIsProcTest < ActionDispatch::IntegrationTest
- class TestController < ActionController::Base
- def test
- self.response_body = proc { |response, output|
- output.write 'Hello'
- }
- end
- end
-
- def test_simple_get
- with_test_route_set do
- assert_deprecated do
- get '/test'
- end
- assert_response :success
- assert_equal 'Hello', response.body
- end
- end
-
- private
-
- def with_test_route_set(options = {})
- with_routing do |set|
- set.draw do
- match ':action', :to => ::ResponseBodyIsProcTest::TestController
- end
-
- @app = self.class.build_app(set) do |middleware|
- middleware.delete "ActionDispatch::ShowExceptions"
- end
-
- yield
- end
- end
-end
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index b0efbcef4a..301bf9c6d2 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -6,7 +6,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
- SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16))
+ SignedBar = Verifier.generate(:foo => "bar", :session_id => SecureRandom.hex(16))
class TestController < ActionController::Base
def no_session_access
diff --git a/actionpack/test/fixtures/sprockets/app/javascripts/application.js b/actionpack/test/fixtures/sprockets/app/javascripts/application.js
index e69de29bb2..e611d2b129 100644
--- a/actionpack/test/fixtures/sprockets/app/javascripts/application.js
+++ b/actionpack/test/fixtures/sprockets/app/javascripts/application.js
@@ -0,0 +1 @@
+//= require xmlhr
diff --git a/actionpack/test/fixtures/sprockets/app/stylesheets/application.css b/actionpack/test/fixtures/sprockets/app/stylesheets/application.css
index e69de29bb2..2365eaa4cd 100644
--- a/actionpack/test/fixtures/sprockets/app/stylesheets/application.css
+++ b/actionpack/test/fixtures/sprockets/app/stylesheets/application.css
@@ -0,0 +1 @@
+/*= require style */
diff --git a/actionpack/test/fixtures/test/deprecated_nested_layout.erb b/actionpack/test/fixtures/test/deprecated_nested_layout.erb
deleted file mode 100644
index 7b6dcbb6c7..0000000000
--- a/actionpack/test/fixtures/test/deprecated_nested_layout.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<% content_for :title, "title" -%>
-<% content_for :column do -%>column<% end -%>
-<% render :layout => 'layouts/column' do -%>content<% end -%> \ No newline at end of file
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 286bfb4d04..f2a49f7a68 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -974,6 +974,22 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_index_and_parent_fields
+ form_for(@post, :index => 1) do |c|
+ concat c.text_field(:title)
+ concat c.fields_for_with_index('comment', @comment, :index => 1) { |r, comment_index|
+ concat r.text_field(:name, "data-index" => comment_index)
+ }
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
+ "<input name='post[1][title]' size='30' type='text' id='post_1_title' value='Hello World' />" +
+ "<input name='post[1][comment][1][name]' size='30' type='text' id='post_1_comment_1_name' value='new comment' data-index='1' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_form_for_with_index_and_nested_fields_for
output_buffer = form_for(@post, :index => 1) do |f|
concat f.fields_for(:comment, @post) { |c|
@@ -1030,6 +1046,20 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_index_radio_button
+ form_for(@post) do |f|
+ concat f.fields_for_with_index(:comment, @post, :index => 5) { |c, index|
+ concat c.radio_button(:title, "hello", "data-index" => index)
+ }
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', 'put') do
+ "<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' data-index='5' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_with_auto_index_on_both
form_for(@post, :as => "post[]") do |f|
concat f.fields_for("comment[]", @post) { |c|
@@ -1229,6 +1259,29 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_existing_records_on_a_nested_attributes_collection_association
+ @post.comments = Array.new(2) { |id| Comment.new(id + 1) }
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment) { |cf, index|
+ concat cf.text_field(:name, "data-index" => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" data-index="0" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" data-index="1" />' +
+ '<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)
@@ -1256,6 +1309,33 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id
+ @post.comments = Array.new(2) { |id| Comment.new(id + 1) }
+ @post.author = Author.new(321)
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ concat f.fields_for(:author) { |af|
+ concat af.text_field(:name)
+ }
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment, :include_id => false) { |cf, index|
+ concat cf.text_field(:name, 'data-index' => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_author_attributes_name" name="post[author_attributes][name]" size="30" type="text" value="author #321" />' +
+ '<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #1" data-index="0" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="comment #2" data-index="1" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_collection_association_with_disabled_hidden_id_inherited
@post.comments = Array.new(2) { |id| Comment.new(id + 1) }
@post.author = Author.new(321)
@@ -1377,6 +1457,28 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_new_records_on_a_nested_attributes_collection_association
+ @post.comments = [Comment.new, Comment.new]
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment) { |cf, index|
+ concat cf.text_field(:name, "data-index" => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="new comment" data-index="0" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" data-index="1" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
+
def test_nested_fields_for_with_existing_and_new_records_on_a_nested_attributes_collection_association
@post.comments = [Comment.new(321), Comment.new]
@@ -1399,6 +1501,29 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_nested_fields_for_with_index_with_existing_and_new_records_on_a_nested_attributes_collection_association
+ @post.comments = [Comment.new(321), Comment.new]
+
+ form_for(@post) do |f|
+ concat f.text_field(:title)
+ @post.comments.each do |comment|
+ concat f.fields_for_with_index(:comments, comment) { |cf, index|
+ concat cf.text_field(:name, "data-index" => index)
+ }
+ end
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'put') do
+ '<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
+ '<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" size="30" type="text" value="comment #321" data-index="0" />' +
+ '<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
+ '<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" size="30" type="text" value="new comment" data-index="1" />'
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
+
def test_nested_fields_for_with_an_empty_supplied_attributes_collection
form_for(@post) do |f|
concat f.text_field(:title)
diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb
index 63b92aadf4..0104c20bc7 100644
--- a/actionpack/test/template/number_helper_test.rb
+++ b/actionpack/test/template/number_helper_test.rb
@@ -19,15 +19,6 @@ class NumberHelperTest < ActionView::TestCase
gigabytes(number) * 1024
end
- def silence_deprecation_warnings
- @old_deprecatios_silenced = ActiveSupport::Deprecation.silenced
- ActiveSupport::Deprecation.silenced = true
- end
-
- def restore_deprecation_warnings
- ActiveSupport::Deprecation.silenced = @old_deprecatios_silenced
- end
-
def test_number_to_phone
assert_equal("555-1234", number_to_phone(5551234))
assert_equal("800-555-1212", number_to_phone(8005551212))
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index 8d3be09a4f..ebb7e48d70 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -1,11 +1,10 @@
require 'abstract_unit'
require 'sprockets'
+require 'sprockets/helpers/rails_helper'
require 'mocha'
-module Rails; end
-
class SprocketsHelperTest < ActionView::TestCase
- tests ActionView::Helpers::SprocketsHelper
+ tests Sprockets::Helpers::RailsHelper
attr_accessor :assets
@@ -13,6 +12,7 @@ class SprocketsHelperTest < ActionView::TestCase
super
@controller = BasicController.new
+ @controller.stubs(:params).returns({})
@request = Class.new do
def protocol() 'http://' end
@@ -57,6 +57,12 @@ class SprocketsHelperTest < ActionView::TestCase
asset_path("http://www.example.com/video/play.mp4")
end
+ test "asset path with relative url root" do
+ @controller.config.relative_url_root = "/collaboration/hieraki"
+ assert_equal "/collaboration/hieraki/images/logo.gif",
+ asset_path("/images/logo.gif")
+ end
+
test "javascript path" do
assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js",
asset_path(:application, "js")
@@ -77,18 +83,21 @@ class SprocketsHelperTest < ActionView::TestCase
test "javascript include tag" do
assert_equal '<script src="/assets/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
- sprockets_javascript_include_tag(:application)
+ javascript_include_tag(:application)
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
- sprockets_javascript_include_tag("xmlhr")
+ javascript_include_tag("xmlhr")
assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
- sprockets_javascript_include_tag("xmlhr.js")
+ javascript_include_tag("xmlhr.js")
assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>',
- sprockets_javascript_include_tag("http://www.example.com/xmlhr")
+ javascript_include_tag("http://www.example.com/xmlhr")
+
+ assert_equal "<script src=\"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>\n<script src=\"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js?body=1\" type=\"text/javascript\"></script>",
+ javascript_include_tag(:application, :debug => true)
end
test "stylesheet path" do
- assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", asset_path(:application, "css")
+ assert_equal "/assets/application-68b329da9893e34099c7d8ad5cb9c940.css", asset_path(:application, "css")
assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css")
assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css")
@@ -101,19 +110,22 @@ class SprocketsHelperTest < ActionView::TestCase
end
test "stylesheet link tag" do
- assert_equal '<link href="/assets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag(:application)
+ assert_equal '<link href="/assets/application-68b329da9893e34099c7d8ad5cb9c940.css" media="screen" rel="stylesheet" type="text/css" />',
+ stylesheet_link_tag(:application)
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style")
+ stylesheet_link_tag("style")
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style.css")
+ stylesheet_link_tag("style.css")
assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("http://www.example.com/style.css")
+ stylesheet_link_tag("http://www.example.com/style.css")
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style", :media => "all")
+ stylesheet_link_tag("style", :media => "all")
assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
- sprockets_stylesheet_link_tag("style", :media => "print")
+ stylesheet_link_tag("style", :media => "print")
+
+ assert_equal "<link href=\"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"/assets/application-68b329da9893e34099c7d8ad5cb9c940.css?body=1\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />",
+ stylesheet_link_tag(:application, :debug => true)
end
end
diff --git a/actionpack/test/template/streaming_render_test.rb b/actionpack/test/template/streaming_render_test.rb
index b2df8efee3..023ce723ed 100644
--- a/actionpack/test/template/streaming_render_test.rb
+++ b/actionpack/test/template/streaming_render_test.rb
@@ -8,7 +8,7 @@ end
class FiberedTest < ActiveSupport::TestCase
def setup
view_paths = ActionController::Base.view_paths
- @assigns = { :secret => 'in the sauce' }
+ @assigns = { :secret => 'in the sauce', :name => nil }
@view = ActionView::Base.new(view_paths, @assigns)
@controller_view = TestController.new.view_context
end
@@ -106,4 +106,4 @@ class FiberedTest < ActiveSupport::TestCase
buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming")
end
-end if defined?(Fiber) \ No newline at end of file
+end if defined?(Fiber)
diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb
index cd4618a505..f463675a2e 100644
--- a/actionpack/test/template/test_case_test.rb
+++ b/actionpack/test/template/test_case_test.rb
@@ -141,22 +141,6 @@ module ActionView
end
end
- class AssignsTest < ActionView::TestCase
- setup do
- ActiveSupport::Deprecation.stubs(:warn)
- end
-
- test "_assigns delegates to user_defined_ivars" do
- self.expects(:view_assigns)
- _assigns
- end
-
- test "_assigns is deprecated" do
- ActiveSupport::Deprecation.expects(:warn)
- _assigns
- end
- end
-
class ViewAssignsTest < ActionView::TestCase
test "view_assigns returns a Hash of user defined ivars" do
@a = 'b'
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 8d0f0124c2..4aa45c8bf0 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -25,6 +25,8 @@ class UrlHelperTest < ActiveSupport::TestCase
include ActionView::Context
include RenderERBUtils
+ setup :_prepare_context
+
def hash_for(opts = [])
ActiveSupport::OrderedHash[*([:controller, "foo", :action, "bar"].concat(opts))]
end
diff --git a/activemodel/Rakefile b/activemodel/Rakefile
index 0a10912695..c4b020196d 100755
--- a/activemodel/Rakefile
+++ b/activemodel/Rakefile
@@ -20,11 +20,11 @@ namespace :test do
end
require 'rake/packagetask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
spec = eval(File.read("#{dir}/activemodel.gemspec"))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
diff --git a/activemodel/activemodel.gemspec b/activemodel/activemodel.gemspec
index 22c0a6224f..562f07fcd7 100644
--- a/activemodel/activemodel.gemspec
+++ b/activemodel/activemodel.gemspec
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
s.add_dependency('activesupport', version)
s.add_dependency('builder', '~> 3.0.0')
- s.add_dependency('i18n', '~> 0.6.0beta1')
+ s.add_dependency('i18n', '~> 0.6')
s.add_dependency('bcrypt-ruby', '~> 2.1.4')
end
diff --git a/activemodel/lib/active_model/callbacks.rb b/activemodel/lib/active_model/callbacks.rb
index 2a1f51a9a7..37d0c9a0b9 100644
--- a/activemodel/lib/active_model/callbacks.rb
+++ b/activemodel/lib/active_model/callbacks.rb
@@ -59,7 +59,7 @@ module ActiveModel
# define_model_callbacks :initializer, :only => :after
#
# Note, the <tt>:only => <type></tt> hash will apply to all callbacks defined on
- # that method call. To get around this you can call the define_model_callbacks
+ # that method call. To get around this you can call the define_model_callbacks
# method as many times as you need.
#
# define_model_callbacks :create, :only => :after
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 22ca3efa2b..0e2a2fd5e2 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -49,8 +49,8 @@ module ActiveModel
#
# The last three methods are required in your object for Errors to be
# able to generate error messages correctly and also handle multiple
- # languages. Of course, if you extend your object with ActiveModel::Translations
- # you will not need to implement the last two. Likewise, using
+ # languages. Of course, if you extend your object with ActiveModel::Translations
+ # you will not need to implement the last two. Likewise, using
# ActiveModel::Validations will handle the validation related methods
# for you.
#
@@ -117,7 +117,7 @@ module ActiveModel
end
# Iterates through each error key, value pair in the error messages hash.
- # Yields the attribute and the error for that attribute. If the attribute
+ # Yields the attribute and the error for that attribute. If the attribute
# has more than one error message, yields once for each error message.
#
# p.errors.add(:name, "can't be blank")
diff --git a/activemodel/lib/active_model/mass_assignment_security.rb b/activemodel/lib/active_model/mass_assignment_security.rb
index 483b577681..cc30609f2b 100644
--- a/activemodel/lib/active_model/mass_assignment_security.rb
+++ b/activemodel/lib/active_model/mass_assignment_security.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/class/attribute.rb'
require 'active_model/mass_assignment_security/permission_set'
+require 'active_model/mass_assignment_security/sanitizer'
module ActiveModel
# = Active Model Mass-Assignment Security
@@ -10,6 +11,7 @@ module ActiveModel
class_attribute :_accessible_attributes
class_attribute :_protected_attributes
class_attribute :_active_authorizer
+ class_attribute :mass_assignment_sanitizer
end
# Mass assignment security provides an interface for protecting attributes
@@ -181,16 +183,14 @@ module ActiveModel
def protected_attributes_configs
self._protected_attributes ||= begin
- default_black_list = BlackList.new(attributes_protected_by_default).tap do |w|
- w.logger = self.logger if self.respond_to?(:logger)
- end
+ default_black_list = BlackList.new(attributes_protected_by_default)
Hash.new(default_black_list)
end
end
def accessible_attributes_configs
self._accessible_attributes ||= begin
- default_white_list = WhiteList.new.tap { |w| w.logger = self.logger if self.respond_to?(:logger) }
+ default_white_list = WhiteList.new
Hash.new(default_white_list)
end
end
@@ -199,7 +199,11 @@ module ActiveModel
protected
def sanitize_for_mass_assignment(attributes, role = :default)
- mass_assignment_authorizer(role).sanitize(attributes)
+ (mass_assignment_sanitizer || default_mass_assignment_sanitizer).sanitize(attributes, mass_assignment_authorizer(role))
+ end
+
+ def default_mass_assignment_sanitizer
+ DefaultSanitizer.new(self.respond_to?(:logger) && self.logger)
end
def mass_assignment_authorizer(role = :default)
diff --git a/activemodel/lib/active_model/mass_assignment_security/permission_set.rb b/activemodel/lib/active_model/mass_assignment_security/permission_set.rb
index 9fcb94d48a..a1fcdf1a38 100644
--- a/activemodel/lib/active_model/mass_assignment_security/permission_set.rb
+++ b/activemodel/lib/active_model/mass_assignment_security/permission_set.rb
@@ -1,10 +1,8 @@
require 'set'
-require 'active_model/mass_assignment_security/sanitizer'
module ActiveModel
module MassAssignmentSecurity
class PermissionSet < Set
- attr_accessor :logger
def +(values)
super(values.map(&:to_s))
@@ -14,6 +12,10 @@ module ActiveModel
super(remove_multiparameter_id(key))
end
+ def deny?(key)
+ raise NotImplementedError, "#deny?(key) suppose to be overwritten"
+ end
+
protected
def remove_multiparameter_id(key)
@@ -22,7 +24,6 @@ module ActiveModel
end
class WhiteList < PermissionSet
- include Sanitizer
def deny?(key)
!include?(key)
@@ -30,7 +31,6 @@ module ActiveModel
end
class BlackList < PermissionSet
- include Sanitizer
def deny?(key)
include?(key)
diff --git a/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb b/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb
index 150beb1ff2..5dbcf473bd 100644
--- a/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb
+++ b/activemodel/lib/active_model/mass_assignment_security/sanitizer.rb
@@ -1,9 +1,9 @@
module ActiveModel
module MassAssignmentSecurity
- module Sanitizer
+ class Sanitizer
# Returns all attributes not denied by the authorizer.
- def sanitize(attributes)
- sanitized_attributes = attributes.reject { |key, value| deny?(key) }
+ def sanitize(attributes, authorizer)
+ sanitized_attributes = attributes.reject { |key, value| authorizer.deny?(key) }
debug_protected_attribute_removal(attributes, sanitized_attributes)
sanitized_attributes
end
@@ -12,10 +12,24 @@ module ActiveModel
def debug_protected_attribute_removal(attributes, sanitized_attributes)
removed_keys = attributes.keys - sanitized_attributes.keys
- warn!(removed_keys) if removed_keys.any?
+ process_removed_attributes(removed_keys) if removed_keys.any?
end
+
+ def process_removed_attributes(attrs)
+ raise NotImplementedError, "#process_removed_attributes(attrs) suppose to be overwritten"
+ end
+
+ end
+ class DefaultSanitizer < Sanitizer
- def warn!(attrs)
+ attr_accessor :logger
+
+ def initialize(logger = nil)
+ self.logger = logger
+ super()
+ end
+
+ def process_removed_attributes(attrs)
self.logger.debug "WARNING: Can't mass-assign protected attributes: #{attrs.join(', ')}" if self.logger
end
end
diff --git a/activemodel/lib/active_model/observer_array.rb b/activemodel/lib/active_model/observer_array.rb
index 5fb73f1c78..3d463885be 100644
--- a/activemodel/lib/active_model/observer_array.rb
+++ b/activemodel/lib/active_model/observer_array.rb
@@ -15,7 +15,7 @@ module ActiveModel
disabled_observers.include?(observer.class)
end
- # Disables one or more observers. This supports multiple forms:
+ # Disables one or more observers. This supports multiple forms:
#
# ORM.observers.disable :user_observer
# # => disables the UserObserver
@@ -38,7 +38,7 @@ module ActiveModel
set_enablement(false, observers, &block)
end
- # Enables one or more observers. This supports multiple forms:
+ # Enables one or more observers. This supports multiple forms:
#
# ORM.observers.enable :user_observer
# # => enables the UserObserver
@@ -59,7 +59,7 @@ module ActiveModel
# # just the duration of the block
# end
#
- # Note: all observers are enabled by default. This method is only
+ # Note: all observers are enabled by default. This method is only
# useful when you have previously disabled one or more observers.
def enable(*observers, &block)
set_enablement(true, observers, &block)
diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb
index ee94ad66cf..63380d6ffd 100644
--- a/activemodel/lib/active_model/secure_password.rb
+++ b/activemodel/lib/active_model/secure_password.rb
@@ -30,7 +30,7 @@ module ActiveModel
# User.find_by_name("david").try(:authenticate, "notright") # => nil
# User.find_by_name("david").try(:authenticate, "mUc3m00RsqyRe") # => user
def has_secure_password
- attr_reader :password
+ attr_reader :password
validates_confirmation_of :password
validates_presence_of :password_digest
diff --git a/activemodel/lib/active_model/serialization.rb b/activemodel/lib/active_model/serialization.rb
index caf44a2ee0..4a174cb62a 100644
--- a/activemodel/lib/active_model/serialization.rb
+++ b/activemodel/lib/active_model/serialization.rb
@@ -31,7 +31,7 @@ module ActiveModel
# you want to serialize and their current value.
#
# Most of the time though, you will want to include the JSON or XML
- # serializations. Both of these modules automatically include the
+ # serializations. Both of these modules automatically include the
# ActiveModel::Serialization module, so there is no need to explicitly
# include it.
#
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb
index eb3975f86b..f6aae24324 100644
--- a/activemodel/lib/active_model/serializers/xml.rb
+++ b/activemodel/lib/active_model/serializers/xml.rb
@@ -55,10 +55,10 @@ module ActiveModel
end
# To replicate the behavior in ActiveRecord#attributes, <tt>:except</tt>
- # takes precedence over <tt>:only</tt>. If <tt>:only</tt> is not set
+ # takes precedence over <tt>:only</tt>. If <tt>:only</tt> is not set
# for a N level model but is set for the N+1 level models,
# then because <tt>:except</tt> is set to a default value, the second
- # level model can have both <tt>:except</tt> and <tt>:only</tt> set. So if
+ # level model can have both <tt>:except</tt> and <tt>:only</tt> set. So if
# <tt>:only</tt> is set, always delete <tt>:except</tt>.
def attributes_hash
attributes = @serializable.attributes
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 5e567307f3..8ed392abca 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -81,7 +81,7 @@ module ActiveModel
# proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or
- # <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_each(*attr_names, &block)
options = attr_names.extract_options!.symbolize_keys
diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb
index 4f390613aa..01907ac9da 100644
--- a/activemodel/lib/active_model/validations/acceptance.rb
+++ b/activemodel/lib/active_model/validations/acceptance.rb
@@ -49,7 +49,7 @@ module ActiveModel
# before validation.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
# if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
- # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false
# value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
diff --git a/activemodel/lib/active_model/validations/confirmation.rb b/activemodel/lib/active_model/validations/confirmation.rb
index e6d10cfff8..a9dcb0b505 100644
--- a/activemodel/lib/active_model/validations/confirmation.rb
+++ b/activemodel/lib/active_model/validations/confirmation.rb
@@ -50,7 +50,7 @@ module ActiveModel
# and <tt>:update</tt>.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine
# if the validation should occur (e.g. <tt>:if => :allow_validation</tt>,
- # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false
# value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to
diff --git a/activemodel/lib/active_model/validations/exclusion.rb b/activemodel/lib/active_model/validations/exclusion.rb
index a85c23f725..ab4de3c459 100644
--- a/activemodel/lib/active_model/validations/exclusion.rb
+++ b/activemodel/lib/active_model/validations/exclusion.rb
@@ -54,10 +54,10 @@ module ActiveModel
# validation contexts by default (+nil+), other options are <tt>:create</tt>
# and <tt>:update</tt>.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_exclusion_of(*attr_names)
validates_with ExclusionValidator, _merge_attributes(attr_names)
diff --git a/activemodel/lib/active_model/validations/format.rb b/activemodel/lib/active_model/validations/format.rb
index 6f23d492eb..090e8cfbae 100644
--- a/activemodel/lib/active_model/validations/format.rb
+++ b/activemodel/lib/active_model/validations/format.rb
@@ -79,10 +79,10 @@ module ActiveModel
# validation contexts by default (+nil+), other options are <tt>:create</tt>
# and <tt>:update</tt>.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_format_of(*attr_names)
validates_with FormatValidator, _merge_attributes(attr_names)
diff --git a/activemodel/lib/active_model/validations/inclusion.rb b/activemodel/lib/active_model/validations/inclusion.rb
index d32aebeb88..bfb65d2f3f 100644
--- a/activemodel/lib/active_model/validations/inclusion.rb
+++ b/activemodel/lib/active_model/validations/inclusion.rb
@@ -54,10 +54,10 @@ module ActiveModel
# validation contexts by default (+nil+), other options are <tt>:create</tt>
# and <tt>:update</tt>.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_inclusion_of(*attr_names)
validates_with InclusionValidator, _merge_attributes(attr_names)
diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb
index d595a5fb43..48d14978fa 100644
--- a/activemodel/lib/active_model/validations/length.rb
+++ b/activemodel/lib/active_model/validations/length.rb
@@ -83,15 +83,15 @@ module ActiveModel
# * <tt>:too_long</tt> - The error message if the attribute goes over the maximum (default is: "is too long (maximum is %{count} characters)").
# * <tt>:too_short</tt> - The error message if the attribute goes under the minimum (default is: "is too short (min is %{count} characters)").
# * <tt>:wrong_length</tt> - The error message if using the <tt>:is</tt> method and the attribute is the wrong size (default is: "is the wrong length (should be %{count} characters)").
- # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
+ # * <tt>:message</tt> - The error message to use for a <tt>:minimum</tt>, <tt>:maximum</tt>, or <tt>:is</tt> violation. An alias of the appropriate <tt>too_long</tt>/<tt>too_short</tt>/<tt>wrong_length</tt> message.
# * <tt>:on</tt> - Specifies when this validation is active. Runs in all
# validation contexts by default (+nil+), other options are <tt>:create</tt>
# and <tt>:update</tt>.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:tokenizer</tt> - Specifies how to split up the attribute string. (e.g. <tt>:tokenizer => lambda {|str| str.scan(/\w+/)}</tt> to
# count words as in above example.)
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb
index 42556c80a9..0d1903362c 100644
--- a/activemodel/lib/active_model/validations/numericality.rb
+++ b/activemodel/lib/active_model/validations/numericality.rb
@@ -102,10 +102,10 @@ module ActiveModel
# * <tt>:odd</tt> - Specifies the value must be an odd number.
# * <tt>:even</tt> - Specifies the value must be an even number.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
#
# The following checks can also be supplied with a proc or a symbol which corresponds to a method:
diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb
index 01f0158678..2e860272a4 100644
--- a/activemodel/test/cases/helper.rb
+++ b/activemodel/test/cases/helper.rb
@@ -10,5 +10,4 @@ require 'active_support/core_ext/string/access'
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
-require 'rubygems'
require 'test/unit'
diff --git a/activemodel/test/cases/mass_assignment_security/black_list_test.rb b/activemodel/test/cases/mass_assignment_security/black_list_test.rb
index ed168bc016..0ec7f8719c 100644
--- a/activemodel/test/cases/mass_assignment_security/black_list_test.rb
+++ b/activemodel/test/cases/mass_assignment_security/black_list_test.rb
@@ -16,13 +16,5 @@ class BlackListTest < ActiveModel::TestCase
assert_equal false, @black_list.deny?('first_name')
end
- test "sanitize attributes" do
- original_attributes = { 'first_name' => 'allowed', 'admin' => 'denied', 'admin(1)' => 'denied' }
- attributes = @black_list.sanitize(original_attributes)
-
- assert attributes.key?('first_name'), "Allowed key shouldn't be rejected"
- assert !attributes.key?('admin'), "Denied key should be rejected"
- assert !attributes.key?('admin(1)'), "Multi-parameter key should be detected"
- end
end
diff --git a/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb b/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb
index 9a73a5ad91..8547694c24 100644
--- a/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb
+++ b/activemodel/test/cases/mass_assignment_security/sanitizer_test.rb
@@ -4,24 +4,21 @@ require 'active_support/core_ext/object/inclusion'
class SanitizerTest < ActiveModel::TestCase
- class SanitizingAuthorizer
- include ActiveModel::MassAssignmentSecurity::Sanitizer
-
- attr_accessor :logger
+ class Authorizer < ActiveModel::MassAssignmentSecurity::PermissionSet
def deny?(key)
key.in?(['admin'])
end
-
end
def setup
- @sanitizer = SanitizingAuthorizer.new
+ @sanitizer = ActiveModel::MassAssignmentSecurity::DefaultSanitizer.new
+ @authorizer = Authorizer.new
end
test "sanitize attributes" do
original_attributes = { 'first_name' => 'allowed', 'admin' => 'denied' }
- attributes = @sanitizer.sanitize(original_attributes)
+ attributes = @sanitizer.sanitize(original_attributes, @authorizer)
assert attributes.key?('first_name'), "Allowed key shouldn't be rejected"
assert !attributes.key?('admin'), "Denied key should be rejected"
@@ -31,7 +28,7 @@ class SanitizerTest < ActiveModel::TestCase
original_attributes = { 'first_name' => 'allowed', 'admin' => 'denied' }
log = StringIO.new
@sanitizer.logger = Logger.new(log)
- @sanitizer.sanitize(original_attributes)
+ @sanitizer.sanitize(original_attributes, @authorizer)
assert_match(/admin/, log.string, "Should log removed attributes: #{log.string}")
end
diff --git a/activemodel/test/cases/mass_assignment_security/white_list_test.rb b/activemodel/test/cases/mass_assignment_security/white_list_test.rb
index aa3596ad2a..737b55492a 100644
--- a/activemodel/test/cases/mass_assignment_security/white_list_test.rb
+++ b/activemodel/test/cases/mass_assignment_security/white_list_test.rb
@@ -16,13 +16,4 @@ class WhiteListTest < ActiveModel::TestCase
assert_equal true, @white_list.deny?('admin')
end
- test "sanitize attributes" do
- original_attributes = { 'first_name' => 'allowed', 'admin' => 'denied', 'admin(1)' => 'denied' }
- attributes = @white_list.sanitize(original_attributes)
-
- assert attributes.key?('first_name'), "Allowed key shouldn't be rejected"
- assert !attributes.key?('admin'), "Denied key should be rejected"
- assert !attributes.key?('admin(1)'), "Multi-parameter key should be detected"
- end
-
end
diff --git a/activemodel/test/cases/mass_assignment_security_test.rb b/activemodel/test/cases/mass_assignment_security_test.rb
index 43a12eed61..a778240827 100644
--- a/activemodel/test/cases/mass_assignment_security_test.rb
+++ b/activemodel/test/cases/mass_assignment_security_test.rb
@@ -1,6 +1,15 @@
require "cases/helper"
require 'models/mass_assignment_specific'
+
+class CustomSanitizer < ActiveModel::MassAssignmentSecurity::Sanitizer
+
+ def process_removed_attributes(attrs)
+ raise StandardError
+ end
+
+end
+
class MassAssignmentSecurityTest < ActiveModel::TestCase
def test_attribute_protection
@@ -76,4 +85,15 @@ class MassAssignmentSecurityTest < ActiveModel::TestCase
assert_equal sanitized, { }
end
+ def test_custom_sanitizer
+ user = User.new
+ User.mass_assignment_sanitizer = CustomSanitizer.new
+ assert_raise StandardError do
+ user.sanitize_for_mass_assignment("admin" => true)
+ end
+ ensure
+ User.mass_assignment_sanitizer = nil
+
+ end
+
end
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 502a7e43de..b05d3970c7 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,13 @@
*Rails 3.1.0 (unreleased)*
+* AR#pluralize_table_names can be used to singularize/pluralize table name of an individual model:
+
+ class User < ActiveRecord::Base
+ self.pluralize_table_names = false
+ end
+
+ Previously this could only be set globally for all models through ActiveRecord::Base.pluralize_table_names. [Guillermo Iguaran]
+
* Add block setting of attributes to singular associations:
class User < ActiveRecord::Base
diff --git a/activerecord/README.rdoc b/activerecord/README.rdoc
index 6b4c85bb93..0d00749901 100644
--- a/activerecord/README.rdoc
+++ b/activerecord/README.rdoc
@@ -215,7 +215,7 @@ Active Record is released under the MIT license.
API documentation is at
-* http://api.rubyonrails.com
+* http://api.rubyonrails.org
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
diff --git a/activerecord/Rakefile b/activerecord/Rakefile
index e414c4fb1c..346c7e8142 100755
--- a/activerecord/Rakefile
+++ b/activerecord/Rakefile
@@ -1,7 +1,7 @@
#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
require File.expand_path(File.dirname(__FILE__)) + "/test/config"
@@ -171,7 +171,7 @@ task :rebuild_frontbase_databases => 'frontbase:rebuild_databases'
spec = eval(File.read('activerecord.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
diff --git a/activerecord/activerecord.gemspec b/activerecord/activerecord.gemspec
index 43a1258c20..b7e23faa09 100644
--- a/activerecord/activerecord.gemspec
+++ b/activerecord/activerecord.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.email = 'david@loudthinking.com'
s.homepage = 'http://www.rubyonrails.org'
- s.files = Dir['CHANGELOG', 'README.rdoc', 'examples/**/*', 'lib/**/*']
+ s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README.rdoc', 'examples/**/*', 'lib/**/*']
s.require_path = 'lib'
s.extra_rdoc_files = %w( README.rdoc )
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb
index 90d3b58c78..81ddbba51e 100644
--- a/activerecord/lib/active_record/aggregations.rb
+++ b/activerecord/lib/active_record/aggregations.rb
@@ -176,7 +176,7 @@ module ActiveRecord
# order in which mappings are defined determine the order in which attributes are sent to the
# value class constructor.
# * <tt>:allow_nil</tt> - Specifies that the value object will not be instantiated when all mapped
- # attributes are +nil+. Setting the value object to +nil+ has the effect of writing +nil+ to all
+ # attributes are +nil+. Setting the value object to +nil+ has the effect of writing +nil+ to all
# mapped attributes.
# This defaults to +false+.
# * <tt>:constructor</tt> - A symbol specifying the name of the constructor method or a Proc that
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 4979113b0b..a0a1ff23db 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -76,12 +76,6 @@ module ActiveRecord
end
end
- class HasAndBelongsToManyAssociationWithPrimaryKeyError < ActiveRecordError #:nodoc:
- def initialize(reflection)
- super("Primary key is not allowed in a has_and_belongs_to_many join table (#{reflection.options[:join_table]}).")
- end
- end
-
class HasAndBelongsToManyAssociationForeignKeyNeeded < ActiveRecordError #:nodoc:
def initialize(reflection)
super("Cannot create self referential has_and_belongs_to_many association on '#{reflection.class_name rescue nil}##{reflection.name rescue nil}'. :association_foreign_key cannot be the same as the :foreign_key.")
@@ -469,9 +463,9 @@ module ActiveRecord
# === Association Join Models
#
# Has Many associations can be configured with the <tt>:through</tt> option to use an
- # explicit join model to retrieve the data. This operates similarly to a
- # +has_and_belongs_to_many+ association. The advantage is that you're able to add validations,
- # callbacks, and extra attributes on the join model. Consider the following schema:
+ # explicit join model to retrieve the data. This operates similarly to a
+ # +has_and_belongs_to_many+ association. The advantage is that you're able to add validations,
+ # callbacks, and extra attributes on the join model. Consider the following schema:
#
# class Author < ActiveRecord::Base
# has_many :authorships
@@ -528,7 +522,7 @@ module ActiveRecord
# @group.avatars # selects all avatars by going through the User join model.
#
# An important caveat with going through +has_one+ or +has_many+ associations on the
- # join model is that these associations are *read-only*. For example, the following
+ # join model is that these associations are *read-only*. For example, the following
# would not work following the previous example:
#
# @group.avatars << Avatar.new # this would work if User belonged_to Avatar rather than the other way around
@@ -596,7 +590,7 @@ module ActiveRecord
# === Polymorphic Associations
#
# Polymorphic associations on models are not restricted on what types of models they
- # can be associated with. Rather, they specify an interface that a +has_many+ association
+ # can be associated with. Rather, they specify an interface that a +has_many+ association
# must adhere to.
#
# class Asset < ActiveRecord::Base
@@ -610,7 +604,7 @@ module ActiveRecord
# @asset.attachable = @post
#
# This works by using a type column in addition to a foreign key to specify the associated
- # record. In the Asset example, you'd need an +attachable_id+ integer column and an
+ # record. In the Asset example, you'd need an +attachable_id+ integer column and an
# +attachable_type+ string column.
#
# Using polymorphic associations in combination with single table inheritance (STI) is
@@ -666,7 +660,7 @@ module ActiveRecord
#
# Consider the following loop using the class above:
#
- # for post in Post.all
+ # Post.all.each do |post|
# puts "Post: " + post.title
# puts "Written by: " + post.author.name
# puts "Last comment on: " + post.comments.first.created_on
@@ -675,7 +669,7 @@ module ActiveRecord
# To iterate over these one hundred posts, we'll generate 201 database queries. Let's
# first just optimize it for retrieving the author:
#
- # for post in Post.find(:all, :include => :author)
+ # Post.find(:all, :include => :author).each do |post|
#
# This references the name of the +belongs_to+ association that also used the <tt>:author</tt>
# symbol. After loading the posts, find will collect the +author_id+ from each one and load
@@ -684,7 +678,7 @@ module ActiveRecord
#
# We can improve upon the situation further by referencing both associations in the finder with:
#
- # for post in Post.find(:all, :include => [ :author, :comments ])
+ # Post.find(:all, :include => [ :author, :comments ]).each do |post|
#
# This will load all comments with a single query. This reduces the total number of queries
# to 3. More generally the number of queries will be 1 plus the number of associations
@@ -692,7 +686,7 @@ module ActiveRecord
#
# To include a deep hierarchy of associations, use a hash:
#
- # for post in Post.find(:all, :include => [ :author, { :comments => { :author => :gravatar } } ])
+ # Post.find(:all, :include => [ :author, { :comments => { :author => :gravatar } } ]).each do |post|
#
# That'll grab not only all the comments but all their authors and gravatar pictures.
# You can mix and match symbols, arrays and hashes in any combination to describe the
@@ -741,7 +735,7 @@ module ActiveRecord
# Picture.find(:first, :include => :most_recent_comments).most_recent_comments # => returns all associated comments.
#
# When eager loaded, conditions are interpolated in the context of the model class, not
- # the model instance. Conditions are lazily interpolated before the actual model exists.
+ # the model instance. Conditions are lazily interpolated before the actual model exists.
#
# Eager loading is supported with polymorphic associations.
#
@@ -765,7 +759,7 @@ module ActiveRecord
# == Table Aliasing
#
# Active Record uses table aliasing in the case that a table is referenced multiple times
- # in a join. If a table is referenced only once, the standard table name is used. The
+ # in a join. If a table is referenced only once, the standard table name is used. The
# second time, the table is aliased as <tt>#{reflection_name}_#{parent_table_name}</tt>.
# Indexes are appended for any more successive uses of the table name.
#
@@ -847,7 +841,7 @@ module ActiveRecord
# == Bi-directional associations
#
# When you specify an association there is usually an association on the associated model
- # that specifies the same relationship in reverse. For example, with the following models:
+ # that specifies the same relationship in reverse. For example, with the following models:
#
# class Dungeon < ActiveRecord::Base
# has_many :traps
@@ -864,9 +858,9 @@ module ActiveRecord
#
# The +traps+ association on +Dungeon+ and the +dungeon+ association on +Trap+ are
# the inverse of each other and the inverse of the +dungeon+ association on +EvilWizard+
- # is the +evil_wizard+ association on +Dungeon+ (and vice-versa). By default,
+ # is the +evil_wizard+ association on +Dungeon+ (and vice-versa). By default,
# Active Record doesn't know anything about these inverse relationships and so no object
- # loading optimisation is possible. For example:
+ # loading optimisation is possible. For example:
#
# d = Dungeon.first
# t = d.traps.first
@@ -876,8 +870,8 @@ module ActiveRecord
#
# The +Dungeon+ instances +d+ and <tt>t.dungeon</tt> in the above example refer to
# the same object data from the database, but are actually different in-memory copies
- # of that data. Specifying the <tt>:inverse_of</tt> option on associations lets you tell
- # Active Record about inverse relationships and it will optimise object loading. For
+ # of that data. Specifying the <tt>:inverse_of</tt> option on associations lets you tell
+ # Active Record about inverse relationships and it will optimise object loading. For
# example, if we changed our model definitions to:
#
# class Dungeon < ActiveRecord::Base
@@ -1060,7 +1054,7 @@ module ActiveRecord
# specify it with this option.
# [:conditions]
# Specify the conditions that the associated objects must meet in order to be included as a +WHERE+
- # SQL fragment, such as <tt>price > 5 AND name LIKE 'B%'</tt>. Record creations from
+ # SQL fragment, such as <tt>price > 5 AND name LIKE 'B%'</tt>. Record creations from
# the association are scoped if a hash is used.
# <tt>has_many :posts, :conditions => {:published => true}</tt> will create published
# posts with <tt>@blog.posts.create</tt> or <tt>@blog.posts.build</tt>.
@@ -1075,10 +1069,11 @@ module ActiveRecord
# Specify the method that returns the primary key used for the association. By default this is +id+.
# [:dependent]
# If set to <tt>:destroy</tt> all the associated objects are destroyed
- # alongside this object by calling their +destroy+ method. If set to <tt>:delete_all</tt> all associated
- # objects are deleted *without* calling their +destroy+ method. If set to <tt>:nullify</tt> all associated
+ # alongside this object by calling their +destroy+ method. If set to <tt>:delete_all</tt> all associated
+ # objects are deleted *without* calling their +destroy+ method. If set to <tt>:nullify</tt> all associated
# objects' foreign keys are set to +NULL+ *without* calling their +save+ callbacks. If set to
- # <tt>:restrict</tt> this object cannot be deleted if it has any associated object.
+ # <tt>:restrict</tt> this object raises an <tt>ActiveRecord::DeleteRestrictionError</tt> exception and
+ # cannot be deleted if it has any associated objects.
#
# If using with the <tt>:through</tt> option, the association on the join model must be
# a +belongs_to+, and the records which get deleted are the join records, rather than
@@ -1227,7 +1222,8 @@ module ActiveRecord
# If set to <tt>:destroy</tt>, the associated object is destroyed when this object is. If set to
# <tt>:delete</tt>, the associated object is deleted *without* calling its destroy method.
# If set to <tt>:nullify</tt>, the associated object's foreign key is set to +NULL+.
- # Also, association is assigned.
+ # Also, association is assigned. If set to <tt>:restrict</tt> this object raises an
+ # <tt>ActiveRecord::DeleteRestrictionError</tt> exception and cannot be deleted if it has any associated object.
# [:foreign_key]
# Specify the foreign key used for the association. By default this is guessed to be the name
# of this class in lower-case and "_id" suffixed. So a Person class that makes a +has_one+ association
@@ -1243,7 +1239,7 @@ module ActiveRecord
# you want to do a join but not include the joined columns. Do not forget to include the
# primary and foreign keys, otherwise it will raise an error.
# [:through]
- # Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt>,
+ # Specifies a Join Model through which to perform the query. Options for <tt>:class_name</tt>,
# <tt>:primary_key</tt>, and <tt>:foreign_key</tt> are ignored, as the association uses the
# source reflection. You can only use a <tt>:through</tt> query through a <tt>has_one</tt>
# or <tt>belongs_to</tt> association on the join model.
@@ -1265,7 +1261,7 @@ module ActiveRecord
# By default, only save the associated object if it's a new record.
# [:inverse_of]
# Specifies the name of the <tt>belongs_to</tt> association on the associated object
- # that is the inverse of this <tt>has_one</tt> association. Does not work in combination
+ # that is the inverse of this <tt>has_one</tt> association. Does not work in combination
# with <tt>:through</tt> or <tt>:as</tt> options.
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
#
@@ -1383,7 +1379,7 @@ module ActiveRecord
# will be updated with the current time in addition to the updated_at/on attribute.
# [:inverse_of]
# Specifies the name of the <tt>has_one</tt> or <tt>has_many</tt> association on the associated
- # object that is the inverse of this <tt>belongs_to</tt> association. Does not work in
+ # object that is the inverse of this <tt>belongs_to</tt> association. Does not work in
# combination with the <tt>:polymorphic</tt> options.
# See ActiveRecord::Associations::ClassMethods's overview on Bi-directional associations for more detail.
#
@@ -1403,15 +1399,15 @@ module ActiveRecord
end
# Specifies a many-to-many relationship with another class. This associates two classes via an
- # intermediate join table. Unless the join table is explicitly specified as an option, it is
+ # intermediate join table. Unless the join table is explicitly specified as an option, it is
# guessed using the lexical order of the class names. So a join between Developer and Project
# will give the default join table name of "developers_projects" because "D" outranks "P".
- # Note that this precedence is calculated using the <tt><</tt> operator for String. This
+ # Note that this precedence is calculated using the <tt><</tt> operator for String. This
# means that if the strings are of different lengths, and the strings are equal when compared
# up to the shortest length, then the longer string is considered of higher
- # lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers"
+ # lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers"
# to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes",
- # but it in fact generates a join table name of "paper_boxes_papers". Be aware of this caveat, and use the
+ # but it in fact generates a join table name of "paper_boxes_papers". Be aware of this caveat, and use the
# custom <tt>:join_table</tt> option if you need to.
#
# The join table should not have a primary key or a model associated with it. You must manually generate the
@@ -1513,7 +1509,7 @@ module ActiveRecord
# the association will use "project_id" as the default <tt>:association_foreign_key</tt>.
# [:conditions]
# Specify the conditions that the associated object must meet in order to be included as a +WHERE+
- # SQL fragment, such as <tt>authorized = 1</tt>. Record creations from the association are
+ # SQL fragment, such as <tt>authorized = 1</tt>. Record creations from the association are
# scoped if a hash is used.
# <tt>has_many :posts, :conditions => {:published => true}</tt> will create published posts with <tt>@blog.posts.create</tt>
# or <tt>@blog.posts.build</tt>.
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index ab102b2b8f..9e6d9e73c5 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -60,7 +60,7 @@ module ActiveRecord
scope = scope.joins(join(
join_table,
- table[reflection.active_record_primary_key].
+ table[reflection.association_primary_key].
eq(join_table[reflection.association_foreign_key])
))
@@ -75,10 +75,16 @@ module ActiveRecord
foreign_key = reflection.active_record_primary_key
end
+ conditions = self.conditions[i]
+
if reflection == chain.last
scope = scope.where(table[key].eq(owner[foreign_key]))
- conditions[i].each do |condition|
+ if reflection.type
+ scope = scope.where(table[reflection.type].eq(owner.class.base_class.name))
+ end
+
+ conditions.each do |condition|
if options[:through] && condition.is_a?(Hash)
condition = { table.name => condition }
end
@@ -87,12 +93,16 @@ module ActiveRecord
end
else
constraint = table[key].eq(foreign_table[foreign_key])
- join = join(foreign_table, constraint)
- scope = scope.joins(join)
+ if reflection.type
+ type = chain[i + 1].klass.base_class.name
+ constraint = constraint.and(table[reflection.type].eq(type))
+ end
+
+ scope = scope.joins(join(foreign_table, constraint))
- unless conditions[i].empty?
- scope = scope.where(sanitize(conditions[i], table))
+ unless conditions.empty?
+ scope = scope.where(sanitize(conditions, table))
end
end
end
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
index 4b48757da7..d7632b2ea9 100644
--- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
+++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
@@ -39,10 +39,6 @@ module ActiveRecord::Associations::Builder
model.send(:undecorated_table_name, model.to_s),
model.send(:undecorated_table_name, reflection.class_name)
)
-
- if model.connection.supports_primary_key? && (model.connection.primary_key(reflection.options[:join_table]) rescue false)
- raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError.new(reflection)
- end
end
# Generates a join table name from two provided table names.
diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb
index 638a2ec72a..0cbbba041a 100644
--- a/activerecord/lib/active_record/associations/builder/singular_association.rb
+++ b/activerecord/lib/active_record/associations/builder/singular_association.rb
@@ -13,19 +13,6 @@ module ActiveRecord::Associations::Builder
private
- def define_readers
- super
- name = self.name
-
- model.redefine_method("#{name}_loaded?") do
- ActiveSupport::Deprecation.warn(
- "Calling obj.#{name}_loaded? is deprecated. Please use " \
- "obj.association(:#{name}).loaded? instead."
- )
- association(name).loaded?
- end
- end
-
def define_constructors
name = self.name
diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb
index 902ad8cb64..8a028c8996 100644
--- a/activerecord/lib/active_record/associations/collection_association.rb
+++ b/activerecord/lib/active_record/associations/collection_association.rb
@@ -126,7 +126,7 @@ module ActiveRecord
record
end
- # Add +records+ to this association. Returns +self+ so method calls may be chained.
+ # Add +records+ to this association. Returns +self+ so method calls may be chained.
# Since << flattens its argument list and inserts each record, +push+ and +concat+ behave identically.
def concat(*records)
result = true
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 8415942a1a..adfc71d435 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -123,30 +123,6 @@ module ActiveRecord
method_missing(:new, *args, &block)
end
end
-
- def proxy_owner
- ActiveSupport::Deprecation.warn(
- "Calling record.#{@association.reflection.name}.proxy_owner is deprecated. Please use " \
- "record.association(:#{@association.reflection.name}).owner instead."
- )
- @association.owner
- end
-
- def proxy_target
- ActiveSupport::Deprecation.warn(
- "Calling record.#{@association.reflection.name}.proxy_target is deprecated. Please use " \
- "record.association(:#{@association.reflection.name}).target instead."
- )
- @association.target
- end
-
- def proxy_reflection
- ActiveSupport::Deprecation.warn(
- "Calling record.#{@association.reflection.name}.proxy_reflection is deprecated. Please use " \
- "record.association(:#{@association.reflection.name}).reflection instead."
- )
- @association.reflection
- end
end
end
end
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index 78c5c4b870..7172e89a05 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -18,7 +18,7 @@ module ActiveRecord
#
# If the association has a counter cache it gets that value. Otherwise
# it will attempt to do a count via SQL, bounded to <tt>:limit</tt> if
- # there's one. Some configuration options like :group make it impossible
+ # there's one. Some configuration options like :group make it impossible
# to do an SQL count, in those cases the array count will be used.
#
# That does not depend on whether the collection has already been loaded
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index c32753782f..03963ab060 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -62,6 +62,7 @@ module ActiveRecord
def join_to(relation)
tables = @tables.dup
foreign_table = parent_table
+ foreign_klass = parent.active_record
# The chain starts with the target table, but we want to end with it here (makes
# more sense in this context), so we reverse
@@ -91,14 +92,17 @@ module ActiveRecord
constraint = build_constraint(reflection, table, key, foreign_table, foreign_key)
- unless conditions[i].empty?
- constraint = constraint.and(sanitize(conditions[i], table))
+ conditions = self.conditions[i].dup
+ conditions << { reflection.type => foreign_klass.base_class.name } if reflection.type
+
+ unless conditions.empty?
+ constraint = constraint.and(sanitize(conditions, table))
end
relation.from(join(table, constraint))
# The current table in this iteration becomes the foreign table in the next
- foreign_table = table
+ foreign_table, foreign_klass = table, reflection.klass
end
relation
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb
index 53c5c3cedf..81172179e0 100644
--- a/activerecord/lib/active_record/associations/through_association.rb
+++ b/activerecord/lib/active_record/associations/through_association.rb
@@ -16,7 +16,7 @@ module ActiveRecord
chain[1..-1].each do |reflection|
scope = scope.merge(
reflection.klass.scoped.with_default_scope.
- except(:select, :create_with)
+ except(:select, :create_with, :includes)
)
end
scope
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index aef99e3129..7d4182291a 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -58,7 +58,7 @@ module ActiveRecord
generated_attribute_methods.module_eval("def _#{attr_name}; #{access_code}; end; alias #{attr_name} _#{attr_name}", __FILE__, __LINE__)
end
- # Define an attribute reader method. Cope with nil column.
+ # Define an attribute reader method. Cope with nil column.
# method_name is the same as attr_name except when a non-standard primary key is used,
# we still define #id as an accessor for the key
def define_read_method(method_name, attr_name, column)
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 48dbe0838a..036d514a03 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -161,7 +161,7 @@ module ActiveRecord
#
# For performance reasons, we don't check whether to validate at runtime.
# However the validation and callback methods are lazy and those methods
- # get created when they are invoked for the very first time. However,
+ # get created when they are invoked for the very first time. However,
# this can change, for instance, when using nested attributes, which is
# called _after_ the association has been defined. Since we don't want
# the callbacks to get defined multiple times, there are guards that
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 19a7965429..f74810720d 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -428,6 +428,10 @@ module ActiveRecord #:nodoc:
class_attribute :default_scopes, :instance_writer => false
self.default_scopes = []
+ # Boolean flag to prevent infinite recursion when evaluating default scopes
+ class_attribute :apply_default_scope, :instance_writer => false
+ self.apply_default_scope = true
+
# Returns a hash of all the attributes that have been specified for serialization as
# keys and their class restriction as values.
class_attribute :serialized_attributes
@@ -1261,11 +1265,14 @@ MSG
self.default_scopes = default_scopes + [scope]
end
+ # The apply_default_scope flag is used to prevent an infinite recursion situation where
+ # a default scope references a scope which has a default scope which references a scope...
def build_default_scope #:nodoc:
+ return unless apply_default_scope
+ self.apply_default_scope = false
+
if method(:default_scope).owner != Base.singleton_class
- # Use relation.scoping to ensure we ignore whatever the current value of
- # self.current_scope may be.
- relation.scoping { default_scope }
+ default_scope
elsif default_scopes.any?
default_scopes.inject(relation) do |default_scope, scope|
if scope.is_a?(Hash)
@@ -1277,6 +1284,8 @@ MSG
end
end
end
+ ensure
+ self.apply_default_scope = true
end
# Returns the class type of the record using the current module as a prefix. So descendants of
@@ -1653,9 +1662,6 @@ MSG
# If any attributes are protected by either +attr_protected+ or
# +attr_accessible+ then only settable attributes will be assigned.
#
- # The +guard_protected_attributes+ argument is now deprecated, use
- # the +assign_attributes+ method if you want to bypass mass-assignment security.
- #
# class User < ActiveRecord::Base
# attr_protected :is_admin
# end
@@ -1664,20 +1670,10 @@ MSG
# user.attributes = { :username => 'Phusion', :is_admin => true }
# user.username # => "Phusion"
# user.is_admin? # => false
- def attributes=(new_attributes, guard_protected_attributes = nil)
- unless guard_protected_attributes.nil?
- message = "the use of 'guard_protected_attributes' will be removed from the next major release of rails, " +
- "if you want to bypass mass-assignment security then look into using assign_attributes"
- ActiveSupport::Deprecation.warn(message)
- end
-
+ def attributes=(new_attributes)
return unless new_attributes.is_a?(Hash)
- if guard_protected_attributes == false
- assign_attributes(new_attributes, :without_protection => true)
- else
- assign_attributes(new_attributes)
- end
+ assign_attributes(new_attributes)
end
# Allows you to set all the attributes for a particular mass-assignment
@@ -1861,12 +1857,16 @@ MSG
# Returns the contents of the record as a nicely formatted string.
def inspect
- attributes_as_nice_string = self.class.column_names.collect { |name|
- if has_attribute?(name)
- "#{name}: #{attribute_for_inspect(name)}"
- end
- }.compact.join(", ")
- "#<#{self.class} #{attributes_as_nice_string}>"
+ inspection = if @attributes
+ self.class.column_names.collect { |name|
+ if has_attribute?(name)
+ "#{name}: #{attribute_for_inspect(name)}"
+ end
+ }.compact.join(", ")
+ else
+ "not initialized"
+ end
+ "#<#{self.class} #{inspection}>"
end
protected
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index 6f21cea288..8ffd40f7e5 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -165,7 +165,7 @@ module ActiveRecord
checkin conn if conn
end
- # If a connection already exists yield it to the block. If no connection
+ # If a connection already exists yield it to the block. If no connection
# exists checkout a connection, yield it to the block, and checkin the
# connection when finished.
def with_connection
@@ -262,7 +262,7 @@ module ActiveRecord
else
clear_stale_cached_connections!
if @size == @checked_out.size
- raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
+ raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
index b3eb23bbb3..777ef15dfc 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/module/deprecation'
-
module ActiveRecord
module ConnectionAdapters # :nodoc:
module DatabaseStatements
@@ -42,7 +40,7 @@ module ActiveRecord
undef_method :execute
# Executes +sql+ statement in the context of this connection using
- # +binds+ as the bind substitutes. +name+ is logged along with
+ # +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement.
def exec_query(sql, name = 'SQL', binds = [])
end
@@ -245,38 +243,13 @@ module ActiveRecord
# done if the transaction block raises an exception or returns false.
def rollback_db_transaction() end
- # Appends +LIMIT+ and +OFFSET+ options to an SQL statement, or some SQL
- # fragment that has the same semantics as LIMIT and OFFSET.
- #
- # +options+ must be a Hash which contains a +:limit+ option
- # and an +:offset+ option.
- #
- # This method *modifies* the +sql+ parameter.
- #
- # This method is deprecated!! Stop using it!
- #
- # ===== Examples
- # add_limit_offset!('SELECT * FROM suppliers', {:limit => 10, :offset => 50})
- # generates
- # SELECT * FROM suppliers LIMIT 10 OFFSET 50
- def add_limit_offset!(sql, options)
- if limit = options[:limit]
- sql << " LIMIT #{sanitize_limit(limit)}"
- end
- if offset = options[:offset]
- sql << " OFFSET #{offset.to_i}"
- end
- sql
- end
- deprecate :add_limit_offset!
-
def default_sequence_name(table, column)
nil
end
# Set the sequence to the max value of the table's column.
def reset_sequence!(table, column, sequence = nil)
- # Do nothing by default. Implement for PostgreSQL, Oracle, ...
+ # Do nothing by default. Implement for PostgreSQL, Oracle, ...
end
# Inserts the given fixture into the table. Overridden in adapters that require
@@ -308,10 +281,10 @@ module ActiveRecord
# Sanitizes the given LIMIT parameter in order to prevent SQL injection.
#
# The +limit+ may be anything that can evaluate to a string via #to_s. It
- # should look like an integer, or a comma-delimited list of integers, or
+ # should look like an integer, or a comma-delimited list of integers, or
# an Arel SQL literal.
#
- # Returns Integer and Arel::Nodes::SqlLiteral limits as is.
+ # Returns Integer and Arel::Nodes::SqlLiteral limits as is.
# Returns the sanitized limit parameter, either as an integer, or as a
# string which contains a comma-delimited list of integers.
def sanitize_limit(limit)
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 9f9c2c42cb..a754f46af0 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -4,7 +4,7 @@ module ActiveRecord
module ConnectionAdapters # :nodoc:
module SchemaStatements
# Returns a Hash of mappings from the abstract data types to the native
- # database types. See TableDefinition#column for details on the recognized
+ # database types. See TableDefinition#column for details on the recognized
# abstract data types.
def native_database_types
{}
@@ -78,7 +78,7 @@ module ActiveRecord
# Creates a new table with the name +table_name+. +table_name+ may either
# be a String or a Symbol.
#
- # There are two ways to work with +create_table+. You can use the block
+ # There are two ways to work with +create_table+. You can use the block
# form or the regular form, like this:
#
# === Block form
@@ -299,7 +299,7 @@ module ActiveRecord
raise NotImplementedError, "rename_column is not implemented"
end
- # Adds a new index to the table. +column_name+ can be a single Symbol, or
+ # Adds a new index to the table. +column_name+ can be a single Symbol, or
# an Array of Symbols.
#
# The index will be named after the table and the first column name,
@@ -564,7 +564,7 @@ module ActiveRecord
def columns_for_remove(table_name, *column_names)
column_names = column_names.flatten
- raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.blank?
+ raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.blank?
column_names.map {|column_name| quote_column_name(column_name) }
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
index ac2da73a84..6e2c3f4527 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb
@@ -280,7 +280,7 @@ module ActiveRecord
end
rescue ActiveRecord::StatementInvalid => exception
if exception.message.split(":").first =~ /Packets out of order/
- raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
+ raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
else
raise
end
@@ -347,19 +347,6 @@ module ActiveRecord
execute("RELEASE SAVEPOINT #{current_savepoint_name}")
end
- def add_limit_offset!(sql, options)
- limit, offset = options[:limit], options[:offset]
- if limit && offset
- sql << " LIMIT #{offset.to_i}, #{sanitize_limit(limit)}"
- elsif limit
- sql << " LIMIT #{sanitize_limit(limit)}"
- elsif offset
- sql << " OFFSET #{offset.to_i}"
- end
- sql
- end
- deprecate :add_limit_offset!
-
# SCHEMA STATEMENTS ========================================
def structure_dump
@@ -582,11 +569,6 @@ module ActiveRecord
pk_and_sequence && pk_and_sequence.first
end
- def case_sensitive_equality_operator
- "= BINARY"
- end
- deprecate :case_sensitive_equality_operator
-
def case_sensitive_modifier(node)
Arel::Nodes::Bin.new(node)
end
@@ -662,7 +644,7 @@ module ActiveRecord
result = @connection.query(sql)
rescue ActiveRecord::StatementInvalid => exception
if exception.message.split(":").first =~ /Packets out of order/
- raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
+ raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
else
raise
end
diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
index a9f4c08348..ee83f8120d 100644
--- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
@@ -1,5 +1,4 @@
require 'active_record/connection_adapters/abstract_adapter'
-require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/object/blank'
require 'set'
@@ -407,7 +406,7 @@ module ActiveRecord
def exec_without_stmt(sql, name = 'SQL') # :nodoc:
# Some queries, like SHOW CREATE TABLE don't work through the prepared
- # statement API. For those queries, we need to use this method. :'(
+ # statement API. For those queries, we need to use this method. :'(
log(sql, name) do
result = @connection.query(sql)
cols = []
@@ -432,7 +431,7 @@ module ActiveRecord
end
rescue ActiveRecord::StatementInvalid => exception
if exception.message.split(":").first =~ /Packets out of order/
- raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
+ raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings."
else
raise
end
@@ -488,19 +487,6 @@ module ActiveRecord
execute("RELEASE SAVEPOINT #{current_savepoint_name}")
end
- def add_limit_offset!(sql, options) #:nodoc:
- limit, offset = options[:limit], options[:offset]
- if limit && offset
- sql << " LIMIT #{offset.to_i}, #{sanitize_limit(limit)}"
- elsif limit
- sql << " LIMIT #{sanitize_limit(limit)}"
- elsif offset
- sql << " OFFSET #{offset.to_i}"
- end
- sql
- end
- deprecate :add_limit_offset!
-
# SCHEMA STATEMENTS ========================================
def structure_dump #:nodoc:
@@ -713,11 +699,6 @@ module ActiveRecord
pk_and_sequence && pk_and_sequence.first
end
- def case_sensitive_equality_operator
- "= BINARY"
- end
- deprecate :case_sensitive_equality_operator
-
def case_sensitive_modifier(node)
Arel::Nodes::Bin.new(node)
end
@@ -833,7 +814,7 @@ module ActiveRecord
stmt.execute(*binds.map { |col, val| type_cast(val, col) })
rescue Mysql::Error => e
# Older versions of MySQL leave the prepared statement in a bad
- # place when an error occurs. To support older mysql versions, we
+ # place when an error occurs. To support older mysql versions, we
# need to close the statement and delete the statement from the
# cache.
stmt.close
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 0a460bc086..8b48c055ac 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1,5 +1,4 @@
require 'active_record/connection_adapters/abstract_adapter'
-require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/object/blank'
# Make sure we're using pg high enough for PGResult#values
@@ -199,7 +198,7 @@ module ActiveRecord
# * <tt>:password</tt> - Defaults to nothing.
# * <tt>:database</tt> - The name of the database. No default, must be provided.
# * <tt>:schema_search_path</tt> - An optional schema search path for the connection given
- # as a string of comma-separated schema names. This is backward-compatible with the <tt>:schema_order</tt> option.
+ # as a string of comma-separated schema names. This is backward-compatible with the <tt>:schema_order</tt> option.
# * <tt>:encoding</tt> - An optional client encoding that is used in a <tt>SET client_encoding TO
# <encoding></tt> call on the connection.
# * <tt>:min_messages</tt> - An optional client min messages that is used in a
@@ -619,7 +618,7 @@ module ActiveRecord
create_database(name)
end
- # Create a new PostgreSQL database. Options include <tt>:owner</tt>, <tt>:template</tt>,
+ # Create a new PostgreSQL database. Options include <tt>:owner</tt>, <tt>:template</tt>,
# <tt>:encoding</tt>, <tt>:tablespace</tt>, and <tt>:connection_limit</tt> (note that MySQL uses
# <tt>:charset</tt> while PostgreSQL uses <tt>:encoding</tt>).
#
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
index d2785b234a..724b2e6d9c 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -1,5 +1,4 @@
require 'active_record/connection_adapters/abstract_adapter'
-require 'active_support/core_ext/kernel/requires'
module ActiveRecord
module ConnectionAdapters #:nodoc:
@@ -103,6 +102,10 @@ module ActiveRecord
# Clears the prepared statements cache.
def clear_cache!
+ @statements.values.map { |hash| hash[:stmt] }.each { |stmt|
+ stmt.close unless stmt.closed?
+ }
+
@statements.clear
end
@@ -320,7 +323,7 @@ module ActiveRecord
end
def remove_column(table_name, *column_names) #:nodoc:
- raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
+ raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
column_names.flatten.each do |column_name|
alter_table(table_name) do |definition|
definition.columns.delete(definition[column_name])
diff --git a/activerecord/lib/active_record/counter_cache.rb b/activerecord/lib/active_record/counter_cache.rb
index 7839f03848..4d387565d9 100644
--- a/activerecord/lib/active_record/counter_cache.rb
+++ b/activerecord/lib/active_record/counter_cache.rb
@@ -2,7 +2,7 @@ module ActiveRecord
# = Active Record Counter Cache
module CounterCache
# Resets one or more counter caches to their correct value using an SQL
- # count query. This is useful when adding new counter caches, or if the
+ # count query. This is useful when adding new counter caches, or if the
# counter has been corrupted or modified directly by SQL.
#
# ==== Parameters
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 4aa6389a04..819743a361 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -6,14 +6,13 @@ rescue LoadError
end
require 'yaml'
-require 'csv'
require 'zlib'
require 'active_support/dependencies'
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/logger'
require 'active_support/ordered_hash'
-require 'active_support/core_ext/module/deprecation'
+require 'active_record/fixtures/file'
if defined? ActiveRecord
class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
@@ -54,14 +53,14 @@ class FixturesFileNotFound < StandardError; end
# name: Google
# url: http://www.google.com
#
-# This YAML fixture file includes two fixtures. Each YAML fixture (ie. record) is given a name and is followed by an
-# indented list of key/value pairs in the "key: value" format. Records are separated by a blank line for your viewing
+# This YAML fixture file includes two fixtures. Each YAML fixture (ie. record) is given a name and is followed by an
+# indented list of key/value pairs in the "key: value" format. Records are separated by a blank line for your viewing
# pleasure.
#
# Note that YAML fixtures are unordered. If you want ordered fixtures, use the omap YAML type.
# See http://yaml.org/type/omap.html
-# for the specification. You will need ordered fixtures when you have foreign key constraints on keys in the same table.
-# This is commonly needed for tree structures. Example:
+# for the specification. You will need ordered fixtures when you have foreign key constraints on keys in the same table.
+# This is commonly needed for tree structures. Example:
#
# --- !omap
# - parent:
@@ -75,7 +74,7 @@ class FixturesFileNotFound < StandardError; end
#
# = Using fixtures in testcases
#
-# Since fixtures are a testing construct, we use them in our unit and functional tests. There are two ways to use the
+# Since fixtures are a testing construct, we use them in our unit and functional tests. There are two ways to use the
# fixtures, but first let's take a look at a sample unit test:
#
# require 'test_helper'
@@ -385,17 +384,14 @@ class FixturesFileNotFound < StandardError; end
#
# first:
# name: Smurf
-# <<: *DEFAULTS
+# *DEFAULTS
#
# second:
# name: Fraggle
-# <<: *DEFAULTS
+# *DEFAULTS
#
# Any fixture labeled "DEFAULTS" is safely ignored.
-Fixture = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Fixture', 'ActiveRecord::Fixture')
-Fixtures = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Fixtures', 'ActiveRecord::Fixtures')
-
module ActiveRecord
class Fixtures
MAX_ID = 2 ** 30 - 1
@@ -477,7 +473,7 @@ module ActiveRecord
connection,
table_name,
class_names[table_name.to_sym] || table_name.classify,
- File.join(fixtures_directory, path))
+ ::File.join(fixtures_directory, path))
end
all_loaded_fixtures.update(fixtures_map)
@@ -558,7 +554,7 @@ module ActiveRecord
fixtures.size
end
- # Return a hash of rows to be inserted. The key is the table, the value is
+ # Return a hash of rows to be inserted. The key is the table, the value is
# a list of rows to insert to that table.
def table_rows
now = ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now
@@ -655,74 +651,33 @@ module ActiveRecord
end
def read_fixture_files
- if File.file?(yaml_file_path)
+ if ::File.file?(yaml_file_path)
read_yaml_fixture_files
- elsif File.file?(csv_file_path)
- read_csv_fixture_files
else
- raise FixturesFileNotFound, "Could not find #{yaml_file_path} or #{csv_file_path}"
+ raise FixturesFileNotFound, "Could not find #{yaml_file_path}"
end
end
def read_yaml_fixture_files
- yaml_string = (Dir["#{@fixture_path}/**/*.yml"].select { |f|
- File.file?(f)
- } + [yaml_file_path]).map { |file_path| IO.read(file_path) }.join
-
- if yaml = parse_yaml_string(yaml_string)
- # If the file is an ordered map, extract its children.
- yaml_value =
- if yaml.respond_to?(:type_id) && yaml.respond_to?(:value)
- yaml.value
- else
- [yaml]
- end
-
- yaml_value.each do |fixture|
- raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{fixture}" unless fixture.respond_to?(:each)
- fixture.each do |name, data|
- unless data
- raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
- end
-
- fixtures[name] = ActiveRecord::Fixture.new(data, model_class)
+ yaml_files = Dir["#{@fixture_path}/**/*.yml"].select { |f|
+ ::File.file?(f)
+ } + [yaml_file_path]
+
+ yaml_files.each do |file|
+ Fixtures::File.open(file) do |fh|
+ fh.each do |name, row|
+ fixtures[name] = ActiveRecord::Fixture.new(row, model_class)
end
end
end
end
- def read_csv_fixture_files
- reader = CSV.parse(erb_render(IO.read(csv_file_path)))
- header = reader.shift
- i = 0
- reader.each do |row|
- data = {}
- row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
- fixtures["#{@class_name.to_s.underscore}_#{i+=1}"] = ActiveRecord::Fixture.new(data, model_class)
- end
- end
- deprecate :read_csv_fixture_files
-
def yaml_file_path
"#{@fixture_path}.yml"
end
- def csv_file_path
- @fixture_path + ".csv"
- end
-
def yaml_fixtures_key(path)
- File.basename(@fixture_path).split(".").first
- end
-
- def parse_yaml_string(fixture_content)
- YAML::load(erb_render(fixture_content))
- rescue => error
- raise Fixture::FormatError, "a YAML error occurred parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{error.class}: #{error}"
- end
-
- def erb_render(fixture_content)
- ERB.new(fixture_content).result
+ ::File.basename(@fixture_path).split(".").first
end
end
@@ -798,7 +753,7 @@ module ActiveRecord
def fixtures(*fixture_names)
if fixture_names.first == :all
- fixture_names = Dir["#{fixture_path}/**/*.{yml,csv}"]
+ fixture_names = Dir["#{fixture_path}/**/*.{yml}"]
fixture_names.map! { |f| f[(fixture_path.size + 1)..-5] }
else
fixture_names = fixture_names.flatten.map { |n| n.to_s }
diff --git a/activerecord/lib/active_record/fixtures/file.rb b/activerecord/lib/active_record/fixtures/file.rb
new file mode 100644
index 0000000000..04f494db2c
--- /dev/null
+++ b/activerecord/lib/active_record/fixtures/file.rb
@@ -0,0 +1,55 @@
+begin
+ require 'psych'
+rescue LoadError
+end
+
+require 'erb'
+require 'yaml'
+
+module ActiveRecord
+ class Fixtures
+ class File
+ include Enumerable
+
+ ##
+ # Open a fixture file named +file+. When called with a block, the block
+ # is called with the filehandle and the filehandle is automatically closed
+ # when the block finishes.
+ def self.open(file)
+ x = new file
+ block_given? ? yield(x) : x
+ end
+
+ def initialize(file)
+ @file = file
+ @rows = nil
+ end
+
+ def each(&block)
+ rows.each(&block)
+ end
+
+ private
+ def rows
+ return @rows if @rows
+
+ data = YAML.load(render(IO.read(@file)))
+ @rows = data ? validate(data).to_a : []
+ end
+
+ def render(content)
+ ERB.new(content).result
+ end
+
+ # Validate our unmarshalled data.
+ def validate(data)
+ unless Hash === data || YAML::Omap === data
+ raise Fixture::FormatError, 'fixture is not a hash'
+ end
+
+ raise Fixture::FormatError unless data.all? { |name, row| Hash === row }
+ data
+ end
+ end
+ end
+end
diff --git a/activerecord/lib/active_record/locking/pessimistic.rb b/activerecord/lib/active_record/locking/pessimistic.rb
index 4c4c1bf5a1..66994e4797 100644
--- a/activerecord/lib/active_record/locking/pessimistic.rb
+++ b/activerecord/lib/active_record/locking/pessimistic.rb
@@ -14,7 +14,7 @@ module ActiveRecord
# Account.transaction do
# # select * from accounts where name = 'shugo' limit 1 for update
# shugo = Account.where("name = 'shugo'").lock(true).first
- # yuko = Account.where("name = 'shugo'").lock(true).first
+ # yuko = Account.where("name = 'yuko'").lock(true).first
# shugo.balance -= 100
# shugo.save!
# yuko.balance += 100
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index c9d57ce812..ed8e5ae140 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -1,7 +1,7 @@
module ActiveRecord
class Migration
# ActiveRecord::Migration::CommandRecorder records commands done during
- # a migration and knows how to reverse those commands. The CommandRecorder
+ # a migration and knows how to reverse those commands. The CommandRecorder
# knows how to invert the following commands:
#
# * add_column
@@ -20,7 +20,7 @@ module ActiveRecord
@delegate = delegate
end
- # record +command+. +command+ should be a method name and arguments.
+ # record +command+. +command+ should be a method name and arguments.
# For example:
#
# recorder.record(:method_name, [:arg1, arg2])
@@ -29,7 +29,7 @@ module ActiveRecord
end
# Returns a list that represents commands that are the inverse of the
- # commands stored in +commands+. For example:
+ # commands stored in +commands+. For example:
#
# recorder.record(:rename_table, [:old, :new])
# recorder.inverse # => [:rename_table, [:new, :old]]
@@ -79,8 +79,10 @@ module ActiveRecord
end
def invert_add_index(args)
- table, columns, _ = *args
- [:remove_index, [table, {:column => columns}]]
+ table, columns, options = *args
+ index_name = options.try(:[], :name)
+ options_hash = index_name ? {:name => index_name} : {:column => columns}
+ [:remove_index, [table, options_hash]]
end
def invert_remove_timestamps(args)
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index b9041f44d8..4ec0431b8c 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -33,7 +33,11 @@ module ActiveRecord
# +save+ returns +false+. See ActiveRecord::Callbacks for further
# details.
def save(*)
- create_or_update
+ begin
+ create_or_update
+ rescue ActiveRecord::RecordInvalid
+ false
+ end
end
# Saves the model.
@@ -133,6 +137,8 @@ module ActiveRecord
# * Callbacks are skipped.
# * updated_at/updated_on column is not updated if that column is available.
#
+ # Raises an +ActiveRecordError+ when called on new objects, or when the +name+
+ # attribute is marked as readonly.
def update_column(name, value)
name = name.to_s
raise ActiveRecordError, "#{name} is marked as readonly" if self.class.readonly_attributes.include?(name)
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index bae2ded244..47133e77e8 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -29,8 +29,8 @@ module ActiveRecord
# When loading console, force ActiveRecord::Base to be loaded
# to avoid cross references when loading a constant for the
# first time. Also, make it output to STDERR.
- console do |sandbox|
- require "active_record/railties/console_sandbox" if sandbox
+ console do |app|
+ require "active_record/railties/console_sandbox" if app.sandbox?
ActiveRecord::Base.logger = Logger.new(STDERR)
end
diff --git a/activerecord/lib/active_record/railties/controller_runtime.rb b/activerecord/lib/active_record/railties/controller_runtime.rb
index fb3fd34665..c5db9b4625 100644
--- a/activerecord/lib/active_record/railties/controller_runtime.rb
+++ b/activerecord/lib/active_record/railties/controller_runtime.rb
@@ -32,7 +32,9 @@ module ActiveRecord
def append_info_to_payload(payload)
super
- payload[:db_runtime] = db_runtime
+ if ActiveRecord::Base.connected?
+ payload[:db_runtime] = (db_runtime || 0) + ActiveRecord::LogSubscriber.reset_runtime
+ end
end
module ClassMethods
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 85ad43b35f..6f8f84d50b 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -27,7 +27,7 @@ db_namespace = namespace :db do
#
# development:
# database: blog_development
- # <<: *defaults
+ # *defaults
next unless config['database']
# Only connect to local databases
local_database?(config) { create_database(config) }
@@ -296,7 +296,7 @@ db_namespace = namespace :db do
end
namespace :fixtures do
- desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
+ desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in test/fixtures using FIXTURES_DIR=z. Specify an alternative path (eg. spec/fixtures) using FIXTURES_PATH=spec/fixtures."
task :load => :environment do
require 'active_record/fixtures'
@@ -338,6 +338,7 @@ db_namespace = namespace :db do
task :dump => :load_config do
require 'active_record/schema_dumper'
File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
+ ActiveRecord::Base.establish_connection(Rails.env)
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
db_namespace['schema:dump'].reenable
@@ -480,8 +481,7 @@ db_namespace = namespace :db do
# desc "Creates a sessions migration for use with ActiveRecord::SessionStore"
task :create => :environment do
raise 'Task unavailable to this database (no migration support)' unless ActiveRecord::Base.connection.supports_migrations?
- require 'rails/generators'
- Rails::Generators.configure!
+ Rails.application.load_generators
require 'rails/generators/rails/session_migration/session_migration_generator'
Rails::Generators::SessionMigrationGenerator.start [ ENV['MIGRATION'] || 'add_sessions_table' ]
end
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index bcba85d7a4..6df473d011 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -1,5 +1,4 @@
require 'active_support/core_ext/class/attribute'
-require 'active_support/core_ext/module/deprecation'
require 'active_support/core_ext/object/inclusion'
module ActiveRecord
@@ -202,17 +201,12 @@ module ActiveRecord
@foreign_key ||= options[:foreign_key] || derive_foreign_key
end
- def primary_key_name
- foreign_key
- end
- deprecate :primary_key_name => :foreign_key
-
def foreign_type
@foreign_type ||= options[:foreign_type] || "#{name}_type"
end
def type
- @type ||= "#{options[:as]}_type"
+ @type ||= options[:as] && "#{options[:as]}_type"
end
def primary_key_column
@@ -280,9 +274,7 @@ module ActiveRecord
# in the #chain. The inside arrays are simply conditions (and each condition may itself be
# a hash, array, arel predicate, etc...)
def conditions
- conditions = [options[:conditions]].compact
- conditions << { type => active_record.base_class.name } if options[:as]
- [conditions]
+ [[options[:conditions]].compact]
end
alias :source_macro :macro
@@ -378,9 +370,10 @@ module ActiveRecord
# Holds all the meta-data about a :through association as it was specified
# in the Active Record class.
class ThroughReflection < AssociationReflection #:nodoc:
- delegate :foreign_key, :foreign_type, :association_foreign_key, :active_record_primary_key, :to => :source_reflection
+ delegate :foreign_key, :foreign_type, :association_foreign_key,
+ :active_record_primary_key, :type, :to => :source_reflection
- # Gets the source of the through reflection. It checks both a singularized
+ # Gets the source of the through reflection. It checks both a singularized
# and pluralized form for <tt>:belongs_to</tt> or <tt>:has_many</tt>.
#
# class Post < ActiveRecord::Base
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index ae9afad48a..e852f50d86 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -12,7 +12,7 @@ module ActiveRecord
# These are explicitly delegated to improve performance (avoids method_missing)
delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to => :to_a
- delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key, :to => :klass
+ delegate :table_name, :quoted_table_name, :primary_key, :quoted_primary_key, :connection, :column_hash,:to => :klass
attr_reader :table, :klass, :loaded
attr_accessor :extensions, :default_scoped
@@ -102,24 +102,30 @@ module ActiveRecord
def to_a
return @records if loaded?
- @records = if @readonly_value.nil? && !@klass.locking_enabled?
- eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values)
- else
- IdentityMap.without do
+ default_scoped = with_default_scope
+
+ if default_scoped.equal?(self)
+ @records = if @readonly_value.nil? && !@klass.locking_enabled?
eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values)
+ else
+ IdentityMap.without do
+ eager_loading? ? find_with_associations : @klass.find_by_sql(arel.to_sql, @bind_values)
+ end
end
- end
- preload = @preload_values
- preload += @includes_values unless eager_loading?
- preload.each do |associations|
- ActiveRecord::Associations::Preloader.new(@records, associations).run
- end
+ preload = @preload_values
+ preload += @includes_values unless eager_loading?
+ preload.each do |associations|
+ ActiveRecord::Associations::Preloader.new(@records, associations).run
+ end
- # @readonly_value is true only if set explicitly. @implicit_readonly is true if there
- # are JOINS and no explicit SELECT.
- readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value
- @records.each { |record| record.readonly! } if readonly
+ # @readonly_value is true only if set explicitly. @implicit_readonly is true if there
+ # are JOINS and no explicit SELECT.
+ readonly = @readonly_value.nil? ? @implicit_readonly : @readonly_value
+ @records.each { |record| record.readonly! } if readonly
+ else
+ @records = default_scoped.to_a
+ end
@loaded = true
@records
@@ -287,7 +293,7 @@ module ActiveRecord
end
# Destroy an object (or multiple objects) that has the given id, the object is instantiated first,
- # therefore all callbacks and filters are fired off before the object is deleted. This method is
+ # therefore all callbacks and filters are fired off before the object is deleted. This method is
# less efficient than ActiveRecord#delete but allows cleanup methods and other actions to be run.
#
# This essentially finds the object (or multiple objects) with the given id, creates a new object
@@ -316,7 +322,7 @@ module ActiveRecord
# Deletes the records matching +conditions+ without instantiating the records first, and hence not
# calling the +destroy+ method nor invoking callbacks. This is a single SQL DELETE statement that
# goes straight to the database, much more efficient than +destroy_all+. Be careful with relations
- # though, in particular <tt>:dependent</tt> rules defined on associations are not honored. Returns
+ # though, in particular <tt>:dependent</tt> rules defined on associations are not honored. Returns
# the number of rows affected.
#
# ==== Parameters
@@ -418,9 +424,10 @@ module ActiveRecord
end
def with_default_scope #:nodoc:
- if default_scoped?
- default_scope = @klass.send(:build_default_scope)
- default_scope ? default_scope.merge(self) : self
+ if default_scoped? && default_scope = klass.send(:build_default_scope)
+ default_scope = default_scope.merge(self)
+ default_scope.default_scoped = false
+ default_scope
else
self
end
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 0fcae92d51..a785f38e89 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -66,7 +66,7 @@ module ActiveRecord
calculate(:average, column_name, options)
end
- # Calculates the minimum value on a given column. The value is returned
+ # Calculates the minimum value on a given column. The value is returned
# with the same data type of the column, or +nil+ if there's no row. See
# +calculate+ for examples with options.
#
@@ -93,7 +93,7 @@ module ActiveRecord
calculate(:sum, column_name, options)
end
- # This calculates aggregate values in the given column. Methods for count, sum, average,
+ # This calculates aggregate values in the given column. Methods for count, sum, average,
# minimum, and maximum have been added as shortcuts. Options such as <tt>:conditions</tt>,
# <tt>:order</tt>, <tt>:group</tt>, <tt>:having</tt>, and <tt>:joins</tt> can be passed to customize the query.
#
@@ -101,7 +101,7 @@ module ActiveRecord
# * Single aggregate value: The single value is type cast to Fixnum for COUNT, Float
# for AVG, and the given column's type for everything else.
# * Grouped values: This returns an ordered hash of the values and groups them by the
- # <tt>:group</tt> option. It takes either a column name, or the name of a belongs_to association.
+ # <tt>:group</tt> option. It takes either a column name, or the name of a belongs_to association.
#
# values = Person.maximum(:age, :group => 'last_name')
# puts values["Drake"]
@@ -119,7 +119,7 @@ module ActiveRecord
# Options:
# * <tt>:conditions</tt> - An SQL fragment like "administrator = 1" or [ "user_name = ?", username ].
# See conditions in the intro to ActiveRecord::Base.
- # * <tt>:include</tt>: Eager loading, see Associations for details. Since calculations don't load anything,
+ # * <tt>:include</tt>: Eager loading, see Associations for details. Since calculations don't load anything,
# the purpose of this is to access fields on joined tables in your conditions, order, or group clauses.
# * <tt>:joins</tt> - An SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id".
# (Rarely needed).
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 4659563f33..c6e8762b4a 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -83,7 +83,7 @@ module ActiveRecord
#
# Example for find with a lock: Imagine two concurrent transactions:
# each will read <tt>person.visits == 2</tt>, add 1 to it, and save, resulting
- # in two saves of <tt>person.visits = 3</tt>. By locking the row, the second
+ # in two saves of <tt>person.visits = 3</tt>. By locking the row, the second
# transaction has to wait until the first is finished; we get the
# expected <tt>person.visits == 4</tt>.
#
diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb
index 243012f88c..9ceab2eabc 100644
--- a/activerecord/lib/active_record/result.rb
+++ b/activerecord/lib/active_record/result.rb
@@ -1,7 +1,7 @@
module ActiveRecord
###
# This class encapsulates a Result returned from calling +exec_query+ on any
- # database connection adapter. For example:
+ # database connection adapter. For example:
#
# x = ActiveRecord::Base.connection.exec_query('SELECT * FROM foo')
# x # => #<ActiveRecord::Result:0xdeadbeef>
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index a893c0ad85..62e6999736 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -106,7 +106,7 @@ HEADER
spec = {}
spec[:name] = column.name.inspect
- # AR has an optimisation which handles zero-scale decimals as integers. This
+ # AR has an optimisation which handles zero-scale decimals as integers. This
# code ensures that the dumper still dumps the column as a decimal.
spec[:type] = if column.type == :integer && [/^numeric/, /^decimal/].any? { |e| e.match(column.sql_type) }
'decimal'
diff --git a/activerecord/lib/active_record/serialization.rb b/activerecord/lib/active_record/serialization.rb
index be4354ce6a..e3185a9c5a 100644
--- a/activerecord/lib/active_record/serialization.rb
+++ b/activerecord/lib/active_record/serialization.rb
@@ -31,9 +31,6 @@ module ActiveRecord #:nodoc:
def serializable_add_includes(options = {})
return unless include_associations = options.delete(:include)
- base_only_or_except = { :except => options[:except],
- :only => options[:only] }
-
include_has_options = include_associations.is_a?(Hash)
associations = include_has_options ? include_associations.keys : Array.wrap(include_associations)
@@ -46,9 +43,8 @@ module ActiveRecord #:nodoc:
end
if records
- association_options = include_has_options ? include_associations[association] : base_only_or_except
- opts = options.merge(association_options)
- yield(association, records, opts)
+ association_options = include_has_options ? include_associations[association] : {}
+ yield(association, records, association_options)
end
end
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb
index 8c4adf7116..f8e6cf958c 100644
--- a/activerecord/lib/active_record/serializers/xml_serializer.rb
+++ b/activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -75,7 +75,7 @@ module ActiveRecord #:nodoc:
# </firm>
#
# Additionally, the record being serialized will be passed to a Proc's second
- # parameter. This allows for ad hoc additions to the resultant document that
+ # parameter. This allows for ad hoc additions to the resultant document that
# incorporate the context of the record being serialized. And by leveraging the
# closure created by a Proc, to_xml can be used to add elements that normally fall
# outside of the scope of the model -- for example, generating and appending URLs
diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb
index c3e976002e..929559c3ba 100644
--- a/activerecord/lib/active_record/session_store.rb
+++ b/activerecord/lib/active_record/session_store.rb
@@ -1,7 +1,7 @@
module ActiveRecord
# = Active Record Session Store
#
- # A session store backed by an Active Record class. A default class is
+ # A session store backed by an Active Record class. A default class is
# provided, but any object duck-typing to an Active Record Session class
# with text +session_id+ and +data+ attributes is sufficient.
#
@@ -23,7 +23,7 @@ module ActiveRecord
# ActiveRecord::SessionStore::Session.data_column_name = 'legacy_session_data'
#
# Note that setting the primary key to the +session_id+ frees you from
- # having a separate +id+ column if you don't want it. However, you must
+ # having a separate +id+ column if you don't want it. However, you must
# set <tt>session.model.id = session.session_id</tt> by hand! A before filter
# on ApplicationController is a good place.
#
@@ -46,7 +46,7 @@ module ActiveRecord
# save
# destroy
#
- # The example SqlBypass class is a generic SQL session store. You may
+ # The example SqlBypass class is a generic SQL session store. You may
# use it as a basis for high-performance database-specific stores.
class SessionStore < ActionDispatch::Session::AbstractStore
module ClassMethods # :nodoc:
@@ -79,7 +79,7 @@ module ActiveRecord
##
# :singleton-method:
- # Customizable data column name. Defaults to 'data'.
+ # Customizable data column name. Defaults to 'data'.
cattr_accessor :data_column_name
self.data_column_name = 'data'
@@ -161,12 +161,12 @@ module ActiveRecord
end
# A barebones session store which duck-types with the default session
- # store but bypasses Active Record and issues SQL directly. This is
+ # store but bypasses Active Record and issues SQL directly. This is
# an example session model class meant as a basis for your own classes.
#
# The database connection, table name, and session id and data columns
- # are configurable class attributes. Marshaling and unmarshaling
- # are implemented as class methods that you may override. By default,
+ # are configurable class attributes. Marshaling and unmarshaling
+ # are implemented as class methods that you may override. By default,
# marshaling data is
#
# ActiveSupport::Base64.encode64(Marshal.dump(data))
@@ -176,7 +176,7 @@ module ActiveRecord
# Marshal.load(ActiveSupport::Base64.decode64(data))
#
# This marshaling behavior is intended to store the widest range of
- # binary session data in a +text+ column. For higher performance,
+ # binary session data in a +text+ column. For higher performance,
# store in a +blob+ column instead and forgo the Base64 encoding.
class SqlBypass
extend ClassMethods
@@ -286,7 +286,7 @@ module ActiveRecord
end
end
- # The class used for session storage. Defaults to
+ # The class used for session storage. Defaults to
# ActiveRecord::SessionStore::Session
cattr_accessor :session_class
self.session_class = Session
diff --git a/activerecord/lib/active_record/test_case.rb b/activerecord/lib/active_record/test_case.rb
index 0d47eb3338..c61428e104 100644
--- a/activerecord/lib/active_record/test_case.rb
+++ b/activerecord/lib/active_record/test_case.rb
@@ -13,7 +13,7 @@ module ActiveRecord
ActiveRecord::IdentityMap.clear
end
- # Backport skip to Ruby 1.8. test/unit doesn't support it, so just
+ # Backport skip to Ruby 1.8. test/unit doesn't support it, so just
# make it a noop.
unless instance_methods.map(&:to_s).include?("skip")
def skip(message)
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 59b6876135..4b075183c3 100644
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -1,7 +1,7 @@
module ActiveRecord
# = Active Record RecordInvalid
#
- # Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
+ # Raised by <tt>save!</tt> and <tt>create!</tt> when the record is invalid. Use the
# +record+ method to retrieve the record which did not validate.
#
# begin
diff --git a/activerecord/lib/active_record/validations/associated.rb b/activerecord/lib/active_record/validations/associated.rb
index 3a783aeb00..5df85304a2 100644
--- a/activerecord/lib/active_record/validations/associated.rb
+++ b/activerecord/lib/active_record/validations/associated.rb
@@ -37,10 +37,10 @@ module ActiveRecord
# validation contexts by default (+nil+), other options are <tt>:create</tt>
# and <tt>:update</tt>.
# * <tt>:if</tt> - Specifies a method, proc or string to call to determine if the validation should
- # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
+ # occur (e.g. <tt>:if => :allow_validation</tt>, or <tt>:if => Proc.new { |user| user.signup_step > 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
- # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
+ # not occur (e.g. <tt>:unless => :skip_validation</tt>, or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The
# method, proc or string should return or evaluate to a true or false value.
def validates_associated(*attr_names)
validates_with AssociatedValidator, _merge_attributes(attr_names)
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 4db4105389..484b1d369b 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -83,7 +83,7 @@ module ActiveRecord
# validates_uniqueness_of :user_name, :scope => :account_id
# end
#
- # Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once
+ # Or even multiple scope parameters. For example, making sure that a teacher can only be on the schedule once
# per semester for a particular class.
#
# class TeacherSchedule < ActiveRecord::Base
@@ -105,7 +105,7 @@ module ActiveRecord
# The method, proc or string should return or evaluate to a true or false value.
# * <tt>:unless</tt> - Specifies a method, proc or string to call to determine if the validation should
# not occur (e.g. <tt>:unless => :skip_validation</tt>, or
- # <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method, proc or string should
+ # <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method, proc or string should
# return or evaluate to a true or false value.
#
# === Concurrency and integrity
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 3e92a77830..325fc58958 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -380,6 +380,18 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal subscriptions, subscriber.subscriptions.sort_by(&:id)
end
+ def test_string_id_column_joins
+ s = Subscriber.create! do |c|
+ c.id = "PL"
+ end
+
+ b = Book.create!
+
+ Subscription.create!(:subscriber_id => "PL", :book_id => b.id)
+ s.reload
+ s.book_ids = s.book_ids
+ end
+
def test_eager_load_has_many_through_with_string_keys
books = books(:awdr, :rfr)
subscriber = Subscriber.find(subscribers(:second).id, :include => :books)
@@ -448,6 +460,12 @@ class EagerAssociationTest < ActiveRecord::TestCase
assert_equal post_tags, eager_post_tags
end
+ def test_eager_with_has_many_through_join_model_ignores_default_includes
+ assert_nothing_raised do
+ authors(:david).comments_on_posts_with_default_include.to_a
+ end
+ end
+
def test_eager_with_has_many_and_limit
posts = Post.find(:all, :order => 'posts.id asc', :include => [ :author, :comments ], :limit => 2)
assert_equal 2, posts.size
@@ -675,6 +693,46 @@ class EagerAssociationTest < ActiveRecord::TestCase
}
end
+ def test_eager_with_default_scope
+ developer = EagerDeveloperWithDefaultScope.where(:name => 'David').first
+ projects = Project.order(:id).all
+ assert_no_queries do
+ assert_equal(projects, developer.projects)
+ end
+ end
+
+ def test_eager_with_default_scope_as_class_method
+ developer = EagerDeveloperWithClassMethodDefaultScope.where(:name => 'David').first
+ projects = Project.order(:id).all
+ assert_no_queries do
+ assert_equal(projects, developer.projects)
+ end
+ end
+
+ def test_eager_with_default_scope_as_lambda
+ developer = EagerDeveloperWithLambdaDefaultScope.where(:name => 'David').first
+ projects = Project.order(:id).all
+ assert_no_queries do
+ assert_equal(projects, developer.projects)
+ end
+ end
+
+ def test_eager_with_default_scope_as_block
+ developer = EagerDeveloperWithBlockDefaultScope.where(:name => 'David').first
+ projects = Project.order(:id).all
+ assert_no_queries do
+ assert_equal(projects, developer.projects)
+ end
+ end
+
+ def test_eager_with_default_scope_as_callable
+ developer = EagerDeveloperWithCallableDefaultScope.where(:name => 'David').first
+ projects = Project.order(:id).all
+ assert_no_queries do
+ assert_equal(projects, developer.projects)
+ end
+ end
+
def find_all_ordered(className, include=nil)
className.find(:all, :order=>"#{className.table_name}.#{className.primary_key}", :include=>include)
end
diff --git a/activerecord/test/cases/associations/habtm_join_table_test.rb b/activerecord/test/cases/associations/habtm_join_table_test.rb
index 745f169ad7..fe2b82f2c1 100644
--- a/activerecord/test/cases/associations/habtm_join_table_test.rb
+++ b/activerecord/test/cases/associations/habtm_join_table_test.rb
@@ -32,13 +32,4 @@ class HabtmJoinTableTest < ActiveRecord::TestCase
ActiveRecord::Base.connection.drop_table :my_readers
ActiveRecord::Base.connection.drop_table :my_books_my_readers
end
-
- uses_transaction :test_should_raise_exception_when_join_table_has_a_primary_key
- def test_should_raise_exception_when_join_table_has_a_primary_key
- if ActiveRecord::Base.connection.supports_primary_key?
- assert_raise ActiveRecord::HasAndBelongsToManyAssociationWithPrimaryKeyError do
- MyReader.has_and_belongs_to_many :my_books
- end
- end
- end
end
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index f4d14853d3..839a7852fc 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -100,6 +100,16 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal 'c1', record[0]
assert_equal 't1', record[1]
end
+
+ def test_proper_usage_of_primary_keys_and_join_table
+ setup_data_for_habtm_case
+
+ assert_equal 'country_id', Country.primary_key
+ assert_equal 'treaty_id', Treaty.primary_key
+
+ country = Country.first
+ assert_equal 1, country.treaties.count
+ end
def test_has_and_belongs_to_many
david = Developer.find(1)
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 522ac56d82..43974fd895 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -11,6 +11,7 @@ require 'models/comment'
require 'models/person'
require 'models/reader'
require 'models/tagging'
+require 'models/tag'
require 'models/invoice'
require 'models/line_item'
require 'models/car'
@@ -1468,4 +1469,10 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
bulb = car.bulbs.build({ :bulb_type => :custom }, :as => :admin)
assert_equal CustomBulb, bulb.class
end
+
+ def test_abstract_class_with_polymorphic_has_many
+ post = SubStiPost.create! :title => "fooo", :body => "baa"
+ tagging = Tagging.create! :taggable => post
+ assert_equal [tagging], post.taggings
+ end
end
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index 89117593fd..877148bd5e 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -766,4 +766,46 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_equal [category.name], post.named_category_ids # checks when target loaded
assert_equal [category.name], post.reload.named_category_ids # checks when target no loaded
end
+
+ def test_create_should_not_raise_exception_when_join_record_has_errors
+ repair_validations(Categorization) do
+ Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
+ Category.create(:name => 'Fishing', :authors => [Author.first])
+ end
+ end
+
+ def test_save_should_not_raise_exception_when_join_record_has_errors
+ repair_validations(Categorization) do
+ Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
+ c = Category.create(:name => 'Fishing', :authors => [Author.first])
+ c.save
+ end
+ end
+
+ def test_create_bang_should_raise_exception_when_join_record_has_errors
+ repair_validations(Categorization) do
+ Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
+ assert_raises(ActiveRecord::RecordInvalid) do
+ Category.create!(:name => 'Fishing', :authors => [Author.first])
+ end
+ end
+ end
+
+ def test_save_bang_should_raise_exception_when_join_record_has_errors
+ repair_validations(Categorization) do
+ Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
+ c = Category.new(:name => 'Fishing', :authors => [Author.first])
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.save!
+ end
+ end
+ end
+
+ def test_create_bang_returns_falsy_when_join_record_has_errors
+ repair_validations(Categorization) do
+ Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' }
+ c = Category.new(:name => 'Fishing', :authors => [Author.first])
+ assert !c.save
+ end
+ end
end
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index f3bf5baa95..299688d840 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -370,15 +370,6 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
assert_nil new_ship.pirate_id
end
- def test_deprecated_association_loaded
- firm = companies(:first_firm)
- firm.association(:account).stubs(:loaded?).returns(stub)
-
- assert_deprecated do
- assert_equal firm.association(:account).loaded?, firm.account_loaded?
- end
- end
-
def test_association_keys_bypass_attribute_protection
car = Car.create(:name => 'honda')
diff --git a/activerecord/test/cases/associations_test.rb b/activerecord/test/cases/associations_test.rb
index 38d439d68a..49d82ba2df 100644
--- a/activerecord/test/cases/associations_test.rb
+++ b/activerecord/test/cases/associations_test.rb
@@ -203,18 +203,6 @@ class AssociationProxyTest < ActiveRecord::TestCase
assert_equal david.projects, david.projects.reload.reload
end
end
-
- # Tests that proxy_owner, proxy_target and proxy_reflection are implement as deprecated methods
- def test_proxy_deprecations
- david = developers(:david)
- david.projects.load_target
-
- [:owner, :target, :reflection].each do |name|
- assert_deprecated do
- assert_equal david.association(:projects).send(name), david.projects.send("proxy_#{name}")
- end
- end
- end
end
class OverridingAssociationsTest < ActiveRecord::TestCase
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 5074ae50ab..54c4d4ae90 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -109,6 +109,14 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert_respond_to topic, :title
end
+ # IRB inspects the return value of "MyModel.allocate"
+ # by inspecting it.
+ def test_allocated_object_can_be_inspected
+ topic = Topic.allocate
+ assert_nothing_raised { topic.inspect }
+ assert topic.inspect, "#<Topic not initialized>"
+ end
+
def test_array_content
topic = Topic.new
topic.content = %w( one two three )
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 87ce537e0e..39043447fc 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -502,13 +502,6 @@ class BasicsTest < ActiveRecord::TestCase
assert_equal 'value2', weird.send('a$b')
end
- def test_attributes_guard_protected_attributes_is_deprecated
- attributes = { "title" => "An amazing title" }
- post = ProtectedTitlePost.new
- assert_deprecated { post.send(:attributes=, attributes, false) }
- assert_equal "An amazing title", post.title
- end
-
def test_multiparameter_attributes_on_date
attributes = { "last_read(1i)" => "2004", "last_read(2i)" => "6", "last_read(3i)" => "24" }
topic = Topic.find(1)
diff --git a/activerecord/test/cases/fixtures/file_test.rb b/activerecord/test/cases/fixtures/file_test.rb
new file mode 100644
index 0000000000..8dbf92ae9a
--- /dev/null
+++ b/activerecord/test/cases/fixtures/file_test.rb
@@ -0,0 +1,83 @@
+require "cases/helper"
+require 'tempfile'
+
+module ActiveRecord
+ class Fixtures
+ class FileTest < ActiveRecord::TestCase
+ def test_open
+ fh = File.open(::File.join(FIXTURES_ROOT, "accounts.yml"))
+ assert_equal 6, fh.to_a.length
+ end
+
+ def test_open_with_block
+ called = false
+ File.open(::File.join(FIXTURES_ROOT, "accounts.yml")) do |fh|
+ called = true
+ assert_equal 6, fh.to_a.length
+ end
+ assert called, 'block called'
+ end
+
+ def test_names
+ File.open(::File.join(FIXTURES_ROOT, "accounts.yml")) do |fh|
+ assert_equal ["signals37",
+ "unknown",
+ "rails_core_account",
+ "last_account",
+ "rails_core_account_2",
+ "odegy_account"].sort, fh.to_a.map(&:first).sort
+ end
+ end
+
+ def test_values
+ File.open(::File.join(FIXTURES_ROOT, "accounts.yml")) do |fh|
+ assert_equal [1,2,3,4,5,6].sort, fh.to_a.map(&:last).map { |x|
+ x['id']
+ }.sort
+ end
+ end
+
+ def test_erb_processing
+ File.open(::File.join(FIXTURES_ROOT, "developers.yml")) do |fh|
+ devs = Array.new(8) { |i| "dev_#{i + 3}" }
+ assert_equal [], devs - fh.to_a.map(&:first)
+ end
+ end
+
+ def test_empty_file
+ tmp_yaml ['empty', 'yml'], '' do |t|
+ assert_equal [], File.open(t.path) { |fh| fh.to_a }
+ end
+ end
+
+ # A valid YAML file is not necessarily a value Fixture file. Make sure
+ # an exception is raised if the format is not valid Fixture format.
+ def test_wrong_fixture_format_string
+ tmp_yaml ['empty', 'yml'], 'qwerty' do |t|
+ assert_raises(ActiveRecord::Fixture::FormatError) do
+ File.open(t.path) { |fh| fh.to_a }
+ end
+ end
+ end
+
+ def test_wrong_fixture_format_nested
+ tmp_yaml ['empty', 'yml'], 'one: two' do |t|
+ assert_raises(ActiveRecord::Fixture::FormatError) do
+ File.open(t.path) { |fh| fh.to_a }
+ end
+ end
+ end
+
+ private
+ def tmp_yaml(name, contents)
+ t = Tempfile.new name
+ t.binmode
+ t.write contents
+ t.close
+ yield t
+ ensure
+ t.close true
+ end
+ end
+ end
+end
diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb
index b0bd9c5763..306b437fb3 100644
--- a/activerecord/test/cases/fixtures_test.rb
+++ b/activerecord/test/cases/fixtures_test.rb
@@ -174,12 +174,6 @@ class FixturesTest < ActiveRecord::TestCase
end
end
- def test_empty_csv_fixtures
- assert_deprecated do
- assert_not_nil ActiveRecord::Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/csv/accounts")
- end
- end
-
def test_omap_fixtures
assert_nothing_raised do
fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")
diff --git a/activerecord/test/cases/helper.rb b/activerecord/test/cases/helper.rb
index fbb4ee6f7b..9644ac1b02 100644
--- a/activerecord/test/cases/helper.rb
+++ b/activerecord/test/cases/helper.rb
@@ -26,8 +26,8 @@ ActiveSupport::Deprecation.debug = true
# Quote "type" if it's a reserved word for the current connection.
QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type')
-# Enable Identity Map for testing
-ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "false" ? false : true)
+# Enable Identity Map only when ENV['IM'] is set to "true"
+ActiveRecord::IdentityMap.enabled = (ENV['IM'] == "true")
def current_adapter?(*types)
types.any? do |type|
diff --git a/activerecord/test/cases/json_serialization_test.rb b/activerecord/test/cases/json_serialization_test.rb
index 8664d63e8f..d9e350abc0 100644
--- a/activerecord/test/cases/json_serialization_test.rb
+++ b/activerecord/test/cases/json_serialization_test.rb
@@ -161,6 +161,15 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
assert_match %r{"tag":\{"name":"General"\}}, json
end
+ def test_includes_doesnt_merge_opts_from_base
+ json = @david.to_json(
+ :only => :id,
+ :include => :posts
+ )
+
+ assert_match %{"title":"Welcome to the weblog"}, json
+ end
+
def test_should_not_call_methods_on_associations_that_dont_respond
def @david.favorite_quote; "Constraints are liberating"; end
json = @david.to_json(:include => :posts, :methods => :favorite_quote)
diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb
index ae531ebb4c..0f79c99e1a 100644
--- a/activerecord/test/cases/migration/command_recorder_test.rb
+++ b/activerecord/test/cases/migration/command_recorder_test.rb
@@ -86,6 +86,18 @@ module ActiveRecord
assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove
end
+ def test_invert_add_index_with_name
+ @recorder.record :add_index, [:table, [:one, :two], {:name => "new_index"}]
+ remove = @recorder.inverse.first
+ assert_equal [:remove_index, [:table, {:name => "new_index"}]], remove
+ end
+
+ def test_invert_add_index_with_no_options
+ @recorder.record :add_index, [:table, [:one, :two]]
+ remove = @recorder.inverse.first
+ assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove
+ end
+
def test_invert_rename_index
@recorder.record :rename_index, [:old, :new]
rename = @recorder.inverse.first
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 97d9669483..58c78ab058 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -216,7 +216,7 @@ class ReflectionTest < ActiveRecord::TestCase
def test_conditions
expected = [
[{ :tags => { :name => 'Blue' } }],
- [{ :taggings => { :comment => 'first' } }, { "taggable_type" => "Post" }],
+ [{ :taggings => { :comment => 'first' } }],
[{ :posts => { :title => ['misc post by bob', 'misc post by mary'] } }]
]
actual = Author.reflect_on_association(:misc_post_first_blue_tags).conditions
@@ -224,7 +224,7 @@ class ReflectionTest < ActiveRecord::TestCase
expected = [
[{ :tags => { :name => 'Blue' } }, { :taggings => { :comment => 'first' } }, { :posts => { :title => ['misc post by bob', 'misc post by mary'] } }],
- [{ "taggable_type" => "Post" }],
+ [],
[]
]
actual = Author.reflect_on_association(:misc_post_first_blue_tags_2).conditions
@@ -304,13 +304,6 @@ class ReflectionTest < ActiveRecord::TestCase
assert_equal "category_id", Post.reflect_on_association(:categorizations).foreign_key.to_s
end
- def test_primary_key_name
- assert_deprecated do
- assert_equal "author_id", Author.reflect_on_association(:posts).primary_key_name.to_s
- assert_equal "category_id", Post.reflect_on_association(:categorizations).primary_key_name.to_s
- end
- end
-
private
def assert_reflection(klass, association, options)
assert reflection = klass.reflect_on_association(association)
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb
index c215602567..8f8e72f052 100644
--- a/activerecord/test/cases/relation_scoping_test.rb
+++ b/activerecord/test/cases/relation_scoping_test.rb
@@ -312,6 +312,14 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal [developers(:david).becomes(ClassMethodDeveloperCalledDavid)], ClassMethodDeveloperCalledDavid.all
end
+ def test_default_scope_as_class_method_referencing_scope
+ assert_equal [developers(:david).becomes(ClassMethodReferencingScopeDeveloperCalledDavid)], ClassMethodReferencingScopeDeveloperCalledDavid.all
+ end
+
+ def test_default_scope_as_block_referencing_scope
+ assert_equal [developers(:david).becomes(LazyBlockReferencingScopeDeveloperCalledDavid)], LazyBlockReferencingScopeDeveloperCalledDavid.all
+ end
+
def test_default_scope_with_lambda
assert_equal [developers(:david).becomes(LazyLambdaDeveloperCalledDavid)], LazyLambdaDeveloperCalledDavid.all
end
diff --git a/activerecord/test/fixtures/categories_ordered.yml b/activerecord/test/fixtures/categories_ordered.yml
index 2afc6cb5a9..294a6368d6 100644
--- a/activerecord/test/fixtures/categories_ordered.yml
+++ b/activerecord/test/fixtures/categories_ordered.yml
@@ -1,4 +1,4 @@
---- !!omap
+--- !omap
<% 100.times do |i| %>
- fixture_no_<%= i %>:
id: <%= i %>
diff --git a/activerecord/test/fixtures/parrots.yml b/activerecord/test/fixtures/parrots.yml
index 8b73b8cdf6..8425ef98e0 100644
--- a/activerecord/test/fixtures/parrots.yml
+++ b/activerecord/test/fixtures/parrots.yml
@@ -24,4 +24,4 @@ DEFAULTS: &DEFAULTS
parrot_sti_class: LiveParrot
davey:
- <<: *DEFAULTS
+ *DEFAULTS
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
index e0cbc44265..23db5650d4 100644
--- a/activerecord/test/models/author.rb
+++ b/activerecord/test/models/author.rb
@@ -138,6 +138,9 @@ class Author < ActiveRecord::Base
has_many :misc_post_first_blue_tags_2, :through => :posts, :source => :first_blue_tags_2,
:conditions => { :posts => { :title => ['misc post by bob', 'misc post by mary'] } }
+ has_many :posts_with_default_include, :class_name => 'PostWithDefaultInclude'
+ has_many :comments_on_posts_with_default_include, :through => :posts_with_default_include, :source => :comments
+
scope :relation_include_posts, includes(:posts)
scope :relation_include_tags, includes(:tags)
diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb
index 152f804e16..41c52f7df0 100644
--- a/activerecord/test/models/developer.rb
+++ b/activerecord/test/models/developer.rb
@@ -127,6 +127,21 @@ class ClassMethodDeveloperCalledDavid < ActiveRecord::Base
end
end
+class ClassMethodReferencingScopeDeveloperCalledDavid < ActiveRecord::Base
+ self.table_name = 'developers'
+ scope :david, where(:name => 'David')
+
+ def self.default_scope
+ david
+ end
+end
+
+class LazyBlockReferencingScopeDeveloperCalledDavid < ActiveRecord::Base
+ self.table_name = 'developers'
+ scope :david, where(:name => 'David')
+ default_scope { david }
+end
+
class DeveloperCalledJamis < ActiveRecord::Base
self.table_name = 'developers'
@@ -165,4 +180,39 @@ class ModuleIncludedPoorDeveloperCalledJamis < DeveloperCalledJamis
include SalaryDefaultScope
end
+class EagerDeveloperWithDefaultScope < ActiveRecord::Base
+ self.table_name = 'developers'
+ has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id'
+
+ default_scope includes(:projects)
+end
+class EagerDeveloperWithClassMethodDefaultScope < ActiveRecord::Base
+ self.table_name = 'developers'
+ has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id'
+
+ def self.default_scope
+ includes(:projects)
+ end
+end
+
+class EagerDeveloperWithLambdaDefaultScope < ActiveRecord::Base
+ self.table_name = 'developers'
+ has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id'
+
+ default_scope lambda { includes(:projects) }
+end
+
+class EagerDeveloperWithBlockDefaultScope < ActiveRecord::Base
+ self.table_name = 'developers'
+ has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id'
+
+ default_scope { includes(:projects) }
+end
+
+class EagerDeveloperWithCallableDefaultScope < ActiveRecord::Base
+ self.table_name = 'developers'
+ has_and_belongs_to_many :projects, :foreign_key => 'developer_id', :join_table => 'developers_projects', :order => 'projects.id'
+
+ default_scope OpenStruct.new(:call => includes(:projects))
+end
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index 80296032bb..f2ab7b053e 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -162,3 +162,9 @@ class FirstPost < ActiveRecord::Base
has_many :comments, :foreign_key => :post_id
has_one :comment, :foreign_key => :post_id
end
+
+class PostWithDefaultInclude < ActiveRecord::Base
+ self.table_name = 'posts'
+ default_scope includes(:comments)
+ has_many :comments, :foreign_key => :post_id
+end \ No newline at end of file
diff --git a/activeresource/README.rdoc b/activeresource/README.rdoc
index afa25e1676..b03e8c4c25 100644
--- a/activeresource/README.rdoc
+++ b/activeresource/README.rdoc
@@ -20,6 +20,16 @@ Model classes are mapped to remote REST resources by Active Resource much the sa
tables. When a request is made to a remote resource, a REST XML request is generated, transmitted, and the result
received and serialized into a usable Ruby object.
+== Download and installation
+
+The latest version of Active Support can be installed with Rubygems:
+
+ % [sudo] gem install activeresource
+
+Source code can be downloaded as part of the Rails project on GitHub
+
+* https://github.com/rails/rails/tree/master/activeresource/
+
=== Configuration and Usage
Putting Active Resource to use is very similar to Active Record. It's as simple as creating a model class
@@ -160,6 +170,18 @@ Destruction of a resource can be invoked as a class and instance method of the r
Person.delete(2) # => true
Person.exists?(2) # => false
+== License
-You can find more usage information in the ActiveResource::Base documentation.
+Active Support is released under the MIT license.
+== Support
+
+API documentation is at
+
+* http://api.rubyonrails.org
+
+Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
+
+* https://github.com/rails/rails/issues
+
+You can find more usage information in the ActiveResource::Base documentation.
diff --git a/activeresource/Rakefile b/activeresource/Rakefile
index 42e450da66..b1c18ff189 100755
--- a/activeresource/Rakefile
+++ b/activeresource/Rakefile
@@ -1,7 +1,7 @@
#!/usr/bin/env rake
require 'rake/testtask'
require 'rake/packagetask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
desc "Default Task"
task :default => [ :test ]
@@ -26,7 +26,7 @@ end
spec = eval(File.read('activeresource.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
diff --git a/activeresource/activeresource.gemspec b/activeresource/activeresource.gemspec
index 400a0d851d..a8772ecf8c 100644
--- a/activeresource/activeresource.gemspec
+++ b/activeresource/activeresource.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.email = 'david@loudthinking.com'
s.homepage = 'http://www.rubyonrails.org'
- s.files = Dir['CHANGELOG', 'README.rdoc', 'examples/**/*', 'lib/**/*']
+ s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README.rdoc', 'examples/**/*', 'lib/**/*']
s.require_path = 'lib'
s.extra_rdoc_files = %w( README.rdoc )
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index e90580be4f..6167c1420e 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -55,7 +55,7 @@ module ActiveResource
@responses = responses
end
- for method in [ :post, :put, :get, :delete, :head ]
+ [ :post, :put, :get, :delete, :head ].each do |method|
# def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})
# @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
# end
diff --git a/activeresource/test/abstract_unit.rb b/activeresource/test/abstract_unit.rb
index 948dd94a1d..9c1e9a526d 100644
--- a/activeresource/test/abstract_unit.rb
+++ b/activeresource/test/abstract_unit.rb
@@ -3,7 +3,6 @@ require File.expand_path('../../../load_paths', __FILE__)
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
-require 'rubygems'
require 'test/unit'
require 'active_resource'
require 'active_support'
@@ -14,11 +13,6 @@ require 'setter_trap'
require 'logger'
ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
-begin
- require 'ruby-debug'
-rescue LoadError
-end
-
def setup_response
matz_hash = { 'person' => { :id => 1, :name => 'Matz' } }
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 23b0df1d5c..bf48306684 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,14 @@
+*Rails 3.2.0 (unreleased)*
+
+* Removed ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
+
+* ActiveSupport::OrderedHash now has different behavior for #each and
+#each_pair when given a block accepting its parameters with a splat. [Andrew Radev]
+
*Rails 3.1.0 (unreleased)*
+* Deprecated ActiveSupport::SecureRandom in favour of SecureRandom from the standard library [Jon Leighton]
+
* New reporting method Kernel#quietly. [fxn]
* Add String#inquiry as a convenience method for turning a string into a StringInquirer object [DHH]
diff --git a/activesupport/README.rdoc b/activesupport/README.rdoc
index 8bb15e849a..a38ad76f43 100644
--- a/activesupport/README.rdoc
+++ b/activesupport/README.rdoc
@@ -26,7 +26,7 @@ Active Support is released under the MIT license.
API documentation is at
-* http://api.rubyonrails.com
+* http://api.rubyonrails.org
Bug reports and feature requests can be filed with the rest for the Ruby on Rails project here:
diff --git a/activesupport/Rakefile b/activesupport/Rakefile
index d117ca6356..822c9d98ae 100755
--- a/activesupport/Rakefile
+++ b/activesupport/Rakefile
@@ -1,5 +1,5 @@
require 'rake/testtask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
task :default => :test
Rake::TestTask.new do |t|
@@ -20,7 +20,7 @@ dist_dirs = [ "lib", "test"]
spec = eval(File.read('activesupport.gemspec'))
-Rake::GemPackageTask.new(spec) do |p|
+Gem::PackageTask.new(spec) do |p|
p.gem_spec = spec
end
diff --git a/activesupport/activesupport.gemspec b/activesupport/activesupport.gemspec
index f6eb2be5ae..2ee6bb788a 100644
--- a/activesupport/activesupport.gemspec
+++ b/activesupport/activesupport.gemspec
@@ -9,12 +9,13 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.8.7'
- s.author = 'David Heinemeier Hansson'
- s.email = 'david@loudthinking.com'
- s.homepage = 'http://www.rubyonrails.org'
+ s.author = 'David Heinemeier Hansson'
+ s.email = 'david@loudthinking.com'
+ s.homepage = 'http://www.rubyonrails.org'
- s.files = Dir['CHANGELOG', 'README.rdoc', 'lib/**/*']
+ s.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README.rdoc', 'lib/**/*']
s.require_path = 'lib'
+ s.add_dependency('i18n', '~> 0.6')
s.add_dependency('multi_json', '~> 1.0')
end
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb
index a846f81c12..cc9ea5cffa 100644
--- a/activesupport/lib/active_support.rb
+++ b/activesupport/lib/active_support.rb
@@ -21,6 +21,8 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
+require 'securerandom'
+
module ActiveSupport
class << self
attr_accessor :load_all_hooks
@@ -30,7 +32,7 @@ module ActiveSupport
self.load_all_hooks = []
on_load_all do
- [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte, SecureRandom]
+ [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte]
end
end
@@ -68,7 +70,6 @@ module ActiveSupport
autoload :OrderedHash
autoload :OrderedOptions
autoload :Rescuable
- autoload :SecureRandom
autoload :StringInquirer
autoload :XmlMini
end
diff --git a/activesupport/lib/active_support/benchmarkable.rb b/activesupport/lib/active_support/benchmarkable.rb
index df62c18f41..e303eaa5ce 100644
--- a/activesupport/lib/active_support/benchmarkable.rb
+++ b/activesupport/lib/active_support/benchmarkable.rb
@@ -6,7 +6,7 @@ module ActiveSupport
# Allows you to measure the execution time of a block
# in a template and records the result to the log. Wrap this block around
# expensive operations or possible bottlenecks to get a time reading
- # for the operation. For example, let's say you thought your file
+ # for the operation. For example, let's say you thought your file
# processing method was taking too long; you could wrap it in a benchmark block.
#
# <% benchmark "Process data files" do %>
@@ -31,13 +31,8 @@ module ActiveSupport
# <% end %>
def benchmark(message = "Benchmarking", options = {})
if logger
- if options.is_a?(Symbol)
- ActiveSupport::Deprecation.warn("use benchmark('#{message}', :level => :#{options}) instead", caller)
- options = { :level => options, :silence => false }
- else
- options.assert_valid_keys(:level, :silence)
- options[:level] ||= :info
- end
+ options.assert_valid_keys(:level, :silence)
+ options[:level] ||= :info
result = nil
ms = Benchmark.ms { result = options[:silence] ? logger.silence { yield } : yield }
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index 2668087f57..26412cd7f4 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -77,7 +77,7 @@ module ActiveSupport
# def info
# def warn
# def debug
- for severity in Severity.constants
+ Severity.constants.each do |severity|
class_eval <<-EOT, __FILE__, __LINE__ + 1
def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block)
diff --git a/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb b/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb
deleted file mode 100644
index 7c7d1c4b00..0000000000
--- a/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module ActiveSupport
- module Cache
- class CompressedMemCacheStore < MemCacheStore
- def initialize(*args)
- ActiveSupport::Deprecation.warn('ActiveSupport::Cache::CompressedMemCacheStore has been deprecated in favor of ActiveSupport::Cache::MemCacheStore(:compress => true).', caller)
- addresses = args.dup
- options = addresses.extract_options!
- args = addresses + [options.merge(:compress => true)]
- super(*args)
- end
- end
- end
-end
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb
index a1376ae52a..c4da04e532 100644
--- a/activesupport/lib/active_support/cache/file_store.rb
+++ b/activesupport/lib/active_support/cache/file_store.rb
@@ -77,19 +77,7 @@ module ActiveSupport
def read_entry(key, options)
file_name = key_file_path(key)
if File.exist?(file_name)
- entry = File.open(file_name) { |f| Marshal.load(f) }
- if entry && !entry.expired? && !entry.expires_in && !self.options[:expires_in]
- # Check for deprecated use of +:expires_in+ option from versions < 3.0
- deprecated_expires_in = options[:expires_in]
- if deprecated_expires_in
- ActiveSupport::Deprecation.warn('Setting :expires_in on read has been deprecated in favor of setting it on write.', caller)
- if entry.created_at + deprecated_expires_in.to_f <= Time.now.to_f
- delete_entry(key, options)
- entry = nil
- end
- end
- end
- entry
+ File.open(file_name) { |f| Marshal.load(f) }
end
rescue
nil
diff --git a/activesupport/lib/active_support/cache/synchronized_memory_store.rb b/activesupport/lib/active_support/cache/synchronized_memory_store.rb
deleted file mode 100644
index 37caa6b6f1..0000000000
--- a/activesupport/lib/active_support/cache/synchronized_memory_store.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module ActiveSupport
- module Cache
- # Like MemoryStore, but thread-safe.
- class SynchronizedMemoryStore < MemoryStore
- def initialize(*args)
- ActiveSupport::Deprecation.warn('ActiveSupport::Cache::SynchronizedMemoryStore has been deprecated in favor of ActiveSupport::Cache::MemoryStore.', caller)
- super
- end
- end
- end
-end
diff --git a/activesupport/lib/active_support/core_ext/class.rb b/activesupport/lib/active_support/core_ext/class.rb
index 6f308a0d62..86b752c2f3 100644
--- a/activesupport/lib/active_support/core_ext/class.rb
+++ b/activesupport/lib/active_support/core_ext/class.rb
@@ -1,5 +1,4 @@
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/class/attribute_accessors'
-require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/core_ext/class/delegating_attributes'
require 'active_support/core_ext/class/subclasses'
diff --git a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb b/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
deleted file mode 100644
index ec475134ef..0000000000
--- a/activesupport/lib/active_support/core_ext/class/inheritable_attributes.rb
+++ /dev/null
@@ -1,178 +0,0 @@
-require 'active_support/core_ext/object/duplicable'
-require 'active_support/core_ext/array/extract_options'
-require 'active_support/deprecation'
-
-# Retained for backward compatibility. Methods are now included in Class.
-module ClassInheritableAttributes # :nodoc:
- DEPRECATION_WARNING_MESSAGE = "class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first"
-end
-
-# It is recommended to use <tt>class_attribute</tt> over methods defined in this file. Please
-# refer to documentation for <tt>class_attribute</tt> for more information. Officially it is not
-# deprecated but <tt>class_attribute</tt> is faster.
-#
-# Allows attributes to be shared within an inheritance hierarchy. Each descendant gets a copy of
-# their parents' attributes, instead of just a pointer to the same. This means that the child can add elements
-# to, for example, an array without those additions being shared with either their parent, siblings, or
-# children. This is unlike the regular class-level attributes that are shared across the entire hierarchy.
-#
-# The copies of inheritable parent attributes are added to subclasses when they are created, via the
-# +inherited+ hook.
-#
-# class Person
-# class_inheritable_accessor :hair_colors
-# end
-#
-# Person.hair_colors = [:brown, :black, :blonde, :red]
-# Person.hair_colors # => [:brown, :black, :blonde, :red]
-# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
-#
-# To opt out of the instance writer method, pass :instance_writer => false.
-# To opt out of the instance reader method, pass :instance_reader => false.
-#
-# class Person
-# class_inheritable_accessor :hair_colors :instance_writer => false, :instance_reader => false
-# end
-#
-# Person.new.hair_colors = [:brown] # => NoMethodError
-# Person.new.hair_colors # => NoMethodError
-class Class # :nodoc:
- def class_inheritable_reader(*syms)
- ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
- options = syms.extract_options!
- syms.each do |sym|
- next if sym.is_a?(Hash)
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def self.#{sym} # def self.after_add
- read_inheritable_attribute(:#{sym}) # read_inheritable_attribute(:after_add)
- end # end
- #
- #{" #
- def #{sym} # def after_add
- self.class.#{sym} # self.class.after_add
- end # end
- " unless options[:instance_reader] == false } # # the reader above is generated unless options[:instance_reader] == false
- EOS
- end
- end
-
- def class_inheritable_writer(*syms)
- ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
- options = syms.extract_options!
- syms.each do |sym|
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def self.#{sym}=(obj) # def self.color=(obj)
- write_inheritable_attribute(:#{sym}, obj) # write_inheritable_attribute(:color, obj)
- end # end
- #
- #{" #
- def #{sym}=(obj) # def color=(obj)
- self.class.#{sym} = obj # self.class.color = obj
- end # end
- " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false
- EOS
- end
- end
-
- def class_inheritable_array_writer(*syms)
- ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
- options = syms.extract_options!
- syms.each do |sym|
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def self.#{sym}=(obj) # def self.levels=(obj)
- write_inheritable_array(:#{sym}, obj) # write_inheritable_array(:levels, obj)
- end # end
- #
- #{" #
- def #{sym}=(obj) # def levels=(obj)
- self.class.#{sym} = obj # self.class.levels = obj
- end # end
- " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false
- EOS
- end
- end
-
- def class_inheritable_hash_writer(*syms)
- ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
- options = syms.extract_options!
- syms.each do |sym|
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def self.#{sym}=(obj) # def self.nicknames=(obj)
- write_inheritable_hash(:#{sym}, obj) # write_inheritable_hash(:nicknames, obj)
- end # end
- #
- #{" #
- def #{sym}=(obj) # def nicknames=(obj)
- self.class.#{sym} = obj # self.class.nicknames = obj
- end # end
- " unless options[:instance_writer] == false } # # the writer above is generated unless options[:instance_writer] == false
- EOS
- end
- end
-
- def class_inheritable_accessor(*syms)
- class_inheritable_reader(*syms)
- class_inheritable_writer(*syms)
- end
-
- def class_inheritable_array(*syms)
- class_inheritable_reader(*syms)
- class_inheritable_array_writer(*syms)
- end
-
- def class_inheritable_hash(*syms)
- class_inheritable_reader(*syms)
- class_inheritable_hash_writer(*syms)
- end
-
- def inheritable_attributes
- @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES
- end
-
- def write_inheritable_attribute(key, value)
- if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
- @inheritable_attributes = {}
- end
- inheritable_attributes[key] = value
- end
-
- def write_inheritable_array(key, elements)
- write_inheritable_attribute(key, []) if read_inheritable_attribute(key).nil?
- write_inheritable_attribute(key, read_inheritable_attribute(key) + elements)
- end
-
- def write_inheritable_hash(key, hash)
- write_inheritable_attribute(key, {}) if read_inheritable_attribute(key).nil?
- write_inheritable_attribute(key, read_inheritable_attribute(key).merge(hash))
- end
-
- def read_inheritable_attribute(key)
- inheritable_attributes[key]
- end
-
- def reset_inheritable_attributes
- ActiveSupport::Deprecation.warn ClassInheritableAttributes::DEPRECATION_WARNING_MESSAGE
- @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
- end
-
- private
- # Prevent this constant from being created multiple times
- EMPTY_INHERITABLE_ATTRIBUTES = {}.freeze
-
- def inherited_with_inheritable_attributes(child)
- inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes)
-
- if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
- new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
- else
- new_inheritable_attributes = Hash[inheritable_attributes.map do |(key, value)|
- [key, value.duplicable? ? value.dup : value]
- end]
- end
-
- child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
- end
-
- alias inherited_without_inheritable_attributes inherited
- alias inherited inherited_with_inheritable_attributes
-end
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 236055d77a..26a99658cc 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -103,7 +103,7 @@ class Date
alias_method :minus_without_duration, :-
alias_method :-, :minus_with_duration
- # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
+ # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
# any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
def advance(options)
options = options.dup
diff --git a/activesupport/lib/active_support/core_ext/file/atomic.rb b/activesupport/lib/active_support/core_ext/file/atomic.rb
index 26b73ed442..3645597301 100644
--- a/activesupport/lib/active_support/core_ext/file/atomic.rb
+++ b/activesupport/lib/active_support/core_ext/file/atomic.rb
@@ -1,5 +1,5 @@
class File
- # Write to a file atomically. Useful for situations where you don't
+ # Write to a file atomically. Useful for situations where you don't
# want other processes or threads to see half-written files.
#
# File.atomic_write("important.file") do |file|
diff --git a/activesupport/lib/active_support/core_ext/kernel.rb b/activesupport/lib/active_support/core_ext/kernel.rb
index 01cfe7fc10..0275f4c037 100644
--- a/activesupport/lib/active_support/core_ext/kernel.rb
+++ b/activesupport/lib/active_support/core_ext/kernel.rb
@@ -1,5 +1,4 @@
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/kernel/agnostics'
-require 'active_support/core_ext/kernel/requires'
require 'active_support/core_ext/kernel/debugger'
require 'active_support/core_ext/kernel/singleton_class'
diff --git a/activesupport/lib/active_support/core_ext/kernel/agnostics.rb b/activesupport/lib/active_support/core_ext/kernel/agnostics.rb
index c0cb4fb427..64837d87aa 100644
--- a/activesupport/lib/active_support/core_ext/kernel/agnostics.rb
+++ b/activesupport/lib/active_support/core_ext/kernel/agnostics.rb
@@ -1,11 +1,11 @@
class Object
# Makes backticks behave (somewhat more) similarly on all platforms.
# On win32 `nonexistent_command` raises Errno::ENOENT; on Unix, the
- # spawned shell prints a message to stderr and sets $?. We emulate
+ # spawned shell prints a message to stderr and sets $?. We emulate
# Unix on the former but not the latter.
def `(command) #:nodoc:
super
rescue Errno::ENOENT => e
STDERR.puts "#$0: #{e}"
end
-end \ No newline at end of file
+end
diff --git a/activesupport/lib/active_support/core_ext/kernel/debugger.rb b/activesupport/lib/active_support/core_ext/kernel/debugger.rb
index 692340c7c7..7516f41e0b 100644
--- a/activesupport/lib/active_support/core_ext/kernel/debugger.rb
+++ b/activesupport/lib/active_support/core_ext/kernel/debugger.rb
@@ -5,12 +5,6 @@ module Kernel
message = "\n***** Debugger requested, but was not available (ensure ruby-debug is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n"
defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
end
- end
-
- undef :breakpoint if respond_to?(:breakpoint)
- def breakpoint
- message = "\n***** The 'breakpoint' command has been renamed 'debugger' -- please change *****\n"
- defined?(Rails) ? Rails.logger.info(message) : $stderr.puts(message)
- debugger
+ alias breakpoint debugger unless respond_to?(:breakpoint)
end
end
diff --git a/activesupport/lib/active_support/core_ext/kernel/requires.rb b/activesupport/lib/active_support/core_ext/kernel/requires.rb
deleted file mode 100644
index 3bf46271d7..0000000000
--- a/activesupport/lib/active_support/core_ext/kernel/requires.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'active_support/core_ext/kernel/reporting'
-
-module Kernel
- # Require a library with fallback to RubyGems. Warnings during library
- # loading are silenced to increase signal/noise for application warnings.
- def require_library_or_gem(library_name)
- silence_warnings do
- begin
- require library_name
- rescue LoadError => cannot_require
- # 1. Requiring the module is unsuccessful, maybe it's a gem and nobody required rubygems yet. Try.
- begin
- require 'rubygems'
- rescue LoadError # => rubygems_not_installed
- raise cannot_require
- end
- # 2. Rubygems is installed and loaded. Try to load the library again
- begin
- require library_name
- rescue LoadError # => gem_not_installed
- raise cannot_require
- end
- end
- end
- end
-end
diff --git a/activesupport/lib/active_support/core_ext/module.rb b/activesupport/lib/active_support/core_ext/module.rb
index f59fcd123c..9fed346b7c 100644
--- a/activesupport/lib/active_support/core_ext/module.rb
+++ b/activesupport/lib/active_support/core_ext/module.rb
@@ -4,7 +4,6 @@ require 'active_support/core_ext/module/anonymous'
require 'active_support/core_ext/module/reachable'
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/module/attr_internal'
-require 'active_support/core_ext/module/attr_accessor_with_default'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/synchronization'
require 'active_support/core_ext/module/deprecation'
diff --git a/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb b/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
deleted file mode 100644
index 984f6fb957..0000000000
--- a/activesupport/lib/active_support/core_ext/module/attr_accessor_with_default.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-class Module
- # Declare an attribute accessor with an initial default return value.
- #
- # To give attribute <tt>:age</tt> the initial value <tt>25</tt>:
- #
- # class Person
- # attr_accessor_with_default :age, 25
- # end
- #
- # person = Person.new
- # person.age # => 25
- #
- # person.age = 26
- # person.age # => 26
- #
- # To give attribute <tt>:element_name</tt> a dynamic default value, evaluated
- # in scope of self:
- #
- # attr_accessor_with_default(:element_name) { name.underscore }
- #
- def attr_accessor_with_default(sym, default = Proc.new)
- ActiveSupport::Deprecation.warn "attr_accessor_with_default is deprecated. Use Ruby instead!"
- define_method(sym, block_given? ? default : Proc.new { default })
- module_eval(<<-EVAL, __FILE__, __LINE__ + 1)
- def #{sym}=(value) # def age=(value)
- class << self; attr_accessor :#{sym} end # class << self; attr_accessor :age end
- @#{sym} = value # @age = value
- end # end
- EVAL
- end
-end
diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb
index fb5abf2aa5..8221dc4abe 100644
--- a/activesupport/lib/active_support/core_ext/object/blank.rb
+++ b/activesupport/lib/active_support/core_ext/object/blank.rb
@@ -22,7 +22,7 @@ class Object
# <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
#
# This is handy for any representation of objects where blank is the same
- # as not present at all. For example, this simplifies a common check for
+ # as not present at all. For example, this simplifies a common check for
# HTTP POST/query parameters:
#
# state = params[:state] if params[:state].present?
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index dc10f78104..cae68c3c95 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -5,7 +5,6 @@ require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/module/introspection'
require 'active_support/core_ext/module/anonymous'
-require 'active_support/core_ext/module/deprecation'
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/load_error'
require 'active_support/core_ext/name_error'
@@ -550,23 +549,6 @@ module ActiveSupport #:nodoc:
end
alias :get :[]
- class Getter # :nodoc:
- def initialize(name)
- @name = name
- end
-
- def get
- Reference.get @name
- end
- deprecate :get
- end
-
- def new(name)
- self[name] = name
- Getter.new(name)
- end
- deprecate :new
-
def store(name)
self[name] = name
self
@@ -579,11 +561,6 @@ module ActiveSupport #:nodoc:
Reference = ClassCache.new
- def ref(name)
- Reference.new(name)
- end
- deprecate :ref
-
# Store a reference to a class +klass+.
def reference(klass)
Reference.store klass
@@ -652,7 +629,7 @@ module ActiveSupport #:nodoc:
end
class LoadingModule #:nodoc:
- # Old style environment.rb referenced this method directly. Please note, it doesn't
+ # Old style environment.rb referenced this method directly. Please note, it doesn't
# actually *do* anything any more.
def self.root(*args)
if defined?(Rails) && Rails.logger
diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb
index 00ea8813dd..f9c5e5e2f8 100644
--- a/activesupport/lib/active_support/i18n.rb
+++ b/activesupport/lib/active_support/i18n.rb
@@ -2,7 +2,7 @@ begin
require 'i18n'
require 'active_support/lazy_load_hooks'
rescue LoadError => e
- $stderr.puts "You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install"
+ $stderr.puts "The i18n gem is not available. Please add it to your Gemfile and run bundle install"
raise e
end
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index d22fe14b33..67698c1cff 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -1,6 +1,5 @@
require 'active_support/core_ext/object/to_json'
require 'active_support/core_ext/module/delegation'
-require 'active_support/deprecation'
require 'active_support/json/variable'
require 'active_support/ordered_hash'
@@ -14,6 +13,7 @@ require 'time'
require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/date_time/conversions'
require 'active_support/core_ext/date/conversions'
+require 'set'
module ActiveSupport
class << self
@@ -39,7 +39,7 @@ module ActiveSupport
def initialize(options = nil)
@options = options
- @seen = []
+ @seen = Set.new
end
def encode(value, use_options = true)
@@ -71,13 +71,12 @@ module ActiveSupport
private
def check_for_circular_references(value)
- if @seen.any? { |object| object.equal?(value) }
+ unless @seen.add?(value.__id__)
raise CircularReferenceError, 'object references itself'
end
- @seen.unshift value
yield
ensure
- @seen.shift
+ @seen.delete(value.__id__)
end
end
@@ -139,8 +138,6 @@ module ActiveSupport
self.use_standard_json_time_format = true
self.escape_html_entities_in_json = false
end
-
- CircularReferenceError = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::JSON::CircularReferenceError', Encoding::CircularReferenceError)
end
end
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index 441fefb491..3941c285a2 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -1,4 +1,3 @@
-require 'active_support/secure_random'
require 'active_support/core_ext/module/delegation'
module ActiveSupport
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb
index 762a64a881..68f4bd66da 100644
--- a/activesupport/lib/active_support/ordered_hash.rb
+++ b/activesupport/lib/active_support/ordered_hash.rb
@@ -158,7 +158,11 @@ module ActiveSupport
self
end
- alias_method :each_pair, :each
+ def each_pair
+ return to_enum(:each_pair) unless block_given?
+ @keys.each {|key| yield key, self[key]}
+ self
+ end
alias_method :select, :find_all
diff --git a/activesupport/lib/active_support/secure_random.rb b/activesupport/lib/active_support/secure_random.rb
deleted file mode 100644
index 52f8c72b77..0000000000
--- a/activesupport/lib/active_support/secure_random.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require 'securerandom'
-
-module ActiveSupport
- # Use Ruby's SecureRandom library.
- SecureRandom = ::SecureRandom # :nodoc:
-end
diff --git a/activesupport/lib/active_support/testing/performance/jruby.rb b/activesupport/lib/active_support/testing/performance/jruby.rb
index 6b27959840..326904bbac 100644
--- a/activesupport/lib/active_support/testing/performance/jruby.rb
+++ b/activesupport/lib/active_support/testing/performance/jruby.rb
@@ -1,6 +1,6 @@
require 'jruby/profiler'
require 'java'
-import java.lang.management.ManagementFactory
+java_import java.lang.management.ManagementFactory
module ActiveSupport
module Testing
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index abd585b64f..728921a069 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -315,10 +315,8 @@ module ActiveSupport
tzinfo.period_for_local(time, dst)
end
- # TODO: Preload instead of lazy load for thread safety
def self.find_tzinfo(name)
- require 'active_support/tzinfo' unless defined?(::TZInfo)
- ::TZInfo::TimezoneProxy.new(MAPPING[name] || name)
+ TZInfo::TimezoneProxy.new(MAPPING[name] || name)
end
class << self
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index 6e12404ad4..1ea9a9d7e1 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -1,3 +1,4 @@
+require 'time'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/string/inflections'
@@ -51,13 +52,12 @@ module ActiveSupport
"yaml" => Proc.new { |yaml| yaml.to_yaml }
} unless defined?(FORMATTING)
- # TODO: use Time.xmlschema instead of Time.parse;
- # use regexp instead of Date.parse
+ # TODO use regexp instead of Date.parse
unless defined?(PARSING)
PARSING = {
"symbol" => Proc.new { |symbol| symbol.to_sym },
"date" => Proc.new { |date| ::Date.parse(date) },
- "datetime" => Proc.new { |time| ::Time.parse(time).utc rescue ::DateTime.parse(time).utc },
+ "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
"integer" => Proc.new { |integer| integer.to_i },
"float" => Proc.new { |float| float.to_f },
"decimal" => Proc.new { |number| BigDecimal(number) },
diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb
index 48c1cb3fe9..6c222b83ba 100644
--- a/activesupport/lib/active_support/xml_mini/jdom.rb
+++ b/activesupport/lib/active_support/xml_mini/jdom.rb
@@ -5,12 +5,12 @@ include Java
require 'active_support/core_ext/object/blank'
-import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
-import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
-import java.io.StringReader unless defined? StringReader
-import org.xml.sax.InputSource unless defined? InputSource
-import org.xml.sax.Attributes unless defined? Attributes
-import org.w3c.dom.Node unless defined? Node
+java_import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
+java_import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
+java_import java.io.StringReader unless defined? StringReader
+java_import org.xml.sax.InputSource unless defined? InputSource
+java_import org.xml.sax.Attributes unless defined? Attributes
+java_import org.w3c.dom.Node unless defined? Node
# = XmlMini JRuby JDOM implementation
module ActiveSupport
@@ -41,7 +41,7 @@ module ActiveSupport
xml_string_reader = StringReader.new(data)
xml_input_source = InputSource.new(xml_string_reader)
doc = @dbf.new_document_builder.parse(xml_input_source)
- merge_element!({}, doc.document_element)
+ merge_element!({CONTENT_KEY => ''}, doc.document_element)
end
end
@@ -54,9 +54,14 @@ module ActiveSupport
# element::
# XML element to merge into hash
def merge_element!(hash, element)
+ delete_empty(hash)
merge!(hash, element.tag_name, collapse(element))
end
+ def delete_empty(hash)
+ hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ''
+ end
+
# Actually converts an XML document element into a data structure.
#
# element::
@@ -84,6 +89,7 @@ module ActiveSupport
# element::
# XML element whose texts are to me merged into the hash
def merge_texts!(hash, element)
+ delete_empty(hash)
text_children = texts(element)
if text_children.join.empty?
hash
@@ -128,6 +134,7 @@ module ActiveSupport
attribute_hash = {}
attributes = element.attributes
for i in 0...attributes.length
+ attribute_hash[CONTENT_KEY] ||= ''
attribute_hash[attributes.item(i).name] = attributes.item(i).value
end
attribute_hash
diff --git a/activesupport/test/benchmarkable_test.rb b/activesupport/test/benchmarkable_test.rb
index 766956f50f..06f5172e1f 100644
--- a/activesupport/test/benchmarkable_test.rb
+++ b/activesupport/test/benchmarkable_test.rb
@@ -26,17 +26,6 @@ class BenchmarkableTest < ActiveSupport::TestCase
assert_last_logged 'test_run'
end
- def test_with_message_and_deprecated_level
- i_was_run = false
-
- assert_deprecated do
- benchmark('debug_run', :debug) { i_was_run = true }
- end
-
- assert i_was_run
- assert_last_logged 'debug_run'
- end
-
def test_within_level
logger.level = ActiveSupport::BufferedLogger::DEBUG
benchmark('included_debug_run', :level => :debug) { }
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 476d55fffd..ed5ccb44de 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -531,26 +531,6 @@ class FileStoreTest < ActiveSupport::TestCase
include CacheDeleteMatchedBehavior
include CacheIncrementDecrementBehavior
- def test_deprecated_expires_in_on_read
- ActiveSupport::Deprecation.silence do
- old_cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir)
-
- time = Time.local(2008, 4, 24)
- Time.stubs(:now).returns(time)
-
- old_cache.write("foo", "bar")
- assert_equal 'bar', old_cache.read('foo', :expires_in => 60)
-
- Time.stubs(:now).returns(time + 30)
- assert_equal 'bar', old_cache.read('foo', :expires_in => 60)
-
- Time.stubs(:now).returns(time + 61)
- assert_equal 'bar', old_cache.read('foo')
- assert_nil old_cache.read('foo', :expires_in => 60)
- assert_nil old_cache.read('foo')
- end
- end
-
def test_key_transformation
key = @cache.send(:key_file_path, "views/index?id=1")
assert_equal "views/index?id=1", @cache.send(:file_path_key, key)
@@ -628,18 +608,6 @@ class MemoryStoreTest < ActiveSupport::TestCase
end
end
-class SynchronizedStoreTest < ActiveSupport::TestCase
- def setup
- ActiveSupport::Deprecation.silence do
- @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60)
- end
- end
-
- include CacheStoreBehavior
- include CacheDeleteMatchedBehavior
- include CacheIncrementDecrementBehavior
-end
-
uses_memcached 'memcached backed store' do
class MemCacheStoreTest < ActiveSupport::TestCase
def setup
@@ -672,18 +640,6 @@ uses_memcached 'memcached backed store' do
end
end
end
-
- class CompressedMemCacheStore < ActiveSupport::TestCase
- def setup
- ActiveSupport::Deprecation.silence do
- @cache = ActiveSupport::Cache.lookup_store(:compressed_mem_cache_store, :expires_in => 60)
- @cache.clear
- end
- end
-
- include CacheStoreBehavior
- include CacheIncrementDecrementBehavior
- end
end
class CacheStoreLoggerTest < ActiveSupport::TestCase
diff --git a/activesupport/test/class_cache_test.rb b/activesupport/test/class_cache_test.rb
index fc2d54515d..752c0ee478 100644
--- a/activesupport/test/class_cache_test.rb
+++ b/activesupport/test/class_cache_test.rb
@@ -51,20 +51,6 @@ module ActiveSupport
assert_equal @cache[ClassCacheTest], @cache.get(ClassCacheTest.name)
end
- def test_new
- assert_deprecated do
- @cache.new ClassCacheTest
- end
- assert @cache.key?(ClassCacheTest.name)
- end
-
- def test_new_rejects_strings_when_called_on_a_new_string
- assert_deprecated do
- @cache.new ClassCacheTest.name
- end
- assert !@cache.key?(ClassCacheTest.name)
- end
-
def test_new_rejects_strings
@cache.store ClassCacheTest.name
assert !@cache.key?(ClassCacheTest.name)
@@ -74,35 +60,6 @@ module ActiveSupport
x = @cache.store ClassCacheTest
assert_equal @cache, x
end
-
- def test_new_returns_proxy
- v = nil
- assert_deprecated do
- v = @cache.new ClassCacheTest.name
- end
-
- assert_deprecated do
- assert_equal ClassCacheTest, v.get
- end
- end
-
- def test_anonymous_class_fail
- assert_raises(ArgumentError) do
- assert_deprecated do
- @cache.new Class.new
- end
- end
-
- assert_raises(ArgumentError) do
- x = Class.new
- @cache[x] = x
- end
-
- assert_raises(ArgumentError) do
- x = Class.new
- @cache.store x
- end
- end
end
end
end
diff --git a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb b/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
deleted file mode 100644
index 020dfce56a..0000000000
--- a/activesupport/test/core_ext/class/class_inheritable_attributes_test.rb
+++ /dev/null
@@ -1,230 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/class/inheritable_attributes'
-
-class ClassInheritableAttributesTest < Test::Unit::TestCase
- def setup
- ActiveSupport::Deprecation.silenced = true
- @klass = Class.new
- end
-
- def teardown
- ActiveSupport::Deprecation.silenced = false
- end
-
- def test_reader_declaration
- assert_nothing_raised do
- @klass.class_inheritable_reader :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- end
- end
-
- def test_writer_declaration
- assert_nothing_raised do
- @klass.class_inheritable_writer :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_writer_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_writer :a, :instance_writer => false
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_accessor_declaration
- assert_nothing_raised do
- @klass.class_inheritable_accessor :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_accessor_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_accessor :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_array_declaration
- assert_nothing_raised do
- @klass.class_inheritable_array :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_array_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_array :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_hash_declaration
- assert_nothing_raised do
- @klass.class_inheritable_hash :a
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert_respond_to @klass.new, :a=
- end
- end
-
- def test_hash_declaration_without_instance_writer
- assert_nothing_raised do
- @klass.class_inheritable_hash :a, :instance_writer => false
- assert_respond_to @klass, :a
- assert_respond_to @klass.new, :a
- assert_respond_to @klass, :a=
- assert !@klass.new.respond_to?(:a=)
- end
- end
-
- def test_reader
- @klass.class_inheritable_reader :a
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.send(:write_inheritable_attribute, :a, 'a')
-
- assert_equal 'a', @klass.a
- assert_equal 'a', @klass.new.a
- assert_equal @klass.a, @klass.new.a
- assert_equal @klass.a.object_id, @klass.new.a.object_id
- end
-
- def test_writer
- @klass.class_inheritable_reader :a
- @klass.class_inheritable_writer :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = 'a'
- assert_equal 'a', @klass.a
- @klass.new.a = 'A'
- assert_equal 'A', @klass.a
- end
-
- def test_array
- @klass.class_inheritable_array :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = %w(a b c)
- assert_equal %w(a b c), @klass.a
- assert_equal %w(a b c), @klass.new.a
-
- @klass.new.a = %w(A B C)
- assert_equal %w(a b c A B C), @klass.a
- assert_equal %w(a b c A B C), @klass.new.a
- end
-
- def test_hash
- @klass.class_inheritable_hash :a
-
- assert_nil @klass.a
- assert_nil @klass.new.a
-
- @klass.a = { :a => 'a' }
- assert_equal({ :a => 'a' }, @klass.a)
- assert_equal({ :a => 'a' }, @klass.new.a)
-
- @klass.new.a = { :b => 'b' }
- assert_equal({ :a => 'a', :b => 'b' }, @klass.a)
- assert_equal({ :a => 'a', :b => 'b' }, @klass.new.a)
- end
-
- def test_inheritance
- @klass.class_inheritable_accessor :a
- @klass.a = 'a'
-
- @sub = eval("class FlogMe < @klass; end; FlogMe")
-
- @klass.class_inheritable_accessor :b
-
- assert_respond_to @sub, :a
- assert_respond_to @sub, :b
- assert_equal @klass.a, @sub.a
- assert_equal @klass.b, @sub.b
- assert_equal 'a', @sub.a
- assert_nil @sub.b
-
- @klass.b = 'b'
- assert_not_equal @klass.b, @sub.b
- assert_equal 'b', @klass.b
- assert_nil @sub.b
-
- @sub.a = 'A'
- assert_not_equal @klass.a, @sub.a
- assert_equal 'a', @klass.a
- assert_equal 'A', @sub.a
-
- @sub.b = 'B'
- assert_not_equal @klass.b, @sub.b
- assert_equal 'b', @klass.b
- assert_equal 'B', @sub.b
- end
-
- def test_array_inheritance
- @klass.class_inheritable_accessor :a
- @klass.a = []
-
- @sub = eval("class SubbyArray < @klass; end; SubbyArray")
-
- assert_equal [], @klass.a
- assert_equal [], @sub.a
-
- @sub.a << :first
-
- assert_equal [:first], @sub.a
- assert_equal [], @klass.a
- end
-
- def test_array_inheritance_
- @klass.class_inheritable_accessor :a
- @klass.a = {}
-
- @sub = eval("class SubbyHash < @klass; end; SubbyHash")
-
- assert_equal Hash.new, @klass.a
- assert_equal Hash.new, @sub.a
-
- @sub.a[:first] = :first
-
- assert_equal 1, @sub.a.keys.size
- assert_equal 0, @klass.a.keys.size
- end
-
- def test_reset_inheritable_attributes
- @klass.class_inheritable_accessor :a
- @klass.a = 'a'
-
- @sub = eval("class Inheriting < @klass; end; Inheriting")
-
- assert_equal 'a', @klass.a
- assert_equal 'a', @sub.a
-
- @klass.reset_inheritable_attributes
- @sub = eval("class NotInheriting < @klass; end; NotInheriting")
-
- assert_nil @klass.a
- assert_nil @sub.a
- end
-end
diff --git a/activesupport/test/core_ext/kernel_test.rb b/activesupport/test/core_ext/kernel_test.rb
index ede9b0a6aa..995bc0751a 100644
--- a/activesupport/test/core_ext/kernel_test.rb
+++ b/activesupport/test/core_ext/kernel_test.rb
@@ -52,10 +52,10 @@ class KernelTest < Test::Unit::TestCase
class << o; @x = 1; end
assert_equal 1, o.class_eval { @x }
end
-
+
def test_capture
- assert_equal 'STDERR', capture(:stderr) {$stderr.print 'STDERR'}
- assert_equal 'STDOUT', capture(:stdout) {print 'STDOUT'}
+ assert_equal 'STDERR', capture(:stderr) { $stderr.print 'STDERR' }
+ assert_equal 'STDOUT', capture(:stdout) { print 'STDOUT' }
end
end
@@ -73,3 +73,43 @@ class KernelSuppressTest < Test::Unit::TestCase
suppress(LoadError, ArgumentError) { raise ArgumentError }
end
end
+
+class MockStdErr
+ attr_reader :output
+ def puts(message)
+ @output ||= []
+ @output << message
+ end
+
+ def info(message)
+ puts(message)
+ end
+
+ def write(message)
+ puts(message)
+ end
+end
+
+class KernelDebuggerTest < Test::Unit::TestCase
+ def test_debugger_not_available_message_to_stderr
+ old_stderr = $stderr
+ $stderr = MockStdErr.new
+ debugger
+ assert_match(/Debugger requested/, $stderr.output.first)
+ ensure
+ $stderr = old_stderr
+ end
+
+ def test_debugger_not_available_message_to_rails_logger
+ rails = Class.new do
+ def self.logger
+ @logger ||= MockStdErr.new
+ end
+ end
+ Object.const_set("Rails", rails)
+ debugger
+ assert_match(/Debugger requested/, rails.logger.output.first)
+ ensure
+ Object.send(:remove_const, "Rails")
+ end
+end \ No newline at end of file
diff --git a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb b/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
deleted file mode 100644
index 0ecd16b051..0000000000
--- a/activesupport/test/core_ext/module/attr_accessor_with_default_test.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'abstract_unit'
-require 'active_support/core_ext/module/attr_accessor_with_default'
-
-class AttrAccessorWithDefaultTest < ActiveSupport::TestCase
- def setup
- @target = Class.new do
- def helper
- 'helper'
- end
- end
- @instance = @target.new
- end
-
- def test_default_arg
- assert_deprecated do
- @target.attr_accessor_with_default :foo, :bar
- end
- assert_equal(:bar, @instance.foo)
- @instance.foo = nil
- assert_nil(@instance.foo)
- end
-
- def test_default_proc
- assert_deprecated do
- @target.attr_accessor_with_default(:foo) {helper.upcase}
- end
- assert_equal('HELPER', @instance.foo)
- @instance.foo = nil
- assert_nil(@instance.foo)
- end
-
- def test_invalid_args
- assert_raise(ArgumentError) do
- assert_deprecated do
- @target.attr_accessor_with_default :foo
- end
- end
- end
-end
diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb
index ef017d7436..2ddbce5150 100644
--- a/activesupport/test/dependencies_test.rb
+++ b/activesupport/test/dependencies_test.rb
@@ -24,11 +24,13 @@ class DependenciesTest < Test::Unit::TestCase
old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load
this_dir = File.dirname(__FILE__)
parent_dir = File.dirname(this_dir)
+ path_copy = $LOAD_PATH.dup
$LOAD_PATH.unshift(parent_dir) unless $LOAD_PATH.include?(parent_dir)
prior_autoload_paths = ActiveSupport::Dependencies.autoload_paths
ActiveSupport::Dependencies.autoload_paths = from.collect { |f| "#{this_dir}/#{f}" }
yield
ensure
+ $LOAD_PATH.replace(path_copy)
ActiveSupport::Dependencies.autoload_paths = prior_autoload_paths
ActiveSupport::Dependencies.mechanism = old_mechanism
ActiveSupport::Dependencies.explicitly_unloadable_constants = []
diff --git a/activesupport/test/load_paths_test.rb b/activesupport/test/load_paths_test.rb
index 36e3726a02..a2d8da726a 100644
--- a/activesupport/test/load_paths_test.rb
+++ b/activesupport/test/load_paths_test.rb
@@ -10,6 +10,7 @@ class LoadPathsTest < Test::Unit::TestCase
}
load_paths_count[File.expand_path('../../lib', __FILE__)] -= 1
- assert load_paths_count.select { |k, v| v > 1 }.empty?, $LOAD_PATH.inspect
+ filtered = load_paths_count.select { |k, v| v > 1 }
+ assert filtered.empty?, filtered.inspect
end
end
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
index 419ac14283..e45d5ecd59 100644
--- a/activesupport/test/message_encryptor_test.rb
+++ b/activesupport/test/message_encryptor_test.rb
@@ -11,7 +11,7 @@ require 'active_support/time'
class MessageEncryptorTest < Test::Unit::TestCase
def setup
- @encryptor = ActiveSupport::MessageEncryptor.new(ActiveSupport::SecureRandom.hex(64))
+ @encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.hex(64))
@data = { :some => "data", :now => Time.local(2010) }
end
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index 7b48b3f85b..cc0dc564f7 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -215,7 +215,7 @@ module Notifications
protected
def random_id
- @random_id ||= ActiveSupport::SecureRandom.hex(10)
+ @random_id ||= SecureRandom.hex(10)
end
end
end
diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb
index f3dcd7b068..bf851dbcbc 100644
--- a/activesupport/test/ordered_hash_test.rb
+++ b/activesupport/test/ordered_hash_test.rb
@@ -114,6 +114,9 @@ class OrderedHashTest < Test::Unit::TestCase
end
assert_equal @values, values
assert_equal @keys, keys
+
+ expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
+ assert_kind_of expected_class, @ordered_hash.each_pair
end
def test_find_all
@@ -257,6 +260,26 @@ class OrderedHashTest < Test::Unit::TestCase
assert_equal @values, values
end
+ def test_each_when_yielding_to_block_with_splat
+ hash_values = []
+ ordered_hash_values = []
+
+ @hash.each { |*v| hash_values << v }
+ @ordered_hash.each { |*v| ordered_hash_values << v }
+
+ assert_equal hash_values.sort, ordered_hash_values.sort
+ end
+
+ def test_each_pair_when_yielding_to_block_with_splat
+ hash_values = []
+ ordered_hash_values = []
+
+ @hash.each_pair { |*v| hash_values << v }
+ @ordered_hash.each_pair { |*v| ordered_hash_values << v }
+
+ assert_equal hash_values.sort, ordered_hash_values.sort
+ end
+
def test_order_after_yaml_serialization
@deserialized_ordered_hash = YAML.load(YAML.dump(@ordered_hash))
diff --git a/activesupport/test/secure_random_test.rb b/activesupport/test/secure_random_test.rb
deleted file mode 100644
index 44694cd811..0000000000
--- a/activesupport/test/secure_random_test.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require 'abstract_unit'
-
-class SecureRandomTest < Test::Unit::TestCase
- def test_random_bytes
- b1 = ActiveSupport::SecureRandom.random_bytes(64)
- b2 = ActiveSupport::SecureRandom.random_bytes(64)
- assert_not_equal b1, b2
- end
-
- def test_hex
- b1 = ActiveSupport::SecureRandom.hex(64)
- b2 = ActiveSupport::SecureRandom.hex(64)
- assert_not_equal b1, b2
- end
-
- def test_random_number
- assert ActiveSupport::SecureRandom.random_number(5000) < 5000
- end
-end
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb
index b745228994..7f809e7898 100644
--- a/activesupport/test/xml_mini/jdom_engine_test.rb
+++ b/activesupport/test/xml_mini/jdom_engine_test.rb
@@ -1,38 +1,38 @@
-require 'abstract_unit'
-require 'active_support/xml_mini'
-
if RUBY_PLATFORM =~ /java/
+ require 'abstract_unit'
+ require 'active_support/xml_mini'
+ require 'active_support/core_ext/hash/conversions'
-class JDOMEngineTest < Test::Unit::TestCase
- include ActiveSupport
+ class JDOMEngineTest < Test::Unit::TestCase
+ include ActiveSupport
- def setup
- @default_backend = XmlMini.backend
- XmlMini.backend = 'JDOM'
- end
+ def setup
+ @default_backend = XmlMini.backend
+ XmlMini.backend = 'JDOM'
+ end
- def teardown
- XmlMini.backend = @default_backend
- end
+ def teardown
+ XmlMini.backend = @default_backend
+ end
+
+ def test_file_from_xml
+ hash = Hash.from_xml(<<-eoxml)
+ <blog>
+ <logo type="file" name="logo.png" content_type="image/png">
+ </logo>
+ </blog>
+ eoxml
+ assert hash.has_key?('blog')
+ assert hash['blog'].has_key?('logo')
+
+ file = hash['blog']['logo']
+ assert_equal 'logo.png', file.original_filename
+ assert_equal 'image/png', file.content_type
+ end
- # def test_file_from_xml
- # hash = Hash.from_xml(<<-eoxml)
- # <blog>
- # <logo type="file" name="logo.png" content_type="image/png">
- # </logo>
- # </blog>
- # eoxml
- # assert hash.has_key?('blog')
- # assert hash['blog'].has_key?('logo')
- #
- # file = hash['blog']['logo']
- # assert_equal 'logo.png', file.original_filename
- # assert_equal 'image/png', file.content_type
- # end
-
- def test_exception_thrown_on_expansion_attack
- assert_raise NativeException do
- attack_xml = <<-EOT
+ def test_exception_thrown_on_expansion_attack
+ assert_raise NativeException do
+ attack_xml = <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@@ -46,91 +46,91 @@ class JDOMEngineTest < Test::Unit::TestCase
<member>
&a;
</member>
- EOT
- Hash.from_xml(attack_xml)
+ EOT
+ Hash.from_xml(attack_xml)
+ end
end
- end
- def test_setting_JDOM_as_backend
- XmlMini.backend = 'JDOM'
- assert_equal XmlMini_JDOM, XmlMini.backend
- end
+ def test_setting_JDOM_as_backend
+ XmlMini.backend = 'JDOM'
+ assert_equal XmlMini_JDOM, XmlMini.backend
+ end
- def test_blank_returns_empty_hash
- assert_equal({}, XmlMini.parse(nil))
- assert_equal({}, XmlMini.parse(''))
- end
+ def test_blank_returns_empty_hash
+ assert_equal({}, XmlMini.parse(nil))
+ assert_equal({}, XmlMini.parse(''))
+ end
- def test_array_type_makes_an_array
- assert_equal_rexml(<<-eoxml)
+ def test_array_type_makes_an_array
+ assert_equal_rexml(<<-eoxml)
<blog>
<posts type="array">
<post>a post</post>
<post>another post</post>
</posts>
</blog>
- eoxml
- end
+ eoxml
+ end
- def test_one_node_document_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_one_node_document_as_hash
+ assert_equal_rexml(<<-eoxml)
<products/>
- eoxml
- end
+ eoxml
+ end
- def test_one_node_with_attributes_document_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_one_node_with_attributes_document_as_hash
+ assert_equal_rexml(<<-eoxml)
<products foo="bar"/>
- eoxml
- end
+ eoxml
+ end
- def test_products_node_with_book_node_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_book_node_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
</products>
- eoxml
- end
+ eoxml
+ end
- def test_products_node_with_two_book_nodes_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_two_book_nodes_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
- eoxml
- end
+ eoxml
+ end
- def test_single_node_with_content_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_single_node_with_content_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
hello world
</products>
- eoxml
- end
+ eoxml
+ end
- def test_children_with_children
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_children
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
- eoxml
- end
+ eoxml
+ end
- def test_children_with_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello everyone
</products>
</root>
- eoxml
- end
+ eoxml
+ end
- def test_children_with_non_adjacent_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_non_adjacent_text
+ assert_equal_rexml(<<-eoxml)
<root>
good
<products>
@@ -138,15 +138,15 @@ class JDOMEngineTest < Test::Unit::TestCase
</products>
morning
</root>
- eoxml
- end
+ eoxml
+ end
- private
- def assert_equal_rexml(xml)
- hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }
- assert_equal(hash, XmlMini.parse(xml))
+ private
+ def assert_equal_rexml(xml)
+ hash = XmlMini.with_backend('REXML') { XmlMini.parse(xml) }
+ assert_equal(hash, XmlMini.parse(xml))
+ end
end
-end
else
# don't run these test because we aren't running in JRuby
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index c465b08594..c77d03c39f 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,3 +1,10 @@
+*Rails 3.2.0 (unreleased)*
+
+* Removed old plugin generator (`rails generate plugin`) in favor of `rails plugin new` command. [Guillermo Iguaran]
+
+* Removed old 'config.paths.app.controller' API in favor of 'config.paths["app/controller"]' API. [Guillermo Iguaran]
+
+
*Rails 3.1.0 (unreleased)*
* Application and plugin generation run bundle install unless --skip-gemfile or --skip-bundle. [fxn]
diff --git a/railties/Rakefile b/railties/Rakefile
index 827b2ba0cd..be9a77d4e4 100755
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -1,6 +1,6 @@
#!/usr/bin/env rake
require 'rake/testtask'
-require 'rake/gempackagetask'
+require 'rubygems/package_task'
require 'date'
require 'rbconfig'
@@ -55,7 +55,7 @@ end
spec = eval(File.read('railties.gemspec'))
-Rake::GemPackageTask.new(spec) do |pkg|
+Gem::PackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index f75b245ed8..fbb684978a 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -61,7 +61,7 @@ h4. Upgrade Process
To help with the upgrade process, a plugin named "Rails Upgrade":http://github.com/jm/rails_upgrade has been created to automate part of it.
-Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following:
+Simply install the plugin, then run +rake rails:upgrade:check+ to check your app for pieces that need to be updated (with links to information on how to update them). It also offers a task to generate a +Gemfile+ based on your current +config.gem+ calls and a task to generate a new routes file from your current one. To get the plugin, simply run the following:
<shell>
$ ruby script/plugin install git://github.com/jm/rails_upgrade.git
@@ -69,7 +69,7 @@ $ ruby script/plugin install git://github.com/jm/rails_upgrade.git
You can see an example of how that works at "Rails Upgrade is now an Official Plugin":http://omgbloglol.com/post/364624593/rails-upgrade-is-now-an-official-plugin
-Aside from Rails Upgrade tool, if you need more help, there are people on IRC and "rubyonrails-talk":http://groups.google.com/group/rubyonrails-talk that are probably doing the same thing, possibly hitting the same issues. Be sure to blog your own experiences when upgrading so others can benefit from your knowledge!
+Aside from Rails Upgrade tool, if you need more help, there are people on IRC and "rubyonrails-talk":http://groups.google.com/group/rubyonrails-talk that are probably doing the same thing, possibly hitting the same issues. Be sure to blog your own experiences when upgrading so others can benefit from your knowledge!
More information - "The Path to Rails 3: Approaching the upgrade":http://omgbloglol.com/post/353978923/the-path-to-rails-3-approaching-the-upgrade
@@ -113,42 +113,42 @@ Railties was updated to provide a consistent plugin API for the entire Rails fra
h4. All Rails core components are decoupled
-With the merge of Merb and Rails, one of the big jobs was to remove the tight coupling between Rails core components. This has now been achieved, and all Rails core components are now using the same API that you can use for developing plugins. This means any plugin you make, or any core component replacement (like DataMapper or Sequel) can access all the functionality that the Rails core components have access to and extend and enhance at will.
+With the merge of Merb and Rails, one of the big jobs was to remove the tight coupling between Rails core components. This has now been achieved, and all Rails core components are now using the same API that you can use for developing plugins. This means any plugin you make, or any core component replacement (like DataMapper or Sequel) can access all the functionality that the Rails core components have access to and extend and enhance at will.
More information: - "The Great Decoupling":http://yehudakatz.com/2009/07/19/rails-3-the-great-decoupling/
h4. Active Model Abstraction
-Part of decoupling the core components was extracting all ties to Active Record from Action Pack. This has now been completed. All new ORM plugins now just need to implement Active Model interfaces to work seamlessly with Action Pack.
+Part of decoupling the core components was extracting all ties to Active Record from Action Pack. This has now been completed. All new ORM plugins now just need to implement Active Model interfaces to work seamlessly with Action Pack.
More information: - "Make Any Ruby Object Feel Like ActiveRecord":http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
h4. Controller Abstraction
-Another big part of decoupling the core components was creating a base superclass that is separated from the notions of HTTP in order to handle rendering of views etc. This creation of +AbstractController+ allowed +ActionController+ and +ActionMailer+ to be greatly simplified with common code removed from all these libraries and put into Abstract Controller.
+Another big part of decoupling the core components was creating a base superclass that is separated from the notions of HTTP in order to handle rendering of views etc. This creation of +AbstractController+ allowed +ActionController+ and +ActionMailer+ to be greatly simplified with common code removed from all these libraries and put into Abstract Controller.
More Information: - "Rails Edge Architecture":http://yehudakatz.com/2009/06/11/rails-edge-architecture/
h4. Arel Integration
-"Arel":http://github.com/brynary/arel (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails. Arel provides an SQL abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record.
+"Arel":http://github.com/brynary/arel (or Active Relation) has been taken on as the underpinnings of Active Record and is now required for Rails. Arel provides an SQL abstraction that simplifies out Active Record and provides the underpinnings for the relation functionality in Active Record.
More information: - "Why I wrote Arel":http://magicscalingsprinkles.wordpress.com/2010/01/28/why-i-wrote-arel/.
h4. Mail Extraction
-Action Mailer ever since its beginnings has had monkey patches, pre parsers and even delivery and receiver agents, all in addition to having TMail vendored in the source tree. Version 3 changes that with all email message related functionality abstracted out to the "Mail":http://github.com/mikel/mail gem. This again reduces code duplication and helps create definable boundaries between Action Mailer and the email parser.
+Action Mailer ever since its beginnings has had monkey patches, pre parsers and even delivery and receiver agents, all in addition to having TMail vendored in the source tree. Version 3 changes that with all email message related functionality abstracted out to the "Mail":http://github.com/mikel/mail gem. This again reduces code duplication and helps create definable boundaries between Action Mailer and the email parser.
More information: - "New Action Mailer API in Rails 3":http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3
h3. Documentation
-The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
+The documentation in the Rails tree is being updated with all the API changes, additionally, the "Rails Edge Guides":http://edgeguides.rubyonrails.org/ are being updated one by one to reflect the changes in Rails 3.0. The guides at "guides.rubyonrails.org":http://guides.rubyonrails.org/ however will continue to contain only the stable version of Rails (at this point, version 2.3.5, until 3.0 is released).
More Information: - "Rails Documentation Projects":http://weblog.rubyonrails.org/2009/1/15/rails-documentation-projects.
@@ -157,7 +157,7 @@ h3. Internationalization
A large amount of work has been done with I18n support in Rails 3, including the latest "I18n":http://github.com/svenfuchs/i18n gem supplying many speed improvements.
-* I18n for any object - I18n behavior can be added to any object by including <tt>ActiveModel::Translation</tt> and <tt>ActiveModel::Validations</tt>. There is also an <tt>errors.messages</tt> fallback for translations.
+* I18n for any object - I18n behavior can be added to any object by including <tt>ActiveModel::Translation</tt> and <tt>ActiveModel::Validations</tt>. There is also an <tt>errors.messages</tt> fallback for translations.
* Attributes can have default translations.
* Form Submit Tags automatically pull the correct status (Create or Update) depending on the object status, and so pull the correct translation.
* Labels with I18n also now work by just passing the attribute name.
@@ -173,7 +173,7 @@ With the decoupling of the main Rails frameworks, Railties got a huge overhaul s
* Anything under <tt>Rails.root/app</tt> is now added to the load path, so you can make <tt>app/observers/user_observer.rb</tt> and Rails will load it without any modifications.
* Rails 3.0 now provides a <tt>Rails.config</tt> object, which provides a central repository of all sorts of Rails wide configuration options.
-Application generation has received extra flags allowing you to skip the installation of test-unit, Active Record, Prototype and Git. Also a new <tt>--dev</tt> flag has been added which sets the application up with the +Gemfile+ pointing to your Rails checkout (which is determined by the path to the +rails+ binary). See <tt>rails --help</tt> for more info.
+Application generation has received extra flags allowing you to skip the installation of test-unit, Active Record, Prototype and Git. Also a new <tt>--dev</tt> flag has been added which sets the application up with the +Gemfile+ pointing to your Rails checkout (which is determined by the path to the +rails+ binary). See <tt>rails --help</tt> for more info.
Railties generators got a huge amount of attention in Rails 3.0, basically:
@@ -215,7 +215,7 @@ There have been significant internal and external changes in Action Pack.
h4. Abstract Controller
-Abstract Controller pulls out the generic parts of Action Controller into a reusable module that any library can use to render templates, render partials, helpers, translations, logging, any part of the request response cycle. This abstraction allowed <tt>ActionMailer::Base</tt> to now just inherit from +AbstractController+ and just wrap the Rails DSL onto the Mail gem.
+Abstract Controller pulls out the generic parts of Action Controller into a reusable module that any library can use to render templates, render partials, helpers, translations, logging, any part of the request response cycle. This abstraction allowed <tt>ActionMailer::Base</tt> to now just inherit from +AbstractController+ and just wrap the Rails DSL onto the Mail gem.
It also provided an opportunity to clean up Action Controller, abstracting out what could to simplify the code.
@@ -231,7 +231,7 @@ h4. Action Controller
* The <tt>session_store</tt> was configured in <tt>ActionController::Base.session</tt>, and that is now moved to <tt>Rails.application.config.session_store</tt>. Defaults are set up in <tt>config/initializers/session_store.rb</tt>.
* <tt>cookies.secure</tt> allowing you to set encrypted values in cookies with <tt>cookie.secure[:key] => value</tt>.
* <tt>cookies.permanent</tt> allowing you to set permanent values in the cookie hash <tt>cookie.permanent[:key] => value</tt> that raise exceptions on signed values if verification failures.
-* You can now pass <tt>:notice => 'This is a flash message'</tt> or <tt>:alert => 'Something went wrong'</tt> to the <tt>format</tt> call inside a +respond_to+ block. The <tt>flash[]</tt> hash still works as previously.
+* You can now pass <tt>:notice => 'This is a flash message'</tt> or <tt>:alert => 'Something went wrong'</tt> to the <tt>format</tt> call inside a +respond_to+ block. The <tt>flash[]</tt> hash still works as previously.
* <tt>respond_with</tt> method has now been added to your controllers simplifying the venerable +format+ blocks.
* <tt>ActionController::Responder</tt> added allowing you flexibility in how your responses get generated.
@@ -298,9 +298,9 @@ h4. Action View
h5. Unobtrusive JavaScript
-Major re-write was done in the Action View helpers, implementing Unobtrusive JavaScript (UJS) hooks and removing the old inline AJAX commands. This enables Rails to use any compliant UJS driver to implement the UJS hooks in the helpers.
+Major re-write was done in the Action View helpers, implementing Unobtrusive JavaScript (UJS) hooks and removing the old inline AJAX commands. This enables Rails to use any compliant UJS driver to implement the UJS hooks in the helpers.
-What this means is that all previous <tt>remote_&lt;method&gt;</tt> helpers have been removed from Rails core and put into the "Prototype Legacy Helper":http://github.com/rails/prototype_legacy_helper. To get UJS hooks into your HTML, you now pass <tt>:remote => true</tt> instead. For example:
+What this means is that all previous <tt>remote_&lt;method&gt;</tt> helpers have been removed from Rails core and put into the "Prototype Legacy Helper":http://github.com/rails/prototype_legacy_helper. To get UJS hooks into your HTML, you now pass <tt>:remote => true</tt> instead. For example:
<ruby>
form_for @post, :remote => true
@@ -341,12 +341,12 @@ h5. Other Changes
h3. Active Model
-Active Model is new in Rails 3.0. It provides an abstraction layer for any ORM libraries to use to interact with Rails by implementing an Active Model interface.
+Active Model is new in Rails 3.0. It provides an abstraction layer for any ORM libraries to use to interact with Rails by implementing an Active Model interface.
h4. ORM Abstraction and Action Pack Interface
-Part of decoupling the core components was extracting all ties to Active Record from Action Pack. This has now been completed. All new ORM plugins now just need to implement Active Model interfaces to work seamlessly with Action Pack.
+Part of decoupling the core components was extracting all ties to Active Record from Action Pack. This has now been completed. All new ORM plugins now just need to implement Active Model interfaces to work seamlessly with Action Pack.
More Information: - "Make Any Ruby Object Feel Like ActiveRecord":http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/
@@ -410,12 +410,12 @@ More Information:
h3. Active Record
-Active Record received a lot of attention in Rails 3.0, including abstraction into Active Model, a full update to the Query interface using Arel, validation updates and many enhancements and fixes. All of the Rails 2.x API will be usable through a compatibility layer that will be supported until version 3.1.
+Active Record received a lot of attention in Rails 3.0, including abstraction into Active Model, a full update to the Query interface using Arel, validation updates and many enhancements and fixes. All of the Rails 2.x API will be usable through a compatibility layer that will be supported until version 3.1.
h4. Query Interface
-Active Record, through the use of Arel, now returns relations on its core methods. The existing API in Rails 2.3.x is still supported and will not be deprecated until Rails 3.1 and not removed until Rails 3.2, however, the new API provides the following new methods that all return relations allowing them to be chained together:
+Active Record, through the use of Arel, now returns relations on its core methods. The existing API in Rails 2.3.x is still supported and will not be deprecated until Rails 3.1 and not removed until Rails 3.2, however, the new API provides the following new methods that all return relations allowing them to be chained together:
* <tt>where</tt> - provides conditions on the relation, what gets returned.
* <tt>select</tt> - choose what attributes of the models you wish to have returned from the database.
@@ -502,7 +502,7 @@ Deprecations:
h3. Active Support
-A large effort was made in Active Support to make it cherry pickable, that is, you no longer have to require the entire Active Support library to get pieces of it. This allows the various core components of Rails to run slimmer.
+A large effort was made in Active Support to make it cherry pickable, that is, you no longer have to require the entire Active Support library to get pieces of it. This allows the various core components of Rails to run slimmer.
These are the main changes in Active Support:
@@ -559,7 +559,7 @@ The following methods have been removed because they are no longer used in the f
h3. Action Mailer
-Action Mailer has been given a new API with TMail being replaced out with the new "Mail":http://github.com/mikel/mail as the Email library. Action Mailer itself has been given an almost complete re-write with pretty much every line of code touched. The result is that Action Mailer now simply inherits from Abstract Controller and wraps the Mail gem in a Rails DSL. This reduces the amount of code and duplication of other libraries in Action Mailer considerably.
+Action Mailer has been given a new API with TMail being replaced out with the new "Mail":http://github.com/mikel/mail as the Email library. Action Mailer itself has been given an almost complete re-write with pretty much every line of code touched. The result is that Action Mailer now simply inherits from Abstract Controller and wraps the Mail gem in a Rails DSL. This reduces the amount of code and duplication of other libraries in Action Mailer considerably.
* All mailers are now in <tt>app/mailers</tt> by default.
* Can now send email using new API with three methods: +attachments+, +headers+ and +mail+.
@@ -589,7 +589,7 @@ More Information:
h3. Credits
-See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails 3. Kudos to all of them.
+See the "full list of contributors to Rails":http://contributors.rubyonrails.org/ for the many people who spent many hours making Rails 3. Kudos to all of them.
Rails 3.0 Release Notes were compiled by "Mikel Lindsaar":http://lindsaar.net.
diff --git a/railties/guides/source/action_mailer_basics.textile b/railties/guides/source/action_mailer_basics.textile
index a6ff8f877d..e1ff49cd60 100644
--- a/railties/guides/source/action_mailer_basics.textile
+++ b/railties/guides/source/action_mailer_basics.textile
@@ -104,7 +104,7 @@ When you call the +mail+ method now, Action Mailer will detect the two templates
h5. Wire It Up So That the System Sends the Email When a User Signs Up
-There are several ways to do this, some people create Rails Observers to fire off emails, others do it inside of the User Model. However, in Rails 3, mailers are really just another way to render a view. Instead of rendering a view and sending out the HTTP protocol, they are just sending it out through the Email protocols instead. Due to this, it makes sense to just have your controller tell the mailer to send an email when a user is successfully created.
+There are several ways to do this, some people create Rails Observers to fire off emails, others do it inside of the User Model. However, in Rails 3, mailers are really just another way to render a view. Instead of rendering a view and sending out the HTTP protocol, they are just sending it out through the Email protocols instead. Due to this, it makes sense to just have your controller tell the mailer to send an email when a user is successfully created.
Setting this up is painfully simple.
@@ -293,7 +293,7 @@ class UserMailer < ActionMailer::Base
end
</ruby>
-Will render 'another_template.text.erb' and 'another_template.html.erb'. The render command is the same one used inside of Action Controller, so you can use all the same options, such as <tt>:text</tt> etc.
+Will render 'another_template.text.erb' and 'another_template.html.erb'. The render command is the same one used inside of Action Controller, so you can use all the same options, such as <tt>:text</tt> etc.
h4. Action Mailer Layouts
@@ -363,7 +363,7 @@ h4. Sending Multipart Emails
Action Mailer will automatically send multipart emails if you have different templates for the same action. So, for our UserMailer example, if you have +welcome_email.text.erb+ and +welcome_email.html.erb+ in +app/views/user_mailer+, Action Mailer will automatically send a multipart email with the HTML and text versions setup as different parts.
-The order of the parts getting inserted is determined by the <tt>:parts_order</tt> inside of the <tt>ActionMailer::Base.default</tt> method. If you want to explicitly alter the order, you can either change the <tt>:parts_order</tt> or explicitly render the parts in a different order:
+The order of the parts getting inserted is determined by the <tt>:parts_order</tt> inside of the <tt>ActionMailer::Base.default</tt> method. If you want to explicitly alter the order, you can either change the <tt>:parts_order</tt> or explicitly render the parts in a different order:
<ruby>
class UserMailer < ActionMailer::Base
@@ -419,7 +419,7 @@ class UserMailer < ActionMailer::Base
)
if email.has_attachments?
- for attachment in email.attachments
+ email.attachments.each do |attachment|
page.attachments.create({
:file => attachment,
:description => email.subject
diff --git a/railties/guides/source/action_view_overview.textile b/railties/guides/source/action_view_overview.textile
index 2b2c197f46..b064851312 100644
--- a/railties/guides/source/action_view_overview.textile
+++ b/railties/guides/source/action_view_overview.textile
@@ -615,7 +615,7 @@ atom_feed do |feed|
feed.title("Posts Index")
feed.updated((@posts.first.created_at))
- for post in @posts
+ @posts.each do |post|
feed.entry(post) do |entry|
entry.title(post.title)
entry.content(post.body, :type => 'html')
diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile
index 19bd4ad0f1..9f59397d7d 100644
--- a/railties/guides/source/active_record_validations_callbacks.textile
+++ b/railties/guides/source/active_record_validations_callbacks.textile
@@ -165,23 +165,23 @@ Each helper accepts an arbitrary number of attribute names, so with a single lin
All of them accept the +:on+ and +:message+ options, which define when the validation should be run and what message should be added to the +errors+ collection if it fails, respectively. The +:on+ option takes one of the values +:save+ (the default), +:create+ or +:update+. There is a default error message for each one of the validation helpers. These messages are used when the +:message+ option isn't specified. Let's take a look at each one of the available helpers.
-h4. +validates_acceptance_of+
+h4. +acceptance+
Validates that a checkbox on the user interface was checked when a form was submitted. This is typically used when the user needs to agree to your application's terms of service, confirm reading some text, or any similar concept. This validation is very specific to web applications and this 'acceptance' does not need to be recorded anywhere in your database (if you don't have a field for it, the helper will just create a virtual attribute).
<ruby>
class Person < ActiveRecord::Base
- validates_acceptance_of :terms_of_service
+ validates :terms_of_service, :acceptance => true
end
</ruby>
-The default error message for +validates_acceptance_of+ is "_must be accepted_".
+The default error message for this helper is "_must be accepted_".
-+validates_acceptance_of+ can receive an +:accept+ option, which determines the value that will be considered acceptance. It defaults to "1", but you can change this.
+It can receive an +:accept+ option, which determines the value that will be considered acceptance. It defaults to "1" and can be easily changed.
<ruby>
class Person < ActiveRecord::Base
- validates_acceptance_of :terms_of_service, :accept => 'yes'
+ validates :terms_of_service, :acceptance => true, :accept => 'yes'
end
</ruby>
@@ -202,13 +202,13 @@ CAUTION: Don't use +validates_associated+ on both ends of your associations. The
The default error message for +validates_associated+ is "_is invalid_". Note that each associated object will contain its own +errors+ collection; errors do not bubble up to the calling model.
-h4. +validates_confirmation_of+
+h4. +confirmation+
You should use this helper when you have two text fields that should receive exactly the same content. For example, you may want to confirm an email address or a password. This validation creates a virtual attribute whose name is the name of the field that has to be confirmed with "_confirmation" appended.
<ruby>
class Person < ActiveRecord::Base
- validates_confirmation_of :email
+ validates :email, :confirmation => true
end
</ruby>
@@ -219,70 +219,70 @@ In your view template you could use something like
<%= text_field :person, :email_confirmation %>
</erb>
-This check is performed only if +email_confirmation+ is not +nil+. To require confirmation, make sure to add a presence check for the confirmation attribute (we'll take a look at +validates_presence_of+ later on this guide):
+This check is performed only if +email_confirmation+ is not +nil+. To require confirmation, make sure to add a presence check for the confirmation attribute (we'll take a look at +presence+ later on this guide):
<ruby>
class Person < ActiveRecord::Base
- validates_confirmation_of :email
- validates_presence_of :email_confirmation
+ validates :email, :confirmation => true
+ validates :email_confirmation, :presence => true
end
</ruby>
-The default error message for +validates_confirmation_of+ is "_doesn't match confirmation_".
+The default error message for this helper is "_doesn't match confirmation_".
-h4. +validates_exclusion_of+
+h4. +exclusion+
This helper validates that the attributes' values are not included in a given set. In fact, this set can be any enumerable object.
<ruby>
class Account < ActiveRecord::Base
- validates_exclusion_of :subdomain, :in => %w(www us ca jp),
- :message => "Subdomain %{value} is reserved."
+ validates :subdomain, :exclusion => { :in => %w(www us ca jp),
+ :message => "Subdomain %{value} is reserved." }
end
</ruby>
-The +validates_exclusion_of+ helper has an option +:in+ that receives the set of values that will not be accepted for the validated attributes. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. This example uses the +:message+ option to show how you can include the attribute's value.
+The +exclusion+ helper has an option +:in+ that receives the set of values that will not be accepted for the validated attributes. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. This example uses the +:message+ option to show how you can include the attribute's value.
-The default error message for +validates_exclusion_of+ is "_is reserved_".
+The default error message is "_is reserved_".
-h4. +validates_format_of+
+h4. +format+
This helper validates the attributes' values by testing whether they match a given regular expression, which is specified using the +:with+ option.
<ruby>
class Product < ActiveRecord::Base
- validates_format_of :legacy_code, :with => /\A[a-zA-Z]+\z/,
- :message => "Only letters allowed"
+ validates :legacy_code, :format => { :with => /\A[a-zA-Z]+\z/,
+ :message => "Only letters allowed" }
end
</ruby>
-The default error message for +validates_format_of+ is "_is invalid_".
+The default error message is "_is invalid_".
-h4. +validates_inclusion_of+
+h4. +inclusion+
This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object.
<ruby>
class Coffee < ActiveRecord::Base
- validates_inclusion_of :size, :in => %w(small medium large),
- :message => "%{value} is not a valid size"
+ validates :size, :inclusion => { :in => %w(small medium large),
+ :message => "%{value} is not a valid size" }
end
</ruby>
-The +validates_inclusion_of+ helper has an option +:in+ that receives the set of values that will be accepted. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. The previous example uses the +:message+ option to show how you can include the attribute's value.
+The +inclusion+ helper has an option +:in+ that receives the set of values that will be accepted. The +:in+ option has an alias called +:within+ that you can use for the same purpose, if you'd like to. The previous example uses the +:message+ option to show how you can include the attribute's value.
-The default error message for +validates_inclusion_of+ is "_is not included in the list_".
+The default error message for this helper is "_is not included in the list_".
-h4. +validates_length_of+
+h4. +length+
This helper validates the length of the attributes' values. It provides a variety of options, so you can specify length constraints in different ways:
<ruby>
class Person < ActiveRecord::Base
- validates_length_of :name, :minimum => 2
- validates_length_of :bio, :maximum => 500
- validates_length_of :password, :in => 6..20
- validates_length_of :registration_number, :is => 6
+ validates :name, :length => { :minimum => 2 }
+ validates :bio, :length => { :maximum => 500 }
+ validates :password, :length => { :in => 6..20 }
+ validates :registration_number, :length => { :is => 6 }
end
</ruby>
@@ -297,8 +297,8 @@ The default error messages depend on the type of length validation being perform
<ruby>
class Person < ActiveRecord::Base
- validates_length_of :bio, :maximum => 1000,
- :too_long => "%{count} characters is the maximum allowed"
+ validates :bio, :length => { :maximum => 1000,
+ :too_long => "%{count} characters is the maximum allowed" }
end
</ruby>
@@ -306,20 +306,21 @@ This helper counts characters by default, but you can split the value in a diffe
<ruby>
class Essay < ActiveRecord::Base
- validates_length_of :content,
+ validates :content, :length => {
:minimum => 300,
:maximum => 400,
:tokenizer => lambda { |str| str.scan(/\w+/) },
:too_short => "must have at least %{count} words",
:too_long => "must have at most %{count} words"
+ }
end
</ruby>
-Note that the default error messages are plural (e.g., "is too short (minimum is %{count} characters)"). For this reason, when +:minimum+ is 1 you should provide a personalized message or use +validates_presence_of+ instead. When +:in+ or +:within+ have a lower limit of 1, you should either provide a personalized message or call +validates_presence_of+ prior to +validates_length_of+.
+Note that the default error messages are plural (e.g., "is too short (minimum is %{count} characters)"). For this reason, when +:minimum+ is 1 you should provide a personalized message or use +validates_presence_of+ instead. When +:in+ or +:within+ have a lower limit of 1, you should either provide a personalized message or call +presence+ prior to +length+.
-The +validates_size_of+ helper is an alias for +validates_length_of+.
+The +size+ helper is an alias for +length+.
-h4. +validates_numericality_of+
+h4. +numericality+
This helper validates that your attributes have only numeric values. By default, it will match an optional sign followed by an integral or floating point number. To specify that only integral numbers are allowed set +:only_integer+ to true.
@@ -335,12 +336,12 @@ WARNING. Note that the regular expression above allows a trailing newline charac
<ruby>
class Player < ActiveRecord::Base
- validates_numericality_of :points
- validates_numericality_of :games_played, :only_integer => true
+ validates :points, :numericality => true
+ validates :games_played, :numericality => true, :only_integer => true
end
</ruby>
-Besides +:only_integer+, the +validates_numericality_of+ helper also accepts the following options to add constraints to acceptable values:
+Besides +:only_integer+, this helper also accepts the following options to add constraints to acceptable values:
* +:greater_than+ - Specifies the value must be greater than the supplied value. The default error message for this option is "_must be greater than %{count}_".
* +:greater_than_or_equal_to+ - Specifies the value must be greater than or equal to the supplied value. The default error message for this option is "_must be greater than or equal to %{count}_".
@@ -350,9 +351,9 @@ Besides +:only_integer+, the +validates_numericality_of+ helper also accepts the
* +:odd+ - Specifies the value must be an odd number if set to true. The default error message for this option is "_must be odd_".
* +:even+ - Specifies the value must be an even number if set to true. The default error message for this option is "_must be even_".
-The default error message for +validates_numericality_of+ is "_is not a number_".
+The default error message is "_is not a number_".
-h4. +validates_presence_of+
+h4. +presence+
This helper validates that the specified attributes are not empty. It uses the +blank?+ method to check if the value is either +nil+ or a blank string, that is, a string that is either empty or consists of whitespace.
@@ -367,21 +368,21 @@ If you want to be sure that an association is present, you'll need to test wheth
<ruby>
class LineItem < ActiveRecord::Base
belongs_to :order
- validates_presence_of :order_id
+ validates :order_id, :presence => true
end
</ruby>
-Since +false.blank?+ is true, if you want to validate the presence of a boolean field you should use +validates_inclusion_of :field_name, :in => [true, false]+.
+Since +false.blank?+ is true, if you want to validate the presence of a boolean field you should use <tt>validates :field_name, :inclusion => { :in => [true, false] }</tt>.
-The default error message for +validates_presence_of+ is "_can't be empty_".
+The default error message is "_can't be empty_".
-h4. +validates_uniqueness_of+
+h4. +uniqueness+
This helper validates that the attribute's value is unique right before the object gets saved. It does not create a uniqueness constraint in the database, so it may happen that two different database connections create two records with the same value for a column that you intend to be unique. To avoid that, you must create a unique index in your database.
<ruby>
class Account < ActiveRecord::Base
- validates_uniqueness_of :email
+ validates :email, :uniqueness => true
end
</ruby>
@@ -391,7 +392,7 @@ There is a +:scope+ option that you can use to specify other attributes that are
<ruby>
class Holiday < ActiveRecord::Base
- validates_uniqueness_of :name, :scope => :year,
+ validates :name, :uniqueness => true, :scope => :year,
:message => "should happen once per year"
end
</ruby>
@@ -400,13 +401,13 @@ There is also a +:case_sensitive+ option that you can use to define whether the
<ruby>
class Person < ActiveRecord::Base
- validates_uniqueness_of :name, :case_sensitive => false
+ validates :name, :uniqueness => true, :case_sensitive => false
end
</ruby>
WARNING. Note that some databases are configured to perform case-insensitive searches anyway.
-The default error message for +validates_uniqueness_of+ is "_has already been taken_".
+The default error message is "_has already been taken_".
h4. +validates_with+
@@ -470,8 +471,8 @@ The +:allow_nil+ option skips the validation when the value being validated is +
<ruby>
class Coffee < ActiveRecord::Base
- validates_inclusion_of :size, :in => %w(small medium large),
- :message => "%{value} is not a valid size", :allow_nil => true
+ validates :size, :inclusion => { :in => %w(small medium large),
+ :message => "%{value} is not a valid size" }, :allow_nil => true
end
</ruby>
@@ -483,10 +484,10 @@ The +:allow_blank+ option is similar to the +:allow_nil+ option. This option wil
<ruby>
class Topic < ActiveRecord::Base
- validates_length_of :title, :is => 5, :allow_blank => true
+ validates :title, :length => { :is => 5 }, :allow_blank => true
end
-Topic.create("title" => "").valid? # => true
+Topic.create("title" => "").valid? # => true
Topic.create("title" => nil).valid? # => true
</ruby>
@@ -503,10 +504,10 @@ The +:on+ option lets you specify when the validation should happen. The default
<ruby>
class Person < ActiveRecord::Base
# it will be possible to update email with a duplicated value
- validates_uniqueness_of :email, :on => :create
+ validates :email, :uniqueness => true, :on => :create
# it will be possible to create the record with a non-numerical age
- validates_numericality_of :age, :on => :update
+ validates :age, :numericality => true, :on => :update
# the default (validates on both create and update)
validates :name, :presence => true, :on => :save
@@ -523,7 +524,7 @@ You can associate the +:if+ and +:unless+ options with a symbol corresponding to
<ruby>
class Order < ActiveRecord::Base
- validates_presence_of :card_number, :if => :paid_with_card?
+ validates :card_number, :presence => true, :if => :paid_with_card?
def paid_with_card?
payment_type == "card"
@@ -537,7 +538,7 @@ You can also use a string that will be evaluated using +eval+ and needs to conta
<ruby>
class Person < ActiveRecord::Base
- validates_presence_of :surname, :if => "name.nil?"
+ validates :surname, :presence => true, :if => "name.nil?"
end
</ruby>
@@ -547,7 +548,7 @@ Finally, it's possible to associate +:if+ and +:unless+ with a +Proc+ object whi
<ruby>
class Account < ActiveRecord::Base
- validates_confirmation_of :password,
+ validates :password, :confirmation => true,
:unless => Proc.new { |a| a.password.blank? }
end
</ruby>
@@ -559,8 +560,8 @@ Sometimes it is useful to have multiple validations use one condition, it can be
<ruby>
class User < ActiveRecord::Base
with_options :if => :is_admin? do |admin|
- admin.validates_length_of :password, :minimum => 10
- admin.validates_presence_of :email
+ admin.validates :password, :length => { :minimum => 10 }
+ admin.validates :email, :presence => true
end
end
</ruby>
@@ -597,7 +598,7 @@ You can even create your own validation helpers and reuse them in several differ
<ruby>
ActiveRecord::Base.class_eval do
def self.validates_as_choice(attr_name, n, options={})
- validates_inclusion_of attr_name, {:in => 1..n}.merge(options)
+ validates attr_name, :inclusion => { {:in => 1..n}.merge(options) }
end
end
</ruby>
@@ -622,8 +623,7 @@ Returns an OrderedHash with all errors. Each key is the attribute name and the v
<ruby>
class Person < ActiveRecord::Base
- validates :name, :presence => true
- validates_length_of :name, :minimum => 3
+ validates :name, :presence => true, :length => { :minimum => 3 }
end
person = Person.new
@@ -642,8 +642,7 @@ h4(#working_with_validation_errors-errors-2). +errors[]+
<ruby>
class Person < ActiveRecord::Base
- validates :name, :presence => true
- validates_length_of :name, :minimum => 3
+ validates :name, :presence => true, :length => { :minimum => 3 }
end
person = Person.new(:name => "John Doe")
@@ -718,8 +717,7 @@ The +clear+ method is used when you intentionally want to clear all the messages
<ruby>
class Person < ActiveRecord::Base
- validates :name, :presence => true
- validates_length_of :name, :minimum => 3
+ validates :name, :presence => true, :length => { :minimum => 3 }
end
person = Person.new
@@ -742,9 +740,7 @@ The +size+ method returns the total number of error messages for the object.
<ruby>
class Person < ActiveRecord::Base
- validates :name, :presence => true
- validates_length_of :name, :minimum => 3
- validates_presence_of :email
+ validates :name, :presence => true, :length => { :minimum => 3 }
end
person = Person.new
@@ -765,13 +761,14 @@ h4. Installing as a plugin
$ rails plugin install git://github.com/joelmoss/dynamic_form.git
</shell>
-h4 Installing as a Gem
-Add this line on your Gemfile:
+h4. Installing as a Gem
+
+Add this line in your Gemfile:
<ruby>
gem "dynamic_form"
</ruby>
-Now you will have access to these two methods in your view templates:
+Now you will have access to these two methods in your view templates.
h4. +error_messages+ and +error_messages_for+
@@ -779,8 +776,8 @@ When creating a form with the +form_for+ helper, you can use the +error_messages
<ruby>
class Product < ActiveRecord::Base
- validates_presence_of :description, :value
- validates_numericality_of :value, :allow_nil => true
+ validates :description, :value, :presence => true
+ validates :value, :numericality => true, :allow_nil => true
end
</ruby>
@@ -878,7 +875,7 @@ In order to use the available callbacks, you need to register them. You can do t
<ruby>
class User < ActiveRecord::Base
- validates_presence_of :login, :email
+ validates :login, :email, :presence => true
before_validation :ensure_login_has_a_value
@@ -895,7 +892,7 @@ The macro-style class methods can also receive a block. Consider using this styl
<ruby>
class User < ActiveRecord::Base
- validates_presence_of :login, :email
+ validates :login, :email, :presence => true
before_create do |user|
user.name = user.login.capitalize if user.name.blank?
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 66869b4eeb..43aa6dfbbb 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -436,20 +436,6 @@ end
NOTE: Defined in +active_support/core_ext/kernel/reporting.rb+.
-h4. +require_library_or_gem+
-
-The convenience method +require_library_or_gem+ tries to load its argument with a regular +require+ first. If it fails loads +rubygems+ and tries again.
-
-If the first attempt is a failure and +rubygems+ can't be loaded the method raises +LoadError+. A +LoadError+ is also raised if +rubygems+ is available but the argument is not loadable as a gem.
-
-For example, that's the way the MySQL adapter loads the MySQL library:
-
-<ruby>
-require_library_or_gem('mysql')
-</ruby>
-
-NOTE: Defined in +active_support/core_ext/kernel/requires.rb+.
-
h4. +in?+
The predicate +in?+ tests if an object is included in another object. An +ArgumentError+ exception will be raised if the argument passed does not respond to +include?+.
diff --git a/railties/guides/source/asset_pipeline.textile b/railties/guides/source/asset_pipeline.textile
new file mode 100644
index 0000000000..9ea1aa9e01
--- /dev/null
+++ b/railties/guides/source/asset_pipeline.textile
@@ -0,0 +1,29 @@
+h2. Asset Pipeline
+
+This guide will cover the ideology of the asset pipeline introduced in Rails 3.1.
+By referring to this guide you will be able to:
+
+* Properly organize your application assets
+* Understand the benefits of the asset pipline
+* Adding a preproccessor to the pipeline
+* Package assets with your plugin
+
+endprologue.
+
+h3. What Is The Asset Pipeline?
+
+h4. Why Should I Use it?
+
+h3. How to Use the Asset Pipeline
+
+h4. Asset Organization
+
+h4. Default Files Loaded
+
+h4. Directives
+
+h4. Stacking Preproccessors
+
+h3. Packaging Assets with Your Plugin
+
+h3. More on Sprockets
diff --git a/railties/guides/source/configuring.textile b/railties/guides/source/configuring.textile
index fbe3d46367..135c849ec3 100644
--- a/railties/guides/source/configuring.textile
+++ b/railties/guides/source/configuring.textile
@@ -414,7 +414,7 @@ Rails has 5 initialization events which can be hooked into (listed in order that
* +to_prepare+: Run after the initializers are ran for all Railties (including the application itself), but before eager loading and the middleware stack is built.
-* +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ enviroment.
+* +before_eager_load+: This is run directly before eager loading occurs, which is the default behaviour for the _production_ environment and not for the +development+ environment.
* +after_initialize+: Run directly after the initialization of the application, but before the application initializers are run.
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index a63245acec..4134c9f8ed 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -712,7 +712,7 @@ You might want to render a form with a set of edit fields for each of a person's
<erb>
<%= form_for @person do |person_form| %>
<%= person_form.text_field :name %>
- <% for address in @person.addresses %>
+ <% @person.addresses.each do |address| %>
<%= person_form.fields_for address, :index => address do |address_form|%>
<%= address_form.text_field :city %>
<% end %>
diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile
index 1c66115d44..8a9086f416 100644
--- a/railties/guides/source/getting_started.textile
+++ b/railties/guides/source/getting_started.textile
@@ -544,7 +544,7 @@ This view iterates over the contents of the +@posts+ array to display content an
* +link_to+ builds a hyperlink to a particular destination
* +edit_post_path+ and +new_post_path+ are helpers that Rails provides as part of RESTful routing. You'll see a variety of these helpers for the different actions that the controller includes.
-NOTE. In previous versions of Rails, you had to use +&lt;%=h post.name %&gt;+ so that any HTML would be escaped before being inserted into the page. In Rails 3.0, this is now the default. To get unescaped HTML, you now use +&lt;%= raw post.name %&gt;+.
+NOTE. In previous versions of Rails, you had to use +&lt;%=h post.name %&gt;+ so that any HTML would be escaped before being inserted into the page. In Rails 3.0, this is now the default. To get unescaped HTML, you now use +&lt;%= raw post.name %&gt;+.
TIP: For more details on the rendering process, see "Layouts and Rendering in Rails":layouts_and_rendering.html.
diff --git a/railties/guides/source/plugins.textile b/railties/guides/source/plugins.textile
index d486e8ade3..2eb71e49c4 100644
--- a/railties/guides/source/plugins.textile
+++ b/railties/guides/source/plugins.textile
@@ -25,33 +25,36 @@ endprologue.
h3. Setup
-h4. Generating the Plugin Skeleton
+Before you continue, take a moment to decide if your new plugin will be potentially shared across different Rails applications.
-Rails currently ships with a generator to generate a plugin within a Rails application. Help text is available that will explain
-how this generator works.
+* If your plugin is specific to your application, your new plugin will be a _vendored plugin_.
+* If you think your plugin may be used across applications, build it as a _gemified plugin_.
+
+h4. Either generate a vendored plugin...
+
+Use the +rails generate plugin+ command in your Rails root directory
+ to create a new plugin that will live in the +vendor/plugins+
+ directory. See usage and options by asking for help:
<shell>
-$ rails generate plugin --help
+$ rails generate plugin new --help
</shell>
-This generator places the plugin into the vendor/plugins directory.
+h4. Or generate a gemified plugin.
-Vendored plugins are useful for quickly prototyping your plugin but current thinking in the Rails community is shifting towards
-packaging plugins as gems, especially with the inclusion of Bundler as the Rails dependency manager.
-Packaging a plugin as a gem may be overkill for any plugins that will not be shared across projects but doing so from the start makes it easier to share the plugin going forward without adding too much additional overhead during development.
+Writing your Rails plugin as a gem, rather than as a vendored plugin,
+ lets you share your plugin across different rails applications using
+ RubyGems and Bundler.
-Rails 3.1 will ship with a plugin generator that will default to setting up a plugin
-as a gem. This tutorial will begin to bridge that gap by demonstrating how to create a gem based plugin using the
-"Enginex gem":http://www.github.com/josevalim/enginex.
+Rails 3.1 ships with a +rails plugin new+ command which creates a
+ skeleton for developing any kind of Rails extension with the ability
+ to run integration tests using a dummy Rails application. See usage
+ and options by asking for help:
<shell>
-$ gem install enginex
-$ enginex --help
-$ enginex yaffle
+$ rails plugin --help
</shell>
-This command will create a new directory named "yaffle" within the current directory.
-
h3. Testing your newly generated plugin
You can navigate to the directory that contains the plugin, run the +bundle install+ command
@@ -319,7 +322,7 @@ When you run +rake+ you should see the tests all pass:
h4. Add an Instance Method
-This plugin will add a method named 'squawk' to any Active Record objects that call 'acts_as_yaffle'. The 'squawk'
+This plugin will add a method named 'squawk' to any Active Record objects that call 'acts_as_yaffle'. The 'squawk'
method will simply set the value of one of the fields in the database.
To start out, write a failing test that shows the behavior you'd like:
@@ -387,9 +390,7 @@ Run +rake+ one final time and you should see:
7 tests, 7 assertions, 0 failures, 0 errors, 0 skips
</shell>
-NOTE: The use of +write_attribute+ to write to the field in model is just one example of how a plugin can
-interact with the model, and will not always be the right method to use. For example, you could also
-use +send("#{self.class.yaffle_text_field}=", string.to_squawk)+.
+NOTE: The use of +write_attribute+ to write to the field in model is just one example of how a plugin can interact with the model, and will not always be the right method to use. For example, you could also use <tt>send("#{self.class.yaffle_text_field}=", string.to_squawk)</tt>.
h3. Generators
diff --git a/railties/guides/source/routing.textile b/railties/guides/source/routing.textile
index 99fdcee68a..08615bed4e 100644
--- a/railties/guides/source/routing.textile
+++ b/railties/guides/source/routing.textile
@@ -880,7 +880,7 @@ h3. Changelog
* April 10, 2010: Updated guide to remove outdated and superfluous information, and to provide information about new features, by "Yehuda Katz":http://www.yehudakatz.com
* April 2, 2010: Updated guide to match new Routing DSL in Rails 3, by "Rizwan Reza":http://www.rizwanreza.com/
-* Febuary 1, 2010: Modifies the routing documentation to match new routing DSL in Rails 3, by Prem Sichanugrist
+* February 1, 2010: Modifies the routing documentation to match new routing DSL in Rails 3, by Prem Sichanugrist
* October 4, 2008: Added additional detail on specifying verbs for resource member/collection routes, by "Mike Gunderloy":credits.html#mgunderloy
* September 23, 2008: Added section on namespaced controllers and routing, by "Mike Gunderloy":credits.html#mgunderloy
* September 10, 2008: initial version by "Mike Gunderloy":credits.html#mgunderloy
diff --git a/railties/guides/source/ruby_on_rails_guides_guidelines.textile b/railties/guides/source/ruby_on_rails_guides_guidelines.textile
index 26a5a4c3c9..9ae360a73b 100644
--- a/railties/guides/source/ruby_on_rails_guides_guidelines.textile
+++ b/railties/guides/source/ruby_on_rails_guides_guidelines.textile
@@ -62,10 +62,10 @@ To force process of all the guides, pass +ALL=1+.
It is also recommended that you work with +WARNINGS=1+. This detects duplicate IDs and warns about broken internal links.
-If you want to generate guides in languages other than English, you can keep them in a separate directory under +source+ (eg. <tt>source/es</tt>) and use the +LANGUAGE+ environment variable:
+If you want to generate guides in languages other than English, you can keep them in a separate directory under +source+ (eg. <tt>source/es</tt>) and use the +GUIDES_LANGUAGE+ environment variable:
<plain>
-rake generate_guides LANGUAGE=es
+rake generate_guides GUIDES_LANGUAGE=es
</plain>
h3. HTML Validation
diff --git a/railties/guides/source/security.textile b/railties/guides/source/security.textile
index e0ccc7a6e6..412ded1d0b 100644
--- a/railties/guides/source/security.textile
+++ b/railties/guides/source/security.textile
@@ -386,7 +386,7 @@ params[:user] # => {:name => “ow3ned”, :admin => true}
So if you create a new user using mass-assignment, it may be too easy to become an administrator.
-Note that this vulnerability is not restricted to database columns. Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method. In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3+. The +accepts_nested_attributes_for+ declaration provides us the ability to extend mass assignment to model associations (+has_many+, +has_one+, +has_and_belongs_to_many+). For example:
+Note that this vulnerability is not restricted to database columns. Any setter method, unless explicitly protected, is accessible via the <tt>attributes=</tt> method. In fact, this vulnerability is extended even further with the introduction of nested mass assignment (and nested object forms) in Rails 2.3+. The +accepts_nested_attributes_for+ declaration provides us the ability to extend mass assignment to model associations (+has_many+, +has_one+, +has_and_belongs_to_many+). For example:
<ruby>
class Person < ActiveRecord::Base
@@ -469,7 +469,7 @@ A more paranoid technique to protect your whole project would be to enforce that
config.active_record.whitelist_attributes = true
</ruby>
-This will create an empty whitelist of attributes available for mass-assignment for all models in your app. As such, your models will need to explicitly whitelist or blacklist accessible parameters by using an +attr_accessible+ or +attr_protected+ declaration. This technique is best applied at the start of a new project. However, for an existing project with a thorough set of functional tests, it should be straightforward and relatively quick to use this application config option; run your tests, and expose each attribute (via +attr_accessible+ or +attr_protected+) as dictated by your failing tests.
+This will create an empty whitelist of attributes available for mass-assignment for all models in your app. As such, your models will need to explicitly whitelist or blacklist accessible parameters by using an +attr_accessible+ or +attr_protected+ declaration. This technique is best applied at the start of a new project. However, for an existing project with a thorough set of functional tests, it should be straightforward and relatively quick to use this application config option; run your tests, and expose each attribute (via +attr_accessible+ or +attr_protected+) as dictated by your failing tests.
h3. User Management
@@ -540,7 +540,7 @@ Most bots are really dumb, they crawl the web and put their spam into every form
Here are some ideas how to hide honeypot fields by JavaScript and/or CSS:
* position the fields off of the visible area of the page
-* make the elements very small or colour them the same as the background of the page
+* make the elements very small or color them the same as the background of the page
* leave the fields displayed, but tell humans to leave them blank
The most simple negative CAPTCHA is one hidden honeypot field. On the server side, you will check the value of the field: If it contains any text, it must be a bot. Then, you can either ignore the post or return a positive result, but not saving the post to the database. This way the bot will be satisfied and moves on. You can do this with annoying users, too.
@@ -567,7 +567,7 @@ h4. Good Passwords
-- _Do you find it hard to remember all your passwords? Don't write them down, but use the initial letters of each word in an easy to remember sentence._
-Bruce Schneier, a security technologist, "has analysed":http://www.schneier.com/blog/archives/2006/12/realworld_passw.html 34,000 real-world user names and passwords from the MySpace phishing attack mentioned <a href="#examples-from-the-underground">below</a>. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are:
+Bruce Schneier, a security technologist, "has analyzed":http://www.schneier.com/blog/archives/2006/12/realworld_passw.html 34,000 real-world user names and passwords from the MySpace phishing attack mentioned <a href="#examples-from-the-underground">below</a>. It turns out that most of the passwords are quite easy to crack. The 20 most common passwords are:
password1, abc123, myspace1, password, blink182, qwerty1, ****you, 123abc, baseball1, football1, 123456, soccer, monkey1, liverpool1, princess1, jordan23, slipknot1, superman1, iloveyou1, and monkey.
@@ -885,7 +885,7 @@ The "moz-binding":http://www.securiteam.com/securitynews/5LP051FHPE.html CSS pro
h5(#css-injection-countermeasures). Countermeasures
-This example, again, showed that a blacklist filter is never complete. However, as custom CSS in web applications is a quite rare feature, I am not aware of a whitelist CSS filter. _(highlight)If you want to allow custom colours or images, you can allow the user to choose them and build the CSS in the web application_. Use Rails' +sanitize()+ method as a model for a whitelist CSS filter, if you really need one.
+This example, again, showed that a blacklist filter is never complete. However, as custom CSS in web applications is a quite rare feature, I am not aware of a whitelist CSS filter. _(highlight)If you want to allow custom colors or images, you can allow the user to choose them and build the CSS in the web application_. Use Rails' +sanitize()+ method as a model for a whitelist CSS filter, if you really need one.
h4. Textile Injection
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index a7405aae16..953233d774 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -50,7 +50,9 @@ module Rails
end
end
- attr_accessor :assets
+ attr_accessor :assets, :sandbox
+ alias_method :sandbox?, :sandbox
+
delegate :default_url_options, :default_url_options=, :to => :routes
# This method is called just after an application inherits from Rails::Application,
@@ -96,24 +98,25 @@ module Rails
self
end
- def load_tasks
+ def load_tasks(app=self)
initialize_tasks
- railties.all { |r| r.load_tasks }
+ railties.all { |r| r.load_tasks(app) }
super
self
end
- def load_generators
+ def load_generators(app=self)
initialize_generators
- railties.all { |r| r.load_generators }
+ railties.all { |r| r.load_generators(app) }
+ Rails::Generators.configure!(app.config.generators)
super
self
end
- def load_console(sandbox=false)
- initialize_console(sandbox)
- railties.all { |r| r.load_console(sandbox) }
- super()
+ def load_console(app=self)
+ initialize_console
+ railties.all { |r| r.load_console(app) }
+ super
self
end
@@ -141,8 +144,6 @@ module Rails
def default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use ::Rails::Rack::ContentLength, config.action_dispatch.x_sendfile_header
-
if rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache
require "action_dispatch/http/rack_cache"
middleware.use ::Rack::Cache, rack_cache
@@ -198,7 +199,7 @@ module Rails
require "rails/generators"
end
- def initialize_console(sandbox=false)
+ def initialize_console
require "pp"
require "rails/console/app"
require "rails/console/helpers"
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb
index 40416dd83a..770c23ae41 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -104,4 +104,4 @@ class CodeStatistics #:nodoc:
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)}"
puts ""
end
- end
+end
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 4a082aedb8..39627a3094 100644
--- a/railties/lib/rails/commands.rb
+++ b/railties/lib/rails/commands.rb
@@ -15,6 +15,8 @@ command = aliases[command] || command
case command
when 'generate', 'destroy', 'plugin'
+ require 'rails/generators'
+
if command == 'plugin' && ARGV.first == 'new'
require "rails/commands/plugin_new"
else
@@ -22,7 +24,9 @@ when 'generate', 'destroy', 'plugin'
Rails.application.require_environment!
if defined?(ENGINE_PATH) && engine = Rails::Engine.find(ENGINE_PATH)
- Rails.application = engine
+ Rails.application.load_generators(engine)
+ else
+ Rails.application.load_generators
end
require "rails/commands/#{command}"
diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb
index f3fa1fd54d..1cf23a8b92 100644
--- a/railties/lib/rails/commands/application.rb
+++ b/railties/lib/rails/commands/application.rb
@@ -12,7 +12,6 @@ else
end
require 'rubygems' if ARGV.include?("--dev")
-
require 'rails/generators'
require 'rails/generators/rails/app/app_generator'
diff --git a/railties/lib/rails/commands/console.rb b/railties/lib/rails/commands/console.rb
index 66dbb5d11e..32e361d421 100644
--- a/railties/lib/rails/commands/console.rb
+++ b/railties/lib/rails/commands/console.rb
@@ -23,7 +23,8 @@ module Rails
opt.parse!(ARGV)
end
- @app.load_console(options[:sandbox])
+ @app.sandbox = options[:sandbox]
+ @app.load_console
if options[:debugger]
begin
diff --git a/railties/lib/rails/commands/destroy.rb b/railties/lib/rails/commands/destroy.rb
index 2a84e2a6df..ae354eca97 100644
--- a/railties/lib/rails/commands/destroy.rb
+++ b/railties/lib/rails/commands/destroy.rb
@@ -1,8 +1,6 @@
require 'rails/generators'
require 'active_support/core_ext/object/inclusion'
-Rails::Generators.configure!
-
if ARGV.first.in?([nil, "-h", "--help"])
Rails::Generators.help 'destroy'
exit
diff --git a/railties/lib/rails/commands/generate.rb b/railties/lib/rails/commands/generate.rb
index 28c1c56352..b6f9a003d1 100644
--- a/railties/lib/rails/commands/generate.rb
+++ b/railties/lib/rails/commands/generate.rb
@@ -1,8 +1,6 @@
require 'rails/generators'
require 'active_support/core_ext/object/inclusion'
-Rails::Generators.configure!
-
if ARGV.first.in?([nil, "-h", "--help"])
Rails::Generators.help 'generate'
exit
diff --git a/railties/lib/rails/commands/plugin_new.rb b/railties/lib/rails/commands/plugin_new.rb
index 8baa8ebfd4..0287ba0638 100644
--- a/railties/lib/rails/commands/plugin_new.rb
+++ b/railties/lib/rails/commands/plugin_new.rb
@@ -1,3 +1,5 @@
+require 'rubygems' if ARGV.include?("--dev")
+
if ARGV.first != "new"
ARGV[0] = "--help"
else
@@ -6,5 +8,4 @@ end
require 'rails/generators'
require 'rails/generators/rails/plugin_new/plugin_new_generator'
-
-Rails::Generators::PluginNewGenerator.start
+Rails::Generators::PluginNewGenerator.start \ No newline at end of file
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 505a4ca2bd..91c87514cf 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -78,6 +78,7 @@ module Rails
middlewares = []
middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
middlewares << [Rails::Rack::Debugger] if options[:debugger]
+ middlewares << [Rails::Rack::ContentLength]
Hash.new(middlewares)
end
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb
index 66fab0a760..f8ad17773a 100644
--- a/railties/lib/rails/configuration.rb
+++ b/railties/lib/rails/configuration.rb
@@ -43,6 +43,7 @@ module Rails
class Generators #:nodoc:
attr_accessor :aliases, :options, :templates, :fallbacks, :colorize_logging
+ attr_reader :hidden_namespaces
def initialize
@aliases = Hash.new { |h,k| h[k] = {} }
@@ -50,6 +51,7 @@ module Rails
@fallbacks = {}
@templates = []
@colorize_logging = true
+ @hidden_namespaces = []
end
def initialize_copy(source)
@@ -59,6 +61,10 @@ module Rails
@templates = @templates.dup
end
+ def hide_namespace(namespace)
+ @hidden_namespaces << namespace
+ end
+
def method_missing(method, *args)
method = method.to_s.sub(/=$/, '').to_sym
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 81a0350724..383be1802f 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -180,7 +180,7 @@ module Rails
# <tt>my_engine:install:assets</tt>
#
# Engine name is set by default based on class name. For <tt>MyEngine::Engine</tt> it will be
- # <tt>my_engine_engine</tt>. You can change it manually it manually using the <tt>engine_name</tt> method:
+ # <tt>my_engine_engine</tt>. You can change it manually using the <tt>engine_name</tt> method:
#
# module MyEngine
# class Engine < Rails::Engine
@@ -296,7 +296,7 @@ module Rails
# helper MyEngine::SharedEngineHelper
# end
#
- # If you want to include all of the engine's helpers, you can use #helpers method on egine's
+ # If you want to include all of the engine's helpers, you can use #helpers method on an engine's
# instance:
#
# class ApplicationController < ActionController::Base
@@ -305,7 +305,7 @@ module Rails
#
# It will include all of the helpers from engine's directory. Take into account that this does
# not include helpers defined in controllers with helper_method or other similar solutions,
- # only helpers defined in helpers directory will be included.
+ # only helpers defined in the helpers directory will be included.
#
# == Migrations & seed data
#
@@ -387,7 +387,7 @@ module Rails
delegate :middleware, :root, :paths, :to => :config
delegate :engine_name, :isolated?, :to => "self.class"
- def load_tasks
+ def load_tasks(*)
super
paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
end
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 85c67af19a..09e505a75b 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -57,7 +57,7 @@ module Rails
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
:stylesheets => true,
- :stylesheet_engine => nil,
+ :stylesheet_engine => :css,
:test_framework => false,
:template_engine => :erb
},
@@ -68,13 +68,14 @@ module Rails
}
}
- def self.configure!(config = Rails.application.config.generators) #:nodoc:
+ def self.configure!(config) #:nodoc:
no_color! unless config.colorize_logging
aliases.deep_merge! config.aliases
options.deep_merge! config.options
fallbacks.merge! config.fallbacks
templates_path.concat config.templates
templates_path.uniq!
+ hide_namespaces *config.hidden_namespaces
end
def self.templates_path
@@ -175,6 +176,7 @@ module Rails
orm = options[:rails][:orm]
test = options[:rails][:test_framework]
template = options[:rails][:template_engine]
+ css = options[:rails][:stylesheet_engine]
[
"rails",
@@ -194,7 +196,11 @@ module Rails
"#{test}:plugin",
"#{template}:controller",
"#{template}:scaffold",
- "#{template}:mailer"
+ "#{template}:mailer",
+ "#{css}:scaffold",
+ "#{css}:assets",
+ "css:assets",
+ "css:scaffold"
]
end
end
@@ -280,7 +286,6 @@ module Rails
# Receives namespaces in an array and tries to find matching generators
# in the load path.
def self.lookup(namespaces) #:nodoc:
- load_generators_from_railties!
paths = namespaces_to_paths(namespaces)
paths.each do |raw_path|
@@ -304,8 +309,6 @@ module Rails
# This will try to load any generator in the load path to show in help.
def self.lookup! #:nodoc:
- load_generators_from_railties!
-
$LOAD_PATH.each do |base|
Dir[File.join(base, "{rails/generators,generators}", "**", "*_generator.rb")].each do |path|
begin
@@ -318,13 +321,6 @@ module Rails
end
end
- # Allow generators to be loaded from custom paths.
- def self.load_generators_from_railties! #:nodoc:
- return if defined?(@generators_from_railties) || Rails.application.nil?
- @generators_from_railties = true
- Rails.application.load_generators
- end
-
# Convert namespaces to paths by replacing ":" for "/" and adding
# an extra lookup. For example, "rails:model" should be searched
# in both: "rails/model/model_generator" and "rails/model_generator".
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb
index 8512b1ca4a..7972c72c1e 100644
--- a/railties/lib/rails/generators/app_base.rb
+++ b/railties/lib/rails/generators/app_base.rb
@@ -1,5 +1,5 @@
require 'digest/md5'
-require 'active_support/secure_random'
+require 'securerandom'
require 'active_support/core_ext/string/strip'
require 'rails/version' unless defined?(Rails::VERSION)
require 'rbconfig'
@@ -128,7 +128,7 @@ module Rails
end
def comment_if(value)
- options[value] ? '#' : ''
+ options[value] ? '# ' : ''
end
def rails_gemfile_entry
diff --git a/railties/lib/rails/generators/css/assets/assets_generator.rb b/railties/lib/rails/generators/css/assets/assets_generator.rb
new file mode 100644
index 0000000000..492177ca2e
--- /dev/null
+++ b/railties/lib/rails/generators/css/assets/assets_generator.rb
@@ -0,0 +1,13 @@
+require "rails/generators/named_base"
+
+module Css
+ module Generators
+ class AssetsGenerator < Rails::Generators::NamedBase
+ source_root File.expand_path("../templates", __FILE__)
+
+ def copy_stylesheet
+ copy_file "stylesheet.css", File.join('app/assets/stylesheets', class_path, "#{file_name}.css")
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss b/railties/lib/rails/generators/css/assets/templates/stylesheet.css
index ba95e217cc..afad32db02 100644
--- a/railties/lib/rails/generators/rails/assets/templates/stylesheet.css.scss
+++ b/railties/lib/rails/generators/css/assets/templates/stylesheet.css
@@ -1,5 +1,4 @@
-/*
+/*
Place all the styles related to the matching controller here.
They will automatically be included in application.css.
- You can use Sass (SCSS) here: http://sass-lang.com/
*/
diff --git a/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb
new file mode 100644
index 0000000000..1d7fe9fac0
--- /dev/null
+++ b/railties/lib/rails/generators/css/scaffold/scaffold_generator.rb
@@ -0,0 +1,16 @@
+require "rails/generators/named_base"
+
+module Css
+ module Generators
+ class ScaffoldGenerator < Rails::Generators::NamedBase
+ # In order to allow the Sass generators to pick up the default Rails CSS and
+ # transform it, we leave it in a standard location for the CSS stylesheet
+ # generators to handle. For the simple, default case, just copy it over.
+ def copy_stylesheet
+ dir = Rails::Generators::ScaffoldGenerator.source_root
+ file = File.join(dir, "scaffold.css")
+ create_file "app/assets/stylesheets/scaffold.css", File.read(file)
+ end
+ end
+ end
+end
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index 5f9fb9685c..242677cc65 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -272,7 +272,7 @@ module Rails
end
def app_secret
- ActiveSupport::SecureRandom.hex(64)
+ SecureRandom.hex(64)
end
def mysql_socket
diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile
index 5e1b4b0098..ebe38bf8e6 100644
--- a/railties/lib/rails/generators/rails/app/templates/Gemfile
+++ b/railties/lib/rails/generators/rails/app/templates/Gemfile
@@ -4,10 +4,10 @@ source 'http://rubygems.org'
<%= database_gemfile_entry -%>
-<%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6" -%>
+<%= "gem 'jruby-openssl'\n" if defined?(JRUBY_VERSION) -%>
# Asset template engines
<%= "gem 'json'\n" if RUBY_VERSION < "1.9.2" -%>
-gem 'sass'
+gem 'sass-rails'
gem 'coffee-script'
gem 'uglifier'
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index 8ff80c6fd3..37c2fb1263 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -4,7 +4,7 @@ require File.expand_path('../boot', __FILE__)
require 'rails/all'
<% else -%>
# Pick the frameworks you want:
-<%= comment_if :skip_active_record %> require "active_record/railtie"
+<%= comment_if :skip_active_record %>require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
@@ -39,17 +39,6 @@ module <%= app_const_base %>
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
- # Please note that JavaScript expansions are *ignored altogether* if the asset
- # pipeline is enabled (see config.assets.enabled below). Put your defaults in
- # app/assets/javascripts/application.js in that case.
- #
- # JavaScript files you want as :defaults (application.js is always included).
-<% if options[:skip_javascript] -%>
- # config.action_view.javascript_expansions[:defaults] = %w()
-<% else -%>
- # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs)
-<% end -%>
-
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
index 066aa54862..ffd9058238 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt
@@ -2,7 +2,7 @@
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
- # every request. This slows down response time but is perfect for development
+ # every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
@@ -21,4 +21,7 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
+
+ # Do not compress assets
+ config.assets.compress = false
end
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
index 1c3dc1117f..60e26755fe 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt
@@ -11,9 +11,11 @@
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
- # Compress both stylesheets and JavaScripts
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Specify the default JavaScript compressor
config.assets.js_compressor = :uglifier
- config.assets.css_compressor = :scss
# Specifies the header that your server uses for sending files
# (comment out if your front-end server doesn't support this)
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
index 8d11377211..ee068b0202 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
+++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt
@@ -2,9 +2,9 @@
# Settings specified here will take precedence over those in config/application.rb
# The test environment is used exclusively to run your application's
- # test suite. You never need to work with it otherwise. Remember that
+ # test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
- # and recreated between test runs. Don't rely on the data there!
+ # and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Configure static asset server for tests with Cache-Control for performance
diff --git a/railties/lib/rails/generators/rails/assets/assets_generator.rb b/railties/lib/rails/generators/rails/assets/assets_generator.rb
index 2d52da77eb..db3422fe83 100644
--- a/railties/lib/rails/generators/rails/assets/assets_generator.rb
+++ b/railties/lib/rails/generators/rails/assets/assets_generator.rb
@@ -13,12 +13,6 @@ module Rails
File.join('app/assets/javascripts', class_path, "#{asset_name}.#{javascript_extension}")
end
- def create_stylesheet_files
- return unless options.stylesheets?
- copy_file "stylesheet.#{stylesheet_extension}",
- File.join('app/assets/stylesheets', class_path, "#{asset_name}.#{stylesheet_extension}")
- end
-
protected
def asset_name
@@ -30,9 +24,8 @@ module Rails
"js.#{options.javascript_engine}" : "js"
end
- def stylesheet_extension
- options.stylesheet_engine.present? ?
- "css.#{options.stylesheet_engine}" : "css"
+ hook_for :stylesheet_engine do |stylesheet_engine|
+ invoke stylesheet_engine, [name] if options[:stylesheets]
end
end
end
diff --git a/railties/lib/rails/generators/rails/plugin/USAGE b/railties/lib/rails/generators/rails/plugin/USAGE
deleted file mode 100644
index 1bcfcf190d..0000000000
--- a/railties/lib/rails/generators/rails/plugin/USAGE
+++ /dev/null
@@ -1,13 +0,0 @@
-Description:
- Stubs out a new plugin at vendor/plugins. Pass the plugin name, either
- CamelCased or under_scored, as an argument.
-
-Example:
- `rails generate plugin BrowserFilters`
-
- creates a standard browser_filters plugin:
- vendor/plugins/browser_filters/README
- vendor/plugins/browser_filters/init.rb
- vendor/plugins/browser_filters/install.rb
- vendor/plugins/browser_filters/lib/browser_filters.rb
- vendor/plugins/browser_filters/test/browser_filters_test.rb
diff --git a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb b/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
deleted file mode 100644
index 97f681d826..0000000000
--- a/railties/lib/rails/generators/rails/plugin/plugin_generator.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-
-require 'rails/generators/rails/generator/generator_generator'
-
-module Rails
- module Generators
- class PluginGenerator < NamedBase
- class_option :tasks, :desc => "When supplied creates tasks base files."
-
- def show_deprecation
- return unless behavior == :invoke
- message = "Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure."
- ActiveSupport::Deprecation.warn message
- end
-
- check_class_collision
-
- def create_root_files
- directory '.', plugin_dir, :recursive => false
- end
-
- def create_lib_files
- directory 'lib', plugin_dir('lib'), :recursive => false
- end
-
- def create_tasks_files
- return unless options[:tasks]
- directory 'lib/tasks', plugin_dir('lib/tasks')
- end
-
- hook_for :generator do |generator|
- inside plugin_dir, :verbose => true do
- invoke generator, [ name ], :namespace => false
- end
- end
-
- hook_for :test_framework do |test_framework|
- inside plugin_dir, :verbose => true do
- invoke test_framework
- end
- end
-
- protected
-
- def plugin_dir(join=nil)
- if join
- File.join(plugin_dir, join)
- else
- "vendor/plugins/#{file_name}"
- end
- end
-
- end
- end
-end
diff --git a/railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt b/railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt
deleted file mode 100644
index 8717df053d..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/MIT-LICENSE.tt
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) <%= Date.today.year %> [name of plugin creator]
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/railties/lib/rails/generators/rails/plugin/templates/README.tt b/railties/lib/rails/generators/rails/plugin/templates/README.tt
deleted file mode 100644
index 702db07cb1..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/README.tt
+++ /dev/null
@@ -1,13 +0,0 @@
-<%= class_name %>
-<%= "=" * class_name.size %>
-
-Introduction goes here.
-
-
-Example
-=======
-
-Example goes here.
-
-
-Copyright (c) <%= Date.today.year %> [name of plugin creator], released under the MIT license
diff --git a/railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt b/railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt
deleted file mode 100644
index 77149ae351..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/Rakefile.tt
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/env rake
-require 'rake/testtask'
-require 'rake/rdoctask'
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test the <%= file_name %> plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Generate documentation for the <%= file_name %> plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = '<%= class_name %>'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end \ No newline at end of file
diff --git a/railties/lib/rails/generators/rails/plugin/templates/init.rb b/railties/lib/rails/generators/rails/plugin/templates/init.rb
deleted file mode 100644
index 3c19a743c9..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/init.rb
+++ /dev/null
@@ -1 +0,0 @@
-# Include hook code here
diff --git a/railties/lib/rails/generators/rails/plugin/templates/install.rb b/railties/lib/rails/generators/rails/plugin/templates/install.rb
deleted file mode 100644
index f7732d3796..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/install.rb
+++ /dev/null
@@ -1 +0,0 @@
-# Install hook code here
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt b/railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt
deleted file mode 100644
index d8d908a959..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/%file_name%.rb.tt
+++ /dev/null
@@ -1 +0,0 @@
-# <%= class_name %>
diff --git a/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt b/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt
deleted file mode 100644
index 72920a9d3a..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/lib/tasks/%file_name%_tasks.rake.tt
+++ /dev/null
@@ -1,4 +0,0 @@
-# desc "Explaining what the task does"
-# task :<%= file_name %> do
-# # Task goes here
-# end
diff --git a/railties/lib/rails/generators/rails/plugin/templates/uninstall.rb b/railties/lib/rails/generators/rails/plugin/templates/uninstall.rb
deleted file mode 100644
index 9738333463..0000000000
--- a/railties/lib/rails/generators/rails/plugin/templates/uninstall.rb
+++ /dev/null
@@ -1 +0,0 @@
-# Uninstall hook code here
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index 9ddb3cae33..00f90f9498 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -202,7 +202,7 @@ task :default => :test
end
def create_test_dummy_files
- return if options[:skip_test_unit]
+ return if options[:skip_test_unit] && options[:dummy_path] == 'test/dummy'
create_dummy_app
end
@@ -258,7 +258,7 @@ task :default => :test
elsif RESERVED_NAMES.include?(name)
raise Error, "Invalid plugin name #{name}. Please give a name which does not match one of the reserved rails words."
elsif Object.const_defined?(camelized)
- raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another application name."
+ raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another plugin name."
end
end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
index 3d9bfb22c7..56b06829d8 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
@@ -4,6 +4,9 @@ Gem::Specification.new do |s|
s.name = "<%= name %>"
s.summary = "Insert <%= camelized %> summary."
s.description = "Insert <%= camelized %> description."
- s.files = Dir["lib/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.files = Dir["{app,config,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+<% unless options.skip_test_unit? -%>
+ s.test_files = Dir["test/**/*"]
+<% end -%>
s.version = "0.0.1"
end
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
index 5704e75a29..b28a842731 100755
--- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile
@@ -4,10 +4,15 @@ begin
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
-require 'rake/rdoctask'
-
-Rake::RDocTask.new(:rdoc) do |rdoc|
+RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = '<%= camelized %>'
rdoc.options << '--line-numbers' << '--inline-source'
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb
index aa8ea77bae..967668fe66 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/lib/%name%/engine.rb
@@ -1,5 +1,5 @@
module <%= camelized %>
- class Engine < Rails::Engine
+ class Engine < ::Rails::Engine
<% if mountable? -%>
isolate_namespace <%= camelized %>
<% end -%>
diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
index ebd5a77dd5..65d82abf6d 100644
--- a/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
+++ b/railties/lib/rails/generators/rails/plugin_new/templates/script/rails.tt
@@ -1,4 +1,3 @@
-#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENGINE_PATH = File.expand_path('../..', __FILE__)
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index aa9b45c5a5..03a61a035e 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -11,21 +11,12 @@ module Rails
hook_for :scaffold_controller, :required => true
- def copy_stylesheets_file
- if behavior == :invoke && options.stylesheets?
- template "scaffold.#{stylesheet_extension}", "app/assets/stylesheets/scaffold.#{stylesheet_extension}"
- end
- end
-
hook_for :assets do |assets|
invoke assets, [controller_name]
end
- private
-
- def stylesheet_extension
- options.stylesheet_engine.present? ?
- "css.#{options.stylesheet_engine}" : "css"
+ hook_for :stylesheet_engine do |stylesheet_engine|
+ invoke stylesheet_engine, [controller_name] if options[:stylesheets] && behavior == :invoke
end
end
end
diff --git a/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss b/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss
deleted file mode 100644
index 45116b53f6..0000000000
--- a/railties/lib/rails/generators/rails/scaffold/templates/scaffold.css.scss
+++ /dev/null
@@ -1,58 +0,0 @@
-body { background-color: #fff; color: #333; }
-
-body, p, ol, ul, td {
- font-family: verdana, arial, helvetica, sans-serif;
- font-size: 13px;
- line-height: 18px;
-}
-
-pre {
- background-color: #eee;
- padding: 10px;
- font-size: 11px;
-}
-
-a {
- color: #000;
- &:visited { color: #666; }
- &:hover { color: #fff; background-color:#000; }
-}
-
-div.field, div.actions {
- margin-bottom: 10px;
-}
-
-#notice {
- color: green;
-}
-
-.field_with_errors {
- padding: 2px;
- background-color: red;
- display: table;
-}
-
-#error_explanation {
- width: 450px;
- border: 2px solid red;
- padding: 7px;
- padding-bottom: 0;
- margin-bottom: 20px;
- background-color: #f0f0f0;
-
- h2 {
- text-align: left;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- font-size: 12px;
- margin: -7px;
- margin-bottom: 0px;
- background-color: #c00;
- color: #fff;
- }
-
- ul li {
- font-size: 12px;
- list-style: square;
- }
-} \ No newline at end of file
diff --git a/railties/lib/rails/paths.rb b/railties/lib/rails/paths.rb
index 5d217dcb10..09ff0ef378 100644
--- a/railties/lib/rails/paths.rb
+++ b/railties/lib/rails/paths.rb
@@ -2,29 +2,11 @@ require 'set'
module Rails
module Paths
- module PathParent #:nodoc:
- def method_missing(id, *args)
- match = id.to_s.match(/^(.*)=$/)
- full = [@current, $1 || id].compact.join("/")
-
- ActiveSupport::Deprecation.warn 'config.paths.app.controller API is deprecated in ' <<
- 'favor of config.paths["app/controller"] API.'
-
- if match || args.any?
- @root[full] = Path.new(@root, full, *args)
- elsif path = @root[full]
- path
- else
- super
- end
- end
- end
-
# This object is an extended hash that behaves as root of the Rails::Paths system.
# It allows you to collect information about how you want to structure your application
# paths by a Hash like API. It requires you to give a physical path on initialization.
#
- # root = Root.new
+ # root = Root.new "/rails"
# root.add "app/controllers", :eager_load => true
#
# The command above creates a new root object and add "app/controllers" as a path.
@@ -54,8 +36,7 @@ module Rails
#
# Finally, the Path object also provides a few helpers:
#
- # root = Root.new
- # root.path = "/rails"
+ # root = Root.new "/rails"
# root.add "app/controllers"
#
# root["app/controllers"].expanded # => ["/rails/app/controllers"]
@@ -63,11 +44,10 @@ module Rails
#
# Check the Path documentation for more information.
class Root < ::Hash
- include PathParent
attr_accessor :path
def initialize(path)
- raise if path.is_a?(Array)
+ raise "Argument should be a String of the physical root path" if path.is_a?(Array)
@current = nil
@path = path
@root = self
@@ -121,8 +101,6 @@ module Rails
end
class Path < Array
- include PathParent
-
attr_reader :path
attr_accessor :glob
@@ -194,11 +172,6 @@ module Rails
expanded.select { |f| File.exists?(f) }
end
- def paths
- ActiveSupport::Deprecation.warn "paths is deprecated. Please call expand instead."
- expanded
- end
-
alias to_a expanded
end
end
diff --git a/railties/lib/rails/rack/debugger.rb b/railties/lib/rails/rack/debugger.rb
index 06e23db5f1..831188eeee 100644
--- a/railties/lib/rails/rack/debugger.rb
+++ b/railties/lib/rails/rack/debugger.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/kernel/requires'
-
module Rails
module Rack
class Debugger
@@ -8,11 +6,12 @@ module Rails
ARGV.clear # clear ARGV so that rails server options aren't passed to IRB
- require_library_or_gem 'ruby-debug'
+ require 'ruby-debug'
+
::Debugger.start
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
puts "=> Debugger enabled"
- rescue Exception
+ rescue LoadError
puts "You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'"
exit
end
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index 0a65840c2b..65c567d72f 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -173,24 +173,24 @@ module Rails
def eager_load!
end
- def load_console(sandbox=false)
- self.class.console.each { |block| block.call(sandbox) }
+ def load_console(app)
+ self.class.console.each { |block| block.call(app) }
end
- def load_tasks
+ def load_tasks(app)
extend Rake::DSL if defined? Rake::DSL
- self.class.rake_tasks.each(&:call)
+ self.class.rake_tasks.each { |block| block.call(app) }
# load also tasks from all superclasses
klass = self.class.superclass
while klass.respond_to?(:rake_tasks)
- klass.rake_tasks.each { |t| self.instance_exec(&t) }
+ klass.rake_tasks.each { |t| self.instance_exec(app, &t) }
klass = klass.superclass
end
end
- def load_generators
- self.class.generators.each(&:call)
+ def load_generators(app)
+ self.class.generators.each { |block| block.call(app) }
end
end
end
diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb
index bfd2a73aeb..f888684117 100644
--- a/railties/lib/rails/railtie/configuration.rb
+++ b/railties/lib/rails/railtie/configuration.rb
@@ -26,11 +26,6 @@ module Rails
@@app_generators
end
- def generators(&block) #:nodoc
- ActiveSupport::Deprecation.warn "config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead."
- app_generators(&block)
- end
-
# First configurable block to run. Called before any initializers are run.
def before_configuration(&block)
ActiveSupport.on_load(:before_configuration, :yield => true, &block)
diff --git a/railties/lib/rails/tasks/assets.rake b/railties/lib/rails/tasks/assets.rake
index 158df31749..5d2f02af13 100644
--- a/railties/lib/rails/tasks/assets.rake
+++ b/railties/lib/rails/tasks/assets.rake
@@ -2,7 +2,7 @@ namespace :assets do
desc "Compile all the assets named in config.assets.precompile"
task :precompile => :environment do
# Give assets access to asset_path
- ActionView::Helpers::SprocketsHelper
+ Sprockets::Helpers::RailsHelper
assets = Rails.application.config.assets.precompile
Rails.application.assets.precompile(*assets)
diff --git a/railties/lib/rails/tasks/documentation.rake b/railties/lib/rails/tasks/documentation.rake
index edd716d7d0..79255d1f56 100644
--- a/railties/lib/rails/tasks/documentation.rake
+++ b/railties/lib/rails/tasks/documentation.rake
@@ -1,7 +1,13 @@
-require 'rake/rdoctask'
+begin
+ require 'rdoc/task'
+rescue LoadError
+ require 'rdoc/rdoc'
+ require 'rake/rdoctask'
+ RDoc::Task = Rake::RDocTask
+end
# Monkey-patch to remove redoc'ing and clobber descriptions to cut down on rake -T noise
-class RDocTaskWithoutDescriptions < Rake::RDocTask
+class RDocTaskWithoutDescriptions < RDoc::Task
def define
task rdoc_task_name
diff --git a/railties/lib/rails/tasks/misc.rake b/railties/lib/rails/tasks/misc.rake
index e505b8c338..833fcb6f72 100644
--- a/railties/lib/rails/tasks/misc.rake
+++ b/railties/lib/rails/tasks/misc.rake
@@ -9,8 +9,8 @@ end
desc 'Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions).'
task :secret do
- require 'active_support/secure_random'
- puts ActiveSupport::SecureRandom.hex(64)
+ require 'securerandom'
+ puts SecureRandom.hex(64)
end
desc 'List versions of all Rails frameworks and the environment'
diff --git a/railties/lib/rails/test_help.rb b/railties/lib/rails/test_help.rb
index 41485c8bac..68f566274d 100644
--- a/railties/lib/rails/test_help.rb
+++ b/railties/lib/rails/test_help.rb
@@ -3,7 +3,6 @@
abort("Abort testing: Your Rails environment is running in production mode!") if Rails.env.production?
require 'test/unit'
-require 'active_support/core_ext/kernel/requires'
require 'active_support/test_case'
require 'action_controller/test_case'
require 'action_dispatch/testing/integration'
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
index 5ae6323345..db8f1f2ac6 100644
--- a/railties/test/application/console_test.rb
+++ b/railties/test/application/console_test.rb
@@ -10,7 +10,8 @@ class ConsoleTest < Test::Unit::TestCase
def load_environment(sandbox = false)
require "#{rails_root}/config/environment"
- Rails.application.load_console(sandbox)
+ Rails.application.sandbox = sandbox
+ Rails.application.load_console
end
def test_app_method_should_return_integration_session
@@ -78,8 +79,8 @@ class ConsoleTest < Test::Unit::TestCase
value = false
Class.new(Rails::Railtie) do
- console do |sandbox|
- value = sandbox
+ console do |app|
+ value = app.sandbox?
end
end
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
index 8b840fffd0..1ca9515335 100644
--- a/railties/test/application/generators_test.rb
+++ b/railties/test/application/generators_test.rb
@@ -68,8 +68,7 @@ module ApplicationTests
# Initialize the application
require "#{app_path}/config/environment"
- require "rails/generators"
- Rails::Generators.configure!
+ Rails.application.load_generators
assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
@@ -84,8 +83,7 @@ module ApplicationTests
# Initialize the application
require "#{app_path}/config/environment"
- require "rails/generators"
- Rails::Generators.configure!
+ Rails.application.load_generators
assert_equal Thor::Base.shell, Thor::Shell::Basic
end
diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb
index 7e035be764..c87433db0d 100644
--- a/railties/test/application/initializers/notifications_test.rb
+++ b/railties/test/application/initializers/notifications_test.rb
@@ -33,7 +33,7 @@ module ApplicationTests
wait
assert_equal 1, logger.logged(:debug).size
- assert_match /SHOW tables/, logger.logged(:debug).last
+ assert_match(/SHOW tables/, logger.logged(:debug).last)
end
end
end
diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb
index f582ed0e42..a8033d2b23 100644
--- a/railties/test/application/middleware/cache_test.rb
+++ b/railties/test/application/middleware/cache_test.rb
@@ -16,7 +16,7 @@ module ApplicationTests
class ExpiresController < ApplicationController
def expires_header
expires_in 10, :public => !params[:private]
- render :text => ActiveSupport::SecureRandom.hex(16)
+ render :text => SecureRandom.hex(16)
end
def expires_etag
@@ -30,7 +30,7 @@ module ApplicationTests
private
def render_conditionally(headers)
if stale?(headers.merge(:public => !params[:private]))
- render :text => ActiveSupport::SecureRandom.hex(16)
+ render :text => SecureRandom.hex(16)
end
end
end
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index ef448f7791..715798ca08 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -19,7 +19,6 @@ module ApplicationTests
boot!
assert_equal [
- "Rails::Rack::ContentLength",
"ActionDispatch::Static",
"Rack::Lock",
"ActiveSupport::Cache::Strategy::LocalCache",
@@ -49,7 +48,7 @@ module ApplicationTests
boot!
- assert_equal "Rack::Cache", middleware.second
+ assert_equal "Rack::Cache", middleware.first
end
test "Rack::SSL is present when force_ssl is set" do
@@ -104,7 +103,7 @@ module ApplicationTests
end
test "insert middleware after" do
- add_to_config "config.middleware.insert_after Rails::Rack::ContentLength, Rack::Config"
+ add_to_config "config.middleware.insert_after ActionDispatch::Static, Rack::Config"
boot!
assert_equal "Rack::Config", middleware.second
end
@@ -112,12 +111,12 @@ module ApplicationTests
test "RAILS_CACHE does not respond to middleware" do
add_to_config "config.cache_store = :memory_store"
boot!
- assert_equal "Rack::Runtime", middleware.fourth
+ assert_equal "Rack::Runtime", middleware.third
end
test "RAILS_CACHE does respond to middleware" do
boot!
- assert_equal "Rack::Runtime", middleware.fifth
+ assert_equal "Rack::Runtime", middleware.fourth
end
test "identity map is inserted" do
@@ -127,7 +126,7 @@ module ApplicationTests
end
test "insert middleware before" do
- add_to_config "config.middleware.insert_before Rails::Rack::ContentLength, Rack::Config"
+ add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config"
boot!
assert_equal "Rack::Config", middleware.first
end
@@ -201,4 +200,4 @@ module ApplicationTests
AppTemplate::Application.middleware.map(&:klass).map(&:name)
end
end
-end
+end \ No newline at end of file
diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb
index b1ff6e9cb1..03e0247556 100644
--- a/railties/test/application/paths_test.rb
+++ b/railties/test/application/paths_test.rb
@@ -61,7 +61,7 @@ module ApplicationTests
end
test "environments has a glob equal to the current environment" do
- assert_equal "#{Rails.env}.rb", @paths.config.environments.glob
+ assert_equal "#{Rails.env}.rb", @paths["config/environments"].glob
end
test "load path includes each of the paths in config.paths as long as the directories exist" do
diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb
index a29244357c..715af5c642 100644
--- a/railties/test/application/rack/logger_test.rb
+++ b/railties/test/application/rack/logger_test.rb
@@ -21,19 +21,19 @@ module ApplicationTests
test "logger logs proper HTTP verb and path" do
get "/blah"
wait
- assert_match /^Started GET "\/blah"/, logs[0]
+ assert_match(/^Started GET "\/blah"/, logs[0])
end
test "logger logs HTTP verb override" do
post "/", {:_method => 'put'}
wait
- assert_match /^Started PUT "\/"/, logs[0]
+ assert_match(/^Started PUT "\/"/, logs[0])
end
test "logger logs HEAD requests" do
post "/", {:_method => 'head'}
wait
- assert_match /^Started HEAD "\/"/, logs[0]
+ assert_match(/^Started HEAD "\/"/, logs[0])
end
end
end
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb
index d77c2d14ab..ab36ace5e5 100644
--- a/railties/test/application/rake_test.rb
+++ b/railties/test/application/rake_test.rb
@@ -31,7 +31,7 @@ module ApplicationTests
AppTemplate::Application.initialize!
RUBY
- assert_match "SuperMiddleware", Dir.chdir(app_path){ `rake middleware` }
+ assert_match("SuperMiddleware", Dir.chdir(app_path){ `rake middleware` })
end
def test_initializers_are_executed_in_rake_tasks
@@ -93,16 +93,16 @@ module ApplicationTests
end
output = Dir.chdir(app_path){ `rake db:migrate` }
- assert_match /create_table\(:users\)/, output
- assert_match /CreateUsers: migrated/, output
- assert_match /add_column\(:users, :email, :string\)/, output
- assert_match /AddEmailToUsers: migrated/, output
+ assert_match(/create_table\(:users\)/, output)
+ assert_match(/CreateUsers: migrated/, output)
+ assert_match(/add_column\(:users, :email, :string\)/, output)
+ assert_match(/AddEmailToUsers: migrated/, output)
output = Dir.chdir(app_path){ `rake db:rollback STEP=2` }
- assert_match /drop_table\("users"\)/, output
- assert_match /CreateUsers: reverted/, output
- assert_match /remove_column\("users", :email\)/, output
- assert_match /AddEmailToUsers: reverted/, output
+ assert_match(/drop_table\("users"\)/, output)
+ assert_match(/CreateUsers: reverted/, output)
+ assert_match(/remove_column\("users", :email\)/, output)
+ assert_match(/AddEmailToUsers: reverted/, output)
end
def test_loading_specific_fixtures
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 42fe7a7fea..c31c65a27d 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -136,7 +136,9 @@ class AppGeneratorTest < Rails::Generators::TestCase
run_generator([destination_root, "-d", "jdbcmysql"])
assert_file "config/database.yml", /jdbcmysql/
assert_file "Gemfile", /^gem\s+["']activerecord-jdbcmysql-adapter["']$/
- assert_file "Gemfile", /^gem\s+["']jruby-openssl["']$/ if defined?(JRUBY_VERSION) && JRUBY_VERSION < "1.6"
+ # TODO: When the JRuby guys merge jruby-openssl in
+ # jruby this will be removed
+ assert_file "Gemfile", /^gem\s+["']jruby-openssl["']$/ if defined?(JRUBY_VERSION)
end
def test_config_jdbcsqlite3_database
@@ -172,7 +174,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_jquery_is_the_default_javascript_library
run_generator
- assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/
assert_file "app/assets/javascripts/application.js" do |contents|
assert_match %r{^//= require jquery}, contents
assert_match %r{^//= require jquery_ujs}, contents
@@ -184,7 +185,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_other_javascript_libraries
run_generator [destination_root, '-j', 'prototype']
- assert_file "config/application.rb", /#\s+config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(prototype prototype_ujs\)/
assert_file "app/assets/javascripts/application.js" do |contents|
assert_match %r{^//= require prototype}, contents
assert_match %r{^//= require prototype_ujs}, contents
@@ -196,7 +196,6 @@ class AppGeneratorTest < Rails::Generators::TestCase
def test_javascript_is_skipped_if_required
run_generator [destination_root, "--skip-javascript"]
- assert_file "config/application.rb", /^\s+# config\.action_view\.javascript_expansions\[:defaults\]\s+=\s+%w\(\)/
assert_file "app/assets/javascripts/application.js" do |contents|
assert_no_match %r{^//=\s+require\s}, contents
end
diff --git a/railties/test/generators/assets_generator_test.rb b/railties/test/generators/assets_generator_test.rb
index 375632e5bc..2d20982d04 100644
--- a/railties/test/generators/assets_generator_test.rb
+++ b/railties/test/generators/assets_generator_test.rb
@@ -9,17 +9,17 @@ class AssetsGeneratorTest < Rails::Generators::TestCase
def test_assets
run_generator
assert_file "app/assets/javascripts/posts.js.coffee"
- assert_file "app/assets/stylesheets/posts.css.scss"
+ assert_file "app/assets/stylesheets/posts.css"
end
def test_skipping_assets
content = run_generator ["posts", "--no-stylesheets", "--no-javascripts"]
assert_no_file "app/assets/javascripts/posts.js.coffee"
- assert_no_file "app/assets/stylesheets/posts.css.scss"
+ assert_no_file "app/assets/stylesheets/posts.css"
end
def test_vanilla_assets
- run_generator ["posts", "--no-javascript-engine", "--no-stylesheet-engine"]
+ run_generator ["posts", "--no-javascript-engine"]
assert_file "app/assets/javascripts/posts.js"
assert_file "app/assets/stylesheets/posts.css"
end
diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb
index 46533b70be..3adf7be118 100644
--- a/railties/test/generators/controller_generator_test.rb
+++ b/railties/test/generators/controller_generator_test.rb
@@ -40,7 +40,7 @@ class ControllerGeneratorTest < Rails::Generators::TestCase
def test_invokes_assets
run_generator
assert_file "app/assets/javascripts/account.js.coffee"
- assert_file "app/assets/stylesheets/account.css.scss"
+ assert_file "app/assets/stylesheets/account.css"
end
def test_invokes_default_test_framework
diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb
index 1b9a8fd8a7..7fdd54fc30 100644
--- a/railties/test/generators/generators_test_helper.rb
+++ b/railties/test/generators/generators_test_helper.rb
@@ -12,7 +12,7 @@ Rails.application.config.generators.templates = [File.join(Rails.root, "lib", "t
# Call configure to load the settings from
# Rails.application.config.generators to Rails::Generators
-Rails::Generators.configure!
+Rails.application.load_generators
require 'active_record'
require 'action_dispatch'
diff --git a/railties/test/generators/namespaced_generators_test.rb b/railties/test/generators/namespaced_generators_test.rb
index 6f8a9b4280..17cbac0912 100644
--- a/railties/test/generators/namespaced_generators_test.rb
+++ b/railties/test/generators/namespaced_generators_test.rb
@@ -252,7 +252,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
assert_file "test/unit/helpers/test_app/product_lines_helper_test.rb"
# Stylesheets
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
end
def test_scaffold_on_revoke
@@ -283,7 +283,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
assert_no_file "test/unit/helpers/test_app/product_lines_helper_test.rb"
# Stylesheets (should not be removed)
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
end
def test_scaffold_with_namespace_on_invoke
@@ -324,7 +324,7 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
assert_file "test/unit/helpers/test_app/admin/roles_helper_test.rb"
# Stylesheets
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
end
def test_scaffold_with_namespace_on_revoke
@@ -356,6 +356,6 @@ class NamespacedScaffoldGeneratorTest < NamespacedGeneratorTestCase
assert_no_file "test/unit/helpers/test_app/admin/roles_helper_test.rb"
# Stylesheets (should not be removed)
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
end
end
diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb
deleted file mode 100644
index 5c0774ddbd..0000000000
--- a/railties/test/generators/plugin_generator_test.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-require 'generators/generators_test_helper'
-require 'rails/generators/rails/plugin/plugin_generator'
-
-class PluginGeneratorTest < Rails::Generators::TestCase
- include GeneratorsTestHelper
- arguments %w(plugin_fu)
-
- def test_plugin_skeleton_is_created
- silence(:stderr) { run_generator }
- year = Date.today.year
-
- %w(
- vendor/plugins
- vendor/plugins/plugin_fu
- vendor/plugins/plugin_fu/init.rb
- vendor/plugins/plugin_fu/install.rb
- vendor/plugins/plugin_fu/uninstall.rb
- vendor/plugins/plugin_fu/lib
- vendor/plugins/plugin_fu/lib/plugin_fu.rb
- vendor/plugins/plugin_fu/Rakefile
- ).each{ |path| assert_file path }
-
- %w(
- vendor/plugins/plugin_fu/README
- ).each{ |path| assert_file path, /PluginFu/ }
-
- %w(
- vendor/plugins/plugin_fu/README
- vendor/plugins/plugin_fu/MIT-LICENSE
- ).each{ |path| assert_file path, /#{year}/ }
- end
-
- def test_check_class_collision
- content = capture(:stderr){ run_generator ["object"] }
- assert_match(/The name 'Object' is either already used in your application or reserved/, content)
- end
-
- def test_invokes_default_test_framework
- silence(:stderr) { run_generator }
- assert_file "vendor/plugins/plugin_fu/test/plugin_fu_test.rb", /class PluginFuTest < ActiveSupport::TestCase/
- assert_file "vendor/plugins/plugin_fu/test/test_helper.rb"
- end
-
- def test_logs_if_the_test_framework_cannot_be_found
- content = nil
- silence(:stderr) { content = run_generator ["plugin_fu", "--test-framework=rspec"] }
- assert_match(/rspec \[not found\]/, content)
- end
-
- def test_creates_tasks_if_required
- silence(:stderr) { run_generator ["plugin_fu", "--tasks"] }
- assert_file "vendor/plugins/plugin_fu/lib/tasks/plugin_fu_tasks.rake"
- end
-
- def test_creates_generator_if_required
- silence(:stderr) { run_generator ["plugin_fu", "--generator"] }
- assert_file "vendor/plugins/plugin_fu/lib/generators/templates"
- assert_file "vendor/plugins/plugin_fu/lib/generators/plugin_fu_generator.rb",
- /class PluginFuGenerator < Rails::Generators::NamedBase/
- end
-
- def test_plugin_generator_on_revoke
- silence(:stderr) { run_generator }
- run_generator ["plugin_fu"], :behavior => :revoke
- end
-
- def test_deprecation
- output = capture(:stderr) { run_generator }
- assert_match(/Plugin generator is deprecated, please use 'rails plugin new' command to generate plugin structure./, output)
- end
-end
diff --git a/railties/test/generators/plugin_new_generator_test.rb b/railties/test/generators/plugin_new_generator_test.rb
index 297ac5d238..528c73ffaf 100644
--- a/railties/test/generators/plugin_new_generator_test.rb
+++ b/railties/test/generators/plugin_new_generator_test.rb
@@ -148,7 +148,7 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_file "app/views"
assert_file "app/helpers"
assert_file "config/routes.rb", /Rails.application.routes.draw do/
- assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < Rails::Engine\n end\nend/
+ assert_file "lib/bukkits/engine.rb", /module Bukkits\n class Engine < ::Rails::Engine\n end\nend/
assert_file "lib/bukkits.rb", /require "bukkits\/engine"/
end
@@ -169,6 +169,19 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_file "app/views/layouts/bukkits/application.html.erb", /<title>Bukkits<\/title>/
end
+ def test_creating_gemspec
+ run_generator
+ assert_file "bukkits.gemspec", /s.name = "bukkits"/
+ assert_file "bukkits.gemspec", /s.files = Dir\["\{app,config,lib\}\/\*\*\/\*"\]/
+ assert_file "bukkits.gemspec", /s.test_files = Dir\["test\/\*\*\/\*"\]/
+ assert_file "bukkits.gemspec", /s.version = "0.0.1"/
+ end
+
+ def test_shebang
+ run_generator
+ assert_file "script/rails", /#!\/usr\/bin\/env ruby/
+ end
+
def test_passing_dummy_path_as_a_parameter
run_generator [destination_root, "--dummy_path", "spec/dummy"]
assert_file "spec/dummy"
@@ -176,6 +189,21 @@ class PluginNewGeneratorTest < Rails::Generators::TestCase
assert_no_file "test/dummy"
end
+ def test_creating_dummy_without_tests_but_with_dummy_path
+ run_generator [destination_root, "--dummy_path", "spec/dummy", "--skip-test-unit"]
+ assert_file "spec/dummy"
+ assert_file "spec/dummy/config/application.rb"
+ assert_no_file "test"
+ end
+
+ def test_skipping_test_unit
+ run_generator [destination_root, "--skip-test-unit"]
+ assert_no_file "test"
+ assert_file "bukkits.gemspec" do |contents|
+ assert_no_match /s.test_files = Dir\["test\/\*\*\/\*"\]/, contents
+ end
+ end
+
def test_skipping_gemspec
run_generator [destination_root, "--skip-gemspec"]
assert_no_file "bukkits.gemspec"
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index 4b07f8bcbe..2135ffac81 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -80,9 +80,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "test/unit/helpers/product_lines_helper_test.rb"
# Assets
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
assert_file "app/assets/javascripts/product_lines.js.coffee"
- assert_file "app/assets/stylesheets/product_lines.css.scss"
+ assert_file "app/assets/stylesheets/product_lines.css"
end
def test_scaffold_on_revoke
@@ -113,9 +113,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_no_file "test/unit/helpers/product_lines_helper_test.rb"
# Assets
- assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/
+ assert_file "app/assets/stylesheets/scaffold.css", /:visited/
assert_no_file "app/assets/javascripts/product_lines.js.coffee"
- assert_no_file "app/assets/stylesheets/product_lines.css.scss"
+ assert_no_file "app/assets/stylesheets/product_lines.css"
end
def test_scaffold_with_namespace_on_invoke
@@ -189,9 +189,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_file "test/unit/helpers/admin/roles_helper_test.rb"
# Assets
- assert_file "app/assets/stylesheets/scaffold.css.scss", /&:visited/
+ assert_file "app/assets/stylesheets/scaffold.css", /:visited/
assert_file "app/assets/javascripts/admin/roles.js.coffee"
- assert_file "app/assets/stylesheets/admin/roles.css.scss"
+ assert_file "app/assets/stylesheets/admin/roles.css"
end
def test_scaffold_with_namespace_on_revoke
@@ -223,9 +223,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_no_file "test/unit/helpers/admin/roles_helper_test.rb"
# Assets
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
assert_no_file "app/assets/javascripts/admin/roles.js.coffee"
- assert_no_file "app/assets/stylesheets/admin/roles.css.scss"
+ assert_no_file "app/assets/stylesheets/admin/roles.css"
end
def test_scaffold_generator_on_revoke_does_not_mutilate_legacy_map_parameter
@@ -245,27 +245,27 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
def test_scaffold_generator_no_assets
run_generator [ "posts", "--no-assets" ]
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
assert_no_file "app/assets/javascripts/posts.js.coffee"
- assert_no_file "app/assets/stylesheets/posts.css.scss"
+ assert_no_file "app/assets/stylesheets/posts.css"
end
def test_scaffold_generator_no_stylesheets
run_generator [ "posts", "--no-stylesheets" ]
- assert_no_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_no_file "app/assets/stylesheets/scaffold.css"
assert_file "app/assets/javascripts/posts.js.coffee"
- assert_no_file "app/assets/stylesheets/posts.css.scss"
+ assert_no_file "app/assets/stylesheets/posts.css"
end
def test_scaffold_generator_no_javascripts
run_generator [ "posts", "--no-javascripts" ]
- assert_file "app/assets/stylesheets/scaffold.css.scss"
+ assert_file "app/assets/stylesheets/scaffold.css"
assert_no_file "app/assets/javascripts/posts.js.coffee"
- assert_file "app/assets/stylesheets/posts.css.scss"
+ assert_file "app/assets/stylesheets/posts.css"
end
- def test_scaffold_generator_no_negines
- run_generator [ "posts", "--no-javascript-engine", "--no-stylesheet-engine" ]
+ def test_scaffold_generator_no_engines
+ run_generator [ "posts", "--no-javascript-engine" ]
assert_file "app/assets/stylesheets/scaffold.css"
assert_file "app/assets/javascripts/posts.js"
assert_file "app/assets/stylesheets/posts.css"
diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb
index 1264ac7764..301ae80bcf 100644
--- a/railties/test/generators_test.rb
+++ b/railties/test/generators_test.rb
@@ -185,13 +185,6 @@ class GeneratorsTest < Rails::Generators::TestCase
Rails::Generators.subclasses.delete(WithOptionsGenerator)
end
- def test_load_generators_from_railties
- Rails::Generators::ModelGenerator.expects(:start).with(["Account"], {})
- Rails::Generators.send(:remove_instance_variable, :@generators_from_railties)
- Rails.application.expects(:load_generators)
- Rails::Generators.invoke("model", ["Account"])
- end
-
def test_rails_root_templates
template = File.join(Rails.root, "lib", "templates", "active_record", "model", "model.rb")
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index f2261540ca..69208ce4c3 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -8,9 +8,8 @@
# Rails booted up.
require 'fileutils'
-# TODO: Remove rubygems when possible
-require 'rubygems'
require 'test/unit'
+require 'rubygems'
# TODO: Remove setting this magic constant
RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..")
diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb
index 6e4e3446b3..c0f3887263 100644
--- a/railties/test/paths_test.rb
+++ b/railties/test/paths_test.rb
@@ -227,57 +227,4 @@ class PathsTest < ActiveSupport::TestCase
assert @root["app"].autoload?
assert_equal ["/app"], @root.autoload_paths
end
-
- # Deprecated API tests
-
- test "reading a root level path with assignment" do
- @root.add "app"
- assert_deprecated do
- assert_equal ["/foo/bar/app"], @root.app.to_a
- end
- end
-
- test "creating a root level path with assignment" do
- assert_deprecated do
- @root.app = "/foo/bar"
- end
- assert_equal ["/foo/bar"], @root["app"].to_a
- end
-
- test "creating a root level path without assignment" do
- assert_deprecated do
- @root.app "/foo/bar"
- end
- assert_equal ["/foo/bar"], @root["app"].to_a
- end
-
- test "reading a nested level path with assignment" do
- @root.add "app"
- @root.add "app/model"
- assert_deprecated do
- assert_equal ["/foo/bar/app/model"], @root.app.model.to_a
- end
- end
-
- test "creating a nested level path with assignment" do
- @root.add "app"
- assert_deprecated do
- @root.app.model = "/foo/bar"
- end
- assert_equal ["/foo/bar"], @root["app/model"].to_a
- end
-
- test "creating a nested level path without assignment" do
- @root.add "app"
- assert_deprecated do
- @root.app.model "/foo/bar"
- end
- assert_equal ["/foo/bar"], @root["app/model"].to_a
- end
-
- test "trying to access a path that does not exist raises NoMethodError" do
- assert_deprecated do
- assert_raises(NoMethodError) { @root.app }
- end
- end
end
diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb
index 9d194f41a6..8a9363fb80 100644
--- a/railties/test/rails_info_controller_test.rb
+++ b/railties/test/rails_info_controller_test.rb
@@ -1,5 +1,4 @@
require 'abstract_unit'
-require 'action_controller'
module ActionController
class Base
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index 7ea8364ae9..18fdf59fe3 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -97,7 +97,7 @@ module RailtiesTest
assert !$ran_block
require 'rake'
require 'rake/testtask'
- require 'rake/rdoctask'
+ require 'rdoc/task'
AppTemplate::Application.load_tasks
assert $ran_block
@@ -121,7 +121,7 @@ module RailtiesTest
assert_equal [], $ran_block
require 'rake'
require 'rake/testtask'
- require 'rake/rdoctask'
+ require 'rdoc/task'
AppTemplate::Application.load_tasks
assert $ran_block.include?("my_tie")
diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb
index e5debf29ae..659551d08a 100644
--- a/railties/test/railties/shared_tests.rb
+++ b/railties/test/railties/shared_tests.rb
@@ -237,7 +237,7 @@ module RailtiesTest
boot_rails
require 'rake'
- require 'rake/rdoctask'
+ require 'rdoc/task'
require 'rake/testtask'
Rails.application.load_tasks
Rake::Task[:foo].invoke