Commit Graph

1803 Commits

Author SHA1 Message Date
Rafael França
a215642828 Merge pull request #25364 from kamipo/fix_serialize_for_date_type
Fix `Type::Date#serialize` to return a date object correctly
2016-06-28 23:33:31 -03:00
Robin Dupret
eb1c0e2283 Tiny documentation fixes [ci skip]
Fix a tiny typo and vertical-align some return results in the
ActiveModel::Errors documentation.
2016-06-25 16:10:04 +02:00
Alex Kitchens
8305a09c5e [ci skip] Add additional documentation to ActiveModel::Errors 2016-06-22 15:45:11 -05:00
Rafael França
1a4474c2c7 Merge pull request #25415 from maclover7/jm-fix-25410
Add test to better demonstrate `ActiveModel::Errors#added?` behavior
2016-06-21 16:47:44 -03:00
Jon Moss
87e8719da3
Add test to better demonstrate ActiveModel::Errors#added? behavior
Fixes #25410.
2016-06-21 11:18:02 -04:00
Alex Kitchens
92e8ede6df [ci skip] Remove duplicate alias documentation in ActiveModel::Validations 2016-06-16 09:15:44 -05:00
Ryuta Kamizono
10b81fb51a Fix Type::Date#serialize to return a date object correctly
Currently `Type::Date#serialize` does not cast a value to a date object.
It should be cast to a date object for finding by date column correctly
working.

Fixes #25354.
2016-06-16 08:04:16 +09:00
Jon Moss
b351061b83
Remove unused require and unused model stub
- The `Project` model should have been removed in 468939297db91f8e595a93c94a16e23b26eee61a.
- The superfluous require was added in 605c6455ac722ed9679e17458a47cc649cdedab0.

Closes #25215

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-05-31 11:30:23 -07:00
Sean Griffin
b3dfd7d16c Ensure that instances of ActiveModel::Errors can be marshalled
We now use default procs inside of the errors object, which gets
included by default when marshaling anything that includes
`ActiveModel::Validations`. This means that Active Record objects cannot
be marshalled. We strip and apply the default proc ourselves. This will
ensure the objects are YAML serializable as well, since YAML falls back
to marshal implementations now. This is less important, however, as the
errors aren't included when dumping Active Record objects.

This commit does not include a changelog entry, as 5.0 is still in RC
status at the time of writing, and 5.0.0 will not release with the bug
this fixes.

Fixes #25165
2016-05-30 14:04:29 -04:00
Javan Makhmali
d12209cad2 Remove package:clean task
Introduced in d6f2000a67cc63aa67414c75ce77de671824ec52 and was only used by Action Cable. Now handled by Action Cable’s assets:compile task.
2016-05-24 13:11:28 -04:00
Jeremy Daer
89e2f7e722
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.
2016-05-18 21:58:51 -07:00
Mohit Natoo
75c221f10f - removing redundant 'happens' in documentation [ci skip] 2016-05-19 02:02:30 +05:30
Vijay Dev
83ecf3fe56 Merge branch 'master' of github.com:rails/docrails
Conflicts:
	guides/source/configuring.md
