Commit Graph

1766 Commits

Author SHA1 Message Date
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
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
Mehmet Emin İNAÇ
e38ced376f Add documentation about method to describe how it works [ci skip] 2016-02-04 20:03:24 +02:00
Sean Griffin
49f6ce63f3 Preparing for Rails 5.0.0.beta2 2016-02-01 14:37:52 -07:00
Matthew Draper
d6f2000a67 Wrangle the asset build into something that sounds more general 2016-02-01 05:03:03 +10:30
Aaron Patterson
6dfab475ca Merge branch '5-0-beta-sec'
* 5-0-beta-sec:
  bumping version
  fix version update task to deal with .beta1.1
  Eliminate instance level writers for class accessors
  allow :file to be outside rails root, but anything else must be inside the rails view directory
  Don't short-circuit reject_if proc
  stop caching mime types globally
  use secure string comparisons for basic auth username / password
2016-01-25 11:25:11 -08:00
Aaron Patterson
908c011395 bumping version 2016-01-25 10:22:15 -08:00
Aaron Patterson
4642d68d80 Eliminate instance level writers for class accessors
Instance level writers can have an impact on how the Active Model /
Record objects are saved.  Specifically, they can be used to bypass
validations.  This is a problem if mass assignment protection is
disabled and specific attributes are passed to the constructor.

CVE-2016-0753
2016-01-22 15:02:46 -08:00
Sean Griffin
302e92359c Refactor tz aware types, add support for PG ranges
This is an alternate implementation to #22875, that generalizes a lot of
the logic that type decorators are going to need, in order to have them
work with arrays, ranges, etc. The types have the ability to map over a
value, with the default implementation being to just yield that given
value. Array and Range give more appropriate definitions.

This does not automatically make ranges time zone aware, as they need to
be added to the `time_zone_aware` types config, but we could certainly
make that change if we feel it is appropriate. I do think this would be
a breaking change however, and should at least have a deprecation cycle.

Closes #22875.

/cc @matthewd
2016-01-08 14:11:45 -07:00
Lachlan Sylvester
4ba66ef108 remove activemodel dependency on builder 2016-01-06 18:55:59 +11:00
Rafael Mendonça França
53954aa476 Move CHANGELOG entry to Active Record
While the type definition is in Active Model the change of behavior will
be only user facing in Active Record so better to put the entry in its
changelog.

