Commit Graph

194 Commits

Author SHA1 Message Date
Rafael Mendonça França
9834be6565
Start Rails 6.1 development 2019-04-24 15:57:14 -04:00
Ryuta Kamizono
b89a3e7e63 Tweaks CHANGELOGs and docs [ci skip]
* add leading `#` before `=>` since hash rocket is valid Ruby code
* add backticks
* remove trailing spaces
* and more
2019-03-31 08:38:37 +09:00
Ryuta Kamizono
406d3a926c
Merge pull request #35794 from kamipo/type_cast_symbol_false
Type cast falsy boolean symbols on boolean attribute as false
2019-03-30 05:07:07 +09:00
Ryuta Kamizono
2d12f800f1 Type cast falsy boolean symbols on boolean attribute as false
Before 34cc301, type casting by boolean attribute when querying is a
no-op, so finding by truthy boolean string (i.e.
`where(value: "true") # => value = 'true'`) didn't work as expected
(matches it to FALSE in MySQL #32624). By type casting is ensured, a
value on boolean attribute is always serialized to TRUE or FALSE.

In PostgreSQL, `where(value: :false) # => value = 'false'` was a valid
SQL, so 34cc301 is a regresson for PostgreSQL since all symbol values
are serialized as TRUE.

I'd say using `:false` is mostly a developer's mistake (user's input
basically comes as a string), but `:false` on boolean attribute is
serialized as TRUE is not a desirable behavior for anybody.

This allows falsy boolean symbols as false, i.e.
`klass.create(value: :false).value? # => false` and
`where(value: :false) # => value = FALSE`.

Fixes #35676.
2019-03-30 04:18:25 +09:00
Prathamesh Sonpatki
d8ba2f7c56
Rename i18n_full_message config option to i18n_customize_full_message
- I feel `i18n_customize_full_messages` explains the meaning of the
  config better.
- Followup of https://github.com/rails/rails/pull/32956
2019-03-29 21:38:48 +05:30
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
Sharang Dashputre
5289a0b6b9 Edit a changelog entry [ci skip] 2019-03-12 20:00:13 +05:30
Hugo Vacher
9ccc5e1042 Update Changelog with new locale fallback behavior on validation 2019-03-11 15:55:16 -04:00
eileencodes
7c87fd5635 Prep release
* Update RAILS_VERSION
* Bundle
* rake update_versions
* rake changelog:header
2019-03-11 11:58:15 -04:00
Rafael Mendonça França
5e6e505083
Preparing for 6.0.0.beta2 release 2019-02-25 17:45:04 -05:00
Ryuta Kamizono
4ea067017a Merge pull request #29651 from Sayanc93/return-correct-date
Return correct date in ActiveModel for time to date conversions
2019-02-18 16:04:47 +09:00
Andrew White
ccdedeb9d5
Fix year value when casting a multiparameter time hash
When assigning a hash to a time attribute that's missing a year
component (e.g. a `time_select` with `:ignore_date` set to `true`)
then the year defaults to 1970 instead of the expected 2000. This
results in the attribute changing as a result of the save.

Before:

    event = Event.new(start_time: { 4 => 20, 5 => 30 })
    event.start_time # => 1970-01-01 20:30:00 UTC
    event.save
    event.reload
    event.start_time # => 2000-01-01 20:30:00 UTC

After:

    event = Event.new(start_time: { 4 => 20, 5 => 30 })
    event.start_time # => 2000-01-01 20:30:00 UTC
    event.save
    event.reload
    event.start_time # => 2000-01-01 20:30:00 UTC
2019-01-21 09:23:12 +00:00
Rafael Mendonça França
5a0230c67f
Preparing for 6.0.0.beta1 release 2019-01-18 15:42:12 -05:00
bogdanvlviv
d5c26c43c0
Add ActiveModel::Errors#of_kind?
Related to https://github.com/rails/rails/pull/34817#issuecomment-451508668
2019-01-04 20:47:31 +02:00
Kasper Timm Hansen
1b7c3222e8
Require Ruby 2.5 for Rails 6.
Generally followed the pattern for https://github.com/rails/rails/pull/32034

* Removes needless CI configs for 2.4
* Targets 2.5 in rubocop
* Updates existing CHANGELOG entries for fewer merge conflicts
* Removes Hash#slice extension as that's inlined on Ruby 2.5.
* Removes the need for send on define_method in MethodCallAssertions.
2018-12-19 21:47:50 +01:00
Gannon McGibbon
d126c0d6c0 Fix numericality equality validation on floats 2018-12-12 12:02:12 -05:00
Daniel Lopez Prat
ee2b84f3cb
Add slice! method to ActiveModel::Errors 2018-11-21 08:56:19 +09:00
Ryuta Kamizono
736edb9828 Formatting CHANGELOGs [ci skip]
Fixing code block rendering, indentation, backticks, etc.
2018-09-07 07:59:19 +09:00
Ryuta Kamizono
47a6d788dd Fix numericality validator to still use value before type cast except Active Record
The purpose of fe9547b is to work type casting to value from database.

But that was caused not to use the value before type cast even except
Active Record.

There we never guarantees that the value before type cast was going to
the used in this validation, but we should not change the behavior
unless there is some particular reason.

To restore original behavior, still use the value before type cast if
`came_from_user?` is undefined (i.e. except Active Record).

Fixes #33651.
Fixes #33686.
2018-08-24 00:44:02 +09:00
bogdanvlviv
159dc60bee
Add changelog entry for #31503 [ci skip]
Related to #31503
2018-08-12 15:38:47 +03:00
bogdanvlviv
e62e68e25b
has_secure_password: use recovery_password instead of activation_token
Since we have `has_secure_token`, it is too confusing to use `_token`
suffix with `has_secure_password`.
Context https://github.com/rails/rails/pull/33307#discussion_r200807185
2018-07-08 14:12:27 +03:00
Rafael Mendonça França
08dde0f355
Merge pull request #26764 from choncou/improve_has_secure_password
Allow configurable attribute name on `#has_secure_password`
2018-06-28 13:01:21 +02:00
bogdanvlviv
f009e553ce
Add changelog for #32956 [ci skip]
Add mention about default value of `config.active_model.i18n_full_message`.
2018-06-12 01:39:32 +03:00
Rafael Mendonça França
ba0ae542ca
Remove changelog header for unreleased version
We only add the header when releasing to avoid some conflicts.

[ci skip]
2018-03-13 15:20:57 -04:00
Ryuta Kamizono
9dbc475454 Remove CHANGELOG entries which were backported to 5-2-stable 2018-02-28 20:46:17 +09:00
Ryuta Kamizono
0605f45ab3 Merge pull request #28270 from mmangino/dont_ignore_seralization_options
Don't accidentally lose includes in serialization
2018-02-27 23:42:15 +09:00
Jeremy Daer
d4eb0dc89e Rails 6 requires Ruby 2.4.1+
Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug.

References #32028
2018-02-17 15:34:57 -08:00
Rafael Mendonça França
1c383df324 Start Rails 6.0 development!!!
🎉🎉🎉
2018-01-30 18:51:17 -05:00
Sean Griffin
0af36c62a5 Allow attributes with a proc default to be marshalled
We don't implement much custom marshalling logic for these objects, but
the proc default case needs to be handled separately. Unfortunately
there's no way to just say "do what you would have done but with this
value for one ivar", so we have to manually implement `marshal_load` as
well.

The test case is a little bit funky, but I'd really like an equality
test in there, and there's no easy way to add one now that this is out
of AR (since the `attributes` method isn't here)

Fixes #31216
2018-01-23 14:12:13 -07:00
Yoshiyuki Hirano
470d0e459f Fix validation callbacks on multiple context
I found a bug that validation callbacks don't fire on multiple context.
So I've fixed it.

Example:

```ruby
class Dog
  include ActiveModel::Validations
  include ActiveModel::Validations::Callbacks

  attr_accessor :history

  def initialize
    @history = []
  end

  before_validation :set_before_validation_on_a, on: :a
  before_validation :set_before_validation_on_b, on: :b
  after_validation :set_after_validation_on_a, on: :a
  after_validation :set_after_validation_on_b, on: :b

  def set_before_validation_on_a; history << "before_validation on a"; end
  def set_before_validation_on_b; history << "before_validation on b"; end
  def set_after_validation_on_a;  history << "after_validation on a" ; end
  def set_after_validation_on_b;  history << "after_validation on b" ; end
end
```

Before:

```
d = Dog.new
d.valid?([:a, :b])
d.history # []
```

After:

```
d = Dog.new
d.valid?([:a, :b])
d.history # ["before_validation on a", "before_validation on b", "after_validation on a", "after_validation on b"]
```
2017-12-20 00:27:19 +09:00
Sayan Chakraborty
eb73dfc067 Return correct date in ActiveModel for time to date conversions
time.to_date conversion happens considering leap years
so a conversion of "Day.new({'day(1i)'=>'1', 'day(2i)'=>'1', 'day(3i)'=>'1'})" results in saving the date as Mon, 03 Jan 0001
which might seem weird on the user level, hence falling back to parsing on string level resolves this data mismatch
Fixes #28521
2017-12-17 23:56:16 +05:30
Rafael Mendonça França
2837d0f334
Preparing for 5.2.0.beta2 release 2017-11-28 14:41:02 -05:00
Rafael Mendonça França
cceeeb6e57
Preparing for 5.2.0.beta1 release 2017-11-27 14:50:03 -05:00
bogdanvlviv
7308991630
Execute ConfirmationValidator validation when _confirmation's value is false 2017-11-05 19:24:49 +00:00
Matt Rohrer
b8b089ef11
Allow passing a Proc or Symbol as an argument to length validator values
This brings the Length validator in line with the Numericality
validator, which currently supports Proc & Symbol arguments
2017-10-26 10:01:06 +02:00
Jahfer Husain
3650ca983c Add ActiveModel::Errors#merge!
ActiveModel::Errors#merge! allows ActiveModel::Errors to append errors from
a separate ActiveModel::Errors instance onto their own.

Example:

    person = Person.new
    person.errors.add(:name, :blank)

    errors = ActiveModel::Errors.new(Person.new)
    errors.add(:name, :invalid)

    person.errors.merge!(errors)
    puts person.errors.messages
    # => { name: ["can't be blank", "is invalid"] }
2017-07-07 14:32:59 -04:00
Ryuta Kamizono
9fdebb17ff ✂️
[ci skip]
2017-06-28 22:21:03 +09:00
Bradley Priest
d83b8e6510 Fix regression in Numericality validator where extra decimal places on
a user input for a decimal column were ignored by numerically validations
2017-05-27 21:58:35 +08:00
Ryuta Kamizono
89389428b5 Cleanup CHANGELOGs [ci skip]
* Remove trailing spaces.
* Add backticks around method and command.
* Fix indentation.
2017-04-30 02:41:44 +09:00
Jon Moss
a02fb802e9 Remove CHANGELOG.md entry that appears in 5-1-stable
This CHANGELOG.md is a continuation of the 5-1-stable one, there
shouldn't be any duplicate entries.

[ci skip]
2017-03-29 08:38:01 -04:00
bogdanvlviv
01269aede3 Fix ActiveModel::Errors #keys, #values
Before:
  person.errors.keys    # => []
  person.errors.values  # => []
  person.errors[:name]  # => []
  person.errors.keys    # => [:name]
  person.errors.values  # => [[]]

After:
  person.errors.keys   # => []
  person.errors.values # => []
  person.errors[:name] # => []
  person.errors.keys   # => []
  person.errors.values # => []

Related to #23468
2017-03-28 18:48:56 +03:00
Rafael Mendonça França
9426bd7a19
Merge pull request #28050 from namusyaka/avoid-converting-int-into-float
Avoid converting integer as a string into float
2017-03-27 18:23:56 -04:00
Matthew Draper
6c08d480f1 Start Rails 5.2 development 2017-03-22 10:11:39 +10:30
Mike Mangino
1bb0605dfe Don't accidentally lose includes in serialization 2017-03-03 15:02:35 -05:00
Rafael Mendonça França
f4acdd83ff
Preparing for 5.1.0.beta1 release 2017-02-23 14:53:21 -05:00
namusyaka
b0be7792ad
Avoid converting integer as a string into float 2017-02-18 19:04:48 +09:00
Rafael Mendonça França
3a25cdca3e
Remove deprecated behavior that halts callbacks when the return is false 2017-02-07 12:19:37 -03:00
yuuji.yaginuma
4f8d86c822 Remove ActiveModel::TestCase from lib
`ActiveModel::TestCase` is used only for the test of Active Model.
Also, it is a private API and can not be used in applications.
Therefore, it is not necessary to include it in lib.
2017-02-07 07:46:52 +09:00
Sean Griffin
ef76f83f4c Merge pull request #26696 from iainbeeston/only-ruby-types-in-activemodel
Moved database-specific ActiveModel types into ActiveRecord
2016-12-08 13:45:47 -05:00
Kenichi Kamiya
9f566aba32 Allow indifferent access in ActiveModel::Errors
`#[]` has already applied indifferent access, but some methods does not.

  `#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
2016-11-22 04:10:41 +09:00