2016-05-14 09:54:23 +00:00
Rafael Mendonça França
8ecc5ab1d8 Start Rails 5.1 development 🎉 2016-05-10 03:46:56 -03:00
Rafael Mendonça França
fbdcf5221a Preparing for 5.0.0.rc1 release 2016-05-06 16:54:40 -05:00
Rafael França
1949412a86 Merge pull request #24799 from prathamesh-sonpatki/18439-followup
Active Model: Improve CHANGELOG and documentation for `validates_acceptance_of` [ci skip]
2016-05-05 16:29:20 -05:00
Prathamesh Sonpatki
f7d7147ae6
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`.
2016-05-05 16:25:47 -05:00
Rafael França
9c86a1804d Merge pull request #24806 from vipulnsward/errors-details-test
Followup of #18322
2016-05-05 16:23:52 -05:00
Rafael Mendonça França
ab44e36624 Check for the right exception 2016-05-03 17:21:05 -05:00
Christian Blais
17141481d9 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.
2016-05-03 14:46:49 -04:00
Vipul A M
25f829e43f Add example for UnknownAttributeError
[ci skip]
2016-05-02 03:08:59 +05:30
Vipul A M
4dd7a9d4a5 Followup of #18322
Mirror the documented new behavior of including details, when performing errors test.
2016-05-02 02:39:07 +05:30
Prathamesh Sonpatki
707b5c00ab
Active Model: Messages for strict validation always convert attributes to human readable form [ci skip] 2016-05-01 13:41:57 -05:00
lvl0nax
517cf249c3
Chomp: prefer String#chomp where we can for a clarity boost
Closes #24766, #24767

Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
2016-04-29 13:43:15 -07:00
eileencodes
f7a986012a Prep Rails 5 beta 4 2016-04-27 15:48:47 -05:00
Mohit Natoo
51d6a59329 - [ci skip] regardless is usually followed by of and not by if .. or not. 2016-04-21 00:04:05 +05:30
Bogdan Gusiev
80b9e5d7bd Fixed bug introduced in #24519. Makes build green again 2016-04-13 21:13:33 +03:00
Bogdan Gusiev
afb1f32e79 Use keyword arguments to cleanup without droping performance 2016-04-13 02:03:51 +03:00
Sen-Zhang
051d859880 prevent 'attribute_changed?' from returning nil 2016-04-11 19:33:52 -07:00
Jeremy Daer
20ffb63c2e Merge pull request #24511 from lihanli/activemodel-dirty-attribute-changed
speed up ActiveModel::Dirty#attribute_changed?
2016-04-11 15:14:44 -07:00
Lihan Li
73e2dbe651 set default parameter to nil to speed up attribute_changed?
Benchmark results:

Warming up --------------------------------------
            old code    32.176k i/100ms
            new code    34.837k i/100ms
Calculating -------------------------------------
            old code      1.595M (± 3.5%) i/s -      7.947M
            new code      1.942M (± 3.9%) i/s -      9.685M
2016-04-11 17:46:34 -04:00
Vipul A M
ac027338e4 Pass over all Rails 5 warnings, to make sure:
- we are ending sentences properly
- fixing of space issues
- fixed continuity issues in some sentences.

Reverts 8fc97d198e .
This change reverts making sure we add '.' at end of deprecation sentences.
This is to keep sentences within Rails itself consistent and with a '.' at the end.
2016-04-12 02:26:56 +05:30
PareshGupta
57f5f51bd2 fix length validation error typo 2016-04-07 15:37:17 +05:30
Vipul A M
1f99bdb620 Add test case for interpolation with passing of data along with record attribute in error message, where a proc is passed. 2016-04-05 14:18:44 +05:30
Prathamesh Sonpatki
7bdb4b5598 Allow passing record being validated to error message generator
- Pass object to I18n helper so that when calling message proc, it will
  pass that object as argument to the proc and we can generate custom
  error messages based on current record being validated.
- Based on https://github.com/rails/rails/issues/856.

[Łukasz Bandzarewicz, Prathamesh Sonpatki]
2016-04-05 12:55:02 +05:30
Kasper Timm Hansen
044baef101 Merge pull request #24299 from kitop/activemodel-errors-include-fix
Do not create a hash key when calling ActiveModel::Errors#include?
2016-03-25 13:24:41 +01:00
Sean Griffin
c7d3bd48df Apply scale before precision when coercing floats to decimal
Since precision is always larger than scale, it can actually change
rounding behavior. Given a precision of 5 and a scale of 3, when you
apply the precision of 5 to `1.25047`, the result is `1.2505`, which
when the scale is applied would be `1.251` instead of the expected
`1.250`.

This issue appears to only occur with floats, as scale doesn't apply to
other numeric types, and the bigdecimal constructor actually ignores
precision entirely when working with strings. There's no way we could
handle this for the "unknown object which responds to `to_d`" case, as
we can't assume an interface for applying the scale.

Fixes #24235
2016-03-24 16:09:19 -06:00
Esteban Pastorino
9848c4632f Do not create a hash key when calling ActiveModel::Errors#include?
From: https://github.com/rails/rails/issues/24279

Problem:
By doing `record.errors.include? :foo`, it adds a new key to the
@messages hash that defaults to an empty array.

This happens because of a combination of these 2 commits:
b97035df64
(Added in Rails 4.1)
and
6ec8ba16d8 (diff-fdcf8b65b5fb954372c6fe1ddf284c78R76)
(Rails 5.0)

By adding the default proc that returns an array for non-existing keys,
ruby adds that key to the hash.

Solution:
Change `#include?` to check with `has_key?` and then check if that value is
`present?`.

