From f7a986012a6099445e20b6414d253ee0fc039118 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Wed, 27 Apr 2016 15:47:22 -0500 Subject: Prep Rails 5 beta 4 --- activemodel/CHANGELOG.md | 2 ++ activemodel/lib/active_model/gem_version.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 7be8b2e522..a35e20579d 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,3 +1,5 @@ +## Rails 5.0.0.beta4 (April 27, 2016) ## + * Allow passing record being validated to the message proc to generate customized error messages for that object using I18n helper. diff --git a/activemodel/lib/active_model/gem_version.rb b/activemodel/lib/active_model/gem_version.rb index 62862aa4e9..514c3ba4a8 100644 --- a/activemodel/lib/active_model/gem_version.rb +++ b/activemodel/lib/active_model/gem_version.rb @@ -8,7 +8,7 @@ module ActiveModel MAJOR = 5 MINOR = 0 TINY = 0 - PRE = "beta3" + PRE = "beta4" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From 517cf249c369d4bca40b1f590ca641d8b717985e Mon Sep 17 00:00:00 2001 From: lvl0nax Date: Thu, 28 Apr 2016 15:18:51 +0300 Subject: Chomp: prefer String#chomp where we can for a clarity boost Closes #24766, #24767 Signed-off-by: Jeremy Daer --- activemodel/lib/active_model/validations/acceptance.rb | 6 +----- activemodel/lib/active_model/validator.rb | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index c5c0cd4636..a04e5f347e 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -64,11 +64,7 @@ module ActiveModel private def convert_to_reader_name(method_name) - attr_name = method_name.to_s - if attr_name.end_with?("=") - attr_name = attr_name[0..-2] - end - attr_name + method_name.to_s.chomp('=') end end end diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 109bf038b0..699f74ed17 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -100,7 +100,7 @@ module ActiveModel # PresenceValidator.kind # => :presence # UniquenessValidator.kind # => :uniqueness def self.kind - @kind ||= name.split('::').last.underscore.sub(/_validator$/, '').to_sym unless anonymous? + @kind ||= name.split('::').last.underscore.chomp('_validator').to_sym unless anonymous? end # Accepts options that will be made available through the +options+ reader. -- cgit v1.2.3 From 707b5c00abf98f1a383b96ad34313ff82d40758d Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 1 May 2016 13:41:57 -0500 Subject: Active Model: Messages for strict validation always convert attributes to human readable form [ci skip] --- activemodel/lib/active_model/errors.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index d106f65fa2..87db8e2e19 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -310,9 +310,9 @@ module ActiveModel # :strict option can also be set to any other exception. # # person.errors.add(:name, :invalid, strict: true) - # # => ActiveModel::StrictValidationFailed: name is invalid + # # => ActiveModel::StrictValidationFailed: Name is invalid # person.errors.add(:name, :invalid, strict: NameIsInvalid) - # # => NameIsInvalid: name is invalid + # # => NameIsInvalid: Name is invalid # # person.errors.messages # => {} # -- cgit v1.2.3 From 4dd7a9d4a5b69bad7ff24b63f5fb8ae20eadc74c Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 2 May 2016 02:39:07 +0530 Subject: Followup of #18322 Mirror the documented new behavior of including details, when performing errors test. --- activemodel/test/cases/errors_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 26ba6ba4fb..fbf208836f 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -11,7 +11,7 @@ class ErrorsTest < ActiveModel::TestCase attr_reader :errors def validate! - errors.add(:name, "cannot be nil") if name == nil + errors.add(:name, :blank, message: "cannot be nil") if name == nil end def read_attribute_for_validation(attr) -- cgit v1.2.3 From 25f829e43fbae0c29a3f2e54f5f0c7ebd7c9b46e Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 2 May 2016 03:08:59 +0530 Subject: Add example for UnknownAttributeError [ci skip] --- activemodel/lib/active_model/errors.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 87db8e2e19..c0f1bb084a 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -527,6 +527,15 @@ module ActiveModel end # Raised when unknown attributes are supplied via mass assignment. + # + # class Person + # include ActiveModel::AttributeAssignment + # include ActiveModel::Validations + # end + # + # person = Person.new + # person.assign_attributes(name: 'Gorby') + # # => ActiveModel::UnknownAttributeError: unknown attribute 'name' for Person. class UnknownAttributeError < NoMethodError attr_reader :record, :attribute -- cgit v1.2.3 From 17141481d99f1ae6d229cd5330b249f101abd116 Mon Sep 17 00:00:00 2001 From: Christian Blais Date: Tue, 3 May 2016 14:37:11 -0400 Subject: Change RangeError to a more specific ActiveModel::RangeError The should make it easier for apps to rescue ActiveModel specific errors without the need to wrap all method calls with a generic rescue RangeError. --- activemodel/lib/active_model.rb | 1 + activemodel/lib/active_model/errors.rb | 4 ++++ activemodel/lib/active_model/type/integer.rb | 2 +- activemodel/test/cases/type/integer_test.rb | 12 ++++++------ 4 files changed, 12 insertions(+), 7 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb index b95c174d6e..7de259a60d 100644 --- a/activemodel/lib/active_model.rb +++ b/activemodel/lib/active_model.rb @@ -49,6 +49,7 @@ module ActiveModel eager_autoload do autoload :Errors + autoload :RangeError, 'active_model/errors' autoload :StrictValidationFailed, 'active_model/errors' autoload :UnknownAttributeError, 'active_model/errors' end diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index d106f65fa2..685e235730 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -526,6 +526,10 @@ module ActiveModel class StrictValidationFailed < StandardError end + # Raised when attribute values are out of range. + class RangeError < ::RangeError + end + # Raised when unknown attributes are supplied via mass assignment. class UnknownAttributeError < NoMethodError attr_reader :record, :attribute diff --git a/activemodel/lib/active_model/type/integer.rb b/activemodel/lib/active_model/type/integer.rb index 2f73ede009..eea2280b22 100644 --- a/activemodel/lib/active_model/type/integer.rb +++ b/activemodel/lib/active_model/type/integer.rb @@ -46,7 +46,7 @@ module ActiveModel def ensure_in_range(value) unless range.cover?(value) - raise RangeError, "#{value} is out of range for #{self.class} with limit #{_limit}" + raise ActiveModel::RangeError, "#{value} is out of range for #{self.class} with limit #{_limit}" end end diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb index dac922db42..6603f25c9a 100644 --- a/activemodel/test/cases/type/integer_test.rb +++ b/activemodel/test/cases/type/integer_test.rb @@ -53,25 +53,25 @@ module ActiveModel end test "values below int min value are out of range" do - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do Integer.new.serialize(-2147483649) end end test "values above int max value are out of range" do - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do Integer.new.serialize(2147483648) end end test "very small numbers are out of range" do - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do Integer.new.serialize(-9999999999999999999999999999999) end end test "very large numbers are out of range" do - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do Integer.new.serialize(9999999999999999999999999999999) end end @@ -96,10 +96,10 @@ module ActiveModel assert_equal(9223372036854775807, type.serialize(9223372036854775807)) assert_equal(-9223372036854775808, type.serialize(-9223372036854775808)) - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do type.serialize(-9999999999999999999999999999999) end - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do type.serialize(9999999999999999999999999999999) end end -- cgit v1.2.3 From ab44e366246960e52fb03836d62ea0015f5cf0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 3 May 2016 17:21:05 -0500 Subject: Check for the right exception --- activemodel/test/cases/type/unsigned_integer_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/test/cases/type/unsigned_integer_test.rb b/activemodel/test/cases/type/unsigned_integer_test.rb index 16301b3ac0..026cb08a06 100644 --- a/activemodel/test/cases/type/unsigned_integer_test.rb +++ b/activemodel/test/cases/type/unsigned_integer_test.rb @@ -9,7 +9,7 @@ module ActiveModel end test "minus value is out of range" do - assert_raises(::RangeError) do + assert_raises(ActiveModel::RangeError) do UnsignedInteger.new.serialize(-1) end end -- cgit v1.2.3 From f7d7147ae6b40ab06750e58c2edcc1c8046f90cb Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 30 Apr 2016 08:18:48 -0400 Subject: Active Model: Improve CHANGELOG and documentation for `validates_acceptance_of` [ci skip] - Improve CHANGELOG entry for #18439. - The documentation is updated as per changes in PR #18439 to the `accept` option. - The explanation about the virtual attribute is moved at the end so that the arity of `accept` option is explained first. - Added a note that `message` can also be passed to `validates_acceptance_of`. --- activemodel/CHANGELOG.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'activemodel') diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index a35e20579d..d221eff1e7 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -123,11 +123,13 @@ *Wojciech Wnętrzak* -* Change validates_acceptance_of to accept true by default. +* Change `validates_acceptance_of` to accept `true` by default besides `'1'`. - The default for validates_acceptance_of is now "1" and true. - In the past, only "1" was the default and you were required to add - accept: true. + The default for `validates_acceptance_of` is now `'1'` and `true`. + In the past, only `"1"` was the default and you were required to pass + `accept: true` separately. + + *mokhan* * Remove deprecated `ActiveModel::Dirty#reset_#{attribute}` and `ActiveModel::Dirty#reset_changes`. -- cgit v1.2.3 From fbdcf5221ad7ea3d40ad09651962fc85d101dd67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 6 May 2016 16:54:40 -0500 Subject: Preparing for 5.0.0.rc1 release --- activemodel/CHANGELOG.md | 5 +++++ activemodel/lib/active_model/gem_version.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index d221eff1e7..a1220ba4c5 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,3 +1,8 @@ +## Rails 5.0.0.rc1 (May 06, 2016) ## + +* No changes. + + ## Rails 5.0.0.beta4 (April 27, 2016) ## * Allow passing record being validated to the message proc to generate diff --git a/activemodel/lib/active_model/gem_version.rb b/activemodel/lib/active_model/gem_version.rb index 514c3ba4a8..d1a9a3bec9 100644 --- a/activemodel/lib/active_model/gem_version.rb +++ b/activemodel/lib/active_model/gem_version.rb @@ -8,7 +8,7 @@ module ActiveModel MAJOR = 5 MINOR = 0 TINY = 0 - PRE = "beta4" + PRE = "rc1" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From 8ecc5ab1d88532a239f17c7520ed922c7579b01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 10 May 2016 01:07:09 -0300 Subject: Start Rails 5.1 development :tada: --- activemodel/CHANGELOG.md | 156 +--------------------------- activemodel/lib/active_model/gem_version.rb | 4 +- 2 files changed, 3 insertions(+), 157 deletions(-) (limited to 'activemodel') diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index a1220ba4c5..206699c036 100644 --- a/activemodel/CHANGELOG.md +++ b/activemodel/CHANGELOG.md @@ -1,156 +1,2 @@ -## Rails 5.0.0.rc1 (May 06, 2016) ## -* No changes. - - -## Rails 5.0.0.beta4 (April 27, 2016) ## - -* Allow passing record being validated to the message proc to generate - customized error messages for that object using I18n helper. - - *Prathamesh Sonpatki* - -## Rails 5.0.0.beta3 (February 24, 2016) ## - -* No changes. - - -## Rails 5.0.0.beta2 (February 01, 2016) ## - -* No changes. - - -## Rails 5.0.0.beta1 (December 18, 2015) ## - -* Validate multiple contexts on `valid?` and `invalid?` at once. - - Example: - - class Person - include ActiveModel::Validations - - attr_reader :name, :title - validates_presence_of :name, on: :create - validates_presence_of :title, on: :update - end - - person = Person.new - person.valid?([:create, :update]) # => false - person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]} - - *Dmitry Polushkin* - -* Add case_sensitive option for confirmation validator in models. - - *Akshat Sharma* - -* Ensure `method_missing` is called for methods passed to - `ActiveModel::Serialization#serializable_hash` that don't exist. - - *Jay Elaraj* - -* Remove `ActiveModel::Serializers::Xml` from core. - - *Zachary Scott* - -* Add `ActiveModel::Dirty#[attr_name]_previously_changed?` and - `ActiveModel::Dirty#[attr_name]_previous_change` to improve access - to recorded changes after the model has been saved. - - It makes the dirty-attributes query methods consistent before and after - saving. - - *Fernando Tapia Rico* - -* Deprecate the `:tokenizer` option for `validates_length_of`, in favor of - plain Ruby. - - *Sean Griffin* - -* Deprecate `ActiveModel::Errors#add_on_empty` and `ActiveModel::Errors#add_on_blank` - with no replacement. - - *Wojciech Wnętrzak* - -* Deprecate `ActiveModel::Errors#get`, `ActiveModel::Errors#set` and - `ActiveModel::Errors#[]=` methods that have inconsistent behavior. - - *Wojciech Wnętrzak* - -* Allow symbol as values for `tokenize` of `LengthValidator`. - - *Kensuke Naito* - -* Assigning an unknown attribute key to an `ActiveModel` instance during initialization - will now raise `ActiveModel::AttributeAssignment::UnknownAttributeError` instead of - `NoMethodError`. - - Example: - - User.new(foo: 'some value') - # => ActiveModel::AttributeAssignment::UnknownAttributeError: unknown attribute 'foo' for User. - - *Eugene Gilburg* - -* Extracted `ActiveRecord::AttributeAssignment` to `ActiveModel::AttributeAssignment` - allowing to use it for any object as an includable module. - - Example: - - class Cat - include ActiveModel::AttributeAssignment - attr_accessor :name, :status - end - - cat = Cat.new - cat.assign_attributes(name: "Gorby", status: "yawning") - cat.name # => 'Gorby' - cat.status # => 'yawning' - cat.assign_attributes(status: "sleeping") - cat.name # => 'Gorby' - cat.status # => 'sleeping' - - *Bogdan Gusiev* - -* Add `ActiveModel::Errors#details` - - To be able to return type of used validator, one can now call `details` - on errors instance. - - Example: - - class User < ActiveRecord::Base - validates :name, presence: true - end - - user = User.new; user.valid?; user.errors.details - => {name: [{error: :blank}]} - - *Wojciech Wnętrzak* - -* Change `validates_acceptance_of` to accept `true` by default besides `'1'`. - - The default for `validates_acceptance_of` is now `'1'` and `true`. - In the past, only `"1"` was the default and you were required to pass - `accept: true` separately. - - *mokhan* - -* Remove deprecated `ActiveModel::Dirty#reset_#{attribute}` and - `ActiveModel::Dirty#reset_changes`. - - *Rafael Mendonça França* - -* Change the way in which callback chains can be halted. - - The preferred method to halt a callback chain from now on is to explicitly - `throw(:abort)`. - In the past, returning `false` in an Active Model `before_` callback had - the side effect of halting the callback chain. - This is not recommended anymore and, depending on the value of the - `ActiveSupport.halt_callback_chains_on_return_false` option, will - either not work at all or display a deprecation warning. - - *claudiob* - -Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activemodel/CHANGELOG.md) for previous changes. +Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activemodel/CHANGELOG.md) for previous changes. diff --git a/activemodel/lib/active_model/gem_version.rb b/activemodel/lib/active_model/gem_version.rb index d1a9a3bec9..4a8ee915cf 100644 --- a/activemodel/lib/active_model/gem_version.rb +++ b/activemodel/lib/active_model/gem_version.rb @@ -6,9 +6,9 @@ module ActiveModel module VERSION MAJOR = 5 - MINOR = 0 + MINOR = 1 TINY = 0 - PRE = "rc1" + PRE = "alpha" STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") end -- cgit v1.2.3 From 75c221f10ff94f8f91f9b0664f0f41c053d47c51 Mon Sep 17 00:00:00 2001 From: Mohit Natoo Date: Thu, 19 May 2016 02:02:30 +0530 Subject: - removing redundant 'happens' in documentation [ci skip] --- activemodel/lib/active_model/validations/callbacks.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/validations/callbacks.rb b/activemodel/lib/active_model/validations/callbacks.rb index 52111e5442..a201f72ed0 100644 --- a/activemodel/lib/active_model/validations/callbacks.rb +++ b/activemodel/lib/active_model/validations/callbacks.rb @@ -29,8 +29,7 @@ module ActiveModel end module ClassMethods - # Defines a callback that will get called right before validation - # happens. + # Defines a callback that will get called right before validation. # # class Person # include ActiveModel::Validations @@ -65,8 +64,7 @@ module ActiveModel set_callback(:validation, :before, *args, &block) end - # Defines a callback that will get called right after validation - # happens. + # Defines a callback that will get called right after validation. # # class Person # include ActiveModel::Validations -- cgit v1.2.3 From 89e2f7e722e06f900bdb1c14db33073c90d7cdea Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Tue, 17 May 2016 07:56:08 -0700 Subject: Support for unified Integer class in Ruby 2.4+ Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer. --- activemodel/lib/active_model/validations/numericality.rb | 2 +- activemodel/test/cases/validations/length_validation_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index ad7012df48..9a0a0655de 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -120,7 +120,7 @@ module ActiveModel # * :only_integer - Specifies whether the value has to be an # integer, e.g. an integral value (default is +false+). # * :allow_nil - Skip validation if attribute is +nil+ (default is - # +false+). Notice that for fixnum and float columns empty strings are + # +false+). Notice that for Integer and Float columns empty strings are # converted to +nil+. # * :greater_than - Specifies the value must be greater than the # supplied value. diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index ee901b75fb..11dce1df20 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -355,7 +355,7 @@ class LengthValidationTest < ActiveModel::TestCase assert_equal ["Your essay must be at least 5 words."], t.errors[:content] end - def test_validates_length_of_for_fixnum + def test_validates_length_of_for_integer Topic.validates_length_of(:approved, is: 4) t = Topic.new("title" => "uhohuhoh", "content" => "whatever", approved: 1) -- cgit v1.2.3 From d12209cad2d8961f396a6e7cbd0ee9437b9751ef Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Mon, 23 May 2016 17:05:44 -0400 Subject: Remove package:clean task MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced in d6f2000a67cc63aa67414c75ce77de671824ec52 and was only used by Action Cable. Now handled by Action Cable’s assets:compile task. --- activemodel/Rakefile | 1 - 1 file changed, 1 deletion(-) (limited to 'activemodel') diff --git a/activemodel/Rakefile b/activemodel/Rakefile index 9982d49bcb..036815a987 100644 --- a/activemodel/Rakefile +++ b/activemodel/Rakefile @@ -5,7 +5,6 @@ dir = File.dirname(__FILE__) task :default => :test task :package -task "package:clean" Rake::TestTask.new do |t| t.libs << "test" -- cgit v1.2.3