[ci skip]
2016-01-05 23:00:57 -02:00
Andrey Novikov
0a0ffb64d8 Take UTC offset into account when assigning string value to time attribute. 2016-01-05 18:35:04 +03:00
Rashmi Yadav
1b608a695c Update copyright notices to 2016 [ci skip] 2015-12-31 18:27:19 +02:00
Robert Eshleman
57fb74e081 Convert non-Numeric values to Floats 2015-12-22 16:01:50 -05:00
Robert Eshleman
9c330798b0 Fix Regression in Numericality Validations
A regression (#22744) introduced in 7500dae caused certain numericality
validations to raise an error when run against an attribute with a
string value. Previously, these validations would successfully run
against string values because the value was cast to a numeric class.

This commit resolves the regression by converting string values to
floats before performing numericality comparison validations.

[fixes #22744]
2015-12-22 14:27:25 -05:00
Robert Eshleman
b96fdd234d Failing Tests for Validating String Numbericality
Covers Regressions:

* <=
* <
* ==
* >
* >=
* other than
2015-12-22 14:27:25 -05:00
Genadi Samokovarov
c5b6ec7b0f No more no changes entries in the CHANGELOGs
During the `5.0.0.beta1` release, the CHANGELOGs got an entry like the
following:

```
* No changes.
```

It is kinda confusing as there are indeed changes after it. Not a
biggie, just a small pass over the CHANGELOGs.

[ci skip]
2015-12-21 11:46:38 +02:00
Jon Atack
d3e98c6f30 Add missing @claudiob credit to change log [skip ci] 2015-12-20 22:03:53 +01:00
eileencodes
099ddfdefd Add CHANGELOG headers for Rails 5.0.0.beta1 2015-12-18 15:58:25 -05:00
eileencodes
7eae0bb88e Change alpha to beta1 to prep for release of Rails 5
🎉 🍻
2015-12-18 12:14:09 -05:00
Rafael França
b7a7e82207 Merge pull request #22598 from yui-knk/deprecate_string_callback
Deprecate passing string to define callback.
2015-12-16 13:54:02 -02:00
yui-knk
21f4017fd9 Deprecate passing string to define callback. 2015-12-16 19:56:20 +09:00
Vokhmin Alexey V
61e5081404 ActiveRecord::Base#becomes should copy the errors 2015-12-14 19:02:20 +03:00
Sean Griffin
574f255629 Use a bind param for LIMIT and OFFSET
We currently generate an unbounded number of prepared statements when
`limit` or `offset` are called with a dynamic argument. This changes
`LIMIT` and `OFFSET` to use bind params, eliminating the problem.

`Type::Value#hash` needed to be implemented, as it turns out we busted
the query cache if the type object used wasn't exactly the same object.

This drops support for passing an `Arel::Nodes::SqlLiteral` to `limit`.
Doing this relied on AR internals, and was never officially supported
usage.

Fixes #22250.
2015-12-14 08:40:02 -07:00
Aaron Patterson
2de7385cef Merge pull request #22381 from yahonda/use_adapter_subsecond_precision_supported
Use adapter supports_datetime_with_precision
2015-12-13 12:13:22 +09:00
Rafael França
bf9facb31c Merge pull request #22517 from Elektron1c97/master
[ci skip] Add a dollar sign to each command in the READMEs
2015-12-07 01:07:09 -02:00
Elektron1c97
6bd417df50 [ci skip] Add a dollar sign to each command in the READMEs
According to pr #22443 in the guides there's always a dollar sign before every command, so why is in the main README a `$` and in every submodule a `%`?

Just eye candy..
2015-12-06 19:18:52 +01:00
keepcosmos
7a8031b578 add test for nested model translation 2015-12-03 14:37:05 +09:00
Yasuo Honda
589cef086f Avoid dummy_time_value to add "2000-01-01" twice 2015-11-30 20:04:46 +00:00
Sean Griffin
c78c43533e Fix test failures caused by #21000 2015-11-23 15:19:39 -07:00
Sean Griffin
de9b870f40 Merge pull request #21000 from twalpole/find_or_parameter_issues
Update and fix forbidden attributes test issues caused by AC::Parameters change
2015-11-23 14:58:05 -07:00
Yves Senn
96cc2e8335 Merge pull request #22333 from harrykiselev/patch-3
[ci skip] Update dirty.rb: documentation fix.
2015-11-21 11:21:20 +01:00
Harry V. Kiselev
ea0617e789 Update dirty.rb: documentation fix.
ActiveModel::Dirty module documentation fix.
2015-11-19 00:45:54 +03:00
Jerry D'Antonio
23b6f65fd1 Require only necessary concurrent-ruby classes. 2015-11-04 21:12:28 -05:00
Thomas Walpole
85f7d955f3 Update and fix forbidden attributes tests
Add AC::Parameters tests for WhereChain#not
2015-11-03 11:34:07 -08:00
Sean Griffin
0d216d1add Really fix test failures caused by #19851
Ok, this explains why the branch showed as green. We don't run files in
isolation for PRs, only for master. Active Support monkeypatches
`BigDecimal#to_s`, so the generated error message was different
depending on if the file was run in isolation
2015-10-20 18:08:50 -06:00
Sean Griffin
12df3391e3 Fix test failures caused by #19851
The error message when asserting `greater_than: BigDecimal.new` will
give an error message based on how BigDecimal displays itself. Big
decimal appears to always use scientific notation. This might not be the
best error message for the general case, but the general case wouldn't
use big decimal for the validation. And if they do, they likely need
this level of precision.
2015-10-20 17:49:47 -06:00
Sean Griffin
328ec26cbe Merge pull request #19851 from repinel/numericality-validation2
Use the post-type-cast version of the attribute to validate numericality
2015-10-20 17:05:44 -06:00
Sean Griffin
d6919c524a All strings returned by ImmutableString should be frozen
I seriously don't even know why we handle booleans, but those strings
should technically be frozen. Additionally, we don't need to actually
check the class in the mutable string type, since the `cast_value`
function will always return a string.
2015-10-15 09:55:30 -07:00