diff options
-rw-r--r-- | actionpack/lib/action_controller/metal/strong_parameters.rb | 11 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 2 | ||||
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 38 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/delegation.rb | 2 | ||||
-rw-r--r-- | guides/source/active_job_basics.md | 2 | ||||
-rw-r--r-- | guides/source/upgrading_ruby_on_rails.md | 35 | ||||
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 29 |
7 files changed, 102 insertions, 17 deletions
diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 9a99bd2001..f08c84de5b 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -100,7 +100,6 @@ module ActionController # params[:key] # => "value" # params["key"] # => "value" class Parameters < ActiveSupport::HashWithIndifferentAccess - cattr_accessor :permit_all_parameters, instance_accessor: false cattr_accessor :action_on_unpermitted_parameters, instance_accessor: false # By default, never raise an UnpermittedParameters exception if these @@ -123,6 +122,16 @@ module ActionController always_permitted_parameters end + # Returns the value of +permit_all_parameters+. + def self.permit_all_parameters + Thread.current[:action_controller_permit_all_parameters] + end + + # Sets the value of +permit_all_parameters+. + def self.permit_all_parameters=(value) + Thread.current[:action_controller_permit_all_parameters] = value + end + # Returns a new instance of <tt>ActionController::Parameters</tt>. # Also, sets the +permitted+ attribute to the default value of # <tt>ActionController::Parameters.permit_all_parameters</tt>. diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index c1e344b215..6a2668b8f7 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -87,7 +87,7 @@ module ActiveModel validates_with BlockValidator, _merge_attributes(attr_names), &block end - VALID_OPTIONS_FOR_VALIDATE = [:on, :if, :unless].freeze + VALID_OPTIONS_FOR_VALIDATE = [:on, :if, :unless, :prepend].freeze # Adds a validation method or block to the class. This is useful when # overriding the +validate+ instance method becomes too unwieldy and diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 98e0266d7e..cef66f3c0d 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -172,7 +172,43 @@ class ValidationsTest < ActiveModel::TestCase Topic.validate :title, presence: true end message = 'Unknown key: :presence. Valid keys are: :on, :if, :unless. Perhaps you meant to call `validates` instead of `validate`?' - assert_equal message, error.message + assert_includes error.message, "Unknown key: :presence" + assert_includes error.message, "Perhaps you meant to call `validates` instead of `validate`?" + end + + def test_callback_options_to_validate + klass = Class.new(Topic) do + attr_reader :call_sequence + + def initialize(*) + super + @call_sequence = [] + end + + private + def validator_a + @call_sequence << :a + end + + def validator_b + @call_sequence << :b + end + + def validator_c + @call_sequence << :c + end + end + + assert_nothing_raised do + klass.validate :validator_a, if: ->{ true } + klass.validate :validator_b, prepend: true + klass.validate :validator_c, unless: ->{ true } + end + + t = klass.new + + assert_predicate t, :valid? + assert_equal [:b, :a], t.call_sequence end def test_errors_conversions diff --git a/activesupport/lib/active_support/core_ext/module/delegation.rb b/activesupport/lib/active_support/core_ext/module/delegation.rb index 570585b89a..24df83800b 100644 --- a/activesupport/lib/active_support/core_ext/module/delegation.rb +++ b/activesupport/lib/active_support/core_ext/module/delegation.rb @@ -17,7 +17,7 @@ class Module # ==== Options # * <tt>:to</tt> - Specifies the target object # * <tt>:prefix</tt> - Prefixes the new method with the target name or a custom prefix - # * <tt>:allow_nil</tt> - if set to true, prevents a +NoMethodError+ to be raised + # * <tt>:allow_nil</tt> - if set to true, prevents a +NoMethodError+ from being raised # # The macro receives one or more method names (specified as symbols or # strings) and the name of the target object via the <tt>:to</tt> option diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md index 748467866d..3657d7cad7 100644 --- a/guides/source/active_job_basics.md +++ b/guides/source/active_job_basics.md @@ -155,7 +155,7 @@ end # environment ``` -The default queue name prefix delimiter is '_'. This can be changed by setting +The default queue name prefix delimiter is '\_'. This can be changed by setting `config.active_job.queue_name_delimiter` in `application.rb`: ```ruby diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index f26ddd1df8..51f79f44f5 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -207,12 +207,47 @@ gem 'rails-deprecated_sanitizer' ``` ### Rails DOM Testing + The [`TagAssertions` module](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/TagAssertions.html) (containing methods such as `assert_tag`), [has been deprecated](https://github.com/rails/rails/blob/6061472b8c310158a2a2e8e9a6b81a1aef6b60fe/actionpack/lib/action_dispatch/testing/assertions/dom.rb) in favor of the `assert_select` methods from the `SelectorAssertions` module, which has been extracted into the [rails-dom-testing gem](https://github.com/rails/rails-dom-testing). ### Masked Authenticity Tokens + In order to mitigate SSL attacks, `form_authenticity_token` is now masked so that it varies with each request. Thus, tokens are validated by unmasking and then decrypting. As a result, any strategies for verifying requests from non-rails forms that relied on a static session CSRF token have to take this into account. +### Action Mailer + +Previously, calling a mailer method on a mailer class will result in the +corresponding instance method being executed directly. With the introduction of +Active Job and `#deliver_later`, this is no longer true. In Rails 4.2, the +invocation of the instance methods are deferred until either `deliver_now` or +`deliver_later` is called. For example: + +```ruby +class Notifier < ActionMailer::Base + def notify(user, ...) + puts "Called" + mail(to: user.email, ...) + end +end + +mail = Notifier.notify(user, ...) # Notifier#welcome is not yet called at this point +mail = mail.deliver_now # Prints "Called" +``` + +This should not result in any noticible differnces for most applications. +However, if you need some non-mailer methods to be exectuted synchronously, and +you were previously relying on the synchronous proxying behavior, you should +define them as class methods on the mailer class directly: + +```ruby +class Notifier < ActionMailer::Base + def self.broadcast_notifications(users, ...) + users.each { |user| Notifier.notify(user, ...) } + end +end +``` + Upgrading from Rails 4.0 to Rails 4.1 ------------------------------------- diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 3ea50607a5..518277a254 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -181,8 +181,12 @@ module Rails super end - def self.github(name, github, comment = nil) - new(name, nil, comment, github: github) + def self.github(name, github, branch = nil, comment = nil) + if branch + new(name, nil, comment, github: github, branch: branch) + else + new(name, nil, comment, github: github) + end end def self.version(name, version, comment = nil) @@ -196,9 +200,15 @@ module Rails def rails_gemfile_entry if options.dev? - [GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH)] + [ + GemfileEntry.path('rails', Rails::Generators::RAILS_DEV_PATH), + GemfileEntry.github('arel', 'rails/arel') + ] elsif options.edge? - [GemfileEntry.github('rails', 'rails/rails')] + [ + GemfileEntry.github('rails', 'rails/rails'), + GemfileEntry.github('arel', 'rails/arel') + ] else [GemfileEntry.version('rails', Rails::VERSION::STRING, @@ -237,13 +247,8 @@ module Rails return [] if options[:skip_sprockets] gems = [] - if options.dev? || options.edge? - gems << GemfileEntry.github('sass-rails', 'rails/sass-rails', - 'Use SCSS for stylesheets') - else - gems << GemfileEntry.version('sass-rails', '~> 4.0', + gems << GemfileEntry.version('sass-rails', '~> 5.0', 'Use SCSS for stylesheets') - end gems << GemfileEntry.version('uglifier', '>= 1.3.0', @@ -265,7 +270,7 @@ module Rails def console_gemfile_entry comment = 'Use Rails Console on the Browser' if options.dev? || options.edge? - GemfileEntry.github 'web-console', 'rails/web-console', comment + GemfileEntry.github 'web-console', 'rails/web-console', nil, comment else [] end @@ -274,7 +279,7 @@ module Rails def coffee_gemfile_entry comment = 'Use CoffeeScript for .coffee assets and views' if options.dev? || options.edge? - GemfileEntry.github 'coffee-rails', 'rails/coffee-rails', comment + GemfileEntry.github 'coffee-rails', 'rails/coffee-rails', nil, comment else GemfileEntry.version 'coffee-rails', '~> 4.1.0', comment end |