Add test case for ActiveModels::Errors#include?
2016-03-24 16:29:22 -04:00
ojab
3ece0d89d4 Use Range#cover? for Date inclusion validator 2016-03-24 11:36:07 +00:00
ojab
01b8a23a7c Add edge cases to Time/Date/DateTime inclusion validation tests 2016-03-24 11:36:02 +00:00
Xavier Noria
1eb27fafa9 revises the homepage URL in the gemspecs [ci skip]
References https://github.com/rails/homepage/issues/46.
2016-03-10 07:55:27 +01:00
yuuji.yaginuma
163df5d6a0 use same name to type object
Follow up to #24079
2016-03-09 20:47:45 +09:00
Arthur Neves
2abcdfd978 Remove load_paths file 2016-02-27 13:03:57 -05:00
eileencodes
dbfa8fdfc2 Preparing for 5.0.0.beta3 release
Adds changelog headers for beta3 release
2016-02-24 11:14:40 -05:00
eileencodes
826420b5fc Prep release for Rails 5 beta3 2016-02-24 10:27:02 -05:00
eileencodes
2c02bc0a47 Revert changes to validations from PR #18612
In order to fix issue #17621 we added a check to validations that
determined if a record should be validated. Based on the existing tests
and behavior we wanted we determined the best way to do that was by
checking if `!record.peristed? || record.changed? || record.marked_for_destruction?`

This change didn't make it into a release until now. When #23790 was
opened we realized that `valid?` and `invalid?` were broken and did not
work on persisted records because of the `!record.persisted?`.

While there is still a bug that #17621 brought up, this change was too
drastic and should not be a RC blocker. I will work on fixing this so
that we don't break `valid?` but also aren't validating parent records
through child records if that parent record is validate false. This
change removes the code changes to validate and the corresponding tests.
It adds tests for two of the bugs found since Rails 5 beta2 release.

Fixes #17621
2016-02-23 15:21:46 -05:00
Tara Scherner de la Fuente
926a24a751 remove args from assert_nothing_raised in tests 2016-02-22 22:56:23 -08:00
Santiago Pastorino
e8d58bb299 Merge pull request #23743 from maclover7/rm-unused-parameter
Remove unused parameter from method
2016-02-21 21:45:22 -03:00
eileencodes
6f15b276cb Always validate record if validating a virtual attribute
Fixes #23645

When you're using an `attr_accessor` for a record instead of an
attribute in the database there's no way for the record to know if it
has `changed?` unless you tell it `attribute_will_change!("attribute")`.

The change made in 27aa4dd updated validations to check if a record was
`changed?` or `marked_for_destruction?` or not `persisted?`. It did not
take into account virtual attributes that do not affect the model's
dirty status.

The only way to fix this is to always validate the record if the
attribute does not belong to the set of attributes the record expects
(in `record.attributes`) because virtual attributes will not be in that
hash.

I think we should consider deprecating this particular behavior in the
future and requiring that the user mark the record dirty by noting that
the virtual attribute will change. Unfortunately this isn't easy because
we have no way of knowing that you did the "right thing" in your
application by marking it dirty and will get the deprecation warning
even if you are doing the correct thing.

For now this restores expected behavior when using a virtual attribute
by always validating the record, as well as adds tests for this case.

I was going to add the `!record.attributes.include?(attribute)` to the
`should_validate?` method but `uniqueness` cannot validate a virtual
attribute with nothing to hold on to the attribute. Because of this
`should_validate?` was about to become a very messy method so I decided
to split them up so we can handle it specifically for each case.
2016-02-20 09:15:39 -05:00
Jon Moss
67ba041a32 Remove unused parameter from method
The `attribute` parameter is not used inside the `normalize_detail`
method. This does not need to go through a deprecation cycle, since the
method is private.
2016-02-17 16:09:54 -05:00